From 6f61c21e3c80a206526a393d0d64a9c78946a461 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 15 May 2018 19:50:59 -0400 Subject: [PATCH] export TD Annotation to Dxf --- src/Mod/Import/App/ImpExpDxf.cpp | 14 +++++++++ src/Mod/Import/App/ImpExpDxf.h | 2 ++ src/Mod/Import/App/dxf.cpp | 40 ++++++++++++++++++++++++++ src/Mod/Import/App/dxf.h | 2 ++ src/Mod/TechDraw/App/AppTechDrawPy.cpp | 15 +++++++++- 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/Mod/Import/App/ImpExpDxf.cpp b/src/Mod/Import/App/ImpExpDxf.cpp index fbcd7a78df..1460fb4d23 100644 --- a/src/Mod/Import/App/ImpExpDxf.cpp +++ b/src/Mod/Import/App/ImpExpDxf.cpp @@ -632,4 +632,18 @@ void ImpExpDxfWrite::exportLWPoly(BRepAdaptor_Curve c) } } +void ImpExpDxfWrite::exportText(const char* text, Base::Vector3d position1, Base::Vector3d position2, double size, int just) +{ + double location1[3] = {0,0,0}; + location1[0] = position1.x; + location1[1] = position1.y; + location1[2] = position1.z; + double location2[3] = {0,0,0}; + location2[0] = position2.x; + location2[1] = position2.y; + location2[2] = position2.z; + WriteText(text, location1, location2, size, just, getLayerName().c_str()); + + +} diff --git a/src/Mod/Import/App/ImpExpDxf.h b/src/Mod/Import/App/ImpExpDxf.h index 9a71f048f2..a8bbc4baa3 100644 --- a/src/Mod/Import/App/ImpExpDxf.h +++ b/src/Mod/Import/App/ImpExpDxf.h @@ -80,6 +80,7 @@ namespace Import std::string getOptionSource() { return m_optionSource; } void setOptionSource(std::string s) { m_optionSource = s; } void setOptions(void); + void exportText(const char* text, Base::Vector3d position1, Base::Vector3d position2, double size, int just); static bool gp_PntEqual(gp_Pnt p1, gp_Pnt p2); static bool gp_PntCompare(gp_Pnt p1, gp_Pnt p2); @@ -93,6 +94,7 @@ namespace Import void exportBCurve(BRepAdaptor_Curve c); void exportLine(BRepAdaptor_Curve c); void exportLWPoly(BRepAdaptor_Curve c); + std::string m_layerName; std::string m_optionSource; double optionMaxLength; diff --git a/src/Mod/Import/App/dxf.cpp b/src/Mod/Import/App/dxf.cpp index d66079af04..d6a33347be 100644 --- a/src/Mod/Import/App/dxf.cpp +++ b/src/Mod/Import/App/dxf.cpp @@ -302,6 +302,46 @@ void CDxfWrite::WriteVertex(double x, double y, double z, const char* layer_name (*m_ofs) << 0 << endl; } +//*************************** +//WriteText +//added by Wandererfan 2018 (wandererfan@gmail.com) for FreeCAD project +void CDxfWrite::WriteText(const char* text, const double* location1, const double* location2, + const double height, const int horizJust, const char* layer_name) +{ + (*m_ofs) << 0 << endl; + (*m_ofs) << "TEXT" << endl; + (*m_ofs) << 8 << endl; + (*m_ofs) << layer_name << endl; + (*m_ofs) << 100 << endl; + (*m_ofs) << "AcDbEntity" << endl; + (*m_ofs) << 100 << endl; + (*m_ofs) << "AcDbText" << endl; + (*m_ofs) << 39 << endl; + (*m_ofs) << 0 << endl; //thickness + (*m_ofs) << 10 << endl; //first alignment point + (*m_ofs) << location1[0] << endl; + (*m_ofs) << 20 << endl; + (*m_ofs) << location1[1] << endl; + (*m_ofs) << 30 << endl; + (*m_ofs) << location1[2] << endl; + (*m_ofs) << 40 << endl; + (*m_ofs) << height << endl; + (*m_ofs) << 1 << endl; + (*m_ofs) << text << endl; + (*m_ofs) << 50 << endl; + (*m_ofs) << 0 << endl; //rotation + (*m_ofs) << 7 << endl; + (*m_ofs) << "STANDARD" << endl; //style + (*m_ofs) << 72 << endl; + (*m_ofs) << horizJust << endl; + (*m_ofs) << 11 << endl; //second alignment point + (*m_ofs) << location2[0] << endl; + (*m_ofs) << 21 << endl; + (*m_ofs) << location2[1] << endl; + (*m_ofs) << 31 << endl; + (*m_ofs) << location2[2] << endl; +} + CDxfRead::CDxfRead(const char* filepath) { diff --git a/src/Mod/Import/App/dxf.h b/src/Mod/Import/App/dxf.h index 2b516b9cdc..33176a417c 100644 --- a/src/Mod/Import/App/dxf.h +++ b/src/Mod/Import/App/dxf.h @@ -135,6 +135,8 @@ public: void WriteSpline(SplineDataOut sd, const char* layer_name); void WriteLWPolyLine(LWPolyDataOut pd, const char* layer_name); void WriteVertex(double x, double y, double z, const char* layer_name); + void WriteText(const char* text, const double* location1, const double* location2, + const double height, const int horizJust, const char* layer_name); }; // derive a class from this and implement it's virtual functions diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 9f39da835d..f7c447ea1f 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -60,6 +60,7 @@ #include "DrawProjectSplit.h" #include "DrawViewPart.h" #include "DrawViewPartPy.h" +#include "DrawViewAnnotation.h" #include "DrawPage.h" #include "DrawPagePy.h" #include "Geometry.h" @@ -579,6 +580,7 @@ private: App::DocumentObject* obj = 0; TechDraw::DrawViewPart* dvp = 0; + TechDraw::DrawViewAnnotation* dva = 0; TechDraw::DrawPage* dp = 0; if (PyObject_TypeCheck(pageObj, &(TechDraw::DrawPagePy::Type))) { obj = static_cast(pageObj)->getDocumentObjectPtr(); @@ -590,7 +592,18 @@ private: layerName = dvp->getNameInDocument(); writer.setLayerName(layerName); write1ViewDxf(writer,dvp,true); - } + } else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) { + dva = static_cast(v); + layerName = dva->getNameInDocument(); + writer.setLayerName(layerName); + double height = dva->TextSize.getValue(); //mm + int just = 1; //centered + double x = dva->X.getValue(); + double y = dva->Y.getValue(); + Base::Vector3d loc(x,y,0.0); + auto lines = dva->Text.getValues(); + writer.exportText(lines[0].c_str(),loc,loc, height,just); + } } } }