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 aItem->SetWidth( new_width );
84
85 if( via && new_drill > 0 )
86 via->SetDrill( new_drill );
87 }
88}
89
90
91void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
92{
93 int ii;
94 int id = event.GetId();
95
96 switch( id )
97 {
102 break;
103
106 break;
107
108 case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
109 case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
127 break;
128
129 case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
130 case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
145 // select the new current value for via size (via diameter)
148 break;
149
151 ii = m_SelTrackWidthBox->GetSelection();
152
153 if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
154 {
155 // this is the separator
156 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
157 }
158 else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
159 {
160 m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
161
162 // Best-guess fix for issue #23708 (crash on dialog OK reported on
163 // Flatpak/FreeBSD, not reproduced locally). Suspected cause is that
164 // ReCreateAuxiliaryToolbar(), run on dialog OK, destroys this very
165 // wxChoice while its EVT_CHOICE handler is still on the GTK signal
166 // stack. Defer the dialog so the handler unwinds first.
167 CallAfter( [this]()
168 {
169 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
170 } );
171 }
172 else
173 {
176 }
177
178 // Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
179 GetCanvas()->SetFocus();
180
181 break;
182
184 ii = m_SelViaSizeBox->GetSelection();
185
186 if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
187 {
188 // this is the separator
189 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
190 }
191 else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
192 {
193 m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
194
195 // See the matching comment in the track-width case above.
196 CallAfter( [this]()
197 {
198 ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
199 } );
200 }
201 else
202 {
204 }
205
206 // Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
207 GetCanvas()->SetFocus();
208
209 break;
210
211 default:
212 break;
213 }
214
215 // trackViaSizeChanged triggers ReCreateAuxiliaryToolbar(), which destroys m_SelTrackWidthBox /
216 // m_SelViaSizeBox. When this handler runs from the wxChoice EVT_CHOICE it is still on the GTK
217 // gtk_combo_box_set_active_iter signal stack for that very combo, so rebuilding the toolbar
218 // synchronously frees the combo mid-signal and crashes on the trailing g_object_notify (#23970).
219 // Defer the action so the GTK signal unwinds first, matching the deferred dialog above.
220 CallAfter( [this]() { m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged ); } );
221}
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:29
T Opt() const
Definition minoptmax.h:31
bool HasOpt() const
Definition minoptmax.h:35
int GetuViaDrill() const
Definition netclass.h:163
int GetuViaDiameter() const
Definition netclass.h:155
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:69
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: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