KiCad PCB EDA Suite
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-2022 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 <board.h>
28#include <pcb_track.h>
29#include <pcb_group.h>
32#include <tool/tool_manager.h>
36
37
38// Columns of netclasses grid
39enum {
46 GRID_DIFF_PAIR_WIDTH, // not currently included in grid
47 GRID_DIFF_PAIR_GAP, // not currently included in grid
48 GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
49};
50
51
52// Globals to remember control settings during a session
53static bool g_modifyTracks = true;
54static bool g_modifyVias = true;
56static wxString g_netclassFilter;
57static bool g_filterByNet;
58static wxString g_netFilter;
59static bool g_filterByLayer;
60static int g_layerFilter;
61static bool g_filterSelected = false;
62
63
65{
66private:
71 std::vector<BOARD_ITEM*> m_items_changed; // a list of modified items
72
73public:
76
77protected:
78 void onSpecifiedValuesUpdateUi( wxUpdateUIEvent& event ) override;
79 void OnSizeNetclassGrid( wxSizeEvent& event ) override;
80
81 void OnNetclassFilterSelect( wxCommandEvent& event ) override
82 {
83 m_netclassFilterOpt->SetValue( true );
84 }
85 void OnLayerFilterSelect( wxCommandEvent& event ) override
86 {
87 m_layerFilterOpt->SetValue( true );
88 }
89
90 void onUnitsChanged( wxCommandEvent& aEvent );
91
92private:
93 void visitItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
94 void processItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
95
96 bool TransferDataToWindow() override;
97 bool TransferDataFromWindow() override;
98
99 void AdjustNetclassGridColumns( int aWidth );
100
101 void OnNetFilterSelect( wxCommandEvent& event )
102 {
103 m_netFilterOpt->SetValue( true );
104 }
105
106 void buildNetclassesGrid();
107 void buildFilterLists();
108};
109
110
113{
114 m_parent = aParent;
116
117 m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
118
119 for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
120 m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
121
123
128
134
135 m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
137
138 m_netclassGrid->SetCellHighlightPenWidth( 0 );
139
141
142 m_netFilter->Connect( NET_SELECTED,
144 nullptr, this );
145
147
149}
150
151
153{
154 g_modifyTracks = m_tracks->GetValue();
155 g_modifyVias = m_vias->GetValue();
157 g_netclassFilter = m_netclassFilter->GetStringSelection();
158 g_filterByNet = m_netFilterOpt->GetValue();
160 g_filterByLayer = m_layerFilterOpt->GetValue();
163
164 m_netFilter->Disconnect( NET_SELECTED,
166 nullptr, this );
167
168 m_parent->Unbind( UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
169
170 delete[] m_originalColWidths;
171}
172
173
175{
176 int trackSel = m_trackWidthSelectBox->GetSelection();
177 int viaSel = m_viaSizesSelectBox->GetSelection();
178
183
184 m_trackWidthSelectBox->SetSelection( trackSel );
185 m_viaSizesSelectBox->SetSelection( viaSel );
186
187 m_netclassGrid->ClearGrid();
189
190 aEvent.Skip();
191}
192
193
195{
196 // Populate the net filter list with net names
199
200 if( !m_brd->GetHighLightNetCodes().empty() )
202
203 // Populate the netclass filter list with netclass names
204 wxArrayString netclassNames;
205 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
206
207 netclassNames.push_back( settings->m_DefaultNetClass->GetName() );
208
209 for( const auto& [ name, netclass ] : settings->m_NetClasses )
210 netclassNames.push_back( name );
211
212 m_netclassFilter->Set( netclassNames );
214
215 // Populate the layer filter list
221}
222
223
225{
226 int row = 0;
227
228 m_netclassGrid->SetCellValue( row, GRID_TRACKSIZE, _( "Track Width" ) );
229 m_netclassGrid->SetCellValue( row, GRID_VIASIZE, _( "Via Diameter" ) );
230 m_netclassGrid->SetCellValue( row, GRID_VIADRILL, _( "Via Hole" ) );
231 m_netclassGrid->SetCellValue( row, GRID_uVIASIZE, _( "uVia Diameter" ) );
232 m_netclassGrid->SetCellValue( row, GRID_uVIADRILL, _( "uVia Hole" ) );
233 row++;
234
235 auto setNetclassValue =
236 [this]( int aRow, int aCol, int aVal )
237 {
238 m_netclassGrid->SetCellValue( aRow, aCol, m_parent->StringFromValue( aVal, true ) );
239 };
240
241 auto buildRow =
242 [this, &setNetclassValue]( int aRow, const std::shared_ptr<NETCLASS>& aNc )
243 {
244 m_netclassGrid->SetCellValue( aRow, GRID_NAME, aNc->GetName() );
245 setNetclassValue( aRow, GRID_TRACKSIZE, aNc->GetTrackWidth() );
246 setNetclassValue( aRow, GRID_VIASIZE, aNc->GetViaDiameter() );
247 setNetclassValue( aRow, GRID_VIADRILL, aNc->GetViaDrill() );
248 setNetclassValue( aRow, GRID_uVIASIZE, aNc->GetuViaDiameter() );
249 setNetclassValue( aRow, GRID_uVIADRILL, aNc->GetuViaDrill() );
250 };
251
252 const std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
253
254 m_netclassGrid->AppendRows( 1 );
255 buildRow( row++, settings->m_DefaultNetClass );
256
257 m_netclassGrid->AppendRows( settings->m_NetClasses.size() );
258
259 for( const auto& [ name, netclass ] : settings->m_NetClasses )
260 buildRow( row++, netclass );
261}
262
263
265{
267 m_selection = selTool->GetSelection();
269
270 m_tracks->SetValue( g_modifyTracks );
271 m_vias->SetValue( g_modifyVias );
272
273 if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
274 m_netclassFilterOpt->SetValue( true );
275 else if( item )
276 m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClass()->GetName() );
277
278 if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
279 {
281 m_netFilterOpt->SetValue( true );
282 }
283 else if( item )
284 {
286 }
287
289 {
290 m_layerFilterOpt->SetValue( true );
291 }
292 else if( item )
293 {
294 if( item->Type() == PCB_ZONE_T ) // a zone can be on more than one layer
295 m_layerFilter->SetLayerSelection( static_cast<ZONE*>(item)->GetFirstLayer() );
296 else
298 }
299
300 m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
301 m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
302 m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
303
305
306 return true;
307}
308
309
311{
312 // Enable the items in the use specified values section
313 event.Enable( m_setToSpecifiedValues->GetValue() );
314}
315
316
318 PCB_TRACK* aItem )
319{
321 bool isTrack = aItem->Type() == PCB_TRACE_T;
322 bool isArc = aItem->Type() == PCB_ARC_T;
323 bool isVia = aItem->Type() == PCB_VIA_T;
324
325 if( m_setToSpecifiedValues->GetValue() )
326 {
327 if( ( isArc || isTrack )
328 && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
329 {
330 unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
331 int trackWidthIndex = m_trackWidthSelectBox->GetSelection();
332
333 if( trackWidthIndex >= 0 )
334 brdSettings.SetTrackWidthIndex( static_cast<unsigned>( trackWidthIndex ) );
335
336 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
337
338 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
339 }
340 else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
341 {
342 unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
343 int viaSizeIndex = m_viaSizesSelectBox->GetSelection();
344
345 if( viaSizeIndex >= 0 )
346 brdSettings.SetViaSizeIndex( static_cast<unsigned>( viaSizeIndex ) );
347
348 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
349
350 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
351 }
352
353 if( ( isArc || isTrack ) && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
354 {
355 if( aUndoList->FindItem( aItem ) < 0 )
356 {
357 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
358 picker.SetLink( aItem->Clone() );
359 aUndoList->PushItem( picker );
360 }
361
363 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
364 }
365 }
366 else
367 {
368 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
369 }
370
371 m_items_changed.push_back( aItem );
372}
373
374
376{
377 if( m_selectedItemsFilter->GetValue() )
378 {
379 if( !aItem->IsSelected() )
380 {
381 PCB_GROUP* group = aItem->GetParentGroup();
382
383 while( group && !group->IsSelected() )
384 group = group->GetParentGroup();
385
386 if( !group )
387 return;
388 }
389 }
390
391 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
392 {
393 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
394 return;
395 }
396
397 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
398 {
399 if( aItem->GetEffectiveNetClass()->GetName() != m_netclassFilter->GetStringSelection() )
400 return;
401 }
402
404 {
405 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
406 return;
407 }
408
409 processItem( aUndoList, aItem );
410}
411
412
414{
415 PICKED_ITEMS_LIST itemsListPicker;
416 wxBusyCursor dummy;
417
418 // Examine segments
419 for( PCB_TRACK* track : m_brd->Tracks() )
420 {
421 if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
422 visitItem( &itemsListPicker, track );
423 else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
424 visitItem( &itemsListPicker, track );
425 else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
426 visitItem( &itemsListPicker, track );
427 }
428
429 if( itemsListPicker.GetCount() > 0 )
430 {
432
433 for( PCB_TRACK* track : m_brd->Tracks() )
434 m_parent->GetCanvas()->GetView()->Update( track );
435 }
436
437 if( m_items_changed.size() )
438 {
441 }
442
443 return true;
444}
445
446
448{
449 for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
450 {
451 m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
452 aWidth -= m_originalColWidths[ i ];
453 }
454
455 m_netclassGrid->SetColSize( 0, aWidth );
456}
457
458
460{
461 AdjustNetclassGridColumns( event.GetSize().GetX() );
462 event.Skip();
463}
464
465
467{
468 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
469 DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
470
471 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
472 return 0;
473}
474
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:167
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:62
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:201
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:763
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:472
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1392
TRACKS & Tracks()
Definition: board.h:304
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:618
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:1997
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:424
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
void OnLayerFilterSelect(wxCommandEvent &event) override
void onSpecifiedValuesUpdateUi(wxUpdateUIEvent &event) override
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
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...
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
bool IsSelected() const
Definition: eda_item.h:107
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:111
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:300
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()
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:59
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:200
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.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:236
static bool g_filterByNet
static wxString g_netclassFilter
static bool g_filterByNetclass
static int g_layerFilter
static bool g_filterSelected
static wxString g_netFilter
static bool g_modifyVias
static bool g_modifyTracks
static bool g_filterByLayer
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:926
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
#define INDETERMINATE_ACTION
Definition: ui_common.h:43