KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_global_edit_tracks_and_vias.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2009-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <pcb_edit_frame.h>
26#include <widgets/unit_binder.h>
27#include <board.h>
29#include <pcb_track.h>
30#include <pcb_group.h>
33#include <tool/tool_manager.h>
37
38
39// Columns of netclasses grid
40enum {
47 GRID_DIFF_PAIR_WIDTH, // not currently included in grid
48 GRID_DIFF_PAIR_GAP, // not currently included in grid
49 GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
50};
51
52
53// Globals to remember control settings during a session
54static bool g_modifyTracks = true;
55static bool g_modifyVias = true;
57static wxString g_netclassFilter;
58static bool g_filterByNet;
59static wxString g_netFilter;
60static bool g_filterByLayer;
61static int g_layerFilter;
62static bool g_filterByTrackWidth = false;
63static int g_trackWidthFilter = 0;
64static bool g_filterByViaSize = false;
65static int g_viaSizeFilter = 0;
66static bool g_filterSelected = false;
67
68
70{
71public:
74
75protected:
76 void onActionButtonChange( wxCommandEvent& event ) override;
77
78 void OnNetclassFilterSelect( wxCommandEvent& event ) override
79 {
80 m_netclassFilterOpt->SetValue( true );
81 }
82 void OnLayerFilterSelect( wxCommandEvent& event ) override
83 {
84 m_layerFilterOpt->SetValue( true );
85 }
86 void OnTrackWidthText( wxCommandEvent& aEvent ) override
87 {
88 m_filterByTrackWidth->SetValue( true );
89 }
90 void OnViaSizeText( wxCommandEvent& aEvent ) override
91 {
92 m_filterByViaSize->SetValue( true );
93 }
94
95 void onUnitsChanged( wxCommandEvent& aEvent );
96
97private:
98 void visitItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
99 void processItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
100
101 bool TransferDataToWindow() override;
102 bool TransferDataFromWindow() override;
103
104 void OnNetFilterSelect( wxCommandEvent& event )
105 {
106 m_netFilterOpt->SetValue( true );
107 }
108
109 void buildFilterLists();
110
111private:
115
118
119 std::vector<BOARD_ITEM*> m_items_changed; // a list of modified items
120};
121
122
125 m_trackWidthFilter( aParent, nullptr, m_trackWidthFilterCtrl, m_trackWidthFilterUnits ),
126 m_viaSizeFilter( aParent, nullptr, m_viaSizeFilterCtrl, m_viaSizeFilterUnits )
127{
128 m_parent = aParent;
130
132
137
143
145
146 m_netFilter->Connect( NET_SELECTED,
148 nullptr, this );
149
151 this );
152
154}
155
156
158{
159 g_modifyTracks = m_tracks->GetValue();
160 g_modifyVias = m_vias->GetValue();
162 g_netclassFilter = m_netclassFilter->GetStringSelection();
163 g_filterByNet = m_netFilterOpt->GetValue();
165 g_filterByLayer = m_layerFilterOpt->GetValue();
172
173 m_netFilter->Disconnect( NET_SELECTED,
175 nullptr, this );
176
177 m_parent->Unbind( EDA_EVT_UNITS_CHANGED,
179}
180
181
183{
184 int trackSel = m_trackWidthCtrl->GetSelection();
185 int viaSel = m_viaSizesCtrl->GetSelection();
186
191
192 m_trackWidthCtrl->SetSelection( trackSel );
193 m_viaSizesCtrl->SetSelection( viaSel );
194
195 aEvent.Skip();
196}
197
198
200{
201 // Populate the net filter list with net names
204
205 if( !m_brd->GetHighLightNetCodes().empty() )
207
208 // Populate the netclass filter list with netclass names
209 wxArrayString netclassNames;
210 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
211
212 netclassNames.push_back( settings->m_DefaultNetClass->GetName() );
213
214 for( const auto& [ name, netclass ] : settings->m_NetClasses )
215 netclassNames.push_back( name );
216
217 m_netclassFilter->Set( netclassNames );
219
220 // Populate the layer filter list
226}
227
228
230{
232 m_selection = selTool->GetSelection();
234
235 m_tracks->SetValue( g_modifyTracks );
236 m_vias->SetValue( g_modifyVias );
237
238 if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
239 m_netclassFilterOpt->SetValue( true );
240 else if( item )
241 m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClass()->GetName() );
242
243 if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
244 {
246 m_netFilterOpt->SetValue( true );
247 }
248 else if( item )
249 {
251 }
252
254 {
255 m_layerFilterOpt->SetValue( true );
256 }
257 else if( item )
258 {
259 if( item->Type() == PCB_ZONE_T ) // a zone can be on more than one layer
260 m_layerFilter->SetLayerSelection( static_cast<ZONE*>(item)->GetFirstLayer() );
261 else
263 }
264
266 {
267 m_filterByTrackWidth->SetValue( true );
269 }
270
272 {
273 m_filterByViaSize->SetValue( true );
275 }
276
277 m_trackWidthCtrl->SetSelection( (int) m_trackWidthCtrl->GetCount() - 1 );
278 m_viaSizesCtrl->SetSelection( (int) m_viaSizesCtrl->GetCount() - 1 );
279 m_layerCtrl->SetStringSelection( INDETERMINATE_ACTION );
280
282
283 wxCommandEvent dummy;
285
286 return true;
287}
288
289
291{
292 // Enable the items in the use specified values section
293 bool enable = m_setToSpecifiedValues->GetValue();
294
295 m_trackWidthLabel->Enable( enable );
296 m_trackWidthCtrl->Enable( enable );
297 m_viaSizeLabel->Enable( enable );
298 m_viaSizesCtrl->Enable( enable );
299 m_layerLabel->Enable( enable );
300 m_layerCtrl->Enable( enable );
301}
302
303
305 PCB_TRACK* aItem )
306{
308 bool isTrack = aItem->Type() == PCB_TRACE_T;
309 bool isArc = aItem->Type() == PCB_ARC_T;
310 bool isVia = aItem->Type() == PCB_VIA_T;
311
312 if( m_setToSpecifiedValues->GetValue() )
313 {
314 if( ( isArc || isTrack ) && m_trackWidthCtrl->GetStringSelection() != INDETERMINATE_ACTION )
315 {
316 unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
317 int trackWidthIndex = m_trackWidthCtrl->GetSelection();
318
319 if( trackWidthIndex >= 0 )
320 brdSettings.SetTrackWidthIndex( static_cast<unsigned>( trackWidthIndex + 1 ) );
321
322 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
323
324 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
325 }
326 else if( isVia && m_viaSizesCtrl->GetStringSelection() != INDETERMINATE_ACTION )
327 {
328 unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
329 int viaSizeIndex = m_viaSizesCtrl->GetSelection();
330
331 if( viaSizeIndex >= 0 )
332 brdSettings.SetViaSizeIndex( static_cast<unsigned>( viaSizeIndex + 1 ) );
333
334 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
335
336 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
337 }
338
339 if( ( isArc || isTrack ) && m_layerCtrl->GetLayerSelection() != UNDEFINED_LAYER )
340 {
341 if( aUndoList->FindItem( aItem ) < 0 )
342 {
343 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
344 picker.SetLink( aItem->Clone() );
345 aUndoList->PushItem( picker );
346 }
347
349 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
350 }
351 }
352 else
353 {
354 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
355 }
356
357 m_items_changed.push_back( aItem );
358}
359
360
362{
363 if( m_selectedItemsFilter->GetValue() )
364 {
365 if( !aItem->IsSelected() )
366 {
367 PCB_GROUP* group = aItem->GetParentGroup();
368
369 while( group && !group->IsSelected() )
370 group = group->GetParentGroup();
371
372 if( !group )
373 return;
374 }
375 }
376
377 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
378 {
379 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
380 return;
381 }
382
383 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
384 {
385 if( aItem->GetEffectiveNetClass()->GetName() != m_netclassFilter->GetStringSelection() )
386 return;
387 }
388
390 {
391 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
392 return;
393 }
394
395 if( aItem->Type() == PCB_VIA_T )
396 {
397 if( m_filterByViaSize->GetValue() && aItem->GetWidth() != m_viaSizeFilter.GetValue() )
398 return;
399 }
400 else
401 {
402 if( m_filterByTrackWidth->GetValue() && aItem->GetWidth() != m_trackWidthFilter.GetValue() )
403 return;
404 }
405
406 processItem( aUndoList, aItem );
407}
408
409
411{
412 PICKED_ITEMS_LIST itemsListPicker;
413 wxBusyCursor dummy;
414
415 // Examine segments
416 for( PCB_TRACK* track : m_brd->Tracks() )
417 {
418 if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
419 visitItem( &itemsListPicker, track );
420 else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
421 visitItem( &itemsListPicker, track );
422 else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
423 visitItem( &itemsListPicker, track );
424 }
425
426 if( itemsListPicker.GetCount() > 0 )
427 {
428 m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
429
430 for( PCB_TRACK* track : m_brd->Tracks() )
431 m_parent->GetCanvas()->GetView()->Update( track );
432 }
433
435
436 if( m_items_changed.size() )
437 {
440 }
441
442 return true;
443}
444
445
447{
448 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
449 DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
450
451 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
452 return 0;
453}
454
const char * name
Definition: DXF_plotter.cpp:57
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
const wxString & GetCurrentNetClassName() const
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
unsigned GetTrackWidthIndex() const
unsigned GetViaSizeIndex() const
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:231
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:91
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:265
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:853
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:517
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1803
const TRACKS & Tracks() const
Definition: board.h:321
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
void OnItemsChanged(std::vector< BOARD_ITEM * > &aItems)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition: board.cpp:2523
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:460
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
void OnTrackWidthText(wxCommandEvent &aEvent) override
void OnLayerFilterSelect(wxCommandEvent &event) override
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
void OnViaSizeText(wxCommandEvent &aEvent) override
void OnNetclassFilterSelect(wxCommandEvent &event) override
void onActionButtonChange(wxCommandEvent &event) override
void processItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowQuasiModal()
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void ForceRefresh()
Force a redraw.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
bool IsSelected() const
Definition: eda_item.h:109
int EditTracksAndVias(const TOOL_EVENT &aEvent)
void SetLink(EDA_ITEM *aItem)
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
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:884
const wxString GetName() const
Definition: netclass.h:62
NETCLASS * GetNetClass()
Definition: netinfo.h:101
void SetNetInfo(const NETINFO_LIST *aNetInfoList)
void SetBoard(BOARD *aBoard)
int GetSelectedNetcode()
void SetSelectedNetcode(int aNetcode)
void SetSelectedNet(const wxString &aNetname)
wxString GetSelectedNetname()
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
Definition: undo_redo.cpp:162
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aShowNetclass, bool aShowEdit)
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aShowNetclass, bool aShowEdit)
void SetTrackSegmentWidth(PCB_TRACK *aItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseDesignRules)
Modify one track segment width or one via diameter (using DRC control).
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetNotAllowedLayerSet(LSET aMask)
void SetUndefinedLayerName(const wxString &aName)
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
int GetWidth() const
Definition: pcb_track.h:108
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:64
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
int FindItem(const EDA_ITEM *aItem) const
unsigned GetCount() const
EDA_ITEM * Front() const
Definition: selection.h:172
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Generic, UI-independent tool event.
Definition: tool_event.h:167
int GetIntValue()
Definition: unit_binder.h:127
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:246
static bool g_filterByNet
static wxString g_netclassFilter
static bool g_filterByNetclass
static int g_layerFilter
static int g_trackWidthFilter
static bool g_filterSelected
static int g_viaSizeFilter
static bool g_filterByViaSize
static wxString g_netFilter
static bool g_modifyVias
static bool g_modifyTracks
static bool g_filterByTrackWidth
static bool g_filterByLayer
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:1022
Class to handle a set of BOARD_ITEMs.
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:107
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
#define INDETERMINATE_ACTION
Definition: ui_common.h:47