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 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef KICAD_SCH_SELECTION_TOOL_H
25 #define KICAD_SCH_SELECTION_TOOL_H
26 
27 #include <tool/tool_interactive.h>
28 #include <tool/action_menu.h>
29 #include <tool/selection.h>
30 #include <tool/tool_menu.h>
31 #include <ee_collectors.h>
32 #include <sch_component.h>
33 
34 class SCH_BASE_FRAME;
35 class SCH_ITEM;
36 class EE_COLLECTOR;
37 
38 namespace KIGFX
39 {
40  class GAL;
41 }
42 
43 
45 {
46 public:
50 
54 };
55 
56 
58 {
59 public:
62 
64  bool Init() override;
65 
67  void Reset( RESET_REASON aReason ) override;
68 
69  int UpdateMenu( const TOOL_EVENT& aEvent );
70 
76  int Main( const TOOL_EVENT& aEvent );
77 
84 
85  inline TOOL_MENU& GetToolMenu() { return m_menu; }
86 
94 
105  EDA_ITEM* SelectPoint( const VECTOR2I& aWhere,
106  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
107  bool* aSelectionCancelledFlag = NULL, bool aCheckLocked = false );
108 
109  int AddItemToSel( const TOOL_EVENT& aEvent );
110  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
111  int AddItemsToSel( const TOOL_EVENT& aEvent );
112  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
113 
114  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
115  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
116  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
117  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
118 
120  EDA_ITEM* GetNode( VECTOR2I aPosition );
121 
123  int SelectNode( const TOOL_EVENT& aEvent );
124 
126  int SelectConnection( const TOOL_EVENT& aEvent );
127 
129  int ClearSelection( const TOOL_EVENT& aEvent );
130 
138  int SelectionMenu( const TOOL_EVENT& aEvent );
139 
144  void RebuildSelection();
145 
146 private:
154  bool selectMultiple();
155 
160  void guessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aWhere );
161 
168  bool doSelectionMenu( EE_COLLECTOR* aItems );
169 
174  void clearSelection();
175 
183  void toggleSelection( EDA_ITEM* aItem, bool aForce = false );
184 
191  bool selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
192 
199  void select( EDA_ITEM* aItem );
200 
207  void unselect( EDA_ITEM* aItem );
208 
216  void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr );
217 
225  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr );
226 
233  bool selectionContains( const VECTOR2I& aPoint ) const;
234 
236  void setTransitions() override;
237 
238 private:
239  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
240  SELECTION m_selection; // Current state of selection
241 
242  bool m_additive; // Items should be added to selection (instead of replacing)
243  bool m_subtractive; // Items should be removed from selection
244  bool m_multiple; // Multiple selection mode is active
245  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
246 
248  int m_unit; // Fixed unit filter (for symbol editor)
249  int m_convert; // Fixed DeMorgan filter (for symbol editor)
250 
252 };
253 
254 #endif //KICAD_SCH_SELECTION_TOOL_H
SELECTION & GetSelection()
Function GetSelection()
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
int UpdateMenu(const TOOL_EVENT &aEvent)
void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
static SELECTION_CONDITION SingleSymbol
TOOL_MENU & GetToolMenu()
Class TOOL_MENU.
Definition: tool_menu.h:47
static SELECTION_CONDITION IdleSelection
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.
Class EE_COLLECTOR.
Definition: ee_collectors.h:38
int AddItemsToSel(const TOOL_EVENT &aEvent)
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
static SELECTION_CONDITION Idle
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
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 guessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aWhere)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
void toggleSelection(EDA_ITEM *aItem, bool aForce=false)
Function toggleSelection() Changes selection status of a given item.
static SELECTION_CONDITION Empty
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:588
Class TOOL_EVENT.
Definition: tool_event.h:167
void clearSelection()
Function clearSelection() Clears the current selection.
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.
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
static SELECTION_CONDITION SingleMultiUnitSymbol
EDA_ITEM * GetNode(VECTOR2I aPosition)
Find (but don't select) node under cursor
bool selectable(const EDA_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
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)
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
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:41
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
void setTransitions() override
Sets up handlers for various events.
EDA_ITEM * SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, bool *aSelectionCancelledFlag=NULL, bool aCheckLocked=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function RequestSelection()
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
int Main(const TOOL_EVENT &aEvent)
Function Main()