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 onSpecifiedValuesUpdateUi( wxUpdateUIEvent& event ) override;
77 void OnSizeNetclassGrid( wxSizeEvent& event ) override;
78
79 void OnNetclassFilterSelect( wxCommandEvent& event ) override
80 {
81 m_netclassFilterOpt->SetValue( true );
82 }
83 void OnLayerFilterSelect( wxCommandEvent& event ) override
84 {
85 m_layerFilterOpt->SetValue( true );
86 }
87 void OnTrackWidthText( wxCommandEvent& aEvent ) override
88 {
89 m_filterByTrackWidth->SetValue( true );
90 }
91 void OnViaSizeText( wxCommandEvent& aEvent ) override
92 {
93 m_filterByViaSize->SetValue( true );
94 }
95
96 void onUnitsChanged( wxCommandEvent& aEvent );
97
98private:
99 void visitItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
100 void processItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
101
102 bool TransferDataToWindow() override;
103 bool TransferDataFromWindow() override;
104
105 void AdjustNetclassGridColumns( int aWidth );
106
107 void OnNetFilterSelect( wxCommandEvent& event )
108 {
109 m_netFilterOpt->SetValue( true );
110 }
111
112 void buildNetclassesGrid();
113 void buildFilterLists();
114
115private:
120
123
124 std::vector<BOARD_ITEM*> m_items_changed; // a list of modified items
125};
126
127
130 m_trackWidthFilter( aParent, nullptr, m_trackWidthFilterCtrl, m_trackWidthFilterUnits ),
131 m_viaSizeFilter( aParent, nullptr, m_viaSizeFilterCtrl, m_viaSizeFilterUnits )
132{
133 m_parent = aParent;
135
136 m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
137
138 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
139 m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
140
142
147
153
154 m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
156
157 m_netclassGrid->SetCellHighlightPenWidth( 0 );
158
160
161 m_netFilter->Connect( NET_SELECTED,
163 nullptr, this );
164
166 this );
167
169}
170
171
173{
174 g_modifyTracks = m_tracks->GetValue();
175 g_modifyVias = m_vias->GetValue();
177 g_netclassFilter = m_netclassFilter->GetStringSelection();
178 g_filterByNet = m_netFilterOpt->GetValue();
180 g_filterByLayer = m_layerFilterOpt->GetValue();
187
188 m_netFilter->Disconnect( NET_SELECTED,
190 nullptr, this );
191
192 m_parent->Unbind( EDA_EVT_UNITS_CHANGED,
194
195 delete[] m_originalColWidths;
196}
197
198
200{
201 int trackSel = m_trackWidthSelectBox->GetSelection();
202 int viaSel = m_viaSizesSelectBox->GetSelection();
203
208
209 m_trackWidthSelectBox->SetSelection( trackSel );
210 m_viaSizesSelectBox->SetSelection( viaSel );
211
212 m_netclassGrid->ClearGrid();
214
215 aEvent.Skip();
216}
217
218
220{
221 // Populate the net filter list with net names
224
225 if( !m_brd->GetHighLightNetCodes().empty() )
227
228 // Populate the netclass filter list with netclass names
229 wxArrayString netclassNames;
230 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
231
232 netclassNames.push_back( settings->m_DefaultNetClass->GetName() );
233
234 for( const auto& [ name, netclass ] : settings->m_NetClasses )
235 netclassNames.push_back( name );
236
237 m_netclassFilter->Set( netclassNames );
239
240 // Populate the layer filter list
246}
247
248
250{
251 int row = 0;
252
253 m_netclassGrid->SetCellValue( row, GRID_TRACKSIZE, _( "Track Width" ) );
254 m_netclassGrid->SetCellValue( row, GRID_VIASIZE, _( "Via Diameter" ) );
255 m_netclassGrid->SetCellValue( row, GRID_VIADRILL, _( "Via Hole" ) );
256 m_netclassGrid->SetCellValue( row, GRID_uVIASIZE, _( "uVia Diameter" ) );
257 m_netclassGrid->SetCellValue( row, GRID_uVIADRILL, _( "uVia Hole" ) );
258 row++;
259
260 auto setNetclassValue =
261 [this]( int aRow, int aCol, int aVal )
262 {
263 m_netclassGrid->SetCellValue( aRow, aCol, m_parent->StringFromValue( aVal, true ) );
264 };
265
266 auto buildRow =
267 [this, &setNetclassValue]( int aRow, const std::shared_ptr<NETCLASS>& aNc )
268 {
269 m_netclassGrid->SetCellValue( aRow, GRID_NAME, aNc->GetName() );
270 setNetclassValue( aRow, GRID_TRACKSIZE, aNc->GetTrackWidth() );
271 setNetclassValue( aRow, GRID_VIASIZE, aNc->GetViaDiameter() );
272 setNetclassValue( aRow, GRID_VIADRILL, aNc->GetViaDrill() );
273 setNetclassValue( aRow, GRID_uVIASIZE, aNc->GetuViaDiameter() );
274 setNetclassValue( aRow, GRID_uVIADRILL, aNc->GetuViaDrill() );
275 };
276
277 const std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
278
279 m_netclassGrid->AppendRows( 1 );
280 buildRow( row++, settings->m_DefaultNetClass );
281
282 m_netclassGrid->AppendRows( (int) settings->m_NetClasses.size() );
283
284 for( const auto& [ name, netclass ] : settings->m_NetClasses )
285 buildRow( row++, netclass );
286}
287
288
290{
292 m_selection = selTool->GetSelection();
294
295 m_tracks->SetValue( g_modifyTracks );
296 m_vias->SetValue( g_modifyVias );
297
298 if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
299 m_netclassFilterOpt->SetValue( true );
300 else if( item )
301 m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClass()->GetName() );
302
303 if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
304 {
306 m_netFilterOpt->SetValue( true );
307 }
308 else if( item )
309 {
311 }
312
314 {
315 m_layerFilterOpt->SetValue( true );
316 }
317 else if( item )
318 {
319 if( item->Type() == PCB_ZONE_T ) // a zone can be on more than one layer
320 m_layerFilter->SetLayerSelection( static_cast<ZONE*>(item)->GetFirstLayer() );
321 else
323 }
324
326 {
327 m_filterByTrackWidth->SetValue( true );
329 }
330
332 {
333 m_filterByViaSize->SetValue( true );
335 }
336
337 m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
338 m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
339 m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
340
342
343 return true;
344}
345
346
348{
349 // Enable the items in the use specified values section
350 event.Enable( m_setToSpecifiedValues->GetValue() );
351}
352
353
355 PCB_TRACK* aItem )
356{
358 bool isTrack = aItem->Type() == PCB_TRACE_T;
359 bool isArc = aItem->Type() == PCB_ARC_T;
360 bool isVia = aItem->Type() == PCB_VIA_T;
361
362 if( m_setToSpecifiedValues->GetValue() )
363 {
364 if( ( isArc || isTrack )
365 && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
366 {
367 unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
368 int trackWidthIndex = m_trackWidthSelectBox->GetSelection();
369
370 if( trackWidthIndex >= 0 )
371 brdSettings.SetTrackWidthIndex( static_cast<unsigned>( trackWidthIndex ) );
372
373 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
374
375 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
376 }
377 else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
378 {
379 unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
380 int viaSizeIndex = m_viaSizesSelectBox->GetSelection();
381
382 if( viaSizeIndex >= 0 )
383 brdSettings.SetViaSizeIndex( static_cast<unsigned>( viaSizeIndex ) );
384
385 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
386
387 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
388 }
389
390 if( ( isArc || isTrack ) && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
391 {
392 if( aUndoList->FindItem( aItem ) < 0 )
393 {
394 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
395 picker.SetLink( aItem->Clone() );
396 aUndoList->PushItem( picker );
397 }
398
400 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
401 }
402 }
403 else
404 {
405 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
406 }
407
408 m_items_changed.push_back( aItem );
409}
410
411
413{
414 if( m_selectedItemsFilter->GetValue() )
415 {
416 if( !aItem->IsSelected() )
417 {
418 PCB_GROUP* group = aItem->GetParentGroup();
419
420 while( group && !group->IsSelected() )
421 group = group->GetParentGroup();
422
423 if( !group )
424 return;
425 }
426 }
427
428 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
429 {
430 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
431 return;
432 }
433
434 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
435 {
436 if( aItem->GetEffectiveNetClass()->GetName() != m_netclassFilter->GetStringSelection() )
437 return;
438 }
439
441 {
442 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
443 return;
444 }
445
446 if( aItem->Type() == PCB_VIA_T )
447 {
448 if( m_filterByViaSize->GetValue() && aItem->GetWidth() != m_viaSizeFilter.GetValue() )
449 return;
450 }
451 else
452 {
453 if( m_filterByTrackWidth->GetValue() && aItem->GetWidth() != m_trackWidthFilter.GetValue() )
454 return;
455 }
456
457 processItem( aUndoList, aItem );
458}
459
460
462{
463 PICKED_ITEMS_LIST itemsListPicker;
464 wxBusyCursor dummy;
465
466 // Examine segments
467 for( PCB_TRACK* track : m_brd->Tracks() )
468 {
469 if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
470 visitItem( &itemsListPicker, track );
471 else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
472 visitItem( &itemsListPicker, track );
473 else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
474 visitItem( &itemsListPicker, track );
475 }
476
477 if( itemsListPicker.GetCount() > 0 )
478 {
479 m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
480
481 for( PCB_TRACK* track : m_brd->Tracks() )
482 m_parent->GetCanvas()->GetView()->Update( track );
483 }
484
486
487 if( m_items_changed.size() )
488 {
491 }
492
493 return true;
494}
495
496
498{
499 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
500 {
501 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
502 aWidth -= m_originalColWidths[ i ];
503 }
504
505 m_netclassGrid->SetColSize( 0, std::max( 72, aWidth ) );
506}
507
508
510{
511 AdjustNetclassGridColumns( event.GetSize().GetX() );
512 event.Skip();
513}
514
515
517{
518 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
519 DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
520
521 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
522 return 0;
523}
524
const char * name
Definition: DXF_plotter.cpp:56
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:196
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:85
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:230
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:800
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:484
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1533
TRACKS & Tracks()
Definition: board.h:309
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:728
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:2133
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:432
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
void OnTrackWidthText(wxCommandEvent &aEvent) override
void OnLayerFilterSelect(wxCommandEvent &event) override
void onSpecifiedValuesUpdateUi(wxUpdateUIEvent &event) override
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
void OnViaSizeText(wxCommandEvent &aEvent) override
void OnNetclassFilterSelect(wxCommandEvent &event) override
void OnSizeNetclassGrid(wxSizeEvent &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:97
bool IsSelected() const
Definition: eda_item.h:106
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:92
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:794
const wxString GetName() const
Definition: netclass.h:65
NETCLASS * GetNetClass()
Definition: netinfo.h:112
void SetBoard(BOARD *aBoard)
int GetSelectedNetcode()
void SetSelectedNetcode(int aNetcode)
void SetNetInfo(NETINFO_LIST *aNetInfoList)
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:282
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 SetTrackSegmentWidth(PCB_TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aEdit=true)
void OnModify() override
Must be called after a board change to set the modified flag.
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aEdit=true)
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:107
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:61
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:208
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
Generic, UI-independent tool event.
Definition: tool_event.h:156
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aValue in internal units into a united string.
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:254
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
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
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:93
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:103
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:94
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:92
#define INDETERMINATE_ACTION
Definition: ui_common.h:43