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-2020 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 <pcb_edit_frame.h>
26 #include <board.h>
27 #include <track.h>
29 #include <pcb_layer_box_selector.h>
30 #include <tool/tool_manager.h>
32 #include <tools/global_edit_tool.h>
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 static bool g_filterByNetclass;
53 static wxString g_netclassFilter;
54 static bool g_filterByNet;
55 static wxString g_netFilter;
56 static bool g_filterByLayer;
58 static bool g_filterSelected = false;
59 
60 
62 {
63 private:
68 
69 public:
72 
73 protected:
74  void onSpecifiedValuesUpdateUi( wxUpdateUIEvent& event ) override;
75  void OnSizeNetclassGrid( wxSizeEvent& event ) override;
76 
77  void OnNetclassFilterSelect( wxCommandEvent& event ) override
78  {
79  m_netclassFilterOpt->SetValue( true );
80  }
81  void OnLayerFilterSelect( wxCommandEvent& event ) override
82  {
83  m_layerFilterOpt->SetValue( true );
84  }
85 
86 private:
87  void visitItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
88  void processItem( PICKED_ITEMS_LIST* aUndoList, TRACK* aItem );
89 
90  bool TransferDataToWindow() override;
91  bool TransferDataFromWindow() override;
92 
93  void AdjustNetclassGridColumns( int aWidth );
94 
95  void OnNetFilterSelect( wxCommandEvent& event )
96  {
97  m_netFilterOpt->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 
117 
122 
124  m_layerBox->SetLayersHotkeys( false );
127  m_layerBox->Resync();
128 
129  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
130  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
131  m_netclassGrid->SetDefaultCellFont( infoFont );
133 
134  m_netclassGrid->SetCellHighlightPenWidth( 0 );
135  m_sdbSizerOK->SetDefault();
136 
137  m_netFilter->Connect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
138 
140 }
141 
142 
144 {
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();
154 
155  m_netFilter->Disconnect( NET_SELECTED, wxCommandEventHandler( DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnNetFilterSelect ), NULL, this );
156 
157  delete[] m_originalColWidths;
158 }
159 
160 
162 {
163  // Populate the net filter list with net names
166 
167  if( !m_brd->GetHighLightNetCodes().empty() )
169 
170  // Populate the netclass filter list with netclass names
171  wxArrayString netclassNames;
172  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
173 
174  netclassNames.push_back( netclasses.GetDefaultPtr()->GetName() );
175 
176  for( NETCLASSES::const_iterator nc = netclasses.begin(); nc != netclasses.end(); ++nc )
177  netclassNames.push_back( nc->second->GetName() );
178 
179  m_netclassFilter->Set( netclassNames );
181 
182  // Populate the layer filter list
188 }
189 
190 
192 {
193 #define SET_NETCLASS_VALUE( row, col, val ) \
194  m_netclassGrid->SetCellValue( row, col, StringFromValue( GetUserUnits(), val, true ) )
195 
196  m_netclassGrid->SetCellValue( 0, GRID_TRACKSIZE, _( "Track Width" ) );
197  m_netclassGrid->SetCellValue( 0, GRID_VIASIZE, _( "Via Size" ) );
198  m_netclassGrid->SetCellValue( 0, GRID_VIADRILL, _( "Via Drill" ) );
199  m_netclassGrid->SetCellValue( 0, GRID_uVIASIZE, _( "uVia Size" ) );
200  m_netclassGrid->SetCellValue( 0, GRID_uVIADRILL, _( "uVia Drill" ) );
201 
202  NETCLASSES& netclasses = m_brd->GetDesignSettings().GetNetClasses();
203  NETCLASS* defaultNetclass = m_brd->GetDesignSettings().GetDefault();
204  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 );
205 
206  m_netclassGrid->SetCellValue( 1, GRID_NAME, defaultNetclass->GetName() );
207  SET_NETCLASS_VALUE( 1, GRID_TRACKSIZE, defaultNetclass->GetTrackWidth() );
208  SET_NETCLASS_VALUE( 1, GRID_VIASIZE, defaultNetclass->GetViaDiameter() );
209  SET_NETCLASS_VALUE( 1, GRID_VIADRILL, defaultNetclass->GetViaDrill() );
210  SET_NETCLASS_VALUE( 1, GRID_uVIASIZE, defaultNetclass->GetuViaDiameter() );
211  SET_NETCLASS_VALUE( 1, GRID_uVIADRILL, defaultNetclass->GetuViaDrill() );
212 
213  int row = 2;
214  for( const auto& netclass : netclasses )
215  {
216  m_netclassGrid->SetCellValue( row, GRID_NAME, netclass.first );
217  SET_NETCLASS_VALUE( row, GRID_TRACKSIZE, netclass.second->GetTrackWidth() );
218  SET_NETCLASS_VALUE( row, GRID_VIASIZE, netclass.second->GetViaDiameter() );
219  SET_NETCLASS_VALUE( row, GRID_VIADRILL, netclass.second->GetViaDrill() );
220  SET_NETCLASS_VALUE( row, GRID_uVIASIZE, netclass.second->GetuViaDiameter() );
221  SET_NETCLASS_VALUE( row, GRID_uVIADRILL, netclass.second->GetuViaDrill() );
222  row++;
223  }
224 }
225 
226 
228 {
230  m_selection = selTool->GetSelection();
231  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( m_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()->GetNetClassName() );
240 
241  if( g_filterByNet && m_brd->FindNet( g_netFilter ) != NULL )
242  {
244  m_netFilterOpt->SetValue( true );
245  }
246  else if( item )
247  {
249  }
250 
252  m_layerFilterOpt->SetValue( true );
253  else if( item )
255 
256  m_trackWidthSelectBox->SetSelection( (int) m_trackWidthSelectBox->GetCount() - 1 );
257  m_viaSizesSelectBox->SetSelection( (int) m_viaSizesSelectBox->GetCount() - 1 );
258  m_layerBox->SetStringSelection( INDETERMINATE_ACTION );
259 
261 
262  return true;
263 }
264 
265 
267 {
268  // Enable the items in the use specified values section
269  event.Enable( m_setToSpecifiedValues->GetValue() );
270 }
271 
272 
274 {
276  bool isTrack = aItem->Type() == PCB_TRACE_T;
277  bool isVia = aItem->Type() == PCB_VIA_T;
278 
279  if( m_setToSpecifiedValues->GetValue() )
280  {
281  if( isTrack && m_trackWidthSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
282  {
283  unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
284  brdSettings.SetTrackWidthIndex( (unsigned) m_trackWidthSelectBox->GetSelection() );
285 
286  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
287 
288  brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
289  }
290  else if( isVia && m_viaSizesSelectBox->GetStringSelection() != INDETERMINATE_ACTION )
291  {
292  unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
293  brdSettings.SetViaSizeIndex( (unsigned) m_viaSizesSelectBox->GetSelection() );
294 
295  m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
296 
297  brdSettings.SetViaSizeIndex( prevViaSizeIndex );
298  }
299 
300  if( isTrack && m_layerBox->GetLayerSelection() != UNDEFINED_LAYER )
301  {
302  if( aUndoList->FindItem( aItem ) < 0 )
303  {
304  ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
305  picker.SetLink( aItem->Clone() );
306  aUndoList->PushItem( picker );
307  }
308 
310  m_parent->GetBoard()->GetConnectivity()->Update( aItem );
311  }
312  }
313  else
314  {
315  m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
316  }
317 
318  m_brd->OnItemChanged( aItem );
319 }
320 
321 
323 {
324  if( m_selectedItemsFilter->GetValue() && !m_selection.Contains( aItem ) )
325  return;
326 
327  if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
328  {
329  if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
330  return;
331  }
332 
333  if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
334  {
335  if( aItem->GetNetClassName() != m_netclassFilter->GetStringSelection() )
336  return;
337  }
338 
340  {
341  if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
342  return;
343  }
344 
345  processItem( aUndoList, aItem );
346 }
347 
348 
350 {
351  PICKED_ITEMS_LIST itemsListPicker;
352  wxBusyCursor dummy;
353 
354  // Examine segments
355  for( auto segment : m_brd->Tracks() )
356  {
357  if( m_tracks->GetValue() && segment->Type() == PCB_TRACE_T )
358  visitItem( &itemsListPicker, segment );
359  else if (m_vias->GetValue() && segment->Type() == PCB_VIA_T )
360  visitItem( &itemsListPicker, segment );
361  }
362 
363  if( itemsListPicker.GetCount() > 0 )
364  {
365  m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
366 
367  for( auto segment : m_brd->Tracks() )
368  m_parent->GetCanvas()->GetView()->Update( segment );
369  }
370 
371  return true;
372 }
373 
374 
376 {
377  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
378  {
379  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
380  aWidth -= m_originalColWidths[ i ];
381  }
382 
383  m_netclassGrid->SetColSize( 0, aWidth );
384 }
385 
386 
388 {
389  AdjustNetclassGridColumns( event.GetSize().GetX() );
390  event.Skip();
391 }
392 
393 
395 {
396  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
397  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
398 
399  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
400  return 0;
401 }
402 
void visitItem(PICKED_ITEMS_LIST *aUndoList, TRACK *aItem)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1291
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
Definition: undo_redo.cpp:177
int FindItem(const EDA_ITEM *aItem) const
void SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
wxString GetNetClassName() const
Definition: netinfo.h:108
void SetNotAllowedLayerSet(LSET aMask)
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
const wxString & GetName() const
Definition: netclass.h:65
static LAYER_NUM g_layerFilter
void SetBoard(BOARD *aBoard)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:773
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: track.cpp:54
static wxString g_netclassFilter
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
int GetSelectedNetcode()
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:754
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
iterator end()
Definition: netclass.h:236
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
static bool g_filterSelected
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
void SetLink(EDA_ITEM *aItem)
wxString GetSelectedNetname()
void OnNetclassFilterSelect(wxCommandEvent &event) override
unsigned GetCount() const
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:238
virtual wxString GetNetClassName() const
Returns 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
virtual PCB_LAYER_ID GetActiveLayer() const
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aEdit=true)
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
LAYER_NUM GetLayerSelection() const
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
int EditTracksAndVias(const TOOL_EVENT &aEvent)
int GetTrackWidth() const
Definition: netclass.h:128
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
iterator begin()
Definition: netclass.h:235
A container for NETCLASS instances.
Definition: netclass.h:218
#define NULL
#define SET_NETCLASS_VALUE(row, col, val)
const wxString & GetCurrentNetClassName() const
unsigned GetViaSizeIndex() const
int ShowQuasiModal()
Generic, UI-independent tool event.
Definition: tool_event.h:173
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
void SetSelectedNetcode(int aNetcode)
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:114
int GetViaDrill() const
Definition: netclass.h:136
unsigned GetTrackWidthIndex() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:416
static bool g_filterByNetclass
int SetLayerSelection(LAYER_NUM layer)
NETCLASSES & GetNetClasses() const
void OnLayerFilterSelect(wxCommandEvent &event) override
int GetuViaDiameter() const
Definition: netclass.h:140
static bool g_filterByLayer
void SetNetInfo(NETINFO_LIST *aNetInfoList)
A holder to handle information on schematic or board items.
NETCLASS * GetDefaultPtr() const
Definition: netclass.h:258
static bool g_modifyVias
bool SetLayersHotkeys(bool value)
static wxString g_netFilter
void onSpecifiedValuesUpdateUi(wxUpdateUIEvent &event) override
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
int LAYER_NUM
This can be replaced with int and removed.
void SetUndefinedLayerName(const wxString &aName)
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:456
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
static bool g_filterByNet
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
NETCLASS * GetDefault() const
The main frame for Pcbnew.
void SetSelectedNet(const wxString &aNetname)
The selection tool: currently supports:
int GetViaDiameter() const
Definition: netclass.h:132
void OnItemChanged(BOARD_ITEM *aItem)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition: board.cpp:2035
unsigned GetCount() const
Definition: netclass.h:245
int GetuViaDrill() const
Definition: netclass.h:144
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aEdit=true)
BOARD * GetBoard() const
void OnSizeNetclassGrid(wxSizeEvent &event) override
#define INDETERMINATE_ACTION
Definition: base_units.h:49
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:302
Definition: track.h:83
EDA_ITEM * Front() const
Definition: selection.h:203
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
Container for design settings for a BOARD object.