KiCad PCB EDA Suite
gerbview/tools/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) 2017 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __GERBVIEW_SELECTION_TOOL_H
22 #define __GERBVIEW_SELECTION_TOOL_H
23 
24 #include <memory>
25 #include <math/vector2d.h>
26 
27 #include <tool/tool_interactive.h>
28 #include <tool/context_menu.h>
29 #include <tool/selection.h>
31 #include <tool/tool_menu.h>
32 
33 #include <gerbview_frame.h>
34 
35 class SELECTION_AREA;
36 class GERBER_COLLECTOR;
37 
38 namespace KIGFX
39 {
40  class GAL;
41 }
42 
43 
50 {
51 public:
54 
56  bool Init() override;
57 
59  void Reset( RESET_REASON aReason ) override;
60 
66  int Main( const TOOL_EVENT& aEvent );
67 
74 
76  {
77  return m_menu;
78  }
79 
81  int CursorSelection( const TOOL_EVENT& aEvent );
82 
84  int ClearSelection( const TOOL_EVENT& aEvent );
85 
87  int SelectItem( const TOOL_EVENT& aEvent );
88 
90  int SelectItems( const TOOL_EVENT& aEvent );
91 
93  int UnselectItem( const TOOL_EVENT& aEvent );
94 
96  int UnselectItems( const TOOL_EVENT& aEvent );
97 
99  int MeasureTool( const TOOL_EVENT& aEvent );
100 
102  static const TOOL_EVENT SelectedEvent;
103 
106 
108  static const TOOL_EVENT ClearedEvent;
109 
111  void setTransitions() override;
112 
114  void zoomFitSelection( void );
115 
116 private:
128  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false );
129 
137  bool selectCursor( bool aSelectAlways = false );
138 
146  bool selectMultiple();
147 
152  void clearSelection();
153 
162 
169  void toggleSelection( EDA_ITEM* aItem );
170 
177  bool selectable( const EDA_ITEM* aItem ) const;
178 
185  void select( EDA_ITEM* aItem );
186 
193  void unselect( EDA_ITEM* aItem );
194 
200  void selectVisually( EDA_ITEM* aItem );
201 
207  void unselectVisually( EDA_ITEM* aItem );
208 
215  bool selectionContains( const VECTOR2I& aPoint ) const;
216 
223  void guessSelectionCandidates( GERBER_COLLECTOR& aCollector ) const;
224 
227 
230 
233 
236 
239 
242 
245 };
246 
247 #endif
SELECTION & GetSelection()
Function GetSelection()
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
bool selectable(const EDA_ITEM *aItem) const
Function selectable() Checks conditions for an item to be selected.
Class GERBER_COLLECTOR is intended for use when the right click button is pressed,...
bool m_preliminary
Determines if the selection is preliminary or final.
EDA_ITEM * disambiguationMenu(GERBER_COLLECTOR *aItems)
Function disambiguationMenu() Handles the menu that allows one to select one of many items in case th...
SELECTION m_selection
Current state of selection.
Class TOOL_MENU.
Definition: tool_menu.h:47
int CursorSelection(const TOOL_EVENT &aEvent)
Select a single item under cursor event handler.
void selectVisually(EDA_ITEM *aItem)
Function selectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
int Main(const TOOL_EVENT &aEvent)
Function Main()
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
int UnselectItem(const TOOL_EVENT &aEvent)
Item unselection event handler.
void setTransitions() override
Sets up handlers for various events.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
Class TOOL_EVENT.
Definition: tool_event.h:168
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
void zoomFitSelection(void)
Zooms the screen to center and fit the current selection.
void unselectVisually(EDA_ITEM *aItem)
Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
GERBVIEW_FRAME * m_frame
Pointer to the parent frame.
void toggleSelection(EDA_ITEM *aItem)
Function toggleSelection() Changes selection status of a given item.
int SelectItems(const TOOL_EVENT &aEvent)
Multiple item selection event handler
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
int MeasureTool(const TOOL_EVENT &aEvent)
Launches a tool to measure between points
int SelectItem(const TOOL_EVENT &aEvent)
Item selection event handler.
Class GERBVIEW_SELECTION_TOOL.
int UnselectItems(const TOOL_EVENT &aEvent)
Multiple item unselection event handler
bool selectCursor(bool aSelectAlways=false)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
void guessSelectionCandidates(GERBER_COLLECTOR &aCollector) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void clearSelection()
Function clearSelection() Clears the current selection.
TOOL_MENU m_menu
Menu model displayed by the tool.
bool m_multiple
Flag saying if multiple selection mode is active.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
bool m_subtractive
Flag saying if items should be removed from the current selection.