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.SetIgnoreMTextsMarkedNoShow( !board()->IsElementVisible( LAYER_HIDDEN_TEXT ) );
57 guide.SetIgnoreMTextsOnBack( !board()->IsElementVisible( LAYER_FP_TEXT ) );
58 guide.SetIgnoreMTextsOnFront( !board()->IsElementVisible( LAYER_FP_TEXT ) );
59 guide.SetIgnoreModulesOnBack( !board()->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
60 guide.SetIgnoreModulesOnFront( !board()->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
61 guide.SetIgnorePadsOnBack( padsDisabled || !board()->IsElementVisible( LAYER_PADS_SMD_BK ) );
62 guide.SetIgnorePadsOnFront( padsDisabled || !board()->IsElementVisible( LAYER_PADS_SMD_FR ) );
63 guide.SetIgnoreThroughHolePads( padsDisabled || !board()->IsElementVisible( LAYER_PADS_TH ) );
64 guide.SetIgnoreModulesVals( !board()->IsElementVisible( LAYER_FP_VALUES ) );
65 guide.SetIgnoreModulesRefs( !board()->IsElementVisible( LAYER_FP_REFERENCES ) );
66 guide.SetIgnoreThroughVias( !board()->IsElementVisible( LAYER_VIAS ) );
67 guide.SetIgnoreBlindBuriedVias( !board()->IsElementVisible( LAYER_VIAS ) );
68 guide.SetIgnoreMicroVias( !board()->IsElementVisible( LAYER_VIAS ) );
69 guide.SetIgnoreTracks( !board()->IsElementVisible( LAYER_TRACKS ) );
70
71 return guide;
72}
73
75{
77 GENERAL_COLLECTOR collector;
78
79 for( auto item : m_selection.Items() )
80 {
82 }
83
86
87 if( m_selectableTypes.empty() )
88 collector.Collect( board(), GENERAL_COLLECTOR::AllBoardItems, aWhere, guide );
89 else
90 collector.Collect( board(), m_selectableTypes, aWhere, guide );
91
92 if( collector.GetCount() > 0 )
93 {
94 for( int i = 0; i < collector.GetCount(); ++i )
95 {
96 {
97 select( collector[i] );
98 }
99 }
100 }
101
103
104 if( m_selectionHook )
106
107 return false;
108}
109
110
112{
114}
115
116
117void PCB_TEST_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
118{
119 if( aMode == SELECTED )
120 aItem->SetSelected();
121 else if( aMode == BRIGHTENED )
122 aItem->SetBrightened();
123
124 if( aUsingOverlay && aMode != BRIGHTENED )
125 view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
126
127 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
128 {
129 boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this,
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( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
163 {
164 boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this,
165 std::placeholders::_1, aMode, aUsingOverlay ) );
166 }
167}
168
169
170void PCB_TEST_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
171{
172 if( aGroup )
173 aGroup->Add( aItem );
174
175 highlightInternal( aItem, aMode, aGroup != nullptr );
176 view()->Update( aItem, KIGFX::REPAINT );
177}
178
179
181{
182 if( aItem->IsSelected() )
183 return;
184
185 highlight( aItem, SELECTED, &m_selection );
186}
187
188
190{
191 unhighlight( aItem, SELECTED, &m_selection );
192}
193
195{
196 // Main loop: keep receiving events
197 while( TOOL_EVENT* evt = Wait() )
198 {
199 if( evt->IsClick( BUT_LEFT ) )
200 {
201 selectPoint( evt->Position() );
202 }
203 else if( evt->IsCancel() )
204 {
205 if( !GetSelection().Empty() )
206 {
208 }
209 }
210 else
211 {
212 evt->SetPassEvent();
213 }
214 }
215
216 // Shutting down; clear the selection
218 m_disambiguateTimer.Stop();
219
220 return 0;
221}
222
223void PCB_TEST_SELECTION_TOOL::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
224{
225 m_selectableTypes = aTypes;
226}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:746
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:88
void ClearSelected()
Definition: eda_item.h:121
bool IsSelected() const
Definition: eda_item.h:109
void SetSelected()
Definition: eda_item.h:118
void ClearBrightened()
Definition: eda_item.h:122
void SetBrightened()
Definition: eda_item.h:119
static const TOOL_EVENT SelectedEvent
Definition: actions.h:260
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:323
void SetIgnoreBlindBuriedVias(bool ignore)
Definition: collectors.h:469
void SetIgnoreTracks(bool ignore)
Definition: collectors.h:475
void SetIgnoreMTextsMarkedNoShow(bool ignore)
Definition: collectors.h:409
void SetIgnoreModulesOnFront(bool ignore)
Definition: collectors.h:433
void SetIgnoreModulesRefs(bool ignore)
Definition: collectors.h:463
void SetIgnoreMicroVias(bool ignore)
Definition: collectors.h:472
void SetIgnorePadsOnBack(bool ignore)
Definition: collectors.h:439
void SetIgnoreModulesOnBack(bool ignore)
Definition: collectors.h:427
void SetIgnoreModulesVals(bool ignore)
Definition: collectors.h:457
void SetIgnoreThroughVias(bool ignore)
Definition: collectors.h:466
void SetIgnoreThroughHolePads(bool ignore)
Definition: collectors.h:451
void SetIgnoreMTextsOnFront(bool ignore)
Definition: collectors.h:421
void SetIgnoreMTextsOnBack(bool ignore)
Definition: collectors.h:415
void SetIgnorePadsOnFront(bool ignore)
Definition: collectors.h:445
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:206
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition: collectors.h:226
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:481
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:75
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:66
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1579
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:619
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:78
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:99
EDA_ITEM * Front() const
Definition: selection.h:208
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:92
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:213
void ClearReferencePoint()
Definition: selection.cpp:185
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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:212
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:215
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored)
Definition: layer_ids.h:234
@ LAYER_HIDDEN_TEXT
text marked as invisible
Definition: layer_ids.h:204
@ LAYER_TRACKS
Definition: layer_ids.h:216
@ LAYER_FP_TEXT
Definition: layer_ids.h:202
@ LAYER_FOOTPRINTS_BK
show footprints on back
Definition: layer_ids.h:213
@ LAYER_PADS_SMD_BK
smd pads, back layer
Definition: layer_ids.h:207
@ LAYER_PADS_TH
multilayer pads, usually with holes
Definition: layer_ids.h:217
@ LAYER_PADS_SMD_FR
smd pads, front layer
Definition: layer_ids.h:206
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:214
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:197
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