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