GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use a separate value of chord tolerance for exporting. · realthunder/solvespace@89eb208

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • confscreen.cpp
    • draw.cpp
    • export.cpp
    • exportstep.cpp
    • graphicswin.cpp
    • solvespace.cpp
    • solvespace.h
    • srf
      • ratpoly.cpp
      • surfinter.cpp
      • triangulate.cpp
    • ui.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/confscreen.cpp‎

Copy file name to clipboardExpand all lines: src/confscreen.cpp
+37-5Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,27 @@ void TextWindow::ScreenChangeColor(int link, uint32_t v) {
2626
}
2727

2828
void TextWindow::ScreenChangeChordTolerance(int link, uint32_t v) {
29-
SS.TW.ShowEditControl(3, ssprintf("%.2f", SS.chordTol));
29+
SS.TW.ShowEditControl(3, ssprintf("%lg", SS.chordTol));
3030
SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE;
31+
SS.TW.edit.i = 0;
3132
}
3233

3334
void TextWindow::ScreenChangeMaxSegments(int link, uint32_t v) {
3435
SS.TW.ShowEditControl(3, ssprintf("%d", SS.maxSegments));
3536
SS.TW.edit.meaning = EDIT_MAX_SEGMENTS;
37+
SS.TW.edit.i = 0;
38+
}
39+
40+
void TextWindow::ScreenChangeExportChordTolerance(int link, uint32_t v) {
41+
SS.TW.ShowEditControl(3, ssprintf("%lg", SS.exportChordTol));
42+
SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE;
43+
SS.TW.edit.i = 1;
44+
}
45+
46+
void TextWindow::ScreenChangeExportMaxSegments(int link, uint32_t v) {
47+
SS.TW.ShowEditControl(3, ssprintf("%d", SS.exportMaxSegments));
48+
SS.TW.edit.meaning = EDIT_MAX_SEGMENTS;
49+
SS.TW.edit.i = 1;
3650
}
3751

