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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef KICAD_SCH_MOVE_TOOL_H
26#define KICAD_SCH_MOVE_TOOL_H
27
28#include <tools/sch_tool_base.h>
29#include <sch_base_frame.h>
30#include <unordered_map>
31#include <unordered_set>
32
33
34class SCH_EDIT_FRAME;
36class SCH_LINE;
37class SCH_LABEL_BASE;
38class SCH_SHEET_PIN;
39class SCH_JUNCTION;
40class SCH_SELECTION;
41class SCH_SHEET;
42class SCH_COMMIT;
43class SCH_ITEM;
44class EE_GRID_HELPER;
45
46enum GRID_HELPER_GRIDS : int;
47
48
54
55
56class SCH_MOVE_TOOL : public SCH_TOOL_BASE<SCH_EDIT_FRAME>
57{
58public:
66
68 ~SCH_MOVE_TOOL() override { }
69
71 bool Init() override;
72
74 void Reset( RESET_REASON aReason ) override;
75
79 int Main( const TOOL_EVENT& aEvent );
80
87 int AlignToGrid( const TOOL_EVENT& aEvent );
88
89private:
90 bool doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit );
91
92 void moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta );
93
97 void getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint, EDA_ITEMS& aList );
98 void getConnectedDragItems( SCH_COMMIT* aCommit, SCH_ITEM* fixed, const VECTOR2I& selected,
99 EDA_ITEMS& aList );
100
101 void orthoLineDrag( SCH_COMMIT* aCommit, SCH_LINE* line, const VECTOR2I& splitDelta,
102 int& xBendCount, int& yBendCount, const EE_GRID_HELPER& grid );
103
104 void moveSelectionToSheet( SCH_SELECTION& aSelection, SCH_SHEET* aTarget, SCH_COMMIT* aCommit );
105
107 void clearNewDragLines();
108
110 void setTransitions() override;
111
113 void trimDanglingLines( SCH_COMMIT* aCommit );
114
116 void preprocessBreakOrSliceSelection( SCH_COMMIT* aCommit, const TOOL_EVENT& aEvent );
117
118 // Helper methods for doMoveSelection refactoring
120 bool checkMoveInProgress( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aCurrentModeIsDragLike,
121 bool aWasDragging );
122
124 SCH_SELECTION& prepareSelection( bool& aUnselect );
125
127 void refreshSelectionTraits( const SCH_SELECTION& aSelection, bool& aHasSheetPins,
128 bool& aHasGraphicItems, bool& aHasNonGraphicItems,
129 bool& aIsGraphicsOnly );
130
132 void initializeMoveOperation( const TOOL_EVENT& aEvent, SCH_SELECTION& aSelection, SCH_COMMIT* aCommit,
133 std::vector<DANGLING_END_ITEM>& aInternalPoints, GRID_HELPER_GRIDS& aSnapLayer );
134
136 void setupItemsForDrag( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit );
137
139 void setupItemsForMove( SCH_SELECTION& aSelection,
140 std::vector<DANGLING_END_ITEM>& aInternalPoints );
141
143 SCH_SHEET* findTargetSheet( const SCH_SELECTION& aSelection, const VECTOR2I& aCursorPos,
144 bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown );
145
147 void performItemMove( SCH_SELECTION& aSelection, const VECTOR2I& aDelta,
148 SCH_COMMIT* aCommit, int& aXBendCount, int& aYBendCount,
149 const EE_GRID_HELPER& aGrid );
150
152 bool handleMoveToolActions( const TOOL_EVENT* aEvent, SCH_COMMIT* aCommit,
153 const SCH_SELECTION& aSelection );
154
156 void updateStoredPositions( const SCH_SELECTION& aSelection );
157
159 void finalizeMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit, bool aUnselect,
160 const std::vector<DANGLING_END_ITEM>& aInternalPoints );
161
162private:
165
169
171 std::vector<KIID> m_dragAdditions;
173 std::map<SCH_LINE*, EDA_ITEMS> m_lineConnectionCache;
175 std::unordered_set<SCH_LINE*> m_newDragLines;
177 std::unordered_set<SCH_LINE*> m_changedDragLines;
179 std::vector<SCH_JUNCTION*> m_hiddenJunctions;
180
182
186
189
190 // A map of labels to scaling factors. Used to scale the movement vector for labels that
191 // are attached to wires which have only one end moving.
192 std::map<SCH_LABEL_BASE*, SPECIAL_CASE_LABEL_INFO> m_specialCaseLabels;
193
194 // A map of sheet pins to the line-endings (true == start) they're connected to. Sheet
195 // pins are constrained in their movement so their attached lines must be too.
196 std::map<SCH_SHEET_PIN*, std::pair<SCH_LINE*, bool>> m_specialCaseSheetPins;
197};
198
199#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
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
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:47
SCH_TOOL_BASE(const std::string &aName)
Generic, UI-independent tool event.
Definition tool_event.h:171
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition eda_item.h:566
void Reset() override
GRID_HELPER_GRIDS
Definition grid_helper.h:44
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695