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:
60};
61
62
64{
65public:
68
70 bool Init() override;
71
73 void Reset( RESET_REASON aReason ) override;
74
78 int Main( const TOOL_EVENT& aEvent );
79
80 void OnIdle( wxIdleEvent& aEvent );
81
83 void ZoomFitCrossProbeBBox( const BOX2I& aBBox );
84
89
97 EE_SELECTION& RequestSelection( const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
98 bool aPromoteCellSelections = false );
99
116 bool SelectPoint( const VECTOR2I& aWhere,
117 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T },
118 EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
119 bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
120 bool aExclusiveOr = false );
121
128 EDA_ITEM* GetNode( const VECTOR2I& aPosition );
129
134 int SelectNode( const TOOL_EVENT& aEvent );
135
140 int SelectConnection( const TOOL_EVENT& aEvent );
141
142 int SelectColumns( const TOOL_EVENT& aEvent );
143 int SelectRows( const TOOL_EVENT& aEvent );
144 int SelectTable( const TOOL_EVENT& aEvent );
145
147 int ClearSelection( const TOOL_EVENT& aEvent );
148
150 int SelectAll( const TOOL_EVENT& aEvent );
151
153 int UnselectAll( const TOOL_EVENT& aEvent );
154
155 void ClearSelection( bool aQuietMode = false );
156
162 bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
163 bool checkVisibilityOnly = false ) const;
164
169 void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
170
177 void RebuildSelection();
178
187 bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
188 const std::vector<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } );
189
192 void SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath, SCH_ITEM* focusItem,
193 const std::vector<SCH_ITEM*>& items );
194
196
197protected:
198 SELECTION& selection() override { return m_selection; }
199
200private:
202
212 void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked,
213 bool aSelectedOnly = false );
214
230 bool selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, EDA_ITEM** aItem = nullptr,
231 bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
232 bool aSubtract = false, bool aExclusiveOr = false );
233
239 bool selectMultiple();
240
246 bool selectTableCells( SCH_TABLE* aTable );
247
251 int disambiguateCursor( const TOOL_EVENT& aEvent );
252
258 void select( EDA_ITEM* aItem ) override;
259
265 void unselect( EDA_ITEM* aItem ) override;
266
274 void highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
275
283 void unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup = nullptr ) override;
284
289
293 bool selectionContains( const VECTOR2I& aPoint ) const;
294
298 bool itemPassesFilter( EDA_ITEM* aItem );
299
301 void setTransitions() override;
302
303private:
304
305 SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
306 EE_SELECTION m_selection; // Current state of selection
307
308 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
309
310 bool m_isSymbolEditor; // True when the symbol editor is the parent frame
311 bool m_isSymbolViewer; // True when the symbol browser is the parent frame
312 int m_unit; // Fixed unit filter (for symbol editor)
313 int m_bodyStyle; // Fixed DeMorgan filter (for symbol editor)
314
316};
317
318#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:89
static SELECTION_CONDITION SingleSymbol
static SELECTION_CONDITION AllPinsOrSheetPins
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:166
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