3852
void TextWindow::ScreenChangeCameraTangent(int link, uint32_t v) {
@@ -182,6 +196,16 @@ void TextWindow::ShowConfiguration(void) {
182196
SS.maxSegments,
183197
&ScreenChangeMaxSegments);
184198

199+
Printf(false, "");
200+
Printf(false, "%Ft export chord tolerance (in mm)%E");
201+
Printf(false, "%Ba %@ %Fl%Ll%f%D[change]%E",
202+
SS.exportChordTol,
203+
&ScreenChangeExportChordTolerance, 0);
204+
Printf(false, "%Ft export max piecewise linear segments%E");
205+
Printf(false, "%Ba %d %Fl%Ll%f[change]%E",
206+
SS.exportMaxSegments,
207+
&ScreenChangeExportMaxSegments);
208+
185209
Printf(false, "");
186210
Printf(false, "%Ft perspective factor (0 for parallel)%E");
187211
Printf(false, "%Ba %# %Fl%Ll%f%D[change]%E",
@@ -312,13 +336,21 @@ bool TextWindow::EditControlDoneForConfiguration(const char *s) {
312336
break;
313337
}
314338
case EDIT_CHORD_TOLERANCE: {
315-
SS.chordTol = min(10.0, max(0.1, atof(s)));
316-
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
339+
if(edit.i == 0) {
340+
SS.chordTol = max(0.0, atof(s));
341+
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
342+
} else {
343+
SS.exportChordTol = max(0.0, atof(s));
344+
}
317345
break;
318346
}
319347
case EDIT_MAX_SEGMENTS: {
320-
SS.maxSegments = min(1000, max(7, atoi(s)));
321-
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
348+
if(edit.i == 0) {
349+
SS.maxSegments = min(1000, max(7, atoi(s)));
350+
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
351+
} else {
352+
SS.exportMaxSegments = min(1000, max(7, atoi(s)));
353+
}
322354
break;
323355
}
324356
case EDIT_CAMERA_TANGENT: {
Collapse file

‎src/draw.cpp‎

Copy file name to clipboardExpand all lines: src/draw.cpp
+28-17Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -796,28 +796,39 @@ nogrid:;
796796

797797
// A note to indicate the origin in the just-exported file.
798798
if(SS.justExportedInfo.draw) {
799-
ssglColorRGB(Style::Color(Style::DATUM));
800-
Vector p = SS.justExportedInfo.pt,
801-
u = SS.justExportedInfo.u,
802-
v = SS.justExportedInfo.v;
799+
Vector p, u, v;
800+
if(SS.justExportedInfo.showOrigin) {
801+
p = SS.justExportedInfo.pt,
802+
u = SS.justExportedInfo.u,
803+
v = SS.justExportedInfo.v;
804+
} else {
805+
p = SS.GW.offset.ScaledBy(-1);
806+
u = SS.GW.projRight;
807+
v = SS.GW.projUp;
808+
}
803809

804-
ssglLineWidth(1.5);
805-
glBegin(GL_LINES);
806-
ssglVertex3v(p.Plus(u.WithMagnitude(-15/scale)));
807-
ssglVertex3v(p.Plus(u.WithMagnitude(30/scale)));
808-
ssglVertex3v(p.Plus(v.WithMagnitude(-15/scale)));
809-
ssglVertex3v(p.Plus(v.WithMagnitude(30/scale)));
810-
glEnd();
810+
ssglColorRGB(Style::Color(Style::DATUM));
811811

812-
ssglWriteText("(x, y) = (0, 0) for file just exported",
812+
ssglWriteText("previewing exported geometry; press Esc to return",
813813
DEFAULT_TEXT_HEIGHT,
814814
p.Plus(u.ScaledBy(10/scale)).Plus(v.ScaledBy(10/scale)),
815815
u, v, NULL, NULL);
816-
ssglWriteText("press Esc to clear this message",
817-
DEFAULT_TEXT_HEIGHT,
818-
p.Plus(u.ScaledBy(40/scale)).Plus(
819-
v.ScaledBy(-(DEFAULT_TEXT_HEIGHT)/scale)),
820-
u, v, NULL, NULL);
816+
817+
if(SS.justExportedInfo.showOrigin) {
818+
ssglLineWidth(1.5);
819+
glBegin(GL_LINES);
820+
ssglVertex3v(p.Plus(u.WithMagnitude(-15/scale)));
821+
ssglVertex3v(p.Plus(u.WithMagnitude(30/scale)));
822+
ssglVertex3v(p.Plus(v.WithMagnitude(-15/scale)));
823+
ssglVertex3v(p.Plus(v.WithMagnitude(30/scale)));
824+
glEnd();
825+
826+
ssglWriteText("(x, y) = (0, 0) for file just exported",
827+
DEFAULT_TEXT_HEIGHT,
828+
p.Plus(u.ScaledBy(40/scale)).Plus(
829+
v.ScaledBy(-(DEFAULT_TEXT_HEIGHT)/scale)),
830+
u, v, NULL, NULL);
831+
}
821832
}
822833

823834
// And finally the toolbar.
Collapse file

‎src/export.cpp‎

Copy file name to clipboardExpand all lines: src/export.cpp
+22-5Lines changed: 22 additions & 5 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+
SS.exportMode = true;
116+
GenerateAll(GENERATE_ALL);
117+
115118
SMesh *sm = NULL;
116119
if(SS.GW.showShaded) {
117120
Group *g = SK.GetGroup(SS.GW.activeGroup);
@@ -178,12 +181,16 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const std::string &filename, bool wir
178181
// These file formats don't have a canvas size, so they just
179182
// get exported in the raw coordinate system. So indicate what
180183
// that was on-screen.
181-
SS.justExportedInfo.draw = true;
184+
SS.justExportedInfo.showOrigin = true;
182185
SS.justExportedInfo.pt = origin;
183186
SS.justExportedInfo.u = u;
184187
SS.justExportedInfo.v = v;
185-
InvalidateGraphics();
188+
} else {
189+
SS.justExportedInfo.showOrigin = false;
186190
}
191+
192+
SS.justExportedInfo.draw = true;
193+
InvalidateGraphics();
187194
}
188195

189196
edges.Clear();
@@ -365,7 +372,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
365372
SEdge notClosedAt;
366373
sbl->l.ClearTags();
367374
sblss.FindOuterFacesFrom(sbl, &spxyz, &srf,
368-
SS.ChordTolMm()*s,
375+
SS.ExportChordTolMm(),
369376
&allClosed, &notClosedAt,
370377
NULL, NULL,
371378
&leftovers);
@@ -509,7 +516,7 @@ void VectorFileWriter::Output(SBezierLoopSetSet *sblss, SMesh *sm) {
509516

510517
void VectorFileWriter::BezierAsPwl(SBezier *sb) {
511518
List<Vector> lv = {};
512-
sb->MakePwlInto(&lv, SS.ChordTolMm() / SS.exportScale);
519+
sb->MakePwlInto(&lv, SS.ExportChordTolMm());
513520
int i;
514521
for(i = 1; i < lv.n; i++) {
515522
SBezier sb = SBezier::From(lv.elem[i-1], lv.elem[i]);
@@ -528,7 +535,7 @@ void VectorFileWriter::BezierAsNonrationalCubic(SBezier *sb, int depth) {
528535
sb->Finish().Minus(t1.ScaledBy(1.0/3)),
529536
sb->Finish());
530537

531-
double tol = SS.ChordTolMm() / SS.exportScale;
538+
double tol = SS.ExportChordTolMm();
532539
// Arbitrary choice, but make it a little finer than pwl tolerance since
533540
// it should be easier to achieve that with the smooth curves.
534541
tol /= 2;
@@ -559,6 +566,12 @@ void VectorFileWriter::BezierAsNonrationalCubic(SBezier *sb, int depth) {
559566
// Export a triangle mesh, in the requested format.
560567
//-----------------------------------------------------------------------------
561568
void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
569+
SS.exportMode = true;
570+
GenerateAll(GENERATE_ALL);
571+
572+
Group *g = SK.GetGroup(SS.GW.activeGroup);
573+
g->GenerateDisplayItems();
574+
562575
SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh);
563576
if(m->IsEmpty()) {
564577
Error("Active group mesh is empty; nothing to export.");
@@ -585,6 +598,10 @@ void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
585598
}
586599

587600
fclose(f);
601+
602+
SS.justExportedInfo.showOrigin = false;
603+
SS.justExportedInfo.draw = true;
604+
InvalidateGraphics();
588605
}
589606

590607
//-----------------------------------------------------------------------------
Collapse file

‎src/exportstep.cpp‎

Copy file name to clipboardExpand all lines: src/exportstep.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void StepFileWriter::ExportSurface(SSurface *ss, SBezierList *sbl) {
237237
// tolerance are required, because they are used to calculate the
238238
// contour directions and determine inner vs. outer contours.
239239
sblss.FindOuterFacesFrom(sbl, &spxyz, ss,
240-
SS.ChordTolMm() / SS.exportScale,
240+
SS.ExportChordTolMm(),
241241
&allClosed, &notClosedAt,
242242
NULL, NULL,
243243
NULL);
Collapse file

‎src/graphicswin.cpp‎

Copy file name to clipboardExpand all lines: src/graphicswin.cpp
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@ void GraphicsWindow::MenuEdit(int id) {
732732
for(p = SK.param.First(); p; p = SK.param.NextAfter(p)) {
733733
p->free = false;
734734
}
735+
if(SS.exportMode) {
736+
SS.exportMode = false;
737+
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
738+
}
735739
break;
736740

737741
case MNU_SELECT_ALL: {
Collapse file

‎src/solvespace.cpp‎

Copy file name to clipboardExpand all lines: src/solvespace.cpp
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ void SolveSpaceUI::Init() {
3636
lightDir[1].x = CnfThawFloat( 1.0f, "LightDir_1_Right" );
3737
lightDir[1].y = CnfThawFloat( 0.0f, "LightDir_1_Up" );
3838
lightDir[1].z = CnfThawFloat( 0.0f, "LightDir_1_Forward" );
39+
40+
exportMode = false;
3941
// Chord tolerance
4042
chordTol = CnfThawFloat(2.0f, "ChordTolerance");
4143
// Max pwl segments to generate
4244
maxSegments = CnfThawInt(10, "MaxSegments");
45+
// Chord tolerance
46+
exportChordTol = CnfThawFloat(0.1f, "ExportChordTolerance");
47+
// Max pwl segments to generate
48+
exportMaxSegments = CnfThawInt(64, "ExportMaxSegments");
4349
// View units
4450
viewUnits = (Unit)CnfThawInt((uint32_t)UNIT_MM, "ViewUnits");
4551
// Number of digits after the decimal point
@@ -157,6 +163,10 @@ void SolveSpaceUI::Exit(void) {
157163
CnfFreezeFloat((float)chordTol, "ChordTolerance");
158164
// Max pwl segments to generate
159165
CnfFreezeInt((uint32_t)maxSegments, "MaxSegments");
166+
// Export Chord tolerance
167+
CnfFreezeFloat((float)exportChordTol, "ExportChordTolerance");
168+
// Export Max pwl segments to generate
169+
CnfFreezeInt((uint32_t)exportMaxSegments, "ExportMaxSegments");
160170
// View units
161171
CnfFreezeInt((uint32_t)viewUnits, "ViewUnits");
162172
// Number of digits after the decimal point
@@ -259,7 +269,15 @@ double SolveSpaceUI::StringToMm(const std::string &str) {
259269
return std::stod(str) * MmPerUnit();
260270
}
261271
double SolveSpaceUI::ChordTolMm(void) {
262-
return SS.chordTol / SS.GW.scale;
272+
if(exportMode) return ExportChordTolMm();
273+
return chordTol / GW.scale;
274+
}
275+
double SolveSpaceUI::ExportChordTolMm(void) {
276+
return exportChordTol / exportScale;
277+
}
278+
int SolveSpaceUI::GetMaxSegments(void) {
279+
if(exportMode) return exportMaxSegments;
280+
return maxSegments;
263281
}
264282
int SolveSpaceUI::UnitDigitsAfterDecimal(void) {
265283
return (viewUnits == UNIT_INCHES) ? afterDecimalInch : afterDecimalMm;
Collapse file

‎src/solvespace.h‎

Copy file name to clipboardExpand all lines: src/solvespace.h
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ class SolveSpaceUI {
752752
double ambientIntensity;
753753
double chordTol;
754754
int maxSegments;
755+
double exportChordTol;
756+
int exportMaxSegments;
755757
double cameraTangent;
756758
float gridSpacing;
757759
float exportScale;
@@ -764,6 +766,7 @@ class SolveSpaceUI {
764766
bool exportShadedTriangles;
765767
bool exportPwlCurves;
766768
bool exportCanvasSizeAuto;
769+
bool exportMode;
767770
struct {
768771
float left;
769772
float right;
@@ -800,6 +803,8 @@ class SolveSpaceUI {
800803
int UnitDigitsAfterDecimal(void);
801804
void SetUnitDigitsAfterDecimal(int v);
802805
double ChordTolMm(void);
806+
double ExportChordTolMm(void);
807+
int GetMaxSegments(void);
803808
bool usePerspectiveProj;
804809
double CameraTangent(void);
805810

@@ -892,7 +897,7 @@ class SolveSpaceUI {
892897
Vector origin;
893898
} bgImage;
894899
struct {
895-
bool draw;
900+
bool draw, showOrigin;
896901
Vector pt, u, v;
897902
} justExportedInfo;
898903

Collapse file

‎src/srf/ratpoly.cpp‎

Copy file name to clipboardExpand all lines: src/srf/ratpoly.cpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void SBezier::MakePwlWorker(List<Vector> *l, double ta, double tb, double chordT
281281
Vector pm = PointAt((ta + tb) / 2.0);
282282
double d = pm.DistanceToLine(pa, pb.Minus(pa));
283283

284-
double step = 1.0/SS.maxSegments;
284+
double step = 1.0/SS.GetMaxSegments();
285285
if((tb - ta) < step || d < chordTol) {
286286
// A previous call has already added the beginning of our interval.
287287
l->Add(&pb);
@@ -311,7 +311,7 @@ void SBezier::MakePwlInitialWorker(List<Vector> *l, double ta, double tb, double
311311
pm3.DistanceToLine(pa, dir)
312312
});
313313

314-
double step = 1.0/SS.maxSegments;
314+
double step = 1.0/SS.GetMaxSegments();
315315
if((tb - ta) < step || d < chordTol) {
316316
// A previous call has already added the beginning of our interval.
317317
l->Add(&pb);
Collapse file

‎src/srf/surfinter.cpp‎

Copy file name to clipboardExpand all lines: src/srf/surfinter.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
376376

377377
// Our chord tolerance is whatever the user specified
378378
double maxtol = SS.ChordTolMm();
379-
int maxsteps = max(300, SS.maxSegments*3);
379+
int maxsteps = max(300, SS.GetMaxSegments()*3);
380380

381381
// The curve starts at our starting point.
382382
SCurvePt padd = {};
Collapse file

‎src/srf/triangulate.cpp‎

Copy file name to clipboardExpand all lines: src/srf/triangulate.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void SSurface::MakeTriangulationGridInto(List<double> *l, double vs, double vf,
409409
worst = max(worst, pm2.DistanceToLine(ps, pf.Minus(ps)));
410410
}
411411

412-
double step = 1.0/SS.maxSegments;
412+
double step = 1.0/SS.GetMaxSegments();
413413
if((vf - vs) < step || worst < SS.ChordTolMm()) {
414414
l->Add(&vf);
415415
} else {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.