From 668fe6f493eb96e9b4add37b6dbe9b82070cd9cc Mon Sep 17 00:00:00 2001 From: phkahler <14852918+phkahler@users.noreply.github.com> Date: Sat, 12 Sep 2020 15:52:27 -0400 Subject: [PATCH] Make the redundant constraint timeout a configuration value and add the config UI elements to edit that value. --- src/confscreen.cpp | 20 ++++++++++++++++++++ src/generate.cpp | 1 + src/sketch.h | 1 + src/solvespace.cpp | 4 ++++ src/solvespace.h | 4 +++- src/system.cpp | 2 +- src/ui.h | 2 ++ 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/confscreen.cpp b/src/confscreen.cpp index 347d77b..07c42b7 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -204,6 +204,11 @@ void TextWindow::ScreenChangeAutosaveInterval(int link, uint32_t v) { SS.TW.edit.meaning = Edit::AUTOSAVE_INTERVAL; } +void TextWindow::ScreenChangeFindConstraintTimeout(int link, uint32_t v) { + SS.TW.ShowEditControl(3, std::to_string(SS.timeoutRedundantConstr)); + SS.TW.edit.meaning = Edit::FIND_CONSTRAINT_TIMEOUT; +} + void TextWindow::ShowConfiguration() { int i; Printf(true, "%Ft user color (r, g, b)"); @@ -371,6 +376,10 @@ void TextWindow::ShowConfiguration() { Printf(false, "%Ft autosave interval (in minutes)%E"); Printf(false, "%Ba %d %Fl%Ll%f[change]%E", SS.autosaveInterval, &ScreenChangeAutosaveInterval); + Printf(false, ""); + Printf(false, "%Ft redundant constraint timeout (in ms)%E"); + Printf(false, "%Ba %d %Fl%Ll%f[change]%E", + SS.timeoutRedundantConstr, &ScreenChangeFindConstraintTimeout); if(canvas) { const char *gl_vendor, *gl_renderer, *gl_version; @@ -542,6 +551,17 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) { } break; } + case Edit::FIND_CONSTRAINT_TIMEOUT: { + int timeout = atoi(s.c_str()); + if(timeout) { + if(timeout >= 1) { + SS.timeoutRedundantConstr = timeout; + } else { + SS.timeoutRedundantConstr = 1000; + } + } + break; + } default: return false; } diff --git a/src/generate.cpp b/src/generate.cpp index 70b57c1..fdda994 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -533,6 +533,7 @@ void SolveSpaceUI::SolveGroup(hGroup hg, bool andFindFree) { WriteEqSystemForGroup(hg); Group *g = SK.GetGroup(hg); g->solved.remove.Clear(); + g->solved.findToFixTimeout = SS.timeoutRedundantConstr; SolveResult how = sys.Solve(g, NULL, &(g->solved.dof), &(g->solved.remove), diff --git a/src/sketch.h b/src/sketch.h index 65d9c15..869e0b6 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -189,6 +189,7 @@ public: struct { SolveResult how; int dof; + int findToFixTimeout; bool timeout; List remove; } solved; diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 697e740..d68cedf 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -51,6 +51,8 @@ void SolveSpaceUI::Init() { exportChordTol = settings->ThawFloat("ExportChordTolerance", 0.1); // Max pwl segments to generate exportMaxSegments = settings->ThawInt("ExportMaxSegments", 64); + // Timeout value for finding redundant constrains (ms) + timeoutRedundantConstr = settings->ThawInt("TimeoutRedundantConstraints", 1000); // View units viewUnits = (Unit)settings->ThawInt("ViewUnits", (uint32_t)Unit::MM); // Number of digits after the decimal point @@ -231,6 +233,8 @@ void SolveSpaceUI::Exit() { settings->FreezeFloat("ExportChordTolerance", (float)exportChordTol); // Export Max pwl segments to generate settings->FreezeInt("ExportMaxSegments", (uint32_t)exportMaxSegments); + // Timeout for finding which constraints to fix Jacobian + settings->FreezeInt("TimeoutRedundantConstraints", (uint32_t)timeoutRedundantConstr); // View units settings->FreezeInt("ViewUnits", (uint32_t)viewUnits); // Number of digits after the decimal point diff --git a/src/solvespace.h b/src/solvespace.h index 425e4c8..795c888 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -268,7 +268,8 @@ public: void EvalJacobian(); void WriteEquationsExceptFor(hConstraint hc, Group *g); - void FindWhichToRemoveToFixJacobian(Group *g, List *bad, bool forceDofCheck); + void FindWhichToRemoveToFixJacobian(Group *g, List *bad, + bool forceDofCheck); void SolveBySubstitution(); bool IsDragged(hParam p); @@ -562,6 +563,7 @@ public: int maxSegments; double exportChordTol; int exportMaxSegments; + int timeoutRedundantConstr; //milliseconds double cameraTangent; double gridSpacing; double exportScale; diff --git a/src/system.cpp b/src/system.cpp index 2b471e4..1119c34 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -361,7 +361,7 @@ void System::FindWhichToRemoveToFixJacobian(Group *g, List *bad, bo for(a = 0; a < 2; a++) { for(auto &con : SK.constraint) { - if((GetMilliseconds() - time) > 1500) { // todo: make timeout configurable + if((GetMilliseconds() - time) > g->solved.findToFixTimeout) { g->solved.timeout = true; return; } diff --git a/src/ui.h b/src/ui.h index 9e9bf50..b44d566 100644 --- a/src/ui.h +++ b/src/ui.h @@ -316,6 +316,7 @@ public: G_CODE_PLUNGE_FEED = 115, AUTOSAVE_INTERVAL = 116, LIGHT_AMBIENT = 117, + FIND_CONSTRAINT_TIMEOUT = 118, // For TTF text TTF_TEXT = 300, // For the step dimension screen @@ -488,6 +489,7 @@ public: static void ScreenChangeExportOffset(int link, uint32_t v); static void ScreenChangeGCodeParameter(int link, uint32_t v); static void ScreenChangeAutosaveInterval(int link, uint32_t v); + static void ScreenChangeFindConstraintTimeout(int link, uint32_t v); static void ScreenChangeStyleName(int link, uint32_t v); static void ScreenChangeStyleMetric(int link, uint32_t v); static void ScreenChangeStyleTextAngle(int link, uint32_t v);