diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index da12ec12..2862b5f4 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -268,6 +268,8 @@ add_resources( icons/graphics-window/trim.png icons/graphics-window/vert.png icons/text-window/constraint.png + icons/text-window/constraint-dimo.png + icons/text-window/constraint-wo.png icons/text-window/construction.png icons/text-window/edges.png icons/text-window/faces.png diff --git a/res/icons/text-window/constraint-dimo.png b/res/icons/text-window/constraint-dimo.png new file mode 100644 index 00000000..b48715e0 Binary files /dev/null and b/res/icons/text-window/constraint-dimo.png differ diff --git a/res/icons/text-window/constraint-wo.png b/res/icons/text-window/constraint-wo.png new file mode 100644 index 00000000..1fbb7dd7 Binary files /dev/null and b/res/icons/text-window/constraint-wo.png differ diff --git a/src/drawconstraint.cpp b/src/drawconstraint.cpp index 02aababb..2a2acd60 100644 --- a/src/drawconstraint.cpp +++ b/src/drawconstraint.cpp @@ -449,21 +449,39 @@ void Constraint::DoArcForAngle(Canvas *canvas, Canvas::hStroke hcs, } bool Constraint::IsVisible() const { - if(!SS.GW.showConstraints) return false; - Group *g = SK.GetGroup(group); - // If the group is hidden, then the constraints are hidden and not - // able to be selected. - if(!(g->visible)) return false; - // And likewise if the group is not the active group; except for comments - // with an assigned style. - if(g->h != SS.GW.activeGroup && !(type == Type::COMMENT && disp.style.v)) { - 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){ + 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; + default:; + } + + if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL || isDim ) { + Group *g = SK.GetGroup(group); + // If the group is hidden, then the constraints are hidden and not + // able to be selected. + if(!(g->visible)) return false; + // And likewise if the group is not the active group; except for comments + // with an assigned style. + if(g->h != SS.GW.activeGroup && !(type == Type::COMMENT && disp.style.v)) { + return false; + } + if(disp.style.v) { + Style *s = Style::Get(disp.style); + if(!s->visible) return false; + } + return true; } - if(disp.style.v) { - Style *s = Style::Get(disp.style); - if(!s->visible) return false; - } - return true; + return false; } bool Constraint::DoLineExtend(Canvas *canvas, Canvas::hStroke hcs, diff --git a/src/export.cpp b/src/export.cpp index f1c331fd..7a54581e 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -227,7 +227,7 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const Platform::Path &filename, bool } } - if(SS.GW.showConstraints) { + if(SS.GW.showConstraints != GraphicsWindow::ShowConstraintMode::SCM_NOSHOW ) { if(!out->OutputConstraints(&SK.constraint)) { GetEdgesCanvas canvas = {}; canvas.camera = SS.GW.GetCamera(); diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 3d7a69b7..b397c0be 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -409,7 +409,7 @@ void GraphicsWindow::Init() { showNormals = true; showPoints = true; showConstruction = true; - showConstraints = true; + showConstraints = GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL; showShaded = true; showEdges = true; showMesh = false; diff --git a/src/solvespace.cpp b/src/solvespace.cpp index b0e48016..a7c44360 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -719,7 +719,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 && + if(SS.GW.showConstraints != GraphicsWindow::ShowConstraintMode::SCM_NOSHOW && (dialog->GetFilename().HasExtension("txt") || fabs(SS.exportOffset) > LENGTH_EPS)) { diff --git a/src/textscreens.cpp b/src/textscreens.cpp index ba5d977c..c73361f9 100644 --- a/src/textscreens.cpp +++ b/src/textscreens.cpp @@ -194,8 +194,7 @@ void TextWindow::ScreenHoverRequest(int link, uint32_t v) { SS.GW.hover.emphasized = true; } void TextWindow::ScreenHoverConstraint(int link, uint32_t v) { - if(!SS.GW.showConstraints) return; - + if( SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_NOSHOW ) return; hConstraint hc = { v }; SS.GW.hover.Clear(); SS.GW.hover.constraint = hc; diff --git a/src/textwin.cpp b/src/textwin.cpp index b68c0680..0b58523a 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -82,6 +82,62 @@ 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){} + + GraphicsWindow::ShowConstraintMode* variable; + std::array states; + std::array tooltips; + std::array iconNames; + std::shared_ptr icons[3]; + + std::string Tooltip() override { + for (size_t k = 0; k < 3; ++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) + 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] ){ + icon = icons[k]; + 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 { + for (size_t k = 0;k < 3;++k) + if ( *variable == states[k] ){ + *variable = states[(k+1)%3]; + break; + } + + SS.GenerateAll(); + SS.GW.Invalidate(); + SS.ScheduleShowTW(); + } +}; + class OccludedLinesButton : public Button { public: @@ -163,8 +219,15 @@ static ShowHideButton pointsButton = { &(SS.GW.showPoints), "point", "points" }; static ShowHideButton constructionButton = { &(SS.GW.showConstruction), "construction", "construction entities" }; -static ShowHideButton constraintsButton = - { &(SS.GW.showConstraints), "constraint", "constraints and dimensions" }; +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 FacesButton facesButton; static ShowHideButton shadedButton = { &(SS.GW.showShaded), "shaded", "shaded view of solid model" }; diff --git a/src/ui.h b/src/ui.h index fb777a87..67eb248f 100644 --- a/src/ui.h +++ b/src/ui.h @@ -801,12 +801,14 @@ 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; - bool showConstraints; + ShowConstraintMode showConstraints; bool showTextWindow; bool showShaded; bool showEdges;