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-2020 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 <track.h>
29 #include <pcb_layer_box_selector.h>
30 #include <tool/tool_manager.h>
32 #include <tools/global_edit_tool.h>
34 
35 // Columns of netclasses grid
36 enum {
37  GRID_NAME = 0,
43  GRID_DIFF_PAIR_WIDTH, // not currently included in grid
44  GRID_DIFF_PAIR_GAP, // not currently included in grid
45  GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
46 };
47 
48 
49 // Globals to remember control settings during a session
50 static bool g_modifyTracks = true;
51 static bool g_modifyVias = true;
52 static bool g_filterByNetclass;
53 static wxString g_netclassFilter;
54 static bool g_filterByNet;
55 static wxString g_netFilter;
56 static bool g_filterByLayer;
58 static bool g_filterSelected = false;
59 
60 
62 {
63 private:
68 
69 public:
72 
73 private:
74  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
75  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
76 
77  bool TransferDataToWindow() override;
78  bool TransferDataFromWindow() override;
79 
80  void OnUpdateUI( wxUpdateUIEvent& event ) override;
81  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
82  void AdjustNetclassGridColumns( int aWidth );
83 
84  void OnNetFilterSelect( wxCommandEvent& event )
85  {
86  m_netFilterOpt->SetValue( true );
87  }
88  void OnNetclassFilterSelect( wxCommandEvent& event ) override
89  {
90  m_netclassFilterOpt->SetValue( true );
91  }
92  void OnLayerFilterSelect( wxCommandEvent& event ) override
93  {
94  m_layerFilterOpt->SetValue( true );
95  }
96 
97  void buildNetclassesGrid();
98  void buildFilterLists();
99 };
100 
101 
104 {
105  m_parent = aParent;
106  m_brd = m_parent->GetBoard();
107 
108  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
109 
110  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
111  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
112 
114 
119 
121  m_layerBox->SetLayersHotkeys( false );
124  m_layerBox->Resync();
125 
126  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
127  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
128  m_netclassGrid->SetDefaultCellFont( infoFont );
130 
131  m_netclassGrid->SetCellHighlightPenWidth( 0 );
132  m_sdbSizerOK->SetDefault();
133 
134  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
135 
137 }
138 
139 
141 {
142  g_modifyTracks = m_tracks->GetValue();
143  g_modifyVias = m_vias->GetValue();
145  g_netclassFilter = m_netclassFilter->GetStringSelection();
146  g_filterByNet = m_netFilterOpt->GetValue();
148  g_filterByLayer = m_layerFilterOpt->GetValue();
151 
152  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
153 
154  delete[] m_originalColWidths;
155 }
156 
157 
159 {
160  // Populate the net filter list with net names
163 
164  if( !m_brd->GetHighLightNetCodes().empty() )
166 
167  // Populate the netclass filter list with netclass names
168  wxArrayString netclassNames;
169  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
170 
171  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
172 
173  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
174  netclassNames.push_back( nc->second->GetName() );
175 
176  m_netclassFilter->Set( netclassNames );
178 
179  // Populate the layer filter list
185 }
186 
187 
189 {
190 #define SET_NETCLASS_VALUE( row, col, val ) \
191  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true ) )
192 
193  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
194  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
195  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
196  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
197  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
198 
199  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
200  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
201  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
202 
203  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
204  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
205  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
206  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
207  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
208  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
209 
210  int row = 2;
211  for( const auto& netclass : netclasses )
212  {
213  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
214  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
215  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
216  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
217  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
218  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
219  row++;
220  }
221 }
222 
223 
225 {
227  m_selection = selTool->GetSelection();
228  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_selection.Front() );
229 
230  m_tracks->SetValue( g_modifyTracks );
231  m_vias->SetValue( g_modifyVias );
232 
233  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
234  m_netclassFilterOpt->SetValue( true );
235  else if( item )
236  m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClassName() );
237 
238  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
239  {
241  m_netFilterOpt->SetValue( true );
242  }
243  else if( item )
244  {
246  }
247 
249  m_layerFilterOpt->SetValue( true );
250  else if( item )
252 
253  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
254  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
255  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
256 
258 
259  return true;
260 }
261 
262 
264 {
265  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
266  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
267 }
268 
269 
271 {
273  bool isTrack = aItem->Type() == PCB_TRACE_T;
274  bool isVia = aItem->Type() == PCB_VIA_T;
275 
276  if( m_setToSpecifiedValues->GetValue() )
277  {
278  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
279  {
280  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
281  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
282 
283  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
284 
285  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
286  }
287  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
288  {
289  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
290  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
291 
292  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
293 
294  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
295  }
296 
297  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
298  {
299  if( aUndoList->FindItem( aItem ) < 0 )
300  {
301  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
302  picker.SetLink( aItem->Clone() );
303  aUndoList->PushItem( picker );
304  }
305 
307  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
308  }
309  }
310  else
311  {
312  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
313  }
314 
315  m_brd->OnItemChanged( aItem );
316 }
317 
318 
320 {
321  if( m_selectedItemsFilter->GetValue() && !m_selection.Contains( aItem ) )
322  return;
323 
324  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
325  {
326  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
327  return;
328  }
329 
330  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
331  {
332  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
333  return;
334  }
335 
337  {
338  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
339  return;
340  }
341 
342  processItem( aUndoList, aItem );
343 }
344 
345 
347 {
348  PICKED_ITEMS_LIST itemsListPicker;
349  wxBusyCursor dummy;
350 
351  // Examine segments
352  for( auto segment : m_brd->Tracks() )
353  {
354  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
355  visitItem( &itemsListPicker, segment );
356  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
357  visitItem( &itemsListPicker, segment );
358  }
359 
360  if( itemsListPicker.GetCount() > 0 )
361  {
362  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
363 
364  for( auto segment : m_brd->Tracks() )
365  m_parent->GetCanvas()->GetView()->Update( segment );
366  }
367 
368  return true;
369 }
370 
371 
373 {
374  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
375  {
376  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
377  aWidth -= m_originalColWidths[ i ];
378  }
379 
380  m_netclassGrid->SetColSize( 0, aWidth );
381 }
382 
383 
385 {
386  AdjustNetclassGridColumns( event.GetSize().GetX() );
387  event.Skip();
388 }
389 
390 
392 {
393  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
394  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
395 
396  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
397  return 0;
398 }
399 
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1268
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:177
int FindItem(const EDA_ITEM *aItem) const
void SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
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
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: track.cpp:54
static wxString g_netclassFilter
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:591
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:752
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,...
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
void OnUpdateUI(wxUpdateUIEvent &event) override
virtual wxString GetNetClassName() const
Returns the netclass of the zone.
void processItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
static bool g_modifyTracks
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 NULL
#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:173
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.h:114
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:414
static bool g_filterByNetclass
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
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:454
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.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
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:1972
unsigned GetCount() const
Definition: netclass.h:245
int GetuViaDrill() const
Definition: netclass.h:144
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aEdit=true)
BOARD * GetBoard() const
void OnSizeNetclassGrid(wxSizeEvent &event) override
#define INDETERMINATE_ACTION
Definition: base_units.h:49
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:300
Definition: track.h:83
EDA_ITEM * Front() const
Definition: selection.h:203
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162
Container for design settings for a BOARD object.