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( via->GetViaType() == VIATYPE::MICROVIA )
57 {
58 new_width = aTrackItem->GetEffectiveNetClass()->GetuViaDiameter();
59 new_drill = aTrackItem->GetEffectiveNetClass()->GetuViaDrill();
60 }
61 else if( aUseNetclassValue )
62 {
63 new_width = aTrackItem->GetEffectiveNetClass()->GetViaDiameter();
64 new_drill = aTrackItem->GetEffectiveNetClass()->GetViaDrill();
65 }
66 else
67 {
70 }
71
72 // Old versions set a drill value <= 0, when the default netclass it used but it could
73 // be better to set the drill value to the actual value to avoid issues for existing vias,
74 // if the default drill value is modified in the netclass, and not in current vias.
75 if( via->GetDrill() <= 0 ) // means default netclass drill value used
76 initial_drill = -1; // Force drill vias re-initialization
77 }
78
79 if( initial_width != new_width || initial_drill != new_drill )
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
105{
106 int ii;
107 int id = event.GetId();
108
109 switch( id )
110 {
112 {
113 if( GetDesignSettings().UseCustomTrackViaSize() )
114 {
117 }
118 else
119 {
122 }
123
124 break;
125 }
126
131 break;
132
135 break;
136
137 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
138 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
156 break;
157
158 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
159 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
174 // select the new current value for via size (via diameter)
177 break;
178
180 ii = m_SelTrackWidthBox->GetSelection();
181
182 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
183 {
184 // this is the separator
185 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
186 }
187 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
188 {
189 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
190 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
191 }
192 else
193 {
196 }
197
198 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
199 GetCanvas()->SetFocus();
200
201 break;
202
204 ii = m_SelViaSizeBox->GetSelection();
205
206 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
207 {
208 // this is the separator
209 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
210 }
211 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
212 {
213 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
214 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
215 }
216 else
217 {
219 }
220
221 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
222 GetCanvas()->SetFocus();
223
224 break;
225
226 default:
227 break;
228 }
229
231}
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 GetuViaDrill() const
Definition: netclass.h:92
int GetuViaDiameter() const
Definition: netclass.h:88
int GetTrackWidth() const
Definition: netclass.h:76
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:338
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:107
int GetWidth() const
Definition: pcb_track.h:108
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