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 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/tool_interactive.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_component.h>
34 #include <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:
51 };
52 
53 
55 {
56 public:
59 
61  bool Init() override;
62 
64  void Reset( RESET_REASON aReason ) override;
65 
66  int UpdateMenu( const TOOL_EVENT& aEvent );
67 
73  int Main( const TOOL_EVENT& aEvent );
74 
75  void OnIdle( wxIdleEvent& aEvent );
76 
83 
91 
108  bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
109  EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
110  bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
111  bool aExclusiveOr = false );
112 
113  int AddItemToSel( const TOOL_EVENT& aEvent );
114  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
115  int AddItemsToSel( const TOOL_EVENT& aEvent );
116  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
117 
118  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
119  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
120  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
121  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
122 
123  void BrightenItem( EDA_ITEM* aItem );
124  void UnbrightenItem( EDA_ITEM* aItem );
125 
126  void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
127 
129  EDA_ITEM* GetNode( VECTOR2I aPosition );
130 
132  int SelectNode( const TOOL_EVENT& aEvent );
133 
135  int SelectConnection( const TOOL_EVENT& aEvent );
136 
138  int ClearSelection( const TOOL_EVENT& aEvent );
139 
141  int SelectAll( const TOOL_EVENT& aEvent );
142 
143  void ClearSelection();
144 
150  bool Selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
151 
156  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
157 
165  int SelectionMenu( const TOOL_EVENT& aEvent );
166 
171  void RebuildSelection();
172 
173 private:
185  bool collectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
186  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems );
187 
195  void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked );
196 
213  bool selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem = nullptr,
214  bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
215  bool aSubtract = false, bool aExclusiveOr = false );
216 
224  bool selectMultiple();
225 
232  bool doSelectionMenu( EE_COLLECTOR* aItems );
233 
240  void select( EDA_ITEM* aItem );
241 
248  void unselect( EDA_ITEM* aItem );
249 
257  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
258 
266  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
267 
271  void updateReferencePoint();
272 
277  bool selectionContains( const VECTOR2I& aPoint ) const;
278 
280  void setTransitions() override;
281 
282 private:
283  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
284  EE_SELECTION m_selection; // Current state of selection
285 
286  bool m_additive; // Items should be added to sel (instead of replacing)
287  bool m_subtractive; // Items should be removed from sel
288  bool m_exclusive_or; // Items' selection state should be toggled
289  bool m_multiple; // Multiple selection mode is active
290  bool m_skip_heuristics; // Show disambuguation menu for all items under the
291  // cursor rather than trying to narrow them down first
292  // using heuristics
293 
294  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
295 
296  bool m_isSymbolEditor; // True when the symbol editor is the parent frame
297  bool m_isLibView; // True when libview is the parent frame
298  int m_unit; // Fixed unit filter (for symbol editor)
299  int m_convert; // Fixed DeMorgan filter (for symbol editor)
300 };
301 
302 #endif //KICAD_SCH_SELECTION_TOOL_H
void OnIdle(wxIdleEvent &aEvent)
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
int UpdateMenu(const TOOL_EVENT &aEvent)
int SelectAll(const TOOL_EVENT &aEvent)
Select all visible items in sheet
bool collectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function CollectHits() Selects one or more items at the location given by parameter aWhere.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
static SELECTION_CONDITION SingleSymbol
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
Class that groups generic conditions for selected items.
EE_COLLECTOR.
Definition: ee_collectors.h:42
bool Selectable(const EDA_ITEM *aItem, bool checkVisibilityOnly=false) const
Function Selectable() Checks conditions for an item to be selected.
int AddItemsToSel(const TOOL_EVENT &aEvent)
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
KICURSOR
Definition: cursors.h:33
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
EE_SELECTION & GetSelection()
Function GetSelection()
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function RequestSelection()
void updateReferencePoint()
Sets the reference point to the anchor of the top-left item.
static SELECTION_CONDITION SingleDeMorganSymbol
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
int SelectNode(const TOOL_EVENT &aEvent)
Select node under cursor
bool Init() override
Function Init() 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)
Function SelectPoint() This is the primary SelectPoint method that will prompt the user with a menu t...
void highlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
void narrowSelection(EE_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked)
Applies rules to narrow the collection down to selectable objects, and then heuristics to try and nar...
void SelectHighlightItem(EDA_ITEM *aItem)
#define SELECTED
Definition: eda_item.h:113
TOOL_EVENT.
Definition: tool_event.h:171
int SelectConnection(const TOOL_EVENT &aEvent)
If node selected then expand to connection, otherwise select connection under cursor
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:576
static SELECTION_CONDITION SingleMultiUnitSymbol
void UnbrightenItem(EDA_ITEM *aItem)
EDA_ITEM * GetNode(VECTOR2I aPosition)
Find (but don't select) node under cursor
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
void unselect(EDA_ITEM *aItem)
Function unselect() Takes 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)
Function SelectPoint() This overload of SelectPoint will create an EE_COLLECTOR and collect hits at l...
int SelectionMenu(const TOOL_EVENT &aEvent)
Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down t...
bool doSelectionMenu(EE_COLLECTOR *aItems)
Allows the selection of a single item from a list via pop-up menu.
SCH_BASE_FRAME * m_frame
void RebuildSelection()
Rebuilds the selection from the EDA_ITEMs' selection flags.
static const KICAD_T AllItems[]
Definition: ee_collectors.h:45
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
void setTransitions() override
Sets up handlers for various 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:194
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
int Main(const TOOL_EVENT &aEvent)
Function Main()