Export Linear Dim to Dxf

This commit is contained in:
wandererfan
2018-05-20 11:58:43 -04:00
parent 4f5e304d64
commit 490b7fc197
5 changed files with 162 additions and 6 deletions

View File

@@ -644,6 +644,27 @@ void ImpExpDxfWrite::exportText(const char* text, Base::Vector3d position1, Base
location2[2] = position2.z;
WriteText(text, location1, location2, size, just, getLayerName().c_str());
}
void ImpExpDxfWrite::exportLinearDim(Base::Vector3d textLocn, Base::Vector3d lineLocn,
Base::Vector3d extLine1Start, Base::Vector3d extLine2Start,
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] = extLine1Start.x;
ext1[1] = extLine1Start.y;
ext1[2] = extLine1Start.z;
double ext2[3] = {0,0,0};
ext2[0] = extLine2Start.x;
ext2[1] = extLine2Start.y;
ext2[2] = extLine2Start.z;
WriteDim(text, line, ext1,ext2,dimText, getLayerName().c_str());
}

View File

@@ -81,6 +81,9 @@ namespace Import
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);
void exportLinearDim(Base::Vector3d textLocn, Base::Vector3d lineLocn,
Base::Vector3d extLine1Start, Base::Vector3d extLine2Start,
char* dimText);
static bool gp_PntEqual(gp_Pnt p1, gp_Pnt p2);
static bool gp_PntCompare(gp_Pnt p1, gp_Pnt p2);

View File

@@ -342,6 +342,105 @@ void CDxfWrite::WriteText(const char* text, const double* location1, const doubl
(*m_ofs) << location2[2] << endl;
}
//***************************
//WriteDim
//added by Wandererfan 2018 (wandererfan@gmail.com) for FreeCAD project
void CDxfWrite::WriteDim(const double* textMidPoint, const double* lineDefPoint,
const double* extLine1, const double* extLine2,
const char* dimText,
const char* layer_name)
//const char* blockName, const int dimType, const int attachPoint,
{
(*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; //dimension line definition point
(*m_ofs) << lineDefPoint[0] << endl;
(*m_ofs) << 20 << endl;
(*m_ofs) << lineDefPoint[1] << endl;
(*m_ofs) << 30 << endl;
(*m_ofs) << lineDefPoint[2] << endl;
(*m_ofs) << 11 << endl; //text mid point
(*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) << 1 << endl; // dimType1 = Aligned
(*m_ofs) << 71 << endl;
(*m_ofs) << 1 << endl; // attachPoint ??1 = topleft
(*m_ofs) << 1 << endl;
(*m_ofs) << dimText << endl;
(*m_ofs) << 3 << endl;
(*m_ofs) << "STANDARD" << endl; //style
//linear dims
(*m_ofs) << 100 << endl;
(*m_ofs) << "AcDbAlignedDimension" << endl;
(*m_ofs) << 13 << endl;
(*m_ofs) << extLine1[0] << endl;
(*m_ofs) << 23 << endl;
(*m_ofs) << extLine1[1] << endl;
(*m_ofs) << 33 << endl;
(*m_ofs) << extLine1[2] << endl;
(*m_ofs) << 14 << endl;
(*m_ofs) << extLine2[0] << endl;
(*m_ofs) << 24 << endl;
(*m_ofs) << extLine2[1] << endl;
(*m_ofs) << 34 << endl;
(*m_ofs) << extLine2[2] << endl;
////angular dims
// (*m_ofs) << 100 << endl;
// (*m_ofs) << "AcDb3PointAngularDimension" << endl;
// (*m_ofs) << 13 << endl;
// (*m_ofs) << extLine1[0] << endl;
// (*m_ofs) << 23 << endl;
// (*m_ofs) << extLine1[1] << endl;
// (*m_ofs) << 33 << endl;
// (*m_ofs) << extLine1[2] << endl;
// (*m_ofs) << 14 << endl;
// (*m_ofs) << extLine2[0] << endl;
// (*m_ofs) << 24 << endl;
// (*m_ofs) << extLine2[1] << endl;
// (*m_ofs) << 34 << endl;
// (*m_ofs) << extLine2[2] << endl;
// (*m_ofs) << 15 << endl;
// (*m_ofs) << apexPoint[0] << endl;
// (*m_ofs) << 25 << endl;
// (*m_ofs) << apexPoint[1] << endl;
// (*m_ofs) << 35 << endl;
// (*m_ofs) << apexPoint[2] << endl;
////radial dims
// (*m_ofs) << 100 << endl;
// (*m_ofs) << "AcDbRadialDimension" << endl;
// (*m_ofs) << 15 << endl;
// (*m_ofs) << arcPoint[0] << endl;
// (*m_ofs) << 25 << endl;
// (*m_ofs) << arcPoint[1] << endl;
// (*m_ofs) << 35 << endl;
// (*m_ofs) << arcPoint[2] << endl;
// (*m_ofs) << 40 << endl;
// (*m_ofs) << lenLeader << endl;
////diametric dims
// (*m_ofs) << 100 << endl;
// (*m_ofs) << "AcDbRadialDimension" << endl;
// (*m_ofs) << 15 << endl;
// (*m_ofs) << arcPoint[0] << endl;
// (*m_ofs) << 25 << endl;
// (*m_ofs) << arcPoint[1] << endl;
// (*m_ofs) << 35 << endl;
// (*m_ofs) << arcPoint[2] << endl;
// (*m_ofs) << 40 << endl;
// (*m_ofs) << lenLeader << endl;
}
CDxfRead::CDxfRead(const char* filepath)
{

View File

@@ -137,6 +137,11 @@ 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,
const double* extLine1, const double* extLine2,
const char* dimText,
const char* layer_name);
// const char* blockName, const int dimType, const int attachPoint,
};
// derive a class from this and implement it's virtual functions

