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 The 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 <netclass.h>
27#include <pcb_edit_frame.h>
28#include <pcbnew_id.h>
29#include <pcb_track.h>
30#include <tools/pcb_actions.h>
31#include <tool/tool_manager.h>
32#include <wx/choice.h>
33
35 bool aUseDesignRules )
36{
37 PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem );
38 int new_width = -1;
39 int new_drill = -1;
40
41 if( aUseDesignRules )
42 {
43 MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
44
45 if( constraint.HasOpt() )
46 new_width = constraint.Opt();
47 else if( constraint.Min() > 0 )
48 new_width = constraint.Min();
49
50 if( via )
51 {
52 constraint = via->GetDrillConstraint();
53
54 if( constraint.HasOpt() )
55 new_drill = constraint.Opt();
56 else if( constraint.Min() > 0 )
57 new_drill = constraint.Min();
58 }
59 }
60 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
61 {
62 new_width = aItem->GetEffectiveNetClass()->GetuViaDiameter();
63 new_drill = aItem->GetEffectiveNetClass()->GetuViaDrill();
64 }
65 else if( via )
66 {
69 }
70 else
71 {
73 }
74
75 if( new_width <= 0 )
76 new_width = aItem->GetWidth();
77
78 if( via && new_drill <= 0 )
79 new_drill = via->GetDrillValue();
80
81 if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
82 {
83 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
84 picker.SetLink( aItem->Clone() );
85 aItemsListPicker->PushItem( picker );
86
87 aItem->SetWidth( new_width );
88
89 if( via && new_drill > 0 )
90 via->SetDrill( new_drill );
91 }
92}
93
94
95void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
96{
97 int ii;
98 int id = event.GetId();
99
100 switch( id )
101 {
106 break;
107
110 break;
111
112 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
113 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
131 break;
132
133 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
134 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
149 // select the new current value for via size (via diameter)
152 break;
153
155 ii = m_SelTrackWidthBox->GetSelection();
156
157 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
158 {
159 // this is the separator
160 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
161 }
162 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
163 {
164 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
165 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
166 }
167 else
168 {
171 }
172
173 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
174 GetCanvas()->SetFocus();
175
176 break;
177
179 ii = m_SelViaSizeBox->GetSelection();
180
181 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
182 {
183 // this is the separator
184 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
185 }
186 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
187 {
188 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
189 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
190 }
191 else
192 {
194 }
195
196 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
197 GetCanvas()->SetFocus();
198
199 break;
200
201 default:
202 break;
203 }
204
206}
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
void SetViaSizeIndex(int aIndex)
Set the current via size list index to aIndex.
void SetTrackWidthIndex(int aIndex)
Set the current track width 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:157
int GetuViaDiameter() const
Definition netclass.h:149
static TOOL_ACTION trackViaSizeChanged
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
Return the BOARD_DESIGN_SETTINGS for the open project.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString, wxWindow *aParent=nullptr)
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
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_track.cpp:73
virtual MINOPTMAX< int > GetWidthConstraint(wxString *aSource=nullptr) const
virtual void SetWidth(int aWidth)
Definition pcb_track.h:147
virtual int GetWidth() const
Definition pcb_track.h:148
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
#define _(s)
ID_POPUP_PCB_SELECT_WIDTH8
@ MICROVIA
Definition pcb_track.h:71
@ ID_POPUP_PCB_SELECT_WIDTH14
Definition pcbnew_id.h:37
@ ID_POPUP_PCB_SELECT_WIDTH9
Definition pcbnew_id.h:32
@ ID_POPUP_PCB_SELECT_WIDTH1
Definition pcbnew_id.h:24
@ ID_POPUP_PCB_SELECT_VIASIZE8
Definition pcbnew_id.h:47
@ ID_POPUP_PCB_SELECT_VIASIZE9
Definition pcbnew_id.h:48
@ ID_POPUP_PCB_SELECT_VIASIZE11
Definition pcbnew_id.h:50
@ ID_POPUP_PCB_SELECT_WIDTH4
Definition pcbnew_id.h:27
@ ID_POPUP_PCB_SELECT_WIDTH11
Definition pcbnew_id.h:34
@ ID_POPUP_PCB_SELECT_VIASIZE15
Definition pcbnew_id.h:54
@ ID_POPUP_PCB_SELECT_VIASIZE3
Definition pcbnew_id.h:42
@ ID_POPUP_PCB_SELECT_VIASIZE7
Definition pcbnew_id.h:46
@ ID_POPUP_PCB_SELECT_VIASIZE10
Definition pcbnew_id.h:49
@ ID_POPUP_PCB_SELECT_WIDTH10
Definition pcbnew_id.h:33
@ ID_POPUP_PCB_SELECT_VIASIZE13
Definition pcbnew_id.h:52
@ ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES
Definition pcbnew_id.h:23
@ ID_AUX_TOOLBAR_PCB_VIA_SIZE
Definition pcbnew_id.h:17
@ ID_POPUP_PCB_SELECT_WIDTH16
Definition pcbnew_id.h:39
@ ID_POPUP_PCB_SELECT_VIASIZE12
Definition pcbnew_id.h:51
@ ID_POPUP_PCB_SELECT_AUTO_WIDTH
Definition pcbnew_id.h:22
@ ID_POPUP_PCB_SELECT_WIDTH2
Definition pcbnew_id.h:25
@ ID_POPUP_PCB_SELECT_WIDTH6
Definition pcbnew_id.h:29
@ ID_POPUP_PCB_SELECT_WIDTH13
Definition pcbnew_id.h:36
@ ID_POPUP_PCB_SELECT_VIASIZE1
Definition pcbnew_id.h:40
@ ID_POPUP_PCB_SELECT_VIASIZE4
Definition pcbnew_id.h:43
@ ID_POPUP_PCB_SELECT_WIDTH12
Definition pcbnew_id.h:35
@ ID_POPUP_PCB_SELECT_VIASIZE5
Definition pcbnew_id.h:44
@ ID_POPUP_PCB_SELECT_VIASIZE16
Definition pcbnew_id.h:55
@ ID_POPUP_PCB_SELECT_WIDTH15
Definition pcbnew_id.h:38
@ ID_POPUP_PCB_SELECT_WIDTH3
Definition pcbnew_id.h:26
@ ID_POPUP_PCB_SELECT_VIASIZE2
Definition pcbnew_id.h:41
@ ID_POPUP_PCB_SELECT_WIDTH7
Definition pcbnew_id.h:30
@ ID_POPUP_PCB_SELECT_VIASIZE14
Definition pcbnew_id.h:53
@ ID_AUX_TOOLBAR_PCB_TRACK_WIDTH
Definition pcbnew_id.h:18
@ ID_POPUP_PCB_SELECT_WIDTH5
Definition pcbnew_id.h:28
@ ID_POPUP_PCB_SELECT_VIASIZE6
Definition pcbnew_id.h:45