Part: Add method Part.Compound.setFaces()

This commit is contained in:
wmayer
2023-09-25 14:45:34 +02:00
committed by wwmayer
parent cdbc778513
commit 563dc0b0cc
2 changed files with 66 additions and 0 deletions

View File

@@ -30,5 +30,10 @@ If Shared is True connection is performed only when adjacent edges share the sa
If Shared is False connection is performed only when ends of adjacent edges are at distance less than Tolerance.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setFaces">
<Documentation>
<UserDocu>A shape is created from points and triangles and set to this object</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -35,6 +35,7 @@
#endif
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
// inclusion of the generated files (generated out of TopoShapeCompoundPy.xml)
#include "TopoShapeCompoundPy.h"
@@ -156,6 +157,66 @@ PyObject* TopoShapeCompoundPy::connectEdgesToWires(PyObject *args)
}
}
PyObject* TopoShapeCompoundPy::setFaces(PyObject *args)
{
using Facet = Data::ComplexGeoData::Facet;
using Point = Base::Vector3d;
std::vector<Point> points;
std::vector<Facet> facets;
PyObject* data{};
double accuracy = 1.0e-06; // NOLINT
if (!PyArg_ParseTuple(args, "O!|d", &PyTuple_Type, &data, &accuracy)) {
return nullptr;
}
Py::Tuple tuple(data);
Py::Sequence pts(tuple.getItem(0));
points.reserve(pts.size());
for (const auto& pt : pts) {
Py::Vector vec(pt);
points.push_back(vec.toVector());
}
std::size_t count = points.size();
auto checkFace = [count](const Facet& face) {
if (face.I1 >= count) {
return false;
}
if (face.I2 >= count) {
return false;
}
if (face.I3 >= count) {
return false;
}
return true;
};
Py::Sequence fts(tuple.getItem(1));
facets.reserve(fts.size());
Facet face;
for (const auto& ft : fts) {
Py::Tuple index(ft);
face.I1 = int32_t(static_cast<int>(Py::Long(index.getItem(0))));
face.I2 = int32_t(static_cast<int>(Py::Long(index.getItem(1))));
face.I3 = int32_t(static_cast<int>(Py::Long(index.getItem(2))));
if (!checkFace(face)) {
PyErr_SetString(PyExc_ValueError, "Point index out of range");
return nullptr;
}
facets.push_back(face);
}
getTopoShapePtr()->setFaces(points, facets, accuracy);
Py_Return;
}
PyObject *TopoShapeCompoundPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;