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{
10}
11
13{
14 view()->Remove( &m_selection );
15}
16
18{
19 view()->Remove( &m_selection );
20 view()->Add( &m_selection );
21
22 return true;
23}
24
26{
27}
28
29
31{
32 if( m_selection.Empty() )
33 return;
34
35 while( m_selection.GetSize() )
37
38 view()->Update( &m_selection );
39
40 m_selection.SetIsHover( false );
42}
43
44#include <collectors.h>
45
46
48{
49 GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
50 (PCB_LAYER_ID) view()->GetTopLayer(), view() );
51
52 bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
53
54 // account for the globals
55 guide.SetIgnoreFPTextOnBack( !board()->IsElementVisible( LAYER_FP_TEXT ) );
56 guide.SetIgnoreFPTextOnFront( !board()->IsElementVisible( LAYER_FP_TEXT ) );
57 guide.SetIgnoreFootprintsOnBack( !board()->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
58 guide.SetIgnoreFootprintsOnFront( !board()->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
59 guide.SetIgnorePadsOnBack( padsDisabled );
60 guide.SetIgnorePadsOnFront( padsDisabled );
61 guide.SetIgnoreThroughHolePads( padsDisabled );
62 guide.SetIgnoreFPValues( !board()->IsElementVisible( LAYER_FP_VALUES ) );
63 guide.SetIgnoreFPReferences( !board()->IsElementVisible( LAYER_FP_REFERENCES ) );
64 guide.SetIgnoreThroughVias( !board()->IsElementVisible( LAYER_VIAS ) );
65 guide.SetIgnoreBlindBuriedVias( !board()->IsElementVisible( LAYER_VIAS ) );
66 guide.SetIgnoreMicroVias( !board()->IsElementVisible( LAYER_VIAS ) );
67 guide.SetIgnoreTracks( !board()->IsElementVisible( LAYER_TRACKS ) );
68
69 return guide;
70}
71
73{
75 GENERAL_COLLECTOR collector;
76
77 for( auto item : m_selection.Items() )
78 {
80 }
81
84
85 if( m_selectableTypes.empty() )
86 collector.Collect( board(), GENERAL_COLLECTOR::AllBoardItems, aWhere, guide );
87 else
88 collector.Collect( board(), m_selectableTypes, aWhere, guide );
89
90 if( collector.GetCount() > 0 )
91 {
92 for( int i = 0; i < collector.GetCount(); ++i )
93 {
94 {
95 select( collector[i] );
96 }
97 }
98 }
99
101
102 if( m_selectionHook )
104
105 return false;
106}
107
108
110{
112}
113
114
115void PCB_TEST_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
116{
117 if( aMode == SELECTED )
118 aItem->SetSelected();
119 else if( aMode == BRIGHTENED )
120 aItem->SetBrightened();
121
122 if( aUsingOverlay && aMode != BRIGHTENED )
123 view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
124
125 if( aItem->IsBOARD_ITEM() )
126 {
127 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
128 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, std::placeholders::_1,
129 aMode, aUsingOverlay ),
130 RECURSE_MODE::RECURSE );
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 );
165 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, std::placeholders::_1,
166 aMode, aUsingOverlay ),
167 RECURSE_MODE::RECURSE );
168 }
169}
170
171
172void PCB_TEST_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
173{
174 if( aGroup )
175 aGroup->Add( aItem );
176
177 highlightInternal( aItem, aMode, aGroup != nullptr );
178 view()->Update( aItem, KIGFX::REPAINT );
179}
180
181
183{
184 if( aItem->IsSelected() )
185 return;
186
187 highlight( aItem, SELECTED, &m_selection );
188}
189
190
192{
193 unhighlight( aItem, SELECTED, &m_selection );
194}
195
197{
198 // Main loop: keep receiving events
199 while( TOOL_EVENT* evt = Wait() )
200 {
201 if( evt->IsClick( BUT_LEFT ) )
202 {
203 selectPoint( evt->Position() );
204 }
205 else if( evt->IsCancel() )
206 {
207 if( !GetSelection().Empty() )
208 {
210 }
211 }
212 else
213 {
214 evt->SetPassEvent();
215 }
216 }
217
218 // Shutting down; clear the selection
220 m_disambiguateTimer.Stop();
221
222 return 0;
223}
224
225void PCB_TEST_SELECTION_TOOL::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
226{
227 m_selectableTypes = aTypes;
228}
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: actions.h:211
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 RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition: board_item.h:208
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:892
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:97
void ClearSelected()
Definition: eda_item.h:136
bool IsSelected() const
Definition: eda_item.h:126
void SetSelected()
Definition: eda_item.h:133
void ClearBrightened()
Definition: eda_item.h:137
void SetBrightened()
Definition: eda_item.h:134
static const TOOL_EVENT SelectedEvent
Definition: actions.h:338
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:1623
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:635
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