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 <track.h>
28 #include <tools/pcb_actions.h>
29 #include <tool/tool_manager.h>
30 
32  PICKED_ITEMS_LIST* aItemsListPicker,
33  bool aUseNetclassValue )
34 {
35  int initial_width;
36  int new_width;
37  int initial_drill = -1;
38  int new_drill = -1;
39 
40  initial_width = aTrackItem->GetWidth();
41 
42  if( aUseNetclassValue )
43  new_width = aTrackItem->GetNetClass()->GetTrackWidth();
44  else
46 
47  if( aTrackItem->Type() == PCB_VIA_T )
48  {
49  const VIA *via = static_cast<const VIA *>( aTrackItem );
50 
51  // Get the drill value, regardless it is default or specific
52  initial_drill = via->GetDrillValue();
53 
54  if( aUseNetclassValue || via->GetViaType() == VIATYPE::MICROVIA )
55  {
56  new_width = aTrackItem->GetNetClass()->GetViaDiameter();
57  new_drill = aTrackItem->GetNetClass()->GetViaDrill();
58  }
59  else
60  {
61  new_width = GetDesignSettings().GetCurrentViaSize();
62  new_drill = GetDesignSettings().GetCurrentViaDrill();
63  }
64 
65  // Old versions set a drill value <= 0, when the default netclass it used
66  // but it could be better to set the drill value to the actual value
67  // to avoid issues for existing vias, if the default drill value is modified
68  // in the netclass, and not in current vias.
69  if( via->GetDrill() <= 0 ) // means default netclass drill value used
70  {
71  initial_drill = -1; // Force drill vias re-initialization
72  }
73  }
74 
75  if( initial_width != new_width || initial_drill != new_drill )
76  {
77  OnModify();
78 
79  if( aItemsListPicker )
80  {
81  aTrackItem->SetWidth( initial_width );
82  ITEM_PICKER picker( nullptr, aTrackItem, UNDO_REDO::CHANGED );
83  picker.SetLink( aTrackItem->Clone() );
84  aItemsListPicker->PushItem( picker );
85  aTrackItem->SetWidth( new_width );
86 
87  if( aTrackItem->Type() == PCB_VIA_T )
88  {
89  // Set new drill value. Note: currently microvias have only a default drill value
90  VIA *via = static_cast<VIA *>( aTrackItem );
91 
92  if( new_drill > 0 )
93  via->SetDrill( new_drill );
94  else
95  via->SetDrillDefault();
96  }
97  }
98  }
99 }
100 
101 
102 void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
103 {
104  int ii;
105  int id = event.GetId();
106 
107  switch( id )
108  {
112  break;
113 
118  break;
119 
122  break;
123 
124  case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
125  case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
141  ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
143  break;
144 
145  case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
146  case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
161  // select the new current value for via size (via diameter)
164  break;
165 
167  ii = m_SelTrackWidthBox->GetSelection();
168 
169  if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
170  {
171  // this is the separator
172  }
173  else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
174  {
175  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
176  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
177  }
178  else
179  {
181  }
182 
183  break;
184 
186  ii = m_SelViaSizeBox->GetSelection();
187 
188  if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
189  {
190  // this is the separator
191  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
192  }
193  else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
194  {
195  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
196  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
197  }
198  else
199  {
201  }
202 
203  break;
204 
205  default:
206  break;
207  }
208 
210 }
void OnModify() override
Must be called after a board change to set the modified flag.
Definition: track.h:343
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
void SetTrackSegmentWidth(TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
virtual NETCLASS * GetNetClass() const
Return the NETCLASS for this item.
wxChoice * m_SelViaSizeBox
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: track.cpp:54
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:303
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
wxChoice * m_SelTrackWidthBox
void SetLink(EDA_ITEM *aItem)
void SetWidth(int aWidth)
Definition: track.h:109
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
int GetTrackWidth() const
Definition: netclass.h:128
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
Definition: track.cpp:173
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: track.h:481
int GetViaDrill() const
Definition: netclass.h:136
A holder to handle information on schematic or board items.
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: track.h:495
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:157
int GetWidth() const
Definition: track.h:110
#define _(s)
Definition: 3d_actions.cpp:33
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: track.h:474
VIATYPE GetViaType() const
Definition: track.h:373
int GetViaDiameter() const
Definition: netclass.h:132
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
ID_POPUP_PCB_SELECT_WIDTH8
Definition: track.h:83
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162