KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 bool aUseDesignRules )
35{
36 PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem );
37 int new_width = -1;
38 int new_drill = -1;
39
40 if( aUseDesignRules )
41 {
42 MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
43
44 if( constraint.HasOpt() )
45 new_width = constraint.Opt();
46 else if( constraint.Min() > 0 )
47 new_width = constraint.Min();
48
49 if( via )
50 {
51 constraint = via->GetDrillConstraint();
52
53 if( constraint.HasOpt() )
54 new_drill = constraint.Opt();
55 else if( constraint.Min() > 0 )
56 new_drill = constraint.Min();
57 }
58 }
59 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
60 {
61 new_width = aItem->GetEffectiveNetClass()->GetuViaDiameter();
62 new_drill = aItem->GetEffectiveNetClass()->GetuViaDrill();
63 }
64 else if( via )
65 {
68 }
69 else
70 {
72 }
73
74 if( new_width <= 0 )
75 new_width = aItem->GetWidth();
76
77 if( via && new_drill <= 0 )
78 new_drill = via->GetDrillValue();
79
80 if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
81 {
82 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
83 picker.SetLink( aItem->Clone() );
84 aItemsListPicker->PushItem( picker );
85
86 aItem->SetWidth( new_width );
87
88 if( via && new_drill > 0 )
89 via->SetDrill( new_drill );
90 }
91}
92
93
94void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
95{
96 int ii;
97 int id = event.GetId();
98
99 switch( id )
100 {
102 {
103 if( GetDesignSettings().UseCustomTrackViaSize() )
104 {
107 }
108 else
109 {
112 }
113
114 break;
115 }
116
121 break;
122
125 break;
126
127 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
128 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
146 break;
147
148 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
149 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
164 // select the new current value for via size (via diameter)
167 break;
168
170 ii = m_SelTrackWidthBox->GetSelection();
171
172 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
173 {
174 // this is the separator
175 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
176 }
177 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
178 {
179 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
180 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
181 }
182 else
183 {
186 }
187
188 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
189 GetCanvas()->SetFocus();
190
191 break;
192
194 ii = m_SelViaSizeBox->GetSelection();
195
196 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
197 {
198 // this is the separator
199 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
200 }
201 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
202 {
203 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
204 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
205 }
206 else
207 {
209 }
210
211 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
212 GetCanvas()->SetFocus();
213
214 break;
215
216 default:
217 break;
218 }
219
221}
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
void SetLink(EDA_ITEM *aItem)
T Min() const
Definition: minoptmax.h:33
T Opt() const
Definition: minoptmax.h:35
bool HasOpt() const
Definition: minoptmax.h:39
int GetuViaDrill() const
Definition: netclass.h:89
int GetuViaDiameter() const
Definition: netclass.h:85
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:387
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 *aItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseDesignRules)
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:106
int GetWidth() const
Definition: pcb_track.h:107
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:64
virtual MINOPTMAX< int > GetWidthConstraint(wxString *aSource=nullptr) const
Definition: pcb_track.cpp:515
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:167
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
#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