FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

DXF: export constraints with labels as DXF constraints, not pwl. · ppd/solvespace@f87152e · GitHub

Repository navigation

Commit f87152e

Browse files
authored andcommitted
DXF: export constraints with labels as DXF constraints, not pwl.
Specifically, the following constraint types: * pt-pt-distance * pt-line-distance * diameter * angle * comment
1 parent e377eb8 commit f87152e

5 files changed

Lines changed: 292 additions & 30 deletions

File tree

‎src/entity.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ Vector EntityBase::VectorGetRefPoint(void) {
7676
}
7777
}
7878

79+
Vector EntityBase::VectorGetStartPoint(void) {
80+
switch(type) {
81+
case LINE_SEGMENT:
82+
return SK.GetEntity(point[1])->PointGetNum();
83+
84+
case NORMAL_IN_3D:
85+
case NORMAL_IN_2D:
86+
case NORMAL_N_COPY:
87+
case NORMAL_N_ROT:
88+
case NORMAL_N_ROT_AA:
89+
return SK.GetEntity(point[0])->PointGetNum();
90+
91+
default: oops();
92+
}
93+
}
94+
7995
bool EntityBase::IsCircle(void) {
8096
return (type == CIRCLE) || (type == ARC_OF_CIRCLE);
8197
}

‎src/export.cpp‎

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const std::string &filename, bool wir
112112
SEdgeList edges = {};
113113
SBezierList beziers = {};
114114

115+
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
116+
if(!out) return;
117+
115118
SS.exportMode = true;
116119
GenerateAll(GENERATE_ALL);
117120

@@ -153,31 +156,41 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const std::string &filename, bool wir
153156
}
154157

155158
if(SS.GW.showConstraints) {
156-
Constraint *c;
157-
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
158-
c->GetEdges(&edges);
159+
if(!out->OutputConstraints(&SK.constraint)) {
160+
// The output format cannot represent constraints directly,
161+
// so convert them to edges.
162+
Constraint *c;
163+
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
164+
c->GetEdges(&edges);
165+
}
159166
}
160167
}
161168

162169
if(wireframe) {
163-
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
164-
if(out) {
165-
ExportWireframeCurves(&edges, &beziers, out);
166-
}
170+
Vector u = Vector::From(1.0, 0.0, 0.0),
171+
v = Vector::From(0.0, 1.0, 0.0),
172+
n = Vector::From(0.0, 0.0, 1.0),
173+
origin = Vector::From(0.0, 0.0, 0.0);
174+
double cameraTan = 0.0,
175+
scale = 1.0;
176+
177+
out->SetModelviewProjection(u, v, n, origin, cameraTan, scale);
178+
179+
ExportWireframeCurves(&edges, &beziers, out);
167180
} else {
168181
Vector u = SS.GW.projRight,
169182
v = SS.GW.projUp,
170183
n = u.Cross(v),
171184
origin = SS.GW.offset.ScaledBy(-1);
172185

173-
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
174-
if(out) {
175-
ExportLinesAndMesh(&edges, &beziers, sm,
176-
u, v, n, origin, SS.CameraTangent()*SS.GW.scale,
177-
out);
178-
}
186+
out->SetModelviewProjection(u, v, n, origin,
187+
SS.CameraTangent()*SS.GW.scale, SS.exportScale);
179188

180-
if(out && !out->HasCanvasSize()) {
189+
ExportLinesAndMesh(&edges, &beziers, sm,
190+
u, v, n, origin, SS.CameraTangent()*SS.GW.scale,
191+
out);
192+
193+
if(!out->HasCanvasSize()) {
181194
// These file formats don't have a canvas size, so they just
182195
// get exported in the raw coordinate system. So indicate what
183196
// that was on-screen.
@@ -215,7 +228,7 @@ void SolveSpaceUI::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl,
215228
sblss.AddOpenPath(sb);
216229
}
217230

218-
out->Output(&sblss, NULL);
231+
out->OutputLinesAndMesh(&sblss, NULL);
219232
sblss.Clear();
220233
}
221234

@@ -381,7 +394,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
381394
}
382395

383396
// Now write the lines and triangles to the output file
384-
out->Output(&sblss, &sms);
397+
out->OutputLinesAndMesh(&sblss, &sms);
385398

386399
leftovers.Clear();
387400
spxyz.Clear();
@@ -441,7 +454,22 @@ VectorFileWriter *VectorFileWriter::ForFile(const std::string &filename) {
441454
return ret;
442455
}
443456

444-
void VectorFileWriter::Output(SBezierLoopSetSet *sblss, SMesh *sm) {
457+
void VectorFileWriter::SetModelviewProjection(const Vector &u, const Vector &v, const Vector &n,
458+
const Vector &origin, double cameraTan,
459+
double scale) {
460+
this->u = u;
461+
this->v = v;
462+
this->n = n;
463+
this->origin = origin;
464+
this->cameraTan = cameraTan;
465+
this->scale = scale;
466+
}
467+
468+
Vector VectorFileWriter::Transform(Vector &pos) const {
469+
return pos.InPerspective(u, v, n, origin, cameraTan).ScaledBy(1.0 / scale);
470+
}
471+
472+
void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
445473
STriangle *tr;
446474
SBezier *b;
447475

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL