Draft: Allow to scale imported DXF files - fixes #2557
This commit is contained in:
@@ -26,8 +26,7 @@
|
||||
#endif
|
||||
|
||||
#include "DraftDxf.h"
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
@@ -51,19 +50,34 @@
|
||||
|
||||
using namespace DraftUtils;
|
||||
|
||||
|
||||
DraftDxfRead::DraftDxfRead(std::string filepath, App::Document *pcDoc) : CDxfRead(filepath.c_str())
|
||||
{
|
||||
document = pcDoc;
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Draft");
|
||||
optionGroupLayers = hGrp->GetBool("groupLayers",false);
|
||||
optionImportAnnotations = hGrp->GetBool("dxftext",false);
|
||||
optionScaling = hGrp->GetFloat("dxfScaling",1.0);
|
||||
}
|
||||
|
||||
|
||||
gp_Pnt DraftDxfRead::makePoint(const double* p)
|
||||
{
|
||||
double sp1(p[0]);
|
||||
double sp2(p[1]);
|
||||
double sp3(p[2]);
|
||||
if (optionScaling != 1.0) {
|
||||
sp1 = sp1 * optionScaling;
|
||||
sp2 = sp2 * optionScaling;
|
||||
sp3 = sp3 * optionScaling;
|
||||
}
|
||||
return gp_Pnt(sp1,sp2,sp3);
|
||||
}
|
||||
|
||||
void DraftDxfRead::OnReadLine(const double* s, const double* e, bool hidden)
|
||||
{
|
||||
gp_Pnt p0(s[0], s[1], s[2]);
|
||||
gp_Pnt p1(e[0], e[1], e[2]);
|
||||
gp_Pnt p0 = makePoint(s);
|
||||
gp_Pnt p1 = makePoint(e);
|
||||
if (p0.IsEqual(p1,0.00000001))
|
||||
return;
|
||||
BRepBuilderAPI_MakeEdge makeEdge(p0, p1);
|
||||
@@ -74,7 +88,7 @@ void DraftDxfRead::OnReadLine(const double* s, const double* e, bool hidden)
|
||||
|
||||
void DraftDxfRead::OnReadPoint(const double* s)
|
||||
{
|
||||
BRepBuilderAPI_MakeVertex makeVertex(gp_Pnt(s[0], s[1], s[2]));
|
||||
BRepBuilderAPI_MakeVertex makeVertex(makePoint(s));
|
||||
TopoDS_Vertex vertex = makeVertex.Vertex();
|
||||
AddObject(new Part::TopoShape(vertex));
|
||||
}
|
||||
@@ -82,12 +96,12 @@ void DraftDxfRead::OnReadPoint(const double* s)
|
||||
|
||||
void DraftDxfRead::OnReadArc(const double* s, const double* e, const double* c, bool dir, bool hidden)
|
||||
{
|
||||
gp_Pnt p0(s[0], s[1], s[2]);
|
||||
gp_Pnt p1(e[0], e[1], e[2]);
|
||||
gp_Pnt p0 = makePoint(s);
|
||||
gp_Pnt p1 = makePoint(e);
|
||||
gp_Dir up(0, 0, 1);
|
||||
if (!dir)
|
||||
up = -up;
|
||||
gp_Pnt pc(c[0], c[1], c[2]);
|
||||
gp_Pnt pc = makePoint(c);
|
||||
gp_Circ circle(gp_Ax2(pc, up), p0.Distance(pc));
|
||||
BRepBuilderAPI_MakeEdge makeEdge(circle, p0, p1);
|
||||
TopoDS_Edge edge = makeEdge.Edge();
|
||||
@@ -97,11 +111,11 @@ void DraftDxfRead::OnReadArc(const double* s, const double* e, const double* c,
|
||||
|
||||
void DraftDxfRead::OnReadCircle(const double* s, const double* c, bool dir, bool hidden)
|
||||
{
|
||||
gp_Pnt p0(s[0], s[1], s[2]);
|
||||
gp_Pnt p0 = makePoint(s);
|
||||
gp_Dir up(0, 0, 1);
|
||||
if (!dir)
|
||||
up = -up;
|
||||
gp_Pnt pc(c[0], c[1], c[2]);
|
||||
gp_Pnt pc = makePoint(c);
|
||||
gp_Circ circle(gp_Ax2(pc, up), p0.Distance(pc));
|
||||
BRepBuilderAPI_MakeEdge makeEdge(circle);
|
||||
TopoDS_Edge edge = makeEdge.Edge();
|
||||
@@ -120,8 +134,8 @@ void DraftDxfRead::OnReadEllipse(const double* c, double major_radius, double mi
|
||||
gp_Dir up(0, 0, 1);
|
||||
if(!dir)
|
||||
up = -up;
|
||||
gp_Pnt pc(c[0], c[1], c[2]);
|
||||
gp_Elips ellipse(gp_Ax2(pc, up), major_radius, minor_radius);
|
||||
gp_Pnt pc = makePoint(c);
|
||||
gp_Elips ellipse(gp_Ax2(pc, up), major_radius * optionScaling, minor_radius * optionScaling);
|
||||
ellipse.Rotate(gp_Ax1(pc,up),rotation);
|
||||
BRepBuilderAPI_MakeEdge makeEdge(ellipse);
|
||||
TopoDS_Edge edge = makeEdge.Edge();
|
||||
@@ -132,7 +146,7 @@ void DraftDxfRead::OnReadEllipse(const double* c, double major_radius, double mi
|
||||
void DraftDxfRead::OnReadText(const double *point, const double height, const char* text)
|
||||
{
|
||||
if (optionImportAnnotations) {
|
||||
Base::Vector3d pt(point[0],point[1],point[2]);
|
||||
Base::Vector3d pt(point[0] * optionScaling, point[1] * optionScaling, point[2] * optionScaling);
|
||||
if(LayerName().substr(0, 6) != "BLOCKS") {
|
||||
App::Annotation *pcFeature = (App::Annotation *)document->addObject("App::Annotation", "Text");
|
||||
pcFeature->LabelText.setValue(Deformat(text));
|
||||
@@ -166,7 +180,7 @@ void DraftDxfRead::OnReadInsert(const double* point, const double* scale, const
|
||||
Base::Matrix4D mat;
|
||||
mat.scale(scale[0],scale[1],scale[2]);
|
||||
mat.rotZ(rotation);
|
||||
mat.move(point[0],point[1],point[2]);
|
||||
mat.move(point[0]*optionScaling,point[1]*optionScaling,point[2]*optionScaling);
|
||||
pcomp->transformShape(mat,true);
|
||||
AddObject(pcomp);
|
||||
}
|
||||
@@ -179,9 +193,9 @@ void DraftDxfRead::OnReadDimension(const double* s, const double* e, const doubl
|
||||
{
|
||||
if (optionImportAnnotations) {
|
||||
Base::Interpreter().runString("import Draft");
|
||||
Base::Interpreter().runStringArg("p1=FreeCAD.Vector(%f,%f,%f)",s[0],s[1],s[2]);
|
||||
Base::Interpreter().runStringArg("p2=FreeCAD.Vector(%f,%f,%f)",e[0],e[1],e[2]);
|
||||
Base::Interpreter().runStringArg("p3=FreeCAD.Vector(%f,%f,%f)",point[0],point[1],point[2]);
|
||||
Base::Interpreter().runStringArg("p1=FreeCAD.Vector(%f,%f,%f)",s[0]*optionScaling,s[1]*optionScaling,s[2]*optionScaling);
|
||||
Base::Interpreter().runStringArg("p2=FreeCAD.Vector(%f,%f,%f)",e[0]*optionScaling,e[1]*optionScaling,e[2]*optionScaling);
|
||||
Base::Interpreter().runStringArg("p3=FreeCAD.Vector(%f,%f,%f)",point[0]*optionScaling,point[1]*optionScaling,point[2]*optionScaling);
|
||||
Base::Interpreter().runString("Draft.makeDimension(p1,p2,p3)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user