From d4c3f9a264e9e8c2f1cf802c8d7e4398c52761dd Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 25 Feb 2019 10:50:38 +0100 Subject: [PATCH] add method to Python interface to get reflect lines of a shape --- src/Mod/Part/App/TopoShapePy.xml | 8 +++++ src/Mod/Part/App/TopoShapePyImp.cpp | 46 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index 4399528d10..c370745758 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -523,6 +523,14 @@ makePerspectiveProjection(shape, pnt) + + + Build reflect lines on a shape according to the axes of view. +Reflect lines are represented by edges in 3d. +reflectLines(ViewDir, ViewPos, UpDir) -> Shape + + + Make a compound shape out of mesh data. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index dc1deb386e..d23dec348b 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -60,6 +60,7 @@ # include #endif +#include #include #include #include @@ -1973,6 +1974,51 @@ PyObject* TopoShapePy::makePerspectiveProjection(PyObject *args) return 0; } +/*! +from pivy import coin + +rot=Gui.ActiveDocument.ActiveView.getCameraOrientation() +vdir=App.Vector(0,0,-1) +vdir=rot.multVec(vdir) +udir=App.Vector(0,1,0) +udir=rot.multVec(udir) + +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) +Part.show(reflect) + */ +PyObject* TopoShapePy::reflectLines(PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"ViewDir", "ViewPos", "UpDir", NULL}; + + PyObject *pView, *pPos, *pUp; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", kwlist, + &Base::VectorPy::Type, &pView, + &Base::VectorPy::Type, &pPos, + &Base::VectorPy::Type, &pUp)) + return 0; + + try { + 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(); + return new TopoShapePy(new TopoShape(lines)); + } + catch (Standard_Failure& e) { + PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); + return 0; + } +} + PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) { PyObject *tup;