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.PinnedOpt();
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.PinnedOpt();
52 else if( constraint.Min() > 0 )
53 new_drill = constraint.Min();
54 }
55 }
56 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
57 {
58 NETCLASS* netClass = via->GetEffectiveNetClass();
59 PCB_VIA original( *via );
60
61 // Resolve on the live via, since rules such as fromTo() match board items only
62 via->SetSizeFromRules( netClass->GetuViaDiameter(), netClass->GetuViaDrill() );
63 new_width = via->GetWidth( PADSTACK::ALL_LAYERS );
64 new_drill = via->GetDrillValue();
65 via->CopyFrom( &original );
66 }
67 else if( via )
68 {
71 }
72 else
73 {
75 }
76
77 if( new_width <= 0 )
78 new_width = aItem->GetWidth();
79
80 if( via && new_drill <= 0 )
81 new_drill = via->GetDrillValue();
82
83 if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
84 {
85 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
86 picker.SetLink( aItem->Clone() );
87 aItemsListPicker->PushItem( picker );
88
89 if( via )
90 via->SetWidth( PADSTACK::ALL_LAYERS, new_width );
91 else
92 aItem->SetWidth( new_width );
93
94 if( via && new_drill > 0 )
95 via->SetDrill( new_drill );
96 }
97}
98
99
100void PCB_EDIT_FRAME::SelectViaStack_Event( wxCommandEvent& event )
101{
102 int nPresets = (int) GetDesignSettings().m_ViaStackPresets.size();
103 int sel = m_SelViaStackBox->GetSelection();
104
105 if( sel == int( m_SelViaStackBox->GetCount() - 2 ) )
106 {
107 // the "---" separator
108 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
109 }
110 else if( sel == int( m_SelViaStackBox->GetCount() - 1 ) )
111 {
112 // "Edit Via Stacks..."
113 m_SelViaStackBox->SetSelection( GetDesignSettings().GetViaStackIndex() );
114
115 // See the matching comment in Tracks_and_Vias_Size_Event: defer so the GTK
116 // EVT_CHOICE signal unwinds before the toolbar is rebuilt.
117 CallAfter(
118 [this]()
119 {
120 ShowBoardSetupDialog( _( "Microvia Stacks" ) );
121 } );
122 }
123 else if( sel >= 0 && sel < nPresets )
124 {
126 }
127
128 GetCanvas()->SetFocus();
129}
130
131
133{
134 int ii;
135 int id = event.GetId();
136
137 switch( id )
138 {
143 break;
144
147 break;
148
149 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
150 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
168 break;
169
170 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
171 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
186 // select the new current value for via size (via diameter)
189 break;
190
192 ii = m_SelTrackWidthBox->GetSelection();
193
194 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
195 {
196 // this is the separator
197 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
198 }
199 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
200 {
201 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
202
203 // Best-guess fix for issue #23708 (crash on dialog OK reported on
204 // Flatpak/FreeBSD, not reproduced locally). Suspected cause is that
205 // ReCreateAuxiliaryToolbar(), run on dialog OK, destroys this very
206 // wxChoice while its EVT_CHOICE handler is still on the GTK signal
207 // stack. Defer the dialog so the handler unwinds first.
208 CallAfter( [this]()
209 {
210 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
211 } );
212 }
213 else
214 {
217 }
218
219 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
220 GetCanvas()->SetFocus();
221
222 break;
223
225 ii = m_SelViaSizeBox->GetSelection();
226
227 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
228 {
229 // this is the separator
230 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
231 }
232 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
233 {
234 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
235
236 // See the matching comment in the track-width case above.
237 CallAfter( [this]()
238 {
239 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
240 } );
241 }
242 else
243 {
245 }
246
247 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
248 GetCanvas()->SetFocus();
249
250 break;
251
252 default:
253 break;
254 }
255
256 // trackViaSizeChanged triggers ReCreateAuxiliaryToolbar(), which destroys m_SelTrackWidthBox /
257 // m_SelViaSizeBox. When this handler runs from the wxChoice EVT_CHOICE it is still on the GTK
258 // gtk_combo_box_set_active_iter signal stack for that very combo, so rebuilding the toolbar
259 // synchronously frees the combo mid-signal and crashes on the trailing g_object_notify (#23970).
260 // Defer the action so the GTK signal unwinds first, matching the deferred dialog above.
261 CallAfter( [this]() { m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged ); } );
262}
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:43
int GetuViaDrill() const
Definition netclass.h:174
int GetuViaDiameter() const
Definition netclass.h:166
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: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