Merge pull request #13196 from bgbsww/bgbsww-toponamingCompSolidPyImp
Toponaming/Part move in PyImps
This commit is contained in:
@@ -95,6 +95,7 @@
|
||||
#include "OCCError.h"
|
||||
#include "PartPyCXX.h"
|
||||
#include "ShapeMapHasher.h"
|
||||
#include "TopoShapeMapper.h"
|
||||
|
||||
|
||||
using namespace Part;
|
||||
@@ -108,20 +109,26 @@ using namespace Part;
|
||||
#endif
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
static Py_hash_t _TopoShapeHash(PyObject *self) {
|
||||
static Py_hash_t _TopoShapeHash(PyObject* self)
|
||||
{
|
||||
if (!self) {
|
||||
PyErr_SetString(PyExc_TypeError, "descriptor 'hash' of 'Part.TopoShape' object needs an argument");
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"descriptor 'hash' of 'Part.TopoShape' object needs an argument");
|
||||
return 0;
|
||||
}
|
||||
if (!static_cast<Base::PyObjectBase*>(self)->isValid()) {
|
||||
PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
|
||||
PyErr_SetString(PyExc_ReferenceError,
|
||||
"This object is already deleted most likely through closing a document. "
|
||||
"This reference is no longer valid!");
|
||||
return 0;
|
||||
}
|
||||
return static_cast<TopoShapePy*>(self)->getTopoShapePtr()->getShape().HashCode(INT_MAX);
|
||||
}
|
||||
|
||||
struct TopoShapePyInit {
|
||||
TopoShapePyInit() {
|
||||
struct TopoShapePyInit
|
||||
{
|
||||
TopoShapePyInit()
|
||||
{
|
||||
TopoShapePy::Type.tp_hash = _TopoShapeHash;
|
||||
}
|
||||
} _TopoShapePyInit;
|
||||
@@ -192,6 +199,7 @@ int TopoShapePy::PyInit(PyObject* args, PyObject* keywds)
|
||||
}
|
||||
_PY_CATCH_OCC(return (-1))
|
||||
#else
|
||||
(void) keywds;
|
||||
PyObject* pcObj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|O", &pcObj)) {
|
||||
return -1;
|
||||
@@ -236,6 +244,35 @@ PyObject* TopoShapePy::copy(PyObject *args)
|
||||
{
|
||||
PyObject* copyGeom = Py_True;
|
||||
PyObject* copyMesh = Py_False;
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
const char* op = nullptr;
|
||||
PyObject* pyHasher = nullptr;
|
||||
if (!PyArg_ParseTuple(args,
|
||||
"|sO!O!O!",
|
||||
&op,
|
||||
&App::StringHasherPy::Type,
|
||||
&pyHasher,
|
||||
&PyBool_Type,
|
||||
©Geom,
|
||||
&PyBool_Type,
|
||||
©Mesh)) {
|
||||
PyErr_Clear();
|
||||
if (!PyArg_ParseTuple(args, "|O!O!", &PyBool_Type, ©Geom, &PyBool_Type, ©Mesh)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (op && !op[0]) {
|
||||
op = nullptr;
|
||||
}
|
||||
App::StringHasherRef hasher;
|
||||
if (pyHasher) {
|
||||
hasher = static_cast<App::StringHasherPy*>(pyHasher)->getStringHasherPtr();
|
||||
}
|
||||
auto& self = *getTopoShapePtr();
|
||||
return Py::new_reference_to(shape2pyshape(
|
||||
TopoShape(self.Tag, hasher)
|
||||
.makeElementCopy(self, op, PyObject_IsTrue(copyGeom), PyObject_IsTrue(copyMesh))));
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "|O!O!", &PyBool_Type, ©Geom, &PyBool_Type, ©Mesh))
|
||||
return nullptr;
|
||||
|
||||
@@ -255,12 +292,21 @@ PyObject* TopoShapePy::copy(PyObject *args)
|
||||
static_cast<TopoShapePy*>(cpy)->getTopoShapePtr()->setShape(c.Shape());
|
||||
}
|
||||
return cpy;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::cleaned(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
auto& self = *getTopoShapePtr();
|
||||
TopoShape copy(self.makeElementCopy());
|
||||
if (!copy.isNull()) {
|
||||
BRepTools::Clean(copy.getShape()); // remove triangulation
|
||||
}
|
||||
return Py::new_reference_to(shape2pyshape(copy));
|
||||
#else
|
||||
|
||||
const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape();
|
||||
PyTypeObject* type = this->GetType();
|
||||
@@ -280,6 +326,7 @@ PyObject* TopoShapePy::cleaned(PyObject *args)
|
||||
static_cast<TopoShapePy*>(cpy)->getTopoShapePtr()->setShape(c.Shape());
|
||||
}
|
||||
return cpy;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::replaceShape(PyObject *args)
|
||||
@@ -289,6 +336,18 @@ PyObject* TopoShapePy::replaceShape(PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
Py::Sequence list(l);
|
||||
std::vector<std::pair<TopoShape, TopoShape>> shapes;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Tuple tuple(*it);
|
||||
Py::TopoShape sh1(tuple[0]);
|
||||
Py::TopoShape sh2(tuple[1]);
|
||||
shapes.push_back(std::make_pair(*sh1.extensionObject()->getTopoShapePtr(),
|
||||
*sh2.extensionObject()->getTopoShapePtr()));
|
||||
}
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->replaceElementShape(shapes)));
|
||||
#else
|
||||
Py::Sequence list(l);
|
||||
std::vector< std::pair<TopoDS_Shape, TopoDS_Shape> > shapes;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
@@ -305,6 +364,7 @@ PyObject* TopoShapePy::replaceShape(PyObject *args)
|
||||
static_cast<TopoShapePy*>(inst)->getTopoShapePtr()->setShape
|
||||
(this->getTopoShapePtr()->replaceShape(shapes));
|
||||
return inst;
|
||||
#endif
|
||||
}
|
||||
catch (const Py::Exception&) {
|
||||
return nullptr;
|
||||
@@ -322,6 +382,10 @@ PyObject* TopoShapePy::removeShape(PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(
|
||||
shape2pyshape(getTopoShapePtr()->removeElementShape(getPyShapes(l))));
|
||||
#else
|
||||
Py::Sequence list(l);
|
||||
std::vector<TopoDS_Shape> shapes;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
@@ -333,6 +397,7 @@ PyObject* TopoShapePy::removeShape(PyObject *args)
|
||||
static_cast<TopoShapePy*>(inst)->getTopoShapePtr()->setShape
|
||||
(this->getTopoShapePtr()->removeShape(shapes));
|
||||
return inst;
|
||||
#endif
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(PartExceptionOCCError, "failed to remove shape");
|
||||
@@ -681,6 +746,10 @@ PyObject* TopoShapePy::extrude(PyObject *args)
|
||||
|
||||
try {
|
||||
Base::Vector3d vec = static_cast<Base::VectorPy*>(pVec)->value();
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(
|
||||
shape2pyshape(getTopoShapePtr()->makeElementPrism(gp_Vec(vec.x, vec.y, vec.z))));
|
||||
#else
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->makePrism(gp_Vec(vec.x,vec.y,vec.z));
|
||||
TopAbs_ShapeEnum type = shape.ShapeType();
|
||||
switch (type) {
|
||||
@@ -708,6 +777,7 @@ PyObject* TopoShapePy::extrude(PyObject *args)
|
||||
|
||||
PyErr_SetString(PartExceptionOCCError, "extrusion for this shape type not supported");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -721,8 +791,14 @@ PyObject* TopoShapePy::revolve(PyObject *args)
|
||||
double d=360;
|
||||
if (!PyArg_ParseTuple(args, "O!O!|d", &(Base::VectorPy::Type), &pPos, &(Base::VectorPy::Type), &pDir,&d))
|
||||
return nullptr;
|
||||
|
||||
Base::Vector3d pos = static_cast<Base::VectorPy*>(pPos)->value();
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementRevolve(
|
||||
gp_Ax1(gp_Pnt(pos.x, pos.y, pos.z), gp_Dir(dir.x, dir.y, dir.z)),
|
||||
d * (M_PI / 180))));
|
||||
#else
|
||||
const TopoDS_Shape& input = this->getTopoShapePtr()->getShape();
|
||||
if (input.IsNull()) {
|
||||
PyErr_SetString(PartExceptionOCCError, "empty shape cannot be revolved");
|
||||
@@ -741,8 +817,6 @@ PyObject* TopoShapePy::revolve(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Vector3d pos = static_cast<Base::VectorPy*>(pPos)->value();
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->revolve(
|
||||
gp_Ax1(gp_Pnt(pos.x,pos.y,pos.z), gp_Dir(dir.x,dir.y,dir.z)),d*(M_PI/180));
|
||||
TopAbs_ShapeEnum type = shape.ShapeType();
|
||||
@@ -772,6 +846,7 @@ PyObject* TopoShapePy::revolve(PyObject *args)
|
||||
|
||||
PyErr_SetString(PartExceptionOCCError, "revolution for this shape type not supported");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -796,8 +871,26 @@ PyObject* TopoShapePy::check(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
static PyObject *makeShape(const char *op,const TopoShape &shape, PyObject *args) {
|
||||
double tol=0;
|
||||
PyObject *pcObj;
|
||||
if (!PyArg_ParseTuple(args, "O|d", &pcObj,&tol))
|
||||
return 0;
|
||||
PY_TRY {
|
||||
std::vector<TopoShape> shapes;
|
||||
shapes.push_back(shape);
|
||||
getPyShapes(pcObj,shapes);
|
||||
return Py::new_reference_to(shape2pyshape(TopoShape().makeElementBoolean(op,shapes,0,tol)));
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject* TopoShapePy::fuse(PyObject *args)
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return makeShape(Part::OpCodes::Fuse, *getTopoShapePtr(), args);
|
||||
#else
|
||||
PyObject *pcObj;
|
||||
if (PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &pcObj)) {
|
||||
TopoDS_Shape shape = static_cast<TopoShapePy*>(pcObj)->getTopoShapePtr()->getShape();
|
||||
@@ -867,10 +960,14 @@ PyObject* TopoShapePy::fuse(PyObject *args)
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "shape or sequence of shape expected");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::multiFuse(PyObject *args)
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return makeShape(Part::OpCodes::Fuse, *getTopoShapePtr(), args);
|
||||
#else
|
||||
double tolerance = 0.0;
|
||||
PyObject *pcObj;
|
||||
if (!PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance))
|
||||
@@ -900,6 +997,7 @@ PyObject* TopoShapePy::multiFuse(PyObject *args)
|
||||
PyErr_SetString(PartExceptionOCCError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::oldFuse(PyObject *args)
|
||||
@@ -926,6 +1024,9 @@ PyObject* TopoShapePy::oldFuse(PyObject *args)
|
||||
|
||||
PyObject* TopoShapePy::common(PyObject *args)
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return makeShape(Part::OpCodes::Common, *getTopoShapePtr(), args);
|
||||
#else
|
||||
PyObject *pcObj;
|
||||
if (PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &pcObj)) {
|
||||
TopoDS_Shape shape = static_cast<TopoShapePy*>(pcObj)->getTopoShapePtr()->getShape();
|
||||
@@ -993,10 +1094,14 @@ PyObject* TopoShapePy::common(PyObject *args)
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "shape or sequence of shape expected");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::section(PyObject *args)
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return makeShape(Part::OpCodes::Section, *getTopoShapePtr(), args);
|
||||
#else
|
||||
PyObject *pcObj;
|
||||
PyObject *approx = Py_False;
|
||||
if (PyArg_ParseTuple(args, "O!|O!", &(TopoShapePy::Type), &pcObj, &(PyBool_Type), &approx)) {
|
||||
@@ -1065,6 +1170,7 @@ PyObject* TopoShapePy::section(PyObject *args)
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "shape or sequence of shape expected");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::slice(PyObject *args)
|
||||
@@ -1074,8 +1180,16 @@ PyObject* TopoShapePy::slice(PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O!d", &(Base::VectorPy::Type), &dir, &d))
|
||||
return nullptr;
|
||||
|
||||
Base::Vector3d vec = Py::Vector(dir, false).toVector();
|
||||
|
||||
try {
|
||||
Base::Vector3d vec = Py::Vector(dir, false).toVector();
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
Py::List wires;
|
||||
for (auto& w : getTopoShapePtr()->makeElementSlice(vec, d).getSubTopoShapes(TopAbs_WIRE)) {
|
||||
wires.append(shape2pyshape(w));
|
||||
}
|
||||
return Py::new_reference_to(wires);
|
||||
#else
|
||||
std::list<TopoDS_Wire> slice = this->getTopoShapePtr()->slice(vec, d);
|
||||
Py::List wire;
|
||||
for (const auto & it : slice) {
|
||||
@@ -1083,6 +1197,7 @@ PyObject* TopoShapePy::slice(PyObject *args)
|
||||
}
|
||||
|
||||
return Py::new_reference_to(wire);
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
|
||||
@@ -1108,8 +1223,12 @@ PyObject* TopoShapePy::slices(PyObject *args)
|
||||
d.reserve(list.size());
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it)
|
||||
d.push_back((double)Py::Float(*it));
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementSlices(vec, d)));
|
||||
#else
|
||||
TopoDS_Compound slice = this->getTopoShapePtr()->slices(vec, d);
|
||||
return new TopoShapeCompoundPy(new TopoShape(slice));
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -1123,6 +1242,9 @@ PyObject* TopoShapePy::slices(PyObject *args)
|
||||
|
||||
PyObject* TopoShapePy::cut(PyObject *args)
|
||||
{
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return makeShape(Part::OpCodes::Cut, *getTopoShapePtr(), args);
|
||||
#else
|
||||
PyObject *pcObj;
|
||||
if (PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &pcObj)) {
|
||||
TopoDS_Shape shape = static_cast<TopoShapePy*>(pcObj)->getTopoShapePtr()->getShape();
|
||||
@@ -1190,6 +1312,7 @@ PyObject* TopoShapePy::cut(PyObject *args)
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "shape or sequence of shape expected");
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::generalFuse(PyObject *args)
|
||||
@@ -1199,6 +1322,29 @@ PyObject* TopoShapePy::generalFuse(PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance))
|
||||
return nullptr;
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
std::vector<std::vector<TopoShape>> modifies;
|
||||
std::vector<TopoShape> shapes;
|
||||
shapes.push_back(*getTopoShapePtr());
|
||||
try {
|
||||
getPyShapes(pcObj, shapes);
|
||||
TopoShape res;
|
||||
res.makeElementGeneralFuse(shapes, modifies, tolerance);
|
||||
Py::List mapPy;
|
||||
for (auto& mod : modifies) {
|
||||
Py::List shapesPy;
|
||||
for (auto& sh : mod) {
|
||||
shapesPy.append(shape2pyshape(sh));
|
||||
}
|
||||
mapPy.append(shapesPy);
|
||||
}
|
||||
Py::Tuple ret(2);
|
||||
ret[0] = shape2pyshape(res);
|
||||
ret[1] = mapPy;
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
#else
|
||||
std::vector<TopoDS_Shape> shapeVec;
|
||||
Py::Sequence shapeSeq(pcObj);
|
||||
for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) {
|
||||
@@ -1236,6 +1382,7 @@ PyObject* TopoShapePy::generalFuse(PyObject *args)
|
||||
PyErr_SetString(PartExceptionOCCError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::sewShape(PyObject *args)
|
||||
@@ -1261,6 +1408,24 @@ PyObject* TopoShapePy::childShapes(PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "|O!O!", &(PyBool_Type), &cumOri, &(PyBool_Type), &cumLoc))
|
||||
return nullptr;
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
TopoShape shape = *getTopoShapePtr();
|
||||
if (!PyObject_IsTrue(cumOri)) {
|
||||
shape.setShape(shape.getShape().Oriented(TopAbs_FORWARD), false);
|
||||
}
|
||||
if (!PyObject_IsTrue(cumLoc)) {
|
||||
shape.setShape(shape.getShape().Located(TopLoc_Location()), false);
|
||||
}
|
||||
Py::List list;
|
||||
PY_TRY
|
||||
{
|
||||
for (auto& s : shape.getSubTopoShapes()) {
|
||||
list.append(shape2pyshape(s));
|
||||
}
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
#else
|
||||
try {
|
||||
const TopoDS_Shape& shape = getTopoShapePtr()->getShape();
|
||||
if (shape.IsNull()) {
|
||||
@@ -1316,6 +1481,7 @@ PyObject* TopoShapePy::childShapes(PyObject *args)
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace Part {
|
||||
@@ -1423,8 +1589,12 @@ PyObject* TopoShapePy::mirror(PyObject *args)
|
||||
|
||||
try {
|
||||
gp_Ax2 ax2(gp_Pnt(base.x,base.y,base.z), gp_Dir(norm.x,norm.y,norm.z));
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementMirror(ax2)));
|
||||
#else
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->mirror(ax2);
|
||||
return new TopoShapePy(new TopoShape(shape));
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -1575,7 +1745,12 @@ PyObject* TopoShapePy::scale(PyObject *args)
|
||||
BRepBuilderAPI_Transform BRepScale(scl);
|
||||
bool bCopy = true;
|
||||
BRepScale.Perform(shape, bCopy);
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
TopoShape copy(*getTopoShapePtr());
|
||||
getTopoShapePtr()->makeElementShape(BRepScale, copy);
|
||||
#else
|
||||
getTopoShapePtr()->setShape(BRepScale.Shape());
|
||||
#endif
|
||||
}
|
||||
return IncRef();
|
||||
}
|
||||
@@ -1605,6 +1780,25 @@ PyObject* TopoShapePy::makeFillet(PyObject *args)
|
||||
// use two radii for all edges
|
||||
double radius1, radius2;
|
||||
PyObject *obj;
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
if (!PyArg_ParseTuple(args, "ddO", &radius1, &radius2, &obj)) {
|
||||
PyErr_Clear();
|
||||
if (!PyArg_ParseTuple(args, "dO", &radius1, &obj)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"This method accepts:\n"
|
||||
"-- one radius and a list of edges\n"
|
||||
"-- two radii and a list of edges");
|
||||
return 0;
|
||||
}
|
||||
radius2 = radius1;
|
||||
}
|
||||
PY_TRY
|
||||
{
|
||||
return Py::new_reference_to(shape2pyshape(
|
||||
getTopoShapePtr()->makeElementFillet(getPyShapes(obj), radius1, radius2)));
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
#else
|
||||
if (PyArg_ParseTuple(args, "ddO", &radius1, &radius2, &obj)) {
|
||||
try {
|
||||
const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape();
|
||||
@@ -1626,7 +1820,7 @@ PyObject* TopoShapePy::makeFillet(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
PyErr_Clear();
|
||||
// use one radius for all edges
|
||||
double radius;
|
||||
@@ -1663,6 +1857,26 @@ PyObject* TopoShapePy::makeChamfer(PyObject *args)
|
||||
// use two radii for all edges
|
||||
double radius1, radius2;
|
||||
PyObject *obj;
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
if (!PyArg_ParseTuple(args, "ddO", &radius1, &radius2, &obj)) {
|
||||
if (!PyArg_ParseTuple(args, "dO", &radius1, &obj)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"This method accepts:\n"
|
||||
"-- one radius and a list of edges\n"
|
||||
"-- two radii and a list of edges");
|
||||
return 0;
|
||||
}
|
||||
PyErr_Clear();
|
||||
radius2 = radius1;
|
||||
}
|
||||
PY_TRY
|
||||
{
|
||||
return Py::new_reference_to(shape2pyshape(
|
||||
getTopoShapePtr()->makeElementChamfer(getPyShapes(obj), radius1, radius2)));
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
#else
|
||||
|
||||
if (PyArg_ParseTuple(args, "ddO", &radius1, &radius2, &obj)) {
|
||||
try {
|
||||
const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape();
|
||||
@@ -1689,7 +1903,7 @@ PyObject* TopoShapePy::makeChamfer(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
PyErr_Clear();
|
||||
// use one radius for all edges
|
||||
double radius;
|
||||
@@ -1738,6 +1952,16 @@ PyObject* TopoShapePy::makeThickness(PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(
|
||||
getTopoShapePtr()->makeElementThickSolid(getPyShapes(obj),
|
||||
offset,
|
||||
tolerance,
|
||||
PyObject_IsTrue(inter) ? true : false,
|
||||
PyObject_IsTrue(self_inter) ? true : false,
|
||||
offsetMode,
|
||||
static_cast<JoinType>(join))));
|
||||
#else
|
||||
TopTools_ListOfShape facesToRemove;
|
||||
Py::Sequence list(obj);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
@@ -1750,6 +1974,7 @@ PyObject* TopoShapePy::makeThickness(PyObject *args)
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->makeThickSolid(facesToRemove, offset, tolerance,
|
||||
Base::asBoolean(inter), Base::asBoolean(self_inter), offsetMode, join);
|
||||
return new TopoShapeSolidPy(new TopoShape(shape));
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -1773,11 +1998,22 @@ PyObject* TopoShapePy::makeOffsetShape(PyObject *args, PyObject *keywds)
|
||||
}
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementOffset(
|
||||
offset,
|
||||
tolerance,
|
||||
PyObject_IsTrue(inter) ? true : false,
|
||||
PyObject_IsTrue(self_inter) ? true : false,
|
||||
offsetMode,
|
||||
static_cast<JoinType>(join),
|
||||
PyObject_IsTrue(fill) ? FillType::fill : FillType::noFill)));
|
||||
#else
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->makeOffsetShape(offset, tolerance,
|
||||
Base::asBoolean(inter),
|
||||
Base::asBoolean(self_inter), offsetMode, join,
|
||||
Base::asBoolean(fill));
|
||||
return new TopoShapePy(new TopoShape(shape));
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -1800,9 +2036,18 @@ PyObject* TopoShapePy::makeOffset2D(PyObject *args, PyObject *keywds)
|
||||
}
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementOffset2D(
|
||||
offset,
|
||||
static_cast<JoinType>(join),
|
||||
PyObject_IsTrue(fill) ? FillType::fill : FillType::noFill,
|
||||
PyObject_IsTrue(openResult) ? OpenResult::allowOpenResult : OpenResult::noOpenResult,
|
||||
PyObject_IsTrue(inter) ? true : false)));
|
||||
#else
|
||||
TopoDS_Shape resultShape = this->getTopoShapePtr()->makeOffset2D(offset, join,
|
||||
Base::asBoolean(fill), Base::asBoolean(openResult), Base::asBoolean(inter));
|
||||
return new_reference_to(shape2pyshape(resultShape));
|
||||
#endif
|
||||
}
|
||||
PY_CATCH_OCC;
|
||||
}
|
||||
@@ -2217,6 +2462,32 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args)
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::makeEvolved(PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject* Profile;
|
||||
PyObject* AxeProf = Py_True;
|
||||
PyObject* Solid = Py_False;
|
||||
PyObject* ProfOnSpine = Py_False;
|
||||
auto JoinType = JoinType::arc;
|
||||
double Tolerance = 0.0000001;
|
||||
|
||||
static char* kwds_evolve[] = {"Profile", "Join", "AxeProf", "Solid", "ProfOnSpine", "Tolerance", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|iO!O!O!d", kwds_evolve,
|
||||
&TopoShapePy::Type, &Profile, &JoinType,
|
||||
&PyBool_Type, &AxeProf, &PyBool_Type, &Solid,
|
||||
&PyBool_Type, &ProfOnSpine, &Tolerance))
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementEvolve(
|
||||
*static_cast<TopoShapePy*>(Profile)->getTopoShapePtr(), JoinType,
|
||||
PyObject_IsTrue(AxeProf) ? CoordinateSystem::global : CoordinateSystem::relativeToSpine,
|
||||
PyObject_IsTrue(Solid) ? MakeSolid::makeSolid : MakeSolid::noSolid,
|
||||
PyObject_IsTrue(ProfOnSpine) ? Spine::on : Spine::notOn,
|
||||
Tolerance)));
|
||||
} PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::makeWires(PyObject *args) {
|
||||
const char *op = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s", &op))
|
||||
@@ -2304,9 +2575,13 @@ PyObject* TopoShapePy::removeSplitter(PyObject *args)
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementRefine()));
|
||||
#else
|
||||
// Remove redundant splitter
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->removeSplitter();
|
||||
return new TopoShapePy(new TopoShape(shape));
|
||||
#endif
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
|
||||
@@ -2779,6 +3054,15 @@ PyObject* TopoShapePy::optimalBoundingBox(PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::clearCache(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return 0;
|
||||
}
|
||||
getTopoShapePtr()->initCache(1);
|
||||
return IncRef();
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::defeaturing(PyObject *args)
|
||||
{
|
||||
PyObject *l;
|
||||
@@ -2806,6 +3090,88 @@ PyObject* TopoShapePy::defeaturing(PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::findSubShape(PyObject* args)
|
||||
{
|
||||
PyObject* pyobj;
|
||||
if (!PyArg_ParseTuple(args, "O", &pyobj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
Py::List res;
|
||||
for (auto& s : getPyShapes(pyobj)) {
|
||||
int index = getTopoShapePtr()->findShape(s.getShape());
|
||||
if (index > 0) {
|
||||
res.append(Py::TupleN(Py::String(s.shapeName()), Py::Int(index)));
|
||||
}
|
||||
else {
|
||||
res.append(Py::TupleN(Py::Object(), Py::Int(0)));
|
||||
}
|
||||
}
|
||||
if (PySequence_Check(pyobj)) {
|
||||
return Py::new_reference_to(res);
|
||||
}
|
||||
return Py::new_reference_to(Py::Object(res[0].ptr()));
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::findSubShapesWithSharedVertex(PyObject* args, PyObject* keywds)
|
||||
{
|
||||
static char* kwlist[] = {"shape", "needName", "checkGeometry", "tol", "atol", nullptr};
|
||||
PyObject* pyobj;
|
||||
PyObject* needName = Py_False;
|
||||
PyObject* checkGeometry = Py_True;
|
||||
double tol = 1e-7;
|
||||
double atol = 1e-12;
|
||||
if (!PyArg_ParseTupleAndKeywords(args,
|
||||
keywds,
|
||||
"O!|OOdd",
|
||||
kwlist,
|
||||
&Type,
|
||||
&pyobj,
|
||||
&needName,
|
||||
&checkGeometry,
|
||||
&tol,
|
||||
&atol)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
Py::List res;
|
||||
const TopoShape& shape = *static_cast<TopoShapePy*>(pyobj)->getTopoShapePtr();
|
||||
if (PyObject_IsTrue(needName)) {
|
||||
std::vector<std::string> names;
|
||||
auto shapes = getTopoShapePtr()->findSubShapesWithSharedVertex(
|
||||
shape,
|
||||
&names,
|
||||
PyObject_IsTrue(checkGeometry) ? CheckGeometry::checkGeometry
|
||||
: CheckGeometry::ignoreGeometry,
|
||||
tol,
|
||||
atol);
|
||||
for (std::size_t i = 0; i < shapes.size(); ++i) {
|
||||
res.append(Py::TupleN(Py::String(names[i]), shape2pyshape(shapes[i])));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (auto& s : getTopoShapePtr()->findSubShapesWithSharedVertex(
|
||||
shape,
|
||||
nullptr,
|
||||
PyObject_IsTrue(checkGeometry) ? CheckGeometry::checkGeometry
|
||||
: CheckGeometry::ignoreGeometry,
|
||||
tol,
|
||||
atol)) {
|
||||
res.append(shape2pyshape(s));
|
||||
}
|
||||
}
|
||||
return Py::new_reference_to(res);
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
// End of Methods, Start of Attributes
|
||||
|
||||
Py::String TopoShapePy::getShapeType() const
|
||||
{
|
||||
@@ -2912,23 +3278,23 @@ getElements(const TopoShape& sh, TopAbs_ShapeEnum type, TopAbs_ShapeEnum avoid =
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Todo: Toponaming Project March, 2024: This code is defined, appears to be correct, but
|
||||
// is not clearly in use, thus commented out:
|
||||
//
|
||||
//PyObject *TopoShapePy::getChildShapes(PyObject *args)
|
||||
//{
|
||||
// const char *type;
|
||||
// const char *avoid = nullptr;
|
||||
// if (!PyArg_ParseTuple(args, "s|s", &type, &avoid))
|
||||
// return nullptr;
|
||||
//
|
||||
// PY_TRY {
|
||||
// return Py::new_reference_to(
|
||||
// getElements(*getTopoShapePtr(),
|
||||
// TopoShape::shapeType(type),
|
||||
// avoid && avoid[0] ? TopoShape::shapeType(avoid) : TopAbs_SHAPE));
|
||||
// }PY_CATCH_OCC;
|
||||
//}
|
||||
PyObject* TopoShapePy::getChildShapes(PyObject* args)
|
||||
{
|
||||
const char* type;
|
||||
const char* avoid = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s|s", &type, &avoid)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY
|
||||
{
|
||||
return Py::new_reference_to(
|
||||
getElements(*getTopoShapePtr(),
|
||||
TopoShape::shapeType(type),
|
||||
avoid && avoid[0] ? TopoShape::shapeType(avoid) : TopAbs_SHAPE));
|
||||
}
|
||||
PY_CATCH_OCC;
|
||||
}
|
||||
|
||||
Py::List TopoShapePy::getSubShapes() const
|
||||
{
|
||||
@@ -3005,14 +3371,121 @@ Py::Float TopoShapePy::getVolume() const
|
||||
return Py::Float(props.Mass());
|
||||
}
|
||||
|
||||
PyObject *TopoShapePy::getCustomAttributes(const char* attr) const
|
||||
PyObject* TopoShapePy::getElementHistory(PyObject* args)
|
||||
{
|
||||
if (!attr)
|
||||
const char* pyname;
|
||||
if (!PyArg_ParseTuple(args, "s", &pyname)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Data::MappedName name(pyname);
|
||||
PY_TRY
|
||||
{
|
||||
Data::MappedName original;
|
||||
std::vector<Data::MappedName> history;
|
||||
long tag = getTopoShapePtr()->getElementHistory(name, &original, &history);
|
||||
if (!tag) {
|
||||
Py_Return;
|
||||
}
|
||||
Py::Tuple ret(3);
|
||||
ret.setItem(0, Py::Int(tag));
|
||||
std::string tmp;
|
||||
ret.setItem(1, Py::String(original.appendToBuffer(tmp)));
|
||||
Py::List pyHistory;
|
||||
for (auto& h : history) {
|
||||
tmp.clear();
|
||||
pyHistory.append(Py::String(h.appendToBuffer(tmp)));
|
||||
}
|
||||
ret.setItem(2, pyHistory);
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
struct PyShapeMapper: Part::ShapeMapper
|
||||
{
|
||||
bool populate(MappingStatus status, PyObject* pyobj)
|
||||
{
|
||||
if (!pyobj || pyobj == Py_None) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Py::Sequence seq(pyobj);
|
||||
for (size_t i = 0, count = seq.size(); i < count; ++i) {
|
||||
Py::Sequence item(seq[i].ptr());
|
||||
if (item.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Part::ShapeMapper::populate(status,
|
||||
getPyShapes(item[0].ptr()),
|
||||
getPyShapes(item[1].ptr()));
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
PyErr_Clear();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void init(PyObject* g, PyObject* m)
|
||||
{
|
||||
const char* msg =
|
||||
"Expect input mapping to be a list of tuple(srcShape|shapeList, dstShape|shapeList)";
|
||||
if (!populate(MappingStatus::Generated, g) || !populate(MappingStatus::Modified, m)) {
|
||||
throw Py::TypeError(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PyObject* TopoShapePy::mapShapes(PyObject* args)
|
||||
{
|
||||
PyObject* generated;
|
||||
PyObject* modified;
|
||||
const char* op = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "OO|s", &generated, &modified, &op)) {
|
||||
return 0;
|
||||
}
|
||||
PY_TRY
|
||||
{
|
||||
PyShapeMapper mapper;
|
||||
mapper.init(generated, modified);
|
||||
TopoShape& self = *getTopoShapePtr();
|
||||
TopoShape s(self.Tag, self.Hasher);
|
||||
s.makeShapeWithElementMap(self.getShape(), mapper, mapper.shapes, op);
|
||||
self = s;
|
||||
return IncRef();
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::mapSubElement(PyObject* args)
|
||||
{
|
||||
const char* op = nullptr;
|
||||
PyObject* sh;
|
||||
if (!PyArg_ParseTuple(args, "O|s", &sh, &op)) {
|
||||
return 0;
|
||||
}
|
||||
PY_TRY
|
||||
{
|
||||
getTopoShapePtr()->mapSubElement(getPyShapes(sh), op);
|
||||
return IncRef();
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
}
|
||||
|
||||
PyObject* TopoShapePy::getCustomAttributes(const char* attr) const
|
||||
{
|
||||
if (!attr) {
|
||||
return nullptr;
|
||||
PY_TRY {
|
||||
TopoDS_Shape res = getTopoShapePtr()->getSubShape(attr,true);
|
||||
if (!res.IsNull())
|
||||
}
|
||||
PY_TRY
|
||||
{
|
||||
TopoDS_Shape res = getTopoShapePtr()->getSubShape(attr, true);
|
||||
if (!res.IsNull()) {
|
||||
return Py::new_reference_to(shape2pyshape(res));
|
||||
}
|
||||
}
|
||||
PY_CATCH_OCC
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user