KiCad PCB EDA Suite
edit_track_width.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) 2007-2016 Jean-Pierre Charras, jp.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 <pcbnew_id.h>
27 #include <board_design_settings.h>
28 #include <class_track.h>
29 #include <tools/pcb_actions.h>
30 #include <tool/tool_manager.h>
31 
33  PICKED_ITEMS_LIST* aItemsListPicker,
34  bool aUseNetclassValue )
35 {
36  int initial_width;
37  int new_width;
38  int initial_drill = -1;
39  int new_drill = -1;
40  NETINFO_ITEM* net = NULL;
41 
42  if( aUseNetclassValue )
43  net = aTrackItem->GetNet();
44 
45  initial_width = aTrackItem->GetWidth();
46 
47  if( net )
48  new_width = net->GetTrackWidth();
49  else
51 
52  if( aTrackItem->Type() == PCB_VIA_T )
53  {
54  const VIA *via = static_cast<const VIA *>( aTrackItem );
55 
56  // Micro vias have a size only defined in their netclass
57  // (no specific values defined by a table of specific value)
58  // Ensure the netclass is accessible:
59  if( via->GetViaType() == VIATYPE::MICROVIA && net == NULL )
60  net = aTrackItem->GetNet();
61 
62  // Get the draill value, regardless it is default or specific
63  initial_drill = via->GetDrillValue();
64 
65  if( net )
66  {
67  new_width = net->GetViaSize();
68  new_drill = net->GetViaDrillSize();
69  }
70  else
71  {
72  new_width = GetDesignSettings().GetCurrentViaSize();
73  new_drill = GetDesignSettings().GetCurrentViaDrill();
74  }
75 
76  if( via->GetViaType() == VIATYPE::MICROVIA )
77  {
78  if( net )
79  {
80  new_width = net->GetMicroViaSize();
81  new_drill = net->GetMicroViaDrillSize();
82  }
83  else
84  {
85  // Should not occur
86  }
87  }
88 
89  // Old versions set a drill value <= 0, when the default netclass it used
90  // but it could be better to set the drill value to the actual value
91  // to avoid issues for existing vias, if the default drill value is modified
92  // in the netclass, and not in current vias.
93  if( via->GetDrill() <= 0 ) // means default netclass drill value used
94  {
95  initial_drill = -1; // Force drill vias re-initialization
96  }
97  }
98 
99  if( initial_width != new_width || initial_drill != new_drill )
100  {
101  OnModify();
102 
103  if( aItemsListPicker )
104  {
105  aTrackItem->SetWidth( initial_width );
106  ITEM_PICKER picker( nullptr, aTrackItem, UNDO_REDO::CHANGED );
107  picker.SetLink( aTrackItem->Clone() );
108  aItemsListPicker->PushItem( picker );
109  aTrackItem->SetWidth( new_width );
110 
111  if( aTrackItem->Type() == PCB_VIA_T )
112  {
113  // Set new drill value. Note: currently microvias have only a default drill value
114  VIA *via = static_cast<VIA *>( aTrackItem );
115  if( new_drill > 0 )
116  via->SetDrill( new_drill );
117  else
118  via->SetDrillDefault();
119  }
120  }
121  }
122 }
123 
124 
125 void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
126 {
127  int ii;
128  int id = event.GetId();
129 
130  switch( id )
131  {
135  break;
136 
141  break;
142 
145  break;
146 
147  case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
148  case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
164  ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
166  break;
167 
168  case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
169  case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
184  // select the new current value for via size (via diameter)
187  break;
188 
190  ii = m_SelTrackWidthBox->GetSelection();
191 
192  if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
193  {
194  // this is the separator
195  }
196  else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
197  {
198  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
199  ShowBoardSetupDialog( _( "Tracks & Vias" ) );
200  }
201  else
202  {
204  }
205 
206  break;
207 
209  ii = m_SelViaSizeBox->GetSelection();
210 
211  if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
212  {
213  // this is the separator
214  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
215  }
216  else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
217  {
218  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
219  ShowBoardSetupDialog( _( "Tracks & Vias" ) );
220  }
221  else
222  {
224  }
225 
226  break;
227 
228  default:
229  break;
230  }
231 
233 }
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
void SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Function SetTrackSegmentWidth Modify one track segment width or one via diameter (using DRC control).
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
wxChoice * m_SelViaSizeBox
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:50
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:299
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
wxChoice * m_SelTrackWidthBox
void SetLink(EDA_ITEM *aItem)
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
void SetWidth(int aWidth)
Definition: class_track.h:109
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
Function ShowBoardSetupDialog.
#define NULL
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:493
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
int GetTrackWidth()
Function GetTrackWidth returns the width of tracks used to route this net.
Definition: netinfo.h:148
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: class_track.h:507
int GetCurrentViaSize() const
Function GetCurrentViaSize.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
int GetWidth() const
Definition: class_track.h:110
#define _(s)
Definition: 3d_actions.cpp:33
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:486
VIATYPE GetViaType() const
Definition: class_track.h:384
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
ID_POPUP_PCB_SELECT_WIDTH8
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182