KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 );
130 std::placeholders::_1, aMode, aUsingOverlay ) );
131 }
132}
133
134
136{
137 if( aGroup )
138 aGroup->Remove( aItem );
139
140 unhighlightInternal( aItem, aMode, aGroup != nullptr );
141 view()->Update( aItem, KIGFX::REPAINT );
142
143 // Many selections are very temporal and updating the display each time just creates noise.
144 if( aMode == BRIGHTENED )
146}
147
148
149void PCB_TEST_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
150{
151 if( aMode == SELECTED )
152 aItem->ClearSelected();
153 else if( aMode == BRIGHTENED )
154 aItem->ClearBrightened();
155
156 if( aUsingOverlay && aMode != BRIGHTENED )
157 {
158 view()->Hide( aItem, false ); // Restore original item visibility...
159 view()->Update( aItem ); // ... and make sure it's redrawn un-selected
160 }
161
162 if( aItem->IsBOARD_ITEM() )
163 {
164 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
166 std::placeholders::_1, aMode, aUsingOverlay ) );
167 }
168}
169
170
171void PCB_TEST_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
172{
173 if( aGroup )
174 aGroup->Add( aItem );
175
176 highlightInternal( aItem, aMode, aGroup != nullptr );
177 view()->Update( aItem, KIGFX::REPAINT );
178}
179
180
182{
183 if( aItem->IsSelected() )
184 return;
185
186 highlight( aItem, SELECTED, &m_selection );
187}
188
189
191{
192 unhighlight( aItem, SELECTED, &m_selection );
193}
194
196{
197 // Main loop: keep receiving events
198 while( TOOL_EVENT* evt = Wait() )
199 {
200 if( evt->IsClick( BUT_LEFT ) )
201 {
202 selectPoint( evt->Position() );
203 }
204 else if( evt->IsCancel() )
205 {
206 if( !GetSelection().Empty() )
207 {
209 }
210 }
211 else
212 {
213 evt->SetPassEvent();
214 }
215 }
216
217 // Shutting down; clear the selection
219 m_disambiguateTimer.Stop();
220
221 return 0;
222}
223
224void PCB_TEST_SELECTION_TOOL::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
225{
226 m_selectableTypes = aTypes;
227}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction, int aDepth=0) const
Invoke a function on all descendants.
Definition: board_item.h:212
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:841
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
void ClearSelected()
Definition: eda_item.h:122
bool IsSelected() const
Definition: eda_item.h:110
void SetSelected()
Definition: eda_item.h:119
void ClearBrightened()
Definition: eda_item.h:123
void SetBrightened()
Definition: eda_item.h:120
static const TOOL_EVENT SelectedEvent
Definition: actions.h:292
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:100
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1635
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:625
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:62
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
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:186
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
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:209
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:212
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored)
Definition: layer_ids.h:231
@ LAYER_TRACKS
Definition: layer_ids.h:213
@ LAYER_FP_TEXT
Definition: layer_ids.h:199
@ LAYER_FOOTPRINTS_BK
show footprints on back
Definition: layer_ids.h:210
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:211
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:194
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
@ BUT_LEFT
Definition: tool_event.h:131