Skip to content

Commit

Permalink
Add an option to edit dimension immediately after adding.
Browse files Browse the repository at this point in the history
  • Loading branch information
vespakoen authored and whitequark committed Nov 26, 2019
1 parent 58f23aa commit dcdfdec
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -42,6 +42,8 @@ New constraint features:
constraints on line segments.
* Automatic creation of constraints no longer happens if the constraint
would have been redundant with other ones.
* New option to open the constraint editor for newly created constraints
with a value.

New export/import features:
* Three.js: allow configuring projection for exported model, and initially
Expand Down
8 changes: 8 additions & 0 deletions src/confscreen.cpp
Expand Up @@ -102,6 +102,11 @@ void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
}
}

void TextWindow::ScreenChangeImmediatelyEditDimension(int link, uint32_t v) {
SS.immediatelyEditDimension = !SS.immediatelyEditDimension;
SS.GW.Invalidate(/*clearPersistent=*/true);
}

void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) {
SS.showContourAreas = !SS.showContourAreas;
SS.GW.Invalidate();
Expand Down Expand Up @@ -342,6 +347,9 @@ void TextWindow::ShowConfiguration() {
SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s use turntable mouse navigation%E", &ScreenChangeTurntableNav,
SS.turntableNav ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%s edit newly added dimensions%E",
&ScreenChangeImmediatelyEditDimension,
SS.immediatelyEditDimension ? CHECK_TRUE : CHECK_FALSE);
Printf(false, "");
Printf(false, "%Ft autosave interval (in minutes)%E");
Printf(false, "%Ba %d %Fl%Ll%f[change]%E",
Expand Down
6 changes: 6 additions & 0 deletions src/constraint.cpp
Expand Up @@ -196,6 +196,9 @@ void Constraint::MenuConstrain(Command id) {
c.valA = 0;
c.ModifyToSatisfy();
AddConstraint(&c);
if (SS.immediatelyEditDimension) {
SS.GW.EditConstraint(c.h);
}
break;
}

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

c.ModifyToSatisfy();
AddConstraint(&c);
if (SS.immediatelyEditDimension) {
SS.GW.EditConstraint(c.h);
}
break;
}

Expand Down
120 changes: 62 additions & 58 deletions src/mouse.cpp
Expand Up @@ -1339,73 +1339,77 @@ void GraphicsWindow::MouseLeftUp(double mx, double my, bool shiftDown, bool ctrl
}
}

void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
if(window->IsEditorVisible()) return;
SS.TW.HideEditControl();

