KiCad PCB EDA Suite
ee_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 (C) 2019-2022 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_SELECTION_TOOL_H
26#define KICAD_SCH_SELECTION_TOOL_H
27
28#include <tool/selection_tool.h>
29#include <tool/action_menu.h>
30#include <tool/tool_menu.h>
31#include <tools/ee_selection.h>
32#include <ee_collectors.h>
33#include <sch_symbol.h>
34#include <gal/cursors.h>
35
36class SCH_BASE_FRAME;
37class SCH_ITEM;
38class EE_GRID_HELPER;
39
40namespace KIGFX
41{
42 class GAL;
43}
44
45
47{
48public:
54};
55
56
58{
59public:
62
64 bool Init() override;
65
67 void Reset( RESET_REASON aReason ) override;
68
72 int Main( const TOOL_EVENT& aEvent );
73
74 void OnIdle( wxIdleEvent& aEvent );
75
77 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
78
83
91 EE_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
92
109 bool SelectPoint( const VECTOR2I& aWhere,
110 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
111 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
112 bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
113 bool aExclusiveOr = false );
114
121 EDA_ITEM* GetNode( VECTOR2I aPosition );
122
127 int SelectNode( const TOOL_EVENT& aEvent );
128
133 int SelectConnection( const TOOL_EVENT& aEvent );
134
136 int ClearSelection( const TOOL_EVENT& aEvent );
137
139 int SelectAll( const TOOL_EVENT& aEvent );
140
141 void ClearSelection( bool aQuietMode = false );
142
148 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
149 bool checkVisibilityOnly = false ) const;
150
155 void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
156
163 void RebuildSelection();
164
173 bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
174 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
175
178 int SyncSelection( std::optional<SCH_SHEET_PATH> targetSheetPath, SCH_ITEM* focusItem,
179 std::vector<SCH_ITEM*> items );
180
181protected:
182 SELECTION& selection() override { return m_selection; }
183
184private:
186
196 void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
197 bool aSelectedOnly = false );
198
214 bool selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
215 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
216 bool aSubtract = false, bool aExclusiveOr = false );
217
223 bool selectMultiple();
224
228 int disambiguateCursor( const TOOL_EVENT& aEvent );
229
235 void select( EDA_ITEM* aItem ) override;
236
242 void unselect( EDA_ITEM* aItem ) override;
243
251 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
252
260 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
261
266
270 bool selectionContains( const VECTOR2I& aPoint ) const;
271
273 void setTransitions() override;
274
275private:
276
277 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
278 EE_SELECTION m_selection; // Current state of selection
279
280 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
281
282 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
283 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
284 int m_unit; // Fixed unit filter (for symbol editor)
285 int m_convert; // Fixed DeMorgan filter (for symbol editor)
286};
287
288#endif //KICAD_SCH_SELECTION_TOOL_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
static SELECTION_CONDITION SingleSymbol
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION SingleMultiUnitSymbol
static SELECTION_CONDITION SingleNonExcludedMarker
static SELECTION_CONDITION SingleDeMorganSymbol
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
bool selectionContains(const VECTOR2I &aPoint) const
Set up handlers for various events.
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
EE_SELECTION m_selection
void unselect(EDA_ITEM *aItem) override
Take necessary action to mark an item as unselected.
int SelectConnection(const TOOL_EVENT &aEvent)
If a connected item is selected then expand the selection to the entire connection,...
SELECTION & selection() override
Return a reference to the selection.
bool CollectHits(EE_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 setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
bool selectPoint(EE_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).
int SelectAll(const TOOL_EVENT &aEvent)
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
void ZoomFitCrossProbeBBox(const BOX2I &aBBox)
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 Main(const TOOL_EVENT &aEvent)
The main loop.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
int SelectNode(const TOOL_EVENT &aEvent)
Selects the connected item at the current cursor position.
bool Init() override
Init() is called once upon a registration of the tool.
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
OPT_TOOL_EVENT autostartEvent(TOOL_EVENT *aEvent, EE_GRID_HELPER &aGrid, SCH_ITEM *aItem)
int SyncSelection(std::optional< SCH_SHEET_PATH > targetSheetPath, SCH_ITEM *focusItem, std::vector< SCH_ITEM * > items)
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
void OnIdle(wxIdleEvent &aEvent)
Zoom the screen to fit the bounding box for cross probing/selection sync.
SCH_BASE_FRAME * m_frame
void narrowSelection(EE_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 highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void select(EDA_ITEM *aItem) override
Take necessary action to mark an item as selected.
EDA_ITEM * GetNode(VECTOR2I aPosition)
Finds a connected item at a point (usually the cursor position).
EE_SELECTION & GetSelection()
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
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:156
KICURSOR
Definition: cursors.h:34
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:557
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:183