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_board.h>
30 #include <view/view.h>
31 #include <pcb_layer_box_selector.h>
32 #include <tool/tool_manager.h>
33 #include <tool/selection.h>
34 #include <tools/selection_tool.h>
35 #include <tools/global_edit_tool.h>
37 
38 // Columns of netclasses grid
39 enum {
40  GRID_NAME = 0,
46  GRID_DIFF_PAIR_WIDTH, // not currently included in grid
47  GRID_DIFF_PAIR_GAP, // not currently included in grid
48  GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
49 };
50 
51 
52 // Globals to remember control settings during a session
53 static bool g_modifyTracks = true;
54 static bool g_modifyVias = true;
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:
70 
71 public:
74 
75 private:
76  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
77  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
78 
79  bool TransferDataToWindow() override;
80  bool TransferDataFromWindow() override;
81 
82  void OnUpdateUI( wxUpdateUIEvent& event ) override;
83  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
84  void AdjustNetclassGridColumns( int aWidth );
85 
86  void OnNetFilterSelect( wxCommandEvent& event )
87  {
88  m_netFilterOpt->SetValue( true );
89  }
90  void OnNetclassFilterSelect( wxCommandEvent& event ) override
91  {
92  m_netclassFilterOpt->SetValue( true );
93  }
94  void OnLayerFilterSelect( wxCommandEvent& event ) override
95  {
96  m_layerFilterOpt->SetValue( true );
97  }
98 
99  void buildNetclassesGrid();
100  void buildFilterLists();
101 };
102 
103 
106 {
107  m_parent = aParent;
108  m_brd = m_parent->GetBoard();
109 
110  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
111 
112  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
113  m_originalColWidths[ i ] = m_netclassGrid->GetColSize( i );
114 
115  m_failedDRC = false;
116 
118 
121 
123  m_layerBox->SetLayersHotkeys( false );
125  m_layerBox->Resync();
126 
127  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
128  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
129  m_netclassGrid->SetDefaultCellFont( infoFont );
131 
132  m_netclassGrid->SetCellHighlightPenWidth( 0 );
133  m_sdbSizerOK->SetDefault();
134 
135  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
136 
138 }
139 
140 
142 {
143  g_modifyTracks = m_tracks->GetValue();
144  g_modifyVias = m_vias->GetValue();
146  g_netclassFilter = m_netclassFilter->GetStringSelection();
147  g_filterByNet = m_netFilterOpt->GetValue();
149  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  // Populate the netclass filter list with netclass names
165  wxArrayString netclassNames;
167 
168  netclassNames.push_back(netclasses.GetDefault()->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, 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 
197  NETCLASSPTR 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  return true;
248 }
249 
250 
252 {
253  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
254  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
255 
256  if( m_failedDRC )
257  {
258  m_failedDRC = false;
259  DisplayError( this, _( "Some items failed DRC and were not modified." ) );
260  }
261 }
262 
263 
265 {
267 
268  if( m_setToSpecifiedValues->GetValue() )
269  {
270  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
271  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
272  {
273  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
274  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
275 
276  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ) == TRACK_ACTION_DRC_ERROR )
277  m_failedDRC = true;
278  }
279  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
280  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
281 
282  if( m_layerBox->GetLayerSelection() != UNDEFINED_LAYER && aItem->Type() == PCB_TRACE_T )
283  {
284  if( aUndoList->FindItem( aItem ) < 0 )
285  {
286  ITEM_PICKER picker( aItem, UR_CHANGED );
287  picker.SetLink( aItem->Clone() );
288  aUndoList->PushItem( picker );
289  }
290 
292  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
293  }
294  }
295  else
296  {
297  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, true ) == TRACK_ACTION_DRC_ERROR )
298  m_failedDRC = true;
299  }
300 }
301 
302 
304 {
305  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
306  {
307  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
308  return;
309  }
310 
311  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
312  {
313  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
314  return;
315  }
316 
318  {
319  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
320  return;
321  }
322 
323  processItem( aUndoList, aItem );
324 }
325 
326 
328 {
329  PICKED_ITEMS_LIST itemsListPicker;
330  wxBusyCursor dummy;
331 
332  // Examine segments
333  for( auto segment : m_brd->Tracks() )
334  {
335  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
336  visitItem( &itemsListPicker, segment );
337  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
338  visitItem( &itemsListPicker, segment );
339  }
340 
341  if( itemsListPicker.GetCount() > 0 )
342  {
343  m_parent->SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
344 
345  for( auto segment : m_brd->Tracks() )
346  m_parent->GetCanvas()->GetView()->Update( segment );
347  }
348 
349  return !m_failedDRC;
350 }
351 
352 
354 {
355  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
356  {
357  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
358  aWidth -= m_originalColWidths[ i ];
359  }
360 
361  m_netclassGrid->SetColSize( 0, aWidth );
362 }
363 
364 
366 {
367  AdjustNetclassGridColumns( event.GetSize().GetX() );
368  event.Skip();
369 }
370 
371 
373 {
374  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
375  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
376 
377  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
378  return 0;
379 }
380 
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
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.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
int GetNetCode() const
Function GetNetCode.
int FindItem(const EDA_ITEM *aItem) const
Function FindItem.
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:91
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 SELECTION_TOOL.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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.
Definition: class_track.cpp:68
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).
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
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:96
static bool g_modifyTracks
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
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)
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()
Class TOOL_EVENT.
Definition: tool_event.h:171
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:301
static bool g_filterByNetclass
int SetLayerSelection(LAYER_NUM layer)
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:182
static bool g_modifyVias
bool SetLayersHotkeys(bool value)
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:738
#define _(s)
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
Type LAYER_NUM can be replaced with int and removed.
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:377
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
NETCLASSPTR GetDefault() const
Function GetDefault.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
size_t i
Definition: json11.cpp:649
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:97
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aEdit=true)
BOARD * GetBoard() const
void OnSizeNetclassGrid(wxSizeEvent &event) override
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:813
TRACKS & Tracks()
Definition: class_board.h:218
EDA_ITEM * Front() const
Definition: selection.h:182
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.