KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_selection_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 SCH_SELECTION_TOOL_H
26#define SCH_SELECTION_TOOL_H
27
29#include <tool/selection_tool.h>
30#include <tool/action_menu.h>
31#include <tool/tool_menu.h>
32#include <tools/sch_selection.h>
33#include <sch_collectors.h>
34#include <sch_symbol.h>
35#include <gal/cursors.h>
36
37class SCH_BASE_FRAME;
38class SCH_GROUP;
39class SCH_ITEM;
40class SCH_TABLE;
41class EE_GRID_HELPER;
42class SCH_TABLECELL;
43
44namespace KIGFX
45{
46class GAL;
47
48namespace PREVIEW
49{
50class SELECTION_AREA;
51}
52}
53
54
56{
57public:
67};
68
69
71{
72public:
75
77 bool Init() override;
78
80 void Reset( RESET_REASON aReason ) override;
81
84
85 int Main( const TOOL_EVENT& aEvent );
87 void OnIdle( wxIdleEvent& aEvent );
88
90 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
91
95 void EnterGroup() override;
96
98
100 * @param aSelectGroup [optional] Select the group after leaving.
101 */
102 void ExitGroup( bool aSelectGroup = false ) override;
103
108
113
114 /**
115 * Return either an existing selection (filtered), or the selection at the current cursor
116 * position if the existing selection is empty.
117 *
118 * @param aScanTypes [optional] List of item types that are acceptable for selection.
119 * @return either the current selection or, if empty, the selection at the cursor.
120 *
121 * @param aPromoteCellSelections [optional] If true, cell selections are promoted to their parent
122 *
123 * @param aPromoteGroups [optional] If true, group selections are promoted the items within the group
124 */
125 SCH_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
126 bool aPromoteCellSelections = false,
127 bool aPromoteGroups = false );
135
137 * selection was canceled (for instance, by clicking outside of
138 * the disambiguation menu).
139 * @param aCheckLocked Indicates if locked items should be excluded.
140 * @param aAdd Indicates if found item(s) should be added to the selection.
141 * @param aSubtract Indicates if found item(s) should be subtracted from the selection.
142 * @param aExclusiveOr Indicates if found item(s) should be toggle in the selection.
143 * @return true if the selection was modified.
144 */
145 bool SelectPoint( const VECTOR2I& aWhere, const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
146 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr, bool aCheckLocked = false,
147 bool aAdd = false, bool aSubtract = false, bool aExclusiveOr = false );
148
149 /**
150 * Finds a connected item at a point (usually the cursor position). Iterative process with a
151 * decreasing slop factor.
152 * @param aPosition Cursor position from which the search should be made.
153 * @return a connected item or nullptr.
154 */
155 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
156
161 int SelectNode( const TOOL_EVENT& aEvent );
162
167 int SelectConnection( const TOOL_EVENT& aEvent );
168
169 int SelectColumns( const TOOL_EVENT& aEvent );
170 int SelectRows( const TOOL_EVENT& aEvent );
171 int SelectTable( const TOOL_EVENT& aEvent );
172
174 int ClearSelection( const TOOL_EVENT& aEvent );
175
177 int SelectAll( const TOOL_EVENT& aEvent );
178
180 int UnselectAll( const TOOL_EVENT& aEvent );
181
183 int SelectNext( const TOOL_EVENT& aEvent );
184
186 int SelectPrevious( const TOOL_EVENT& aEvent );
187
188 void ClearSelection( bool aQuietMode = false );
189
195 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr, bool checkVisibilityOnly = false ) const;
196
201 void GuessSelectionCandidates( SCH_COLLECTOR& collector, const VECTOR2I& aPos );
202
209 void RebuildSelection();
210
219 bool CollectHits( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere,
220 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
221
224 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
225 const std::vector<SCH_ITEM*>& items );
226
228
229protected:
230 SELECTION& selection() override { return m_selection; }
231
232private:
234
244 void narrowSelection( SCH_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
245 bool aSelectedOnly = false,
246 SCH_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
247
263 bool selectPoint( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
264 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false, bool aSubtract = false,
265 bool aExclusiveOr = false );
266
272 bool selectMultiple();
273
274 bool selectLasso();
275
276 int SetSelectRect( const TOOL_EVENT& aEvent );
277 int SetSelectPoly( const TOOL_EVENT& aEvent );
278
279 void SelectMultiple( KIGFX::PREVIEW::SELECTION_AREA& aArea, bool aSubtractive = false,
280 bool aExclusiveOr = false );
281
287 bool selectTableCells( SCH_TABLE* aTable );
288
292 void InitializeSelectionState( SCH_TABLE* aTable );
293
301 void SelectCellsBetween( const VECTOR2D& start, const VECTOR2D& end, SCH_TABLE* aTable );
302
306 int disambiguateCursor( const TOOL_EVENT& aEvent );
307
313 void select( EDA_ITEM* aItem ) override;
314
320 void unselect( EDA_ITEM* aItem ) override;
321
329 void highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
330
338 void unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
339
344
348 bool selectionContains( const VECTOR2I& aPoint ) const;
349
353 int updateSelection( const TOOL_EVENT& aEvent );
354
358 bool itemPassesFilter( EDA_ITEM* aItem, SCH_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
359
364 void filterCollectorForHierarchy( SCH_COLLECTOR& aCollector, bool aMultiselect ) const;
365 void filterCollectedItems( SCH_COLLECTOR& aCollector, bool aMultiSelect );
366
368 void setTransitions() override;
369
370private:
371 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
372 SCH_SELECTION m_selection; // Current state of selection
373
374 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
375
376 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
377 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
378 int m_unit; // Fixed unit filter (for symbol editor)
379 int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
380
381 SCH_GROUP* m_enteredGroup; // If non-null, selections are limited to
382 // members of this group
383 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
384
386
387 SELECTION_MODE m_selectionMode; // Current selection mode
388
389 SCH_TABLECELL* m_previous_first_cell; // First selected cell for shift+click selection range
390};
391
392#endif //SCH_SELECTION_TOOL_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Abstract interface for drawing on a 2D-surface.
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition view_group.h:43
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
static SELECTION_CONDITION SingleMultiFunctionPin
static SELECTION_CONDITION SingleSymbol
static SELECTION_CONDITION MultipleSymbolsOrPower
static SELECTION_CONDITION AllPinsOrSheetPins
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION SingleNonExcludedMarker
static SELECTION_CONDITION SingleMultiUnitSymbol
static SELECTION_CONDITION SingleMultiBodyStyleSymbol
static SELECTION_CONDITION AllPins
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SELECTION & selection() override
Return a reference to the selection.
int SelectPrevious(const TOOL_EVENT &aEvent)
void highlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
void SyncSelection(const std::optional< SCH_SHEET_PATH > &targetSheetPath, SCH_ITEM *focusItem, const std::vector< SCH_ITEM * > &items)
int SelectAll(const TOOL_EVENT &aEvent)
Unselect all visible items in sheet.
void narrowSelection(SCH_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked, bool aSelectedOnly=false, SCH_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
KIGFX::VIEW_GROUP m_enteredGroupOverlay
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
bool itemPassesFilter(EDA_ITEM *aItem, SCH_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
Return true if the given item passes the stateful selection filter.
SCH_BASE_FRAME * m_frame
void EnterGroup() override
Enter the group at the head of the current selection.
void unhighlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
bool selectTableCells(SCH_TABLE *aTable)
Handle a table cell drag selection within a table.
int SetSelectRect(const TOOL_EVENT &aEvent)
int Main(const TOOL_EVENT &aEvent)
The main loop.
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
bool CollectHits(SCH_COLLECTOR &aCollector, const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Collect one or more items at a given point.
void GuessSelectionCandidates(SCH_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
SCH_TABLECELL * m_previous_first_cell
SCH_SELECTION & GetSelection()
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
int SelectNext(const TOOL_EVENT &aEvent)
Select previous net item.
int UnselectAll(const TOOL_EVENT &aEvent)
Select next net item.
bool Init() override
Init() is called once upon a registration of the tool.
bool selectPoint(SCH_COLLECTOR &aCollector, const VECTOR2I &aWhere, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
OPT_TOOL_EVENT autostartEvent(TOOL_EVENT *aEvent, EE_GRID_HELPER &aGrid, SCH_ITEM *aItem)
void filterCollectorForHierarchy(SCH_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
SELECTION_MODE m_selectionMode
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
SCH_GROUP * GetEnteredGroup()
int SelectNode(const TOOL_EVENT &aEvent)
Selects the connected item at the current cursor position.
void InitializeSelectionState(SCH_TABLE *aTable)
Initialize the selection state of table cells.
void ExitGroup(bool aSelectGroup=false) override
Leave the currently-entered group.
int SelectRows(const TOOL_EVENT &aEvent)
void SelectCellsBetween(const VECTOR2D &start, const VECTOR2D &end, SCH_TABLE *aTable)
Select table cells within a rectangular area between two points.
void unselect(EDA_ITEM *aItem) override
Take necessary action to mark an item as unselected.
void select(EDA_ITEM *aItem) override
Take necessary action to mark an item as selected.
void SelectMultiple(KIGFX::PREVIEW::SELECTION_AREA &aArea, bool aSubtractive=false, bool aExclusiveOr=false)
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
int SelectColumns(const TOOL_EVENT &aEvent)
int SetSelectPoly(const TOOL_EVENT &aEvent)
int SelectTable(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
SCH_SELECTION_FILTER_OPTIONS m_filter
int SelectConnection(const TOOL_EVENT &aEvent)
If a connected item is selected then expand the selection to the entire connection,...
void ZoomFitCrossProbeBBox(const BOX2I &aBBox)
void OnIdle(wxIdleEvent &aEvent)
Zoom the screen to fit the bounding box for cross probing/selection sync.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
void filterCollectedItems(SCH_COLLECTOR &aCollector, bool aMultiSelect)
Set up handlers for various events.
bool selectionContains(const VECTOR2I &aPoint) const
Class that groups generic conditions for selected items.
SELECTION_TOOL(const std::string &aName)
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:171
KICURSOR
Definition cursors.h:44
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
SELECTION_MODE
VECTOR2I end
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition tool_event.h:641
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:201
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694