View File

@@ -61,6 +61,7 @@
#include "DrawViewPart.h"
#include "DrawViewPartPy.h"
#include "DrawViewAnnotation.h"
#include "DrawViewDimension.h"
#include "DrawPage.h"
#include "DrawPagePy.h"
#include "Geometry.h"
@@ -579,8 +580,6 @@ private:
writer.setLayerName(layerName);
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<App::DocumentObjectPy*>(pageObj)->getDocumentObjectPtr();
@@ -588,12 +587,12 @@ private:
auto views = dp->getAllViews();
for (auto& v: views) {
if (v->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
dvp = static_cast<TechDraw::DrawViewPart*>(v);
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(v);
layerName = dvp->getNameInDocument();
writer.setLayerName(layerName);
write1ViewDxf(writer,dvp,true);
} else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) {
dva = static_cast<TechDraw::DrawViewAnnotation*>(v);
TechDraw::DrawViewAnnotation* dva = static_cast<TechDraw::DrawViewAnnotation*>(v);
layerName = dva->getNameInDocument();
writer.setLayerName(layerName);
double height = dva->TextSize.getValue(); //mm
@@ -603,6 +602,35 @@ private:
Base::Vector3d loc(x,y,0.0);
auto lines = dva->Text.getValues();
writer.exportText(lines[0].c_str(),loc,loc, height,just);
} else if (v->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
DrawViewDimension* dvd = static_cast<TechDraw::DrawViewDimension*>(v);
TechDraw::DrawViewPart* dvp = dvd->getViewPart();
if (dvp == nullptr) {
continue;
}
double parentX = dvp->X.getValue();
double parentY = dvp->Y.getValue();
layerName = dvd->getNameInDocument();
writer.setLayerName(layerName);
if ( dvd->Type.isValue("Distance") ||
dvd->Type.isValue("DistanceX") ||
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);
}
}
}
}