From 60cd95d6087d91db2756b272a72c8b70ce9dc174 Mon Sep 17 00:00:00 2001 From: ruevs Date: Mon, 16 Jan 2023 22:50:16 +0200 Subject: [PATCH] Dimension constraints only display mode improvements Make the `TriStateButton` class "universal" and use it in place of the `OccludedLinesButton` class which is now removed. Fix the tool-tips on the constraint button to show what will come instead of what is - just like the the occluded lines button. Also change the text of the tool-tips wording to be more clear and consistent with other buttons. Small stylistic and code formatting changes. --- src/drawconstraint.cpp | 11 ++-- src/graphicswin.cpp | 2 +- src/solvespace.cpp | 4 +- src/textwin.cpp | 138 ++++++++++++----------------------------- src/ui.h | 8 ++- 5 files changed, 50 insertions(+), 113 deletions(-) diff --git a/src/drawconstraint.cpp b/src/drawconstraint.cpp index 2a2acd60..e84c0ce4 100644 --- a/src/drawconstraint.cpp +++ b/src/drawconstraint.cpp @@ -449,19 +449,18 @@ void Constraint::DoArcForAngle(Canvas *canvas, Canvas::hStroke hcs, } bool Constraint::IsVisible() const { - if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_NOSHOW ) return false; + if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_NOSHOW) + return false; bool isDim = false; - if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM ) - switch (type){ + if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM) + switch(type) { case ConstraintBase::Type::ANGLE: case ConstraintBase::Type::DIAMETER: case ConstraintBase::Type::PT_PT_DISTANCE: case ConstraintBase::Type::PT_FACE_DISTANCE: case ConstraintBase::Type::PT_LINE_DISTANCE: - case ConstraintBase::Type::PT_PLANE_DISTANCE: - isDim = true; - break; + case ConstraintBase::Type::PT_PLANE_DISTANCE: isDim = true; break; default:; } diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index b397c0be..1c84251e 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -409,7 +409,7 @@ void GraphicsWindow::Init() { showNormals = true; showPoints = true; showConstruction = true; - showConstraints = GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL; + showConstraints = ShowConstraintMode::SCM_SHOW_ALL; showShaded = true; showEdges = true; showMesh = false; diff --git a/src/solvespace.cpp b/src/solvespace.cpp index a7c44360..68aaf5a4 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -720,9 +720,7 @@ void SolveSpaceUI::MenuFile(Command id) { // If the user is exporting something where it would be // inappropriate to include the constraints, then warn. if(SS.GW.showConstraints != GraphicsWindow::ShowConstraintMode::SCM_NOSHOW && - (dialog->GetFilename().HasExtension("txt") || - fabs(SS.exportOffset) > LENGTH_EPS)) - { + (dialog->GetFilename().HasExtension("txt") || fabs(SS.exportOffset) > LENGTH_EPS)) { Message(_("Constraints are currently shown, and will be exported " "in the toolpath. This is probably not what you want; " "hide them by clicking the link at the top of the " diff --git a/src/textwin.cpp b/src/textwin.cpp index 0b58523a..230cfbd4 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -57,7 +57,7 @@ public: /*outlineColor=*/{}); } if(!*(variable)) { - int s = 0, f = 24; + int s = 0, f = 23; RgbaColor color = { 255, 0, 0, 150 }; uiCanvas->DrawLine(x+s, y-s, x+f, y-f, color, 2); uiCanvas->DrawLine(x+s, y-f, x+f, y-s, color, 2); @@ -82,34 +82,39 @@ public: } } }; + #include class TriStateButton : public Button { public: - TriStateButton(GraphicsWindow::ShowConstraintMode*variable, - const std::array &states, - const std::array &tooltips, - const std::array &iconNames ):variable(variable),states(states),tooltips(tooltips),iconNames(iconNames){} + static const size_t tri = 3; - GraphicsWindow::ShowConstraintMode* variable; - std::array states; - std::array tooltips; - std::array iconNames; - std::shared_ptr icons[3]; + TriStateButton(unsigned *variable, const std::array &states, + const std::array &tooltips, + const std::array &iconNames) + : variable(variable), states(states), tooltips(tooltips), iconNames(iconNames) { + } + + unsigned *const variable; + const std::array states; + const std::array tooltips; + const std::array iconNames; + std::shared_ptr icons[tri]; std::string Tooltip() override { - for (size_t k = 0; k < 3; ++k ) - if ( *variable == states[k] ) return tooltips[k]; + for(size_t k = 0; k < tri; ++k) + if(*variable == states[k]) + return tooltips[k]; ssassert(false, "Unexpected mode"); } void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override { - for (size_t k = 0; k < 3;++k) + for(size_t k = 0; k < tri; ++k) if(icons[k] == nullptr) icons[k] = LoadPng("icons/text-window/" + iconNames[k] + ".png"); std::shared_ptr icon; - for (size_t k = 0; k < 3; ++k ) - if ( *variable == states[k] ){ + for(size_t k = 0; k < tri; ++k) + if(*variable == states[k]) { icon = icons[k]; break; } @@ -117,7 +122,7 @@ public: uiCanvas->DrawPixmap(icon, x, y - 24); if(asHovered) { uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26, - /*fillColor=*/{ 255, 255, 0, 75 }, + /*fillColor=*/{255, 255, 0, 75}, /*outlineColor=*/{}); } } @@ -126,9 +131,9 @@ public: int AdvanceWidth() override { return 32; } void Click() override { - for (size_t k = 0;k < 3;++k) - if ( *variable == states[k] ){ - *variable = states[(k+1)%3]; + for(size_t k = 0; k < tri; ++k) + if(*variable == states[k]) { + *variable = states[(k + 1) % tri]; break; } @@ -138,77 +143,6 @@ public: } }; - -class OccludedLinesButton : public Button { -public: - std::shared_ptr visibleIcon; - std::shared_ptr stippledIcon; - std::shared_ptr invisibleIcon; - - std::string Tooltip() override { - switch(SS.GW.drawOccludedAs) { - case GraphicsWindow::DrawOccludedAs::INVISIBLE: - return "Stipple occluded lines"; - - case GraphicsWindow::DrawOccludedAs::STIPPLED: - return "Draw occluded lines"; - - case GraphicsWindow::DrawOccludedAs::VISIBLE: - return "Don't draw occluded lines"; - - default: ssassert(false, "Unexpected mode"); - } - } - - void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override { - if(visibleIcon == NULL) { - visibleIcon = LoadPng("icons/text-window/occluded-visible.png"); - } - if(stippledIcon == NULL) { - stippledIcon = LoadPng("icons/text-window/occluded-stippled.png"); - } - if(invisibleIcon == NULL) { - invisibleIcon = LoadPng("icons/text-window/occluded-invisible.png"); - } - - std::shared_ptr icon; - switch(SS.GW.drawOccludedAs) { - case GraphicsWindow::DrawOccludedAs::INVISIBLE: icon = invisibleIcon; break; - case GraphicsWindow::DrawOccludedAs::STIPPLED: icon = stippledIcon; break; - case GraphicsWindow::DrawOccludedAs::VISIBLE: icon = visibleIcon; break; - } - - uiCanvas->DrawPixmap(icon, x, y - 24); - if(asHovered) { - uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26, - /*fillColor=*/{ 255, 255, 0, 75 }, - /*outlineColor=*/{}); - } - } - - int AdvanceWidth() override { return 32; } - - void Click() override { - switch(SS.GW.drawOccludedAs) { - case GraphicsWindow::DrawOccludedAs::INVISIBLE: - SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::STIPPLED; - break; - - case GraphicsWindow::DrawOccludedAs::STIPPLED: - SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::VISIBLE; - break; - - case GraphicsWindow::DrawOccludedAs::VISIBLE: - SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::INVISIBLE; - break; - } - - SS.GenerateAll(); - SS.GW.Invalidate(); - SS.ScheduleShowTW(); - } -}; - static SpacerButton spacerButton; static ShowHideButton workplanesButton = @@ -219,15 +153,13 @@ static ShowHideButton pointsButton = { &(SS.GW.showPoints), "point", "points" }; static ShowHideButton constructionButton = { &(SS.GW.showConstruction), "construction", "construction entities" }; -static TriStateButton constraintsButton = - { &(SS.GW.showConstraints), - {GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL, - GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM, - GraphicsWindow::ShowConstraintMode::SCM_NOSHOW}, - {"constraints and dimensions","dimensions","none"}, - {"constraint","constraint-dimo","constraint-wo"} - }; - +static TriStateButton constraintsButton = { + (unsigned *)(&(SS.GW.showConstraints)), + {(unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL, + (unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM, + (unsigned)GraphicsWindow::ShowConstraintMode::SCM_NOSHOW}, + {"Show only dimensions", "Hide constraints and dimensions", "Show constraints and dimensions"}, + {"constraint", "constraint-dimo", "constraint-wo"}}; static FacesButton facesButton; static ShowHideButton shadedButton = { &(SS.GW.showShaded), "shaded", "shaded view of solid model" }; @@ -237,7 +169,13 @@ static ShowHideButton outlinesButton = { &(SS.GW.showOutlines), "outlines", "outline of solid model" }; static ShowHideButton meshButton = { &(SS.GW.showMesh), "mesh", "triangle mesh of solid model" }; -static OccludedLinesButton occludedLinesButton; +static TriStateButton occludedLinesButton = { + (unsigned *)(&(SS.GW.drawOccludedAs)), + {(unsigned)GraphicsWindow::DrawOccludedAs::INVISIBLE, + (unsigned)GraphicsWindow::DrawOccludedAs::STIPPLED, + (unsigned)GraphicsWindow::DrawOccludedAs::VISIBLE}, + {"Stipple occluded lines", "Draw occluded lines", "Don't draw occluded lines"}, + {"occluded-invisible", "occluded-stippled", "occluded-visible"}}; static Button *buttons[] = { &workplanesButton, diff --git a/src/ui.h b/src/ui.h index 67eb248f..5b2b1886 100644 --- a/src/ui.h +++ b/src/ui.h @@ -801,14 +801,16 @@ public: bool ToolbarMouseDown(int x, int y); Command toolbarHovered; - enum class ShowConstraintMode{SCM_NOSHOW,SCM_SHOW_ALL,SCM_SHOW_DIM}; // This sets what gets displayed. bool showWorkplanes; bool showNormals; bool showPoints; bool showConstruction; - ShowConstraintMode showConstraints; + + enum class ShowConstraintMode : unsigned { SCM_NOSHOW, SCM_SHOW_ALL, SCM_SHOW_DIM }; + ShowConstraintMode showConstraints; + bool showTextWindow; bool showShaded; bool showEdges; @@ -819,7 +821,7 @@ public: bool showMesh; void ToggleBool(bool *v); - enum class DrawOccludedAs { INVISIBLE, STIPPLED, VISIBLE }; + enum class DrawOccludedAs : unsigned { INVISIBLE, STIPPLED, VISIBLE }; DrawOccludedAs drawOccludedAs; bool showSnapGrid;