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-2018 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 <fctsys.h>
26 #include <confirm.h>
27 #include <pcb_edit_frame.h>
28 #include <class_drawpanel.h>
29 #include <class_board.h>
31 #include <view/view.h>
32 #include <pcb_layer_box_selector.h>
33 
35 
36 // Columns of netclasses grid
37 enum {
38  GRID_NAME = 0,
44  GRID_DIFF_PAIR_WIDTH, // not currently included in grid
45  GRID_DIFF_PAIR_GAP, // not currently included in grid
46  GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
47 };
48 
49 
50 // Globals to remember control settings during a session
51 static bool g_modifyTracks = true;
52 static bool g_modifyVias = true;
53 
54 // These settings go with a particular board, so we save the boardID.
56 static bool g_filterByNetclass;
57 static wxString g_netclassFilter;
58 static bool g_filterByNet;
59 static wxString g_netFilter;
60 static bool g_filterByLayer;
62 
63 
65 {
66 private:
71 
72 public:
75 
76 private:
77  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
78  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
79 
80  bool TransferDataToWindow() override;
81  bool TransferDataFromWindow() override;
82 
83  void OnUpdateUI( wxUpdateUIEvent& event ) override;
84  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
85  void AdjustNetclassGridColumns( int aWidth );
86 
87  void OnNetFilterSelect( wxCommandEvent& event )
88  {
89  m_netFilterOpt->SetValue( true );
90  }
91  void OnNetclassFilterSelect( wxCommandEvent& event ) override
92  {
93  m_netclassFilterOpt->SetValue( true );
94  }
95  void OnLayerFilterSelect( wxCommandEvent& event ) override
96  {
97  m_layerFilterOpt->SetValue( true );
98  }
99 
100  void buildNetclassesGrid();
101  void buildFilterLists();
102 };
103 
104 
107 {
108  m_parent = aParent;
109  m_brd = m_parent->GetBoard();
110 
111  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
112 
113  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
114  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
115 
116  m_failedDRC = false;
117 
119 
122 
124  m_layerBox->SetLayersHotkeys( false );
126  m_layerBox->Resync();
127 
128  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
129  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
130  m_netclassGrid->SetDefaultCellFont( infoFont );
132 
133  m_netclassGrid->SetCellHighlightPenWidth( 0 );
134  m_sdbSizerOK->SetDefault();
135 
136  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
137 
139 }
140 
141 
143 {
145  g_modifyTracks = m_tracks->GetValue();
146  g_modifyVias = m_vias->GetValue();
148  g_netclassFilter = m_netclassFilter->GetStringSelection();
149  g_filterByNet = m_netFilterOpt->GetValue();
151  g_filterByLayer = m_layerFilterOpt->GetValue();
153 
154  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
155 
156  delete[] m_originalColWidths;
157 }
158 
159 
161 {
162  // Populate the net filter list with net names
165 
166  // Populate the netclass filter list with netclass names
167  wxArrayString netclassNames;
169 
170  netclassNames.push_back(netclasses.GetDefault()->GetName() );
171 
172  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
173  netclassNames.push_back( nc->second->GetName() );
174 
175  m_netclassFilter->Set( netclassNames );
177 
178  // Populate the layer filter list
184 }
185 
186 
188 {
189 #define SET_NETCLASS_VALUE( row, col, val ) \
190  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true, true ) )
191 
192  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
193  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
194  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
195  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
196  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
197 
199  NETCLASSPTR defaultNetclass = m_brd->GetDesignSettings().GetDefault();
200  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
201 
202  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
203  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
204  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
205  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
206  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
207  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
208 
209  int row = 2;
210  for( const auto& netclass : netclasses )
211  {
212  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
213  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
214  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
215  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
216  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
217  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
218  row++;
219  }
220 }
221 
222 
224 {
225  auto item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_parent->GetCurItem() );
226 
227  m_tracks->SetValue( g_modifyTracks );
228  m_vias->SetValue( g_modifyVias );
229 
231  {
232  m_netclassFilter->SetStringSelection( g_netclassFilter );
233  m_netclassFilterOpt->SetValue( true );
234  }
235  else if( item )
236  m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() );
237 
239  {
241  m_netFilterOpt->SetValue( true );
242  }
243  else if( item )
244  m_netFilter->SetSelectedNetcode( item->GetNetCode() );
245 
247  {
249  m_layerFilterOpt->SetValue( true );
250  }
251  else if( item )
252  m_layerFilter->SetLayerSelection( item->GetLayer() );
253 
254  return true;
255 }
256 
257 
259 {
260  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
261  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
262 
263  if( m_failedDRC )
264  {
265  m_failedDRC = false;
266  DisplayError( this, _( "Some items failed DRC and were not modified." ) );
267  }
268 }
269 
270 
272 {
274 
275  if( m_setToSpecifiedValues->GetValue() )
276  {
277  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
278  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
279  {
280  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
281  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
282 
283  if( !m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ) )
284  m_failedDRC = true;
285  }
286  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
287  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
288 
289  if( m_layerBox->GetLayerSelection() != UNDEFINED_LAYER && aItem->Type() == PCB_TRACE_T )
290  {
291  if( aUndoList->FindItem( aItem ) < 0 )
292  {
293  ITEM_PICKER picker( aItem, UR_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  if( !m_parent->SetTrackSegmentWidth( aItem, aUndoList, true ) )
305  m_failedDRC = true;
306  }
307 }
308 
309 
311 {
312  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
313  {
314  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
315  return;
316  }
317 
318  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
319  {
320  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
321  return;
322  }
323 
325  {
326  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
327  return;
328  }
329 
330  processItem( aUndoList, aItem );
331 }
332 
333 
335 {
336  PICKED_ITEMS_LIST itemsListPicker;
337  wxBusyCursor dummy;
338 
339  // Examine segments
340  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
341  {
342  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
343  visitItem( &itemsListPicker, segment );
344  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
345  visitItem( &itemsListPicker, segment );
346  }
347 
348  if( itemsListPicker.GetCount() > 0 )
349  {
350  m_parent->SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
351 
352  if( m_parent->IsGalCanvasActive() )
353  {
354  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
355  m_parent->GetGalCanvas()->GetView()->Update( segment );
356  }
357  else
358  m_parent->GetCanvas()->Refresh();
359  }
360 
361  return !m_failedDRC;
362 }
363 
364 
366 {
367  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
368  {
369  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
370  aWidth -= m_originalColWidths[ i ];
371  }
372 
373  m_netclassGrid->SetColSize( 0, aWidth );
374 }
375 
376 
378 {
379  AdjustNetclassGridColumns( event.GetSize().GetX() );
380  event.Skip();
381 }
382 
383 
384 void PCB_EDIT_FRAME::OnEditTracksAndVias( wxCommandEvent& event )
385 {
387  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
388 }
389 
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
NETCLASSPTR GetDefault() const
Function GetDefault.
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:385
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
void UpdateTrackWidthSelectBox(wxComboBox *aTrackWidthSelectBox)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
This file is part of the common library.
void SetNotAllowedLayerSet(LSET aMask)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static LAYER_NUM g_layerFilter
Class BOARD to handle a board.
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:699
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.
static wxString g_netclassFilter
BOARD * GetBoard() const
int GetSelectedNetcode()
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
iterator end()
Definition: netclass.h:249
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
static timestamp_t g_boardID
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
void SetLink(EDA_ITEM *aItem)
wxString GetSelectedNetname()
void OnNetclassFilterSelect(wxCommandEvent &event) override
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:251
void OnUpdateUI(wxUpdateUIEvent &event) override
bool SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Function SetTrackSegmentWidth Modify one track segment width or one via diameter (using DRC control)...
void processItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
unsigned GetViaSizeIndex() const
Function GetViaSizeIndex.
static bool g_modifyTracks
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
void OnEditTracksAndVias(wxCommandEvent &event)
Function OnEditTracksAndVias Dialog for editing the properties of tracks and vias, selected by net, netclass, and/or layer.
iterator begin()
Definition: netclass.h:248
Class NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:224
#define SET_NETCLASS_VALUE(row, col, val)
const wxString & GetCurrentNetClassName() const
Function GetCurrentNetClassName.
int ShowQuasiModal()
void SetSelectedNetcode(int aNetcode)
static bool g_filterByNetclass
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
int SetLayerSelection(LAYER_NUM layer)
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:918
void OnLayerFilterSelect(wxCommandEvent &event) override
static bool g_filterByLayer
void SetNetInfo(NETINFO_LIST *aNetInfoList)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0)) override
Function SaveCopyInUndoList Creates a new entry in undo list of commands.
Definition: undo_redo.cpp:202
static bool g_modifyVias
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
bool SetLayersHotkeys(bool value)
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:756
static wxString g_netFilter
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
unsigned GetCount() const
Function GetCount.
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:259
int GetNetCode() const
Function GetNetCode.
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
TRACK * Next() const
Definition: class_track.h:103
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268
size_t i
Definition: json11.cpp:597
LAYER_NUM GetLayerSelection() const
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void SetSelectedNet(const wxString &aNetname)
void UpdateViaSizeSelectBox(wxComboBox *aViaSizeSelectBox)
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:925
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
wxString GetNetClassName() const
Function GetNetClassName returns a pointer to the netclass of the zone.
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:373
DLIST< TRACK > m_Track
Definition: class_board.h:250
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void OnSizeNetclassGrid(wxSizeEvent &event) override
int FindItem(const EDA_ITEM *aItem) const
Function FindItem.
BOARD_ITEM * GetCurItem()
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:297
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.