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 
105  bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
106  EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
107  bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
108  bool aExclusiveOr = false );
109 
110  int AddItemToSel( const TOOL_EVENT& aEvent );
111  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
112  int AddItemsToSel( const TOOL_EVENT& aEvent );
113  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
114 
115  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
116  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
117  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
118  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
119 
120  void BrightenItem( EDA_ITEM* aItem );
121  void UnbrightenItem( EDA_ITEM* aItem );
122 
123  void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
124 
126  EDA_ITEM* GetNode( VECTOR2I aPosition );
127 
129  int SelectNode( const TOOL_EVENT& aEvent );
130 
132  int SelectConnection( const TOOL_EVENT& aEvent );
133 
135  int ClearSelection( const TOOL_EVENT& aEvent );
136 
137  void ClearSelection();
138 
144  bool Selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
145 
150  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
151 
159  int SelectionMenu( const TOOL_EVENT& aEvent );
160 
165  void RebuildSelection();
166 
167 private:
175  bool selectMultiple();
176 
183  bool doSelectionMenu( EE_COLLECTOR* aItems );
184 
191  void select( EDA_ITEM* aItem );
192 
199  void unselect( EDA_ITEM* aItem );
200 
208  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
209 
217  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
218 
222  void updateReferencePoint();
223 
228  bool selectionContains( const VECTOR2I& aPoint ) const;
229 
231  void setTransitions() override;
232 
233 private:
234  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
235  EE_SELECTION m_selection; // Current state of selection
236 
237  bool m_additive; // Items should be added to selection (instead of replacing)
238  bool m_subtractive; // Items should be removed from selection
239  bool m_exclusive_or; // Items' selection state should be toggled
240  bool m_multiple; // Multiple selection mode is active
241  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
242 
243  bool m_isLibEdit; // True when libedit is the parent frame
244  bool m_isLibView; // True when libview is the parent frame
245  int m_unit; // Fixed unit filter (for symbol editor)
246  int m_convert; // Fixed DeMorgan filter (for symbol editor)
247 };
248 
249 #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: color4d.cpp:175
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.
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.
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.
#define SELECTED
Definition: base_struct.h:124
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:587
void SelectHighlightItem(EDA_ITEM *aItem)
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)
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() Selects one or all items pointed by the parameter aWhere.
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: base_struct.h:159
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: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
EE_SELECTION m_selection
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
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()