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 {
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)
@ -459,9 +460,7 @@ bool Constraint::IsVisible() const {
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:;
}

View File

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

View File

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

View File

@ -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,33 +82,38 @@ public:
}
}
};
#include <array>
class TriStateButton : public Button {
public:
TriStateButton(GraphicsWindow::ShowConstraintMode*variable,
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){}
static const size_t tri = 3;
GraphicsWindow::ShowConstraintMode* variable;
std::array<GraphicsWindow::ShowConstraintMode,3> states;
std::array<std::string,3> tooltips;
std::array<std::string,3> iconNames;
std::shared_ptr<Pixmap> icons[3];
TriStateButton(unsigned *variable, const std::array<unsigned, tri> &states,
const std::array<std::string, tri> &tooltips,
const std::array<std::string, tri> &iconNames)
: variable(variable), states(states), tooltips(tooltips), iconNames(iconNames) {
}
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 {
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<Pixmap> icon;
for (size_t k = 0; k < 3; ++k )
for(size_t k = 0; k < tri; ++k)
if(*variable == states[k]) {
icon = icons[k];
break;
@ -126,80 +131,9 @@ public:
int AdvanceWidth() override { return 32; }
void Click() override {
for (size_t k = 0;k < 3;++k)
for(size_t k = 0; k < tri; ++k)
if(*variable == states[k]) {
*variable = states[(k+1)%3];
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;
*variable = states[(k + 1) % tri];
break;
}
@ -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,

View File

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