Skip to content

Commit 60cd95d

Browse files
ruevsphkahler
authored andcommitted
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.
1 parent a0219b2 commit 60cd95d

File tree

5 files changed

+50
-113
lines changed

5 files changed

+50
-113
lines changed

src/drawconstraint.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,18 @@ void Constraint::DoArcForAngle(Canvas *canvas, Canvas::hStroke hcs,
449449
}
450450

451451
bool Constraint::IsVisible() const {
452-
if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_NOSHOW ) return false;
452+
if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_NOSHOW)
453+
return false;
453454
bool isDim = false;
454455

455-
if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM )
456-
switch (type){
456+
if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM)
457+
switch(type) {
457458
case ConstraintBase::Type::ANGLE:
458459
case ConstraintBase::Type::DIAMETER:
459460
case ConstraintBase::Type::PT_PT_DISTANCE:
460461
case ConstraintBase::Type::PT_FACE_DISTANCE:
461462
case ConstraintBase::Type::PT_LINE_DISTANCE:
462-
case ConstraintBase::Type::PT_PLANE_DISTANCE:
463-
isDim = true;
464-
break;
463+
case ConstraintBase::Type::PT_PLANE_DISTANCE: isDim = true; break;
465464
default:;
466465
}
467466

src/graphicswin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void GraphicsWindow::Init() {
409409
showNormals = true;
410410
showPoints = true;
411411
showConstruction = true;
412-
showConstraints = GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL;
412+
showConstraints = ShowConstraintMode::SCM_SHOW_ALL;
413413
showShaded = true;
414414
showEdges = true;
415415
showMesh = false;

src/solvespace.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,7 @@ void SolveSpaceUI::MenuFile(Command id) {
720720
// If the user is exporting something where it would be
721721
// inappropriate to include the constraints, then warn.
722722
if(SS.GW.showConstraints != GraphicsWindow::ShowConstraintMode::SCM_NOSHOW &&
723-
(dialog->GetFilename().HasExtension("txt") ||
724-
fabs(SS.exportOffset) > LENGTH_EPS))
725-
{
723+
(dialog->GetFilename().HasExtension("txt") || fabs(SS.exportOffset) > LENGTH_EPS)) {
726724
Message(_("Constraints are currently shown, and will be exported "
727725
"in the toolpath. This is probably not what you want; "
728726
"hide them by clicking the link at the top of the "

src/textwin.cpp

+38-100
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ShowHideButton : public Button {
5757
/*outlineColor=*/{});
5858
}
5959
if(!*(variable)) {
60-
int s = 0, f = 24;
60+
int s = 0, f = 23;
6161
RgbaColor color = { 255, 0, 0, 150 };
6262
uiCanvas->DrawLine(x+s, y-s, x+f, y-f, color, 2);
6363
uiCanvas->DrawLine(x+s, y-f, x+f, y-s, color, 2);
@@ -82,42 +82,47 @@ class FacesButton : public ShowHideButton {
8282
}
8383
}
8484
};
85+
8586
#include <array>
8687
class TriStateButton : public Button {
8788
public:
88-
TriStateButton(GraphicsWindow::ShowConstraintMode*variable,
89-
const std::array<GraphicsWindow::ShowConstraintMode,3> &states,
90-
const std::array<std::string,3> &tooltips,
91-
const std::array<std::string,3> &iconNames ):variable(variable),states(states),tooltips(tooltips),iconNames(iconNames){}
89+
static const size_t tri = 3;
90+
91+
TriStateButton(unsigned *variable, const std::array<unsigned, tri> &states,
92+
const std::array<std::string, tri> &tooltips,
93+
const std::array<std::string, tri> &iconNames)
94+
: variable(variable), states(states), tooltips(tooltips), iconNames(iconNames) {
95+
}
9296

93-
GraphicsWindow::ShowConstraintMode* variable;
94-
std::array<GraphicsWindow::ShowConstraintMode,3> states;
95-
std::array<std::string,3> tooltips;
96-
std::array<std::string,3> iconNames;
97-
std::shared_ptr<Pixmap> icons[3];
97+
unsigned *const variable;
98+
const std::array<unsigned, tri> states;
99+
const std::array<std::string, tri> tooltips;
100+
const std::array<std::string, tri> iconNames;
101+
std::shared_ptr<Pixmap> icons[tri];
98102

99103
std::string Tooltip() override {
100-
for (size_t k = 0; k < 3; ++k )
101-
if ( *variable == states[k] ) return tooltips[k];
104+
for(size_t k = 0; k < tri; ++k)
105+
if(*variable == states[k])
106+
return tooltips[k];
102107
ssassert(false, "Unexpected mode");
103108
}
104109

105110
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
106-
for (size_t k = 0; k < 3;++k)
111+
for(size_t k = 0; k < tri; ++k)
107112
if(icons[k] == nullptr)
108113
icons[k] = LoadPng("icons/text-window/" + iconNames[k] + ".png");
109114

110115
std::shared_ptr<Pixmap> icon;
111-
for (size_t k = 0; k < 3; ++k )
112-
if ( *variable == states[k] ){
116+
for(size_t k = 0; k < tri; ++k)
117+
if(*variable == states[k]) {
113118
icon = icons[k];
114119
break;
115120
}
116121

117122
uiCanvas->DrawPixmap(icon, x, y - 24);
118123
if(asHovered) {
119124
uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26,
120-
/*fillColor=*/{ 255, 255, 0, 75 },
125+
/*fillColor=*/{255, 255, 0, 75},
121126
/*outlineColor=*/{});
122127
}
123128
}
@@ -126,9 +131,9 @@ class TriStateButton : public Button {
126131
int AdvanceWidth() override { return 32; }
127132

128133
void Click() override {
129-
for (size_t k = 0;k < 3;++k)
130-
if ( *variable == states[k] ){
131-
*variable = states[(k+1)%3];
134+
for(size_t k = 0; k < tri; ++k)
135+
if(*variable == states[k]) {
136+
*variable = states[(k + 1) % tri];
132137
break;
133138
}
134139

@@ -138,77 +143,6 @@ class TriStateButton : public Button {
138143
}
139144
};
140145

141-
142-
class OccludedLinesButton : public Button {
143-
public:
144-
std::shared_ptr<Pixmap> visibleIcon;
145-
std::shared_ptr<Pixmap> stippledIcon;
146-
std::shared_ptr<Pixmap> invisibleIcon;
147-
148-
std::string Tooltip() override {
149-
switch(SS.GW.drawOccludedAs) {
150-
case GraphicsWindow::DrawOccludedAs::INVISIBLE:
151-
return "Stipple occluded lines";
152-
153-
case GraphicsWindow::DrawOccludedAs::STIPPLED:
154-
return "Draw occluded lines";
155-
156-
case GraphicsWindow::DrawOccludedAs::VISIBLE:
157-
return "Don't draw occluded lines";
158-
159-
default: ssassert(false, "Unexpected mode");
160-
}
161-
}
162-
163-
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override {
164-
if(visibleIcon == NULL) {
165-
visibleIcon = LoadPng("icons/text-window/occluded-visible.png");
166-
}
167-
if(stippledIcon == NULL) {
168-
stippledIcon = LoadPng("icons/text-window/occluded-stippled.png");
169-
}
170-
if(invisibleIcon == NULL) {
171-
invisibleIcon = LoadPng("icons/text-window/occluded-invisible.png");
172-
}
173-
174-
std::shared_ptr<Pixmap> icon;
175-
switch(SS.GW.drawOccludedAs) {
176-
case GraphicsWindow::DrawOccludedAs::INVISIBLE: icon = invisibleIcon; break;
177-
case GraphicsWindow::DrawOccludedAs::STIPPLED: icon = stippledIcon; break;
178-
case GraphicsWindow::DrawOccludedAs::VISIBLE: icon = visibleIcon; break;
179-
}
180-
181-
uiCanvas->DrawPixmap(icon, x, y - 24);
182-
if(asHovered) {
183-
uiCanvas->DrawRect(x - 2, x + 26, y + 2, y - 26,
184-
/*fillColor=*/{ 255, 255, 0, 75 },
185-
/*outlineColor=*/{});
186-
}
187-
}
188-
189-
int AdvanceWidth() override { return 32; }
190-
191-
void Click() override {
192-
switch(SS.GW.drawOccludedAs) {
193-
case GraphicsWindow::DrawOccludedAs::INVISIBLE:
194-
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::STIPPLED;
195-
break;
196-
197-
case GraphicsWindow::DrawOccludedAs::STIPPLED:
198-
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::VISIBLE;
199-
break;
200-
201-
case GraphicsWindow::DrawOccludedAs::VISIBLE:
202-
SS.GW.drawOccludedAs = GraphicsWindow::DrawOccludedAs::INVISIBLE;
203-
break;
204-
}
205-
206-
SS.GenerateAll();
207-
SS.GW.Invalidate();
208-
SS.ScheduleShowTW();
209-
}
210-
};
211-
212146
static SpacerButton spacerButton;
213147

214148
static ShowHideButton workplanesButton =
@@ -219,15 +153,13 @@ static ShowHideButton pointsButton =
219153
{ &(SS.GW.showPoints), "point", "points" };
220154
static ShowHideButton constructionButton =
221155
{ &(SS.GW.showConstruction), "construction", "construction entities" };
222-
static TriStateButton constraintsButton =
223-
{ &(SS.GW.showConstraints),
224-
{GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL,
225-
GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM,
226-
GraphicsWindow::ShowConstraintMode::SCM_NOSHOW},
227-
{"constraints and dimensions","dimensions","none"},
228-
{"constraint","constraint-dimo","constraint-wo"}
229-
};
230-
156+
static TriStateButton constraintsButton = {
157+
(unsigned *)(&(SS.GW.showConstraints)),
158+
{(unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL,
159+
(unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM,
160+
(unsigned)GraphicsWindow::ShowConstraintMode::SCM_NOSHOW},
161+
{"Show only dimensions", "Hide constraints and dimensions", "Show constraints and dimensions"},
162+
{"constraint", "constraint-dimo", "constraint-wo"}};
231163
static FacesButton facesButton;
232164
static ShowHideButton shadedButton =
233165
{ &(SS.GW.showShaded), "shaded", "shaded view of solid model" };
@@ -237,7 +169,13 @@ static ShowHideButton outlinesButton =
237169
{ &(SS.GW.showOutlines), "outlines", "outline of solid model" };
238170
static ShowHideButton meshButton =
239171
{ &(SS.GW.showMesh), "mesh", "triangle mesh of solid model" };
240-
static OccludedLinesButton occludedLinesButton;
172+
static TriStateButton occludedLinesButton = {
173+
(unsigned *)(&(SS.GW.drawOccludedAs)),
174+
{(unsigned)GraphicsWindow::DrawOccludedAs::INVISIBLE,
175+
(unsigned)GraphicsWindow::DrawOccludedAs::STIPPLED,
176+
(unsigned)GraphicsWindow::DrawOccludedAs::VISIBLE},
177+
{"Stipple occluded lines", "Draw occluded lines", "Don't draw occluded lines"},
178+
{"occluded-invisible", "occluded-stippled", "occluded-visible"}};
241179

242180
static Button *buttons[] = {
243181
&workplanesButton,

src/ui.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,16 @@ class GraphicsWindow {
801801
bool ToolbarMouseDown(int x, int y);
802802
Command toolbarHovered;
803803

804-
enum class ShowConstraintMode{SCM_NOSHOW,SCM_SHOW_ALL,SCM_SHOW_DIM};
805804

806805
// This sets what gets displayed.
807806
bool showWorkplanes;
808807
bool showNormals;
809808
bool showPoints;
810809
bool showConstruction;
811-
ShowConstraintMode showConstraints;
810+
811+
enum class ShowConstraintMode : unsigned { SCM_NOSHOW, SCM_SHOW_ALL, SCM_SHOW_DIM };
812+
ShowConstraintMode showConstraints;
813+
812814
bool showTextWindow;
813815
bool showShaded;
814816
bool showEdges;
@@ -819,7 +821,7 @@ class GraphicsWindow {
819821
bool showMesh;
820822
void ToggleBool(bool *v);
821823

822-
enum class DrawOccludedAs { INVISIBLE, STIPPLED, VISIBLE };
824+
enum class DrawOccludedAs : unsigned { INVISIBLE, STIPPLED, VISIBLE };
823825
DrawOccludedAs drawOccludedAs;
824826

825827
bool showSnapGrid;

0 commit comments

Comments
 (0)