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-2016 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 <pcb_edit_frame.h>
27 #include <pcbnew_id.h>
28 #include <class_track.h>
29 #include <pcbnew.h>
30 #include <tools/drc.h>
31 
32 
34  PICKED_ITEMS_LIST* aItemsListPicker,
35  bool aUseNetclassValue )
36 {
37  int initial_width;
38  int new_width;
39  int initial_drill = -1;
40  int new_drill = -1;
41  NETINFO_ITEM* net = NULL;
42 
43  if( aUseNetclassValue )
44  net = aTrackItem->GetNet();
45 
46  initial_width = aTrackItem->GetWidth();
47 
48  if( net )
49  new_width = net->GetTrackWidth();
50  else
52 
53  if( aTrackItem->Type() == PCB_VIA_T )
54  {
55  const VIA *via = static_cast<const VIA *>( aTrackItem );
56 
57  // Micro vias have a size only defined in their netclass
58  // (no specific values defined by a table of specific value)
59  // Ensure the netclass is accessible:
60  if( via->GetViaType() == VIATYPE::MICROVIA && net == NULL )
61  net = aTrackItem->GetNet();
62 
63  // Get the draill value, regardless it is default or specific
64  initial_drill = via->GetDrillValue();
65 
66  if( net )
67  {
68  new_width = net->GetViaSize();
69  new_drill = net->GetViaDrillSize();
70  }
71  else
72  {
73  new_width = GetDesignSettings().GetCurrentViaSize();
74  new_drill = GetDesignSettings().GetCurrentViaDrill();
75  }
76 
77  if( via->GetViaType() == VIATYPE::MICROVIA )
78  {
79  if( net )
80  {
81  new_width = net->GetMicroViaSize();
82  new_drill = net->GetMicroViaDrillSize();
83  }
84  else
85  {
86  // Should not occur
87  }
88  }
89 
90  // Old versions set a drill value <= 0, when the default netclass it used
91  // but it could be better to set the drill value to the actual value
92  // to avoid issues for existing vias, if the default drill value is modified
93  // in the netclass, and not in current vias.
94  if( via->GetDrill() <= 0 ) // means default netclass drill value used
95  {
96  initial_drill = -1; // Force drill vias re-initialization
97  }
98  }
99 
100  if( initial_width != new_width || initial_drill != new_drill )
101  {
102  OnModify();
103 
104  if( aItemsListPicker )
105  {
106  aTrackItem->SetWidth( initial_width );
107  ITEM_PICKER picker( aTrackItem, UR_CHANGED );
108  picker.SetLink( aTrackItem->Clone() );
109  aItemsListPicker->PushItem( picker );
110  aTrackItem->SetWidth( new_width );
111 
112  if( aTrackItem->Type() == PCB_VIA_T )
113  {
114  // Set new drill value. Note: currently microvias have only a default drill value
115  VIA *via = static_cast<VIA *>( aTrackItem );
116  if( new_drill > 0 )
117  via->SetDrill( new_drill );
118  else
119  via->SetDrillDefault();
120  }
121  }
122 
123  return TRACK_ACTION_SUCCESS;
124  }
125  else
126  {
127  return TRACK_ACTION_NONE;
128  }
129 }
130 
131 
132 void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
133 {
134  int ii;
135  int id = event.GetId();
136 
137  switch( id )
138  {
142  break;
143 
148  break;
149 
152  break;
153 
154  case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
155  case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
171  ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
173  break;
174 
175  case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
176  case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
191  // select the new current value for via size (via diameter)
194  break;
195 
197  ii = m_SelTrackWidthBox->GetSelection();
198 
199  if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
200  {
201  // this is the separator
202  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
203  }
204  else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
205  {
206  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
207  DoShowBoardSetupDialog( _( "Tracks & Vias" ) );
208  }
209  else
211 
212  break;
213 
215  ii = m_SelViaSizeBox->GetSelection();
216 
217  if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
218  {
219  // this is the separator
220  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
221  }
222  else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
223  {
224  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
225  DoShowBoardSetupDialog( _( "Tracks & Vias" ) );
226  }
227  else
229 
230  break;
231 
232  default:
233  wxLogDebug( wxT( "PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event() error") );
234  break;
235  }
236 }
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
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
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:69
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 PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
wxChoice * m_SelTrackWidthBox
void SetLink(EDA_ITEM *aItem)
Definitions for tracks, vias and zones.
void SetWidth(int aWidth)
Definition: class_track.h:102
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
#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:358
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:142
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: class_track.h:372
TRACK_ACTION_SUCCESS - Track changed successfully.
int GetCurrentViaSize() const
Function GetCurrentViaSize.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetWidth() const
Definition: class_track.h:103
void DoShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString, const wxString &aInitialParentPage=wxEmptyString)
Function ShowBoardSetupDialog.
#define _(s)
Definition: 3d_actions.cpp:31
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:351
VIATYPE GetViaType() const
Definition: class_track.h:336
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
ID_POPUP_PCB_SELECT_WIDTH8
TRACK_ACTION_NONE - Nothing to change.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207