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 <board_design_settings.h>
26 #include <pcb_edit_frame.h>
27 #include <pcbnew_id.h>
28 #include <pcb_track.h>
29 #include <tools/pcb_actions.h>
30 #include <tool/tool_manager.h>
31 #include <wx/choice.h>
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 
42  initial_width = aTrackItem->GetWidth();
43 
44  if( aUseNetclassValue )
45  new_width = aTrackItem->GetNetClass()->GetTrackWidth();
46  else
48 
49  if( aTrackItem->Type() == PCB_VIA_T )
50  {
51  const PCB_VIA *via = static_cast<const PCB_VIA*>( aTrackItem );
52 
53  // Get the drill value, regardless it is default or specific
54  initial_drill = via->GetDrillValue();
55 
56  if( aUseNetclassValue || via->GetViaType() == VIATYPE::MICROVIA )
57  {
58  new_width = aTrackItem->GetNetClass()->GetViaDiameter();
59  new_drill = aTrackItem->GetNetClass()->GetViaDrill();
60  }
61  else
62  {
63  new_width = GetDesignSettings().GetCurrentViaSize();
64  new_drill = GetDesignSettings().GetCurrentViaDrill();
65  }
66 
67  // Old versions set a drill value <= 0, when the default netclass it used
68  // but it could be better to set the drill value to the actual value
69  // to avoid issues for existing vias, if the default drill value is modified
70  // in the netclass, and not in current vias.
71  if( via->GetDrill() <= 0 ) // means default netclass drill value used
72  {
73  initial_drill = -1; // Force drill vias re-initialization
74  }
75  }
76 
77  if( initial_width != new_width || initial_drill != new_drill )
78  {
79  OnModify();
80 
81  if( aItemsListPicker )
82  {
83  aTrackItem->SetWidth( initial_width );
84  ITEM_PICKER picker( nullptr, aTrackItem, UNDO_REDO::CHANGED );
85  picker.SetLink( aTrackItem->Clone() );
86  aItemsListPicker->PushItem( picker );
87  aTrackItem->SetWidth( new_width );
88 
89  if( aTrackItem->Type() == PCB_VIA_T )
90  {
91  // Set new drill value. Note: currently microvias have only a default drill value
92  PCB_VIA *via = static_cast<PCB_VIA*>( aTrackItem );
93 
94  if( new_drill > 0 )
95  via->SetDrill( new_drill );
96  else
97  via->SetDrillDefault();
98  }
99  }
100  }
101 }
102 
103 
104 void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
105 {
106  int ii;
107  int id = event.GetId();
108 
109  switch( id )
110  {
114  break;
115 
120  break;
121 
124  break;
125 
126  case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
127  case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
143  ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
145  break;
146 
147  case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
148  case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
163  // select the new current value for via size (via diameter)
166  break;
167 
169  ii = m_SelTrackWidthBox->GetSelection();
170 
171  if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
172  {
173  // this is the separator
174  }
175  else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
176  {
177  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
178  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
179  }
180  else
181  {
183  }
184 
185  break;
186 
188  ii = m_SelViaSizeBox->GetSelection();
189 
190  if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
191  {
192  // this is the separator
193  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
194  }
195  else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
196  {
197  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
198  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
199  }
200  else
201  {
203  }
204 
205  break;
206 
207  default:
208  break;
209  }
210 
212 }
void OnModify() override
Must be called after a board change to set the modified flag.
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.
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:57
virtual NETCLASS * GetNetClass() const
Return the NETCLASS for this item.
wxChoice * m_SelViaSizeBox
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:299
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
int GetWidth() const
Definition: pcb_track.h:102
wxChoice * m_SelTrackWidthBox
void SetLink(EDA_ITEM *aItem)
void SetTrackSegmentWidth(PCB_TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
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 GetViaDrill() const
Definition: netclass.h:136
#define _(s)
A holder to handle information on schematic or board items.
void SetWidth(int aWidth)
Definition: pcb_track.h:101
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
int GetViaDiameter() const
Definition: netclass.h:132
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
ID_POPUP_PCB_SELECT_WIDTH8
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113