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>
32#include <pcb_track.h>
33#include <pcb_group.h>
36#include <tool/tool_manager.h>
40#include "magic_enum.hpp"
41
42
43// Columns of netclasses grid
44enum {
51 GRID_DIFF_PAIR_WIDTH, // not currently included in grid
52 GRID_DIFF_PAIR_GAP, // not currently included in grid
53 GRID_DIFF_PAIR_VIA_GAP // not currently included in grid
54};
55
56
57// Globals to remember control settings during a session
58static wxString g_netclassFilter;
59static wxString g_netFilter;
60
61
66{
67 m_parent = aParent;
68 m_brd = m_parent->GetBoard();
69
71
72 m_parent->UpdateTrackWidthSelectBox( m_trackWidthCtrl, false, false );
74 m_parent->UpdateViaSizeSelectBox( m_viaSizesCtrl, false, false );
77
78 m_layerCtrl->SetBoardFrame( m_parent );
79 m_layerCtrl->SetLayersHotkeys( false );
80 m_layerCtrl->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
81 m_layerCtrl->SetUndefinedLayerName( INDETERMINATE_ACTION );
82 m_layerCtrl->Resync();
83
84 for( auto& preset : magic_enum::enum_values<IPC4761_PRESET>() )
85 {
86 if( preset >= IPC4761_PRESET::CUSTOM )
87 continue;
88
89 const auto& name_it = m_IPC4761Names.find( preset );
90
91 wxString name = _( "Unknown choice" );
92
93 if( name_it != m_IPC4761Names.end() )
94 name = name_it->second;
95
96 m_protectionFeatures->AppendString( name );
97 }
98
100
101 SetupStandardButtons( { { wxID_OK, _( "Apply and Close" ) },
102 { wxID_CANCEL, _( "Close" ) } } );
103
104 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
106 nullptr, this );
107
108 m_parent->Bind( EDA_EVT_UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
109
111}
112
113
115{
116 g_netclassFilter = m_netclassFilter->GetStringSelection();
117 g_netFilter = m_netFilter->GetSelectedNetname();
118
119 m_netFilter->Disconnect( FILTERED_ITEM_SELECTED,
121 nullptr, this );
122
123 m_parent->Unbind( EDA_EVT_UNITS_CHANGED, &DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged, this );
124}
125
126
127void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onVias( wxCommandEvent& aEvent )
128{
129 m_throughVias->SetValue( aEvent.IsChecked() );
130 m_microVias->SetValue( aEvent.IsChecked() );
131 m_blindVias->SetValue( aEvent.IsChecked() );
132 m_buriedVias->SetValue( aEvent.IsChecked() );
133
134 aEvent.Skip();
135}
136
137
139{
140 int checked = 0;
141
142 for( const wxCheckBox* cb : { m_throughVias, m_microVias, m_blindVias, m_buriedVias } )
143 {
144 if( cb->GetValue() )
145 checked++;
146 }
147
148 if( checked == 0 )
149 m_vias->SetValue( false );
150 else if( checked == 4 )
151 m_vias->SetValue( true );
152 else
153 m_vias->Set3StateValue( wxCHK_UNDETERMINED );
154}
155
156
158{
159 CallAfter(
160 [this]()
161 {
163 } );
164}
165
166
168{
169 int trackSel = m_trackWidthCtrl->GetSelection();
170 int viaSel = m_viaSizesCtrl->GetSelection();
171
172 m_parent->UpdateTrackWidthSelectBox( m_trackWidthCtrl, false, false );
174 m_parent->UpdateViaSizeSelectBox( m_viaSizesCtrl, false, false );
176
177 m_trackWidthCtrl->SetSelection( trackSel );
178 m_viaSizesCtrl->SetSelection( viaSel );
179
180 aEvent.Skip();
181}
182
183
185{
186 // Populate the net filter list with net names
187 m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
188
189 if( !m_brd->GetHighLightNetCodes().empty() )
190 m_netFilter->SetSelectedNetcode( *m_brd->GetHighLightNetCodes().begin() );
191
192 // Populate the netclass filter list with netclass names
193 wxArrayString netclassNames;
194 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
195
196 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
197
198 for( const auto& [name, netclass] : settings->GetNetclasses() )
199 netclassNames.push_back( name );
200
201 m_netclassFilter->Set( netclassNames );
202 m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() );
203
204 // Populate the layer filter list
205 m_layerFilter->SetBoardFrame( m_parent );
206 m_layerFilter->SetLayersHotkeys( false );
207 m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
208 m_layerFilter->Resync();
209 m_layerFilter->SetLayerSelection( m_parent->GetActiveLayer() );
210}
211
212
214{
215 m_netclassFilter->SetStringSelection( g_netclassFilter );
216
217 if( m_brd->FindNet( g_netFilter ) != nullptr )
218 m_netFilter->SetSelectedNet( g_netFilter );
219
220 m_trackWidthCtrl->SetSelection( (int) m_trackWidthCtrl->GetCount() - 1 );
221 m_viaSizesCtrl->SetSelection( (int) m_viaSizesCtrl->GetCount() - 1 );
222 m_annularRingsCtrl->SetSelection( (int) m_annularRingsCtrl->GetCount() - 1 );
223 m_layerCtrl->SetStringSelection( INDETERMINATE_ACTION );
224 m_protectionFeatures->SetStringSelection( INDETERMINATE_ACTION );
225
226 wxCommandEvent dummy;
228
230
231 return true;
232}
233
234
236{
237 // Enable the items in the use specified values section
238 bool enable = m_setToSpecifiedValues->GetValue();
239
240 m_trackWidthLabel->Enable( enable );
241 m_trackWidthCtrl->Enable( enable );
242 m_viaSizeLabel->Enable( enable );
243 m_viaSizesCtrl->Enable( enable );
244 m_annularRingsLabel->Enable( enable );
245 m_annularRingsCtrl->Enable( enable );
246 m_layerLabel->Enable( enable );
247 m_layerCtrl->Enable( enable );
248}
249
250
252{
253 BOARD_DESIGN_SETTINGS& brdSettings = m_brd->GetDesignSettings();
254 bool isTrack = aItem->Type() == PCB_TRACE_T;
255 bool isArc = aItem->Type() == PCB_ARC_T;
256 bool isVia = aItem->Type() == PCB_VIA_T;
257
258 if( m_setToSpecifiedValues->GetValue() )
259 {
260 if( ( isArc || isTrack ) && m_trackWidthCtrl->GetStringSelection() != INDETERMINATE_ACTION )
261 {
262 int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
263 int trackWidthIndex = m_trackWidthCtrl->GetSelection();
264
265 if( trackWidthIndex >= 0 )
266 brdSettings.SetTrackWidthIndex( trackWidthIndex + 1 );
267
268 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
269
270 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
271 }
272
273 if( isVia && m_viaSizesCtrl->GetStringSelection() != INDETERMINATE_ACTION )
274 {
275 int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
276 int viaSizeIndex = m_viaSizesCtrl->GetSelection();
277
278 if( viaSizeIndex >= 0 )
279 brdSettings.SetViaSizeIndex( viaSizeIndex + 1 );
280
281 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
282
283 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
284 }
285
286 if( isVia && m_annularRingsCtrl->GetStringSelection() != INDETERMINATE_ACTION )
287 {
288 PCB_VIA* v = static_cast<PCB_VIA*>( aItem );
289
290 switch( m_annularRingsCtrl->GetSelection() )
291 {
292 case 0:
294 break;
295 case 1:
297 break;
298 case 2:
300 break;
301 case 3:
303 break;
304 default:
305 break;
306 }
307 }
308
309 if( isVia && m_protectionFeatures->GetStringSelection() != INDETERMINATE_ACTION )
310 {
311 PCB_VIA* v = static_cast<PCB_VIA*>( aItem );
312
313 setViaConfiguration( v, static_cast<IPC4761_PRESET>( m_protectionFeatures->GetSelection() ) );
314 }
315
316 if( ( isArc || isTrack ) && m_layerCtrl->GetLayerSelection() != UNDEFINED_LAYER )
317 {
318 if( aUndoList->FindItem( aItem ) < 0 )
319 {
320 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
321 picker.SetLink( aItem->Clone() );
322 aUndoList->PushItem( picker );
323 }
324
325 aItem->SetLayer( ToLAYER_ID( m_layerCtrl->GetLayerSelection() ) );
326 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
327 }
328 }
329 else
330 {
331 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
332 }
333
334 m_items_changed.push_back( aItem );
335}
336
337
339{
340 if( m_selectedItemsFilter->GetValue() )
341 {
342 if( !aItem->IsSelected() )
343 {
344 EDA_GROUP* group = aItem->GetParentGroup();
345
346 while( group && !group->AsEdaItem()->IsSelected() )
347 group = group->AsEdaItem()->GetParentGroup();
348
349 if( !group )
350 return;
351 }
352 }
353
354 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
355 {
356 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
357 return;
358 }
359
360 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
361 {
362 wxString filterNetclass = m_netclassFilter->GetStringSelection();
363 NETCLASS* netclass = aItem->GetEffectiveNetClass();
364
365 if( !netclass->ContainsNetclassWithName( filterNetclass ) )
366 return;
367 }
368
369 if( m_layerFilterOpt->GetValue() && m_layerFilter->GetLayerSelection() != UNDEFINED_LAYER )
370 {
371 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
372 return;
373 }
374
375 if( aItem->Type() == PCB_VIA_T )
376 {
377 if( m_filterByViaSize->GetValue() && aItem->GetWidth() != m_viaSizeFilter.GetValue() )
378 return;
379 }
380 else
381 {
382 if( m_filterByTrackWidth->GetValue() && aItem->GetWidth() != m_trackWidthFilter.GetValue() )
383 return;
384 }
385
386 processItem( aUndoList, aItem );
387}
388
389
391{
392 PICKED_ITEMS_LIST itemsListPicker;
393 wxBusyCursor dummy;
394
395 // Examine segments
396 for( PCB_TRACK* track : m_brd->Tracks() )
397 {
398 if( track->Type() == PCB_TRACE_T && m_tracks->GetValue() )
399 {
400 visitItem( &itemsListPicker, track );
401 }
402 else if ( track->Type() == PCB_ARC_T && m_tracks->GetValue() )
403 {
404 visitItem( &itemsListPicker, track );
405 }
406 else if( track->Type() == PCB_VIA_T )
407 {
408 PCB_VIA* via = static_cast<PCB_VIA*>( track );
409
410 if( via->GetViaType() == VIATYPE::THROUGH && m_throughVias->GetValue() )
411 visitItem( &itemsListPicker, via );
412 else if( via->GetViaType() == VIATYPE::MICROVIA && m_microVias->GetValue() )
413 visitItem( &itemsListPicker, via );
414 else if( via->GetViaType() == VIATYPE::BLIND && m_blindVias->GetValue() )
415 visitItem( &itemsListPicker, via );
416 else if( via->GetViaType() == VIATYPE::BURIED && m_buriedVias->GetValue() )
417 visitItem( &itemsListPicker, via );
418 }
419 }
420
421 if( itemsListPicker.GetCount() > 0 )
422 {
423 m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
424
425 for( PCB_TRACK* track : m_brd->Tracks() )
426 m_parent->GetCanvas()->GetView()->Update( track );
427 }
428
429 m_parent->GetCanvas()->ForceRefresh();
430
431 if( m_items_changed.size() )
432 {
433 m_brd->OnItemsChanged( m_items_changed );
434 m_parent->OnModify();
435 }
436
437 return true;
438}
const char * name
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
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.
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 onViaType(wxCommandEvent &aEvent) override
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:117
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
bool IsSelected() const
Definition eda_item.h:128
void SetLink(EDA_ITEM *aItem)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:627
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:284
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition padstack.h:364
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:73
virtual int GetWidth() const
Definition pcb_track.h:148
const PADSTACK & Padstack() const
Definition pcb_track.h:463
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
const std::map< IPC4761_PRESET, wxString > m_IPC4761Names
void setViaConfiguration(PCB_VIA *aVia, const IPC4761_PRESET &aPreset)
static wxString g_netclassFilter
#define _(s)
@ UNDEFINED_LAYER
Definition layer_ids.h:61
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:754
@ GRID_DIFF_PAIR_WIDTH
Class to handle a set of BOARD_ITEMs.
@ THROUGH
Definition pcb_track.h:68
@ MICROVIA
Definition pcb_track.h:71
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