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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SCH_SELECTION_TOOL_H
22#define SCH_SELECTION_TOOL_H
23
25#include <tool/selection_tool.h>
26#include <tool/action_menu.h>
27#include <tool/tool_menu.h>
28#include <tools/sch_selection.h>
29#include <sch_collectors.h>
30#include <sch_symbol.h>
31#include <gal/cursors.h>
32
33class SCH_BASE_FRAME;
34class SCH_GROUP;
35class SCH_ITEM;
36class SCH_TABLE;
37class EE_GRID_HELPER;
38class SCH_TABLECELL;
39
40namespace KIGFX
41{
42class GAL;
43
44namespace PREVIEW
45{
46class SELECTION_AREA;
47}
48}
49
50
66
67
69{
70public:
73
75 bool Init() override;
76
78 void Reset( RESET_REASON aReason ) override;
79
82
83 int Main( const TOOL_EVENT& aEvent );
85 void OnIdle( wxIdleEvent& aEvent );
86
88 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
89
90 /**
91 * Enter the group at the head of the current selection.
92 */
93 void EnterGroup() override;
94
100 void ExitGroup( bool aSelectGroup = false ) override;
101
102
116
119 * @param aPromoteCellSelections [optional] If true, cell selections are promoted to their parent
120 *
121 * @param aPromoteGroups [optional] If true, group selections are promoted the items within the group
122 */
123 SCH_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
124 bool aPromoteCellSelections = false,
125 bool aPromoteGroups = false );
126
130
132 * @param aItem [out, optional] The newly selected item if only one was selected, otherwise
133 * unchanged.
134 * @param aSelectionCancelledFlag [out] Allows the function to inform its caller that a
135 * selection was canceled (for instance, by clicking outside of
136 * the disambiguation menu).
137 * @param aCheckLocked Indicates if locked items should be excluded.
138 * @param aAdd Indicates if found item(s) should be added to the selection.
139 * @param aSubtract Indicates if found item(s) should be subtracted from the selection.
140 * @param aExclusiveOr Indicates if found item(s) should be toggle in the selection.
141 * @return true if the selection was modified.
142 */
143 bool SelectPoint( const VECTOR2I& aWhere, const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
144 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr, bool aCheckLocked = false,
145 bool aAdd = false, bool aSubtract = false, bool aExclusiveOr = false );
146
147 /**
148 * Finds a connected item at a point (usually the cursor position). Iterative process with a
149 * decreasing slop factor.
150 * @param aPosition Cursor position from which the search should be made.
151 * @return a connected item or nullptr.
152 */
153 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
154
157
159 int SelectNode( const TOOL_EVENT& aEvent );
160
165 int SelectConnection( const TOOL_EVENT& aEvent );
166
167 int SelectColumns( const TOOL_EVENT& aEvent );
168 int SelectRows( const TOOL_EVENT& aEvent );
169 int SelectTable( const TOOL_EVENT& aEvent );
170
172 int ClearSelection( const TOOL_EVENT& aEvent );
173
175 int SelectAll( const TOOL_EVENT& aEvent );
176
178 int UnselectAll( const TOOL_EVENT& aEvent );
179
181 int SelectNext( const TOOL_EVENT& aEvent );
182
184 int SelectPrevious( const TOOL_EVENT& aEvent );
185
186 void ClearSelection( bool aQuietMode = false );
187
193 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr, bool checkVisibilityOnly = false ) const;
194
199 void GuessSelectionCandidates( SCH_COLLECTOR& collector, const VECTOR2I& aPos );
200
207 void RebuildSelection();
208
217 bool CollectHits( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere,
218 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
219
222 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
223 const std::vector<SCH_ITEM*>& items );
224
226
232
233protected:
234 SELECTION& selection() override { return m_selection; }
235
236private:
238
245
246 std::set<SCH_ITEM*> expandConnectionWithGraph( const SCH_SELECTION& aItems,
247 STOP_CONDITION aStopCondition );
248 std::set<SCH_ITEM*> expandConnectionGraphically( const SCH_SELECTION& aItems );
249
259 void narrowSelection( SCH_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
260 bool aSelectedOnly = false,
261 SCH_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
262
278 bool selectPoint( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
279 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false, bool aSubtract = false,
280 bool aExclusiveOr = false );
281
287 bool selectMultiple();
288
289 bool selectLasso();
290
291 int SetSelectRect( const TOOL_EVENT& aEvent );
292 int SetSelectPoly( const TOOL_EVENT& aEvent );
293
294 void SelectMultiple( KIGFX::PREVIEW::SELECTION_AREA& aArea, bool aSubtractive = false,
295 bool aExclusiveOr = false );
296
302 bool selectTableCells( SCH_TABLE* aTable );
303
307 void InitializeSelectionState( SCH_TABLE* aTable );
308
316 void SelectCellsBetween( const VECTOR2D& start, const VECTOR2D& end, SCH_TABLE* aTable );
317
321 int disambiguateCursor( const TOOL_EVENT& aEvent );
322
328 void select( EDA_ITEM* aItem ) override;
329
335 void unselect( EDA_ITEM* aItem ) override;
336
344 void highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
345
353 void unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
354
359
363 bool selectionContains( const VECTOR2I& aPoint ) const;
364
368 int updateSelection( const TOOL_EVENT& aEvent );
369
373 bool itemPassesFilter( EDA_ITEM* aItem, SCH_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
374
379 void filterCollectorForHierarchy( SCH_COLLECTOR& aCollector, bool aMultiselect ) const;
380 void filterCollectedItems( SCH_COLLECTOR& aCollector, bool aMultiSelect );
381
383 void setTransitions() override;
384
385private:
386 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
387 SCH_SELECTION m_selection; // Current state of selection
388
389 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
390
391 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
392 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
393 int m_unit; // Fixed unit filter (for symbol editor)
394 int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
395
396 SCH_GROUP* m_enteredGroup; // If non-null, selections are limited to
397 // members of this group
398 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
399
401
402 SELECTION_MODE m_selectionMode; // Current selection mode
403
404 SCH_TABLECELL* m_previous_first_cell; // First selected cell for shift+click selection range
405};
406
407#endif //SCH_SELECTION_TOOL_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
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:39
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 HasLockedItems
static SELECTION_CONDITION AllPinsOrSheetPins
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION HasUnlockedItems
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:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
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...
void FilterSelectionForLockedItems()
Remove locked items from the current selection.
std::set< SCH_ITEM * > expandConnectionGraphically(const SCH_SELECTION &aItems)
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()
std::set< SCH_ITEM * > expandConnectionWithGraph(const SCH_SELECTION &aItems, STOP_CONDITION aStopCondition)
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.
@ STOP_AT_PIN
Walk through junctions and labels but stop at pins.
@ STOP_NEVER
Walk the entire connected sub-net.
@ STOP_AT_JUNCTION
Stop at the first junction, label, or pin reached.
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:74
Generic, UI-independent tool event.
Definition tool_event.h:167
KICURSOR
Definition cursors.h:40
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
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:637
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:196
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682