mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-26 07:11:23 -05:00
Select sketch constraints by clicking their badges instead of deleting them (#17459)
* Select sketch constraints by clicking their badges instead of deleting them
* Drop a selected sketch constraint when geometry is picked or the tool changes
(cherry picked from commit c872776d24)
This commit is contained in:
1 parent
b2149b8dab
commit
832e2fc2de
8 files changed
+676
-222
No files matched your search
+19
-6
@@ -266,6 +266,16 @@ Feature tree and Bodies list do between themselves. `Esc`, a click on empty spac
|
||||
empty rubber band all let go of it, whichever list or pick made it — except while a body Move is
|
||||
open, which holds the selection until it ends (see the interaction contract).
|
||||
|
||||
In a sketch, a constraint is selected the same way, from its badge on the canvas or its row in
|
||||
the Constraints card: either selects both, draws the badge in the selection colour and bolder, and
|
||||
lights the entities the constraint binds. Delete removes the selected constraint, as do its row's
|
||||
Delete button and menu. A click on a badge only selects it. A badge is small and sits where a
|
||||
person aims at the geometry and its value labels, so a click that deleted would cost a constraint
|
||||
for a slip of the pointer, with nothing on screen to say so. For the same reason a value label
|
||||
drawn over a badge takes the click and opens its field. The selected constraint and the picked
|
||||
geometry are one selection, so picking either drops the other, and `Esc` lets go of both.
|
||||
Zoom to selection on a constraint's row frames the entities it binds.
|
||||
|
||||
Zoom to selection, on a Feature tree or Bodies row and in its right-click menu, frames one thing
|
||||
along the current view direction, as the canvas's Fit button frames the selection. On a body it
|
||||
frames the body whole, hidden or not, from its display mesh: the viewport never selects a hidden
|
||||
@@ -287,14 +297,17 @@ The tab is a page of Orca's main window and answers to the same settings as Prep
|
||||
- **Scale.** Sizes are in DIP, and a DPI change reaches `DesignPanel::msw_rescale`, which
|
||||
re-rasterises every icon (button faces, flyout rows, card headers, the feature and body lists'
|
||||
row icons).
|
||||
- **Sidebar icons.** Every clickable icon in the sidebar shows a hover chip. The card-header and
|
||||
constraint-row buttons are Orca's self-painted `Button`, because a native button cannot take a
|
||||
hover background on macOS. The Feature tree and Bodies lists are a custom-drawn
|
||||
- **Sidebar icons.** Every clickable icon in the sidebar shows a hover chip. The card-header
|
||||
buttons are Orca's self-painted `Button`, because a native button cannot take a hover
|
||||
background on macOS. The Feature tree, Bodies and Constraints lists are a custom-drawn
|
||||
`DesignRowList` rather than a `wxTreeCtrl`, so each row carries its own actions — Zoom to
|
||||
selection, Edit, Show/hide and Delete on a feature, Zoom to selection, Move, Show/hide and
|
||||
Delete on a body, and only Show/hide on the Origin and Bed rows, a separate non-selectable list
|
||||
above the features — and the eye shows whether that row is hidden. A feature with nothing to
|
||||
frame keeps a blank cell where Zoom to selection would be, so every icon stays in its column.
|
||||
Delete on a body, Zoom to selection and Delete on a constraint, whose row starts with its
|
||||
type's icon from the Constrain toolbar, and only Show/hide on the Origin and Bed rows, a
|
||||
separate non-selectable list above the features — and the eye shows whether that row is
|
||||
hidden. A feature with nothing to frame keeps a blank cell where Zoom to selection would be, so
|
||||
every icon stays in its column. The Constraints list draws its rows rather than holding a
|
||||
window each, so a sketch of thousands of constraints lists them all.
|
||||
- **Plates.** This is the one thing the tab does not follow. The canvas has a bed of its own at
|
||||
the printer bed's home position, whichever plate Prepare has current, and a new document's
|
||||
modeling origin is that bed's centre. A bed that followed the current plate would slide out
|
||||
|
||||
@@ -1674,12 +1674,27 @@ void DesignCanvas::update_constrain_entities(const std::vector<SketchEntity>& en
|
||||
request_repaint();
|
||||
}
|
||||
|
||||
void DesignCanvas::set_constraint_highlight(std::vector<int> entities)
|
||||
int DesignCanvas::selected_sketch_constraint() const
|
||||
{
|
||||
m_sketch_tool.set_constraint_highlight(std::move(entities));
|
||||
return m_sketch_tool.selected_constraint();
|
||||
}
|
||||
|
||||
void DesignCanvas::select_sketch_constraint(int con)
|
||||
{
|
||||
m_sketch_tool.select_constraint(con);
|
||||
request_repaint();
|
||||
}
|
||||
|
||||
void DesignCanvas::set_on_sketch_constraint_selected(std::function<void(int con)> cb)
|
||||
{
|
||||
m_sketch_tool.on_constraint_selected = std::move(cb);
|
||||
}
|
||||
|
||||
BoundingBoxf3 DesignCanvas::sketch_constraint_box(int con) const
|
||||
{
|
||||
return m_sketch_tool.constraint_box(con);
|
||||
}
|
||||
|
||||
void DesignCanvas::set_constraint_glyphs(std::vector<SketchEntityConstraintDef> cons)
|
||||
{
|
||||
m_sketch_tool.set_constraint_glyphs(std::move(cons));
|
||||
|
||||
@@ -364,9 +364,14 @@ public:
|
||||
int selected_constrain_axis() const; // third pick slot (Symmetric axis), -1 if unset
|
||||
bool pick0_point(Vec2d& out) const; // plane-coords of the slot-0 pick (trim/extend)
|
||||
void update_constrain_entities(const std::vector<SketchEntity>& ents);
|
||||
// Constraint manager (C3.4): highlight the entities referenced by a selected
|
||||
// constraint (yellow tint in Constrain mode); empty clears the highlight.
|
||||
void set_constraint_highlight(std::vector<int> entities);
|
||||
// Constraint manager (C3.4): the selected constraint, an index into the constraints on show
|
||||
// (the live session's, or in Constrain mode the feature's), -1 for none; its badge and the
|
||||
// entities it binds are highlighted (DesignSketchTool::selected_constraint). The callback
|
||||
// runs on every change, whether a badge click or select_sketch_constraint made it.
|
||||
int selected_sketch_constraint() const;
|
||||
void select_sketch_constraint(int con);
|
||||
void set_on_sketch_constraint_selected(std::function<void(int con)> cb);
|
||||
BoundingBoxf3 sketch_constraint_box(int con) const; // what zooming to the constraint frames
|
||||
// Constraint glyph badges (C3.4b): the feature's constraints, drawn as iconic
|
||||
// marks near their entities in Constrain mode; empty clears them.
|
||||
void set_constraint_glyphs(std::vector<SketchEntityConstraintDef> cons);
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
#include "slic3r/GUI/Widgets/TextInput.hpp"
|
||||
#include "slic3r/GUI/Widgets/DialogButtons.hpp"
|
||||
#include "slic3r/GUI/MsgDialog.hpp"
|
||||
#include "slic3r/GUI/format.hpp"
|
||||
#include "slic3r/GUI/Widgets/StaticBox.hpp" // Prepare's rounded white card frame around each tool dialog
|
||||
#include "libslic3r/CAD/SketchImport.hpp" // text_to_regions / svg_to_regions
|
||||
#include "libslic3r/CAD/ThreadStandards.hpp" // ISO metric / Unified imperial thread tables
|
||||
@@ -1091,7 +1092,7 @@ DesignPanel::DesignPanel(wxWindow* parent)
|
||||
// nothing) while the line stayed — the reported "I click a line and cannot remove it".
|
||||
m_verb_actions["btn:sk_delete"] = [this] {
|
||||
if (m_viewport && m_viewport->is_sketching())
|
||||
m_viewport->delete_selected_sketch_entities();
|
||||
delete_sketch_selection();
|
||||
else
|
||||
on_delete_feature();
|
||||
};
|
||||
@@ -1527,7 +1528,7 @@ DesignPanel::DesignPanel(wxWindow* parent)
|
||||
add_sep(m_tb_sketch);
|
||||
auto* b_del = icon_btn("design_delete", _L("Delete selected"));
|
||||
b_del->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
if (m_viewport) m_viewport->delete_selected_sketch_entities(); });
|
||||
delete_sketch_selection(); });
|
||||
sadd_bar(b_del); // keep-list: Delete selected stays on the bar
|
||||
// Finish sketch = the unified ✓ Confirm in the action bar (tool_confirm).
|
||||
}
|
||||
@@ -3096,16 +3097,43 @@ DesignPanel::DesignPanel(wxWindow* parent)
|
||||
}
|
||||
cards->Add(m_box_sketch_session, 0, wxEXPAND);
|
||||
|
||||
// --- Constraint-manager card (C3.4): list of the constrained sketch's
|
||||
// entity-constraints; each row selects (highlights) + deletes. Shown only
|
||||
// in Constrain mode; rebuilt by rebuild_constraint_list().
|
||||
// --- Constraint-manager card (C3.4): the open sketch's constraints, one row each, laid out
|
||||
// as the Feature tree's rows are: the constraint's icon and name, then Zoom to selection
|
||||
// and Delete. A row and the constraint's badge on the canvas are one selection. Shown
|
||||
// while a sketch is open and in Constrain mode; rebuilt by rebuild_constraint_list().
|
||||
m_box_constraints = new wxBoxSizer(wxVERTICAL);
|
||||
m_box_constraints->Add(card_header(m_cards, "design_constrain", _L("Constraints"), m_hdr_constraints),
|
||||
0, wxLEFT | wxRIGHT | wxTOP, 12);
|
||||
m_box_constraints->Add(new wxStaticLine(m_cards), 0, wxEXPAND | wxALL, 8);
|
||||
m_constraint_rows = new wxBoxSizer(wxVERTICAL);
|
||||
m_box_constraints->Add(m_constraint_rows, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 12);
|
||||
m_constraints_none = new wxStaticText(m_cards, wxID_ANY, _L("No constraints yet"));
|
||||
m_constraints_none->SetForegroundColour(dp_sec_text());
|
||||
m_box_constraints->Add(m_constraints_none, 0, wxLEFT | wxRIGHT | wxBOTTOM, 12);
|
||||
m_constraint_list = new DesignRowList(m_cards, 8); // scrolls past 8
|
||||
m_constraint_list->SetBackgroundColour(dp_panel_bg());
|
||||
m_box_constraints->Add(m_constraint_list, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 12);
|
||||
cards->Add(m_box_constraints, 0, wxEXPAND);
|
||||
// A row picked here selects its constraint on the canvas, whose report of the change
|
||||
// (on_constraint_selected) finds the list already on that row.
|
||||
m_constraint_list->on_select = [this] {
|
||||
if (m_viewport) m_viewport->select_sketch_constraint(m_constraint_list->selection());
|
||||
};
|
||||
m_constraint_list->on_action = [this](int row, int id) {
|
||||
switch (id) {
|
||||
case RowZoom: zoom_to_constraint(row); break;
|
||||
case RowDelete: delete_constraint(row); break;
|
||||
}
|
||||
};
|
||||
m_constraint_list->on_menu = [this](int row, const wxPoint& screen) {
|
||||
wxMenu menu;
|
||||
const int id_zoom = wxWindow::NewControlId();
|
||||
const int id_del = wxWindow::NewControlId();
|
||||
menu.Append(id_zoom, _L("Zoom to selection"));
|
||||
menu.AppendSeparator();
|
||||
menu.Append(id_del, _L("Delete constraint"));
|
||||
menu.Bind(wxEVT_MENU, [this, row](wxCommandEvent&) { zoom_to_constraint(row); }, id_zoom);
|
||||
menu.Bind(wxEVT_MENU, [this, row](wxCommandEvent&) { delete_constraint(row); }, id_del);
|
||||
m_constraint_list->PopupMenu(&menu, m_constraint_list->ScreenToClient(screen));
|
||||
};
|
||||
|
||||
// Wrap every card label now that the whole stack exists. wxStaticText never wraps on its
|
||||
// own, so a one-sentence help line under a card sets that card's sizer min width to the
|
||||
@@ -3593,6 +3621,8 @@ DesignPanel::DesignPanel(wxWindow* parent)
|
||||
m_viewport->set_on_sketch_constraints_changed([this]() {
|
||||
CallAfter([this]() { rebuild_constraint_list(); });
|
||||
});
|
||||
// A badge clicked on the canvas, or a selection dropped there, moves the list with it.
|
||||
m_viewport->set_on_sketch_constraint_selected([this](int con) { on_constraint_selected(con); });
|
||||
|
||||
// DoF feedback (P3): after each live solve, report constraint state on its own
|
||||
// line. Green = fully constrained, red = conflicting, neutral = N remaining DoF.
|
||||
@@ -4288,9 +4318,11 @@ DesignPanel::DesignPanel(wxWindow* parent)
|
||||
// Focus-independent, same reason as undo above.
|
||||
// WXK_BACK too: on a keyboard whose Del is a chord (every laptop this runs on), Del is
|
||||
// the one destructive key nobody can reach, and Backspace is what users press. oql1.
|
||||
if (!in_text && (key == WXK_DELETE || (key == WXK_BACK && sketching))) {
|
||||
if (sketching) {
|
||||
if (!m_viewport->delete_selected_sketch_entities())
|
||||
// In Constrain mode the selection is the constraint picked in the list or on the canvas.
|
||||
const bool constraining = m_ui_mode == UiMode::Constrain && m_viewport && m_viewport->is_sketching();
|
||||
if (!in_text && (key == WXK_DELETE || (key == WXK_BACK && (sketching || constraining)))) {
|
||||
if (sketching || constraining) {
|
||||
if (!delete_sketch_selection())
|
||||
set_status(_L("Select something to delete"));
|
||||
return;
|
||||
}
|
||||
@@ -6617,7 +6649,7 @@ void DesignPanel::on_sketch_step(int mode, int step, int picks)
|
||||
// only once a constraint exists, so it never advertises a badge that is not on screen.
|
||||
if (DesignSketchTool::Mode(mode) == DesignSketchTool::Mode::Select && m_viewport != nullptr &&
|
||||
m_viewport->sketch_constraint_count() > 0 && !text.IsEmpty())
|
||||
text += _L(" · click a constraint badge to remove it");
|
||||
text += _L(" · click a constraint badge to select it");
|
||||
m_sketch_step = text;
|
||||
if (text.IsEmpty() || m_status == nullptr) return;
|
||||
set_status(StatusKind::Info, text);
|
||||
@@ -7420,6 +7452,7 @@ void DesignPanel::on_sys_color_changed()
|
||||
refresh_icons();
|
||||
refresh_tree(); // the rows carry their own text colours
|
||||
refresh_pinned();
|
||||
rebuild_constraint_list();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -8686,83 +8719,123 @@ bool DesignPanel::live_constraint_scope() const
|
||||
!m_viewport->is_constraining() && !m_viewport->is_constraining_entities();
|
||||
}
|
||||
|
||||
// Rebuild the constraint-row list. Source depends on scope: a LIVE sketch session owns its
|
||||
// The icon the Constrain toolbar shows for a constraint of type `t`.
|
||||
static const char* constraint_icon(SketchConstraintType t)
|
||||
{
|
||||
using T = SketchConstraintType;
|
||||
switch (t) {
|
||||
case T::Fix: return "design_c_fix";
|
||||
case T::Coincident:
|
||||
case T::PointOnLine:
|
||||
case T::PointOnObject: return "design_c_coincident";
|
||||
case T::Horizontal: return "design_c_horizontal";
|
||||
case T::Vertical: return "design_c_vertical";
|
||||
case T::Distance: return "design_dimension";
|
||||
case T::LockX:
|
||||
case T::DistanceX: return "design_c_dist_x";
|
||||
case T::LockY:
|
||||
case T::DistanceY: return "design_c_dist_y";
|
||||
case T::EqualLength: return "design_c_equal";
|
||||
case T::EqualRadius: return "design_c_equal_radius";
|
||||
case T::Parallel: return "design_c_parallel";
|
||||
case T::Perpendicular: return "design_c_perpendicular";
|
||||
case T::Collinear: return "design_c_collinear";
|
||||
case T::Concentric: return "design_c_concentric";
|
||||
case T::Tangent: return "design_c_tangent";
|
||||
case T::Midpoint: return "design_c_midpoint";
|
||||
case T::Symmetric: return "design_c_symmetric";
|
||||
case T::SymmetricAboutY: return "design_c_sym_v";
|
||||
case T::SymmetricAboutX: return "design_c_sym_h";
|
||||
case T::Angle: return "design_c_angle";
|
||||
case T::Radius: return "design_c_radius";
|
||||
case T::Diameter: return "design_c_diameter";
|
||||
}
|
||||
return "design_constrain";
|
||||
}
|
||||
|
||||
const std::vector<SketchEntityConstraintDef>& DesignPanel::shown_constraints() const
|
||||
{
|
||||
static const std::vector<SketchEntityConstraintDef> none;
|
||||
if (live_constraint_scope())
|
||||
return m_viewport->sketch_constraints();
|
||||
if (m_constrain_feat >= 0 && m_constrain_feat < int(m_doc.features.size()))
|
||||
return m_doc.features[m_constrain_feat].entity_constraints;
|
||||
return none;
|
||||
}
|
||||
|
||||
// Refill the constraint rows. Source depends on scope: a LIVE sketch session owns its
|
||||
// constraints inside the sketch tool and has no committed feature yet, so the list read only
|
||||
// the feature's and stayed empty for the whole session — constraints applied while drawing had
|
||||
// no row, no ✗, and no name anywhere in the UI.
|
||||
void DesignPanel::rebuild_constraint_list()
|
||||
{
|
||||
if (m_constraint_rows == nullptr || m_form == nullptr)
|
||||
if (m_constraint_list == nullptr || m_form == nullptr)
|
||||
return;
|
||||
m_constraint_rows->Clear(true /* delete windows */);
|
||||
m_constraint_sel = -1;
|
||||
|
||||
const bool live = live_constraint_scope();
|
||||
const bool active = (m_constrain_feat >= 0 && m_constrain_feat < int(m_doc.features.size()));
|
||||
const std::vector<SketchEntityConstraintDef> empty;
|
||||
const std::vector<SketchEntityConstraintDef>& cons =
|
||||
live ? m_viewport->sketch_constraints()
|
||||
: active ? m_doc.features[m_constrain_feat].entity_constraints : empty;
|
||||
const bool live = live_constraint_scope();
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
|
||||
if (m_hdr_constraints)
|
||||
m_hdr_constraints->SetLabel(wxString::Format(_L("Constraints (%d)"), int(cons.size())));
|
||||
|
||||
if (cons.empty()) {
|
||||
auto* none = new wxStaticText(m_cards, wxID_ANY, _L("No constraints yet"));
|
||||
none->SetForegroundColour(dp_sec_text());
|
||||
m_constraint_rows->Add(none, 0, wxTOP, 4);
|
||||
}
|
||||
for (int i = 0; i < int(cons.size()); ++i) {
|
||||
auto* row = new wxBoxSizer(wxHORIZONTAL);
|
||||
// Delete button first (fixed left position, always visible — long labels can
|
||||
// horizontally scroll but ✗ stays put and clickable).
|
||||
auto* del = sidebar_icon_btn(m_cards, "design_delete", _L("Delete constraint"), 16);
|
||||
// After the click: deleting rebuilds these rows, and with them this button, which must
|
||||
// not be destroyed while its own click is still being dispatched.
|
||||
del->Bind(wxEVT_BUTTON, [this, i](wxCommandEvent&) { CallAfter([this, i] { delete_constraint(i); }); });
|
||||
// Clickable label: selecting it highlights the referenced entities.
|
||||
auto* lbl = new wxStaticText(m_cards, wxID_ANY, constraint_label(cons[i]));
|
||||
lbl->SetCursor(wxCursor(wxCURSOR_HAND));
|
||||
lbl->Bind(wxEVT_LEFT_UP, [this, i](wxMouseEvent&) { highlight_constraint_entities(i); });
|
||||
row->Add(del, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
|
||||
row->Add(lbl, 1, wxALIGN_CENTER_VERTICAL);
|
||||
m_constraint_rows->Add(row, 0, wxEXPAND | wxTOP, 2);
|
||||
std::vector<DesignRowList::Row> rows;
|
||||
rows.reserve(cons.size());
|
||||
for (const SketchEntityConstraintDef& d : cons) {
|
||||
DesignRowList::Row row;
|
||||
row.icon = constraint_icon(d.type);
|
||||
row.label = constraint_label(d);
|
||||
row.colour = dp_item_text();
|
||||
row.actions = { { RowZoom, "design_zoom", _L("Zoom to selection") },
|
||||
{ RowDelete, "design_delete", _L("Delete constraint") } };
|
||||
rows.push_back(std::move(row));
|
||||
}
|
||||
m_constraint_list->set_rows(std::move(rows));
|
||||
|
||||
// Feed the same list to the viewport for the on-sketch glyph badges (C3.4b).
|
||||
if (m_viewport)
|
||||
// Feed the same list to the viewport for the on-sketch glyph badges (C3.4b), then put the
|
||||
// list back on the constraint the canvas still has selected.
|
||||
if (m_viewport) {
|
||||
m_viewport->set_constraint_glyphs(cons);
|
||||
m_constraint_list->select(m_viewport->selected_sketch_constraint());
|
||||
}
|
||||
|
||||
m_cards->GetSizer()->Show(m_box_constraints,
|
||||
m_ui_mode == UiMode::Constrain || live, true);
|
||||
m_cards->GetSizer()->Show(m_box_constraints, m_ui_mode == UiMode::Constrain || live, true);
|
||||
m_constraints_none->Show(cons.empty());
|
||||
m_constraint_list->Show(!cons.empty());
|
||||
update_cards_frame(); m_form->Layout();
|
||||
m_form->FitInside();
|
||||
}
|
||||
|
||||
// Push the entities referenced by constraint `idx` to the viewport as a yellow
|
||||
// highlight (toggle off if the same row is clicked again).
|
||||
void DesignPanel::highlight_constraint_entities(int idx)
|
||||
// The canvas's selected constraint changed, from a badge click, the list, or the selection
|
||||
// dropped: move the list's selection with it and name the constraint on the status line.
|
||||
void DesignPanel::on_constraint_selected(int con)
|
||||
{
|
||||
if (!m_viewport)
|
||||
if (m_constraint_list == nullptr)
|
||||
return;
|
||||
const bool live = live_constraint_scope();
|
||||
if (!live && (m_constrain_feat < 0 || m_constrain_feat >= int(m_doc.features.size())))
|
||||
return;
|
||||
const auto& cons = live ? m_viewport->sketch_constraints()
|
||||
: m_doc.features[m_constrain_feat].entity_constraints;
|
||||
if (idx < 0 || idx >= int(cons.size()))
|
||||
return;
|
||||
if (m_constraint_sel == idx) { // second click clears
|
||||
m_constraint_sel = -1;
|
||||
m_viewport->set_constraint_highlight({});
|
||||
m_constraint_list->select(con);
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
if (con >= 0 && con < int(cons.size()))
|
||||
// TRN Design tab status line. %1% names the selected sketch constraint, e.g. "Horizontal E0·P0 — E0·P1".
|
||||
set_status(StatusKind::Info, format_wxstr(_L("%1% selected — Delete removes it"), constraint_label(cons[con])));
|
||||
}
|
||||
|
||||
void DesignPanel::zoom_to_constraint(int con)
|
||||
{
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
if (m_viewport == nullptr || con < 0 || con >= int(cons.size()))
|
||||
return;
|
||||
if (!m_viewport->zoom_to_box(m_viewport->sketch_constraint_box(con)))
|
||||
set_status(StatusKind::Info, wxString::Format(_L("%s has nothing on show to zoom to"), constraint_label(cons[con])));
|
||||
}
|
||||
|
||||
// Delete what the open sketch has selected: the picked geometry, or the selected constraint.
|
||||
bool DesignPanel::delete_sketch_selection()
|
||||
{
|
||||
if (m_viewport == nullptr)
|
||||
return false;
|
||||
const int con = m_viewport->selected_sketch_constraint();
|
||||
if (con >= 0) {
|
||||
delete_constraint(con);
|
||||
return true;
|
||||
}
|
||||
m_constraint_sel = idx;
|
||||
const SketchEntityConstraintDef& d = cons[idx];
|
||||
std::vector<int> ents;
|
||||
for (int e : { d.ea, d.eb, d.ec })
|
||||
if (e >= 0) ents.push_back(e);
|
||||
m_viewport->set_constraint_highlight(std::move(ents));
|
||||
return m_viewport->delete_selected_sketch_entities();
|
||||
}
|
||||
|
||||
// Drop constraint `idx`, re-solve the feature, and refresh viewport + list + DoF.
|
||||
@@ -8791,7 +8864,6 @@ void DesignPanel::delete_constraint(int idx)
|
||||
m_doc.recompute();
|
||||
sync_recipe_to_model(); // the removal is part of the recipe
|
||||
update_undo_redo_buttons();
|
||||
m_viewport->set_constraint_highlight({});
|
||||
m_viewport->update_constrain_entities(m_doc.features[m_constrain_feat].entities);
|
||||
if (!m_doc.display_mesh.its.indices.empty())
|
||||
feed_bodies();
|
||||
@@ -9506,7 +9578,7 @@ void DesignPanel::after_edit_op()
|
||||
if (m_constrain_feat < 0 || m_constrain_feat >= int(m_doc.features.size()) || !m_viewport)
|
||||
return;
|
||||
m_doc.recompute();
|
||||
m_viewport->set_constraint_highlight({}); // entity indices may have shifted
|
||||
m_viewport->select_sketch_constraint(-1); // entity indices may have shifted
|
||||
m_viewport->update_constrain_entities(m_doc.features[m_constrain_feat].entities);
|
||||
// Refresh the committed-sketch overlay too: it caches the entity list at
|
||||
// constrain-entry, so a relocating edit (Move/Trim/Extend) would otherwise
|
||||
|
||||
@@ -294,9 +294,14 @@ private:
|
||||
// Constrain modes set m_active too, so is_sketching() alone would claim the live scope while
|
||||
// the committed manager is open.
|
||||
bool live_constraint_scope() const;
|
||||
void rebuild_constraint_list(); // refill m_constraint_rows
|
||||
void rebuild_constraint_list(); // refill m_constraint_list
|
||||
void delete_constraint(int idx); // erase + re-solve + refresh
|
||||
void highlight_constraint_entities(int idx); // push referenced entities to viewport
|
||||
// The constraints the card lists: the live session's, or the constrained feature's.
|
||||
const std::vector<SketchEntityConstraintDef>& shown_constraints() const;
|
||||
void on_constraint_selected(int con); // the canvas's selection moved
|
||||
void zoom_to_constraint(int con); // frame the entities it binds
|
||||
// Delete what the open sketch has selected, geometry or a constraint; false when nothing is.
|
||||
bool delete_sketch_selection();
|
||||
void refresh_constrain_dof(); // re-solve feature, mirror DoF readout
|
||||
wxString constraint_label(const SketchEntityConstraintDef& d) const; // human-readable row text
|
||||
void after_edit_op(); // shared edit-op refresh tail
|
||||
@@ -1041,11 +1046,12 @@ private:
|
||||
// Tree row of the sketch currently being constrained (-1 = not constraining).
|
||||
int m_constrain_feat{-1};
|
||||
|
||||
// Constraint-manager card (C3.4): header + a rebuildable list of constraint rows.
|
||||
// Constraint-manager card (C3.4): header + the list of constraint rows, or a line saying
|
||||
// there are none.
|
||||
wxSizer* m_box_constraints{nullptr};
|
||||
wxStaticText* m_hdr_constraints{nullptr};
|
||||
wxSizer* m_constraint_rows{nullptr};
|
||||
int m_constraint_sel{-1}; // highlighted constraint row, or -1
|
||||
wxStaticText* m_constraints_none{nullptr};
|
||||
DesignRowList* m_constraint_list{nullptr};
|
||||
};
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
|
||||
#include <glad/gl.h>
|
||||
@@ -114,7 +115,7 @@ void DesignSketchTool::begin(const SketchPlane& plane, Mode mode)
|
||||
m_sel_a = m_sel_b = -1;
|
||||
m_constrain_entities = false;
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
m_constraint_hl.clear();
|
||||
m_sel_con = -1;
|
||||
m_constrain_cons.clear();
|
||||
m_awaiting_length = false;
|
||||
m_autoedit_seen = 0; // baseline: no entities yet; first commit triggers edit
|
||||
@@ -280,7 +281,10 @@ void DesignSketchTool::set_tool(Mode mode)
|
||||
// follows — leaving a tool must not silently discard what the user entered.
|
||||
if (on_inline_commit) on_inline_commit();
|
||||
|
||||
// Switch the active drawing tool without dropping accumulated entities.
|
||||
// Switch the active drawing tool without dropping accumulated entities. A selected constraint
|
||||
// goes: the next tool picks geometry, and the sketch holds one selection at a time.
|
||||
if (mode != m_mode)
|
||||
set_selected_constraint(-1);
|
||||
m_mode = mode;
|
||||
m_points.clear();
|
||||
m_has_cursor = false;
|
||||
@@ -355,7 +359,7 @@ void DesignSketchTool::cancel()
|
||||
m_sel_a = m_sel_b = -1;
|
||||
m_constrain_entities = false;
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
m_constraint_hl.clear();
|
||||
m_sel_con = -1;
|
||||
m_constrain_cons.clear();
|
||||
m_awaiting_length = false;
|
||||
m_selection.clear();
|
||||
@@ -463,12 +467,149 @@ void DesignSketchTool::request_exit()
|
||||
|
||||
void DesignSketchTool::clear_selection()
|
||||
{
|
||||
set_selected_constraint(-1);
|
||||
if (m_selection.empty() && m_point_sel.empty()) return;
|
||||
m_selection.clear();
|
||||
m_point_sel.clear();
|
||||
if (on_selection_changed) on_selection_changed(0);
|
||||
}
|
||||
|
||||
void DesignSketchTool::set_selected_constraint(int con)
|
||||
{
|
||||
if (con < 0 || con >= int(shown_constraints().size()))
|
||||
con = -1;
|
||||
if (con == m_sel_con)
|
||||
return;
|
||||
m_sel_con = con;
|
||||
if (on_constraint_selected)
|
||||
on_constraint_selected(con);
|
||||
}
|
||||
|
||||
void DesignSketchTool::remap_selected_constraint(const std::vector<int>& remap)
|
||||
{
|
||||
if (m_sel_con >= 0)
|
||||
set_selected_constraint(m_sel_con < int(remap.size()) ? remap[m_sel_con] : -1);
|
||||
}
|
||||
|
||||
void DesignSketchTool::select_constraint(int con)
|
||||
{
|
||||
// The picked geometry goes first, so the report of the constraint is the last word. In
|
||||
// Constrain mode the picks are the slots the CONSTRAIN buttons read.
|
||||
const bool on_show = con >= 0 && con < int(shown_constraints().size());
|
||||
if (on_show && m_mode == Mode::Constrain) {
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
m_sel_a = m_sel_b = -1;
|
||||
}
|
||||
if (on_show && (!m_selection.empty() || !m_point_sel.empty())) {
|
||||
m_selection.clear();
|
||||
m_point_sel.clear();
|
||||
if (on_selection_changed) on_selection_changed(0);
|
||||
}
|
||||
set_selected_constraint(con);
|
||||
}
|
||||
|
||||
void DesignSketchTool::constrain_pick(const Vec2d& p, double reach)
|
||||
{
|
||||
set_selected_constraint(-1);
|
||||
double best = 1e30;
|
||||
int bi = -1;
|
||||
for (size_t i = 0; i < m_entities.size(); ++i) {
|
||||
const double d = entity_pick_dist(p, m_entities[i]);
|
||||
if (d < best) { best = d; bi = int(i); }
|
||||
}
|
||||
// With no limit, a click anywhere on screen picked whatever was nearest; empty space clears.
|
||||
if (bi < 0 || best > reach) {
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
return;
|
||||
}
|
||||
// Rolling three-slot selection: slots 0/1 feed all 2-entity constraints; slot 2 is the
|
||||
// Symmetric axis (only filled once 0 and 1 are set). A click past slot 2 restarts the cycle.
|
||||
if (m_pick0 < 0) { m_pick0 = bi; m_pick0_pt = p; }
|
||||
else if (m_pick1 < 0 && bi != m_pick0) m_pick1 = bi;
|
||||
else if (m_pick1 >= 0 && m_pick2 < 0 && bi != m_pick0 && bi != m_pick1) m_pick2 = bi;
|
||||
else { m_pick0 = bi; m_pick1 = m_pick2 = -1; m_pick0_pt = p; }
|
||||
}
|
||||
|
||||
void DesignSketchTool::set_constraint_glyphs(std::vector<SketchEntityConstraintDef> v)
|
||||
{
|
||||
const bool other_set = v.size() != m_constrain_cons.size();
|
||||
m_constrain_cons = std::move(v);
|
||||
if (other_set && m_mode == Mode::Constrain)
|
||||
set_selected_constraint(-1);
|
||||
}
|
||||
|
||||
std::vector<std::optional<Vec2d>> DesignSketchTool::constraint_badges(double unit_per_px) const
|
||||
{
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
std::vector<std::optional<Vec2d>> out(cons.size());
|
||||
const double cell = std::max(kBadgePx * unit_per_px, 1e-4);
|
||||
std::vector<int> stacked(m_entities.size(), 0); // badges already on each entity
|
||||
for (size_t ci = 0; ci < cons.size(); ++ci) {
|
||||
const int ei = cons[ci].ea;
|
||||
if (ei < 0 || ei >= int(m_entities.size()))
|
||||
continue;
|
||||
const SketchEntity& e = m_entities[ei];
|
||||
// A line's (and a spline's) middle, a round entity's centre, a point itself.
|
||||
Vec2d anchor = e.p0;
|
||||
switch (e.type) {
|
||||
case SketchEntity::Type::Line:
|
||||
case SketchEntity::Type::BSpline: anchor = 0.5 * (e.p0 + e.p1); break;
|
||||
case SketchEntity::Type::Circle:
|
||||
case SketchEntity::Type::Ellipse:
|
||||
case SketchEntity::Type::Arc:
|
||||
case SketchEntity::Type::EllipseArc: anchor = e.center; break;
|
||||
case SketchEntity::Type::Point: break;
|
||||
}
|
||||
out[ci] = anchor + Vec2d(0.0, 1.5 * cell * (1 + stacked[ei]++));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::optional<Vec2d> DesignSketchTool::constraint_badge(int con, double unit_per_px) const
|
||||
{
|
||||
if (con < 0 || con >= int(shown_constraints().size()))
|
||||
return std::nullopt;
|
||||
return constraint_badges(unit_per_px)[con];
|
||||
}
|
||||
|
||||
bool DesignSketchTool::click_constraint_badge(const Vec2d& p, double unit_per_px)
|
||||
{
|
||||
// The nearest badge within 0.6 of a cell: its glyph and a little around it.
|
||||
const std::vector<std::optional<Vec2d>> badges = constraint_badges(unit_per_px);
|
||||
double best_d = 0.6 * std::max(kBadgePx * unit_per_px, 1e-4);
|
||||
int best = -1;
|
||||
for (size_t ci = 0; ci < badges.size(); ++ci)
|
||||
if (badges[ci] && (*badges[ci] - p).norm() < best_d) {
|
||||
best_d = (*badges[ci] - p).norm();
|
||||
best = int(ci);
|
||||
}
|
||||
if (best < 0)
|
||||
return false;
|
||||
select_constraint(best);
|
||||
return true;
|
||||
}
|
||||
|
||||
BoundingBoxf3 DesignSketchTool::constraint_box(int con) const
|
||||
{
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
if (con < 0 || con >= int(cons.size()))
|
||||
return {};
|
||||
std::vector<SketchEntity> bound;
|
||||
for (int ei : { cons[con].ea, cons[con].eb, cons[con].ec })
|
||||
if (ei >= 0 && ei < int(m_entities.size()))
|
||||
bound.push_back(m_entities[ei]);
|
||||
return bound.empty() ? BoundingBoxf3() : sketch_box(bound, m_plane);
|
||||
}
|
||||
|
||||
bool DesignSketchTool::bound_by_selected_constraint(int ei) const
|
||||
{
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
if (m_sel_con < 0 || m_sel_con >= int(cons.size()))
|
||||
return false;
|
||||
const SketchEntityConstraintDef& d = cons[m_sel_con];
|
||||
return ei >= 0 && (d.ea == ei || d.eb == ei || d.ec == ei);
|
||||
}
|
||||
|
||||
bool DesignSketchTool::can_redo_entity() const
|
||||
{
|
||||
return m_active && !m_sketch_redo.empty()
|
||||
@@ -487,6 +628,7 @@ bool DesignSketchTool::redo_last_entity()
|
||||
m_dimensions = std::move(s.dimensions);
|
||||
m_selection.clear();
|
||||
m_point_sel.clear();
|
||||
set_selected_constraint(-1);
|
||||
reset_autoedit();
|
||||
resolve_live();
|
||||
if (on_selection_changed) on_selection_changed(0);
|
||||
@@ -541,6 +683,7 @@ void DesignSketchTool::delete_selected()
|
||||
kept.push_back(c);
|
||||
}
|
||||
m_constraints.swap(kept);
|
||||
remap_selected_constraint(con_remap);
|
||||
m_selection.clear();
|
||||
m_point_sel.clear();
|
||||
// Placed quotes follow their geometry and their driving constraint: a quote whose entity or
|
||||
@@ -1781,6 +1924,7 @@ int DesignSketchTool::erase_constraints(
|
||||
m_constraints.swap(kept);
|
||||
for (DimAnnot& a : m_dimensions) // repair the cached indices
|
||||
if (a.con >= 0) a.con = (a.con < int(remap.size())) ? remap[a.con] : -1;
|
||||
remap_selected_constraint(remap);
|
||||
return dropped;
|
||||
}
|
||||
|
||||
@@ -2481,6 +2625,7 @@ void DesignSketchTool::finish()
|
||||
m_points.clear();
|
||||
m_entities.clear();
|
||||
m_constraints.clear();
|
||||
m_sel_con = -1;
|
||||
m_dimensions.clear();
|
||||
m_point_sel.clear();
|
||||
m_dim_has0 = false;
|
||||
@@ -2502,6 +2647,7 @@ void DesignSketchTool::begin_constrain(const SketchProfile& prof, const SketchPl
|
||||
m_sel_a = m_sel_b = -1;
|
||||
m_constrain_entities = false;
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
m_sel_con = -1;
|
||||
m_active = true;
|
||||
}
|
||||
|
||||
@@ -2516,6 +2662,7 @@ void DesignSketchTool::begin_constrain_entities(const std::vector<SketchEntity>&
|
||||
m_has_cursor = false;
|
||||
m_sel_a = m_sel_b = -1;
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
m_sel_con = -1;
|
||||
m_active = true;
|
||||
}
|
||||
|
||||
@@ -2665,22 +2812,9 @@ bool DesignSketchTool::try_add_constraints(const std::vector<SketchEntityConstra
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete the constraint whose badge is under `p`. Removing a constraint can only FREE degrees
|
||||
// of freedom, so the re-solve cannot fail for over-constraint -- but it is still run, because
|
||||
// the geometry must relax back to what the remaining system allows.
|
||||
bool DesignSketchTool::remove_constraint_near(const Vec2d& p)
|
||||
{
|
||||
if (m_glyph_hits.empty() || m_glyph_r <= 0.0) return false;
|
||||
int best = -1;
|
||||
double best_d = m_glyph_r;
|
||||
for (const GlyphHit& g : m_glyph_hits) {
|
||||
const double d = (g.c - p).norm();
|
||||
if (d < best_d && g.con >= 0 && g.con < int(m_constraints.size())) { best_d = d; best = g.con; }
|
||||
}
|
||||
if (best < 0) return false;
|
||||
return remove_constraint(best);
|
||||
}
|
||||
|
||||
// Removing a constraint can only FREE degrees of freedom, so the re-solve cannot fail for
|
||||
// over-constraint -- but it is still run, because the geometry must relax back to what the
|
||||
// remaining system allows.
|
||||
bool DesignSketchTool::remove_constraint(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= int(m_constraints.size())) return false;
|
||||
@@ -2692,7 +2826,6 @@ bool DesignSketchTool::remove_constraint(int idx)
|
||||
// geometry while leaving the DoF readout and any red over-constrained tint stale — the
|
||||
// readout would still describe the constraint that was just deleted.
|
||||
resolve_live();
|
||||
m_glyph_hits.clear(); // stale until the next render rebuilds them
|
||||
if (on_constraints_changed) on_constraints_changed();
|
||||
return true;
|
||||
}
|
||||
@@ -8439,35 +8572,17 @@ void DesignSketchTool::render_live_quotes(double unit_per_px)
|
||||
}
|
||||
}
|
||||
|
||||
// Iconic constraint badges drawn near each constraint's primary entity (C3.4b).
|
||||
// Each glyph is authored in a unit cell [-0.5,0.5]^2 then scaled to a constant
|
||||
// on-screen size and translated to the anchor; badges on the same entity stack
|
||||
// upward so multiple constraints stay legible.
|
||||
// Iconic constraint badges drawn near each constraint's primary entity (C3.4b), where
|
||||
// constraint_badges() lays them out. Each glyph is authored in a unit cell [-0.5,0.5]^2, then
|
||||
// scaled to a constant on-screen size and moved to its badge.
|
||||
void DesignSketchTool::build_constraint_glyphs(double unit_per_px,
|
||||
const std::vector<SketchEntityConstraintDef>& cons,
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out)
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out,
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out_selected) const
|
||||
{
|
||||
m_glyph_hits.clear();
|
||||
const std::vector<SketchEntityConstraintDef>& cons = shown_constraints();
|
||||
if (cons.empty() || m_entities.empty()) return;
|
||||
using T = SketchConstraintType;
|
||||
const double s = std::max(11.0 * unit_per_px, 1e-4); // glyph cell size in plane units
|
||||
const double step = s * 1.5; // vertical stacking step
|
||||
|
||||
// Representative anchor point on an entity (line midpoint, round-entity centre).
|
||||
auto anchor_of = [&](int ei) -> Vec2d {
|
||||
if (ei < 0 || ei >= int(m_entities.size())) return Vec2d(0, 0);
|
||||
const SketchEntity& e = m_entities[ei];
|
||||
switch (e.type) {
|
||||
case SketchEntity::Type::Line: return 0.5 * (e.p0 + e.p1);
|
||||
case SketchEntity::Type::Circle:
|
||||
case SketchEntity::Type::Ellipse:
|
||||
case SketchEntity::Type::Arc:
|
||||
case SketchEntity::Type::EllipseArc: return e.center;
|
||||
case SketchEntity::Type::BSpline: return 0.5 * (e.p0 + e.p1);
|
||||
case SketchEntity::Type::Point: return e.p0;
|
||||
}
|
||||
return e.p0;
|
||||
};
|
||||
const double s = std::max(kBadgePx * unit_per_px, 1e-4); // glyph cell size in plane units
|
||||
|
||||
// Unit-cell stroke authoring helpers (cell centred on origin).
|
||||
auto seg = [&](std::vector<std::pair<Vec2d, Vec2d>>& v, Vec2d a, Vec2d b) { v.emplace_back(a, b); };
|
||||
@@ -8507,23 +8622,31 @@ void DesignSketchTool::build_constraint_glyphs(double unit_per_px,
|
||||
}
|
||||
};
|
||||
|
||||
// Stack count per entity so successive badges step upward.
|
||||
std::vector<int> stack(m_entities.size(), 0);
|
||||
const Vec2d up(0.0, 1.0); // plane-space up; offset so badge sits off the geometry
|
||||
m_glyph_r = 0.6 * s;
|
||||
const std::vector<std::optional<Vec2d>> badges = constraint_badges(unit_per_px);
|
||||
for (size_t ci = 0; ci < cons.size(); ++ci) {
|
||||
const SketchEntityConstraintDef& d = cons[ci];
|
||||
if (d.ea < 0 || d.ea >= int(m_entities.size())) continue;
|
||||
const int k = stack[d.ea]++;
|
||||
const Vec2d center = anchor_of(d.ea) + up * (step * (1.0 + k));
|
||||
m_glyph_hits.push_back({center, int(ci)});
|
||||
if (!badges[ci]) continue;
|
||||
const Vec2d& center = *badges[ci];
|
||||
std::vector<std::pair<Vec2d, Vec2d>> cell;
|
||||
unit_glyph(d.type, cell);
|
||||
unit_glyph(cons[ci].type, cell);
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& into = int(ci) == m_sel_con ? out_selected : out;
|
||||
for (auto& sgp : cell)
|
||||
out.emplace_back(center + sgp.first * s, center + sgp.second * s);
|
||||
into.emplace_back(center + sgp.first * s, center + sgp.second * s);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignSketchTool::draw_constraint_badges(double unit_per_px)
|
||||
{
|
||||
std::vector<std::pair<Vec2d, Vec2d>> glyphs, selected;
|
||||
build_constraint_glyphs(unit_per_px, glyphs, selected);
|
||||
const double hw = std::max(0.9 * unit_per_px, 1e-4);
|
||||
if (!glyphs.empty())
|
||||
draw_strokes(m_fill_model, glyphs, hw, ColorRGBA(0.45f, 0.95f, 0.70f, 1.0f)); // CAD teal-green
|
||||
// The selected badge last, so it sits over a neighbour it touches, and bolder, so it reads as
|
||||
// picked at a glance and not only by its colour.
|
||||
if (!selected.empty())
|
||||
draw_strokes(m_fill_model, selected, 1.6 * hw, design_selection_color());
|
||||
}
|
||||
|
||||
void DesignSketchTool::draw_entities_preview(const std::vector<SketchEntity>& ents, const ColorRGBA& color)
|
||||
{
|
||||
std::vector<Vec2d> point_markers;
|
||||
@@ -8789,6 +8912,7 @@ void DesignSketchTool::recompute_op_ghost()
|
||||
void DesignSketchTool::op_pick(int ei)
|
||||
{
|
||||
if (ei < 0 || ei >= int(m_entities.size())) return;
|
||||
set_selected_constraint(-1); // the pick is the sketch's one selection now
|
||||
const SketchEntity::Type t = m_entities[ei].type;
|
||||
switch (m_mode) {
|
||||
case Mode::Fillet:
|
||||
@@ -9167,6 +9291,7 @@ void DesignSketchTool::compute_tf_pivot()
|
||||
void DesignSketchTool::tf_pick(int ei)
|
||||
{
|
||||
if (ei < 0 || ei >= int(m_entities.size())) return;
|
||||
set_selected_constraint(-1); // the pick is the sketch's one selection now
|
||||
auto it = std::find(m_tf_targets.begin(), m_tf_targets.end(), ei);
|
||||
if (it == m_tf_targets.end()) m_tf_targets.push_back(ei); // toggle-select like Mirror
|
||||
else m_tf_targets.erase(it);
|
||||
@@ -9732,8 +9857,7 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
const bool sel = (int(i) == m_pick0 || int(i) == m_pick1 || int(i) == m_pick2);
|
||||
// Constraint-manager highlight: the entities a selected constraint
|
||||
// references glow yellow (picked entities still win as red).
|
||||
const bool hl = !sel && std::find(m_constraint_hl.begin(), m_constraint_hl.end(),
|
||||
int(i)) != m_constraint_hl.end();
|
||||
const bool hl = !sel && bound_by_selected_constraint(int(i));
|
||||
const ColorRGBA col = sel ? sel_col : hl ? yellow : e.construction ? grey : orange;
|
||||
if (e.type == SketchEntity::Type::Point) { markers.push_back(e.p0); continue; }
|
||||
bool closed = false;
|
||||
@@ -9743,15 +9867,7 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
if (!markers.empty())
|
||||
draw_vertices(m_vertex_model, markers, orange);
|
||||
// Constraint badges (C3.4b): iconic glyphs near each constraint's entity.
|
||||
{
|
||||
const double upp = 1.0 / std::max(camera.get_zoom(), 1e-6);
|
||||
std::vector<std::pair<Vec2d, Vec2d>> glyphs;
|
||||
build_constraint_glyphs(upp, m_constrain_cons, glyphs);
|
||||
if (!glyphs.empty()) {
|
||||
const ColorRGBA badge(0.45f, 0.95f, 0.70f, 1.0f); // CAD teal-green
|
||||
draw_strokes(m_fill_model, glyphs, std::max(0.9 * upp, 1e-4), badge);
|
||||
}
|
||||
}
|
||||
draw_constraint_badges(1.0 / std::max(camera.get_zoom(), 1e-6));
|
||||
shader->stop_using();
|
||||
glsafe(::glEnable(GL_CULL_FACE));
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
@@ -9835,6 +9951,8 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
const bool editing_this =
|
||||
edit_hi && std::find(edit_hi->begin(), edit_hi->end(), int(i)) != edit_hi->end();
|
||||
const bool bad = i < m_entity_conflict.size() && m_entity_conflict[i];
|
||||
// The entities the selected constraint binds, in the yellow Constrain mode lights them in.
|
||||
const bool bound = bound_by_selected_constraint(int(i));
|
||||
// The first pick of an edit-op has a DIFFERENT ROLE from the rest of the selection —
|
||||
// Mirror's is the axis, Fillet/Chamfer's is the first of the two lines — and until now
|
||||
// every pick painted the same white, so the picture could not answer "what did I select
|
||||
@@ -9845,6 +9963,7 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
if (editing_this) col = editing;
|
||||
else if (op_ref) col = opref;
|
||||
else if (selected) col = sel_col;
|
||||
else if (bound) col = yellow;
|
||||
else if (bad) col = conflict;
|
||||
else if (e.construction) col = grey;
|
||||
else col = fully ? green : orange;
|
||||
@@ -9854,7 +9973,7 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
}
|
||||
bool closed = false;
|
||||
std::vector<Vec2d> poly = entity_polyline(e, closed);
|
||||
GLModel& target = (selected || editing_this || op_ref) ? m_highlight_model : m_line_model;
|
||||
GLModel& target = (selected || editing_this || op_ref || bound) ? m_highlight_model : m_line_model;
|
||||
if (e.construction) {
|
||||
for (const std::vector<Vec2d>& d : dash_polyline(poly, closed, 9.0 * upp_dash, 6.0 * upp_dash))
|
||||
draw_quad_strip(target, d, false, col);
|
||||
@@ -9867,18 +9986,12 @@ void DesignSketchTool::render(GLCanvas3D& canvas)
|
||||
if (!sel_point_markers.empty())
|
||||
draw_vertices(m_highlight_model, sel_point_markers, sel_col);
|
||||
|
||||
// Constraint badges during a LIVE sketch. They used to render only inside Mode::Constrain
|
||||
// on a COMMITTED feature, so every constraint applied while drawing — which is the path the
|
||||
// Constrain buttons take during a session — was invisible and unremovable: you could not
|
||||
// tell whether Parallel had been applied, nor take it back. Same glyphs, same teal, sourced
|
||||
// from this session's m_constraints; click one to delete it (remove_constraint_near).
|
||||
if (!m_constraints.empty()) {
|
||||
std::vector<std::pair<Vec2d, Vec2d>> glyphs;
|
||||
build_constraint_glyphs(upp_dash, m_constraints, glyphs);
|
||||
if (!glyphs.empty())
|
||||
draw_strokes(m_fill_model, glyphs, std::max(0.9 * upp_dash, 1e-4),
|
||||
ColorRGBA(0.45f, 0.95f, 0.70f, 1.0f)); // CAD teal-green
|
||||
}
|
||||
// Constraint badges during a LIVE sketch, not only inside Mode::Constrain on a COMMITTED
|
||||
// feature: a constraint applied while drawing — which is the path the Constrain buttons take
|
||||
// during a session — must be visible and removable, or you cannot tell whether Parallel was
|
||||
// applied, nor take it back. Same glyphs, same teal, sourced from this session's
|
||||
// m_constraints; click one to select it (click_constraint_badge), then Delete removes it.
|
||||
draw_constraint_badges(upp_dash);
|
||||
|
||||
// Endpoint / centre handles so individual points are visible and pickable in the
|
||||
// Select and Dimension tools (a line = a segment + 2 points). Selected ones cyan.
|
||||
@@ -10478,6 +10591,7 @@ int DesignSketchTool::add_entities_scripted(const std::vector<SketchEntity>& ent
|
||||
|
||||
bool DesignSketchTool::select_indices(const std::vector<int>& idx)
|
||||
{
|
||||
set_selected_constraint(-1);
|
||||
m_selection.clear();
|
||||
m_point_sel.clear();
|
||||
const int n = int(m_entities.size());
|
||||
@@ -10679,6 +10793,7 @@ bool DesignSketchTool::select_at_screen(GLCanvas3D& canvas, int sx, int sy)
|
||||
return false; // already selected: leave it alone
|
||||
m_selection.assign(1, ei);
|
||||
m_point_sel.clear();
|
||||
set_selected_constraint(-1);
|
||||
if (on_selection_changed) on_selection_changed(1);
|
||||
return true;
|
||||
}
|
||||
@@ -10687,6 +10802,7 @@ bool DesignSketchTool::select_at_screen(GLCanvas3D& canvas, int sx, int sy)
|
||||
return false; // already selected: leave it alone
|
||||
m_selection.clear();
|
||||
m_point_sel.assign(1, pr);
|
||||
set_selected_constraint(-1);
|
||||
if (on_selection_changed) on_selection_changed(1);
|
||||
return true;
|
||||
}
|
||||
@@ -10697,6 +10813,7 @@ bool DesignSketchTool::select_at_screen(GLCanvas3D& canvas, int sx, int sy)
|
||||
return false; // already selected: leave it alone
|
||||
m_selection.assign(1, hit);
|
||||
m_point_sel.clear();
|
||||
set_selected_constraint(-1);
|
||||
if (on_selection_changed) on_selection_changed(1);
|
||||
return true;
|
||||
}
|
||||
@@ -11407,31 +11524,12 @@ bool DesignSketchTool::on_mouse_impl(wxMouseEvent& evt, GLCanvas3D& canvas)
|
||||
// camera can still orbit while inspecting the sketch.
|
||||
if (m_mode == Mode::Constrain) {
|
||||
if (m_constrain_entities) {
|
||||
// Pick any entity (line/circle/arc/point): rolling two-slot selection.
|
||||
// Pick any entity (line/circle/arc/point): rolling two-slot selection. Same reach as
|
||||
// every other tool that picks an entity to act on.
|
||||
if (evt.LeftDown()) {
|
||||
Vec2d p;
|
||||
screen_to_plane(canvas, evt, p);
|
||||
double best = 1e30;
|
||||
int bi = -1;
|
||||
for (size_t i = 0; i < m_entities.size(); ++i) {
|
||||
const double d = entity_pick_dist(p, m_entities[i]);
|
||||
if (d < best) { best = d; bi = int(i); }
|
||||
}
|
||||
// Same reach as every other tool that picks an entity to act on. With no limit,
|
||||
// a click anywhere on screen picked whatever was nearest; empty space now clears.
|
||||
if (bi >= 0 && best > screen_tol(canvas, evt, p, kToolPickPx)) {
|
||||
bi = -1;
|
||||
m_pick0 = m_pick1 = m_pick2 = -1;
|
||||
}
|
||||
if (bi >= 0) {
|
||||
// Rolling three-slot selection: slots 0/1 feed all 2-entity
|
||||
// constraints; slot 2 is the Symmetric axis (only filled once
|
||||
// 0 and 1 are set). A click past slot 2 restarts the cycle.
|
||||
if (m_pick0 < 0) { m_pick0 = bi; m_pick0_pt = p; }
|
||||
else if (m_pick1 < 0 && bi != m_pick0) m_pick1 = bi;
|
||||
else if (m_pick1 >= 0 && m_pick2 < 0 && bi != m_pick0 && bi != m_pick1) m_pick2 = bi;
|
||||
else { m_pick0 = bi; m_pick1 = m_pick2 = -1; m_pick0_pt = p; }
|
||||
}
|
||||
constrain_pick(p, screen_tol(canvas, evt, p, kToolPickPx));
|
||||
return true;
|
||||
}
|
||||
// The picks are this mode's selection, and right-click on a selection opens the
|
||||
@@ -11455,6 +11553,7 @@ bool DesignSketchTool::on_mouse_impl(wxMouseEvent& evt, GLCanvas3D& canvas)
|
||||
m_sel_a = bi;
|
||||
m_sel_b = int((bi + 1) % n);
|
||||
}
|
||||
set_selected_constraint(-1);
|
||||
return true;
|
||||
}
|
||||
return false; // right-click included: the offer opens on the picked segment
|
||||
@@ -11466,19 +11565,6 @@ bool DesignSketchTool::on_mouse_impl(wxMouseEvent& evt, GLCanvas3D& canvas)
|
||||
if (update_hover(canvas, evt)) return true; // repaint when the hovered handle changes
|
||||
const bool extend = evt.ShiftDown() || evt.ControlDown();
|
||||
|
||||
// A constraint badge is a click target: clicking it DELETES that constraint. Existing or
|
||||
// not is the whole of a constraint's state, so this click is the toggle. Checked before
|
||||
// entity picking because badges sit clear of the geometry (offset along +Y), so a hit
|
||||
// here is unambiguous; plain click only, so Shift/Ctrl multi-select is never eaten.
|
||||
if (evt.LeftDown() && !extend) {
|
||||
Vec2d gp;
|
||||
if (screen_to_plane(canvas, evt, gp) && remove_constraint_near(gp)) {
|
||||
if (on_selection_changed)
|
||||
on_selection_changed(int(m_selection.size() + m_point_sel.size()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Live point drag: once an endpoint/centre was grabbed on LeftDown, dragging
|
||||
// moves it (re-solving constraints live) until the button is released. When
|
||||
// nothing is grabbed, drag falls through so the camera can still orbit.
|
||||
@@ -11626,6 +11712,17 @@ bool DesignSketchTool::on_mouse_impl(wxMouseEvent& evt, GLCanvas3D& canvas)
|
||||
}
|
||||
}
|
||||
|
||||
// A constraint badge: a plain click selects its constraint, and so does the double-click
|
||||
// that follows it. After the value labels, which are drawn over any badge under them, so
|
||||
// a click on a label always opens its field. Before the geometry, which a badge of
|
||||
// another entity may sit on.
|
||||
if (!extend &&
|
||||
click_constraint_badge(p, 1.0 / std::max(wxGetApp().plater()->get_camera().get_zoom(), 1e-6)))
|
||||
return true;
|
||||
// Any other press picks geometry or clears the selection, and a sketch holds one
|
||||
// selection at a time.
|
||||
set_selected_constraint(-1);
|
||||
|
||||
// A derived handle (the circle RadiusHandle — not an entity point, so
|
||||
// hit_test_point can't grab it) arms a handle drag that resizes on motion.
|
||||
// Checked before the point/entity hit-tests so the radius grip wins near
|
||||
|
||||
@@ -510,16 +510,43 @@ public:
|
||||
bool selected_constrain_entities(int& e0, int& e1) const { e0 = m_pick0; e1 = m_pick1; return m_pick0 >= 0; }
|
||||
// Third pick slot (Symmetric axis): only filled after slots 0 and 1 are set.
|
||||
int pick2() const { return m_pick2; }
|
||||
// A Constrain-mode click at `p` in plane coordinates: fills the next pick slot with the entity
|
||||
// nearest `p` within `reach`, or drops the picks when none is that near. Either way it drops the
|
||||
// selected constraint, since a sketch holds one selection at a time.
|
||||
void constrain_pick(const Vec2d& p, double reach);
|
||||
// Plane-coords of the click that filled slot 0 (for pick-point edit ops: trim/extend).
|
||||
bool pick0_point(Vec2d& out) const { out = m_pick0_pt; return m_pick0 >= 0; }
|
||||
// Refresh the displayed entities after the kernel re-solved them.
|
||||
void set_constrain_entities(const std::vector<SketchEntity>& ents) { m_entities = ents; }
|
||||
// Constraint manager (C3.4): entity indices the panel asks to highlight (the
|
||||
// entities a selected constraint references); rendered yellow in Constrain mode.
|
||||
void set_constraint_highlight(std::vector<int> v) { m_constraint_hl = std::move(v); }
|
||||
// The committed feature's constraints, supplied so Constrain-mode render can draw
|
||||
// an iconic glyph badge per constraint near its primary entity (C3.4b).
|
||||
void set_constraint_glyphs(std::vector<SketchEntityConstraintDef> v) { m_constrain_cons = std::move(v); }
|
||||
// an iconic glyph badge per constraint near its primary entity (C3.4b). In Constrain mode a
|
||||
// set of another size drops the selected constraint, whose index no longer names it.
|
||||
void set_constraint_glyphs(std::vector<SketchEntityConstraintDef> v);
|
||||
|
||||
// ---- Constraint selection -----------------------------------------------------------
|
||||
// One of the constraints on show, picked by a click on its badge or from the panel's list:
|
||||
// its badge wears the selection colour and the entities it binds are highlighted. The
|
||||
// constraints on show are the live session's, or in Constrain mode the committed feature's
|
||||
// (set_constraint_glyphs). A sketch holds one selection at a time, so selecting a constraint
|
||||
// drops the picked geometry and picking geometry drops the constraint. -1 for none.
|
||||
int selected_constraint() const { return m_sel_con; }
|
||||
// Select constraint `con`; -1, or an index not on show, clears the selection.
|
||||
void select_constraint(int con);
|
||||
// Where constraint `con`'s badge is drawn at `unit_per_px` plane units per pixel. Badges stack
|
||||
// up the plane's +Y from the middle of the constraint's first entity, one 11 px cell each,
|
||||
// 1.5 cells apart. Nothing for an index not on show, or for a constraint whose first reference
|
||||
// is the origin or an axis, which has no badge.
|
||||
std::optional<Vec2d> constraint_badge(int con, double unit_per_px) const;
|
||||
// A plain Select-mode click at `p` on a constraint badge selects that constraint. It only
|
||||
// selects: a badge is small and sits where a person aims at the geometry and its labels, so
|
||||
// deleting takes Delete or the list's button. False, with nothing changed, when no badge lies
|
||||
// under `p`.
|
||||
bool click_constraint_badge(const Vec2d& p, double unit_per_px);
|
||||
// What Zoom to selection frames for constraint `con`: the entities it binds, in world
|
||||
// coordinates. Undefined when it binds none on show.
|
||||
BoundingBoxf3 constraint_box(int con) const;
|
||||
// The selected constraint changed; `con` is the new one, -1 for none.
|
||||
std::function<void(int con)> on_constraint_selected;
|
||||
|
||||
// Line tool: after a single segment is placed, the panel pops a length dialog
|
||||
// (length, angle_deg are the as-drawn values); it then resolves via
|
||||
@@ -552,7 +579,7 @@ public:
|
||||
const std::vector<int>& selection() const { return m_selection; }
|
||||
// Entities OR bare points: clear_selection() drops both, so "is anything picked" must ask
|
||||
// about both, or Esc at idle would report nothing to do while a point sat highlighted.
|
||||
bool sketch_has_selection() const { return !m_selection.empty() || !m_point_sel.empty(); }
|
||||
bool sketch_has_selection() const { return !m_selection.empty() || !m_point_sel.empty() || m_sel_con >= 0; }
|
||||
// Type of the first selected entity. False when nothing is selected, so the offer menu can
|
||||
// tell a line from an arc from a point and stop collapsing every sketch selection to "none".
|
||||
bool first_selected_type(SketchEntity::Type& out) const {
|
||||
@@ -587,11 +614,7 @@ public:
|
||||
// inconsistent. Returns true when the batch was kept. Public so the panel's live-constraint
|
||||
// path can commit a plan through the SAME append→solve→keep-or-rollback the gestures use.
|
||||
bool try_add_constraints(const std::vector<SketchEntityConstraintDef>& cands);
|
||||
// Click-to-delete on a constraint badge: drop the constraint whose glyph sits under `p`
|
||||
// and re-solve. Returns true if one was removed (the caller then repaints).
|
||||
bool remove_constraint_near(const Vec2d& p);
|
||||
// Drop constraint `idx` from the live session and re-solve. Same operation the badge click
|
||||
// performs, addressed by index instead of by position — the panel list needs the index form.
|
||||
// Drop constraint `idx` from the live session and re-solve.
|
||||
bool remove_constraint(int idx);
|
||||
|
||||
// The loop report: what is CLOSED, what its internal voids are, and where a chain is still
|
||||
@@ -755,6 +778,7 @@ private:
|
||||
static constexpr double kToolPickPx = 24.0; // pick an entity for a tool to act on (trim, edit-ops,
|
||||
// transforms, constrain)
|
||||
static constexpr double kLabelPx = 24.0; // click or double-click a value label
|
||||
static constexpr double kBadgePx = 11.0; // a constraint badge's cell
|
||||
double screen_tol(GLCanvas3D& canvas, const wxMouseEvent& evt, const Vec2d& at, double px = kPickPx) const;
|
||||
// Run kernel inference at the cursor, cache the target for the hint renderer.
|
||||
InferenceSnap infer_at(GLCanvas3D& canvas, const wxMouseEvent& evt, const Vec2d& raw) const;
|
||||
@@ -952,12 +976,28 @@ private:
|
||||
// editing shows live values; click one (m_live_quotes) to promote it to a driving
|
||||
// dim. Self-gates; skips a dim already driven on that entity.
|
||||
void render_live_quotes(double unit_per_px);
|
||||
// Iconic constraint badges (C3.4b): for each m_constrain_cons entry, append a
|
||||
// small screen-constant glyph (H, V, ∥, ⊥, =, ○, …) near its primary entity into
|
||||
// `out`; glyphs touching the same entity stack so they don't overlap.
|
||||
// Iconic constraint badges (C3.4b): for each constraint on show, append a small
|
||||
// screen-constant glyph (H, V, ∥, ⊥, =, ○, …) at its constraint_badge() into `out`, the
|
||||
// selected constraint's into `out_selected`, so it can be drawn in the selection colour.
|
||||
void build_constraint_glyphs(double unit_per_px,
|
||||
const std::vector<SketchEntityConstraintDef>& cons,
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out);
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out,
|
||||
std::vector<std::pair<Vec2d, Vec2d>>& out_selected) const;
|
||||
// Draw every badge of the constraints on show, the selected one in the selection colour.
|
||||
void draw_constraint_badges(double unit_per_px);
|
||||
// Every badge centre of the constraints on show, in order (see constraint_badge()).
|
||||
std::vector<std::optional<Vec2d>> constraint_badges(double unit_per_px) const;
|
||||
// The live session's constraints, or in Constrain mode the committed feature's.
|
||||
const std::vector<SketchEntityConstraintDef>& shown_constraints() const
|
||||
{
|
||||
return m_mode == Mode::Constrain ? m_constrain_cons : m_constraints;
|
||||
}
|
||||
// Whether entity `ei` is one the selected constraint binds, to highlight it.
|
||||
bool bound_by_selected_constraint(int ei) const;
|
||||
// The one write of m_sel_con: reports a change through on_constraint_selected.
|
||||
void set_selected_constraint(int con);
|
||||
// After the live constraints were rewritten, `remap[i]` being constraint i's new index
|
||||
// (-1 for dropped): keep the selected constraint selected under its new index.
|
||||
void remap_selected_constraint(const std::vector<int>& remap);
|
||||
void draw_strokes(GLModel& model, const std::vector<std::pair<Vec2d, Vec2d>>& segs,
|
||||
double hw, const ColorRGBA& color);
|
||||
void draw_text(GLModel& model, const std::string& s, const Vec2d& center,
|
||||
@@ -1248,13 +1288,8 @@ private:
|
||||
int m_pick1{-1};
|
||||
int m_pick2{-1}; // third slot (Symmetric axis)
|
||||
Vec2d m_pick0_pt{0,0}; // plane-coords of the slot-0 pick (trim/extend)
|
||||
std::vector<int> m_constraint_hl; // entities highlighted by the constraint manager
|
||||
std::vector<SketchEntityConstraintDef> m_constrain_cons; // for glyph badges (C3.4b)
|
||||
// Where each badge landed, so a click can find the constraint it stands for. Rebuilt by
|
||||
// build_constraint_glyphs on every render, which is always the frame the user clicked on.
|
||||
struct GlyphHit { Vec2d c{0,0}; int con{-1}; };
|
||||
std::vector<GlyphHit> m_glyph_hits;
|
||||
double m_glyph_r{0.0}; // badge half-size in plane units (hit radius)
|
||||
int m_sel_con{-1}; // the selected constraint, an index into shown_constraints()
|
||||
GLModel m_line_model;
|
||||
GLModel m_vertex_model;
|
||||
GLModel m_highlight_model;
|
||||
|
||||
@@ -464,3 +464,214 @@ TEST_CASE("A move arrow pressed while looking down its axis does not jump on the
|
||||
tool.drag_move_arrow(ray_at(15.));
|
||||
CHECK_THAT(moved.translation().x(), WithinAbs(2., 1e-9));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A 100 x 60 mm rectangle in a fresh Select-mode session on XY, its four sides added as one drawn
|
||||
// gesture adds them, top side first, so the tool infers what a drawn one gets: a Coincident at each
|
||||
// corner and a Horizontal or Vertical on each side.
|
||||
void draw_rectangle(DesignSketchTool& tool)
|
||||
{
|
||||
tool.begin(SketchPlane::XY(), DesignSketchTool::Mode::Select);
|
||||
const Vec2d corners[] = { { -50., 30. }, { 50., 30. }, { 50., -30. }, { -50., -30. } };
|
||||
std::vector<SketchEntity> sides;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
SketchEntity e;
|
||||
e.type = SketchEntity::Type::Line;
|
||||
e.p0 = corners[i];
|
||||
e.p1 = corners[(i + 1) % 4];
|
||||
sides.push_back(e);
|
||||
}
|
||||
tool.add_entities_scripted(sides);
|
||||
}
|
||||
|
||||
// The index of the constraint of type `type` on side `side`, or -1.
|
||||
int constraint_on(const DesignSketchTool& tool, SketchConstraintType type, int side)
|
||||
{
|
||||
const std::vector<SketchEntityConstraintDef>& cons = tool.constraints();
|
||||
for (size_t i = 0; i < cons.size(); ++i)
|
||||
if (cons[i].type == type && cons[i].ea == side)
|
||||
return int(i);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// The view's scale for the badge clicks below: half a millimetre per pixel.
|
||||
constexpr double kUnitPerPx = 0.5;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("A click on a constraint badge selects that constraint and keeps it", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
const size_t count = tool.constraints().size();
|
||||
const int top = constraint_on(tool, SketchConstraintType::Horizontal, 0);
|
||||
REQUIRE(top >= 0);
|
||||
const std::optional<Vec2d> badge = tool.constraint_badge(top, kUnitPerPx);
|
||||
REQUIRE(badge.has_value());
|
||||
|
||||
CHECK(tool.click_constraint_badge(*badge, kUnitPerPx));
|
||||
CHECK(tool.selected_constraint() == top);
|
||||
CHECK(tool.constraints().size() == count);
|
||||
}
|
||||
|
||||
TEST_CASE("A click off every constraint badge selects no constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
|
||||
CHECK_FALSE(tool.click_constraint_badge(Vec2d(0., 0.), kUnitPerPx));
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("A badge click reports the constraint it selected", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
std::vector<int> reported;
|
||||
tool.on_constraint_selected = [&reported](int con) { reported.push_back(con); };
|
||||
const int top = constraint_on(tool, SketchConstraintType::Horizontal, 0);
|
||||
REQUIRE(top >= 0);
|
||||
const std::optional<Vec2d> badge = tool.constraint_badge(top, kUnitPerPx);
|
||||
REQUIRE(badge.has_value());
|
||||
|
||||
tool.click_constraint_badge(*badge, kUnitPerPx);
|
||||
CHECK(reported == std::vector<int>{ top });
|
||||
}
|
||||
|
||||
TEST_CASE("Deleting the selected constraint removes only that one and drops the selection", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
const size_t count = tool.constraints().size();
|
||||
const int top = constraint_on(tool, SketchConstraintType::Horizontal, 0);
|
||||
REQUIRE(top >= 0);
|
||||
tool.select_constraint(top);
|
||||
|
||||
// What Delete does with a constraint selected (DesignPanel::delete_sketch_selection).
|
||||
CHECK(tool.remove_constraint(tool.selected_constraint()));
|
||||
CHECK(tool.constraints().size() == count - 1);
|
||||
CHECK(constraint_on(tool, SketchConstraintType::Horizontal, 0) == -1);
|
||||
CHECK(constraint_on(tool, SketchConstraintType::Horizontal, 2) >= 0);
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("Picking geometry drops the selected constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
tool.select_constraint(constraint_on(tool, SketchConstraintType::Horizontal, 0));
|
||||
REQUIRE(tool.selected_constraint() >= 0);
|
||||
|
||||
tool.select_indices({ 1 });
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("Selecting a constraint drops the picked geometry", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
tool.select_indices({ 1 });
|
||||
REQUIRE_FALSE(tool.selection().empty());
|
||||
|
||||
tool.select_constraint(constraint_on(tool, SketchConstraintType::Horizontal, 0));
|
||||
CHECK(tool.selection().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Clearing the sketch selection drops a selected constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
tool.select_constraint(constraint_on(tool, SketchConstraintType::Horizontal, 0));
|
||||
// Esc asks this before deciding whether it has a selection to drop.
|
||||
REQUIRE(tool.sketch_has_selection());
|
||||
|
||||
tool.clear_selection();
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("The selected constraint stays selected when an earlier one is deleted", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
const int top = constraint_on(tool, SketchConstraintType::Horizontal, 0);
|
||||
REQUIRE(top > 0);
|
||||
tool.select_constraint(top);
|
||||
|
||||
tool.remove_constraint(0);
|
||||
REQUIRE(tool.selected_constraint() == top - 1);
|
||||
CHECK(tool.constraints()[top - 1].type == SketchConstraintType::Horizontal);
|
||||
CHECK(tool.constraints()[top - 1].ea == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Undoing the geometry a selected constraint binds drops the selection", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
// Undo takes away at least the side drawn last, the left one.
|
||||
tool.select_constraint(constraint_on(tool, SketchConstraintType::Vertical, 3));
|
||||
REQUIRE(tool.selected_constraint() >= 0);
|
||||
|
||||
REQUIRE(tool.undo_last_entity());
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("Switching tools drops the selected constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
draw_rectangle(tool);
|
||||
tool.select_constraint(constraint_on(tool, SketchConstraintType::Horizontal, 0));
|
||||
REQUIRE(tool.selected_constraint() >= 0);
|
||||
|
||||
tool.set_tool(DesignSketchTool::Mode::Move);
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// The rectangle of draw_rectangle() opened in Constrain mode as a committed sketch, its constraints
|
||||
// on show as the Design panel shows them.
|
||||
void constrain_rectangle(DesignSketchTool& tool)
|
||||
{
|
||||
DesignSketchTool drawn;
|
||||
draw_rectangle(drawn);
|
||||
tool.begin_constrain_entities(drawn.entities(), SketchPlane::XY());
|
||||
tool.set_constraint_glyphs(drawn.constraints());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Selecting a constraint in Constrain mode drops the entity picks", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
constrain_rectangle(tool);
|
||||
tool.constrain_pick(Vec2d(0., 30.), 1.); // the top side's middle
|
||||
int e0 = -1, e1 = -1;
|
||||
REQUIRE(tool.selected_constrain_entities(e0, e1));
|
||||
|
||||
tool.select_constraint(0);
|
||||
REQUIRE(tool.selected_constraint() == 0);
|
||||
CHECK_FALSE(tool.selected_constrain_entities(e0, e1));
|
||||
}
|
||||
|
||||
TEST_CASE("A Constrain-mode pick drops the selected constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
constrain_rectangle(tool);
|
||||
tool.select_constraint(0);
|
||||
REQUIRE(tool.selected_constraint() == 0);
|
||||
|
||||
tool.constrain_pick(Vec2d(0., 30.), 1.);
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("A Constrain-mode click on empty space drops the selected constraint", "[DesignSketchTool]")
|
||||
{
|
||||
DesignSketchTool tool;
|
||||
constrain_rectangle(tool);
|
||||
tool.select_constraint(0);
|
||||
REQUIRE(tool.selected_constraint() == 0);
|
||||
|
||||
tool.constrain_pick(Vec2d(0., 0.), 1.); // the rectangle's centre, 30 mm from every side
|
||||
CHECK(tool.selected_constraint() == -1);
|
||||
}
|
||||
Reference in new issue
Block a user