KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_test_selection_tool.cpp
Go to the documentation of this file.
1#include "pcb_test_frame.h"
3
5#include <tool/actions.h>
6#include <tool/tool_manager.h>
7
9 : SELECTION_TOOL( "pcbnew.InteractiveSelection" )
10{
11}
12
14{
15 view()->Remove( &m_selection );
16}
17
19{
20 view()->Remove( &m_selection );
21 view()->Add( &m_selection );
22
23 return true;
24}
25
27{
28}
29
30
32{
33 if( m_selection.Empty() )
34 return;
35
36 while( m_selection.GetSize() )
38
39 view()->Update( &m_selection );
40
41 m_selection.SetIsHover( false );
43}
44
45#include <collectors.h>
46
47
49{
50 GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
51 (PCB_LAYER_ID) view()->GetTopLayer(), view() );
52
53 bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
54
55 // account for the globals
56 guide.SetIgnoreFPTextOnBack( !board()->IsElementVisible( LAYER_FP_TEXT ) );
57 guide.SetIgnoreFPTextOnFront( !board()->IsElementVisible( LAYER_FP_TEXT ) );
58 guide.SetIgnoreFootprintsOnBack( !board()->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
59 guide.SetIgnoreFootprintsOnFront( !board()->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
60 guide.SetIgnorePadsOnBack( padsDisabled );
61 guide.SetIgnorePadsOnFront( padsDisabled );
62 guide.SetIgnoreThroughHolePads( padsDisabled );
63 guide.SetIgnoreFPValues( !board()->IsElementVisible( LAYER_FP_VALUES ) );
64 guide.SetIgnoreFPReferences( !board()->IsElementVisible( LAYER_FP_REFERENCES ) );
65 guide.SetIgnoreThroughVias( !board()->IsElementVisible( LAYER_VIAS ) );
66 guide.SetIgnoreBlindBuriedVias( !board()->IsElementVisible( LAYER_VIAS ) );
67 guide.SetIgnoreMicroVias( !board()->IsElementVisible( LAYER_VIAS ) );
68 guide.SetIgnoreTracks( !board()->IsElementVisible( LAYER_TRACKS ) );
69
70 return guide;
71}
72
74{
76 GENERAL_COLLECTOR collector;
77
78 for( auto item : m_selection.Items() )
79 {
81 }
82
85
86 if( m_selectableTypes.empty() )
87 collector.Collect( board(), GENERAL_COLLECTOR::AllBoardItems, aWhere, guide );
88 else
89 collector.Collect( board(), m_selectableTypes, aWhere, guide );
90
91 if( collector.GetCount() > 0 )
92 {
93 for( int i = 0; i < collector.GetCount(); ++i )
94 {
95 {
96 select( collector[i] );
97 }
98 }
99 }
100
102
103 if( m_selectionHook )
105
106 return false;
107}
108
109
111{
113}
114
115
116void PCB_TEST_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
117{
118 if( aMode == SELECTED )
119 aItem->SetSelected();
120 else if( aMode == BRIGHTENED )
121 aItem->SetBrightened();
122
123 if( aUsingOverlay && aMode != BRIGHTENED )
124 view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
125
126 if( aItem->IsBOARD_ITEM() )
127 {
128 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
129 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, std::placeholders::_1,
130 aMode, aUsingOverlay ),
131 RECURSE_MODE::RECURSE );
132 }
133}
134
135
137{
138 if( aGroup )
139 aGroup->Remove( aItem );
140
141 unhighlightInternal( aItem, aMode, aGroup != nullptr );
142 view()->Update( aItem, KIGFX::REPAINT );
143
144 // Many selections are very temporal and updating the display each time just creates noise.
145 if( aMode == BRIGHTENED )
147}
148
149
150void PCB_TEST_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
151{
152 if( aMode == SELECTED )
153 aItem->ClearSelected();
154 else if( aMode == BRIGHTENED )
155 aItem->ClearBrightened();
156
157 if( aUsingOverlay && aMode != BRIGHTENED )
158 {
159 view()->Hide( aItem, false ); // Restore original item visibility...
160 view()->Update( aItem ); // ... and make sure it's redrawn un-selected
161 }
162
163 if( aItem->IsBOARD_ITEM() )
164 {
165 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
166 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, std::placeholders::_1,
167 aMode, aUsingOverlay ),
168 RECURSE_MODE::RECURSE );
169 }
170}
171
172
173void PCB_TEST_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
174{
175 if( aGroup )
176 aGroup->Add( aItem );
177
178 highlightInternal( aItem, aMode, aGroup != nullptr );
179 view()->Update( aItem, KIGFX::REPAINT );
180}
181
182
184{
185 if( aItem->IsSelected() )
186 return;
187
188 highlight( aItem, SELECTED, &m_selection );
189}
190
191
193{
194 unhighlight( aItem, SELECTED, &m_selection );
195}
196
198{
199 // Main loop: keep receiving events
200 while( TOOL_EVENT* evt = Wait() )
201 {
202 if( evt->IsClick( BUT_LEFT ) )
203 {
204 selectPoint( evt->Position() );
205 }
206 else if( evt->IsCancel() )
207 {
208 if( !GetSelection().Empty() )
209 {
211 }
212 }
213 else
214 {
215 evt->SetPassEvent();
216 }
217 }
218
219 // Shutting down; clear the selection
221 m_disambiguateTimer.Stop();
222
223 return 0;
224}
225
226void PCB_TEST_SELECTION_TOOL::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
227{
228 m_selectableTypes = aTypes;
229}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition: board_item.h:211
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:895
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:95
void ClearSelected()
Definition: eda_item.h:126
bool IsSelected() const
Definition: eda_item.h:116
void SetSelected()
Definition: eda_item.h:123
void ClearBrightened()
Definition: eda_item.h:127
void SetBrightened()
Definition: eda_item.h:124
static const TOOL_EVENT SelectedEvent
Definition: actions.h:296
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:319
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:458
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:464
void SetIgnoreFootprintsOnFront(bool ignore)
Definition: collectors.h:422
void SetIgnoreFPTextOnFront(bool ignore)
Definition: collectors.h:410
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:461
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:428
void SetIgnoreFPTextOnBack(bool ignore)
Definition: collectors.h:404
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:455
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:440
void SetIgnoreFPReferences(bool ignore)
Definition: collectors.h:452
void SetIgnoreFPValues(bool ignore)
Definition: collectors.h:446
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:434
void SetIgnoreFootprintsOnBack(bool ignore)
Definition: collectors.h:416
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:202
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition: collectors.h:222
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:482
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:91
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:57
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
bool IsBOARD_ITEM() const
Definition: view_item.h:102
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1621
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:635
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:63
void highlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup) override
Highlight the item visually.
void SetSelectableItemTypes(const std::vector< KICAD_T > aTypes)
void unhighlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup) override
Unhighlight the item visually.
std::function< void(PCB_TEST_FRAME_BASE *, PCB_SELECTION *)> m_selectionHook
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
bool selectPoint(const VECTOR2I &aWhere)
void highlightInternal(EDA_ITEM *aItem, int aMode, bool aUsingOverlay)
bool Init() override
Init() is called once upon a registration of the tool.
std::vector< KICAD_T > m_selectableTypes
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
void select(EDA_ITEM *aItem) override
Take necessary action mark an item as selected.
void unhighlightInternal(EDA_ITEM *aItem, int aMode, bool aUsingOverlay)
int Main(const TOOL_EVENT &aEvent)
PCB_TEST_FRAME_BASE * frame() const
void unselect(EDA_ITEM *aItem) override
Take necessary action mark an item as unselected.
KIGFX::PCB_VIEW * view() const
wxTimer m_disambiguateTimer
Timer to show the disambiguate menu.
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:42
void SetIsHover(bool aIsHover)
Definition: selection.h:79
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:60
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:100
EDA_ITEM * Front() const
Definition: selection.h:172
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:93
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:177
void ClearReferencePoint()
Definition: selection.cpp:184
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:38
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define BRIGHTENED
item is drawn with a bright contour
#define SELECTED
Item was manually selected by the user.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition: layer_ids.h:258
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition: layer_ids.h:265
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition: layer_ids.h:291
@ LAYER_TRACKS
Definition: layer_ids.h:266
@ LAYER_FP_TEXT
Definition: layer_ids.h:239
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition: layer_ids.h:259
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition: layer_ids.h:262
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:232
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:58
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:39
@ BUT_LEFT
Definition: tool_event.h:132