KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_move_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 (C) 2019 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_SCH_MOVE_TOOL_H
22#define KICAD_SCH_MOVE_TOOL_H
23
24#include <tools/sch_tool_base.h>
25#include <sch_base_frame.h>
26#include <unordered_map>
27#include <unordered_set>
28
29
30class SCH_EDIT_FRAME;
32class SCH_LINE;
33class SCH_LABEL_BASE;
34class SCH_SHEET_PIN;
35class SCH_JUNCTION;
36class SCH_SELECTION;
37class SCH_SHEET;
38class SCH_COMMIT;
39class SCH_ITEM;
40class EE_GRID_HELPER;
41
42enum GRID_HELPER_GRIDS : int;
43
44
53
54
55class SCH_MOVE_TOOL : public SCH_TOOL_BASE<SCH_EDIT_FRAME>
56{
57public:
65
67 ~SCH_MOVE_TOOL() override { }
68
70 bool Init() override;
71
73 void Reset( RESET_REASON aReason ) override;
74
78 int Main( const TOOL_EVENT& aEvent );
79
86 int AlignToGrid( const TOOL_EVENT& aEvent );
87
88private:
89 bool doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit );
90
91 void moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta );
92
96 void getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint, EDA_ITEMS& aList );
97 void getConnectedDragItems( SCH_COMMIT* aCommit, SCH_ITEM* fixed, const VECTOR2I& selected,
98 EDA_ITEMS& aList );
99
100 void orthoLineDrag( SCH_COMMIT* aCommit, SCH_LINE* line, const VECTOR2I& splitDelta,
101 int& xBendCount, int& yBendCount, const EE_GRID_HELPER& grid );
102
103 void moveSelectionToSheet( SCH_SELECTION& aSelection, SCH_SHEET* aTarget, SCH_COMMIT* aCommit );
104
106 void clearNewDragLines();
107
109 void setTransitions() override;
110
112 void trimDanglingLines( SCH_COMMIT* aCommit );
113
115 void preprocessBreakOrSliceSelection( SCH_COMMIT* aCommit, const TOOL_EVENT& aEvent );
116
117 // Helper methods for doMoveSelection refactoring
119 SCH_SELECTION& prepareSelection( bool& aUnselect );
120
122 void refreshSelectionTraits( const SCH_SELECTION& aSelection, bool& aHasSheetPins,
123 bool& aHasGraphicItems, bool& aHasNonGraphicItems,
124 bool& aIsGraphicsOnly );
125
127 void restartMoveOperation( const TOOL_EVENT& aEvent, SCH_SELECTION& aSelection, SCH_COMMIT* aCommit,
128 std::vector<DANGLING_END_ITEM>& aInternalPoints, GRID_HELPER_GRIDS& aSnapLayer );
129
131 void prepareMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit,
132 std::vector<DANGLING_END_ITEM>& aInternalPoints, GRID_HELPER_GRIDS& aSnapLayer );
133
135 void startMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit,
136 std::vector<DANGLING_END_ITEM>& aInternalPoints, GRID_HELPER_GRIDS& aSnapLayer );
137
139 void setupItemsForDrag( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit );
140
142 void setupItemsForMove( SCH_SELECTION& aSelection,
143 std::vector<DANGLING_END_ITEM>& aInternalPoints );
144
146 SCH_SHEET* findTargetSheet( const SCH_SELECTION& aSelection, const VECTOR2I& aCursorPos,
147 bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown );
148
150 bool dropWouldRecurse( const SCH_SELECTION& aSelection, const SCH_SHEET* aTargetSheet );
151
153 void performItemMove( SCH_SELECTION& aSelection, const VECTOR2I& aDelta,
154 SCH_COMMIT* aCommit, int& aXBendCount, int& aYBendCount,
155 const EE_GRID_HELPER& aGrid );
156
158 void spreadMovingSheetPinGroups( const SCH_SELECTION& aSelection );
159
161 bool handleMoveToolActions( const TOOL_EVENT* aEvent, SCH_COMMIT* aCommit,
162 const SCH_SELECTION& aSelection );
163
165 void updateStoredPositions( const SCH_SELECTION& aSelection );
166
169 void recordRedundantJunctions( SCH_SELECTION& aSelection );
170
172 void migrateHiddenJunctions( SCH_COMMIT* aCommit );
173
175 void finalizeMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit, bool aUnselect,
176 const std::vector<DANGLING_END_ITEM>& aInternalPoints );
177
178private:
181
185
187 std::vector<KIID> m_dragAdditions;
188
190 std::map<SCH_LINE*, EDA_ITEMS> m_lineConnectionCache;
191
193 std::unordered_set<SCH_LINE*> m_newDragLines;
194
196 std::unordered_set<SCH_LINE*> m_changedDragLines;
197
205
206 std::vector<HIDDEN_JUNCTION> m_hiddenJunctions;
207
209
213
216
217 // A map of labels to scaling factors. Used to scale the movement vector for labels that
218 // are attached to wires which have only one end moving.
219 std::map<SCH_LABEL_BASE*, SPECIAL_CASE_LABEL_INFO> m_specialCaseLabels;
220
221 // A map of sheet pins to the line-endings (true == start) they're connected to. Sheet
222 // pins are constrained in their movement so their attached lines must be too.
223 std::map<SCH_SHEET_PIN*, std::pair<SCH_LINE*, bool>> m_specialCaseSheetPins;
224
225 // Each dragged sheet pin's distance along its sheet border at drag start.
226 std::map<SCH_SHEET_PIN*, long long> m_sheetPinDragArc;
227};
228
229#endif //KICAD_SCH_MOVE_TOOL_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Definition kiid.h:46
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
void moveSelectionToSheet(SCH_SELECTION &aSelection, SCH_SHEET *aTarget, SCH_COMMIT *aCommit)
void refreshSelectionTraits(const SCH_SELECTION &aSelection, bool &aHasSheetPins, bool &aHasGraphicItems, bool &aHasNonGraphicItems, bool &aIsGraphicsOnly)
Refresh selection traits (sheet pins, graphic items, etc.)
bool Init() override
Init() is called once upon a registration of the tool.
VECTOR2I m_cursor
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).
void trimDanglingLines(SCH_COMMIT *aCommit)
Cleanup dangling lines left after a drag.
void orthoLineDrag(SCH_COMMIT *aCommit, SCH_LINE *line, const VECTOR2I &splitDelta, int &xBendCount, int &yBendCount, const EE_GRID_HELPER &grid)
std::unordered_set< SCH_LINE * > m_newDragLines
Lines added at bend points dynamically during the move.
SCH_SHEET * findTargetSheet(const SCH_SELECTION &aSelection, const VECTOR2I &aCursorPos, bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown)
Find the target sheet for dropping items (if any)
bool handleMoveToolActions(const TOOL_EVENT *aEvent, SCH_COMMIT *aCommit, const SCH_SELECTION &aSelection)
Handle tool action events during the move operation.
OPT_VECTOR2I m_anchorPos
void performItemMove(SCH_SELECTION &aSelection, const VECTOR2I &aDelta, SCH_COMMIT *aCommit, int &aXBendCount, int &aYBendCount, const EE_GRID_HELPER &aGrid)
Perform the actual move of items by delta, handling split moves and orthogonal dragging.
int Main(const TOOL_EVENT &aEvent)
Run an interactive move of the selected items, or the item under the cursor.
SCH_SELECTION & prepareSelection(bool &aUnselect)
Promote pin selections to parent symbols and request final selection.
void prepareMoveOperation(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, std::vector< DANGLING_END_ITEM > &aInternalPoints, GRID_HELPER_GRIDS &aSnapLayer)
Set up flags, connections, and undo state for either a new or restarted move.
void spreadMovingSheetPinGroups(const SCH_SELECTION &aSelection)
Slide a group of dragged sheet pins along the sheet border so they keep their spacing.
void setupItemsForMove(SCH_SELECTION &aSelection, std::vector< DANGLING_END_ITEM > &aInternalPoints)
Setup items for move operation, marking dangling ends.
bool m_inMoveTool
Re-entrancy guard.
std::vector< KIID > m_dragAdditions
Items (such as wires) which were added to the selection for a drag.
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
void setupItemsForDrag(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit)
Setup items for drag operation, collecting connected items.
void restartMoveOperation(const TOOL_EVENT &aEvent, SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, std::vector< DANGLING_END_ITEM > &aInternalPoints, GRID_HELPER_GRIDS &aSnapLayer)
Restore the original geometry and restart with the requested move mode.
std::unordered_set< SCH_LINE * > m_changedDragLines
Lines changed by drag algorithm that weren't selected.
void finalizeMoveOperation(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, bool aUnselect, const std::vector< DANGLING_END_ITEM > &aInternalPoints)
Finalize the move operation, updating junctions and cleaning up.
void setTransitions() override
Set up handlers for various events.
~SCH_MOVE_TOOL() override
void getConnectedItems(SCH_ITEM *aOriginalItem, const VECTOR2I &aPoint, EDA_ITEMS &aList)
Find additional items for a drag operation.
std::map< SCH_LINE *, EDA_ITEMS > m_lineConnectionCache
Cache of the line's original connections before dragging started.
OPT_VECTOR2I m_breakPos
std::map< SCH_SHEET_PIN *, long long > m_sheetPinDragArc
void updateStoredPositions(const SCH_SELECTION &aSelection)
Update stored positions after transformations (rotation, mirroring, etc.) during move.
std::vector< HIDDEN_JUNCTION > m_hiddenJunctions
bool doMoveSelection(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit)
void recordRedundantJunctions(SCH_SELECTION &aSelection)
Hide the junction dots that the pending edit will make redundant, noting the line end each one marks.
bool m_moveInProgress
Flag determining if anything is being dragged right now.
bool dropWouldRecurse(const SCH_SELECTION &aSelection, const SCH_SHEET *aTargetSheet)
True when dropping the selection into aTargetSheet would make a sheet its own descendant.
void getConnectedDragItems(SCH_COMMIT *aCommit, SCH_ITEM *fixed, const VECTOR2I &selected, EDA_ITEMS &aList)
VECTOR2I m_moveOffset
std::map< SCH_LABEL_BASE *, SPECIAL_CASE_LABEL_INFO > m_specialCaseLabels
void migrateHiddenJunctions(SCH_COMMIT *aCommit)
Move those junction dots to wherever the line end they marked has ended up.
int AlignToGrid(const TOOL_EVENT &aEvent)
Align selected elements to the grid.
void clearNewDragLines()
Clears the new drag lines and removes them from the screen.
MOVE_MODE m_mode
void preprocessBreakOrSliceSelection(SCH_COMMIT *aCommit, const TOOL_EVENT &aEvent)
Break or slice the current selection before initiating a move, if required.
void startMoveOperation(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, std::vector< DANGLING_END_ITEM > &aInternalPoints, GRID_HELPER_GRIDS &aSnapLayer)
Start a new move and position the selection at its initial cursor anchor.
std::map< SCH_SHEET_PIN *, std::pair< SCH_LINE *, bool > > m_specialCaseSheetPins
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
SCH_TOOL_BASE(const std::string &aName)
Generic, UI-independent tool event.
Definition tool_event.h:167
void Reset() override
GRID_HELPER_GRIDS
Definition grid_helper.h:55
std::vector< EDA_ITEM * > EDA_ITEMS
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
Junctions that were hidden during the move.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708