if(hover.constraint.v) {
constraintBeingEdited = hover.constraint;
ClearSuper();
void GraphicsWindow::EditConstraint(hConstraint constraint) {
constraintBeingEdited = constraint;
ClearSuper();

Constraint *c = SK.GetConstraint(constraintBeingEdited);
if(!c->HasLabel()) {
// Not meaningful to edit a constraint without a dimension
return;
}
if(c->reference) {
// Not meaningful to edit a reference dimension
return;
}
Constraint *c = SK.GetConstraint(constraintBeingEdited);
if(!c->HasLabel()) {
// Not meaningful to edit a constraint without a dimension
return;
}
if(c->reference) {
// Not meaningful to edit a reference dimension
return;
}

Vector p3 = c->GetLabelPos(GetCamera());
Point2d p2 = ProjectPoint(p3);
Vector p3 = c->GetLabelPos(GetCamera());
Point2d p2 = ProjectPoint(p3);

std::string editValue;
std::string editPlaceholder;
switch(c->type) {
case Constraint::Type::COMMENT:
editValue = c->comment;
editPlaceholder = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
break;
std::string editValue;
std::string editPlaceholder;
switch(c->type) {
case Constraint::Type::COMMENT:
editValue = c->comment;
editPlaceholder = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
break;

default: {
double value = fabs(c->valA);
default: {
double value = fabs(c->valA);

// If displayed as radius, also edit as radius.
if(c->type == Constraint::Type::DIAMETER && c->other)
value /= 2;
// If displayed as radius, also edit as radius.
if(c->type == Constraint::Type::DIAMETER && c->other)
value /= 2;

// Try showing value with default number of digits after decimal first.
if(c->type == Constraint::Type::LENGTH_RATIO) {
editValue = ssprintf("%.3f", value);
} else if(c->type == Constraint::Type::ANGLE) {
editValue = SS.DegreeToString(value);
} else {
editValue = SS.MmToString(value);
value /= SS.MmPerUnit();
}
// If that's not enough to represent it exactly, show the value with as many
// digits after decimal as required, up to 10.
int digits = 0;
while(fabs(std::stod(editValue) - value) > 1e-10) {
editValue = ssprintf("%.*f", digits, value);
digits++;
}
editPlaceholder = "10.000000";
break;
// Try showing value with default number of digits after decimal first.
if(c->type == Constraint::Type::LENGTH_RATIO) {
editValue = ssprintf("%.3f", value);
} else if(c->type == Constraint::Type::ANGLE) {
editValue = SS.DegreeToString(value);
} else {
editValue = SS.MmToString(value);
value /= SS.MmPerUnit();
}
// If that's not enough to represent it exactly, show the value with as many
// digits after decimal as required, up to 10.
int digits = 0;
while(fabs(std::stod(editValue) - value) > 1e-10) {
editValue = ssprintf("%.*f", digits, value);
digits++;
}
editPlaceholder = "10.000000";
break;
}
}

double width, height;
window->GetContentSize(&width, &height);
hStyle hs = c->disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
double capHeight = Style::TextHeight(hs);
double fontHeight = VectorFont::Builtin()->GetHeight(capHeight);
double editMinWidth = VectorFont::Builtin()->GetWidth(capHeight, editPlaceholder);
window->ShowEditor(p2.x + width / 2, height / 2 - p2.y,
fontHeight, editMinWidth,
/*isMonospace=*/false, editValue);
double width, height;
window->GetContentSize(&width, &height);
hStyle hs = c->disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
double capHeight = Style::TextHeight(hs);
double fontHeight = VectorFont::Builtin()->GetHeight(capHeight);
double editMinWidth = VectorFont::Builtin()->GetWidth(capHeight, editPlaceholder);
window->ShowEditor(p2.x + width / 2, height / 2 - p2.y,
fontHeight, editMinWidth,
/*isMonospace=*/false, editValue);
}

void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
if(window->IsEditorVisible()) return;
SS.TW.HideEditControl();

if(hover.constraint.v) {
EditConstraint(hover.constraint);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/solvespace.cpp
Expand Up @@ -72,6 +72,8 @@ void SolveSpaceUI::Init() {
drawBackFaces = settings->ThawBool("DrawBackFaces", true);
// Use turntable mouse navigation
turntableNav = settings->ThawBool("TurntableNav", false);
// Immediately edit dimension
immediatelyEditDimension = settings->ThawBool("ImmediatelyEditDimension", false);
// Check that contours are closed and not self-intersecting
checkClosedContour = settings->ThawBool("CheckClosedContour", true);
// Enable automatic constrains for lines
Expand Down Expand Up @@ -251,6 +253,8 @@ void SolveSpaceUI::Exit() {
settings->FreezeBool("CheckClosedContour", checkClosedContour);
// Use turntable mouse navigation
settings->FreezeBool("TurntableNav", turntableNav);
// Immediately edit dimensions
settings->FreezeBool("ImmediatelyEditDimension", immediatelyEditDimension);
// Enable automatic constrains for lines
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
// Export shaded triangles in a 2d view
Expand Down
1 change: 1 addition & 0 deletions src/solvespace.h
Expand Up @@ -587,6 +587,7 @@ class SolveSpaceUI {
bool showContourAreas;
bool checkClosedContour;
bool turntableNav;
bool immediatelyEditDimension;
bool automaticLineConstraints;
bool showToolbar;
Platform::Path screenshotFile;
Expand Down
2 changes: 2 additions & 0 deletions src/ui.h
Expand Up @@ -430,6 +430,7 @@ class TextWindow {
static void ScreenChangeShowContourAreas(int link, uint32_t v);
static void ScreenChangeCheckClosedContour(int link, uint32_t v);
static void ScreenChangeTurntableNav(int link, uint32_t v);
static void ScreenChangeImmediatelyEditDimension(int link, uint32_t v);
static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v);
static void ScreenChangePwlCurves(int link, uint32_t v);
static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);
Expand Down Expand Up @@ -690,6 +691,7 @@ class GraphicsWindow {
void RemoveConstraintsForPointBeingDeleted(hEntity hpt);
void FixConstraintsForRequestBeingDeleted(hRequest hr);
void FixConstraintsForPointBeingDeleted(hEntity hpt);
void EditConstraint(hConstraint constraint);

// A selected entity.
class Selection {
Expand Down

2 comments on commit dcdfdec

@rpavlik
Copy link
Contributor

@rpavlik rpavlik commented on dcdfdec Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ πŸŽ‰ 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
Copy link
Member

@ruevs ruevs commented on dcdfdec Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.