Skip to content

Commit dcdfdec

Browse files
vespakoenwhitequark
authored andcommittedNov 26, 2019
Add an option to edit dimension immediately after adding.
1 parent 58f23aa commit dcdfdec

File tree

7 files changed

+85
-58
lines changed

7 files changed

+85
-58
lines changed
 

Diff for: ‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ New constraint features:
4242
constraints on line segments.
4343
* Automatic creation of constraints no longer happens if the constraint
4444
would have been redundant with other ones.
45+
* New option to open the constraint editor for newly created constraints
46+
with a value.
4547

4648
New export/import features:
4749
* Three.js: allow configuring projection for exported model, and initially

Diff for: ‎src/confscreen.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
102102
}
103103
}
104104

105+
void TextWindow::ScreenChangeImmediatelyEditDimension(int link, uint32_t v) {
106+
SS.immediatelyEditDimension = !SS.immediatelyEditDimension;
107+
SS.GW.Invalidate(/*clearPersistent=*/true);
108+
}
109+
105110
void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) {
106111
SS.showContourAreas = !SS.showContourAreas;
107112
SS.GW.Invalidate();
@@ -342,6 +347,9 @@ void TextWindow::ShowConfiguration() {
342347
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
343348
Printf(false, " %Fd%f%Ll%s use turntable mouse navigation%E", &ScreenChangeTurntableNav,
344349
SS.turntableNav ? CHECK_TRUE : CHECK_FALSE);
350+
Printf(false, " %Fd%f%Ll%s edit newly added dimensions%E",
351+
&ScreenChangeImmediatelyEditDimension,
352+
SS.immediatelyEditDimension ? CHECK_TRUE : CHECK_FALSE);
345353
Printf(false, "");
346354
Printf(false, "%Ft autosave interval (in minutes)%E");
347355
Printf(false, "%Ba %d %Fl%Ll%f[change]%E",

Diff for: ‎src/constraint.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ void Constraint::MenuConstrain(Command id) {
196196
c.valA = 0;
197197
c.ModifyToSatisfy();
198198
AddConstraint(&c);
199+
if (SS.immediatelyEditDimension) {
200+
SS.GW.EditConstraint(c.h);
201+
}
199202
break;
200203
}
201204

@@ -607,6 +610,9 @@ void Constraint::MenuConstrain(Command id) {
607610

608611
c.ModifyToSatisfy();
609612
AddConstraint(&c);
613+
if (SS.immediatelyEditDimension) {
614+
SS.GW.EditConstraint(c.h);
615+
}
610616
break;
611617
}
612618

Diff for: ‎src/mouse.cpp

+62-58
Original file line numberDiff line numberDiff line change
@@ -1339,73 +1339,77 @@ void GraphicsWindow::MouseLeftUp(double mx, double my, bool shiftDown, bool ctrl
13391339
}
13401340
}
13411341

1342-
void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
1343-
if(window->IsEditorVisible()) return;
1344-
SS.TW.HideEditControl();
1345-
1346-
if(hover.constraint.v) {
1347-
constraintBeingEdited = hover.constraint;
1348-
ClearSuper();
1342+
void GraphicsWindow::EditConstraint(hConstraint constraint) {
1343+
constraintBeingEdited = constraint;
1344+
ClearSuper();
13491345

1350-
Constraint *c = SK.GetConstraint(constraintBeingEdited);
1351-
if(!c->HasLabel()) {
1352-
// Not meaningful to edit a constraint without a dimension
1353-
return;
1354-
}
1355-
if(c->reference) {
1356-
// Not meaningful to edit a reference dimension
1357-
return;
1358-
}
1346+
Constraint *c = SK.GetConstraint(constraintBeingEdited);
1347+
if(!c->HasLabel()) {
1348+
// Not meaningful to edit a constraint without a dimension
1349+
return;
1350+
}
1351+
if(c->reference) {
1352+
// Not meaningful to edit a reference dimension
1353+
return;
1354+
}
13591355

1360-
Vector p3 = c->GetLabelPos(GetCamera());
1361-
Point2d p2 = ProjectPoint(p3);
1356+
Vector p3 = c->GetLabelPos(GetCamera());
1357+
Point2d p2 = ProjectPoint(p3);
13621358

1363-
std::string editValue;
1364-
std::string editPlaceholder;
1365-
switch(c->type) {
1366-
case Constraint::Type::COMMENT:
1367-
editValue = c->comment;
1368-
editPlaceholder = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1369-
break;
1359+
std::string editValue;
1360+
std::string editPlaceholder;
1361+
switch(c->type) {
1362+
case Constraint::Type::COMMENT:
1363+
editValue = c->comment;
1364+
editPlaceholder = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1365+
break;
13701366

1371-
default: {
1372-
double value = fabs(c->valA);
1367+
default: {
1368+
double value = fabs(c->valA);
13731369

1374-
// If displayed as radius, also edit as radius.
1375-
if(c->type == Constraint::Type::DIAMETER && c->other)
1376-
value /= 2;
1370+
// If displayed as radius, also edit as radius.
1371+
if(c->type == Constraint::Type::DIAMETER && c->other)
1372+
value /= 2;
13771373

1378-
// Try showing value with default number of digits after decimal first.
1379-
if(c->type == Constraint::Type::LENGTH_RATIO) {
1380-
editValue = ssprintf("%.3f", value);
1381-
} else if(c->type == Constraint::Type::ANGLE) {
1382-
editValue = SS.DegreeToString(value);
1383-
} else {
1384-
editValue = SS.MmToString(value);
1385-
value /= SS.MmPerUnit();
1386-
}
1387-
// If that's not enough to represent it exactly, show the value with as many
1388-
// digits after decimal as required, up to 10.
1389-
int digits = 0;
1390-
while(fabs(std::stod(editValue) - value) > 1e-10) {
1391-
editValue = ssprintf("%.*f", digits, value);
1392-
digits++;
1393-
}
1394-
editPlaceholder = "10.000000";
1395-
break;
1374+
// Try showing value with default number of digits after decimal first.
1375+
if(c->type == Constraint::Type::LENGTH_RATIO) {
1376+
editValue = ssprintf("%.3f", value);
1377+
} else if(c->type == Constraint::Type::ANGLE) {
1378+
editValue = SS.DegreeToString(value);
1379+
} else {
1380+
editValue = SS.MmToString(value);
1381+
value /= SS.MmPerUnit();
13961382
}
1383+
// If that's not enough to represent it exactly, show the value with as many
1384+
// digits after decimal as required, up to 10.
1385+
int digits = 0;
1386+
while(fabs(std::stod(editValue) - value) > 1e-10) {
1387+
editValue = ssprintf("%.*f", digits, value);
1388+
digits++;
1389+
}
1390+
editPlaceholder = "10.000000";
1391+
break;
13971392
}
1393+
}
13981394

1399-
double width, height;
1400-
window->GetContentSize(&width, &height);
1401-
hStyle hs = c->disp.style;
1402-
if(hs.v == 0) hs.v = Style::CONSTRAINT;
1403-
double capHeight = Style::TextHeight(hs);
1404-
double fontHeight = VectorFont::Builtin()->GetHeight(capHeight);
1405-
double editMinWidth = VectorFont::Builtin()->GetWidth(capHeight, editPlaceholder);
1406-
window->ShowEditor(p2.x + width / 2, height / 2 - p2.y,
1407-
fontHeight, editMinWidth,
1408-
/*isMonospace=*/false, editValue);
1395+
double width, height;
1396+
window->GetContentSize(&width, &height);
1397+
hStyle hs = c->disp.style;
1398+
if(hs.v == 0) hs.v = Style::CONSTRAINT;
1399+
double capHeight = Style::TextHeight(hs);
1400+
double fontHeight = VectorFont::Builtin()->GetHeight(capHeight);
1401+
double editMinWidth = VectorFont::Builtin()->GetWidth(capHeight, editPlaceholder);
1402+
window->ShowEditor(p2.x + width / 2, height / 2 - p2.y,
1403+
fontHeight, editMinWidth,
1404+
/*isMonospace=*/false, editValue);
1405+
}
1406+
1407+
void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
1408+
if(window->IsEditorVisible()) return;
1409+
SS.TW.HideEditControl();
1410+
1411+
if(hover.constraint.v) {
1412+
EditConstraint(hover.constraint);
14091413
}
14101414
}
14111415

Diff for: ‎src/solvespace.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void SolveSpaceUI::Init() {
7272
drawBackFaces = settings->ThawBool("DrawBackFaces", true);
7373
// Use turntable mouse navigation
7474
turntableNav = settings->ThawBool("TurntableNav", false);
75+
// Immediately edit dimension
76+
immediatelyEditDimension = settings->ThawBool("ImmediatelyEditDimension", false);
7577
// Check that contours are closed and not self-intersecting
7678
checkClosedContour = settings->ThawBool("CheckClosedContour", true);
7779
// Enable automatic constrains for lines
@@ -251,6 +253,8 @@ void SolveSpaceUI::Exit() {
251253
settings->FreezeBool("CheckClosedContour", checkClosedContour);
252254
// Use turntable mouse navigation
253255
settings->FreezeBool("TurntableNav", turntableNav);
256+
// Immediately edit dimensions
257+
settings->FreezeBool("ImmediatelyEditDimension", immediatelyEditDimension);
254258
// Enable automatic constrains for lines
255259
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
256260
// Export shaded triangles in a 2d view

Diff for: ‎src/solvespace.h

+1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ class SolveSpaceUI {
587587
bool showContourAreas;
588588
bool checkClosedContour;
589589
bool turntableNav;
590+
bool immediatelyEditDimension;
590591
bool automaticLineConstraints;
591592
bool showToolbar;
592593
Platform::Path screenshotFile;

Diff for: ‎src/ui.h

+2
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ class TextWindow {
430430
static void ScreenChangeShowContourAreas(int link, uint32_t v);
431431
static void ScreenChangeCheckClosedContour(int link, uint32_t v);
432432
static void ScreenChangeTurntableNav(int link, uint32_t v);
433+
static void ScreenChangeImmediatelyEditDimension(int link, uint32_t v);
433434
static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v);
434435
static void ScreenChangePwlCurves(int link, uint32_t v);
435436
static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);
@@ -690,6 +691,7 @@ class GraphicsWindow {
690691
void RemoveConstraintsForPointBeingDeleted(hEntity hpt);
691692
void FixConstraintsForRequestBeingDeleted(hRequest hr);
692693
void FixConstraintsForPointBeingDeleted(hEntity hpt);
694+
void EditConstraint(hConstraint constraint);
693695

694696
// A selected entity.
695697
class Selection {

2 commit comments

Comments
 (2)

rpavlik commented on Dec 8, 2019

@rpavlik
Contributor

🎉 🎉 thank you! this is amazing! really a workflow booster - I don't have to go back to the mouse between hitting d and typing the dimension to double-click it

ruevs commented on Dec 8, 2019

@ruevs
Member

The option is nice indeed. I tried it last week on master and I think I'll keep it on.

Please sign in to comment.