Add viewPartAsDxf function in App
This commit is contained in:
@@ -41,14 +41,21 @@
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
#include <Mod/Part/App/TopoShapeEdgePy.h>
|
||||
#include <Mod/Part/App/TopoShapeWirePy.h>
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawingExport.h>
|
||||
|
||||
#include "DrawProjectSplit.h"
|
||||
#include "DrawViewPart.h"
|
||||
#include "DrawViewPartPy.h"
|
||||
#include "GeometryObject.h"
|
||||
#include "EdgeWalker.h"
|
||||
|
||||
|
||||
@@ -61,6 +68,8 @@ using Part::TopoShapePy;
|
||||
using Part::TopoShapeEdgePy;
|
||||
using Part::TopoShapeWirePy;
|
||||
|
||||
using Drawing::DXFOutput;
|
||||
|
||||
namespace TechDraw {
|
||||
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
@@ -77,6 +86,9 @@ public:
|
||||
add_varargs_method("findShapeOutline",&Module::findShapeOutline,
|
||||
"wire = findShapeOutline(shape,scale,direction) -- Project shape in direction and find outer wire of result."
|
||||
);
|
||||
add_varargs_method("viewPartAsDxf",&Module::viewPartAsDxf,
|
||||
"string = viewPartAsDxf(DrawViewPart) -- Return the edges of a DrawViewPart in Dxf format."
|
||||
);
|
||||
initialize("This is a module for making drawings"); // register with Python
|
||||
}
|
||||
virtual ~Module() {}
|
||||
@@ -289,6 +301,62 @@ private:
|
||||
}
|
||||
return Py::asObject(outerWire);
|
||||
}
|
||||
|
||||
Py::Object viewPartAsDxf(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *viewObj;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "O", &viewObj)) {
|
||||
throw Py::Exception("expected (DrawViewPart)");
|
||||
}
|
||||
Py::String dxfReturn;
|
||||
|
||||
try {
|
||||
App::DocumentObject* obj = 0;
|
||||
TechDraw::DrawViewPart* dvp = 0;
|
||||
Drawing::DXFOutput dxfOut;
|
||||
std::string dxfText;
|
||||
std::stringstream ss;
|
||||
if (PyObject_TypeCheck(viewObj, &(TechDraw::DrawViewPartPy::Type))) {
|
||||
obj = static_cast<App::DocumentObjectPy*>(viewObj)->getDocumentObjectPtr();
|
||||
dvp = static_cast<TechDraw::DrawViewPart*>(obj);
|
||||
TechDrawGeometry::GeometryObject* go = dvp->getGeometryObject();
|
||||
TopoDS_Shape s = TechDrawGeometry::mirrorShape(go->getVisHard());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
s = TechDrawGeometry::mirrorShape(go->getVisOutline());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
if (dvp->SmoothVisible.getValue()) {
|
||||
s = TechDrawGeometry::mirrorShape(go->getVisSmooth());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
}
|
||||
if (dvp->SeamVisible.getValue()) {
|
||||
s = TechDrawGeometry::mirrorShape(go->getVisSeam());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
}
|
||||
if (dvp->HardHidden.getValue()) {
|
||||
s = TechDrawGeometry::mirrorShape(go->getHidHard());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
s = TechDrawGeometry::mirrorShape(go->getHidOutline());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
}
|
||||
if (dvp->SmoothHidden.getValue()) {
|
||||
s = TechDrawGeometry::mirrorShape(go->getHidSmooth());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
}
|
||||
if (dvp->SeamHidden.getValue()) {
|
||||
s = TechDrawGeometry::mirrorShape(go->getHidSeam());
|
||||
ss << dxfOut.exportEdges(s);
|
||||
}
|
||||
// ss now contains all edges as Dxf
|
||||
dxfReturn = Py::String(ss.str() + "\n0");
|
||||
}
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError, e.what());
|
||||
}
|
||||
|
||||
return dxfReturn;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
|
||||
@@ -24,6 +24,7 @@ set(TechDrawLIBS
|
||||
Measure
|
||||
Part
|
||||
Spreadsheet
|
||||
Drawing
|
||||
)
|
||||
|
||||
generate_from_xml(DrawPagePy)
|
||||
|
||||
@@ -110,7 +110,9 @@ public:
|
||||
const std::vector<TechDrawGeometry::BaseGeom *> & getEdgeGeometry() const;
|
||||
const std::vector<TechDrawGeometry::BaseGeom *> getVisibleFaceEdges() const;
|
||||
const std::vector<TechDrawGeometry::Face *> & getFaceGeometry() const;
|
||||
|
||||
bool hasGeometry(void) const;
|
||||
TechDrawGeometry::GeometryObject* getGeometryObject(void) const { return geometryObject; }
|
||||
|
||||
TechDrawGeometry::BaseGeom* getProjEdgeByIndex(int idx) const; //get existing geom for edge idx in projection
|
||||
TechDrawGeometry::Vertex* getProjVertexByIndex(int idx) const; //get existing geom for vertex idx in projection
|
||||
|
||||
@@ -537,6 +537,10 @@ TopoDS_Shape TechDrawGeometry::mirrorShape(const TopoDS_Shape &input,
|
||||
double scale)
|
||||
{
|
||||
TopoDS_Shape transShape;
|
||||
if (input.IsNull()) {
|
||||
return transShape;
|
||||
}
|
||||
|
||||
try {
|
||||
// Make tempTransform scale the object around it's centre point and
|
||||
// mirror about the Y axis
|
||||
|
||||
@@ -51,8 +51,8 @@ class Vertex;
|
||||
|
||||
//! scales & mirrors a shape about a center
|
||||
TopoDS_Shape TechDrawExport mirrorShape(const TopoDS_Shape &input,
|
||||
const gp_Pnt& inputCenter,
|
||||
double scale);
|
||||
const gp_Pnt& inputCenter = gp_Pnt(0.0,0.0,0.0),
|
||||
double scale = 1.0);
|
||||
TopoDS_Shape TechDrawExport scaleShape(const TopoDS_Shape &input,
|
||||
double scale);
|
||||
|
||||
@@ -95,6 +95,17 @@ public:
|
||||
void setParentName(std::string n); //for debug messages
|
||||
void pruneVertexGeom(Base::Vector3d center, double radius);
|
||||
|
||||
TopoDS_Shape getVisHard(void) { return visHard; }
|
||||
TopoDS_Shape getVisOutline(void) { return visOutline; }
|
||||
TopoDS_Shape getVisSmooth(void) { return visSmooth; }
|
||||
TopoDS_Shape getVisSeam(void) { return visSeam; }
|
||||
TopoDS_Shape getVisIso(void) { return visIso; }
|
||||
TopoDS_Shape getHidHard(void) { return hidHard; }
|
||||
TopoDS_Shape getHidOutline(void) { return hidOutline; }
|
||||
TopoDS_Shape getHidSmooth(void) { return hidSmooth; }
|
||||
TopoDS_Shape getHidSeam(void) { return hidSeam; }
|
||||
TopoDS_Shape getHidIso(void) { return hidIso; }
|
||||
|
||||
protected:
|
||||
//HLR output
|
||||
TopoDS_Shape visHard;
|
||||
|
||||
@@ -29,12 +29,14 @@
|
||||
// Exporting of App classes
|
||||
#ifdef FC_OS_WIN32
|
||||
# define TechDrawExport __declspec(dllexport)
|
||||
# define PartExport __declspec(dllimport)
|
||||
# define MeasureExport __declspec(dllimport)
|
||||
# define MeshExport __declspec(dllimport)
|
||||
# define DrawingExport __declspec(dllexport)
|
||||
# define PartExport __declspec(dllimport)
|
||||
# define MeasureExport __declspec(dllimport)
|
||||
# define MeshExport __declspec(dllimport)
|
||||
# define SpreadsheetExport __declspec(dllimport)
|
||||
#else // for Linux
|
||||
# define TechDrawExport
|
||||
# define DrawingExport
|
||||
# define MeasureExport
|
||||
# define PartExport
|
||||
# define MeshExport
|
||||
|
||||
Reference in New Issue
Block a user