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>
29 #include <class_track.h>
31 #include <view/view.h>
32 #include <pcb_layer_box_selector.h>
33 #include <tool/tool_manager.h>
34 #include <tool/selection.h>
35 #include <tools/selection_tool.h>
36 #include <tools/global_edit_tool.h>
38 
39 // Columns of netclasses grid
40 enum {
41  GRID_NAME = 0,
47  GRID_DIFF_PAIR_WIDTH, // not currently included in grid
48  GRID_DIFF_PAIR_GAP, // not currently included in grid
49  GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
50 };
51 
52 
53 // Globals to remember control settings during a session
54 static bool g_modifyTracks = true;
55 static bool g_modifyVias = true;
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 
124 
126  m_layerBox->SetLayersHotkeys( false );
129  m_layerBox->Resync();
130 
131  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
132  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
133  m_netclassGrid->SetDefaultCellFont( infoFont );
135 
136  m_netclassGrid->SetCellHighlightPenWidth( 0 );
137  m_sdbSizerOK->SetDefault();
138 
139  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
140 
142 }
143 
144 
146 {
147  g_modifyTracks = m_tracks->GetValue();
148  g_modifyVias = m_vias->GetValue();
150  g_netclassFilter = m_netclassFilter->GetStringSelection();
151  g_filterByNet = m_netFilterOpt->GetValue();
153  g_filterByLayer = m_layerFilterOpt->GetValue();
155 
156  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
157 
158  delete[] m_originalColWidths;
159 }
160 
161 
163 {
164  // Populate the net filter list with net names
167 
168  if( !m_brd->GetHighLightNetCodes().empty() )
170 
171  // Populate the netclass filter list with netclass names
172  wxArrayString netclassNames;
173  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
174 
175  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
176 
177  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
178  netclassNames.push_back( nc->second->GetName() );
179 
180  m_netclassFilter->Set( netclassNames );
182 
183  // Populate the layer filter list
189 }
190 
191 
193 {
194 #define SET_NETCLASS_VALUE( row, col, val ) \
195  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true, true ) )
196 
197  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
198  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
199  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
200  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
201  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
202 
203  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
204  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
205  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
206 
207  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
208  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
209  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
210  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
211  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
212  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
213 
214  int row = 2;
215  for( const auto& netclass : netclasses )
216  {
217  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
218  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
219  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
220  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
221  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
222  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
223  row++;
224  }
225 }
226 
227 
229 {
230  PCBNEW_SELECTION& selection = m_parent->GetToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
231  auto item = dynamic_cast<BOARD_CONNECTED_ITEM*>( selection.Front() );
232 
233  m_tracks->SetValue( g_modifyTracks );
234  m_vias->SetValue( g_modifyVias );
235 
236  if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
237  m_netclassFilterOpt->SetValue( true );
238  else if( item )
239  m_netclassFilter->SetStringSelection( item->GetNet()->GetClassName() );
240 
241  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
242  {
244  m_netFilterOpt->SetValue( true );
245  }
246  else if( item )
247  m_netFilter->SetSelectedNetcode( item->GetNetCode() );
248 
250  m_layerFilterOpt->SetValue( true );
251  else if( item )
252  m_layerFilter->SetLayerSelection( item->GetLayer() );
253 
254  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
255  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
256  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
257 
258  return true;
259 }
260 
261 
263 {
264  m_trackWidthSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
265  m_viaSizesSelectBox->Enable( m_setToSpecifiedValues->GetValue() );
266 
267  if( m_failedDRC )
268  {
269  m_failedDRC = false;
270  DisplayError( this, _( "Some items failed DRC and were not modified." ) );
271  }
272 }
273 
274 
276 {
278  bool isTrack = aItem->Type() == PCB_TRACE_T;
279  bool isVia = aItem->Type() == PCB_VIA_T;
280 
281  if( m_setToSpecifiedValues->GetValue() )
282  {
283  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
284  {
285  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
286  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
287 
288  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ) == TRACK_ACTION_DRC_ERROR )
289  m_failedDRC = true;
290 
291  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
292  }
293  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
294  {
295  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
296  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
297 
298  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, false ) == TRACK_ACTION_DRC_ERROR )
299  m_failedDRC = true;
300 
301  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
302  }
303 
304  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
305  {
306  if( aUndoList->FindItem( aItem ) < 0 )
307  {
308  ITEM_PICKER picker( nullptr, aItem, UR_CHANGED );
309  picker.SetLink( aItem->Clone() );
310  aUndoList->PushItem( picker );
311  }
312 
314  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
315  }
316  }
317  else
318  {
319  if( m_parent->SetTrackSegmentWidth( aItem, aUndoList, true ) == TRACK_ACTION_DRC_ERROR )
320  m_failedDRC = true;
321  }
322 
323  m_brd->OnItemChanged( aItem );
324 }
325 
326 
328 {
329  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
330  {
331  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
332  return;
333  }
334 
335  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
336  {
337  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
338  return;
339  }
340 
342  {
343  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
344  return;
345  }
346 
347  processItem( aUndoList, aItem );
348 }
349 
350 
352 {
353  PICKED_ITEMS_LIST itemsListPicker;
354  wxBusyCursor dummy;
355 
356  // Examine segments
357  for( auto segment : m_brd->Tracks() )
358  {
359  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
360  visitItem( &itemsListPicker, segment );
361  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
362  visitItem( &itemsListPicker, segment );
363  }
364 
365  if( itemsListPicker.GetCount() > 0 )
366  {
367  m_parent->SaveCopyInUndoList( itemsListPicker, UR_CHANGED );
368 
369  for( auto segment : m_brd->Tracks() )
370  m_parent->GetCanvas()->GetView()->Update( segment );
371  }
372 
373  return !m_failedDRC;
374 }
375 
376 
378 {
379  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
380  {
381  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
382  aWidth -= m_originalColWidths[ i ];
383  }
384 
385  m_netclassGrid->SetColSize( 0, aWidth );
386 }
387 
388 
390 {
391  AdjustNetclassGridColumns( event.GetSize().GetX() );
392  event.Skip();
393 }
394 
395 
397 {
398  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
399  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
400 
401  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
402  return 0;
403 }
404 
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
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 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:92
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)
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()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:735
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:45
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:553
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: class_board.h:741
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
iterator end()
Definition: netclass.h:243
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:245
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:168
iterator begin()
Definition: netclass.h:242
NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:222
#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:174
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:355
static bool g_filterByNetclass
int SetLayerSelection(LAYER_NUM layer)
NETCLASSES & GetNetClasses() const
void OnLayerFilterSelect(wxCommandEvent &event) override
int GetuViaDiameter() const
Definition: netclass.h:177
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:267
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:177
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
Type LAYER_NUM can be replaced with int and removed.
void SetUndefinedLayerName(const wxString &aName)
const std::set< int > & GetHighLightNetCodes() const
Function GetHighLightNetCode.
Definition: class_board.h:399
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.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
#define INDETERMINATE_ACTION
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:171
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:253
int GetuViaDrill() const
Definition: netclass.h:180
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:74
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:849
TRACKS & Tracks()
Definition: class_board.h:257
EDA_ITEM * Front() const
Definition: selection.h:184
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.