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 static bool g_filterByNetclass;
54 static wxString g_netclassFilter;
55 static bool g_filterByNet;
56 static wxString g_netFilter;
57 static bool g_filterByLayer;
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 
113  m_failedDRC = false;
114 
116 
119 
121  m_layerBox->SetLayersHotkeys( false );
123  m_layerBox->Resync();
124 
125  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
126  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
127  m_netclassGrid->SetDefaultCellFont( infoFont );
129 
130  m_netclassGrid->SetCellHighlightPenWidth( 0 );
131  m_sdbSizerOK->SetDefault();
132 
133  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
134 
136 }
137 
138 
140 {
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 
226  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
227  m_netclassFilterOpt->SetValue( true );
228  else if( item )
229  m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() );
230 
231  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
232  {
234  m_netFilterOpt->SetValue( true );
235  }
236  else if( item )
237  m_netFilter->SetSelectedNetcode( item->GetNetCode() );
238 
240  m_layerFilterOpt->SetValue( true );
241  else if( item )
242  m_layerFilter->SetLayerSelection( item->GetLayer() );
243 
244  return true;
245 }
246 
247 
249 {
250  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
251  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
252 
253  if( m_failedDRC )
254  {
255  m_failedDRC = false;
256  DisplayError( this, _( "Some items failed DRC and were not modified." ) );
257  }
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 
273  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ) == TRACK_ACTION_DRC_ERROR )
274  m_failedDRC = true;
275  }
276  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
277  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
278 
279  if( m_layerBox->GetLayerSelection() != UNDEFINED_LAYER && aItem->Type() == PCB_TRACE_T )
280  {
281  if( aUndoList->FindItem( aItem ) < 0 )
282  {
283  ITEM_PICKER picker( aItem, UR_CHANGED );
284  picker.SetLink( aItem->Clone() );
285  aUndoList->PushItem( picker );
286  }
287 
289  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
290  }
291  }
292  else
293  {
294  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, true ) == TRACK_ACTION_DRC_ERROR )
295  m_failedDRC = true;
296  }
297 }
298 
299 
301 {
302  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
303  {
304  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
305  return;
306  }
307 
308  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
309  {
310  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
311  return;
312  }
313 
315  {
316  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
317  return;
318  }
319 
320  processItem( aUndoList, aItem );
321 }
322 
323 
325 {
326  PICKED_ITEMS_LIST itemsListPicker;
327  wxBusyCursor dummy;
328 
329  // Examine segments
330  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
331  {
332  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
333  visitItem( &itemsListPicker, segment );
334  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
335  visitItem( &itemsListPicker, segment );
336  }
337 
338  if( itemsListPicker.GetCount() > 0 )
339  {
340  m_parent->SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
341 
342  if( m_parent->IsGalCanvasActive() )
343  {
344  for( TRACK* segment = m_brd->m_Track; segment != nullptr; segment = segment->Next() )
345  m_parent->GetGalCanvas()->GetView()->Update( segment );
346  }
347  else
348  m_parent->GetCanvas()->Refresh();
349  }
350 
351  return !m_failedDRC;
352 }
353 
354 
356 {
357  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
358  {
359  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
360  aWidth -= m_originalColWidths[ i ];
361  }
362 
363  m_netclassGrid->SetColSize( 0, aWidth );
364 }
365 
366 
368 {
369  AdjustNetclassGridColumns( event.GetSize().GetX() );
370  event.Skip();
371 }
372 
373 
374 void PCB_EDIT_FRAME::OnEditTracksAndVias( wxCommandEvent& event )
375 {
377  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
378 }
379 
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches 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.
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)
static LAYER_NUM g_layerFilter
Class BOARD to handle a board.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
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
int SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Function SetTrackSegmentWidth Modify one track segment width or one via diameter (using DRC control).
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, const bool aEdit=true)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:539
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)
TRACK_ACTION_DRC_ERROR - Track not changed to to DRC.
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:251
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)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
static bool g_modifyTracks
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:928
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
LAYER_NUM GetLayerSelection() const
void OnEditTracksAndVias(wxCommandEvent &event)
Function OnEditTracksAndVias Dialog for editing the properties of tracks and vias,...
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.
unsigned GetViaSizeIndex() const
Function GetViaSizeIndex.
int ShowQuasiModal()
void SetSelectedNetcode(int aNetcode)
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:297
static bool g_filterByNetclass
int SetLayerSelection(LAYER_NUM layer)
void OnLayerFilterSelect(wxCommandEvent &event) override
static bool g_filterByLayer
void SetNetInfo(NETINFO_LIST *aNetInfoList)
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:395
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:1539
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.
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:373
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, const bool aEdit=true)
NETCLASSPTR GetDefault() const
Function GetDefault.
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
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
size_t i
Definition: json11.cpp:597
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void SetSelectedNet(const wxString &aNetname)
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:259
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< TRACK > m_Track
Definition: class_board.h:250
BOARD * GetBoard() const
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void OnSizeNetclassGrid(wxSizeEvent &event) override
BOARD_ITEM * GetCurItem()
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:243
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.