From 2daf6a03e467c4f8535b06ff894ab269d63db057 Mon Sep 17 00:00:00 2001 From: tomate44 Date: Tue, 6 Apr 2021 18:45:41 +0200 Subject: [PATCH] Part: Shape.ReflectLines: add 2D/3D, visibility and EdgeType options --- src/Mod/Part/App/TopoShapePy.xml | 17 ++++++++-- src/Mod/Part/App/TopoShapePyImp.cpp | 48 +++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index c2fa24ac61..fada5da207 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -673,10 +673,21 @@ makePerspectiveProjection(shape, pnt) -> Shape - Build reflect lines on a shape according to the axes of view. -reflectLines(ViewDir, ViewPos, UpDir) -> Shape + 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. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 3ea305a027..89dc9c5766 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -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; } }