KiCad PCB EDA Suite
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) 2021-2022 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25#ifndef INCLUDE_TOOL_SELECTION_TOOL_H_
26#define INCLUDE_TOOL_SELECTION_TOOL_H_
27
28#include <math/vector2d.h>
30#include <wx/timer.h>
31
32class COLLECTOR;
33
34
35class SELECTION_TOOL : public TOOL_INTERACTIVE, public wxEvtHandler
36{
37public:
38 SELECTION_TOOL( const std::string& aName );
40
45 int UpdateMenu( const TOOL_EVENT& aEvent );
46
47 int AddItemToSel( const TOOL_EVENT& aEvent );
48 void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
49 int AddItemsToSel( const TOOL_EVENT& aEvent );
50 void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
51
52 int RemoveItemFromSel( const TOOL_EVENT& aEvent );
53 void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
54 int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
55 void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
56
61 void RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode = false );
62
63 void BrightenItem( EDA_ITEM* aItem );
64 void UnbrightenItem( EDA_ITEM* aItem );
65
72 int SelectionMenu( const TOOL_EVENT& aEvent );
73
74protected:
78 virtual SELECTION& selection() = 0;
79
85 void onDisambiguationExpire( wxTimerEvent& aEvent );
86
90 virtual void select( EDA_ITEM* aItem ) = 0;
91
95 virtual void unselect( EDA_ITEM* aItem ) = 0;
96
103 virtual void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) = 0;
104
111 virtual void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) = 0;
112
117 void setModifiersState( bool aShiftState, bool aCtrlState, bool aAltState );
118
122 bool hasModifier();
123
127 virtual bool ctrlClickHighlights() { return false; }
128
129 bool doSelectionMenu( COLLECTOR* aCollector );
130
131protected:
132 bool m_additive; // Items should be added to sel (instead of replacing)
133 bool m_subtractive; // Items should be removed from sel
134 bool m_exclusive_or; // Items' selection state should be toggled
135 bool m_multiple; // Multiple selection mode is active
136 bool m_skip_heuristics; // Show disambuguation menu for all items under the
137 // cursor rather than trying to narrow them down first
138 // using heuristics
139 bool m_highlight_modifier;// select highlight net on left click
140 bool m_drag_additive; // Add multiple items to selection
141 bool m_drag_subtractive; // Remove multiple from selection
142
143 bool m_canceledMenu; // Sets to true if the disambiguation menu was cancelled
144
145 wxTimer m_disambiguateTimer; // Timer to show the disambiguate menu
146
147 VECTOR2I m_originalCursor; // Location of original cursor when starting click
148};
149
150#endif /* INCLUDE_TOOL_SELECTION_TOOL_H_ */
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:48
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
bool doSelectionMenu(COLLECTOR *aCollector)
wxTimer m_disambiguateTimer
int AddItemsToSel(const TOOL_EVENT &aEvent)
void BrightenItem(EDA_ITEM *aItem)
virtual void unselect(EDA_ITEM *aItem)=0
Take necessary action mark an item as unselected.
int AddItemToSel(const TOOL_EVENT &aEvent)
int UpdateMenu(const TOOL_EVENT &aEvent)
Update a menu's state based on the current selection.
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state ...
void UnbrightenItem(EDA_ITEM *aItem)
VECTOR2I m_originalCursor
virtual void select(EDA_ITEM *aItem)=0
Take necessary action mark an item as selected.
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
SELECTION_TOOL(const std::string &aName)
virtual void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)=0
Unhighlight the item visually.
virtual void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)=0
Highlight the item visually.
virtual SELECTION & selection()=0
Return a reference to the selection.
bool hasModifier()
True if a selection modifier is enabled, false otherwise.
virtual bool ctrlClickHighlights()
Determines if ctrl-click is highlight net or XOR selection.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
Generic, UI-independent tool event.
Definition: tool_event.h:156
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:524