-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
edit_track_width.cpp
221 lines (192 loc) · 7.31 KB
/
edit_track_width.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <board_design_settings.h>
#include <pcb_edit_frame.h>
#include <pcbnew_id.h>
#include <pcb_track.h>
#include <tools/pcb_actions.h>
#include <tool/tool_manager.h>
#include <wx/choice.h>
void PCB_EDIT_FRAME::SetTrackSegmentWidth( PCB_TRACK* aItem, PICKED_ITEMS_LIST* aItemsListPicker,
bool aUseDesignRules )
{
PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem );
int new_width = -1;
int new_drill = -1;
if( aUseDesignRules )
{
MINOPTMAX<int> constraint = aItem->GetWidthConstraint();
if( constraint.HasOpt() )
new_width = constraint.Opt();
else if( constraint.Min() > 0 )
new_width = constraint.Min();
if( via )
{
constraint = via->GetDrillConstraint();
if( constraint.HasOpt() )
new_drill = constraint.Opt();
else if( constraint.Min() > 0 )
new_drill = constraint.Min();
}
}
else if( via && via->GetViaType() == VIATYPE::MICROVIA )
{
new_width = aItem->GetEffectiveNetClass()->GetuViaDiameter();
new_drill = aItem->GetEffectiveNetClass()->GetuViaDrill();
}
else if( via )
{
new_width = GetDesignSettings().GetCurrentViaSize();
new_drill = GetDesignSettings().GetCurrentViaDrill();
}
else
{
new_width = GetDesignSettings().GetCurrentTrackWidth();
}
if( new_width <= 0 )
new_width = aItem->GetWidth();
if( via && new_drill <= 0 )
new_drill = via->GetDrillValue();
if( aItem->GetWidth() != new_width || ( via && via->GetDrillValue() != new_drill ) )
{
ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
picker.SetLink( aItem->Clone() );
aItemsListPicker->PushItem( picker );
aItem->SetWidth( new_width );
if( via && new_drill > 0 )
via->SetDrill( new_drill );
}
}
void PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event( wxCommandEvent& event )
{
int ii;
int id = event.GetId();
switch( id )
{
case ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH:
{
if( GetDesignSettings().UseCustomTrackViaSize() )
{
GetDesignSettings().UseCustomTrackViaSize( false );
GetDesignSettings().m_UseConnectedTrackWidth = true;
}
else
{
GetDesignSettings().m_UseConnectedTrackWidth =
not GetDesignSettings().m_UseConnectedTrackWidth;
}
break;
}
case ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES:
GetDesignSettings().m_UseConnectedTrackWidth = false;
GetDesignSettings().SetTrackWidthIndex( 0 );
GetDesignSettings().SetViaSizeIndex( 0 );
break;
case ID_POPUP_PCB_SELECT_AUTO_WIDTH:
GetDesignSettings().m_UseConnectedTrackWidth = true;
break;
case ID_POPUP_PCB_SELECT_WIDTH1: // this is the default Netclass selection
case ID_POPUP_PCB_SELECT_WIDTH2: // this is a custom value selection
case ID_POPUP_PCB_SELECT_WIDTH3:
case ID_POPUP_PCB_SELECT_WIDTH4:
case ID_POPUP_PCB_SELECT_WIDTH5:
case ID_POPUP_PCB_SELECT_WIDTH6:
case ID_POPUP_PCB_SELECT_WIDTH7:
case ID_POPUP_PCB_SELECT_WIDTH8:
case ID_POPUP_PCB_SELECT_WIDTH9:
case ID_POPUP_PCB_SELECT_WIDTH10:
case ID_POPUP_PCB_SELECT_WIDTH11:
case ID_POPUP_PCB_SELECT_WIDTH12:
case ID_POPUP_PCB_SELECT_WIDTH13:
case ID_POPUP_PCB_SELECT_WIDTH14:
case ID_POPUP_PCB_SELECT_WIDTH15:
case ID_POPUP_PCB_SELECT_WIDTH16:
GetDesignSettings().m_UseConnectedTrackWidth = false;
ii = id - ID_POPUP_PCB_SELECT_WIDTH1;
GetDesignSettings().SetTrackWidthIndex( ii );
break;
case ID_POPUP_PCB_SELECT_VIASIZE1: // this is the default Netclass selection
case ID_POPUP_PCB_SELECT_VIASIZE2: // this is a custom value selection
case ID_POPUP_PCB_SELECT_VIASIZE3:
case ID_POPUP_PCB_SELECT_VIASIZE4:
case ID_POPUP_PCB_SELECT_VIASIZE5:
case ID_POPUP_PCB_SELECT_VIASIZE6:
case ID_POPUP_PCB_SELECT_VIASIZE7:
case ID_POPUP_PCB_SELECT_VIASIZE8:
case ID_POPUP_PCB_SELECT_VIASIZE9:
case ID_POPUP_PCB_SELECT_VIASIZE10:
case ID_POPUP_PCB_SELECT_VIASIZE11:
case ID_POPUP_PCB_SELECT_VIASIZE12:
case ID_POPUP_PCB_SELECT_VIASIZE13:
case ID_POPUP_PCB_SELECT_VIASIZE14:
case ID_POPUP_PCB_SELECT_VIASIZE15:
case ID_POPUP_PCB_SELECT_VIASIZE16:
// select the new current value for via size (via diameter)
ii = id - ID_POPUP_PCB_SELECT_VIASIZE1;
GetDesignSettings().SetViaSizeIndex( ii );
break;
case ID_AUX_TOOLBAR_PCB_TRACK_WIDTH:
ii = m_SelTrackWidthBox->GetSelection();
if( ii == int( m_SelTrackWidthBox->GetCount() - 2 ) )
{
// this is the separator
m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
}
else if( ii == int( m_SelTrackWidthBox->GetCount() - 1 ) )
{
m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
}
else
{
GetDesignSettings().SetTrackWidthIndex( ii );
GetDesignSettings().m_TempOverrideTrackWidth = true;
}
// Needed on Windows because the canvas loses focus after clicking on m_SelTrackWidthBox:
GetCanvas()->SetFocus();
break;
case ID_AUX_TOOLBAR_PCB_VIA_SIZE:
ii = m_SelViaSizeBox->GetSelection();
if( ii == int( m_SelViaSizeBox->GetCount() - 2 ) )
{
// this is the separator
m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
}
else if( ii == int( m_SelViaSizeBox->GetCount() - 1 ) )
{
m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
ShowBoardSetupDialog( _( "Pre-defined Sizes" ) );
}
else
{
GetDesignSettings().SetViaSizeIndex( ii );
}
// Needed on Windows because the canvas loses focus after clicking on m_SelViaSizeBox:
GetCanvas()->SetFocus();
break;
default:
break;
}
m_toolManager->RunAction( PCB_ACTIONS::trackViaSizeChanged );
}