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 
35 class SCH_BASE_FRAME;
36 class SCH_ITEM;
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 
92 
103  EDA_ITEM* SelectPoint( const VECTOR2I& aWhere,
104  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
105  bool* aSelectionCancelledFlag = NULL, bool aCheckLocked = false,
106  bool aAdd = false, bool aSubtract = false, 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 
118  void BrightenItem( EDA_ITEM* aItem );
119  void UnbrightenItem( EDA_ITEM* aItem );
120 
122  EDA_ITEM* GetNode( VECTOR2I aPosition );
123 
125  int SelectNode( const TOOL_EVENT& aEvent );
126 
128  int SelectConnection( const TOOL_EVENT& aEvent );
129 
131  int ClearSelection( const TOOL_EVENT& aEvent );
132 
133  void ClearSelection();
134 
140  bool Selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
141 
146  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
147 
155  int SelectionMenu( const TOOL_EVENT& aEvent );
156 
161  void RebuildSelection();
162 
163 private:
171  bool selectMultiple();
172 
179  bool doSelectionMenu( EE_COLLECTOR* aItems );
180 
187  void select( EDA_ITEM* aItem );
188 
195  void unselect( EDA_ITEM* aItem );
196 
204  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
205 
213  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
214 
218  void updateReferencePoint();
219 
224  bool selectionContains( const VECTOR2I& aPoint ) const;
225 
227  void setTransitions() override;
228 
229 private:
230  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
231  EE_SELECTION m_selection; // Current state of selection
232 
233  bool m_additive; // Items should be added to selection (instead of replacing)
234  bool m_subtractive; // Items should be removed from selection
235  bool m_exclusive_or; // Items' selection state should be toggled
236  bool m_multiple; // Multiple selection mode is active
237  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
238 
239  bool m_isLibEdit; // True when libedit is the parent frame
240  bool m_isLibView; // True when libview is the parent frame
241  int m_unit; // Fixed unit filter (for symbol editor)
242  int m_convert; // Fixed DeMorgan filter (for symbol editor)
243 };
244 
245 #endif //KICAD_SCH_SELECTION_TOOL_H
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
int UpdateMenu(const TOOL_EVENT &aEvent)
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
static SELECTION_CONDITION SingleSymbol
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:39
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.
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
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)
void highlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
static SELECTION_CONDITION Empty
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:642
Class 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.
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)
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:42
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
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, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=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,...
EE_SELECTION m_selection
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
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()