KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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}
48
49
51{
52public:
62};
63
64
66{
67public:
70
72 bool Init() override;
73
75 void Reset( RESET_REASON aReason ) override;
76
80 int Main( const TOOL_EVENT& aEvent );
81
82 void OnIdle( wxIdleEvent& aEvent );
83
85 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
86
90 void EnterGroup() override;
91
97 void ExitGroup( bool aSelectGroup = false ) override;
98
103
108
120 SCH_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
121 bool aPromoteCellSelections = false,
122 bool aPromoteGroups = false );
123
140 bool SelectPoint( const VECTOR2I& aWhere, const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
141 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr, bool aCheckLocked = false,
142 bool aAdd = false, bool aSubtract = false, bool aExclusiveOr = false );
143
150 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
151
156 int SelectNode( const TOOL_EVENT& aEvent );
157
162 int SelectConnection( const TOOL_EVENT& aEvent );
163
164 int SelectColumns( const TOOL_EVENT& aEvent );
165 int SelectRows( const TOOL_EVENT& aEvent );
166 int SelectTable( const TOOL_EVENT& aEvent );
167
169 int ClearSelection( const TOOL_EVENT& aEvent );
170
172 int SelectAll( const TOOL_EVENT& aEvent );
173
175 int UnselectAll( const TOOL_EVENT& aEvent );
176
178 int SelectNext( const TOOL_EVENT& aEvent );
179
181 int SelectPrevious( const TOOL_EVENT& aEvent );
182
183 void ClearSelection( bool aQuietMode = false );
184
190 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr, bool checkVisibilityOnly = false ) const;
191
196 void GuessSelectionCandidates( SCH_COLLECTOR& collector, const VECTOR2I& aPos );
197
204 void RebuildSelection();
205
214 bool CollectHits( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere,
215 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
216
219 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
220 const std::vector<SCH_ITEM*>& items );
221
223
224protected:
225 SELECTION& selection() override { return m_selection; }
226
227private:
229
239 void narrowSelection( SCH_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
240 bool aSelectedOnly = false );
241
257 bool selectPoint( SCH_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
258 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false, bool aSubtract = false,
259 bool aExclusiveOr = false );
260
266 bool selectMultiple();
267
273 bool selectTableCells( SCH_TABLE* aTable );
274
278 void InitializeSelectionState( SCH_TABLE* aTable );
279
287 void SelectCellsBetween( const VECTOR2D& start, const VECTOR2D& end, SCH_TABLE* aTable );
288
292 int disambiguateCursor( const TOOL_EVENT& aEvent );
293
299 void select( EDA_ITEM* aItem ) override;
300
306 void unselect( EDA_ITEM* aItem ) override;
307
315 void highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
316
324 void unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
325
330
334 bool selectionContains( const VECTOR2I& aPoint ) const;
335
339 int updateSelection( const TOOL_EVENT& aEvent );
340
344 bool itemPassesFilter( EDA_ITEM* aItem );
345
350 void filterCollectorForHierarchy( SCH_COLLECTOR& aCollector, bool aMultiselect ) const;
351 void filterCollectedItems( SCH_COLLECTOR& aCollector, bool aMultiSelect );
352
354 void setTransitions() override;
355
356private:
357 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
358 SCH_SELECTION m_selection; // Current state of selection
359
360 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
361
362 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
363 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
364 int m_unit; // Fixed unit filter (for symbol editor)
365 int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
366
367 SCH_GROUP* m_enteredGroup; // If non-null, selections are limited to
368 // members of this group
369 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
370
372
373 SCH_TABLECELL* m_previous_first_cell; // First selected cell for shift+click selection range
374};
375
376#endif //SCH_SELECTION_TOOL_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:96
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition: view_group.h:48
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 SingleDeMorganSymbol
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION SingleNonExcludedMarker
static SELECTION_CONDITION SingleMultiUnitSymbol
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)
SCH_SELECTION m_selection
int SelectAll(const TOOL_EVENT &aEvent)
Unselect all visible items in sheet.
KIGFX::VIEW_GROUP m_enteredGroupOverlay
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
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 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 narrowSelection(SCH_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked, bool aSelectedOnly=false)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
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.
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.
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
int SelectColumns(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
bool itemPassesFilter(EDA_ITEM *aItem)
Return true if the given item passes the stateful selection filter.
Class that groups generic conditions for selected items.
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
KICURSOR
Definition: cursors.h:34
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:32
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
VECTOR2I end
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:633
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:199