Py::Object wireFromSegment(const Py::Tuple& args) { PyObject *o, *m; if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o)) throw Py::Exception(); Py::List list(o); Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr(); std::vector<unsigned long> segm; segm.reserve(list.size()); for (unsigned int i=0; i<list.size(); i++) { segm.push_back((int)Py::Int(list[i])); } std::list<std::vector<Base::Vector3f> > bounds; MeshCore::MeshAlgorithm algo(mesh->getKernel()); algo.GetFacetBorders(segm, bounds); Py::List wires; std::list<std::vector<Base::Vector3f> >::iterator bt; for (bt = bounds.begin(); bt != bounds.end(); ++bt) { BRepBuilderAPI_MakePolygon mkPoly; for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); } if (mkPoly.IsDone()) { PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); wires.append(Py::Object(wire, true)); } } return wires; }
static PyObject * wireFromSegment(PyObject *self, PyObject *args) { PyObject *o, *m; if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o)) return 0; Py::List list(o); Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr(); std::vector<unsigned long> segm; segm.reserve(list.size()); for (unsigned int i=0; i<list.size(); i++) { segm.push_back((int)Py::Int(list[i])); } std::list<std::vector<Base::Vector3f> > bounds; MeshCore::MeshAlgorithm algo(mesh->getKernel()); algo.GetFacetBorders(segm, bounds); Py::List wires; std::list<std::vector<Base::Vector3f> >::iterator bt; try { for (bt = bounds.begin(); bt != bounds.end(); ++bt) { BRepBuilderAPI_MakePolygon mkPoly; for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); } if (mkPoly.IsDone()) { PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); wires.append(Py::Object(wire, true)); } } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); return 0; } return Py::new_reference_to(wires); }