KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_edit_tool.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef CONSTRAINT_EDIT_TOOL_H_
21#define CONSTRAINT_EDIT_TOOL_H_
22
23#include <map>
24#include <memory>
25#include <unordered_set>
26#include <vector>
27
28#include <tools/pcb_tool_base.h>
30
31class PCB_SHAPE;
32class PCB_CONSTRAINT;
36
37namespace KIGFX
38{
40}
41
42
52{
53public:
55 ~CONSTRAINT_EDIT_TOOL() override = default;
56
57 void Reset( RESET_REASON aReason ) override;
58 bool Init() override;
59
60 int AddConstraint( const TOOL_EVENT& aEvent );
61 int AddPointConstraint( const TOOL_EVENT& aEvent );
62 int RemoveConstraints( const TOOL_EVENT& aEvent );
63 int ShowConstraints( const TOOL_EVENT& aEvent );
64 int ManageConstraints( const TOOL_EVENT& aEvent );
65
69 bool SelectConstraintAt( const VECTOR2I& aPos );
70
72 bool EditConstraintAt( const VECTOR2I& aPos );
73
76
80
84
86 void SolveAfterMove( const std::vector<PCB_SHAPE*>& aShapes );
87
90 void SolveAfterEdit( const std::vector<PCB_SHAPE*>& aShapes );
91
94 void DiagnoseAfterMove( const std::vector<PCB_SHAPE*>& aShapes );
95
98 void RemoveConstraintById( const KIID& aId );
99 void EditConstraintById( const KIID& aId );
100 void HighlightConstraintMembers( const KIID& aId, int aMemberIndex );
101
103 int refreshOverlay( const TOOL_EVENT& aEvent );
104
106 int onSelectionChanged( const TOOL_EVENT& aEvent );
107
109 int onHoverMotion( const TOOL_EVENT& aEvent );
110
111private:
112 void setTransitions() override;
113
116
119 const std::vector<PCB_CONSTRAINT*>& aAdded );
120
122 bool commitConstraint( std::unique_ptr<PCB_CONSTRAINT> aConstraint );
123
125 int pickShapeConstraint( PCB_CONSTRAINT_TYPE aType, const TOOL_EVENT& aEvent );
126
129 int pickLinearConstraint( PCB_CONSTRAINT_TYPE aType, const TOOL_EVENT& aEvent );
130
132 void solveAddedConstraint( PCB_CONSTRAINT* aConstraint );
133
135 PCB_CONSTRAINT* hitTestBadge( const VECTOR2I& aPos ) const;
136
138 void setSelectedConstraint( PCB_CONSTRAINT* aConstraint );
139
142
146
150
153 void repaintShadowItems( const std::unordered_set<KIID>& aOld, const std::unordered_set<KIID>& aNew );
154
157 void updateConstraintMsgPanel( PCB_CONSTRAINT* aConstraint );
158
160 void refreshDiagnostics();
161
165
169
171 const std::vector<PCB_SHAPE*>& hoverCandidates();
172
176
178 void removeConstraint( PCB_CONSTRAINT* aConstraint );
179
181 PCB_CONSTRAINT* resolveConstraint( const KIID& aId ) const;
182
184 void editConstraint( PCB_CONSTRAINT* aConstraint );
185
188 bool allMembersLocked( const PCB_CONSTRAINT* aConstraint ) const;
189
192 bool isDuplicateConstraint( const PCB_CONSTRAINT* aConstraint ) const;
193
194private:
197 std::unique_ptr<CONSTRAINT_OVERLAY> m_overlay;
199
203 bool m_diagDirty = true;
204 std::optional<std::vector<PCB_SHAPE*>> m_hoverCandidates;
205
208 std::map<PCB_CONSTRAINT_TYPE, double> m_lastConstraintValue;
209 std::map<PCB_CONSTRAINT_TYPE, bool> m_lastConstraintDriving;
210};
211
212#endif // CONSTRAINT_EDIT_TOOL_H_
An incremental DiagnoseBoardConstraints for the interactive edit path.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
bool Init() override
Init() is called once upon a registration of the tool.
bool commitConstraint(std::unique_ptr< PCB_CONSTRAINT > aConstraint)
Confirm any value, reject a duplicate, and commit aConstraint. Returns true if it was added.
~CONSTRAINT_EDIT_TOOL() override=default
int pickShapeConstraint(PCB_CONSTRAINT_TYPE aType, const TOOL_EVENT &aEvent)
Author a whole-shape constraint by clicking its items on the canvas (the no-selection path).
void removeConstraint(PCB_CONSTRAINT *aConstraint)
Remove a constraint in its own commit and refresh the diagnostics.
std::unique_ptr< CONSTRAINT_OVERLAY > m_overlay
BOARD_CONSTRAINT_DIAGNOSTICS m_cachedDiag
Reused until the model changes.
int onHoverMotion(const TOOL_EVENT &aEvent)
In HOVER mode, reveal the constraints of the shape under the cursor (nothing when none).
int AddConstraint(const TOOL_EVENT &aEvent)
void updateConstrainedItems(const BOARD_CONSTRAINT_DIAGNOSTICS &aDiag)
Stash the constrained-item set (the shadow-layer gate) into the render settings and repaint the overl...
PCB_SELECTION_TOOL * m_selectionTool
PCB_CONSTRAINT * hitTestBadge(const VECTOR2I &aPos) const
The constraint whose badge is within the hit radius of aPos, or nullptr.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void updateConstraintMsgPanel(PCB_CONSTRAINT *aConstraint)
Show the selected constraint's type, items and state in the bottom message panel.
void DiagnoseAfterMove(const std::vector< PCB_SHAPE * > &aShapes)
Re-diagnose and refresh the overlay and info bar after the caller re-solves aShapes into its own comm...
void refreshDiagnostics()
Mark the diagnosis and candidate caches stale (the model changed) and re-render the views.
void renderConstraintViews()
Re-render the shown views from the cached diagnosis without invalidating it – for a bare visibility c...
void applyDiagnostics(const BOARD_CONSTRAINT_DIAGNOSTICS &aDiag)
Push an already-computed diagnosis into every shown view, so a caller that already solved does not so...
bool SelectConstraintAt(const VECTOR2I &aPos)
Select the constraint whose on-canvas badge is at aPos (enlarge it, highlight the panel row); returns...
PCB_CONSTRAINT * resolveConstraint(const KIID &aId) const
Resolve a constraint by KIID against the live board, or nullptr.
bool TryDeleteSelectedConstraint()
Delete the currently badge-selected constraint; returns true if one was selected and removed.
void repaintShadowItems(const std::unordered_set< KIID > &aOld, const std::unordered_set< KIID > &aNew)
Re-cache the items whose shadow-set membership changed between aOld and aNew, so the cached constrain...
void SolveAfterEdit(const std::vector< PCB_SHAPE * > &aShapes)
Re-solve after a panel or dialog edit holding aShapes fixed so typed values survive Only their constr...
CONDITIONAL_MENU * m_menu
int RemoveConstraints(const TOOL_EVENT &aEvent)
void setSelectedConstraint(PCB_CONSTRAINT *aConstraint)
Mark aConstraint selected on the overlay and in the panel (nullptr clears).
std::optional< std::vector< PCB_SHAPE * > > m_hoverCandidates
Constrained shapes, per model.
void RemoveConstraintById(const KIID &aId)
Intent entry points for the constraints panel, so it never mutates the board or the selection itself ...
std::map< PCB_CONSTRAINT_TYPE, bool > m_lastConstraintDriving
bool ClearConstraintSelection()
Clear any badge-selected constraint. Returns true if a constraint was selected and is now cleared.
bool allMembersLocked(const PCB_CONSTRAINT *aConstraint) const
True if every item aConstraint references resolves and is locked (nothing the solver may move),...
int ManageConstraints(const TOOL_EVENT &aEvent)
void finishConstraintCommit(BOARD_COMMIT &aCommit, const std::vector< PCB_CONSTRAINT * > &aAdded)
Push aCommit, snap the geometry for the added constraints, and refresh the overlays.
KIGFX::PCB_RENDER_SETTINGS * pcbRenderSettings() const
The active PCB render settings, or nullptr when no painter is attached (headless).
void HighlightConstraintMembers(const KIID &aId, int aMemberIndex)
const BOARD_CONSTRAINT_DIAGNOSTICS & ensureDiagnosis()
The cached board diagnosis, solved only when the model changed since the last call,...
bool TryEditSelectedConstraint()
Edit the currently badge-selected constraint's value; returns true if one was selected.
bool isDuplicateConstraint(const PCB_CONSTRAINT *aConstraint) const
True if the board already holds a constraint equal to aConstraint (same type and members),...
int pickLinearConstraint(PCB_CONSTRAINT_TYPE aType, const TOOL_EVENT &aEvent)
Author a horizontal or vertical constraint from a whole segment or two point anchors Clicking a point...
void EditConstraintById(const KIID &aId)
int refreshOverlay(const TOOL_EVENT &aEvent)
Refresh the diagnostics overlay if it is currently shown.
BOARD_ITEM * constraintParent() const
The owner a new constraint should be parented to (the footprint in the footprint editor).
void SolveAfterMove(const std::vector< PCB_SHAPE * > &aShapes)
Re-solve the clusters of aShapes after a whole-shape edit, folded into that edit's undo.
bool EditConstraintAt(const VECTOR2I &aPos)
Open the value dialog for the constraint badged at aPos; returns true if one was hit.
int ShowConstraints(const TOOL_EVENT &aEvent)
void editConstraint(PCB_CONSTRAINT *aConstraint)
Open the value dialog for a constraint and, on accept, commit + re-solve + refresh.
BOARD_CONSTRAINT_DIAGNOSER m_diagnoser
Incremental board diagnoser for the hot edit path, so editing one shape re-solves only its own cluste...
const std::vector< PCB_SHAPE * > & hoverCandidates()
The shapes referenced by any constraint, the hover-hit candidate set (cached per model).
int onSelectionChanged(const TOOL_EVENT &aEvent)
Clear stale badge/isolation state when the board selection changes.
std::map< PCB_CONSTRAINT_TYPE, double > m_lastConstraintValue
Last value and driving choice per constraint type this session so same type runs keep one size Keyed ...
int AddPointConstraint(const TOOL_EVENT &aEvent)
void updateHighlightedConstraintMembers(PCB_CONSTRAINT *aConstraint)
Stash the selected constraint's members (the highlighted-shadow set) into the render settings and rep...
void solveAddedConstraint(PCB_CONSTRAINT *aConstraint)
Solve a just-added constraint so the geometry snaps to satisfy it, in its own commit.
PCB specific render settings.
Definition pcb_painter.h:80
Definition kiid.h:44
A geometric constraint between board items (issue #2329).
The selection tool: currently supports:
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
Board-wide diagnostics for the constraint overlay and info bar.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683