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 new_width = -1;
35 int new_drill = -1;
36
37 if( aUseDesignRules )
38 {
39 MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
40
41 if( constraint.HasOpt() )
42 new_width = constraint.Opt();
43 else if( constraint.Min() > 0 )
44 new_width = constraint.Min();
45
46 if( via )
47 {
48 constraint = via->GetDrillConstraint();
49
50 if( constraint.HasOpt() )
51 new_drill = constraint.Opt();
52 else if( constraint.Min() > 0 )
53 new_drill = constraint.Min();
54 }
55 }
56 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
57 {
58 new_width = aItem->GetEffectiveNetClass()->GetuViaDiameter();
59 new_drill = aItem->GetEffectiveNetClass()->GetuViaDrill();
60 }
61 else if( via )
62 {
65 }
66 else
67 {
69 }
70
71 if( new_width <= 0 )
72 new_width = aItem->GetWidth();
73
74 if( via && new_drill <= 0 )
75 new_drill = via->GetDrillValue();
76
77 if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
78 {
79 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
80 picker.SetLink( aItem->Clone() );
81 aItemsListPicker->PushItem( picker );
82
83 if( via )
84 via->SetWidth( PADSTACK::ALL_LAYERS, new_width );
85 else
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::SelectViaStack_Event( wxCommandEvent& event )
95{
96 int nPresets = (int) GetDesignSettings().m_ViaStackPresets.size();
97 int sel = m_SelViaStackBox->GetSelection();
98
99 if( sel == int( m_SelViaStackBox->GetCount() - 2 ) )
100 {
101 // the "---" separator
102 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
103 }
104 else if( sel == int( m_SelViaStackBox->GetCount() - 1 ) )
105 {
106 // "Edit Via Stacks..."
107 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
108
109 // See the matching comment in Tracks_and_Vias_Size_Event: defer so the GTK
110 // EVT_CHOICE signal unwinds before the toolbar is rebuilt.
111 CallAfter(
112 [this]()
113 {
114 ShowBoardSetupDialog( _( "Microvia Stacks" ) );
115 } );
116 }
117 else if( sel >= 0 && sel < nPresets )
118 {
120 }
121
122 GetCanvas()->SetFocus();
123}
124
125
127{
128 int ii;
129 int id = event.GetId();
130
131 switch( id )
132 {
137 break;
138
141 break;
142
143 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
144 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
162 break;
163
164 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
165 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
180 // select the new current value for via size (via diameter)
183 break;
184
186 ii = m_SelTrackWidthBox->GetSelection();
187
188 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
189 {
190 // this is the separator
191 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
192 }
193 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
194 {
195 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
196
197 // Best-guess fix for issue #23708 (crash on dialog OK reported on
198 // Flatpak/FreeBSD, not reproduced locally). Suspected cause is that
199 // ReCreateAuxiliaryToolbar(), run on dialog OK, destroys this very
200 // wxChoice while its EVT_CHOICE handler is still on the GTK signal
201 // stack. Defer the dialog so the handler unwinds first.
202 CallAfter( [this]()
203 {
204 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
205 } );
206 }
207 else
208 {
211 }
212
213 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
214 GetCanvas()->SetFocus();
215
216 break;
217
219 ii = m_SelViaSizeBox->GetSelection();
220
221 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
222 {
223 // this is the separator
224 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
225 }
226 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
227 {
228 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
229
230 // See the matching comment in the track-width case above.
231 CallAfter( [this]()
232 {
233 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
234 } );
235 }
236 else
237 {
239 }
240
241 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
242 GetCanvas()->SetFocus();
243
244 break;
245
246 default:
247 break;
248 }
249
250 // trackViaSizeChanged triggers ReCreateAuxiliaryToolbar(), which destroys m_SelTrackWidthBox /
251 // m_SelViaSizeBox. When this handler runs from the wxChoice EVT_CHOICE it is still on the GTK
252 // gtk_combo_box_set_active_iter signal stack for that very combo, so rebuilding the toolbar
253 // synchronously frees the combo mid-signal and crashes on the trailing g_object_notify (#23970).
254 // Defer the action so the GTK signal unwinds first, matching the deferred dialog above.
255 CallAfter( [this]() { m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged ); } );
256}
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
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 Opt() const
Definition minoptmax.h:31
bool HasOpt() const
Definition minoptmax.h:36
int GetuViaDrill() const
Definition netclass.h:171
int GetuViaDiameter() const
Definition netclass.h:163
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
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_track.cpp:71
virtual MINOPTMAX< int > GetWidthConstraint(wxString *aSource=nullptr) const
virtual void SetWidth(int aWidth)
Definition pcb_track.h:86
virtual int GetWidth() const
Definition pcb_track.h:87
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