KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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:
57};
58
59
61{
62public:
65
67 bool Init() override;
68
70 void Reset( RESET_REASON aReason ) override;
71
75 int Main( const TOOL_EVENT& aEvent );
76
77 void OnIdle( wxIdleEvent& aEvent );
78
80 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
81
86
94 EE_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
95
112 bool SelectPoint( const VECTOR2I& aWhere,
113 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
114 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
115 bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
116 bool aExclusiveOr = false );
117
124 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
125
130 int SelectNode( const TOOL_EVENT& aEvent );
131
136 int SelectConnection( const TOOL_EVENT& aEvent );
137
139 int ClearSelection( const TOOL_EVENT& aEvent );
140
142 int SelectAll( const TOOL_EVENT& aEvent );
143
145 int UnselectAll( const TOOL_EVENT& aEvent );
146
147 void ClearSelection( bool aQuietMode = false );
148
154 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
155 bool checkVisibilityOnly = false ) const;
156
161 void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
162
169 void RebuildSelection();
170
179 bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
180 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
181
184 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
185 const std::vector<SCH_ITEM*>& items );
186
187protected:
188 SELECTION& selection() override { return m_selection; }
189
190private:
192
202 void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
203 bool aSelectedOnly = false );
204
220 bool selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
221 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
222 bool aSubtract = false, bool aExclusiveOr = false );
223
229 bool selectMultiple();
230
234 int disambiguateCursor( const TOOL_EVENT& aEvent );
235
241 void select( EDA_ITEM* aItem ) override;
242
248 void unselect( EDA_ITEM* aItem ) override;
249
257 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
258
266 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
267
272
276 bool selectionContains( const VECTOR2I& aPoint ) const;
277
279 void setTransitions() override;
280
281private:
282
283 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
284 EE_SELECTION m_selection; // Current state of selection
285
286 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
287
288 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
289 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
290 int m_unit; // Fixed unit filter (for symbol editor)
291 int m_convert; // Fixed DeMorgan filter (for symbol editor)
292};
293
294#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 SingleMultiFunctionPin
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION SingleMultiUnitSymbol
static SELECTION_CONDITION SingleNonExcludedMarker
static SELECTION_CONDITION SingleDeMorganSymbol
static SELECTION_CONDITION AllPins
static SELECTION_CONDITION MultipleSymbolsOrPower
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.
void SyncSelection(const std::optional< SCH_SHEET_PATH > &targetSheetPath, SCH_ITEM *focusItem, const std::vector< SCH_ITEM * > &items)
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)
Unselect all visible items in sheet.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
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 UnselectAll(const TOOL_EVENT &aEvent)
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)
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 select(EDA_ITEM *aItem) override
Take necessary action to mark an item as selected.
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:151
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:167
KICURSOR
Definition: cursors.h:34
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
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:628
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:183