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-2021 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 
36 class SCH_BASE_FRAME;
37 class SCH_ITEM;
38 
39 namespace KIGFX
40 {
41  class GAL;
42 }
43 
44 
46 {
47 public:
53 };
54 
55 
57 {
58 public:
61 
63  bool Init() override;
64 
66  void Reset( RESET_REASON aReason ) override;
67 
68  int UpdateMenu( const TOOL_EVENT& aEvent );
69 
73  int Main( const TOOL_EVENT& aEvent );
74 
75  void OnIdle( wxIdleEvent& aEvent );
76 
81 
87 
103  bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
104  EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
105  bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
106  bool aExclusiveOr = false );
107 
108  int AddItemToSel( const TOOL_EVENT& aEvent );
109  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
110  int AddItemsToSel( const TOOL_EVENT& aEvent );
111  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
112 
113  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
114  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
115  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
116  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
117 
122  void RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode = false );
123 
124  void BrightenItem( EDA_ITEM* aItem );
125  void UnbrightenItem( EDA_ITEM* aItem );
126 
127  void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
128 
130  EDA_ITEM* GetNode( VECTOR2I aPosition );
131 
133  int SelectNode( const TOOL_EVENT& aEvent );
134 
136  int SelectConnection( const TOOL_EVENT& aEvent );
137 
139  int ClearSelection( const TOOL_EVENT& aEvent );
140 
142  int SelectAll( const TOOL_EVENT& aEvent );
143 
144  void ClearSelection();
145 
151  bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
152  bool checkVisibilityOnly = false ) const;
153 
158  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
159 
166  int SelectionMenu( const TOOL_EVENT& aEvent );
167 
174  void RebuildSelection();
175 
186  bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
187  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems );
188 
189 private:
199  void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked, bool aSelectPoints );
200 
216  bool selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem = nullptr,
217  bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
218  bool aSubtract = false, bool aExclusiveOr = false );
219 
225  bool selectMultiple();
226 
234  bool doSelectionMenu( EE_COLLECTOR* aItems );
235 
241  void onDisambiguationExpire( wxTimerEvent& aEvent );
242 
246  int disambiguateCursor( const TOOL_EVENT& aEvent );
247 
253  void select( EDA_ITEM* aItem );
254 
260  void unselect( EDA_ITEM* aItem );
261 
269  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
270 
278  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
279 
283  void updateReferencePoint();
284 
288  bool selectionContains( const VECTOR2I& aPoint ) const;
289 
291  void setTransitions() override;
292 
293 private:
294 
295  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
296  EE_SELECTION m_selection; // Current state of selection
297 
298  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
299 
300  bool m_isSymbolEditor; // True when the symbol editor is the parent frame
301  bool m_isSymbolViewer; // True when the symbol browser is the parent frame
302  int m_unit; // Fixed unit filter (for symbol editor)
303  int m_convert; // Fixed DeMorgan filter (for symbol editor)
304 };
305 
306 #endif //KICAD_SCH_SELECTION_TOOL_H
void OnIdle(wxIdleEvent &aEvent)
bool selectionContains(const VECTOR2I &aPoint) const
Set up handlers for various events.
int UpdateMenu(const TOOL_EVENT &aEvent)
int SelectAll(const TOOL_EVENT &aEvent)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243
static SELECTION_CONDITION SingleSymbol
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
Class that groups generic conditions for selected items.
int AddItemsToSel(const TOOL_EVENT &aEvent)
void select(EDA_ITEM *aItem)
Take necessary action mark an item as selected.
KICURSOR
Definition: cursors.h:33
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
EE_SELECTION & GetSelection()
Return the set of currently selected items.
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Return either an existing selection (filtered), or the selection at the current cursor if the existin...
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
static SELECTION_CONDITION SingleDeMorganSymbol
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int SelectNode(const TOOL_EVENT &aEvent)
If node selected then expand to connection, otherwise select connection under cursor.
bool Init() override
Init() is called once upon a registration of the tool.
void BrightenItem(EDA_ITEM *aItem)
bool selectPoint(EE_COLLECTOR &aCollector, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This is the primary SelectPoint method that will prompt the user with a menu to disambiguate multiple...
void highlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Highlight the item visually.
void SelectHighlightItem(EDA_ITEM *aItem)
Find (but don't select) node under cursor.
Generic, UI-independent tool event.
Definition: tool_event.h:152
void narrowSelection(EE_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked, bool aSelectPoints)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
int SelectConnection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
#define SELECTED
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Select one or more items at the location given by parameter aWhere.
static SELECTION_CONDITION SingleMultiUnitSymbol
void UnbrightenItem(EDA_ITEM *aItem)
EDA_ITEM * GetNode(VECTOR2I aPosition)
Select node under cursor.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
void unselect(EDA_ITEM *aItem)
Take necessary action mark an item as unselected.
int AddItemToSel(const TOOL_EVENT &aEvent)
bool SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere before c...
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
bool doSelectionMenu(EE_COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
SCH_BASE_FRAME * m_frame
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
static SELECTION_CONDITION SingleNonExcludedMarker
static const KICAD_T AllItems[]
Definition: ee_collectors.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
static SELECTION_CONDITION SingleSymbolOrPower
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
EE_SELECTION m_selection
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
int Main(const TOOL_EVENT &aEvent)
The main loop.