From f00784f00ebf8e6c7f396338f4505d839c55a922 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 27 Mar 2024 11:13:50 -0400 Subject: [PATCH] Toponaming/Part: move in remaining ifdef methods and the new TopoShapePy methods --- src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp | 58 ++-- src/Mod/Part/App/TopoShapeFacePyImp.cpp | 14 + src/Mod/Part/App/TopoShapePy.xml | 93 +++++++ src/Mod/Part/App/TopoShapePyImp.cpp | 269 +++++++++++++++++-- src/Mod/Part/App/TopoShapeShellPyImp.cpp | 30 ++- src/Mod/Part/App/TopoShapeSolidPyImp.cpp | 19 +- 6 files changed, 438 insertions(+), 45 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp b/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp index cf2f42c20d..201c693441 100644 --- a/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp @@ -29,11 +29,13 @@ #endif #include "OCCError.h" +#include "PartPyCXX.h" // inclusion of the generated files (generated out of TopoShapeCompSolidPy.xml) #include "TopoShapeCompSolidPy.h" #include "TopoShapeCompSolidPy.cpp" #include "TopoShapeSolidPy.h" +#include "TopoShapeOpCode.h" using namespace Part; @@ -61,10 +63,16 @@ int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) } PyErr_Clear(); - PyObject *pcObj; - if (!PyArg_ParseTuple(args, "O", &pcObj)) + PyObject* pcObj; + if (!PyArg_ParseTuple(args, "O", &pcObj)) { return -1; - + } +#ifdef FC_USE_TNP_FIX + try { + getTopoShapePtr()->makeElementBoolean(Part::OpCodes::Compsolid, getPyShapes(pcObj)); + } + _PY_CATCH_OCC(return (-1)) +#else BRep_Builder builder; TopoDS_CompSolid Comp; builder.MakeCompSolid(Comp); @@ -73,10 +81,11 @@ int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) Py::Sequence list(pcObj); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapeSolidPy::Type))) { - const TopoDS_Shape& sh = static_cast((*it).ptr())-> - getTopoShapePtr()->getShape(); - if (!sh.IsNull()) + const TopoDS_Shape& sh = + static_cast((*it).ptr())->getTopoShapePtr()->getShape(); + if (!sh.IsNull()) { builder.Add(Comp, sh); + } } } } @@ -87,35 +96,46 @@ int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) } getTopoShapePtr()->setShape(Comp); +#endif return 0; } -PyObject* TopoShapeCompSolidPy::add(PyObject *args) +PyObject* TopoShapeCompSolidPy::add(PyObject* args) { - PyObject *obj; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj)) + PyObject* obj; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj)) { return nullptr; + } BRep_Builder builder; TopoDS_Shape comp = getTopoShapePtr()->getShape(); + auto shapes = getPyShapes(obj); try { - const TopoDS_Shape& sh = static_cast(obj)-> - getTopoShapePtr()->getShape(); - if (!sh.IsNull()) - builder.Add(comp, sh); - else - Standard_Failure::Raise("Cannot empty shape to compound solid"); + for (auto& ts : shapes) { + if (!ts.isNull()) { + builder.Add(comp, ts.getShape()); + } + else { + Standard_Failure::Raise("Cannot empty shape to compound solid"); + } + } +#ifdef FC_USE_TNP_FIX + auto& self = *getTopoShapePtr(); + shapes.push_back(self); + TopoShape tmp(self.Tag, self.Hasher, comp); + tmp.mapSubElement(shapes); + self = tmp; +#else + getTopoShapePtr()->setShape(comp); +#endif + Py_Return; } catch (Standard_Failure& e) { PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return nullptr; } - - getTopoShapePtr()->setShape(comp); - - Py_Return; } PyObject *TopoShapeCompSolidPy::getCustomAttributes(const char* /*attr*/) const diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index eb452b1092..17621f6105 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -88,6 +88,7 @@ #include "FaceMaker.h" #include "Geometry2d.h" #include "OCCError.h" +#include "PartPyCXX.h" #include "Tools.h" @@ -324,6 +325,9 @@ int TopoShapeFacePy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_Clear(); if (PyArg_ParseTuple(args, "Os", &pcPyShapeOrList, &className)) { try { +#ifdef FC_USE_TNP_FIX + getTopoShapePtr()->makeElementFace(getPyShapes(pcPyShapeOrList),0,className); +#else std::unique_ptr fm = Part::FaceMaker::ConstructFromType(className); //dump all supplied shapes to facemaker, no matter what type (let facemaker decide). @@ -355,6 +359,7 @@ int TopoShapeFacePy::PyInit(PyObject* args, PyObject* /*kwd*/) fm->Build(); getTopoShapePtr()->setShape(fm->Face()); +#endif return 0; } catch (Base::Exception &e) { e.setPyException(); @@ -420,6 +425,10 @@ PyObject* TopoShapeFacePy::addWire(PyObject *args) PyObject* TopoShapeFacePy::makeOffset(PyObject *args) { +#ifdef FC_USE_TNP_FIX + Py::Dict dict; + return TopoShapePy::makeOffset2D(args, dict.ptr()); +#else double dist; if (!PyArg_ParseTuple(args, "d",&dist)) return nullptr; @@ -434,6 +443,7 @@ PyObject* TopoShapeFacePy::makeOffset(PyObject *args) mkOffset.Perform(dist); return new TopoShapePy(new TopoShape(mkOffset.Shape())); +#endif } /* @@ -445,6 +455,9 @@ evolve = spine.makeEvolved(Profile=profile, Join=PartEnums.JoinType.Arc) */ PyObject* TopoShapeFacePy::makeEvolved(PyObject *args, PyObject *kwds) { +#ifdef FC_USE_TNP_FIX + return TopoShapePy::makeEvolved(args, kwds); +#else PyObject* Profile; PyObject* AxeProf = Py_True; PyObject* Solid = Py_False; @@ -496,6 +509,7 @@ PyObject* TopoShapeFacePy::makeEvolved(PyObject *args, PyObject *kwds) PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return nullptr; } +#endif } PyObject* TopoShapeFacePy::valueAt(PyObject *args) diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index 07d9b67d38..ac9485ba69 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -511,6 +511,11 @@ Returns: result of offsetting (wire or face or compound of those). Compounding structure follows that of source shape. + + + Profile along the spine + + make wire(s) using the edges of this shape @@ -820,6 +825,45 @@ countElement(type) -> int + + + + mapSubElement(shape|[shape...], op='') - maps the sub element of other shape + + shape: other shape or sequence of shapes to map the sub-elements + op: optional string prefix to append before the mapped sub element names + + + + + + + mapShapes(generated, modified, op='') + + generate element names with user defined mapping + + generated: a list of tuple(src, dst) that indicating src shape or shapes + generates dst shape or shapes. Note that the dst shape or shapes + must be sub-shapes of this shape. + modified: a list of tuple(src, dst) that indicating src shape or shapes + modifies into dst shape or shapes. Note that the dst shape or + shapes must be sub-shapes of this shape. + op: optional string prefix to append before the mapped sub element names + + + + + + + getElementHistory(name) - returns the element mapped name history + + name: mapped element name belonging to this shape + + Returns tuple(sourceShapeTag, sourceName, [intermediateNames...]), + or None if no history. + + + Determines a tolerance from the ones stored in a shape @@ -906,6 +950,55 @@ optimalBoundingBox([useTriangulation = True, useShapeTolerance = False]) -> boun + + + Clear internal sub-shape cache + + + + + + findSubShape(shape) -> (type_name, index) + + Find sub shape and return the shape type name and index. If not found, + then return (None, 0) + + + + + + + searchSubShape(shape, needName=False, checkGeometry=True, tol=1e-7, atol=1e-12) -> Shape + + shape: input elementary shape, currently only support Face, Edge, or Vertex + + needName: if True, return a list of tuple(name, shape), or else return a list + of shapes. + + checkGeometry: whether to compare geometry + + tol: distance tolerance + + atol: angular tolerance + + Search sub shape by checking vertex coordinates and comparing the underlying + geometries, This can find shapes that are copied. It currently only works with + elementary shapes, Face, Edge, Vertex. + + + + + + + getChildShapes(shapetype, avoidtype='') -> list(Shape) + + Return a list of child sub-shapes of given type. + + shapetype: the type of requesting sub shapes + avoidtype: optional shape type to skip when exploring + + +