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
29#include <tool/selection_tool.h>
30#include <tool/action_menu.h>
31#include <tool/tool_menu.h>
32#include <tools/ee_selection.h>
33#include <ee_collectors.h>
34#include <sch_symbol.h>
35#include <gal/cursors.h>
36
37class SCH_BASE_FRAME;
38class SCH_ITEM;
39class SCH_TABLE;
40class EE_GRID_HELPER;
41
42namespace KIGFX
43{
44 class GAL;
45}
46
47
49{
50public:
59};
60
61
63{
64public:
67
69 bool Init() override;
70
72 void Reset( RESET_REASON aReason ) override;
73
77 int Main( const TOOL_EVENT& aEvent );
78
79 void OnIdle( wxIdleEvent& aEvent );
80
82 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
83
88
96 EE_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
97 bool aPromoteCellSelections = false );
98
115 bool SelectPoint( const VECTOR2I& aWhere,
116 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
117 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
118 bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
119 bool aExclusiveOr = false );
120
127 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
128
133 int SelectNode( const TOOL_EVENT& aEvent );
134
139 int SelectConnection( const TOOL_EVENT& aEvent );
140
141 int SelectColumns( const TOOL_EVENT& aEvent );
142 int SelectRows( const TOOL_EVENT& aEvent );
143 int SelectTable( const TOOL_EVENT& aEvent );
144
146 int ClearSelection( const TOOL_EVENT& aEvent );
147
149 int SelectAll( const TOOL_EVENT& aEvent );
150
152 int UnselectAll( const TOOL_EVENT& aEvent );
153
154 void ClearSelection( bool aQuietMode = false );
155
161 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
162 bool checkVisibilityOnly = false ) const;
163
168 void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
169
176 void RebuildSelection();
177
186 bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
187 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
188
191 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
192 const std::vector<SCH_ITEM*>& items );
193
195
196protected:
197 SELECTION& selection() override { return m_selection; }
198
199private:
201
211 void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
212 bool aSelectedOnly = false );
213
229 bool selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
230 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
231 bool aSubtract = false, bool aExclusiveOr = false );
232
238 bool selectMultiple();
239
245 bool selectTableCells( SCH_TABLE* aTable );
246
250 int disambiguateCursor( const TOOL_EVENT& aEvent );
251
257 void select( EDA_ITEM* aItem ) override;
258
264 void unselect( EDA_ITEM* aItem ) override;
265
273 void highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
274
282 void unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
283
288
292 bool selectionContains( const VECTOR2I& aPoint ) const;
293
297 bool itemPassesFilter( EDA_ITEM* aItem );
298
300 void setTransitions() override;
301
302private:
303
304 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
305 EE_SELECTION m_selection; // Current state of selection
306
307 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
308
309 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
310 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
311 int m_unit; // Fixed unit filter (for symbol editor)
312 int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
313
315};
316
317#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:88
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
SCH_SELECTION_FILTER_OPTIONS m_filter
EE_SELECTION m_selection
void unselect(EDA_ITEM *aItem) override
Take necessary action to mark an item as unselected.
void unhighlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
int SelectColumns(const TOOL_EVENT &aEvent)
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.
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
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.
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
bool selectTableCells(SCH_TABLE *aTable)
Handle a table cell drag selection within a table.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
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 SelectTable(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
void highlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
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)
bool itemPassesFilter(EDA_ITEM *aItem)
Return true if the given item passes the stateful selection filter.
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 select(EDA_ITEM *aItem) override
Take necessary action to mark an item as selected.
int SelectRows(const TOOL_EVENT &aEvent)
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:174
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:629
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:198