diff --git a/drawentity.cpp b/drawentity.cpp index 24afa464..2c23168c 100644 --- a/drawentity.cpp +++ b/drawentity.cpp @@ -157,7 +157,8 @@ void Entity::BezierPwl(double ta, double tb, double tol = SS.chordTol/SS.GW.scale; - if((tb - ta) < 0.01 || d < tol) { + double step = 1.0/SS.maxSegments; + if((tb - ta) < step || d < tol) { LineDrawOrGetDistanceOrEdge(pa, pb); } else { double tm = (ta + tb) / 2; diff --git a/solvespace.cpp b/solvespace.cpp index 9994fe24..997d7dc3 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -39,6 +39,8 @@ void SolveSpace::Init(char *cmdLine) { lightDir[1].z = CnfThawFloat( 0.0f, "LightDir_1_Forward" ); // Chord tolerance chordTol = CnfThawFloat(2.0f, "ChordTolerance"); + // Max pwl segments to generate + maxSegments = CnfThawDWORD(40, "MaxSegments"); // View units viewUnits = (Unit)CnfThawDWORD((DWORD)UNIT_MM, "ViewUnits"); // Camera tangent (determines perspective) @@ -95,6 +97,8 @@ void SolveSpace::Exit(void) { CnfFreezeFloat((float)lightDir[1].z, "LightDir_1_Forward"); // Chord tolerance CnfFreezeFloat((float)chordTol, "ChordTolerance"); + // Max pwl segments to generate + CnfFreezeDWORD((DWORD)maxSegments, "MaxSegments"); // Display/entry units CnfFreezeDWORD((DWORD)viewUnits, "ViewUnits"); // Camera tangent (determines perspective) @@ -129,7 +133,7 @@ int SolveSpace::CircleSides(double r) { double tol = chordTol/GW.scale; int n = 3 + (int)(PI/sqrt(2*tol/r)); - return max(7, min(n, 200)); + return max(7, min(n, maxSegments)); } char *SolveSpace::MmToString(double v) { diff --git a/solvespace.h b/solvespace.h index f0b8e941..d9a1a266 100644 --- a/solvespace.h +++ b/solvespace.h @@ -366,6 +366,7 @@ public: Vector lightDir[2]; double lightIntensity[2]; double chordTol; + int maxSegments; double cameraTangent; DWORD edgeColor; float exportScale; diff --git a/textscreens.cpp b/textscreens.cpp index 724bdec6..430d9a65 100644 --- a/textscreens.cpp +++ b/textscreens.cpp @@ -545,31 +545,37 @@ void TextWindow::ScreenChangeColor(int link, DWORD v) { SS.TW.edit.meaning = EDIT_COLOR; SS.TW.edit.i = v; } -void TextWindow::ScreenChangeChordTolerance(int link, DWORD v) { - char str[1024]; - sprintf(str, "%.2f", SS.chordTol); - ShowTextEditControl(37, 3, str); - SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE; -} -void TextWindow::ScreenChangeCameraTangent(int link, DWORD v) { - char str[1024]; - sprintf(str, "%.3f", 1000*SS.cameraTangent); - ShowTextEditControl(43, 3, str); - SS.TW.edit.meaning = EDIT_CAMERA_TANGENT; -} void TextWindow::ScreenChangeEdgeColor(int link, DWORD v) { char str[1024]; sprintf(str, "%.3f, %.3f, %.3f", REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor)); - ShowTextEditControl(49, 3, str); + ShowTextEditControl(37, 3, str); SS.TW.edit.meaning = EDIT_EDGE_COLOR; } +void TextWindow::ScreenChangeChordTolerance(int link, DWORD v) { + char str[1024]; + sprintf(str, "%.2f", SS.chordTol); + ShowTextEditControl(43, 3, str); + SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE; +} +void TextWindow::ScreenChangeMaxSegments(int link, DWORD v) { + char str[1024]; + sprintf(str, "%d", SS.maxSegments); + ShowTextEditControl(47, 3, str); + SS.TW.edit.meaning = EDIT_MAX_SEGMENTS; +} +void TextWindow::ScreenChangeCameraTangent(int link, DWORD v) { + char str[1024]; + sprintf(str, "%.3f", 1000*SS.cameraTangent); + ShowTextEditControl(53, 3, str); + SS.TW.edit.meaning = EDIT_CAMERA_TANGENT; +} void TextWindow::ScreenChangeExportScale(int link, DWORD v) { char str[1024]; sprintf(str, "%.3f", (double)SS.exportScale); - ShowTextEditControl(55, 3, str); + ShowTextEditControl(59, 3, str); SS.TW.edit.meaning = EDIT_EXPORT_SCALE; } void TextWindow::ShowConfiguration(void) { @@ -597,12 +603,22 @@ void TextWindow::ShowConfiguration(void) { SS.lightIntensity[i], i, &ScreenChangeLightIntensity); } + Printf(false, ""); + Printf(false, "%Ft edge color r,g,b (0,0,0 for no edges)%E"); + Printf(false, "%Ba %@, %@, %@ %Fl%Ll%f%D[change]%E", + REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor), + &ScreenChangeEdgeColor, 0); + Printf(false, ""); Printf(false, "%Ft chord tolerance (in screen pixels)%E"); Printf(false, "%Ba %2 %Fl%Ll%f%D[change]%E; now %d triangles", SS.chordTol, &ScreenChangeChordTolerance, 0, SS.GetGroup(SS.GW.activeGroup)->runningMesh.l.n); + Printf(false, "%Ft max piecewise linear segments%E"); + Printf(false, "%Ba %d %Fl%Ll%f[change]%E", + SS.maxSegments, + &ScreenChangeMaxSegments); Printf(false, ""); Printf(false, "%Ft perspective factor (0 for parallel)%E"); @@ -610,12 +626,6 @@ void TextWindow::ShowConfiguration(void) { SS.cameraTangent*1000, &ScreenChangeCameraTangent, 0); - Printf(false, ""); - Printf(false, "%Ft edge color r,g,b (0,0,0 for no edges)%E"); - Printf(false, "%Ba %@, %@, %@ %Fl%Ll%f%D[change]%E", - REDf(SS.edgeColor), GREENf(SS.edgeColor), BLUEf(SS.edgeColor), - &ScreenChangeEdgeColor, 0); - Printf(false, ""); Printf(false, "%Ft export scale factor (1.0=mm, 25.4=inch)"); Printf(false, "%Ba %3 %Fl%Ll%f%D[change]%E", @@ -798,6 +808,11 @@ void TextWindow::EditControlDone(char *s) { SS.GenerateAll(0, INT_MAX); break; } + case EDIT_MAX_SEGMENTS: { + SS.maxSegments = min(1000, max(7, atoi(s))); + SS.GenerateAll(0, INT_MAX); + break; + } case EDIT_CAMERA_TANGENT: { SS.cameraTangent = (min(2, max(0, atof(s))))/1000.0; InvalidateGraphics(); diff --git a/ttf.cpp b/ttf.cpp index 6bd5fc3b..08ec8576 100644 --- a/ttf.cpp +++ b/ttf.cpp @@ -706,7 +706,8 @@ void TtfFont::BezierPwl(double ta, double tb, Vector p0, Vector p1, Vector p2) { double tol = SS.chordTol/SS.GW.scale; - if((tb - ta) < 0.01 || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) { + double step = 1.0/SS.maxSegments; + if((tb - ta) < step || pm.DistanceToLine(pa, pb.Minus(pa)) < tol) { Entity *e = SS.GetEntity(entity); e->LineDrawOrGetDistanceOrEdge(pa, pb); } else { diff --git a/ui.h b/ui.h index c76e6100..7d5c7123 100644 --- a/ui.h +++ b/ui.h @@ -63,21 +63,27 @@ public: ShownState shown; static const int EDIT_NOTHING = 0; + // For multiple groups static const int EDIT_TIMES_REPEATED = 1; static const int EDIT_GROUP_NAME = 2; - static const int EDIT_LIGHT_DIRECTION = 3; - static const int EDIT_LIGHT_INTENSITY = 4; - static const int EDIT_COLOR = 5; - static const int EDIT_CHORD_TOLERANCE = 6; - static const int EDIT_CAMERA_TANGENT = 7; - static const int EDIT_EDGE_COLOR = 8; - static const int EDIT_EXPORT_SCALE = 9; + // For the configuraiton screen + static const int EDIT_LIGHT_DIRECTION = 10; + static const int EDIT_LIGHT_INTENSITY = 11; + static const int EDIT_COLOR = 12; + static const int EDIT_CHORD_TOLERANCE = 13; + static const int EDIT_MAX_SEGMENTS = 14; + static const int EDIT_CAMERA_TANGENT = 15; + static const int EDIT_EDGE_COLOR = 16; + static const int EDIT_EXPORT_SCALE = 17; + // For the helical sweep static const int EDIT_HELIX_TURNS = 20; static const int EDIT_HELIX_PITCH = 21; static const int EDIT_HELIX_DRADIUS = 22; - static const int EDIT_TTF_TEXT = 23; - static const int EDIT_STEP_DIM_FINISH = 30; - static const int EDIT_STEP_DIM_STEPS = 31; + // For TTF text + static const int EDIT_TTF_TEXT = 30; + // For the step dimension screen + static const int EDIT_STEP_DIM_FINISH = 40; + static const int EDIT_STEP_DIM_STEPS = 41; struct { int meaning; int i; @@ -145,6 +151,7 @@ public: static void ScreenChangeLightIntensity(int link, DWORD v); static void ScreenChangeColor(int link, DWORD v); static void ScreenChangeChordTolerance(int link, DWORD v); + static void ScreenChangeMaxSegments(int link, DWORD v); static void ScreenChangeCameraTangent(int link, DWORD v); static void ScreenChangeEdgeColor(int link, DWORD v); static void ScreenChangeExportScale(int link, DWORD v);