KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 (C) 2013-2020 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 * @author Tomasz Wlostowski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef __EDIT_TOOL_H
25#define __EDIT_TOOL_H
26
27#include <math/vector2d.h>
28#include <tools/pcb_tool_base.h>
30#include <status_popup.h>
31#include <unordered_set>
32#include <vector>
33
34
35class BOARD_COMMIT;
36class BOARD_ITEM;
38class PCB_SHAPE;
40
41namespace KIGFX::PREVIEW
42{
43 class RULER_ITEM;
44}
45
46
54{
55public:
56 EDIT_TOOL();
57
59 void Reset( RESET_REASON aReason ) override;
60
62 bool Init() override;
63
65 int GetAndPlace( const TOOL_EVENT& aEvent );
66
70 int Move( const TOOL_EVENT& aEvent );
71
76 int Drag( const TOOL_EVENT& aEvent );
77
81 int Properties( const TOOL_EVENT& aEvent );
82
86 int Rotate( const TOOL_EVENT& aEvent );
87
91 int Flip( const TOOL_EVENT& aEvent );
92
96 int Mirror( const TOOL_EVENT& aEvent );
97
98 static const std::vector<KICAD_T> MirrorableItems;
99
103 int JustifyText( const TOOL_EVENT& aEvent );
104
108 int Swap( const TOOL_EVENT& aEvent );
109
114 int SwapPadNets( const TOOL_EVENT& aEvent );
115 int SwapGateNets( const TOOL_EVENT& aEvent );
116
117
121 int PackAndMoveFootprints( const TOOL_EVENT& aEvent );
122
123 int ToggleFootprintAttribute( const TOOL_EVENT& aEvent );
124
125 int ChangeTrackWidth( const TOOL_EVENT& aEvent );
126 int ChangeTrackLayer( const TOOL_EVENT& aEvent );
127
131 int FilletTracks( const TOOL_EVENT& aEvent );
132
137 int ModifyLines( const TOOL_EVENT& aEvent );
138
142 int HealShapes( const TOOL_EVENT& aEvent );
143
147 int SimplifyPolygons( const TOOL_EVENT& aEvent );
148
152 int OutsetItems( const TOOL_EVENT& aEvent );
153
158 int BooleanPolygons( const TOOL_EVENT& aEvent );
159
163 int Remove( const TOOL_EVENT& aEvent );
164
165 void DeleteItems( const PCB_SELECTION& aItem, bool aIsCut );
166
170 int Duplicate( const TOOL_EVENT& aItem );
171
175 static bool CanDuplicateSelection( const SELECTION& aSelection );
176
180 int MoveExact( const TOOL_EVENT& aEvent );
181
185 int Increment( const TOOL_EVENT& aEvent );
186
190 static void FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector,
191 PCB_SELECTION_TOOL* sTool );
192
196 static void PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector,
197 PCB_SELECTION_TOOL* sTool );
198
199private:
201 void setTransitions() override;
202
206 int copyToClipboard( const TOOL_EVENT& aEvent );
207
211 int copyToClipboardAsText( const TOOL_EVENT& aEvent );
212
213 int EditVertices( const TOOL_EVENT& aEvent );
214
218 int cutToClipboard( const TOOL_EVENT& aEvent );
219
222 bool updateModificationPoint( PCB_SELECTION& aSelection );
223
224 bool invokeInlineRouter( int aDragMode );
225 bool isRouterActive() const;
226
227 VECTOR2I getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSourceBBox,
228 const VECTOR2D& aBBoxOffset );
229
230 bool pickReferencePoint( const wxString& aTooltip, const wxString& aSuccessMessage,
231 const wxString& aCanceledMessage, VECTOR2I& aReferencePoint );
232
235 bool doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit, bool aAutoStart,
236 std::vector<PCB_SHAPE*>* aConstraintShapes = nullptr );
237
239 void rebuildConnectivity();
240
242 void reSolveConstraintsAfterEdit( const PCB_SELECTION& aSelection );
243
244public:
247 static void collectConstraintShapes( const SELECTION& aSelection, std::vector<PCB_SHAPE*>& aShapes );
248
249private:
251 bool m_dragging; // Indicates objects are currently being dragged
252 bool m_inMoveWithReference; // True while doMoveSelection runs a Move with Reference
253 VECTOR2I m_cursor; // Last cursor position (so getModificationPoint()
254 // can avoid changes of edit reference point).
255 std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
256
257 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
258};
259
260#endif
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
static void collectConstraintShapes(const SELECTION &aSelection, std::vector< PCB_SHAPE * > &aShapes)
Collect constrainable PCB_SHAPEs in aSelection recursing groups and footprints so contained shapes se...
bool isRouterActive() const
int Duplicate(const TOOL_EVENT &aItem)
Duplicate the current selection and starts a move action.
int Drag(const TOOL_EVENT &aEvent)
Invoke the PNS router to drag tracks or do an offline resizing of an arc track if a single arc track ...
int SwapGateNets(const TOOL_EVENT &aEvent)
int Swap(const TOOL_EVENT &aEvent)
Swap currently selected items' positions.
bool m_inMoveWithReference
Definition edit_tool.h:252
int OutsetItems(const TOOL_EVENT &aEvent)
Create outset items from selection.
int PackAndMoveFootprints(const TOOL_EVENT &aEvent)
Try to fit selected footprints inside a minimal area and start movement.
int Mirror(const TOOL_EVENT &aEvent)
Mirror the current selection.
int Increment(const TOOL_EVENT &aEvent)
Increment some aspect of the selected items.q.
bool doMoveSelection(const TOOL_EVENT &aEvent, BOARD_COMMIT *aCommit, bool aAutoStart, std::vector< PCB_SHAPE * > *aConstraintShapes=nullptr)
Runs interactive move drag when aConstraintShapes is non null previews constraint solve live each tic...
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
bool Init() override
Init() is called once upon a registration of the tool.
int EditVertices(const TOOL_EVENT &aEvent)
int ToggleFootprintAttribute(const TOOL_EVENT &aEvent)
int ModifyLines(const TOOL_EVENT &aEvent)
"Modify" graphical lines.
bool m_dragging
Definition edit_tool.h:251
int MoveExact(const TOOL_EVENT &aEvent)
Invoke a dialog box to allow moving of the item by an exact amount.
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
static const unsigned int COORDS_PADDING
Definition edit_tool.h:257
int JustifyText(const TOOL_EVENT &aEvent)
Set the justification on any text items (or fields) in the current selection.
bool updateModificationPoint(PCB_SELECTION &aSelection)
Return the right modification point (e.g.
static bool CanDuplicateSelection(const SELECTION &aSelection)
int ChangeTrackLayer(const TOOL_EVENT &aEvent)
VECTOR2I getSafeMovement(const VECTOR2I &aMovement, const BOX2I &aSourceBBox, const VECTOR2D &aBBoxOffset)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition edit_tool.h:255
int copyToClipboard(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard by formatting it as a fake pcb.
int SwapPadNets(const TOOL_EVENT &aEvent)
Swap nets between selected pads and propagate to connected copper items (tracks, arcs,...
int Remove(const TOOL_EVENT &aEvent)
Delete currently selected items.
int cutToClipboard(const TOOL_EVENT &aEvent)
Cut the current selection to the clipboard by formatting it as a fake pcb.
static const std::vector< KICAD_T > MirrorableItems
Definition edit_tool.h:2679
void DeleteItems(const PCB_SELECTION &aItem, bool aIsCut)
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type PCB_PAD_T.
VECTOR2I m_cursor
Definition edit_tool.h:253
bool invokeInlineRouter(int aDragMode)
void rebuildConnectivity()
Rebuilds the ratsnest for operations that require it outside the commit rebuild.
void setTransitions() override
Set up handlers for various events.
int HealShapes(const TOOL_EVENT &aEvent)
Make ends of selected shapes meet by extending or cutting them, or adding extra geometry.
void reSolveConstraintsAfterEdit(const PCB_SELECTION &aSelection)
Re-solve the geometric constraints of any shapes in aSelection after a transform.
int ChangeTrackWidth(const TOOL_EVENT &aEvent)
int BooleanPolygons(const TOOL_EVENT &aEvent)
Modify selected polygons into a single polygon using boolean operations such as merge (union) or subt...
int copyToClipboardAsText(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard as text.
int GetAndPlace(const TOOL_EVENT &aEvent)
Find an item and start moving.
int FilletTracks(const TOOL_EVENT &aEvent)
Fillet (i.e.
PCB_SELECTION_TOOL * m_selectionTool
Definition edit_tool.h:250
int SimplifyPolygons(const TOOL_EVENT &aEvent)
Simplify the outlines of selected polygon objects.
int Properties(const TOOL_EVENT &aEvent)
Display properties window for the selected object.
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type PCB_FOOTPRINT_T.
int Rotate(const TOOL_EVENT &aEvent)
Rotate currently selected items.
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
A drawn ruler item for showing the distance between two points.
Definition ruler_item.h:42
The selection tool: currently supports:
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Extension of STATUS_POPUP for displaying a single line text.
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
void Flip(T &aValue)
#define EDIT_TOOL(tool)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707