KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_global_edit_tracks_and_vias.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) 2009-2016 Jean-Pierre Charras, jean-pierre.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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <algorithm>
26
27#include <pcb_edit_frame.h>
28#include <widgets/unit_binder.h>
29#include <board.h>
31#include <pcb_track.h>
32#include <pcb_group.h>
35#include <tool/tool_manager.h>
39
40
41// Columns of netclasses grid
42enum {
49 GRID_DIFF_PAIR_WIDTH, // not currently included in grid
50 GRID_DIFF_PAIR_GAP, // not currently included in grid
51 GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
52};
53
54
55// Globals to remember control settings during a session
56static wxString g_netclassFilter;
57static wxString g_netFilter;
58
59
64{
65 m_parent = aParent;
66 m_brd = m_parent->GetBoard();
67
69
70 m_parent->UpdateTrackWidthSelectBox( m_trackWidthCtrl, false, false );
72 m_parent->UpdateViaSizeSelectBox( m_viaSizesCtrl, false, false );
75
76 m_layerCtrl->SetBoardFrame( m_parent );
77 m_layerCtrl->SetLayersHotkeys( false );
78 m_layerCtrl->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
79 m_layerCtrl->SetUndefinedLayerName( INDETERMINATE_ACTION );
80 m_layerCtrl->Resync();
81
82 SetupStandardButtons( { { wxID_OK, _( "Apply and Close" ) },
83 { wxID_CANCEL, _( "Close" ) } } );
84
85 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
87 nullptr, this );
88
89 m_parent->Bind( EDA_EVT_UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
90
92}
93
94
96{
97 g_netclassFilter = m_netclassFilter->GetStringSelection();
98 g_netFilter = m_netFilter->GetSelectedNetname();
99
100 m_netFilter->Disconnect( FILTERED_ITEM_SELECTED,
102 nullptr, this );
103
104 m_parent->Unbind( EDA_EVT_UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
105}
106
107
109{
110 int trackSel = m_trackWidthCtrl->GetSelection();
111 int viaSel = m_viaSizesCtrl->GetSelection();
112
113 m_parent->UpdateTrackWidthSelectBox( m_trackWidthCtrl, false, false );
115 m_parent->UpdateViaSizeSelectBox( m_viaSizesCtrl, false, false );
117
118 m_trackWidthCtrl->SetSelection( trackSel );
119 m_viaSizesCtrl->SetSelection( viaSel );
120
121 aEvent.Skip();
122}
123
124
126{
127 // Populate the net filter list with net names
128 m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
129
130 if( !m_brd->GetHighLightNetCodes().empty() )
131 m_netFilter->SetSelectedNetcode( *m_brd->GetHighLightNetCodes().begin() );
132
133 // Populate the netclass filter list with netclass names
134 wxArrayString netclassNames;
135 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
136
137 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
138
139 for( const auto& [name, netclass] : settings->GetNetclasses() )
140 netclassNames.push_back( name );
141
142 m_netclassFilter->Set( netclassNames );
143 m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() );
144
145 // Populate the layer filter list
146 m_layerFilter->SetBoardFrame( m_parent );
147 m_layerFilter->SetLayersHotkeys( false );
148 m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
149 m_layerFilter->Resync();
150 m_layerFilter->SetLayerSelection( m_parent->GetActiveLayer() );
151}
152
153
155{
156 m_netclassFilter->SetStringSelection( g_netclassFilter );
157
158 if( m_brd->FindNet( g_netFilter ) != nullptr )
159 m_netFilter->SetSelectedNet( g_netFilter );
160
161 m_trackWidthCtrl->SetSelection( (int) m_trackWidthCtrl->GetCount() - 1 );
162 m_viaSizesCtrl->SetSelection( (int) m_viaSizesCtrl->GetCount() - 1 );
163 m_annularRingsCtrl->SetSelection( (int) m_annularRingsCtrl->GetCount() - 1 );
164 m_layerCtrl->SetStringSelection( INDETERMINATE_ACTION );
165
166 wxCommandEvent dummy;
168
169 return true;
170}
171
172
174{
175 // Enable the items in the use specified values section
176 bool enable = m_setToSpecifiedValues->GetValue();
177
178 m_trackWidthLabel->Enable( enable );
179 m_trackWidthCtrl->Enable( enable );
180 m_viaSizeLabel->Enable( enable );
181 m_viaSizesCtrl->Enable( enable );
182 m_annularRingsLabel->Enable( enable );
183 m_annularRingsCtrl->Enable( enable );
184 m_layerLabel->Enable( enable );
185 m_layerCtrl->Enable( enable );
186}
187
188
190{
191 BOARD_DESIGN_SETTINGS& brdSettings = m_brd->GetDesignSettings();
192 bool isTrack = aItem->Type() == PCB_TRACE_T;
193 bool isArc = aItem->Type() == PCB_ARC_T;
194 bool isVia = aItem->Type() == PCB_VIA_T;
195
196 if( m_setToSpecifiedValues->GetValue() )
197 {
198 if( ( isArc || isTrack ) && m_trackWidthCtrl->GetStringSelection() != INDETERMINATE_ACTION )
199 {
200 int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
201 int trackWidthIndex = m_trackWidthCtrl->GetSelection();
202
203 if( trackWidthIndex >= 0 )
204 brdSettings.SetTrackWidthIndex( trackWidthIndex + 1 );
205
206 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
207
208 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
209 }
210
211 if( isVia && m_viaSizesCtrl->GetStringSelection() != INDETERMINATE_ACTION )
212 {
213 int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
214 int viaSizeIndex = m_viaSizesCtrl->GetSelection();
215
216 if( viaSizeIndex >= 0 )
217 brdSettings.SetViaSizeIndex( viaSizeIndex + 1 );
218
219 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
220
221 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
222 }
223
224 if( isVia && m_annularRingsCtrl->GetStringSelection() != INDETERMINATE_ACTION )
225 {
226 PCB_VIA* v = static_cast<PCB_VIA*>( aItem );
227
228 switch( m_annularRingsCtrl->GetSelection() )
229 {
230 case 0:
232 break;
233 case 1:
235 break;
236 case 2:
238 break;
239 case 3:
241 break;
242 default:
243 break;
244 }
245 }
246
247 if( ( isArc || isTrack ) && m_layerCtrl->GetLayerSelection() != UNDEFINED_LAYER )
248 {
249 if( aUndoList->FindItem( aItem ) < 0 )
250 {
251 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
252 picker.SetLink( aItem->Clone() );
253 aUndoList->PushItem( picker );
254 }
255
256 aItem->SetLayer( ToLAYER_ID( m_layerCtrl->GetLayerSelection() ) );
257 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
258 }
259 }
260 else
261 {
262 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
263 }
264
265 m_items_changed.push_back( aItem );
266}
267
268
270{
271 if( m_selectedItemsFilter->GetValue() )
272 {
273 if( !aItem->IsSelected() )
274 {
275 EDA_GROUP* group = aItem->GetParentGroup();
276
277 while( group && !group->AsEdaItem()->IsSelected() )
278 group = group->AsEdaItem()->GetParentGroup();
279
280 if( !group )
281 return;
282 }
283 }
284
285 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
286 {
287 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
288 return;
289 }
290
291 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
292 {
293 wxString filterNetclass = m_netclassFilter->GetStringSelection();
294 NETCLASS* netclass = aItem->GetEffectiveNetClass();
295
296 if( !netclass->ContainsNetclassWithName( filterNetclass ) )
297 return;
298 }
299
300 if( m_layerFilterOpt->GetValue() && m_layerFilter->GetLayerSelection() != UNDEFINED_LAYER )
301 {
302 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
303 return;
304 }
305
306 if( aItem->Type() == PCB_VIA_T )
307 {
308 if( m_filterByViaSize->GetValue() && aItem->GetWidth() != m_viaSizeFilter.GetValue() )
309 return;
310 }
311 else
312 {
313 if( m_filterByTrackWidth->GetValue() && aItem->GetWidth() != m_trackWidthFilter.GetValue() )
314 return;
315 }
316
317 processItem( aUndoList, aItem );
318}
319
320
322{
323 PICKED_ITEMS_LIST itemsListPicker;
324 wxBusyCursor dummy;
325
326 // Examine segments
327 for( PCB_TRACK* track : m_brd->Tracks() )
328 {
329 if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
330 visitItem( &itemsListPicker, track );
331 else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
332 visitItem( &itemsListPicker, track );
333 else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
334 visitItem( &itemsListPicker, track );
335 }
336
337 if( itemsListPicker.GetCount() > 0 )
338 {
339 m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
340
341 for( PCB_TRACK* track : m_brd->Tracks() )
342 m_parent->GetCanvas()->GetView()->Update( track );
343 }
344
345 m_parent->GetCanvas()->ForceRefresh();
346
347 if( m_items_changed.size() )
348 {
349 m_brd->OnItemsChanged( m_items_changed );
350 m_parent->OnModify();
351 }
352
353 return true;
354}
const char * name
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
Container for design settings for a BOARD object.
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.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:232
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:280
DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Set Track and Via Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void visitItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
void onActionButtonChange(wxCommandEvent &event) override
void processItem(PICKED_ITEMS_LIST *aUndoList, PCB_TRACK *aItem)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:46
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
bool IsSelected() const
Definition eda_item.h:127
void SetLink(EDA_ITEM *aItem)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:610
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:45
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition netclass.cpp:278
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition padstack.h:315
The main frame for Pcbnew.
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 int GetWidth() const
Definition pcb_track.h:146
const PADSTACK & Padstack() const
Definition pcb_track.h:459
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
int FindItem(const EDA_ITEM *aItem) const
unsigned GetCount() const
static wxString g_netclassFilter
#define _(s)
@ UNDEFINED_LAYER
Definition layer_ids.h:61
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
@ GRID_DIFF_PAIR_WIDTH
Class to handle a set of BOARD_ITEMs.
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96
#define INDETERMINATE_ACTION
Definition ui_common.h:47