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
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->GetEffectiveNetClass()->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->GetEffectiveNetClass()->GetViaDiameter();
59 new_drill = aTrackItem->GetEffectiveNetClass()->GetViaDrill();
60 }
61 else
62 {
65 }
66
67 // Old versions set a drill value <= 0, when the default netclass it used but it could
68 // be better to set the drill value to the actual value to avoid issues for existing vias,
69 // if the default drill value is modified in the netclass, and not in current vias.
70 if( via->GetDrill() <= 0 ) // means default netclass drill value used
71 initial_drill = -1; // Force drill vias re-initialization
72 }
73
74 if( initial_width != new_width || initial_drill != new_drill )
75 {
76 if( aItemsListPicker )
77 {
78 aTrackItem->SetWidth( initial_width );
79 ITEM_PICKER picker( nullptr, aTrackItem, UNDO_REDO::CHANGED );
80 picker.SetLink( aTrackItem->Clone() );
81 aItemsListPicker->PushItem( picker );
82 aTrackItem->SetWidth( new_width );
83
84 if( aTrackItem->Type() == PCB_VIA_T )
85 {
86 // Set new drill value. Note: currently microvias have only a default drill value
87 PCB_VIA *via = static_cast<PCB_VIA*>( aTrackItem );
88
89 if( new_drill > 0 )
90 via->SetDrill( new_drill );
91 else
92 via->SetDrillDefault();
93 }
94 }
95 }
96}
97
98
99void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
100{
101 int ii;
102 int id = event.GetId();
103
104 switch( id )
105 {
107 {
108 if( GetDesignSettings().UseCustomTrackViaSize() )
109 {
112 }
113 else
114 {
117 }
118
119 break;
120 }
121
126 break;
127
130 break;
131
132 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
133 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
151 break;
152
153 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
154 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
169 // select the new current value for via size (via diameter)
172 break;
173
175 ii = m_SelTrackWidthBox->GetSelection();
176
177 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
178 {
179 // this is the separator
180 }
181 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
182 {
183 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
184 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
185 }
186 else
187 {
190 }
191
192 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
193 GetCanvas()->SetFocus();
194
195 break;
196
198 ii = m_SelViaSizeBox->GetSelection();
199
200 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
201 {
202 // this is the separator
203 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
204 }
205 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
206 {
207 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
208 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
209 }
210 else
211 {
213 }
214
215 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
216 GetCanvas()->SetFocus();
217
218 break;
219
220 default:
221 break;
222 }
223
225}
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
void UseCustomTrackViaSize(bool aEnabled)
Enables/disables custom track/via size settings.
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
void SetFocus() override
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void SetLink(EDA_ITEM *aItem)
int GetViaDiameter() const
Definition: netclass.h:80
int GetViaDrill() const
Definition: netclass.h:84
int GetTrackWidth() const
Definition: netclass.h:76
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:334
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
void SetTrackSegmentWidth(PCB_TRACK *aTrackItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseNetclassValue)
Modify one track segment width or one via diameter (using DRC control).
wxChoice * m_SelViaSizeBox
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
wxChoice * m_SelTrackWidthBox
void SetWidth(int aWidth)
Definition: pcb_track.h:105
int GetWidth() const
Definition: pcb_track.h:106
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:61
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
#define _(s)
ID_POPUP_PCB_SELECT_WIDTH8
@ ID_POPUP_PCB_SELECT_WIDTH14
Definition: pcbnew_id.h:42
@ ID_POPUP_PCB_SELECT_WIDTH9
Definition: pcbnew_id.h:37
@ ID_POPUP_PCB_SELECT_WIDTH1
Definition: pcbnew_id.h:29
@ ID_POPUP_PCB_SELECT_VIASIZE8
Definition: pcbnew_id.h:52
@ ID_POPUP_PCB_SELECT_VIASIZE9
Definition: pcbnew_id.h:53
@ ID_POPUP_PCB_SELECT_VIASIZE11
Definition: pcbnew_id.h:55
@ ID_POPUP_PCB_SELECT_WIDTH4
Definition: pcbnew_id.h:32
@ ID_POPUP_PCB_SELECT_WIDTH11
Definition: pcbnew_id.h:39
@ ID_POPUP_PCB_SELECT_VIASIZE15
Definition: pcbnew_id.h:59
@ ID_POPUP_PCB_SELECT_VIASIZE3
Definition: pcbnew_id.h:47
@ ID_POPUP_PCB_SELECT_VIASIZE7
Definition: pcbnew_id.h:51
@ ID_POPUP_PCB_SELECT_VIASIZE10
Definition: pcbnew_id.h:54
@ ID_POPUP_PCB_SELECT_WIDTH10
Definition: pcbnew_id.h:38
@ ID_POPUP_PCB_SELECT_VIASIZE13
Definition: pcbnew_id.h:57
@ ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES
Definition: pcbnew_id.h:28
@ ID_AUX_TOOLBAR_PCB_VIA_SIZE
Definition: pcbnew_id.h:22
@ ID_POPUP_PCB_SELECT_WIDTH16
Definition: pcbnew_id.h:44
@ ID_POPUP_PCB_SELECT_VIASIZE12
Definition: pcbnew_id.h:56
@ ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH
Definition: pcbnew_id.h:24
@ ID_POPUP_PCB_SELECT_AUTO_WIDTH
Definition: pcbnew_id.h:27
@ ID_POPUP_PCB_SELECT_WIDTH2
Definition: pcbnew_id.h:30
@ ID_POPUP_PCB_SELECT_WIDTH6
Definition: pcbnew_id.h:34
@ ID_POPUP_PCB_SELECT_WIDTH13
Definition: pcbnew_id.h:41
@ ID_POPUP_PCB_SELECT_VIASIZE1
Definition: pcbnew_id.h:45
@ ID_POPUP_PCB_SELECT_VIASIZE4
Definition: pcbnew_id.h:48
@ ID_POPUP_PCB_SELECT_WIDTH12
Definition: pcbnew_id.h:40
@ ID_POPUP_PCB_SELECT_VIASIZE5
Definition: pcbnew_id.h:49
@ ID_POPUP_PCB_SELECT_VIASIZE16
Definition: pcbnew_id.h:60
@ ID_POPUP_PCB_SELECT_WIDTH15
Definition: pcbnew_id.h:43
@ ID_POPUP_PCB_SELECT_WIDTH3
Definition: pcbnew_id.h:31
@ ID_POPUP_PCB_SELECT_VIASIZE2
Definition: pcbnew_id.h:46
@ ID_POPUP_PCB_SELECT_WIDTH7
Definition: pcbnew_id.h:35
@ ID_POPUP_PCB_SELECT_VIASIZE14
Definition: pcbnew_id.h:58
@ ID_AUX_TOOLBAR_PCB_TRACK_WIDTH
Definition: pcbnew_id.h:23
@ ID_POPUP_PCB_SELECT_WIDTH5
Definition: pcbnew_id.h:33
@ ID_POPUP_PCB_SELECT_VIASIZE6
Definition: pcbnew_id.h:50
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102