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-2021 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/selection_tool.h>
29 #include <tool/tool_interactive.h>
30 #include <tool/tool_menu.h>
31 #include "tools/pl_selection.h"
32 
33 class PL_EDITOR_FRAME;
34 class SCH_ITEM;
35 class COLLECTOR;
36 
37 namespace KIGFX
38 {
39  class GAL;
40 }
41 
42 
44 {
45 public:
47  ~PL_SELECTION_TOOL() override { }
48 
50  bool Init() override;
51 
53  void Reset( RESET_REASON aReason ) override;
54 
55  int UpdateMenu( const TOOL_EVENT& aEvent );
56 
60  int Main( const TOOL_EVENT& aEvent );
61 
66 
72 
82  void SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag = nullptr );
83 
84  int AddItemToSel( const TOOL_EVENT& aEvent );
85  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
86  int AddItemsToSel( const TOOL_EVENT& aEvent );
87  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
88 
89  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
90  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
91  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
92  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
93 
94  void BrightenItem( EDA_ITEM* aItem );
95  void UnbrightenItem( EDA_ITEM* aItem );
96 
97  int ClearSelection( const TOOL_EVENT& aEvent );
98  void ClearSelection();
99 
104  void RebuildSelection();
105 
112  int SelectionMenu( const TOOL_EVENT& aEvent );
113 
114 private:
120  bool selectMultiple();
121 
126  void guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aWhere );
127 
135  bool doSelectionMenu( COLLECTOR* aItems );
136 
142  void onDisambiguationExpire( wxTimerEvent& aEvent );
143 
147  int disambiguateCursor( const TOOL_EVENT& aEvent );
148 
154  void select( EDA_ITEM* aItem );
155 
161  void unselect( EDA_ITEM* aItem );
162 
170  void highlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
171 
179  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
180 
184  bool selectionContains( const VECTOR2I& aPoint ) const;
185 
187  void setTransitions() override;
188 
189 private:
190  PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame
191  PL_SELECTION m_selection; // Current state of selection
192 };
193 
194 #endif //PL_SELECTION_TOOL_H
void RebuildSelection()
Rebuild the selection from the flags in the view items.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
int UpdateMenu(const TOOL_EVENT &aEvent)
The main window used in the drawing sheet editor.
void BrightenItem(EDA_ITEM *aItem)
Define a general 2D-vector/point.
Definition: vector2d.h:61
void select(EDA_ITEM *aItem)
Takes necessary action mark an item as selected.
void SelectPoint(const VECTOR2I &aWhere, bool *aSelectionCancelledFlag=nullptr)
Select an item pointed by the parameter aWhere.
PL_EDITOR_FRAME * m_frame
~PL_SELECTION_TOOL() override
int AddItemToSel(const TOOL_EVENT &aEvent)
PL_SELECTION & GetSelection()
Return the set of currently selected items.
bool doSelectionMenu(COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
bool selectionContains(const VECTOR2I &aPoint) const
Set up handlers for various events.
void unselect(EDA_ITEM *aItem)
Take necessary action mark an item as unselected.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
Generic, UI-independent tool event.
Definition: tool_event.h:152
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)
Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:507
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
PL_SELECTION m_selection
int Main(const TOOL_EVENT &aEvent)
The main loop.
bool Init() override
Init() is called once upon a registration of the tool.
void UnbrightenItem(EDA_ITEM *aItem)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:48
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
void highlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Highlight the item visually.
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int AddItemsToSel(const TOOL_EVENT &aEvent)
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
PL_SELECTION & RequestSelection()
Return either an existing selection (filtered), or the selection at the current cursor if the existin...