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 <class_board.h>
27 #include <class_track.h>
29 #include <pcb_layer_box_selector.h>
30 #include <tool/tool_manager.h>
31 #include <tools/selection_tool.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 
59 
61 {
62 private:
66 
67 public:
70 
71 private:
72  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
73  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
74 
75  bool TransferDataToWindow() override;
76  bool TransferDataFromWindow() override;
77 
78  void OnUpdateUI( wxUpdateUIEvent& event ) override;
79  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
80  void AdjustNetclassGridColumns( int aWidth );
81 
82  void OnNetFilterSelect( wxCommandEvent& event )
83  {
84  m_netFilterOpt->SetValue( true );
85  }
86  void OnNetclassFilterSelect( wxCommandEvent& event ) override
87  {
88  m_netclassFilterOpt->SetValue( true );
89  }
90  void OnLayerFilterSelect( wxCommandEvent& event ) override
91  {
92  m_layerFilterOpt->SetValue( true );
93  }
94 
95  void buildNetclassesGrid();
96  void buildFilterLists();
97 };
98 
99 
102 {
103  m_parent = aParent;
104  m_brd = m_parent->GetBoard();
105 
106  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
107 
108  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
109  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
110 
112 
117 
119  m_layerBox->SetLayersHotkeys( false );
122  m_layerBox->Resync();
123 
124  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
125  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
126  m_netclassGrid->SetDefaultCellFont( infoFont );
128 
129  m_netclassGrid->SetCellHighlightPenWidth( 0 );
130  m_sdbSizerOK->SetDefault();
131 
132  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
133 
135 }
136 
137 
139 {
140  g_modifyTracks = m_tracks->GetValue();
141  g_modifyVias = m_vias->GetValue();
143  g_netclassFilter = m_netclassFilter->GetStringSelection();
144  g_filterByNet = m_netFilterOpt->GetValue();
146  g_filterByLayer = m_layerFilterOpt->GetValue();
148 
149  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
150 
151  delete[] m_originalColWidths;
152 }
153 
154 
156 {
157  // Populate the net filter list with net names
160 
161  if( !m_brd->GetHighLightNetCodes().empty() )
163 
164  // Populate the netclass filter list with netclass names
165  wxArrayString netclassNames;
166  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
167 
168  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
169 
170  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
171  netclassNames.push_back( nc->second->GetName() );
172 
173  m_netclassFilter->Set( netclassNames );
175 
176  // Populate the layer filter list
182 }
183 
184 
186 {
187 #define SET_NETCLASS_VALUE( row, col, val ) \
188  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true ) )
189 
190  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
191  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
192  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
193  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
194  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
195 
196  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
197  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
198  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
199 
200  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
201  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
202  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
203  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
204  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
205  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
206 
207  int row = 2;
208  for( const auto& netclass : netclasses )
209  {
210  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
211  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
212  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
213  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
214  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
215  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
216  row++;
217  }
218 }
219 
220 
222 {
223  PCBNEW_SELECTION& selection = m_parent->GetToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
224  auto item = dynamic_cast<BOARD_CONNECTED_ITEM*>( selection.Front() );
225 
226  m_tracks->SetValue( g_modifyTracks );
227  m_vias->SetValue( g_modifyVias );
228 
229  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
230  m_netclassFilterOpt->SetValue( true );
231  else if( item )
232  m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() );
233 
234  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
235  {
237  m_netFilterOpt->SetValue( true );
238  }
239  else if( item )
240  m_netFilter->SetSelectedNetcode( item->GetNetCode() );
241 
243  m_layerFilterOpt->SetValue( true );
244  else if( item )
245  m_layerFilter->SetLayerSelection( item->GetLayer() );
246 
247  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
248  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
249  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
250 
251  return true;
252 }
253 
254 
256 {
257  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
258  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
259 }
260 
261 
263 {
265  bool isTrack = aItem->Type() == PCB_TRACE_T;
266  bool isVia = aItem->Type() == PCB_VIA_T;
267 
268  if( m_setToSpecifiedValues->GetValue() )
269  {
270  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
271  {
272  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
273  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
274 
275  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
276 
277  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
278  }
279  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
280  {
281  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
282  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
283 
284  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
285 
286  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
287  }
288 
289  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
290  {
291  if( aUndoList->FindItem( aItem ) < 0 )
292  {
293  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
294  picker.SetLink( aItem->Clone() );
295  aUndoList->PushItem( picker );
296  }
297 
299  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
300  }
301  }
302  else
303  {
304  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
305  }
306 
307  m_brd->OnItemChanged( aItem );
308 }
309 
310 
312 {
313  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
314  {
315  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
316  return;
317  }
318 
319  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
320  {
321  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
322  return;
323  }
324 
326  {
327  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
328  return;
329  }
330 
331  processItem( aUndoList, aItem );
332 }
333 
334 
336 {
337  PICKED_ITEMS_LIST itemsListPicker;
338  wxBusyCursor dummy;
339 
340  // Examine segments
341  for( auto segment : m_brd->Tracks() )
342  {
343  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
344  visitItem( &itemsListPicker, segment );
345  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
346  visitItem( &itemsListPicker, segment );
347  }
348 
349  if( itemsListPicker.GetCount() > 0 )
350  {
351  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
352 
353  for( auto segment : m_brd->Tracks() )
354  m_parent->GetCanvas()->GetView()->Update( segment );
355  }
356 
357  return true;
358 }
359 
360 
362 {
363  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
364  {
365  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
366  aWidth -= m_originalColWidths[ i ];
367  }
368 
369  m_netclassGrid->SetColSize( 0, aWidth );
370 }
371 
372 
374 {
375  AdjustNetclassGridColumns( event.GetSize().GetX() );
376  event.Skip();
377 }
378 
379 
381 {
382  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
383  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
384 
385  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
386  return 0;
387 }
388 
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
int GetNetCode() const
Function GetNetCode.
int FindItem(const EDA_ITEM *aItem) const
Function FindItem.
void SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Function SetTrackSegmentWidth Modify one track segment width or one via diameter (using DRC control).
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetNotAllowedLayerSet(LSET aMask)
const wxString & GetName() const
Definition: netclass.h:96
static LAYER_NUM g_layerFilter
void SetBoard(BOARD *aBoard)
SELECTION_TOOL.
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:772
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_track.cpp:50
static wxString g_netclassFilter
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: class_board.h:724
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
iterator end()
Definition: netclass.h:247
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetLink(EDA_ITEM *aItem)
wxString GetSelectedNetname()
void OnNetclassFilterSelect(wxCommandEvent &event) override
unsigned GetCount() const
Function GetCount.
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:249
void OnUpdateUI(wxUpdateUIEvent &event) override
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.
void processItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
static bool g_modifyTracks
virtual PCB_LAYER_ID GetActiveLayer() const
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aEdit=true)
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
LAYER_NUM GetLayerSelection() const
int EditTracksAndVias(const TOOL_EVENT &aEvent)
int GetTrackWidth() const
Definition: netclass.h:163
iterator begin()
Definition: netclass.h:246
NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:224
#define NULL
#define SET_NETCLASS_VALUE(row, col, val)
const wxString & GetCurrentNetClassName() const
Function GetCurrentNetClassName.
unsigned GetViaSizeIndex() const
Function GetViaSizeIndex.
int ShowQuasiModal()
TOOL_EVENT.
Definition: tool_event.h:171
NETCLASS handles a collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:49
void SetSelectedNetcode(int aNetcode)
int GetViaDrill() const
Definition: netclass.h:171
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: class_board.h:381
static bool g_filterByNetclass
int SetLayerSelection(LAYER_NUM layer)
NETCLASSES & GetNetClasses() const
void OnLayerFilterSelect(wxCommandEvent &event) override
int GetuViaDiameter() const
Definition: netclass.h:175
static bool g_filterByLayer
void SetNetInfo(NETINFO_LIST *aNetInfoList)
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
NETCLASS * GetDefaultPtr() const
Definition: netclass.h:271
static bool g_modifyVias
bool SetLayersHotkeys(bool value)
static wxString g_netFilter
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns 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: class_board.h:421
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0)) override
Function SaveCopyInUndoList Creates a new entry in undo list of commands.
Definition: undo_redo.cpp:179
NETCLASS * GetDefault() const
Function GetDefault.
PCB_EDIT_FRAME is the main frame for Pcbnew.
void SetSelectedNet(const wxString &aNetname)
int GetViaDiameter() const
Definition: netclass.h:167
void OnItemChanged(BOARD_ITEM *aItem)
Notify the board and its listeners that an item on the board has been modified in some way.
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:257
int GetuViaDrill() const
Definition: netclass.h:179
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
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
Function GetLayer returns the primary layer this item is on.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:897
TRACKS & Tracks()
Definition: class_board.h:281
EDA_ITEM * Front() const
Definition: selection.h:184
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.