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, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <netclass.h>
23#include <pcb_edit_frame.h>
24#include <pcbnew_id.h>
25#include <pcb_track.h>
26#include <tools/pcb_actions.h>
27#include <tool/tool_manager.h>
28#include <wx/choice.h>
29
31 bool aUseDesignRules )
32{
33 PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem );
34 int current_width = via ? via->GetWidth( PADSTACK::ALL_LAYERS ) : aItem->GetWidth();
35 int new_width = -1;
36 int new_drill = -1;
37
38 if( aUseDesignRules )
39 {
40 MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
41
42 if( constraint.HasOpt() )
43 new_width = constraint.PinnedOpt();
44 else if( constraint.Min() > 0 )
45 new_width = constraint.Min();
46
47 if( via )
48 {
49 constraint = via->GetDrillConstraint();
50
51 if( constraint.HasOpt() )
52 new_drill = constraint.PinnedOpt();
53 else if( constraint.Min() > 0 )
54 new_drill = constraint.Min();
55 }
56 }
57 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
58 {
59 NETCLASS* netClass = via->GetEffectiveNetClass();
60 PCB_VIA original( *via );
61
62 // Resolve on the live via, since rules such as fromTo() match board items only
63 via->SetSizeFromRules( netClass->GetuViaDiameter(), netClass->GetuViaDrill() );
64 new_width = via->GetWidth( PADSTACK::ALL_LAYERS );
65 new_drill = via->GetDrillValue();
66 via->CopyFrom( &original );
67 }
68 else if( via )
69 {
72 }
73 else
74 {
76 }
77
78 if( new_width <= 0 )
79 new_width = current_width;
80
81 if( via && new_drill <= 0 )
82 new_drill = via->GetDrillValue();
83
84 if( current_width != new_width || ( via && via->GetDrillValue() != new_drill ) )
85 {
86 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
87 picker.SetLink( aItem->Clone() );
88 aItemsListPicker->PushItem( picker );
89
90 if( via )
91 via->SetWidth( PADSTACK::ALL_LAYERS, new_width );
92 else
93 aItem->SetWidth( new_width );
94
95 if( via && new_drill > 0 )
96 via->SetDrill( new_drill );
97 }
98}
99
100
101void PCB_EDIT_FRAME::SelectViaStack_Event( wxCommandEvent& event )
102{
103 int nPresets = (int) GetDesignSettings().m_ViaStackPresets.size();
104 int sel = m_SelViaStackBox->GetSelection();
105
106 if( sel == int( m_SelViaStackBox->GetCount() - 2 ) )
107 {
108 // the "---" separator
109 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
110 }
111 else if( sel == int( m_SelViaStackBox->GetCount() - 1 ) )
112 {
113 // "Edit Via Stacks..."
114 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
115
116 // See the matching comment in Tracks_and_Vias_Size_Event: defer so the GTK
117 // EVT_CHOICE signal unwinds before the toolbar is rebuilt.
118 CallAfter(
119 [this]()
120 {
121 ShowBoardSetupDialog( _( "Microvia Stacks" ) );
122 } );
123 }
124 else if( sel >= 0 && sel < nPresets )
125 {
127 }
128
129 GetCanvas()->SetFocus();
130}
131
132
134{
135 int ii;
136 int id = event.GetId();
137
138 switch( id )
139 {
144 break;
145
148 break;
149
150 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
151 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
169 break;
170
171 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
172 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
187 // select the new current value for via size (via diameter)
190 break;
191
193 ii = m_SelTrackWidthBox->GetSelection();
194
195 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
196 {
197 // this is the separator
198 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
199 }
200 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
201 {
202 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
203
204 // Best-guess fix for issue #23708 (crash on dialog OK reported on
205 // Flatpak/FreeBSD, not reproduced locally). Suspected cause is that
206 // ReCreateAuxiliaryToolbar(), run on dialog OK, destroys this very
207 // wxChoice while its EVT_CHOICE handler is still on the GTK signal
208 // stack. Defer the dialog so the handler unwinds first.
209 CallAfter( [this]()
210 {
211 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
212 } );
213 }
214 else
215 {
218 }
219
220 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
221 GetCanvas()->SetFocus();
222
223 break;
224
226 ii = m_SelViaSizeBox->GetSelection();
227
228 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
229 {
230 // this is the separator
231 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
232 }
233 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
234 {
235 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
236
237 // See the matching comment in the track-width case above.
238 CallAfter( [this]()
239 {
240 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
241 } );
242 }
243 else
244 {
246 }
247
248 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
249 GetCanvas()->SetFocus();
250
251 break;
252
253 default:
254 break;
255 }
256
257 // trackViaSizeChanged triggers ReCreateAuxiliaryToolbar(), which destroys m_SelTrackWidthBox /
258 // m_SelViaSizeBox. When this handler runs from the wxChoice EVT_CHOICE it is still on the GTK
259 // gtk_combo_box_set_active_iter signal stack for that very combo, so rebuilding the toolbar
260 // synchronously frees the combo mid-signal and crashes on the trailing g_object_notify (#23970).
261 // Defer the action so the GTK signal unwinds first, matching the deferred dialog above.
262 CallAfter( [this]() { m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged ); } );
263}
void SetViaSizeIndex(int aIndex)
Set the current via size list index to aIndex.
void SetViaStackIndex(int aIndex)
Set the current via stack preset index to aIndex.
void SetTrackWidthIndex(int aIndex)
Set the current track width list index to aIndex.
std::vector< VIA_STACK_PRESET > m_ViaStackPresets
void SetFocus() override
void SetLink(EDA_ITEM *aItem)
T Min() const
Definition minoptmax.h:29
T PinnedOpt() const
Definition minoptmax.h:32
bool HasOpt() const
Definition minoptmax.h:39
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
int GetuViaDrill() const
Definition netclass.h:182
int GetuViaDiameter() const
Definition netclass.h:174
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
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 SelectViaStack_Event(wxCommandEvent &event)
Handle the via stack preset selector on the auxiliary toolbar.
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
wxChoice * m_SelViaStackBox
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
wxChoice * m_SelTrackWidthBox
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:91
virtual int GetWidth() const
Definition pcb_track.h:92
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
@ ID_POPUP_PCB_SELECT_WIDTH14
Definition pcbnew_id.h:38
@ ID_POPUP_PCB_SELECT_WIDTH9
Definition pcbnew_id.h:33
@ ID_POPUP_PCB_SELECT_WIDTH1
Definition pcbnew_id.h:25
@ ID_POPUP_PCB_SELECT_VIASIZE8
Definition pcbnew_id.h:48
@ ID_POPUP_PCB_SELECT_VIASIZE9
Definition pcbnew_id.h:49
@ ID_POPUP_PCB_SELECT_VIASIZE11
Definition pcbnew_id.h:51
@ ID_POPUP_PCB_SELECT_WIDTH4
Definition pcbnew_id.h:28
@ ID_POPUP_PCB_SELECT_WIDTH11
Definition pcbnew_id.h:35
@ ID_POPUP_PCB_SELECT_VIASIZE15
Definition pcbnew_id.h:55
@ ID_POPUP_PCB_SELECT_VIASIZE3
Definition pcbnew_id.h:43
@ ID_POPUP_PCB_SELECT_VIASIZE7
Definition pcbnew_id.h:47
@ ID_POPUP_PCB_SELECT_VIASIZE10
Definition pcbnew_id.h:50
@ ID_POPUP_PCB_SELECT_WIDTH10
Definition pcbnew_id.h:34
@ ID_POPUP_PCB_SELECT_VIASIZE13
Definition pcbnew_id.h:53
@ ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES
Definition pcbnew_id.h:24
@ ID_AUX_TOOLBAR_PCB_VIA_SIZE
Definition pcbnew_id.h:17
@ ID_POPUP_PCB_SELECT_WIDTH16
Definition pcbnew_id.h:40
@ ID_POPUP_PCB_SELECT_VIASIZE12
Definition pcbnew_id.h:52
@ ID_POPUP_PCB_SELECT_AUTO_WIDTH
Definition pcbnew_id.h:23
@ ID_POPUP_PCB_SELECT_WIDTH2
Definition pcbnew_id.h:26
@ ID_POPUP_PCB_SELECT_WIDTH6
Definition pcbnew_id.h:30
@ ID_POPUP_PCB_SELECT_WIDTH13
Definition pcbnew_id.h:37
@ ID_POPUP_PCB_SELECT_VIASIZE1
Definition pcbnew_id.h:41
@ ID_POPUP_PCB_SELECT_VIASIZE4
Definition pcbnew_id.h:44
@ ID_POPUP_PCB_SELECT_WIDTH12
Definition pcbnew_id.h:36
@ ID_POPUP_PCB_SELECT_VIASIZE5
Definition pcbnew_id.h:45
@ ID_POPUP_PCB_SELECT_VIASIZE16
Definition pcbnew_id.h:56
@ ID_POPUP_PCB_SELECT_WIDTH15
Definition pcbnew_id.h:39
@ ID_POPUP_PCB_SELECT_WIDTH3
Definition pcbnew_id.h:27
@ ID_POPUP_PCB_SELECT_VIASIZE2
Definition pcbnew_id.h:42
@ ID_POPUP_PCB_SELECT_WIDTH7
Definition pcbnew_id.h:31
@ ID_POPUP_PCB_SELECT_VIASIZE14
Definition pcbnew_id.h:54
@ ID_AUX_TOOLBAR_PCB_TRACK_WIDTH
Definition pcbnew_id.h:18
@ ID_POPUP_PCB_SELECT_WIDTH5
Definition pcbnew_id.h:29
@ ID_POPUP_PCB_SELECT_VIASIZE6
Definition pcbnew_id.h:46