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/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  ~PL_SELECTION_TOOL() override { }
47 
49  bool Init() override;
50 
52  void Reset( RESET_REASON aReason ) override;
53 
54  int UpdateMenu( const TOOL_EVENT& aEvent );
55 
59  int Main( const TOOL_EVENT& aEvent );
60 
65 
71 
81  void SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag = nullptr );
82 
83  int AddItemToSel( const TOOL_EVENT& aEvent );
84  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
85  int AddItemsToSel( const TOOL_EVENT& aEvent );
86  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
87 
88  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
89  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
90  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
91  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
92 
93  void BrightenItem( EDA_ITEM* aItem );
94  void UnbrightenItem( EDA_ITEM* aItem );
95 
96  int ClearSelection( const TOOL_EVENT& aEvent );
97  void ClearSelection();
98 
103  void RebuildSelection();
104 
111  int SelectionMenu( const TOOL_EVENT& aEvent );
112 
113 private:
119  bool selectMultiple();
120 
125  void guessSelectionCandidates( COLLECTOR& collector, const VECTOR2I& aWhere );
126 
134  bool doSelectionMenu( COLLECTOR* aItems );
135 
141  void select( EDA_ITEM* aItem );
142 
148  void unselect( EDA_ITEM* aItem );
149 
157  void highlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
158 
166  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr );
167 
171  bool selectionContains( const VECTOR2I& aPoint ) const;
172 
174  void setTransitions() override;
175 
176 private:
177  PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame
178  PL_SELECTION m_selection; // Current state of selection
179 
180  bool m_additive; // Items should be added to selection (instead of replacing)
181  bool m_subtractive; // Items should be removed from selection
182  bool m_exclusive_or; // Items' selection state should be toggled
183  bool m_multiple; // Multiple selection mode is active
184  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
185 };
186 
187 #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:175
int UpdateMenu(const TOOL_EVENT &aEvent)
PL_EDITOR_FRAME is 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:173
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:557
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:150
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:53
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
PL_SELECTION & RequestSelection()
Return either an existing selection (filtered), or the selection at the current cursor if the existin...