Merge branch 'master' into RRF-PP-for-Path

This commit is contained in:
P-C-R
2021-11-15 08:18:18 +01:00
committed by GitHub
59 changed files with 1591 additions and 680 deletions

View File

@@ -58,6 +58,7 @@
<file>icons/Silk_workbench_icon.svg</file>
<file>icons/timber_workbench_icon.svg</file>
<file>icons/ThreadProfile_workbench_icon.svg</file>
<file>icons/VendorParts_workbench_icon.svg</file>
<file>icons/WebTools_workbench_icon.svg</file>
<file>icons/workfeature_workbench_icon.svg</file>
<file>icons/yaml-workspace_workbench_icon.svg</file>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 16.93 16.93" xmlns="http://www.w3.org/2000/svg">
<rect x=".7547" y=".7547" width="15.42" height="15.42" ry="3.148" fill="#f66" stroke-linecap="round" stroke-linejoin="round" stroke-width=".975"/>
<g fill="#fff" stroke-width=".2645" aria-label="VP">
<path d="m4.333 12.16-1.958-7.386h1.767l0.8677 3.756 0.4338 2.127h0.08465l0.4444-2.127 0.8782-3.756h1.682l-1.958 7.386z"/>
<path d="m9.433 12.16v-7.386h2.857q0.5396 0 0.9629 0.1693 0.4233 0.1587 0.7089 0.4656 0.2963 0.3069 0.4444 0.7407t0.1481 0.9735q0 0.5396-0.1481 0.9735t-0.4444 0.7407q-0.2857 0.3069-0.7089 0.4762-0.4233 0.1587-0.9629 0.1587h-1.259v2.688zm1.598-3.968h0.8571q0.5608 0 0.7724-0.2116 0.2222-0.2116 0.2222-0.6984v-0.3174q0-0.4867-0.2222-0.6984-0.2116-0.2116-0.7724-0.2116h-0.8571z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 863 B

View File

@@ -164,36 +164,11 @@ def invert(shape):
def findMidpoint(edge):
"""Return the midpoint of a straight line or circular edge."""
first = edge.Vertexes[0].Point
last = edge.Vertexes[-1].Point
if geomType(edge) == "Circle":
center = edge.Curve.Center
radius = edge.Curve.Radius
if len(edge.Vertexes) == 1:
# Circle
dv = first.sub(center)
dv = dv.negative()
return center.add(dv)
axis = edge.Curve.Axis
chord = last.sub(first)
perp = chord.cross(axis)
perp.normalize()
ray = first.sub(center)
apothem = ray.dot(perp)
sagitta = radius - apothem
startpoint = App.Vector.add(first, chord.multiply(0.5))
endpoint = DraftVecUtils.scaleTo(perp, sagitta)
return App.Vector.add(startpoint, endpoint)
elif geomType(edge) == "Line":
halfedge = (last.sub(first)).multiply(0.5)
return App.Vector.add(first, halfedge)
else:
"""Return the midpoint of an edge."""
if edge.Length == 0:
return None
else:
return edge.valueAt(edge.Curve.parameterAtDistance(edge.Length/2, edge.FirstParameter))
def getTangent(edge, from_point=None):
@@ -248,4 +223,4 @@ def get_referenced_edges(property_value):
isLine = is_line
## @}
## @}

View File

