From 1fc5dea14c7977060a1f4c73b688fa8197e4894b Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Tue, 19 Sep 2023 08:18:45 +0200 Subject: [PATCH] TechDraw: Expose two functions for SVG export --- src/Mod/TechDraw/App/AppTechDrawPy.cpp | 36 ++++++++++++++++++++++++ src/Mod/TechDraw/App/ProjectionAlgos.cpp | 22 ++++++++------- src/Mod/TechDraw/App/ProjectionAlgos.h | 2 ++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 9fb36bb843..f24f71a5d3 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -180,6 +180,13 @@ public: "string = removeSvgTags(string) -- Removes the opening and closing svg tags\n" "and other metatags from a svg code, making it embeddable" ); + add_varargs_method("exportSVGEdges", &Module::exportSVGEdges, + "string = exportSVGEdges(TopoShape) -- export an SVG string of the shape\n" + ); + add_varargs_method("build3dCurves", &Module::build3dCurves, + "TopoShape = build3dCurves(TopoShape) -- convert the edges to a 3D curve\n" + "which is useful for shapes obtained Part.HLRBRep.Algo" + ); initialize("This is a module for making drawings"); // register with Python } ~Module() override {} @@ -1224,6 +1231,35 @@ private: return result; } + Py::Object exportSVGEdges(const Py::Tuple& args) + { + PyObject *pcObjShape(nullptr); + + if (!PyArg_ParseTuple(args.ptr(), "O!", + &(TopoShapePy::Type), &pcObjShape)) + throw Py::Exception(); + + TopoShapePy* pShape = static_cast(pcObjShape); + SVGOutput output; + Py::String result(output.exportEdges(pShape->getTopoShapePtr()->getShape())); + + return result; + } + + Py::Object build3dCurves(const Py::Tuple& args) + { + PyObject *pcObjShape(nullptr); + + if (!PyArg_ParseTuple(args.ptr(), "O!", + &(TopoShapePy::Type), &pcObjShape)) + throw Py::Exception(); + + TopoShapePy* pShape = static_cast(pcObjShape); + const TopoShape& nShape = + TechDraw::build3dCurves(pShape->getTopoShapePtr()->getShape()); + + return Py::Object(new TopoShapePy(new TopoShape(nShape))); + } }; PyObject* initModule() diff --git a/src/Mod/TechDraw/App/ProjectionAlgos.cpp b/src/Mod/TechDraw/App/ProjectionAlgos.cpp index 2a6842dc86..cd88254d11 100644 --- a/src/Mod/TechDraw/App/ProjectionAlgos.cpp +++ b/src/Mod/TechDraw/App/ProjectionAlgos.cpp @@ -50,6 +50,18 @@ using namespace std; // ProjectionAlgos //=========================================================================== +namespace TechDraw { + //added by tanderson. aka blobfish. + //projection algorithms build a 2d curve(pcurve) but no 3d curve. + //this causes problems with meshing algorithms after save and load. + const TopoDS_Shape& build3dCurves(const TopoDS_Shape &shape) + { + TopExp_Explorer it; + for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) + BRepLib::BuildCurve3d(TopoDS::Edge(it.Current())); + return shape; + } +} ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input, const Base::Vector3d &Dir) : Input(Input), Direction(Dir) @@ -61,16 +73,6 @@ ProjectionAlgos::~ProjectionAlgos() { } -//added by tanderson. aka blobfish. -//projection algorithms build a 2d curve(pcurve) but no 3d curve. -//this causes problems with meshing algorithms after save and load. -static const TopoDS_Shape& build3dCurves(const TopoDS_Shape &shape) -{ - TopExp_Explorer it; - for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) - BRepLib::BuildCurve3d(TopoDS::Edge(it.Current())); - return shape; -} void ProjectionAlgos::execute() { diff --git a/src/Mod/TechDraw/App/ProjectionAlgos.h b/src/Mod/TechDraw/App/ProjectionAlgos.h index f4e8199fe1..771661e0c8 100644 --- a/src/Mod/TechDraw/App/ProjectionAlgos.h +++ b/src/Mod/TechDraw/App/ProjectionAlgos.h @@ -38,6 +38,8 @@ class BRepAdaptor_Curve; namespace TechDraw { + const TopoDS_Shape& build3dCurves(const TopoDS_Shape& shape); + /** Algo class for projecting shapes and creating SVG output of it */ class TechDrawExport ProjectionAlgos