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 
72 public:
75 
76 protected:
77  void onSpecifiedValuesUpdateUi( wxUpdateUIEvent& event ) override;
78  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
79 
80  void OnNetclassFilterSelect( wxCommandEvent& event ) override
81  {
82  m_netclassFilterOpt->SetValue( true );
83  }
84  void OnLayerFilterSelect( wxCommandEvent& event ) override
85  {
86  m_layerFilterOpt->SetValue( true );
87  }
88 
89 private:
90  void visitItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
91  void processItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
92 
93  bool TransferDataToWindow() override;
94  bool TransferDataFromWindow() override;
95 
96  void AdjustNetclassGridColumns( int aWidth );
97 
98  void OnNetFilterSelect( wxCommandEvent& event )
99  {
100  m_netFilterOpt->SetValue( true );
101  }
102 
103  void buildNetclassesGrid();
104  void buildFilterLists();
105 };
106 
107 
110 {
111  m_parent = aParent;
112  m_brd = m_parent->GetBoard();
113 
114  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
115 
116  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
117  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
118 
120 
125 
127  m_layerBox->SetLayersHotkeys( false );
130  m_layerBox->Resync();
131 
132  m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont( this ) );
134 
135  m_netclassGrid->SetCellHighlightPenWidth( 0 );
136  m_sdbSizerOK->SetDefault();
137 
138  m_netFilter->Connect( NET_SELECTED,
140  nullptr, this );
141 
143 }
144 
145 
147 {
148  g_modifyTracks = m_tracks->GetValue();
149  g_modifyVias = m_vias->GetValue();
151  g_netclassFilter = m_netclassFilter->GetStringSelection();
152  g_filterByNet = m_netFilterOpt->GetValue();
154  g_filterByLayer = m_layerFilterOpt->GetValue();
157 
158  m_netFilter->Disconnect( NET_SELECTED,
160  nullptr, this );
161 
162  delete[] m_originalColWidths;
163 }
164 
165 
167 {
168  // Populate the net filter list with net names
171 
172  if( !m_brd->GetHighLightNetCodes().empty() )
174 
175  // Populate the netclass filter list with netclass names
176  wxArrayString netclassNames;
177  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
178 
179  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
180 
181  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
182  netclassNames.push_back( nc->second->GetName() );
183 
184  m_netclassFilter->Set( netclassNames );
186 
187  // Populate the layer filter list
193 }
194 
195 
197 {
198 #define SET_NETCLASS_VALUE( row, col, val ) \
199  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true ) )
200 
201  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
202  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
203  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
204  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
205  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
206 
207  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
208  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
209  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
210 
211  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
212  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
213  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
214  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
215  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
216  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
217 
218  int row = 2;
219 
220  for( const auto& netclass : netclasses )
221  {
222  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
223  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
224  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
225  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
226  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
227  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
228  row++;
229  }
230 }
231 
232 
234 {
236  m_selection = selTool->GetSelection();
237  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_selection.Front() );
238 
239  m_tracks->SetValue( g_modifyTracks );
240  m_vias->SetValue( g_modifyVias );
241 
242  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
243  m_netclassFilterOpt->SetValue( true );
244  else if( item )
245  m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClassName() );
246 
247  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
248  {
250  m_netFilterOpt->SetValue( true );
251  }
252  else if( item )
253  {
255  }
256 
258  m_layerFilterOpt->SetValue( true );
259  else if( item )
261 
262  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
263  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
264  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
265 
267 
268  return true;
269 }
270 
271 
273 {
274  // Enable the items in the use specified values section
275  event.Enable( m_setToSpecifiedValues->GetValue() );
276 }
277 
278 
280  PCB_TRACK* aItem )
281 {
283  bool isTrack = aItem->Type() == PCB_TRACE_T;
284  bool isVia = aItem->Type() == PCB_VIA_T;
285 
286  if( m_setToSpecifiedValues->GetValue() )
287  {
288  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
289  {
290  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
291  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
292 
293  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
294 
295  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
296  }
297  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
298  {
299  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
300  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
301 
302  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
303 
304  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
305  }
306 
307  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
308  {
309  if( aUndoList->FindItem( aItem ) < 0 )
310  {
311  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
312  picker.SetLink( aItem->Clone() );
313  aUndoList->PushItem( picker );
314  }
315 
317  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
318  }
319  }
320  else
321  {
322  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
323  }
324 
325  m_brd->OnItemChanged( aItem );
326 }
327 
328 
330 {
331  if( m_selectedItemsFilter->GetValue() )
332  {
333  if( !aItem->IsSelected() )
334  {
335  PCB_GROUP* group = aItem->GetParentGroup();
336 
337  while( group && !group->IsSelected() )
338  group = group->GetParentGroup();
339 
340  if( !group )
341  return;
342  }
343  }
344 
345  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
346  {
347  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
348  return;
349  }
350 
351  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
352  {
353  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
354  return;
355  }
356 
358  {
359  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
360  return;
361  }
362 
363  processItem( aUndoList, aItem );
364 }
365 
366 
368 {
369  PICKED_ITEMS_LIST itemsListPicker;
370  wxBusyCursor dummy;
371 
372  // Examine segments
373  for( auto segment : m_brd->Tracks() )
374  {
375  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
376  visitItem( &itemsListPicker, segment );
377  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
378  visitItem( &itemsListPicker, segment );
379  }
380 
381  if( itemsListPicker.GetCount() > 0 )
382  {
383  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
384 
385  for( auto segment : m_brd->Tracks() )
386  m_parent->GetCanvas()->GetView()->Update( segment );
387  }
388 
389  return true;
390 }
391 
392 
394 {
395  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
396  {
397  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
398  aWidth -= m_originalColWidths[ i ];
399  }
400 
401  m_netclassGrid->SetColSize( 0, aWidth );
402 }
403 
404 
406 {
407  AdjustNetclassGridColumns( event.GetSize().GetX() );
408  event.Skip();
409 }
410 
411 
413 {
414  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
415  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
416 
417  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
418  return 0;
419 }
420 
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:1325
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:123
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:57
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
wxString GetNetClassName() const
Definition: netinfo.h:108
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:773
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
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:679
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:344
static bool g_filterByNetclass
#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:386
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:190
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
void OnItemChanged(BOARD_ITEM *aItem)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition: board.cpp:1979
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:140
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:230
EDA_ITEM * Front() const
Definition: selection.h:145
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.