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.
pull/1333/head
ruevs 2023-01-16 22:50:16 +02:00 committed by Paul Kahler
parent a0219b2228
commit 60cd95d608
5 changed files with 50 additions and 113 deletions

View File

@ -449,7 +449,8 @@ void Constraint::DoArcForAngle(Canvas *canvas, Canvas::hStroke hcs,
} }
bool Constraint::IsVisible() const { 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; bool isDim = false;
if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM) if(SS.GW.showConstraints == GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM)
@ -459,9 +460,7 @@ bool Constraint::IsVisible() const {
case ConstraintBase::Type::PT_PT_DISTANCE: case ConstraintBase::Type::PT_PT_DISTANCE:
case ConstraintBase::Type::PT_FACE_DISTANCE: case ConstraintBase::Type::PT_FACE_DISTANCE:
case ConstraintBase::Type::PT_LINE_DISTANCE: case ConstraintBase::Type::PT_LINE_DISTANCE:
case ConstraintBase::Type::PT_PLANE_DISTANCE: case ConstraintBase::Type::PT_PLANE_DISTANCE: isDim = true; break;
isDim = true;
break;
default:; default:;
} }

View File

@ -409,7 +409,7 @@ void GraphicsWindow::Init() {
showNormals = true; showNormals = true;
showPoints = true; showPoints = true;
showConstruction = true; showConstruction = true;
showConstraints = GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL; showConstraints = ShowConstraintMode::SCM_SHOW_ALL;
showShaded = true; showShaded = true;
showEdges = true; showEdges = true;
showMesh = false; showMesh = false;

View File

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

View File

@ -57,7 +57,7 @@ public:
/*outlineColor=*/{}); /*outlineColor=*/{});
} }
if(!*(variable)) { if(!*(variable)) {
int s = 0, f = 24; int s = 0, f = 23;
RgbaColor color = { 255, 0, 0, 150 }; RgbaColor color = { 255, 0, 0, 150 };
uiCanvas->DrawLine(x+s, y-s, x+f, y-f, color, 2); uiCanvas->DrawLine(x+s, y-s, x+f, y-f, color, 2);
uiCanvas->DrawLine(x+s, y-f, x+f, y-s, color, 2); uiCanvas->DrawLine(x+s, y-f, x+f, y-s, color, 2);
@ -82,33 +82,38 @@ public:
} }
} }
}; };
#include <array> #include <array>
class TriStateButton : public Button { class TriStateButton : public Button {
public: public:
TriStateButton(GraphicsWindow::ShowConstraintMode*variable, static const size_t tri = 3;
const std::array<GraphicsWindow::ShowConstraintMode,3> &states,
const std::array<std::string,3> &tooltips,
const std::array<std::string,3> &iconNames ):variable(variable),states(states),tooltips(tooltips),iconNames(iconNames){}
GraphicsWindow::ShowConstraintMode* variable; TriStateButton(unsigned *variable, const std::array<unsigned, tri> &states,
std::array<GraphicsWindow::ShowConstraintMode,3> states; const std::array<std::string, tri> &tooltips,
std::array<std::string,3> tooltips; const std::array<std::string, tri> &iconNames)
std::array<std::string,3> iconNames; : variable(variable), states(states), tooltips(tooltips), iconNames(iconNames) {
std::shared_ptr<Pixmap> icons[3]; }
unsigned *const variable;
const std::array<unsigned, tri> states;
const std::array<std::string, tri> tooltips;
const std::array<std::string, tri> iconNames;
std::shared_ptr<Pixmap> icons[tri];
std::string Tooltip() override { std::string Tooltip() override {
for (size_t k = 0; k < 3; ++k ) for(size_t k = 0; k < tri; ++k)
if ( *variable == states[k] ) return tooltips[k]; if(*variable == states[k])
return tooltips[k];
ssassert(false, "Unexpected mode"); ssassert(false, "Unexpected mode");
} }
void Draw(UiCanvas *uiCanvas, int x, int y, bool asHovered) override { 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) if(icons[k] == nullptr)
icons[k] = LoadPng("icons/text-window/" + iconNames[k] + ".png"); icons[k] = LoadPng("icons/text-window/" + iconNames[k] + ".png");
std::shared_ptr<Pixmap> icon; std::shared_ptr<Pixmap> icon;
for (size_t k = 0; k < 3; ++k ) for(size_t k = 0; k < tri; ++k)
if(*variable == states[k]) { if(*variable == states[k]) {
icon = icons[k]; icon = icons[k];
break; break;
@ -126,80 +131,9 @@ public:
int AdvanceWidth() override { return 32; } int AdvanceWidth() override { return 32; }
void Click() override { void Click() override {
for (size_t k = 0;k < 3;++k) for(size_t k = 0; k < tri; ++k)
if(*variable == states[k]) { if(*variable == states[k]) {
*variable = states[(k+1)%3]; *variable = states[(k + 1) % tri];
break;
}
SS.GenerateAll();
SS.GW.Invalidate();
SS.ScheduleShowTW();
}
};
class OccludedLinesButton : public Button {
public:
std::shared_ptr<Pixmap> visibleIcon;
std::shared_ptr<Pixmap> stippledIcon;
std::shared_ptr<Pixmap> 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<Pixmap> 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; break;
} }
@ -219,15 +153,13 @@ static ShowHideButton pointsButton =
{ &(SS.GW.showPoints), "point", "points" }; { &(SS.GW.showPoints), "point", "points" };
static ShowHideButton constructionButton = static ShowHideButton constructionButton =
{ &(SS.GW.showConstruction), "construction", "construction entities" }; { &(SS.GW.showConstruction), "construction", "construction entities" };
static TriStateButton constraintsButton = static TriStateButton constraintsButton = {
{ &(SS.GW.showConstraints), (unsigned *)(&(SS.GW.showConstraints)),
{GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL, {(unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_ALL,
GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM, (unsigned)GraphicsWindow::ShowConstraintMode::SCM_SHOW_DIM,
GraphicsWindow::ShowConstraintMode::SCM_NOSHOW}, (unsigned)GraphicsWindow::ShowConstraintMode::SCM_NOSHOW},
{"constraints and dimensions","dimensions","none"}, {"Show only dimensions", "Hide constraints and dimensions", "Show constraints and dimensions"},
{"constraint","constraint-dimo","constraint-wo"} {"constraint", "constraint-dimo", "constraint-wo"}};
};
static FacesButton facesButton; static FacesButton facesButton;
static ShowHideButton shadedButton = static ShowHideButton shadedButton =
{ &(SS.GW.showShaded), "shaded", "shaded view of solid model" }; { &(SS.GW.showShaded), "shaded", "shaded view of solid model" };
@ -237,7 +169,13 @@ static ShowHideButton outlinesButton =
{ &(SS.GW.showOutlines), "outlines", "outline of solid model" }; { &(SS.GW.showOutlines), "outlines", "outline of solid model" };
static ShowHideButton meshButton = static ShowHideButton meshButton =
{ &(SS.GW.showMesh), "mesh", "triangle mesh of solid model" }; { &(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[] = { static Button *buttons[] = {
&workplanesButton, &workplanesButton,

View File

@ -801,14 +801,16 @@ public:
bool ToolbarMouseDown(int x, int y); bool ToolbarMouseDown(int x, int y);
Command toolbarHovered; Command toolbarHovered;
enum class ShowConstraintMode{SCM_NOSHOW,SCM_SHOW_ALL,SCM_SHOW_DIM};
// This sets what gets displayed. // This sets what gets displayed.
bool showWorkplanes; bool showWorkplanes;
bool showNormals; bool showNormals;
bool showPoints; bool showPoints;
bool showConstruction; bool showConstruction;
enum class ShowConstraintMode : unsigned { SCM_NOSHOW, SCM_SHOW_ALL, SCM_SHOW_DIM };
ShowConstraintMode showConstraints; ShowConstraintMode showConstraints;
bool showTextWindow; bool showTextWindow;
bool showShaded; bool showShaded;
bool showEdges; bool showEdges;
@ -819,7 +821,7 @@ public:
bool showMesh; bool showMesh;
void ToggleBool(bool *v); void ToggleBool(bool *v);
enum class DrawOccludedAs { INVISIBLE, STIPPLED, VISIBLE }; enum class DrawOccludedAs : unsigned { INVISIBLE, STIPPLED, VISIBLE };
DrawOccludedAs drawOccludedAs; DrawOccludedAs drawOccludedAs;
bool showSnapGrid; bool showSnapGrid;