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 bool checkMoveInProgress( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aCurrentModeIsDragLike,
120 bool aWasDragging );
121
123 SCH_SELECTION& prepareSelection( bool& aUnselect );
124
126 void refreshSelectionTraits( const SCH_SELECTION& aSelection, bool& aHasSheetPins,
127 bool& aHasGraphicItems, bool& aHasNonGraphicItems,
128 bool& aIsGraphicsOnly );
129
131 void initializeMoveOperation( const TOOL_EVENT& aEvent, SCH_SELECTION& aSelection, SCH_COMMIT* aCommit,
132 std::vector<DANGLING_END_ITEM>& aInternalPoints, GRID_HELPER_GRIDS& aSnapLayer );
133
135 void setupItemsForDrag( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit );
136
138 void setupItemsForMove( SCH_SELECTION& aSelection,
139 std::vector<DANGLING_END_ITEM>& aInternalPoints );
140
142 SCH_SHEET* findTargetSheet( const SCH_SELECTION& aSelection, const VECTOR2I& aCursorPos,
143 bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown );
144
146 void performItemMove( SCH_SELECTION& aSelection, const VECTOR2I& aDelta,
147 SCH_COMMIT* aCommit, int& aXBendCount, int& aYBendCount,
148 const EE_GRID_HELPER& aGrid );
149
151 bool handleMoveToolActions( const TOOL_EVENT* aEvent, SCH_COMMIT* aCommit,
152 const SCH_SELECTION& aSelection );
153
155 void updateStoredPositions( const SCH_SELECTION& aSelection );
156
158 void finalizeMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit, bool aUnselect,
159 const std::vector<DANGLING_END_ITEM>& aInternalPoints );
160
161private:
164
168
170 std::vector<KIID> m_dragAdditions;
172 std::map<SCH_LINE*, EDA_ITEMS> m_lineConnectionCache;
174 std::unordered_set<SCH_LINE*> m_newDragLines;
176 std::unordered_set<SCH_LINE*> m_changedDragLines;
178 std::vector<SCH_JUNCTION*> m_hiddenJunctions;
179
181
185
188
189 // A map of labels to scaling factors. Used to scale the movement vector for labels that
190 // are attached to wires which have only one end moving.
191 std::map<SCH_LABEL_BASE*, SPECIAL_CASE_LABEL_INFO> m_specialCaseLabels;
192
193 // A map of sheet pins to the line-endings (true == start) they're connected to. Sheet
194 // pins are constrained in their movement so their attached lines must be too.
195 std::map<SCH_SHEET_PIN*, std::pair<SCH_LINE*, bool>> m_specialCaseSheetPins;
196};
197
198#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:96
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
void moveSelectionToSheet(SCH_SELECTION &aSelection, SCH_SHEET *aTarget, SCH_COMMIT *aCommit)
Clears the new drag lines and removes them from the screen.
void refreshSelectionTraits(const SCH_SELECTION &aSelection, bool &aHasSheetPins, bool &aHasGraphicItems, bool &aHasNonGraphicItems, bool &aIsGraphicsOnly)
Initialize the move/drag operation, setting up flags and connections.
bool Init() override
Init() is called once upon a registration of the tool.
VECTOR2I m_cursor
void trimDanglingLines(SCH_COMMIT *aCommit)
Break or slice the current selection before initiating a move, if required.
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 changed by drag algorithm that weren't selected.
SCH_SHEET * findTargetSheet(const SCH_SELECTION &aSelection, const VECTOR2I &aCursorPos, bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown)
Perform the actual move of items by delta, handling split moves and orthogonal dragging.
bool handleMoveToolActions(const TOOL_EVENT *aEvent, SCH_COMMIT *aCommit, const SCH_SELECTION &aSelection)
Update stored positions after transformations (rotation, mirroring, etc.) during move.
bool checkMoveInProgress(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit, bool aCurrentModeIsDragLike, bool aWasDragging)
< Check if a move is already in progress and handle state transitions
void initializeMoveOperation(const TOOL_EVENT &aEvent, SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, std::vector< DANGLING_END_ITEM > &aInternalPoints, GRID_HELPER_GRIDS &aSnapLayer)
Setup items for drag operation, collecting connected items.
OPT_VECTOR2I m_anchorPos
void performItemMove(SCH_SELECTION &aSelection, const VECTOR2I &aDelta, SCH_COMMIT *aCommit, int &aXBendCount, int &aYBendCount, const EE_GRID_HELPER &aGrid)
Handle tool action events during the move operation.
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)
Refresh selection traits (sheet pins, graphic items, etc.)
std::vector< SCH_JUNCTION * > m_hiddenJunctions
void setupItemsForMove(SCH_SELECTION &aSelection, std::vector< DANGLING_END_ITEM > &aInternalPoints)
Find the target sheet for dropping items (if any)
bool m_inMoveTool
< Re-entrancy guard
std::vector< KIID > m_dragAdditions
Cache of the line's original connections before dragging started.
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Find additional items for a drag operation.
void setupItemsForDrag(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit)
Setup items for move operation, marking dangling ends.
std::unordered_set< SCH_LINE * > m_changedDragLines
Junctions that were hidden during the move.
void finalizeMoveOperation(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, bool aUnselect, const std::vector< DANGLING_END_ITEM > &aInternalPoints)
void setTransitions() override
Cleanup dangling lines left after a drag.
~SCH_MOVE_TOOL() override
void getConnectedItems(SCH_ITEM *aOriginalItem, const VECTOR2I &aPoint, EDA_ITEMS &aList)
std::map< SCH_LINE *, EDA_ITEMS > m_lineConnectionCache
Lines added at bend points dynamically during the move.
OPT_VECTOR2I m_breakPos
void updateStoredPositions(const SCH_SELECTION &aSelection)
Finalize the move operation, updating junctions and cleaning up.
bool doMoveSelection(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit)
void getConnectedDragItems(SCH_COMMIT *aCommit, SCH_ITEM *fixed, const VECTOR2I &selected, EDA_ITEMS &aList)
VECTOR2I m_moveOffset
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).
std::map< SCH_LABEL_BASE *, SPECIAL_CASE_LABEL_INFO > m_specialCaseLabels
int AlignToGrid(const TOOL_EVENT &aEvent)
Align selected elements to the grid.
void clearNewDragLines()
Set up handlers for various events.
MOVE_MODE m_mode
Items (such as wires) which were added to the selection for a drag.
void preprocessBreakOrSliceSelection(SCH_COMMIT *aCommit, const TOOL_EVENT &aEvent)
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:44
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:40
std::vector< EDA_ITEM * > EDA_ITEMS
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683