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 <pcb_edit_frame.h>
27 #include <class_drawpanel.h>
28 #include <class_board.h>
30 #include <view/view.h>
31 #include <pcb_layer_box_selector.h>
32 
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 
53 // These settings go with a particular board, so we save the boardID.
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 
62 
64 {
65 private:
69 
70 public:
73 
74 private:
75  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
76  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
77 
78  bool TransferDataToWindow() override;
79  bool TransferDataFromWindow() override;
80 
81  void OnUpdateUI( wxUpdateUIEvent& event ) override;
82  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
83  void AdjustNetclassGridColumns( int aWidth );
84 
85  void OnNetFilterSelect( wxCommandEvent& event )
86  {
87  m_netFilterOpt->SetValue( true );
88  }
89  void OnNetclassFilterSelect( wxCommandEvent& event ) override
90  {
91  m_netclassFilterOpt->SetValue( true );
92  }
93  void OnLayerFilterSelect( wxCommandEvent& event ) override
94  {
95  m_layerFilterOpt->SetValue( true );
96  }
97 
98  void buildNetclassesGrid();
99  void buildFilterLists();
100 };
101 
102 
105 {
106  m_parent = aParent;
107  m_brd = m_parent->GetBoard();
108 
109  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
110 
111  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
112  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
113 
115 
118 
120  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 {
141  g_modifyTracks = m_tracks->GetValue();
142  g_modifyVias = m_vias->GetValue();
144  g_netclassFilter = m_netclassFilter->GetStringSelection();
145  g_filterByNet = m_netFilterOpt->GetValue();
147  g_filterByLayer = m_layerFilterOpt->GetValue();
149 
150  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
151 
152  delete[] m_originalColWidths;
153 }
154 
155 
157 {
158  // Populate the net filter list with net names
161 
162  // Populate the netclass filter list with netclass names
163  wxArrayString netclassNames;
165 
166  netclassNames.push_back(netclasses.GetDefault()->GetName() );
167 
168  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
169  netclassNames.push_back( nc->second->GetName() );
170 
171  m_netclassFilter->Set( netclassNames );
173 
174  // Populate the layer filter list
180 }
181 
182 
184 {
185 #define SET_NETCLASS_VALUE( row, col, val ) \
186  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true, true ) )
187 
188  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
189  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
190  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
191  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
192  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
193 
195  NETCLASSPTR defaultNetclass = m_brd->GetDesignSettings().GetDefault();
196  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
197 
198  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
199  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
200  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
201  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
202  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
203  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
204 
205  int row = 2;
206  for( const auto& netclass : netclasses )
207  {
208  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
209  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
210  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
211  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
212  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
213  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
214  row++;
215  }
216 }
217 
218 
220 {
221  auto item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_parent->GetCurItem() );
222 
223  m_tracks->SetValue( g_modifyTracks );
224  m_vias->SetValue( g_modifyVias );
225 
227  {
228  m_netclassFilter->SetStringSelection( g_netclassFilter );
229  m_netclassFilterOpt->SetValue( true );
230  }
231  else if( item )
232  m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() );
233 
235  {
237  m_netFilterOpt->SetValue( true );
238  }
239  else if( item )
240  m_netFilter->SetSelectedNetcode( item->GetNetCode() );
241 
243  {
245  m_layerFilterOpt->SetValue( true );
246  }
247  else if( item )
248  m_layerFilter->SetLayerSelection( item->GetLayer() );
249 
250  return true;
251 }
252 
253 
255 {
256  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
257  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
258 }
259 
260 
262 {
264 
265  if( m_setToSpecifiedValues->GetValue() )
266  {
267  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
268  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
269  {
270  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
271  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
272  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
273  }
274  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
275  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
276 
277  if( m_layerBox->GetLayerSelection() != UNDEFINED_LAYER && aItem->Type() == PCB_TRACE_T )
278  {
279  if( aUndoList->FindItem( aItem ) < 0 )
280  {
281  ITEM_PICKER picker( aItem, UR_CHANGED );
282  picker.SetLink( aItem->Clone() );
283  aUndoList->PushItem( picker );
284  }
285 
287  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
288  }
289  }
290  else
291  {
292  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
293  }
294 }
295 
296 
298 {
299  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
300  {
301  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
302  return;
303  }
304 
305  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
306  {
307  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
308  return;
309  }
310 
312  {
313  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
314  return;
315  }
316 
317  processItem( aUndoList, aItem );
318 }
319 
320 
322 {
323  PICKED_ITEMS_LIST itemsListPicker;
324  wxBusyCursor dummy;
325 
326  // Examine segments
327  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
328  {
329  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
330  visitItem( &itemsListPicker, segment );
331  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
332  visitItem( &itemsListPicker, segment );
333  }
334 
335  if( itemsListPicker.GetCount() > 0 )
336  {
337  m_parent->SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
338 
339  if( m_parent->IsGalCanvasActive() )
340  {
341  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
342  m_parent->GetGalCanvas()->GetView()->Update( segment );
343  }
344  else
345  m_parent->GetCanvas()->Refresh();
346  }
347 
348  return true;
349 }
350 
351 
353 {
354  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
355  {
356  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
357  aWidth -= m_originalColWidths[ i ];
358  }
359 
360  m_netclassGrid->SetColSize( 0, aWidth );
361 }
362 
363 
365 {
366  AdjustNetclassGridColumns( event.GetSize().GetX() );
367  event.Skip();
368 }
369 
370 
371 void PCB_EDIT_FRAME::OnEditTracksAndVias( wxCommandEvent& event )
372 {
374  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
375 }
376 
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox)
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:388
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
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:696
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:538
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:911
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:1521
bool SetLayersHotkeys(bool value)
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:750
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:99
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:170
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)
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:918
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:372
DLIST< TRACK > m_Track
Definition: class_board.h:249
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()
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:296
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.