KiCad PCB EDA Suite
pl_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 PL_SELECTION_TOOL_H
26 #define PL_SELECTION_TOOL_H
27 
28 #include <tool/tool_interactive.h>
29 #include <tool/tool_menu.h>
30 #include <tools/pl_selection.h>
31 
32 class PL_EDITOR_FRAME;
33 class SCH_ITEM;
34 class COLLECTOR;
35 
36 namespace KIGFX
37 {
38  class GAL;
39 }
40 
41 
43 {
44 public:
46 };
47 
48 
50 {
51 public:
53  ~PL_SELECTION_TOOL() override { }
54 
56  bool Init() override;
57 
59  void Reset( RESET_REASON aReason ) override;
60 
61  int UpdateMenu( const TOOL_EVENT& aEvent );
62 
68  int Main( const TOOL_EVENT& aEvent );
69 
76 
84 
94  EDA_ITEM* SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag = nullptr );
95 
96  int AddItemToSel( const TOOL_EVENT& aEvent );
97  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
98  int AddItemsToSel( const TOOL_EVENT& aEvent );
99  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
100 
101  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
102  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
103  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
104  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
105 
106  void BrightenItem( EDA_ITEM* aItem );
107  void UnbrightenItem( EDA_ITEM* aItem );
108 
109  int ClearSelection( const TOOL_EVENT& aEvent );
110  void ClearSelection();
111 
116  void RebuildSelection();
117 
125  int SelectionMenu( const TOOL_EVENT& aEvent );
126 
127 private:
135  bool selectMultiple();
136 
141  void guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aWhere );
142 
149  bool doSelectionMenu( COLLECTOR* aItems );
150 
157  void select( EDA_ITEM* aItem );
158 
165  void unselect( EDA_ITEM* aItem );
166 
174  void highlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
175 
183  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
184 
189  bool selectionContains( const VECTOR2I& aPoint ) const;
190 
192  void setTransitions() override;
193 
194 private:
195  PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame
196  PL_SELECTION m_selection; // Current state of selection
197 
198  bool m_additive; // Items should be added to selection (instead of replacing)
199  bool m_subtractive; // Items should be removed from selection
200  bool m_exclusive_or; // Items' selection state should be toggled
201  bool m_multiple; // Multiple selection mode is active
202  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
203 };
204 
205 #endif //PL_SELECTION_TOOL_H
void RebuildSelection()
Rebuild the selection from the flags in the view items.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
int UpdateMenu(const TOOL_EVENT &aEvent)
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
void BrightenItem(EDA_ITEM *aItem)
static SELECTION_CONDITION Idle
Class that groups generic conditions for selected items.
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
PL_EDITOR_FRAME * m_frame
~PL_SELECTION_TOOL() override
int AddItemToSel(const TOOL_EVENT &aEvent)
PL_SELECTION & GetSelection()
Function GetSelection()
bool doSelectionMenu(COLLECTOR *aItems)
Allows the selection of a single item from a list via pop-up menu.
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:642
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
Class TOOL_EVENT.
Definition: tool_event.h:171
void guessSelectionCandidates(COLLECTOR &collector, const VECTOR2I &aWhere)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
int SelectionMenu(const TOOL_EVENT &aEvent)
Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down t...
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
EDA_ITEM * SelectPoint(const VECTOR2I &aWhere, bool *aSelectionCancelledFlag=nullptr)
Function selectPoint() Selects an item pointed by the parameter aWhere.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
PL_SELECTION m_selection
int Main(const TOOL_EVENT &aEvent)
Function Main()
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
void UnbrightenItem(EDA_ITEM *aItem)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
Definition: collector.h:55
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
void highlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
void setTransitions() override
Sets up handlers for various events.
int AddItemsToSel(const TOOL_EVENT &aEvent)
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
PL_SELECTION & RequestSelection()
Function RequestSelection()