Create outline of 3D shape
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
@@ -46,8 +48,10 @@
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
|
||||
#include "DrawProjectSplit.h"
|
||||
#include "EdgeWalker.h"
|
||||
|
||||
|
||||
namespace TechDraw {
|
||||
//module level static C++ functions go here
|
||||
}
|
||||
@@ -70,6 +74,9 @@ public:
|
||||
add_varargs_method("findOuterWire",&Module::findOuterWire,
|
||||
"wire = findOuterWire(edgeList) -- Planar graph traversal finds OuterWire in edge pile."
|
||||
);
|
||||
add_varargs_method("findShapeOutline",&Module::findShapeOutline,
|
||||
"wire = findShapeOutline(shape,scale,direction) -- Project shape in direction and find outer wire of result."
|
||||
);
|
||||
initialize("This is a module for making drawings"); // register with Python
|
||||
}
|
||||
virtual ~Module() {}
|
||||
@@ -219,6 +226,62 @@ private:
|
||||
}
|
||||
return Py::asObject(outerWire);
|
||||
}
|
||||
|
||||
Py::Object findShapeOutline(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *pcObjShape;
|
||||
double scale;
|
||||
PyObject *pcObjDir;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "OdO", &pcObjShape,
|
||||
&scale,
|
||||
&pcObjDir)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
if (!pShape) {
|
||||
Base::Console().Message("TRACE - AATDP::findShapeOutline - input shape is null\n");
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
const TopoDS_Shape& shape = pShape->getTopoShapePtr()->getShape();
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(pcObjDir)->value();
|
||||
std::vector<TopoDS_Edge> edgeList;
|
||||
try {
|
||||
edgeList = DrawProjectSplit::getEdgesForWalker(shape,scale,dir);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Py::Exception(Part::PartExceptionOCCError, e->GetMessageString());
|
||||
}
|
||||
|
||||
if (edgeList.empty()) {
|
||||
Base::Console().Log("LOG - ATDP::findShapeOutline: input is empty\n");
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
PyObject* outerWire = nullptr;
|
||||
bool success = false;
|
||||
try {
|
||||
EdgeWalker ew;
|
||||
ew.loadEdges(edgeList);
|
||||
success = ew.perform();
|
||||
if (success) {
|
||||
std::vector<TopoDS_Wire> rw = ew.getResultNoDups();
|
||||
std::vector<TopoDS_Wire> sortedWires = ew.sortStrip(rw,true);
|
||||
outerWire = new TopoShapeWirePy(new TopoShape(*sortedWires.begin()));
|
||||
} else {
|
||||
Base::Console().Warning("ATDP::findShapeOutline: input is not planar graph. Wire detection not done\n");
|
||||
}
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError, e.what());
|
||||
}
|
||||
if (!success) {
|
||||
return Py::None();
|
||||
}
|
||||
return Py::asObject(outerWire);
|
||||
}
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
|
||||
Reference in New Issue
Block a user