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