Add an option to edit dimension immediately after adding.

pull/516/head
Koen Schmeets 2019-11-26 23:34:53 +01:00 committed by whitequark
parent 58f23aa061
commit dcdfdec564
7 changed files with 89 additions and 62 deletions

View File

@ -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

View File

@ -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();
@ -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",

View File

@ -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;
}
@ -607,6 +610,9 @@ void Constraint::MenuConstrain(Command id) {
c.ModifyToSatisfy();
AddConstraint(&c);
if (SS.immediatelyEditDimension) {
SS.GW.EditConstraint(c.h);
}
break;
}

View File

@ -1339,73 +1339,77 @@ void GraphicsWindow::MouseLeftUp(double mx, double my, bool shiftDown, bool ctrl
}
}
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;
}
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;
default: {
double value = fabs(c->valA);
// 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;
}
}
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) {
constraintBeingEdited = hover.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;
}
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;
default: {
double value = fabs(c->valA);
// 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;
}
}
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);
EditConstraint(hover.constraint);
}
}

View File

@ -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
@ -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

View File

@ -587,6 +587,7 @@ public:
bool showContourAreas;
bool checkClosedContour;
bool turntableNav;
bool immediatelyEditDimension;
bool automaticLineConstraints;
bool showToolbar;
Platform::Path screenshotFile;

View File

@ -430,6 +430,7 @@ public:
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);
@ -690,6 +691,7 @@ public:
void RemoveConstraintsForPointBeingDeleted(hEntity hpt);
void FixConstraintsForRequestBeingDeleted(hRequest hr);
void FixConstraintsForPointBeingDeleted(hEntity hpt);
void EditConstraint(hConstraint constraint);
// A selected entity.
class Selection {