Skip to content

Commit

Permalink
Make the redundant constraint timeout a configuration value and add t…
Browse files Browse the repository at this point in the history
…he config UI elements to edit that value.
  • Loading branch information
phkahler committed Sep 16, 2020
1 parent 6157084 commit 668fe6f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/confscreen.cpp
Expand Up @@ -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)");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/generate.cpp
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/sketch.h
Expand Up @@ -189,6 +189,7 @@ class Group {
struct {
SolveResult how;
int dof;
int findToFixTimeout;
bool timeout;
List<hConstraint> remove;
} solved;
Expand Down
4 changes: 4 additions & 0 deletions src/solvespace.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/solvespace.h
Expand Up @@ -268,7 +268,8 @@ class System {
void EvalJacobian();

void WriteEquationsExceptFor(hConstraint hc, Group *g);
void FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *bad, bool forceDofCheck);
void FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *bad,
bool forceDofCheck);
void SolveBySubstitution();

bool IsDragged(hParam p);
Expand Down Expand Up @@ -562,6 +563,7 @@ class SolveSpaceUI {
int maxSegments;
double exportChordTol;
int exportMaxSegments;
int timeoutRedundantConstr; //milliseconds
double cameraTangent;
double gridSpacing;
double exportScale;
Expand Down
2 changes: 1 addition & 1 deletion src/system.cpp
Expand Up @@ -361,7 +361,7 @@ void System::FindWhichToRemoveToFixJacobian(Group *g, List<hConstraint> *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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui.h
Expand Up @@ -316,6 +316,7 @@ class TextWindow {
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
Expand Down Expand Up @@ -488,6 +489,7 @@ class TextWindow {
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);
Expand Down

0 comments on commit 668fe6f

Please sign in to comment.