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-2021 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>
27 #include <board_design_settings.h>
28 #include <pcb_track.h>
29 #include <pcb_group.h>
31 #include <pcb_layer_box_selector.h>
32 #include <tool/tool_manager.h>
34 #include <tools/global_edit_tool.h>
36 
37 
38 // Columns of netclasses grid
39 enum {
40  GRID_NAME = 0,
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
53 static bool g_modifyTracks = true;
54 static bool g_modifyVias = true;
55 static bool g_filterByNetclass;
56 static wxString g_netclassFilter;
57 static bool g_filterByNet;
58 static wxString g_netFilter;
59 static bool g_filterByLayer;
61 static bool g_filterSelected = false;
62 
63 
65 {
66 private:
71  std::vector<BOARD_ITEM*> m_items_changed; // a list of modified items
72 
73 public:
76 
77 protected:
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 
92 private:
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;
115  m_brd = m_parent->GetBoard();
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 
130  m_layerBox->SetLayersHotkeys( false );
133  m_layerBox->Resync();
134 
135  m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
137 
138  m_netclassGrid->SetCellHighlightPenWidth( 0 );
139  m_sdbSizerOK->SetDefault();
140 
141  m_netFilter->Connect( NET_SELECTED,
143  nullptr, this );
144 
145  m_parent->Bind( UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
146 
148 }
149 
150 
152 {
153  g_modifyTracks = m_tracks->GetValue();
154  g_modifyVias = m_vias->GetValue();
156  g_netclassFilter = m_netclassFilter->GetStringSelection();
157  g_filterByNet = m_netFilterOpt->GetValue();
159  g_filterByLayer = m_layerFilterOpt->GetValue();
162 
163  m_netFilter->Disconnect( NET_SELECTED,
165  nullptr, this );
166 
167  m_parent->Unbind( UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
168 
169  delete[] m_originalColWidths;
170 }
171 
172 
174 {
175  int trackSel = m_trackWidthSelectBox->GetSelection();
176  int viaSel = m_viaSizesSelectBox->GetSelection();
177 
182 
183  m_trackWidthSelectBox->SetSelection( trackSel );
184  m_viaSizesSelectBox->SetSelection( viaSel );
185 
186  m_netclassGrid->ClearGrid();
188 
189  aEvent.Skip();
190 }
191 
192 
194 {
195  // Populate the net filter list with net names
198 
199  if( !m_brd->GetHighLightNetCodes().empty() )
201 
202  // Populate the netclass filter list with netclass names
203  wxArrayString netclassNames;
204  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
205 
206  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
207 
208  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
209  netclassNames.push_back( nc->second->GetName() );
210 
211  m_netclassFilter->Set( netclassNames );
213 
214  // Populate the layer filter list
220 }
221 
222 
224 {
225 #define SET_NETCLASS_VALUE( row, col, val ) \
226  m_netclassGrid->SetCellValue( row, col, StringFromValue( m_parent->GetUserUnits(), val, true ) )
227 
228  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
229  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
230  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
231  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
232  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
233 
234  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
235  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
236  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
237 
238  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
239  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
240  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
241  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
242  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
243  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
244 
245  int row = 2;
246 
247  for( const std::pair<const wxString, std::shared_ptr<NETCLASS>>& netclass : netclasses )
248  {
249  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
250  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
251  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
252  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
253  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
254  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
255  row++;
256  }
257 }
258 
259 
261 {
263  m_selection = selTool->GetSelection();
264  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_selection.Front() );
265 
266  m_tracks->SetValue( g_modifyTracks );
267  m_vias->SetValue( g_modifyVias );
268 
269  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
270  m_netclassFilterOpt->SetValue( true );
271  else if( item )
272  m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClassName() );
273 
274  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
275  {
277  m_netFilterOpt->SetValue( true );
278  }
279  else if( item )
280  {
282  }
283 
285  m_layerFilterOpt->SetValue( true );
286  else if( item )
288 
289  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
290  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
291  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
292 
294 
295  return true;
296 }
297 
298 
300 {
301  // Enable the items in the use specified values section
302  event.Enable( m_setToSpecifiedValues->GetValue() );
303 }
304 
305 
307  PCB_TRACK* aItem )
308 {
310  bool isTrack = aItem->Type() == PCB_TRACE_T;
311  bool isArc = aItem->Type() == PCB_ARC_T;
312  bool isVia = aItem->Type() == PCB_VIA_T;
313 
314  if( m_setToSpecifiedValues->GetValue() )
315  {
316  if( ( isArc || isTrack )
317  && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
318  {
319  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
320  int trackWidthIndex = m_trackWidthSelectBox->GetSelection();
321 
322  if( trackWidthIndex >= 0 )
323  brdSettings.SetTrackWidthIndex( static_cast<unsigned>( trackWidthIndex ) );
324 
325  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
326 
327  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
328  }
329  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
330  {
331  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
332  int viaSizeIndex = m_viaSizesSelectBox->GetSelection();
333 
334  if( viaSizeIndex >= 0 )
335  brdSettings.SetViaSizeIndex( static_cast<unsigned>( viaSizeIndex ) );
336 
337  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
338 
339  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
340  }
341 
342  if( ( isArc || isTrack ) && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
343  {
344  if( aUndoList->FindItem( aItem ) < 0 )
345  {
346  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
347  picker.SetLink( aItem->Clone() );
348  aUndoList->PushItem( picker );
349  }
350 
352  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
353  }
354  }
355  else
356  {
357  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
358  }
359 
360  m_items_changed.push_back( aItem );
361 }
362 
363 
365 {
366  if( m_selectedItemsFilter->GetValue() )
367  {
368  if( !aItem->IsSelected() )
369  {
370  PCB_GROUP* group = aItem->GetParentGroup();
371 
372  while( group && !group->IsSelected() )
373  group = group->GetParentGroup();
374 
375  if( !group )
376  return;
377  }
378  }
379 
380  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
381  {
382  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
383  return;
384  }
385 
386  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
387  {
388  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
389  return;
390  }
391 
393  {
394  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
395  return;
396  }
397 
398  processItem( aUndoList, aItem );
399 }
400 
401 
403 {
404  PICKED_ITEMS_LIST itemsListPicker;
405  wxBusyCursor dummy;
406 
407  // Examine segments
408  for( PCB_TRACK* track : m_brd->Tracks() )
409  {
410  if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
411  visitItem( &itemsListPicker, track );
412  else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
413  visitItem( &itemsListPicker, track );
414  else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
415  visitItem( &itemsListPicker, track );
416  }
417 
418  if( itemsListPicker.GetCount() > 0 )
419  {
420  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
421 
422  for( PCB_TRACK* track : m_brd->Tracks() )
423  m_parent->GetCanvas()->GetView()->Update( track );
424  }
425 
426  if( m_items_changed.size() )
427  {
429  m_parent->OnModify();
430  }
431 
432  return true;
433 }
434 
435 
437 {
438  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
439  {
440  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
441  aWidth -= m_originalColWidths[ i ];
442  }
443 
444  m_netclassGrid->SetColSize( 0, aWidth );
445 }
446 
447 
449 {
450  AdjustNetclassGridColumns( event.GetSize().GetX() );
451  event.Skip();
452 }
453 
454 
456 {
457  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
458  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
459 
460  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
461  return 0;
462 }
463 
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:60
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1328
void OnModify() override
Must be called after a board change to set the modified flag.
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
Definition: undo_redo.cpp:179
int FindItem(const EDA_ITEM *aItem) const
bool IsSelected() const
Definition: eda_item.h:122
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:58
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:164
wxString GetNetClassName() const
Definition: netinfo.h:115
void SetNotAllowedLayerSet(LSET aMask)
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
static LAYER_NUM g_layerFilter
void SetBoard(BOARD *aBoard)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:782
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
static wxString g_netclassFilter
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:41
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:680
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
iterator end()
Definition: netclass.h:236
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
static bool g_filterSelected
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
void SetLink(EDA_ITEM *aItem)
wxString GetSelectedNetname()
void OnNetclassFilterSelect(wxCommandEvent &event) override
unsigned GetCount() const
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:238
virtual wxString GetNetClassName() const
Returns the netclass of the zone.
void SetTrackSegmentWidth(PCB_TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
static bool g_modifyTracks
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
virtual PCB_LAYER_ID GetActiveLayer() const
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aEdit=true)
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
LAYER_NUM GetLayerSelection() const
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
int EditTracksAndVias(const TOOL_EVENT &aEvent)
int GetTrackWidth() const
Definition: netclass.h:128
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
iterator begin()
Definition: netclass.h:235
A container for NETCLASS instances.
Definition: netclass.h:218
#define SET_NETCLASS_VALUE(row, col, val)
const wxString & GetCurrentNetClassName() const
unsigned GetViaSizeIndex() const
int ShowQuasiModal()
Generic, UI-independent tool event.
Definition: tool_event.h:152
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
void SetSelectedNetcode(int aNetcode)
int GetViaDrill() const
Definition: netclass.h:136
unsigned GetTrackWidthIndex() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:345
static bool g_filterByNetclass
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:1940
#define _(s)
int SetLayerSelection(LAYER_NUM layer)
NETCLASSES & GetNetClasses() const
void OnLayerFilterSelect(wxCommandEvent &event) override
int GetuViaDiameter() const
Definition: netclass.h:140
static bool g_filterByLayer
void SetNetInfo(NETINFO_LIST *aNetInfoList)
A holder to handle information on schematic or board items.
NETCLASS * GetDefaultPtr() const
Definition: netclass.h:258
static bool g_modifyVias
bool SetLayersHotkeys(bool value)
static wxString g_netFilter
void onSpecifiedValuesUpdateUi(wxUpdateUIEvent &event) override
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void SetUndefinedLayerName(const wxString &aName)
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:387
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
const wxString GetName() const
Definition: netclass.h:65
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
NETCLASS * GetDefault() const
The main frame for Pcbnew.
void SetSelectedNet(const wxString &aNetname)
The selection tool: currently supports:
int GetViaDiameter() const
Definition: netclass.h:132
unsigned GetCount() const
Definition: netclass.h:245
int GetuViaDrill() const
Definition: netclass.h:144
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
void processItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aEdit=true)
BOARD * GetBoard() const
void OnSizeNetclassGrid(wxSizeEvent &event) override
#define INDETERMINATE_ACTION
Definition: base_units.h:48
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:143
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914
TRACKS & Tracks()
Definition: board.h:231
EDA_ITEM * Front() const
Definition: selection.h:145
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
Container for design settings for a BOARD object.