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  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  PCB_VIA *via = static_cast<PCB_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  {
110  {
111  if( GetDesignSettings().UseCustomTrackViaSize() )
112  {
115  }
116  else
117  {
120  }
121 
122  break;
123  }
124 
129  break;
130 
133  break;
134 
135  case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
136  case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
152  ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
154  break;
155 
156  case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
157  case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
172  // select the new current value for via size (via diameter)
175  break;
176 
178  ii = m_SelTrackWidthBox->GetSelection();
179 
180  if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
181  {
182  // this is the separator
183  }
184  else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
185  {
186  m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
187  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
188  }
189  else
190  {
193  }
194 
195  // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
196  GetCanvas()->SetFocus();
197 
198  break;
199 
201  ii = m_SelViaSizeBox->GetSelection();
202 
203  if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
204  {
205  // this is the separator
206  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
207  }
208  else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
209  {
210  m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
211  ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
212  }
213  else
214  {
216  }
217 
218  // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
219  GetCanvas()->SetFocus();
220 
221  break;
222 
223  default:
224  break;
225  }
226 
228 }
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:58
virtual NETCLASS * GetNetClass() const
Return the NETCLASS for this item.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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)
virtual void SetFocus() override
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
void UseCustomTrackViaSize(bool aEnabled)
Enables/disables custom track/via size settings.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112