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>
30 #include <pcb_layer_box_selector.h>
31 #include <tool/tool_manager.h>
33 #include <tools/global_edit_tool.h>
35 
36 
37 // Columns of netclasses grid
38 enum {
39  GRID_NAME = 0,
45  GRID_DIFF_PAIR_WIDTH, // not currently included in grid
46  GRID_DIFF_PAIR_GAP, // not currently included in grid
47  GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
48 };
49 
50 
51 // Globals to remember control settings during a session
52 static bool g_modifyTracks = true;
53 static bool g_modifyVias = true;
54 static bool g_filterByNetclass;
55 static wxString g_netclassFilter;
56 static bool g_filterByNet;
57 static wxString g_netFilter;
58 static bool g_filterByLayer;
60 static bool g_filterSelected = false;
61 
62 
64 {
65 private:
70 
71 public:
74 
75 protected:
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 
88 private:
89  void visitItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
90  void processItem( PICKED_ITEMS_LIST* aUndoList, PCB_TRACK* aItem );
91 
92  bool TransferDataToWindow() override;
93  bool TransferDataFromWindow() override;
94 
95  void AdjustNetclassGridColumns( int aWidth );
96 
97  void OnNetFilterSelect( wxCommandEvent& event )
98  {
99  m_netFilterOpt->SetValue( true );
100  }
101 
102  void buildNetclassesGrid();
103  void buildFilterLists();
104 };
105 
106 
109 {
110  m_parent = aParent;
111  m_brd = m_parent->GetBoard();
112 
113  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
114 
115  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
116  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
117 
119 
124 
126  m_layerBox->SetLayersHotkeys( false );
129  m_layerBox->Resync();
130 
131  m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont() );
133 
134  m_netclassGrid->SetCellHighlightPenWidth( 0 );
135  m_sdbSizerOK->SetDefault();
136 
137  m_netFilter->Connect( NET_SELECTED,
139  nullptr, this );
140 
142 }
143 
144 
146 {
147  g_modifyTracks = m_tracks->GetValue();
148  g_modifyVias = m_vias->GetValue();
150  g_netclassFilter = m_netclassFilter->GetStringSelection();
151  g_filterByNet = m_netFilterOpt->GetValue();
153  g_filterByLayer = m_layerFilterOpt->GetValue();
156 
157  m_netFilter->Disconnect( NET_SELECTED,
159  nullptr, this );
160 
161  delete[] m_originalColWidths;
162 }
163 
164 
166 {
167  // Populate the net filter list with net names
170 
171  if( !m_brd->GetHighLightNetCodes().empty() )
173 
174  // Populate the netclass filter list with netclass names
175  wxArrayString netclassNames;
176  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
177 
178  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
179 
180  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
181  netclassNames.push_back( nc->second->GetName() );
182 
183  m_netclassFilter->Set( netclassNames );
185 
186  // Populate the layer filter list
192 }
193 
194 
196 {
197 #define SET_NETCLASS_VALUE( row, col, val ) \
198  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true ) )
199 
200  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
201  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
202  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
203  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
204  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
205 
206  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
207  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
208  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
209 
210  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
211  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
212  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
213  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
214  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
215  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
216 
217  int row = 2;
218 
219  for( const auto& netclass : netclasses )
220  {
221  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
222  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
223  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
224  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
225  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
226  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
227  row++;
228  }
229 }
230 
231 
233 {
235  m_selection = selTool->GetSelection();
236  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_selection.Front() );
237 
238  m_tracks->SetValue( g_modifyTracks );
239  m_vias->SetValue( g_modifyVias );
240 
241  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
242  m_netclassFilterOpt->SetValue( true );
243  else if( item )
244  m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClassName() );
245 
246  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
247  {
249  m_netFilterOpt->SetValue( true );
250  }
251  else if( item )
252  {
254  }
255 
257  m_layerFilterOpt->SetValue( true );
258  else if( item )
260 
261  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
262  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
263  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
264 
266 
267  return true;
268 }
269 
270 
272 {
273  // Enable the items in the use specified values section
274  event.Enable( m_setToSpecifiedValues->GetValue() );
275 }
276 
277 
279  PCB_TRACK* aItem )
280 {
282  bool isTrack = aItem->Type() == PCB_TRACE_T;
283  bool isVia = aItem->Type() == PCB_VIA_T;
284 
285  if( m_setToSpecifiedValues->GetValue() )
286  {
287  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
288  {
289  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
290  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
291 
292  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
293 
294  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
295  }
296  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
297  {
298  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
299  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
300 
301  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
302 
303  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
304  }
305 
306  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
307  {
308  if( aUndoList->FindItem( aItem ) < 0 )
309  {
310  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
311  picker.SetLink( aItem->Clone() );
312  aUndoList->PushItem( picker );
313  }
314 
316  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
317  }
318  }
319  else
320  {
321  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
322  }
323 
324  m_brd->OnItemChanged( aItem );
325 }
326 
327 
329 {
330  if( m_selectedItemsFilter->GetValue() && !m_selection.Contains( aItem ) )
331  return;
332 
333  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
334  {
335  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
336  return;
337  }
338 
339  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
340  {
341  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
342  return;
343  }
344 
346  {
347  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
348  return;
349  }
350 
351  processItem( aUndoList, aItem );
352 }
353 
354 
356 {
357  PICKED_ITEMS_LIST itemsListPicker;
358  wxBusyCursor dummy;
359 
360  // Examine segments
361  for( auto segment : m_brd->Tracks() )
362  {
363  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
364  visitItem( &itemsListPicker, segment );
365  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
366  visitItem( &itemsListPicker, segment );
367  }
368 
369  if( itemsListPicker.GetCount() > 0 )
370  {
371  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
372 
373  for( auto segment : m_brd->Tracks() )
374  m_parent->GetCanvas()->GetView()->Update( segment );
375  }
376 
377  return true;
378 }
379 
380 
382 {
383  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
384  {
385  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
386  aWidth -= m_originalColWidths[ i ];
387  }
388 
389  m_netclassGrid->SetColSize( 0, aWidth );
390 }
391 
392 
394 {
395  AdjustNetclassGridColumns( event.GetSize().GetX() );
396  event.Skip();
397 }
398 
399 
401 {
402  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
403  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
404 
405  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
406  return 0;
407 }
408 
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1343
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
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:192
wxString GetNetClassName() const
Definition: netinfo.h:108
void SetNotAllowedLayerSet(LSET aMask)
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
const wxString & GetName() const
Definition: netclass.h:65
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
static wxString g_netclassFilter
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:684
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:588
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:71
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)
bool Contains(EDA_ITEM *aItem) const
Definition: selection.cpp:61
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.
int LAYER_NUM
This can be replaced with int and removed.
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.
wxFont GetInfoFont()
Definition: ui_common.cpp:97
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:2008
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:171
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:230
EDA_ITEM * Front() const
Definition: selection.h:144
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Container for design settings for a BOARD object.