From 65f67d8ff8670d8c1a8566faf833f4a891503bec Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 20 May 2018 19:15:03 -0400 Subject: [PATCH] Export Angular Dim to Dxf --- src/Mod/Import/App/ImpExpDxf.cpp | 31 +++++++++- src/Mod/Import/App/ImpExpDxf.h | 4 ++ src/Mod/Import/App/dxf.cpp | 80 +++++++++++++++++++++++++- src/Mod/Import/App/dxf.h | 7 ++- src/Mod/TechDraw/App/AppTechDrawPy.cpp | 27 ++++++++- 5 files changed, 142 insertions(+), 7 deletions(-) diff --git a/src/Mod/Import/App/ImpExpDxf.cpp b/src/Mod/Import/App/ImpExpDxf.cpp index 7f309dc78c..25528ecbcb 100644 --- a/src/Mod/Import/App/ImpExpDxf.cpp +++ b/src/Mod/Import/App/ImpExpDxf.cpp @@ -666,5 +666,34 @@ void ImpExpDxfWrite::exportLinearDim(Base::Vector3d textLocn, Base::Vector3d lin ext2[0] = extLine2Start.x; ext2[1] = extLine2Start.y; ext2[2] = extLine2Start.z; - WriteDim(text, line, ext1,ext2,dimText, getLayerName().c_str()); + WriteLinearDim(text, line, ext1,ext2,dimText, getLayerName().c_str()); +} + +void ImpExpDxfWrite::exportAngularDim(Base::Vector3d textLocn, Base::Vector3d lineLocn, + Base::Vector3d extLine1End, Base::Vector3d extLine2End, + Base::Vector3d apexPoint, + char* dimText) +{ + double text[3] = {0,0,0}; + text[0] = textLocn.x; + text[1] = textLocn.y; + text[2] = textLocn.z; + double line[3] = {0,0,0}; + line[0] = lineLocn.x; + line[1] = lineLocn.y; + line[2] = lineLocn.z; + double ext1[3] = {0,0,0}; + ext1[0] = extLine1End.x; + ext1[1] = extLine1End.y; + ext1[2] = extLine1End.z; + double ext2[3] = {0,0,0}; + ext2[0] = extLine2End.x; + ext2[1] = extLine2End.y; + ext2[2] = extLine2End.z; + double apex[3] = {0,0,0}; + apex[0] = apexPoint.x; + apex[1] = apexPoint.y; + apex[2] = apexPoint.z; + WriteAngularDim(text, line, apex, ext1, apex, ext2, dimText, getLayerName().c_str()); + } diff --git a/src/Mod/Import/App/ImpExpDxf.h b/src/Mod/Import/App/ImpExpDxf.h index 7a299e6d8e..97c2e39c22 100644 --- a/src/Mod/Import/App/ImpExpDxf.h +++ b/src/Mod/Import/App/ImpExpDxf.h @@ -84,6 +84,10 @@ namespace Import void exportLinearDim(Base::Vector3d textLocn, Base::Vector3d lineLocn, Base::Vector3d extLine1Start, Base::Vector3d extLine2Start, char* dimText); + void exportAngularDim(Base::Vector3d textLocn, Base::Vector3d lineLocn, + Base::Vector3d extLine1Start, Base::Vector3d extLine2Start, + Base::Vector3d apexPoint, + char* dimText); static bool gp_PntEqual(gp_Pnt p1, gp_Pnt p2); static bool gp_PntCompare(gp_Pnt p1, gp_Pnt p2); diff --git a/src/Mod/Import/App/dxf.cpp b/src/Mod/Import/App/dxf.cpp index b0df56146a..0eb9cf7f73 100644 --- a/src/Mod/Import/App/dxf.cpp +++ b/src/Mod/Import/App/dxf.cpp @@ -343,9 +343,9 @@ void CDxfWrite::WriteText(const char* text, const double* location1, const doubl } //*************************** -//WriteDim +//WriteLinearDim //added by Wandererfan 2018 (wandererfan@gmail.com) for FreeCAD project -void CDxfWrite::WriteDim(const double* textMidPoint, const double* lineDefPoint, +void CDxfWrite::WriteLinearDim(const double* textMidPoint, const double* lineDefPoint, const double* extLine1, const double* extLine2, const char* dimText, const char* layer_name) @@ -441,6 +441,82 @@ void CDxfWrite::WriteDim(const double* textMidPoint, const double* lineDefPoint, // (*m_ofs) << lenLeader << endl; } +//*************************** +//WriteAngularDim +//added by Wandererfan 2018 (wandererfan@gmail.com) for FreeCAD project +void CDxfWrite::WriteAngularDim(const double* textMidPoint, const double* lineDefPoint, + const double* startExt1, const double* endExt1, + const double* startExt2, const double* endExt2, + const char* dimText, + const char* layer_name) +{ + (*m_ofs) << 0 << endl; + (*m_ofs) << "DIMENSION" << endl; + (*m_ofs) << 8 << endl; + (*m_ofs) << layer_name << endl; + (*m_ofs) << 100 << endl; + (*m_ofs) << "AcDbEntity" << endl; + (*m_ofs) << 100 << endl; + (*m_ofs) << "AcDbDimension" << endl; + (*m_ofs) << 2 << endl; + (*m_ofs) << "*D1" << endl; // blockName *D1 ?? + + (*m_ofs) << 10 << endl; + (*m_ofs) << endExt2[0] << endl; + (*m_ofs) << 20 << endl; + (*m_ofs) << endExt2[1] << endl; + (*m_ofs) << 30 << endl; + (*m_ofs) << endExt2[2] << endl; + + (*m_ofs) << 11 << endl; + (*m_ofs) << textMidPoint[0] << endl; + (*m_ofs) << 21 << endl; + (*m_ofs) << textMidPoint[1] << endl; + (*m_ofs) << 31 << endl; + (*m_ofs) << textMidPoint[2] << endl; + + (*m_ofs) << 70 << endl; + (*m_ofs) << 34 << endl; // dimType 2 = Angular 5 = Angular 3 point + // +32 for block?? + (*m_ofs) << 71 << endl; + (*m_ofs) << 5 << endl; // attachPoint 5 = middle + (*m_ofs) << 1 << endl; + (*m_ofs) << dimText << endl; + (*m_ofs) << 3 << endl; + (*m_ofs) << "STANDARD" << endl; //style +//angular dims + (*m_ofs) << 100 << endl; + (*m_ofs) << "AcDb2LineAngularDimension" << endl; + + (*m_ofs) << 13 << endl; + (*m_ofs) << startExt1[0] << endl; + (*m_ofs) << 23 << endl; + (*m_ofs) << startExt1[1] << endl; + (*m_ofs) << 33 << endl; + (*m_ofs) << startExt1[2] << endl; + + (*m_ofs) << 14 << endl; + (*m_ofs) << endExt1[0] << endl; + (*m_ofs) << 24 << endl; + (*m_ofs) << endExt1[1] << endl; + (*m_ofs) << 34 << endl; + (*m_ofs) << endExt1[2] << endl; + + (*m_ofs) << 15 << endl; + (*m_ofs) << startExt2[0] << endl; + (*m_ofs) << 25 << endl; + (*m_ofs) << startExt2[1] << endl; + (*m_ofs) << 35 << endl; + (*m_ofs) << startExt2[2] << endl; + + (*m_ofs) << 16 << endl; + (*m_ofs) << lineDefPoint[0] << endl; + (*m_ofs) << 26 << endl; + (*m_ofs) << lineDefPoint[1] << endl; + (*m_ofs) << 36 << endl; + (*m_ofs) << lineDefPoint[2] << endl; +} + CDxfRead::CDxfRead(const char* filepath) { diff --git a/src/Mod/Import/App/dxf.h b/src/Mod/Import/App/dxf.h index e04d25a619..3e646e7817 100644 --- a/src/Mod/Import/App/dxf.h +++ b/src/Mod/Import/App/dxf.h @@ -137,10 +137,15 @@ public: 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); - void WriteDim(const double* textMidPoint, const double* lineDefPoint, + void WriteLinearDim(const double* textMidPoint, const double* lineDefPoint, const double* extLine1, const double* extLine2, const char* dimText, const char* layer_name); + void WriteAngularDim(const double* textMidPoint, const double* lineDefPoint, + const double* startExt1, const double* endExt1, + const double* startExt2, const double* endExt2, + const char* dimText, + const char* layer_name); // const char* blockName, const int dimType, const int attachPoint, }; diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index e48b840a85..09d513e579 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -610,6 +610,10 @@ private: } double parentX = dvp->X.getValue(); double parentY = dvp->Y.getValue(); + Base::Vector3d parentPos(parentX,parentY,0.0); + std::string sDimText = dvd->getFormatedValue(); + char* dimText = &sDimText[0u]; //hack for const-ness + float gap = 5.0; //hack. don't know font size here. layerName = dvd->getNameInDocument(); writer.setLayerName(layerName); if ( dvd->Type.isValue("Distance") || @@ -617,19 +621,36 @@ private: dvd->Type.isValue("DistanceY") ) { Base::Vector3d textLocn(dvd->X.getValue() + parentX, dvd->Y.getValue() + parentY, 0.0); Base::Vector3d lineLocn(dvd->X.getValue() + parentX, dvd->Y.getValue() + parentY,0.0); - std::string sDimText = dvd->getFormatedValue(); - char* dimText = &sDimText[0u]; //hack for const-ness pointPair pts = dvd->getLinearPoints(); Base::Vector3d dimLine = pts.first - pts.second; Base::Vector3d norm(-dimLine.y,dimLine.x,0.0); norm.Normalize(); - float gap = 5.0; //hack. don't know font size here. lineLocn = lineLocn + (norm * gap); Base::Vector3d extLine1Start = Base::Vector3d(pts.first.x,-pts.first.y,0.0) + Base::Vector3d(parentX,parentY,0.0); Base::Vector3d extLine2Start = Base::Vector3d(pts.second.x, -pts.second.y, 0.0) + Base::Vector3d(parentX,parentY,0.0); writer.exportLinearDim(textLocn, lineLocn, extLine1Start, extLine2Start, dimText); + }else if (dvd->Type.isValue("Angle")) { + Base::Vector3d textLocn(dvd->X.getValue() + parentX, dvd->Y.getValue() + parentY, 0.0); + Base::Vector3d lineLocn(dvd->X.getValue() + parentX, dvd->Y.getValue() + parentY,0.0); + anglePoints pts = dvd->getAnglePoints(); + Base::Vector3d end1 = pts.ends.first; + end1.y = -end1.y; + Base::Vector3d end2 = pts.ends.second; + end2.y = -end2.y; + + Base::Vector3d apex = pts.vertex; + apex.y = -apex.y; + apex = apex + parentPos; + + Base::Vector3d dimLine = end2 - end1; + Base::Vector3d norm(-dimLine.y,dimLine.x,0.0); + norm.Normalize(); + lineLocn = lineLocn + (norm * gap); + end1 = end1 + parentPos; + end2 = end2 + parentPos; + writer.exportAngularDim(textLocn, lineLocn, end1, end2, apex, dimText); } } }