@@ -59,13 +59,7 @@ int ArcOfConic2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwds*/)
Py::Object ArcOfConic2dPy::getLocation(void) const
{
Base::Vector2d loc = getGeom2dArcOfConicPtr()->getLocation();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.x));
arg.setItem(1, Py::Float(loc.y));
return method.apply(arg);
return Base::Vector2dPy::create(loc);
}
void ArcOfConic2dPy::setLocation(Py::Object arg)
@@ -86,12 +80,7 @@ Py::Object ArcOfConic2dPy::getXAxis(void) const
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
gp_Dir2d xdir = conic->XAxis().Direction();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(xdir.X()));
arg.setItem(1, Py::Float(xdir.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(xdir.X(), xdir.Y());
}
void ArcOfConic2dPy::setXAxis(Py::Object arg)
@@ -109,12 +98,7 @@ Py::Object ArcOfConic2dPy::getYAxis(void) const
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(getGeom2dArcOfConicPtr()->handle());
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
gp_Dir2d ydir = conic->YAxis().Direction();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(ydir.X()));
arg.setItem(1, Py::Float(ydir.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(ydir.X(), ydir.Y());
}
void ArcOfConic2dPy::setYAxis(Py::Object arg)

View File

@@ -117,7 +117,6 @@ PyObject* BSplineCurve2dPy::increaseDegree(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -144,7 +143,6 @@ PyObject* BSplineCurve2dPy::increaseMultiplicity(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -162,7 +160,6 @@ PyObject* BSplineCurve2dPy::incrementMultiplicity(PyObject * args)
curve->IncrementMultiplicity(start, end, mult);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -183,7 +180,6 @@ PyObject* BSplineCurve2dPy::insertKnot(PyObject * args)
curve->InsertKnot(U,M,tol);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -224,7 +220,6 @@ PyObject* BSplineCurve2dPy::insertKnots(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -246,7 +241,6 @@ PyObject* BSplineCurve2dPy::removeKnot(PyObject * args)
return PyBool_FromLong(ok ? 1 : 0);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -264,7 +258,6 @@ PyObject* BSplineCurve2dPy::segment(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -322,7 +315,6 @@ PyObject* BSplineCurve2dPy::setKnots(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -344,7 +336,6 @@ PyObject* BSplineCurve2dPy::getKnots(PyObject * args)
return Py::new_reference_to(knots);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -369,7 +360,6 @@ PyObject* BSplineCurve2dPy::setPole(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -386,16 +376,9 @@ PyObject* BSplineCurve2dPy::getPole(PyObject * args)
Standard_OutOfRange_Raise_if
(index < 1 || index > curve->NbPoles(), "Pole index out of range");
gp_Pnt2d pnt = curve->Pole(index);
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(pnt.X(), pnt.Y()));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -412,20 +395,13 @@ PyObject* BSplineCurve2dPy::getPoles(PyObject * args)
curve->Poles(p);
Py::List poles;
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
gp_Pnt2d pnt = p(i);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
poles.append(method.apply(arg));
poles.append(Base::Vector2dPy::create(pnt.X(), pnt.Y()));
}
return Py::new_reference_to(poles);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -456,7 +432,6 @@ PyObject* BSplineCurve2dPy::getPolesAndWeights(PyObject * args)
return Py::new_reference_to(poles);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -475,7 +450,6 @@ PyObject* BSplineCurve2dPy::setWeight(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -495,7 +469,6 @@ PyObject* BSplineCurve2dPy::getWeight(PyObject * args)
return Py_BuildValue("d", weight);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -517,7 +490,6 @@ PyObject* BSplineCurve2dPy::getWeights(PyObject * args)
return Py::new_reference_to(weights);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -536,7 +508,6 @@ PyObject* BSplineCurve2dPy::getResolution(PyObject * args)
return Py_BuildValue("d",utol);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -558,7 +529,6 @@ PyObject* BSplineCurve2dPy::movePoint(PyObject * args)
return Py_BuildValue("(ii)",first, last);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -575,7 +545,6 @@ PyObject* BSplineCurve2dPy::setNotPeriodic(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -592,7 +561,6 @@ PyObject* BSplineCurve2dPy::setPeriodic(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -610,7 +578,6 @@ PyObject* BSplineCurve2dPy::setOrigin(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -650,7 +617,6 @@ PyObject* BSplineCurve2dPy::getMultiplicities(PyObject * args)
return Py::new_reference_to(mults);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -689,13 +655,7 @@ Py::Object BSplineCurve2dPy::getStartPoint(void) const
Handle(Geom2d_BSplineCurve) c = Handle(Geom2d_BSplineCurve)::DownCast
(getGeometry2dPtr()->handle());
gp_Pnt2d pnt = c->StartPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
Py::Object BSplineCurve2dPy::getEndPoint(void) const
@@ -703,13 +663,7 @@ Py::Object BSplineCurve2dPy::getEndPoint(void) const
Handle(Geom2d_BSplineCurve) c = Handle(Geom2d_BSplineCurve)::DownCast
(getGeometry2dPtr()->handle());
gp_Pnt2d pnt = c->EndPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
Py::Object BSplineCurve2dPy::getFirstUKnotIndex(void) const
@@ -769,7 +723,6 @@ PyObject* BSplineCurve2dPy::toBiArcs(PyObject * args)
return Py::new_reference_to(list);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -890,7 +843,6 @@ PyObject* BSplineCurve2dPy::approximate(PyObject *args, PyObject *kwds)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -917,13 +869,8 @@ PyObject* BSplineCurve2dPy::getCardinalSplineTangents(PyObject *args, PyObject *
bspline->getCardinalSplineTangents(interpPoints, parameter, tangents);
Py::List vec;
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (gp_Vec2d it : tangents) {
arg.setItem(0, Py::Float(it.X()));
arg.setItem(1, Py::Float(it.Y()));
vec.append(method.apply(arg));
vec.append(Base::Vector2dPy::create(it.X(), it.Y()));
}
return Py::new_reference_to(vec);
}
@@ -952,18 +899,13 @@ PyObject* BSplineCurve2dPy::getCardinalSplineTangents(PyObject *args, PyObject *
bspline->getCardinalSplineTangents(interpPoints, parameters, tangents);
Py::List vec;
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (gp_Vec2d it : tangents) {
arg.setItem(0, Py::Float(it.X()));
arg.setItem(1, Py::Float(it.Y()));
vec.append(method.apply(arg));
vec.append(Base::Vector2dPy::create(it.X(), it.Y()));
}
return Py::new_reference_to(vec);
}
return 0;
return nullptr;
}
PyObject* BSplineCurve2dPy::interpolate(PyObject *args, PyObject *kwds)
@@ -1057,7 +999,6 @@ PyObject* BSplineCurve2dPy::interpolate(PyObject *args, PyObject *kwds)
}
}
catch (Standard_Failure& e) {
std::string err = e.GetMessageString();
if (err.empty()) err = e.DynamicType()->Name();
PyErr_SetString(PartExceptionOCCError, err.c_str());
@@ -1137,7 +1078,6 @@ PyObject* BSplineCurve2dPy::buildFromPoles(PyObject *args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}

View File

@@ -113,7 +113,6 @@ PyObject* BezierCurve2dPy::insertPoleAfter(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -135,7 +134,6 @@ PyObject* BezierCurve2dPy::insertPoleBefore(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -153,7 +151,6 @@ PyObject* BezierCurve2dPy::removePole(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -171,7 +168,6 @@ PyObject* BezierCurve2dPy::segment(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -196,7 +192,6 @@ PyObject* BezierCurve2dPy::setPole(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -213,16 +208,9 @@ PyObject* BezierCurve2dPy::getPole(PyObject * args)
Standard_OutOfRange_Raise_if
(index < 1 || index > curve->NbPoles(), "Pole index out of range");
gp_Pnt2d pnt = curve->Pole(index);
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(pnt.X(), pnt.Y()));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -239,20 +227,13 @@ PyObject* BezierCurve2dPy::getPoles(PyObject * args)
curve->Poles(p);
Py::List poles;
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
gp_Pnt2d pnt = p(i);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
poles.append(method.apply(arg));
poles.append(Base::Vector2dPy::create(pnt.X(), pnt.Y()));
}
return Py::new_reference_to(poles);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -277,7 +258,6 @@ PyObject* BezierCurve2dPy::setPoles(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -296,7 +276,6 @@ PyObject* BezierCurve2dPy::setWeight(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -316,7 +295,6 @@ PyObject* BezierCurve2dPy::getWeight(PyObject * args)
return Py_BuildValue("d", weight);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -338,7 +316,6 @@ PyObject* BezierCurve2dPy::getWeights(PyObject * args)
return Py::new_reference_to(weights);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -357,7 +334,6 @@ PyObject* BezierCurve2dPy::getResolution(PyObject* args)
return Py_BuildValue("d",utol);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -388,13 +364,7 @@ Py::Object BezierCurve2dPy::getStartPoint(void) const
Handle(Geom2d_BezierCurve) c = Handle(Geom2d_BezierCurve)::DownCast
(getGeometry2dPtr()->handle());
gp_Pnt2d pnt = c->StartPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
Py::Object BezierCurve2dPy::getEndPoint(void) const
@@ -402,13 +372,7 @@ Py::Object BezierCurve2dPy::getEndPoint(void) const
Handle(Geom2d_BezierCurve) c = Handle(Geom2d_BezierCurve)::DownCast
(getGeometry2dPtr()->handle());
gp_Pnt2d pnt = c->EndPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
PyObject *BezierCurve2dPy::getCustomAttributes(const char* /*attr*/) const

View File

@@ -57,13 +57,7 @@ int Conic2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwds*/)
Py::Object Conic2dPy::getLocation(void) const
{
Base::Vector2d loc = getGeom2dConicPtr()->getLocation();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.x));
arg.setItem(1, Py::Float(loc.y));
return method.apply(arg);
return Base::Vector2dPy::create(loc);
}
void Conic2dPy::setLocation(Py::Object arg)
@@ -82,12 +76,7 @@ Py::Object Conic2dPy::getXAxis(void) const
{
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(getGeom2dConicPtr()->handle());
gp_Dir2d xdir = conic->XAxis().Direction();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(xdir.X()));
arg.setItem(1, Py::Float(xdir.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(xdir.X(), xdir.Y());
}
void Conic2dPy::setXAxis(Py::Object arg)
@@ -103,12 +92,7 @@ Py::Object Conic2dPy::getYAxis(void) const
{
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(getGeom2dConicPtr()->handle());
gp_Dir2d ydir = conic->YAxis().Direction();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(ydir.X()));
arg.setItem(1, Py::Float(ydir.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(ydir.X(), ydir.Y());
}
void Conic2dPy::setYAxis(Py::Object arg)

View File

@@ -107,7 +107,6 @@ PyObject* Curve2dPy::reverse(PyObject * args)
Py_Return;
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -187,7 +186,6 @@ PyObject* Curve2dPy::toShape(PyObject *args)
return Py::new_reference_to(shape2pyshape(edge));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -204,7 +202,6 @@ PyObject* Curve2dPy::toShape(PyObject *args)
return Py::new_reference_to(shape2pyshape(edge));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -225,7 +222,6 @@ PyObject* Curve2dPy::toShape(PyObject *args)
return Py::new_reference_to(shape2pyshape(edge));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -265,7 +261,6 @@ PyObject* Curve2dPy::toShape(PyObject *args)
return Py::new_reference_to(shape2pyshape(edge));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -285,7 +280,6 @@ PyObject* Curve2dPy::toShape(PyObject *args)
return Py::new_reference_to(shape2pyshape(edge));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -321,14 +315,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt2d p = adapt.Value (discretizer.Parameter (i));
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -351,14 +340,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt2d p = adapt.Value (discretizer.Parameter (i));
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -379,14 +363,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = discretizer.Value (i);
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -409,14 +388,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = discretizer.Value (i);
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -437,14 +411,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt2d p = adapt.Value (discretizer.Parameter (i));
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -464,15 +433,9 @@ PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds)
if (discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = discretizer.Value (i);
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p.X(), p.Y()));
}
return Py::new_reference_to(points);
@@ -509,7 +472,6 @@ PyObject* Curve2dPy::length(PyObject *args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -535,7 +497,6 @@ PyObject* Curve2dPy::parameterAtDistance(PyObject *args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -554,17 +515,10 @@ PyObject* Curve2dPy::value(PyObject *args)
if (!PyArg_ParseTuple(args, "d", &u))
return 0;
gp_Pnt2d p = c->Value(u);
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(p.X()));
arg.setItem(1, Py::Float(p.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(p.X(), p.Y()));
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -588,16 +542,10 @@ PyObject* Curve2dPy::tangent(PyObject *args)
prop.Tangent(dir);
}
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(dir.X()));
arg.setItem(1, Py::Float(dir.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(dir.X(), dir.Y()));
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -619,16 +567,10 @@ PyObject* Curve2dPy::normal(PyObject *args)
Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion());
prop.Normal(dir);
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(dir.X()));
arg.setItem(1, Py::Float(dir.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(dir.X(), dir.Y()));
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -652,7 +594,6 @@ PyObject* Curve2dPy::curvature(PyObject *args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -674,16 +615,10 @@ PyObject* Curve2dPy::centerOfCurvature(PyObject *args)
gp_Pnt2d pnt ;
prop.CentreOfCurvature(pnt);
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return Py::new_reference_to(method.apply(arg));
return Py::new_reference_to(Base::Vector2dPy::create(pnt.X(), pnt.Y()));
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -737,7 +672,6 @@ PyObject* Curve2dPy::toBSpline(PyObject * args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -791,7 +725,6 @@ PyObject* Curve2dPy::approximateBSpline(PyObject *args)
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
@@ -874,11 +807,9 @@ PyObject* Curve2dPy::intersectCC(PyObject *args)
double prec = Precision::Confusion();
if (!PyArg_ParseTuple(args, "O!|d", &(Part::Curve2dPy::Type), &p, &prec))
return 0;
Handle(Geom2d_Curve) curve2 = Handle(Geom2d_Curve)::DownCast(static_cast<Geometry2dPy*>(p)->getGeometry2dPtr()->handle());
Py::List points;
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
Geom2dAPI_InterCurveCurve intersector(curve1, curve2, prec);
if ((intersector.NbPoints() == 0) && (intersector.NbSegments() == 0)) {
// No intersection
@@ -888,9 +819,7 @@ PyObject* Curve2dPy::intersectCC(PyObject *args)
// Cross intersections
for (int i = 1; i <= intersector.NbPoints(); i++) {
gp_Pnt2d p1 = intersector.Point(i);
arg.setItem(0, Py::Float(p1.X()));
arg.setItem(1, Py::Float(p1.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p1.X(), p1.Y()));
}
}
if (intersector.NbSegments() > 0) {
@@ -905,17 +834,13 @@ PyObject* Curve2dPy::intersectCC(PyObject *args)
continue;
gp_Pnt2d p1, p2;
intersector2.Points(i, p1, p2);
arg.setItem(0, Py::Float(p1.X()));
arg.setItem(1, Py::Float(p1.Y()));
points.append(method.apply(arg));
points.append(Base::Vector2dPy::create(p1.X(), p1.Y()));
}
}
return Py::new_reference_to(points);
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return 0;
}

View File

@@ -160,26 +160,14 @@ Py::Object Ellipse2dPy::getFocus1(void) const
{
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(getGeom2dEllipsePtr()->handle());
gp_Pnt2d loc = ellipse->Focus1();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(loc.X(), loc.Y());
}
Py::Object Ellipse2dPy::getFocus2(void) const
{
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(getGeom2dEllipsePtr()->handle());
gp_Pnt2d loc = ellipse->Focus2();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(loc.X(), loc.Y());
}
PyObject *Ellipse2dPy::getCustomAttributes(const char* /*attr*/) const

View File

@@ -160,26 +160,14 @@ Py::Object Hyperbola2dPy::getFocus1(void) const
{
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
gp_Pnt2d loc = hyperbola->Focus1();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(loc.X(), loc.Y());
}
Py::Object Hyperbola2dPy::getFocus2(void) const
{
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(getGeom2dHyperbolaPtr()->handle());
gp_Pnt2d loc = hyperbola->Focus2();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(loc.X(), loc.Y());
}
PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const

View File

@@ -126,13 +126,7 @@ Py::Object Line2dPy::getLocation(void) const
Handle(Geom2d_Line) this_curve = Handle(Geom2d_Line)::DownCast
(this->getGeom2dLinePtr()->handle());
gp_Pnt2d pnt = this_curve->Location();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
void Line2dPy::setLocation(Py::Object arg)
@@ -180,13 +174,7 @@ Py::Object Line2dPy::getDirection(void) const
Handle(Geom2d_Line) this_curve = Handle(Geom2d_Line)::DownCast
(this->getGeom2dLinePtr()->handle());
gp_Dir2d dir = this_curve->Direction();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(dir.X()));
arg.setItem(1, Py::Float(dir.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(dir.X(), dir.Y());
}
void Line2dPy::setDirection(Py::Object arg)

View File

@@ -201,13 +201,7 @@ Py::Object Line2dSegmentPy::getStartPoint(void) const
Handle(Geom2d_TrimmedCurve) this_curve = Handle(Geom2d_TrimmedCurve)::DownCast
(this->getGeom2dLineSegmentPtr()->handle());
gp_Pnt2d pnt = this_curve->StartPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
void Line2dSegmentPy::setStartPoint(Py::Object arg)
@@ -261,13 +255,7 @@ Py::Object Line2dSegmentPy::getEndPoint(void) const
Handle(Geom2d_TrimmedCurve) this_curve = Handle(Geom2d_TrimmedCurve)::DownCast
(this->getGeom2dLineSegmentPtr()->handle());
gp_Pnt2d pnt = this_curve->EndPoint();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(pnt.X()));
arg.setItem(1, Py::Float(pnt.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(pnt.X(), pnt.Y());
}
void Line2dSegmentPy::setEndPoint(Py::Object arg)

View File

@@ -76,13 +76,7 @@ Py::Object Parabola2dPy::getFocus(void) const
{
Handle(Geom2d_Parabola) curve = Handle(Geom2d_Parabola)::DownCast(getGeometry2dPtr()->handle());
gp_Pnt2d loc = curve->Focus();
Py::Module module("__FreeCADBase__");
Py::Callable method(module.getAttr("Vector2d"));
Py::Tuple arg(2);
arg.setItem(0, Py::Float(loc.X()));
arg.setItem(1, Py::Float(loc.Y()));
return method.apply(arg);
return Base::Vector2dPy::create(loc.X(), loc.Y());
}
Py::Float Parabola2dPy::getParameter(void) const

View File

@@ -123,7 +123,7 @@ App::DocumentObjectExecReturn *Loft::execute(void)
if (subValues.empty())
throw Base::ValueError("Loft: No valid subelement linked in Part::Feature");
shape = static_cast<Part::Feature*>(obj)->Shape.getShape(). getSubShape(subValues[0].c_str());
shape = static_cast<Part::Feature*>(obj)->Shape.getShape().getSubShape(subValues[0].c_str());
}
TopExp_Explorer ex;

View File

@@ -89,7 +89,7 @@ public:
/**
* Verifies the linked Object and returns the shape used as profile
* @param silent if profirle property is malformed and the parameter is true
* @param silent if profile property is malformed and the parameter is true
* silently returns nullptr, otherwise throw a Base::Exception.
* Default is false.
*/

View File

@@ -640,7 +640,8 @@ bool TaskPadParameters::getAlongSketchNormal(void) const
bool TaskPadParameters::getCustom(void) const
{
return ui->checkBoxDirection->isChecked();
// index 2 is hardcoded to custom vector
return ui->directionCB->currentIndex() == 2 ? true : false;
}
std::string TaskPadParameters::getReferenceAxis(void) const

View File

@@ -49,6 +49,23 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelOffset">
<property name="text">
<string>Offset to face</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefQuantitySpinBox" name="offsetEdit">
<property name="toolTip">
<string>Offset from face at which pad will end</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -224,27 +241,6 @@ measured along the specified direction</string>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="labelOffset">
<property name="text">
<string>Offset to face</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="offsetEdit">
<property name="toolTip">
<string>Offset from face in which pad will end</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxMidplane">
<property name="enabled">
@@ -336,6 +332,23 @@ measured along the specified direction</string>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>changeMode</tabstop>
<tabstop>lengthEdit</tabstop>
<tabstop>offsetEdit</tabstop>
<tabstop>directionCB</tabstop>
<tabstop>checkBoxAlongDirection</tabstop>
<tabstop>checkBoxMidplane</tabstop>
<tabstop>checkBoxReversed</tabstop>
<tabstop>lengthEdit2</tabstop>
<tabstop>buttonFace</tabstop>
<tabstop>lineFaceName</tabstop>
<tabstop>checkBoxUpdateView</tabstop>
<tabstop>checkBoxDirection</tabstop>
<tabstop>XDirectionEdit</tabstop>
<tabstop>YDirectionEdit</tabstop>
<tabstop>ZDirectionEdit</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -650,7 +650,8 @@ bool TaskPocketParameters::getAlongSketchNormal(void) const
bool TaskPocketParameters::getCustom(void) const
{
return ui->checkBoxDirection->isChecked();
// index 2 is hardcoded to custom vector
return ui->directionCB->currentIndex() == 2 ? true : false;
}
std::string TaskPocketParameters::getReferenceAxis(void) const

View File

@@ -52,12 +52,15 @@
<item row="2" column="0">
<widget class="QLabel" name="labelOffset">
<property name="text">
<string>Offset</string>
<string>Offset to face</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefQuantitySpinBox" name="offsetEdit">
<property name="toolTip">
<string>Offset from face at which pocket will end</string>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
@@ -327,12 +330,18 @@ measured along the specified direction</string>
<tabstop>changeMode</tabstop>
<tabstop>lengthEdit</tabstop>
<tabstop>offsetEdit</tabstop>
<tabstop>directionCB</tabstop>
<tabstop>checkBoxAlongDirection</tabstop>
<tabstop>checkBoxMidplane</tabstop>
<tabstop>checkBoxReversed</tabstop>
<tabstop>lengthEdit2</tabstop>
<tabstop>buttonFace</tabstop>
<tabstop>lineFaceName</tabstop>
<tabstop>checkBoxUpdateView</tabstop>
<tabstop>checkBoxDirection</tabstop>
<tabstop>XDirectionEdit</tabstop>
<tabstop>YDirectionEdit</tabstop>
<tabstop>ZDirectionEdit</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@@ -1023,38 +1023,39 @@ void PropertySheet::addDependencies(CellAddress key)
if (expression == 0)
return;
for(auto &dep : expression->getDeps()) {
for(auto &var : expression->getIdentifiers()) {
for(auto &dep : var.first.getDep(true)) {
App::DocumentObject *docObj = dep.first;
App::Document *doc = docObj->getDocument();
App::DocumentObject *docObj = dep.first;
App::Document *doc = docObj->getDocument();
std::string docObjName = docObj->getFullName();
std::string docObjName = docObj->getFullName();
owner->observeDocument(doc);
owner->observeDocument(doc);
documentObjectToCellMap[docObjName].insert(key);
cellToDocumentObjectMap[key].insert(docObjName);
++updateCount;
documentObjectToCellMap[docObjName].insert(key);
cellToDocumentObjectMap[key].insert(docObjName);
++updateCount;
for(auto &name : dep.second) {
std::string propName = docObjName + "." + name;
FC_LOG("dep " << key.toString() << " -> " << name);
for(auto &props : dep.second) {
std::string propName = docObjName + "." + props.first;
FC_LOG("dep " << key.toString() << " -> " << propName);
// Insert into maps
propertyNameToCellMap[propName].insert(key);
cellToPropertyNameMap[key].insert(propName);
// Insert into maps
propertyNameToCellMap[propName].insert(key);
cellToPropertyNameMap[key].insert(propName);
// Also an alias?
if (docObj==owner && name.size()) {
auto j = revAliasProp.find(name);
// Also an alias?
if (docObj==owner && props.first.size()) {
std::map<std::string, CellAddress>::const_iterator j = revAliasProp.find(props.first);
if (j != revAliasProp.end()) {
propName = docObjName + "." + j->second.toString();
FC_LOG("dep " << key.toString() << " -> " << propName);
if (j != revAliasProp.end()) {
propName = docObjName + "." + j->second.toString();
FC_LOG("dep " << key.toString() << " -> " << propName);
// Insert into maps
propertyNameToCellMap[propName].insert(key);
cellToPropertyNameMap[key].insert(propName);
// Insert into maps
propertyNameToCellMap[propName].insert(key);
cellToPropertyNameMap[key].insert(propName);
}
}
}
}
@@ -1123,6 +1124,16 @@ void PropertySheet::removeDependencies(CellAddress key)
void PropertySheet::recomputeDependants(const App::DocumentObject *owner, const char *propName)
{
auto itD = _Deps.find(const_cast<App::DocumentObject*>(owner));
if(itD!=_Deps.end() && itD->second) {
// Check for hidden reference. Because a hidden reference is not
// protected by cyclic dependency checking, we need to take special
// care to prevent it from misbehave.
Sheet *sheet = Base::freecad_dynamic_cast<Sheet>(getContainer());
if(!sheet || sheet->testStatus(App::ObjectStatus::Recompute2))
return;
}
// First, search without actual property name for sub-object/link
// references, i.e indirect references. The dependencies of these
// references are too complex to track exactly, so we only track the
@@ -1135,7 +1146,7 @@ void PropertySheet::recomputeDependants(const App::DocumentObject *owner, const
setDirty(cell);
}
if (propName) {
if (propName && *propName) {
// Now, we check for direct property references
it = propertyNameToCellMap.find(fullName + propName);
if (it != propertyNameToCellMap.end()) {
@@ -1302,7 +1313,7 @@ void PropertySheet::hasSetValue()
updateCount = 0;
std::set<App::DocumentObject*> deps;
std::map<App::DocumentObject*,bool> deps;
std::vector<std::string> labels;
unregisterElementReference();
UpdateElementReferenceExpressionVisitor<PropertySheet> v(*this);
@@ -1384,8 +1395,9 @@ bool PropertySheet::adjustLink(const std::set<DocumentObject*> &inList) {
continue;
try {
bool need_adjust = false;
for(auto docObj : expr->getDepObjects()) {
if (docObj && docObj != owner && inList.count(docObj)) {
for(auto &v : expr->getDepObjects()) {
auto docObj = v.first;
if (v.second && docObj && docObj!=owner && inList.count(docObj)) {
need_adjust = true;
break;
}

View File

@@ -118,8 +118,10 @@ PyMOD_INIT_FUNC(SpreadsheetGui)
CreateSpreadsheetCommands();
SpreadsheetGui::ViewProviderSheet::init();
SpreadsheetGui::ViewProviderSheetPython::init();
SpreadsheetGui::Workbench::init();
SpreadsheetGui::SheetView::init();
SpreadsheetGui::SheetViewPy::init_type();
// register preference page
new Gui::PrefPageProducer<SpreadsheetGui::DlgSettingsImp> ("Spreadsheet");

View File

@@ -9,10 +9,12 @@ include_directories(
)
generate_from_xml(SpreadsheetViewPy)
generate_from_xml(ViewProviderSpreadsheetPy)
# The XML files
set(SpreadsheetGui_XML_SRCS
SpreadsheetViewPy.xml
ViewProviderSpreadsheetPy.xml
)
set(SpreadsheetGui_LIBS
@@ -71,6 +73,7 @@ SET(SpreadsheetGui_SRCS
LineEdit.cpp
ViewProviderSpreadsheet.cpp
ViewProviderSpreadsheet.h
ViewProviderSpreadsheetPyImp.cpp
Resources/Spreadsheet.qrc
SpreadsheetView.cpp
SpreadsheetView.h

View File

@@ -48,6 +48,7 @@
#include <Gui/ExpressionCompleter.h>
#include <LineEdit.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <Mod/Spreadsheet/App/SheetPy.h>
#include <Mod/Spreadsheet/App/Utils.h>
#include "qtcolorpicker.h"
@@ -419,6 +420,16 @@ QModelIndexList SheetView::selectedIndexes() const
return ui->cells->selectionModel()->selectedIndexes();
}
void SpreadsheetGui::SheetView::select(App::CellAddress cell, QItemSelectionModel::SelectionFlags flags)
{
ui->cells->selectionModel()->select(model->index(cell.row(), cell.col()), flags);
}
void SpreadsheetGui::SheetView::select(App::CellAddress topLeft, App::CellAddress bottomRight, QItemSelectionModel::SelectionFlags flags)
{
ui->cells->selectionModel()->select(QItemSelection(model->index(topLeft.row(), topLeft.col()), model->index(bottomRight.row(), bottomRight.col())), flags);
}
void SheetView::deleteSelection()
{
ui->cells->deleteSelection();
@@ -429,10 +440,15 @@ QModelIndex SheetView::currentIndex() const
return ui->cells->currentIndex();
}
void SpreadsheetGui::SheetView::setCurrentIndex(App::CellAddress cell) const
{
ui->cells->setCurrentIndex(model->index(cell.row(), cell.col()));
}
PyObject *SheetView::getPyObject()
{
if (!pythonObject)
pythonObject = new SpreadsheetViewPy(this);
pythonObject = new SheetViewPy(this);
Py_INCREF(pythonObject);
return pythonObject;
@@ -443,4 +459,76 @@ void SheetView::deleteSelf()
Gui::MDIView::deleteSelf();
}
// ----------------------------------------------------------
void SheetViewPy::init_type()
{
behaviors().name("SheetViewPy");
behaviors().doc("Python binding class for the Sheet view class");
// you must have overwritten the virtual functions
behaviors().supportRepr();
behaviors().supportGetattr();
behaviors().supportSetattr();
add_varargs_method("getSheet", &SheetViewPy::getSheet, "getSheet()");
behaviors().readyType();
}
SheetViewPy::SheetViewPy(SheetView *mdi)
: base(mdi)
{
}
SheetViewPy::~SheetViewPy()
{
}
Py::Object SheetViewPy::repr()
{
std::ostringstream s_out;
if (!getSheetViewPtr())
throw Py::RuntimeError("Cannot print representation of deleted object");
s_out << "SheetView";
return Py::String(s_out.str());
}
// Since with PyCXX it's not possible to make a sub-class of MDIViewPy
// a trick is to use MDIViewPy as class member and override getattr() to
// join the attributes of both classes. This way all methods of MDIViewPy
// appear for SheetViewPy, too.
Py::Object SheetViewPy::getattr(const char * attr)
{
if (!getSheetViewPtr())
throw Py::RuntimeError("Cannot print representation of deleted object");
std::string name( attr );
if (name == "__dict__" || name == "__class__") {
Py::Dict dict_self(BaseType::getattr("__dict__"));
Py::Dict dict_base(base.getattr("__dict__"));
for (auto it : dict_base) {
dict_self.setItem(it.first, it.second);
}
return dict_self;
}
try {
return BaseType::getattr(attr);
}
catch (Py::AttributeError& e) {
e.clear();
return base.getattr(attr);
}
}
SheetView* SheetViewPy::getSheetViewPtr()
{
return qobject_cast<SheetView*>(base.getMDIViewPtr());
}
Py::Object SheetViewPy::getSheet(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
return Py::asObject(new Spreadsheet::SheetPy(getSheetViewPtr()->getSheet()));
}
#include "moc_SpreadsheetView.cpp"

View File

@@ -24,6 +24,7 @@
#define SpreadsheetView_H
#include <Gui/MDIView.h>
#include <Gui/MDIViewPy.h>
#include <QHeaderView>
#include "SheetModel.h"
#include <Mod/Spreadsheet/App/Sheet.h>
@@ -73,8 +74,14 @@ public:
QModelIndexList selectedIndexes() const;
void select(App::CellAddress cell, QItemSelectionModel::SelectionFlags flags);
void select(App::CellAddress topLeft, App::CellAddress bottomRight, QItemSelectionModel::SelectionFlags flags);
QModelIndex currentIndex() const;
void setCurrentIndex(App::CellAddress cell) const;
void deleteSelection();
PyObject *getPyObject(void);
@@ -111,6 +118,25 @@ protected:
std::map<int, int> newRowSizes;
};
class SheetViewPy : public Py::PythonExtension<SheetViewPy>
{
public:
using BaseType = Py::PythonExtension<SheetViewPy>;
static void init_type();
SheetViewPy(SheetView *mdi);
~SheetViewPy();
Py::Object repr();
Py::Object getattr(const char *);
Py::Object getSheet(const Py::Tuple&);
SheetView* getSheetViewPtr();
protected:
Gui::MDIViewPy base;
};
} // namespace SpreadsheetModGui
#endif // SpreadsheetView_H

View File

@@ -2,6 +2,7 @@
#include "SpreadsheetViewPy.h"
#include "SpreadsheetViewPy.cpp"
#include "ui_Sheet.h"
#include <Mod/Spreadsheet/App/SheetPy.h>

View File

@@ -36,6 +36,7 @@
#include "ViewProviderSpreadsheet.h"
#include "SpreadsheetView.h"
#include "ViewProviderSpreadsheetPy.h"
#include <Mod/Spreadsheet/App/Sheet.h>
#include <App/Range.h>
@@ -181,3 +182,22 @@ void ViewProviderSheet::updateData(const App::Property* prop)
if (view)
view->updateCell(prop);
}
PyObject *ViewProviderSheet::getPyObject()
{
if (!pyViewObject)
pyViewObject = new ViewProviderSpreadsheetPy(this);
pyViewObject->IncRef();
return pyViewObject;
}
// Python feature -----------------------------------------------------------------------
namespace Gui {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(SpreadsheetGui::ViewProviderSheetPython, SpreadsheetGui::ViewProviderSheet)
/// @endcond
// explicit template instantiation
template class SpreadsheetGuiExport ViewProviderPythonFeatureT<ViewProviderSheet>;
}

View File

@@ -26,6 +26,7 @@
#define SPREADSHEET_ViewProviderImagePlane_H
#include <Gui/ViewProviderDocumentObject.h>
#include <Gui/ViewProviderPythonFeature.h>
#include <QPointer>
namespace Spreadsheet {
@@ -67,6 +68,10 @@ public:
virtual Gui::MDIView *getMDIView() const override;
inline SheetView* getView() const { return view; }
PyObject *getPyObject() override;
protected:
SheetView* showSpreadsheetView();
void updateData(const App::Property *prop) override;
@@ -74,6 +79,8 @@ private:
QPointer<SheetView> view;
};
typedef Gui::ViewProviderPythonFeatureT<ViewProviderSheet> ViewProviderSheetPython;
} //namespace Spreadsheet

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ViewProviderDocumentObjectPy"
Name="ViewProviderSpreadsheetPy"
Twin="ViewProviderSheet"
TwinPointer="ViewProviderSheet"
Include="Mod/Spreadsheet/Gui/ViewProviderSpreadsheet.h"
Namespace="SpreadsheetGui"
FatherInclude="Gui/ViewProviderDocumentObjectPy.h"
FatherNamespace="Gui"
Constructor="false"
Delete="false">
<Documentation>
<Author Licence="LGPL" Name="Jose Luis Cercos Pita" EMail="jlcercos@gmail.com" />
<UserDocu>ViewProviderSheet class</UserDocu>
</Documentation>
<Methode Name="selectedRanges">
<Documentation>
<UserDocu>returns a list with the selected ranges of cells</UserDocu>
</Documentation>
</Methode>
<Methode Name="selectedCells">
<Documentation>
<UserDocu>returns a list with the selected cells</UserDocu>
</Documentation>
</Methode>
<Methode Name="select">
<Documentation>
<UserDocu>select(index, flags): Select the specified cell using the given QItemSelectionModel.SelectionFlag set
select(topLeft, bottomRight, flags): Select the specified range using the given QItemSelectionModel.SelectionFlag set</UserDocu>
</Documentation>
</Methode>
<Methode Name="currentIndex">
<Documentation>
<UserDocu>Get the current active cell</UserDocu>
</Documentation>
</Methode>
<Methode Name="setCurrentIndex">
<Documentation>
<UserDocu>Set the current active cell</UserDocu>
</Documentation>
</Methode>
<Methode Name="getView">
<Documentation>
<UserDocu>Get access to the sheet view</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,115 @@
#include "PreCompiled.h"
#include "ViewProviderSpreadsheetPy.h"
#include "ViewProviderSpreadsheetPy.cpp"
#include <CXX/Objects.hxx>
#include "SpreadsheetView.h"
using namespace SpreadsheetGui;
// returns a string which represents the object e.g. when printed in python
std::string ViewProviderSpreadsheetPy::representation(void) const
{
return std::string("<ViewProviderSpreadsheet object>");
}
PyObject* ViewProviderSpreadsheetPy::selectedRanges(PyObject* /*obj*/)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView *sheetView = vp->getView();
std::vector<App::Range> ranges = sheetView->selectedRanges();
Py::List list;
for (const auto &range : ranges)
{
list.append(Py::String(range.rangeString()));
}
return Py::new_reference_to(list);
}
PyObject* ViewProviderSpreadsheetPy::selectedCells(PyObject* /*obj*/)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView *sheetView = vp->getView();
QModelIndexList cells = sheetView->selectedIndexes();
Py::List list;
for (const auto &cell : cells) {
list.append(Py::String(App::CellAddress(cell.row(), cell.column()).toString()));
}
return Py::new_reference_to(list);
}
PyObject* ViewProviderSpreadsheetPy::select(PyObject* _args)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
Py::Sequence args(_args);
const char* cell;
const char* topLeft;
const char* bottomRight;
int flags = 0;
if (args.size() == 2 && PyArg_ParseTuple(_args, "si", &cell, &flags)) {
sheetView->select(App::CellAddress(cell), static_cast<QItemSelectionModel::SelectionFlags>(flags));
}
else if (args.size() == 3 && PyArg_ParseTuple(_args, "ssi", &topLeft, &bottomRight, &flags)) {
sheetView->select(App::CellAddress(topLeft), App::CellAddress(bottomRight), static_cast<QItemSelectionModel::SelectionFlags>(flags));
}
else {
if (args.size() == 2)
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1') and QItemSelectionModel.SelectionFlags");
else if (args.size() == 3)
throw Base::TypeError("Expects the arguments to be a cell name (e.g. 'A1'), a second cell name (e.g. 'B5'), and QItemSelectionModel.SelectionFlags");
else
throw Base::TypeError("Wrong arguments to select: specify either a cell, or two cells (for a range), and QItemSelectionModel.SelectionFlags");
}
Py_RETURN_NONE;
}
PyObject* ViewProviderSpreadsheetPy::currentIndex(PyObject* /*_args*/)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
auto index = sheetView->currentIndex();
Py::String str(App::CellAddress(index.row(), index.column()).toString());
return Py::new_reference_to(str);
}
PyObject* ViewProviderSpreadsheetPy::setCurrentIndex(PyObject* args)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
const char* cell;
if (PyArg_ParseTuple(args, "s", &cell)) {
sheetView->setCurrentIndex(App::CellAddress(cell));
}
Py_RETURN_NONE;
}
PyObject* ViewProviderSpreadsheetPy::getView(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
if (sheetView)
return sheetView->getPyObject();
Py_RETURN_NONE;
}
PyObject *ViewProviderSpreadsheetPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int ViewProviderSpreadsheetPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}