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
16
18{
19 view()->Remove( &m_selection );
20 view()->Add( &m_selection );
21
22 return true;
23}
24
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 );
41 m_selection.ClearReferencePoint();
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
82 m_selection.Clear();
83 m_selection.ClearReferencePoint();
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
100 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
101
102 if( m_selectionHook )
104
105 getView()->SetVisible( &m_selection, true );
106
107 return false;
108}
109
110
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( aItem->IsBOARD_ITEM() )
128 {
129 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
130 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, std::placeholders::_1,
131 aMode, aUsingOverlay ),
133 }
134}
135
136
138{
139 if( aGroup )
140 aGroup->Remove( aItem );
141
142 unhighlightInternal( aItem, aMode, aGroup != nullptr );
143 view()->Update( aItem, KIGFX::REPAINT );
144
145 // Many selections are very temporal and updating the display each time just creates noise.
146 if( aMode == BRIGHTENED )
148}
149
150
151void PCB_TEST_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
152{
153 if( aMode == SELECTED )
154 aItem->ClearSelected();
155 else if( aMode == BRIGHTENED )
156 aItem->ClearBrightened();
157
158 if( aUsingOverlay && aMode != BRIGHTENED )
159 {
160 view()->Hide( aItem, false ); // Restore original item visibility...
161 view()->Update( aItem ); // ... and make sure it's redrawn un-selected
162 }
163
164 if( aItem->IsBOARD_ITEM() )
165 {
166 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
167 boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, std::placeholders::_1,
168 aMode, aUsingOverlay ),
170 }
171}
172
173
174void PCB_TEST_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
175{
176 if( aGroup )
177 aGroup->Add( aItem );
178
179 highlightInternal( aItem, aMode, aGroup != nullptr );
180 view()->Update( aItem, KIGFX::REPAINT );
181}
182
183
188
189
194
196{
197 // Main loop: keep receiving events
198 while( TOOL_EVENT* evt = Wait() )
199 {
201 m_customEventHandler( this, *evt, m_selection );
202
203 if( evt->IsClick( BUT_LEFT ) )
204 {
205 selectPoint( evt->Position() );
206 }
207 else if( evt->IsCancel() )
208 {
209 if( !GetSelection().Empty() )
210 {
212 }
213 }
214 else
215 {
216 evt->SetPassEvent();
217 }
218 }
219
220 // Shutting down; clear the selection
221 m_selection.Clear();
222 m_disambiguateTimer.Stop();
223
224 return 0;
225}
226
227void PCB_TEST_SELECTION_TOOL::SetSelectableItemTypes( const std::vector<KICAD_T> aTypes )
228{
229 m_selectableTypes = aTypes;
230}
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition actions.h:210
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition board_item.h:264
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition board.cpp:1250
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
void ClearSelected()
Definition eda_item.h:153
void SetSelected()
Definition eda_item.h:150
void ClearBrightened()
Definition eda_item.h:154
void SetBrightened()
Definition eda_item.h:151
static const TOOL_EVENT SelectedEvent
Definition actions.h:343
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
void SetIgnoreBlindBuriedVias(bool ignore)
Definition collectors.h:460
void SetIgnoreTracks(bool ignore)
Definition collectors.h:466
void SetIgnoreFootprintsOnFront(bool ignore)
Definition collectors.h:424
void SetIgnoreFPTextOnFront(bool ignore)
Definition collectors.h:412
void SetIgnoreMicroVias(bool ignore)
Definition collectors.h:463
void SetIgnorePadsOnBack(bool ignore)
Definition collectors.h:430
void SetIgnoreFPTextOnBack(bool ignore)
Definition collectors.h:406
void SetIgnoreThroughVias(bool ignore)
Definition collectors.h:457
void SetIgnoreThroughHolePads(bool ignore)
Definition collectors.h:442
void SetIgnoreFPReferences(bool ignore)
Definition collectors.h:454
void SetIgnoreFPValues(bool ignore)
Definition collectors.h:448
void SetIgnorePadsOnFront(bool ignore)
Definition collectors.h:436
void SetIgnoreFootprintsOnBack(bool ignore)
Definition collectors.h:418
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition collectors.h:38
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.
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:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
bool IsBOARD_ITEM() const
Definition view_item.h:98
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:1797
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:659
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition view.cpp:1773
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.
SELECTION_TOOL(const std::string &aName)
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
Definition selection.cpp:38
virtual void Remove(EDA_ITEM *aItem)
Definition selection.cpp:60
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:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
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.
@ RECURSE
Definition eda_item.h:51
#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:255
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:35
@ BUT_LEFT
Definition tool_event.h:128
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683