Part: Shape.ReflectLines: add 2D/3D, visibility and EdgeType options

This commit is contained in:
tomate44
2021-04-06 18:45:41 +02:00
committed by wmayer
parent 197a0692d3
commit 2daf6a03e4
2 changed files with 52 additions and 13 deletions

View File

@@ -673,10 +673,21 @@ makePerspectiveProjection(shape, pnt) -> Shape
</Methode>
<Methode Name="reflectLines" Const="true" Keyword="true">
<Documentation>
<UserDocu>Build reflect lines on a shape according to the axes of view.
reflectLines(ViewDir, ViewPos, UpDir) -> Shape
<UserDocu>Build projection or reflect lines of a shape according to a view direction.
reflectLines(ViewDir, [ViewPos, UpDir, EdgeType, Visible, OnShape]) -> Shape (Compound of edges)
--
Reflect lines are represented by edges in 3d.
This algorithm computes the projection of the shape in the ViewDir direction.
If OnShape is False(default), the returned edges are flat on the XY plane defined by
ViewPos(origin) and UpDir(up direction).
If OnShape is True, the returned edges are the corresponding 3D reflect lines located on the shape.
EdgeType is a string defining the type of result edges :
- IsoLine : isoparametric line
- OutLine : outline (silhouette) edge
- Rg1Line : smooth edge of G1-continuity between two surfaces
- RgNLine : sewn edge of CN-continuity on one surface
- Sharp : sharp edge (of C0-continuity)
If Visible is True (default), only visible edges are returned.
If Visible is False, only invisible edges are returned.
</UserDocu>
</Documentation>
</Methode>

View File

@@ -2069,35 +2069,63 @@ pos=Gui.ActiveDocument.ActiveView.getCameraNode().position.getValue().getValue()
pos=App.Vector(*pos)
shape=App.ActiveDocument.ActiveObject.Shape
reflect=shape.reflectLines(ViewDir=vdir, ViewPos=pos, UpDir=udir)
reflect=shape.reflectLines(ViewDir=vdir, ViewPos=pos, UpDir=udir, EdgeType="Sharp", Visible=True, OnShape=False)
Part.show(reflect)
*/
PyObject* TopoShapePy::reflectLines(PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"ViewDir", "ViewPos", "UpDir", NULL};
static char *kwlist[] = {"ViewDir", "ViewPos", "UpDir", "EdgeType", "Visible", "OnShape", nullptr};
PyObject *pView, *pPos, *pUp;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", kwlist,
char* type="OutLine";
PyObject* vis = Py_True;
PyObject* in3d = Py_False;
PyObject* pPos = nullptr;
PyObject* pUp = nullptr;
PyObject *pView;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!O!sO!O!", kwlist,
&Base::VectorPy::Type, &pView,
&Base::VectorPy::Type, &pPos,
&Base::VectorPy::Type, &pUp))
return 0;
&Base::VectorPy::Type, &pUp,
&type,
&PyBool_Type, &vis,
&PyBool_Type, &in3d))
return nullptr;
try {
HLRBRep_TypeOfResultingEdge t;
std::string str = type;
if (str == "IsoLine")
t = HLRBRep_IsoLine;
else if (str == "Rg1Line")
t = HLRBRep_Rg1Line;
else if (str == "RgNLine")
t = HLRBRep_RgNLine;
else if (str == "Sharp")
t = HLRBRep_Sharp;
else
t = HLRBRep_OutLine;
Base::Vector3d p(0.0, 0.0, 0.0);
if (pPos) {
p = Py::Vector(pPos,false).toVector();
}
Base::Vector3d u(0.0, 1.0, 0.0);
if (pUp) {
u = Py::Vector(pUp,false).toVector();
}
Base::Vector3d v = Py::Vector(pView,false).toVector();
Base::Vector3d p = Py::Vector(pPos,false).toVector();
Base::Vector3d u = Py::Vector(pUp,false).toVector();
const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape();
HLRAppli_ReflectLines reflect(shape);
reflect.SetAxes(v.x, v.y, v.z, p.x, p.y, p.z, u.x, u.y, u.z);
reflect.Perform();
TopoDS_Shape lines = reflect.GetResult();
TopoDS_Shape lines = reflect.GetCompoundOf3dEdges(t, PyObject_IsTrue(vis) ? Standard_True : Standard_False,
PyObject_IsTrue(in3d) ? Standard_True : Standard_False);
return new TopoShapePy(new TopoShape(lines));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
return nullptr;
}
}