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 bool g_modifyTracks = true;
57static bool g_modifyVias = true;
59static wxString g_netclassFilter;
60static bool g_filterByNet;
61static wxString g_netFilter;
62static bool g_filterByLayer;
63static int g_layerFilter;
64static bool g_filterByTrackWidth = false;
65static int g_trackWidthFilter = 0;
66static bool g_filterByViaSize = false;
67static int g_viaSizeFilter = 0;
68static bool g_filterSelected = false;
69static bool g_setToSpecifiedValues = true;
70
71
74 m_trackWidthFilter( aParent, nullptr, m_trackWidthFilterCtrl, m_trackWidthFilterUnits ),
75 m_viaSizeFilter( aParent, nullptr, m_viaSizeFilterCtrl, m_viaSizeFilterUnits )
76{
77 m_parent = aParent;
79
81
87
93
94 if( g_setToSpecifiedValues == true )
95 m_setToSpecifiedValues->SetValue( true );
96 else
97 m_setToDesignRuleValues->SetValue( true );
98
99 SetupStandardButtons( { { wxID_OK, _( "Apply and Close" ) },
100 { wxID_CANCEL, _( "Close" ) } } );
101
102 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
104 nullptr, this );
105
107 this );
108
110}
111
112
114{
115 g_modifyTracks = m_tracks->GetValue();
116 g_modifyVias = m_vias->GetValue();
118 g_netclassFilter = m_netclassFilter->GetStringSelection();
119 g_filterByNet = m_netFilterOpt->GetValue();
121 g_filterByLayer = m_layerFilterOpt->GetValue();
129
130 m_netFilter->Disconnect( FILTERED_ITEM_SELECTED,
132 nullptr, this );
133
134 m_parent->Unbind( EDA_EVT_UNITS_CHANGED,
136}
137
138
140{
141 int trackSel = m_trackWidthCtrl->GetSelection();
142 int viaSel = m_viaSizesCtrl->GetSelection();
143
148
149 m_trackWidthCtrl->SetSelection( trackSel );
150 m_viaSizesCtrl->SetSelection( viaSel );
151
152 aEvent.Skip();
153}
154
155
157{
158 // Populate the net filter list with net names
160
161 if( !m_brd->GetHighLightNetCodes().empty() )
163
164 // Populate the netclass filter list with netclass names
165 wxArrayString netclassNames;
166 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
167
168 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
169
170 for( const auto& [name, netclass] : settings->GetNetclasses() )
171 netclassNames.push_back( name );
172
173 m_netclassFilter->Set( netclassNames );
175
176 // Populate the layer filter list
182}
183
184
186{
188 m_selection = selTool->GetSelection();
190
191 m_tracks->SetValue( g_modifyTracks );
192 m_vias->SetValue( g_modifyVias );
193
194 if( g_filterByNetclass && m_netclassFilter->SetStringSelection( g_netclassFilter ) )
195 {
196 m_netclassFilterOpt->SetValue( true );
197 }
198 else if( item )
199 {
200 m_netclassFilter->SetStringSelection( item->GetNet()->GetNetClass()->GetName() );
201 }
202
203 if( g_filterByNet && m_brd->FindNet( g_netFilter ) != nullptr )
204 {
206 m_netFilterOpt->SetValue( true );
207 }
208 else if( item )
209 {
211 }
212
214 {
215 m_layerFilterOpt->SetValue( true );
216 }
217 else if( item )
218 {
219 if( item->Type() == PCB_ZONE_T ) // a zone can be on more than one layer
220 m_layerFilter->SetLayerSelection( static_cast<ZONE*>(item)->GetFirstLayer() );
221 else
223 }
224
226 {
227 m_filterByTrackWidth->SetValue( true );
229 }
230
232 {
233 m_filterByViaSize->SetValue( true );
235 }
236
237 m_trackWidthCtrl->SetSelection( (int) m_trackWidthCtrl->GetCount() - 1 );
238 m_viaSizesCtrl->SetSelection( (int) m_viaSizesCtrl->GetCount() - 1 );
239 m_annularRingsCtrl->SetSelection( (int) m_annularRingsCtrl->GetCount() - 1 );
240 m_layerCtrl->SetStringSelection( INDETERMINATE_ACTION );
241
243
244 wxCommandEvent dummy;
246
247 return true;
248}
249
250
252{
253 // Enable the items in the use specified values section
254 bool enable = m_setToSpecifiedValues->GetValue();
255
256 m_trackWidthLabel->Enable( enable );
257 m_trackWidthCtrl->Enable( enable );
258 m_viaSizeLabel->Enable( enable );
259 m_viaSizesCtrl->Enable( enable );
260 m_annularRingsLabel->Enable( enable );
261 m_annularRingsCtrl->Enable( enable );
262 m_layerLabel->Enable( enable );
263 m_layerCtrl->Enable( enable );
264}
265
266
268 PCB_TRACK* aItem )
269{
271 bool isTrack = aItem->Type() == PCB_TRACE_T;
272 bool isArc = aItem->Type() == PCB_ARC_T;
273 bool isVia = aItem->Type() == PCB_VIA_T;
274
275 if( m_setToSpecifiedValues->GetValue() )
276 {
277 if( ( isArc || isTrack ) && m_trackWidthCtrl->GetStringSelection() != INDETERMINATE_ACTION )
278 {
279 unsigned int prevTrackWidthIndex = brdSettings.GetTrackWidthIndex();
280 int trackWidthIndex = m_trackWidthCtrl->GetSelection();
281
282 if( trackWidthIndex >= 0 )
283 brdSettings.SetTrackWidthIndex( static_cast<unsigned>( trackWidthIndex + 1 ) );
284
285 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
286
287 brdSettings.SetTrackWidthIndex( prevTrackWidthIndex );
288 }
289
290 if( isVia && m_viaSizesCtrl->GetStringSelection() != INDETERMINATE_ACTION )
291 {
292 unsigned int prevViaSizeIndex = brdSettings.GetViaSizeIndex();
293 int viaSizeIndex = m_viaSizesCtrl->GetSelection();
294
295 if( viaSizeIndex >= 0 )
296 brdSettings.SetViaSizeIndex( static_cast<unsigned>( viaSizeIndex + 1 ) );
297
298 m_parent->SetTrackSegmentWidth( aItem, aUndoList, false );
299
300 brdSettings.SetViaSizeIndex( prevViaSizeIndex );
301 }
302
303 if( isVia && m_annularRingsCtrl->GetStringSelection() != INDETERMINATE_ACTION )
304 {
305 PCB_VIA* v = static_cast<PCB_VIA*>( aItem );
306
307 switch( m_annularRingsCtrl->GetSelection() )
308 {
309 case 0:
312 break;
313 case 1:
316 break;
317 case 2:
320 break;
321 default:
322 break;
323 }
324 }
325
326 if( ( isArc || isTrack ) && m_layerCtrl->GetLayerSelection() != UNDEFINED_LAYER )
327 {
328 if( aUndoList->FindItem( aItem ) < 0 )
329 {
330 ITEM_PICKER picker( nullptr, aItem, UNDO_REDO::CHANGED );
331 picker.SetLink( aItem->Clone() );
332 aUndoList->PushItem( picker );
333 }
334
336 m_parent->GetBoard()->GetConnectivity()->Update( aItem );
337 }
338 }
339 else
340 {
341 m_parent->SetTrackSegmentWidth( aItem, aUndoList, true );
342 }
343
344 m_items_changed.push_back( aItem );
345}
346
347
349{
350 if( m_selectedItemsFilter->GetValue() )
351 {
352 if( !aItem->IsSelected() )
353 {
354 EDA_GROUP* group = aItem->GetParentGroup();
355
356 while( group && !group->AsEdaItem()->IsSelected() )
357 group = group->AsEdaItem()->GetParentGroup();
358
359 if( !group )
360 return;
361 }
362 }
363
364 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
365 {
366 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
367 return;
368 }
369
370 if( m_netclassFilterOpt->GetValue() && !m_netclassFilter->GetStringSelection().IsEmpty() )
371 {
372 wxString filterNetclass = m_netclassFilter->GetStringSelection();
373 NETCLASS* netclass = aItem->GetEffectiveNetClass();
374
375 if( !netclass->ContainsNetclassWithName( filterNetclass ) )
376 return;
377 }
378
380 {
381 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
382 return;
383 }
384
385 if( aItem->Type() == PCB_VIA_T )
386 {
387 if( m_filterByViaSize->GetValue() && aItem->GetWidth() != m_viaSizeFilter.GetValue() )
388 return;
389 }
390 else
391 {
392 if( m_filterByTrackWidth->GetValue() && aItem->GetWidth() != m_trackWidthFilter.GetValue() )
393 return;
394 }
395
396 processItem( aUndoList, aItem );
397}
398
399
401{
402 PICKED_ITEMS_LIST itemsListPicker;
403 wxBusyCursor dummy;
404
405 // Examine segments
406 for( PCB_TRACK* track : m_brd->Tracks() )
407 {
408 if( m_tracks->GetValue() && track->Type() == PCB_TRACE_T )
409 visitItem( &itemsListPicker, track );
410 else if ( m_tracks->GetValue() && track->Type() == PCB_ARC_T )
411 visitItem( &itemsListPicker, track );
412 else if ( m_vias->GetValue() && track->Type() == PCB_VIA_T )
413 visitItem( &itemsListPicker, track );
414 }
415
416 if( itemsListPicker.GetCount() > 0 )
417 {
418 m_parent->SaveCopyInUndoList( itemsListPicker, UNDO_REDO::CHANGED );
419
420 for( PCB_TRACK* track : m_brd->Tracks() )
421 m_parent->GetCanvas()->GetView()->Update( track );
422 }
423
425
426 if( m_items_changed.size() )
427 {
430 }
431
432 return true;
433}
const char * name
Definition: DXF_plotter.cpp:62
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
const wxString & GetCurrentNetClassName() const
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
unsigned GetTrackWidthIndex() const
unsigned GetViaSizeIndex() const
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:283
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:898
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:553
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2010
const TRACKS & Tracks() const
Definition: board.h:336
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:942
void OnItemsChanged(std::vector< BOARD_ITEM * > &aItems)
Notify the board and its listeners that an item on the board has been modified in some way.
Definition: board.cpp:2731
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:496
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
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...
void ForceRefresh()
Force a redraw.
A set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:115
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
bool IsSelected() const
Definition: eda_item.h:126
void SetLink(EDA_ITEM *aItem)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:91
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:613
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
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition: netclass.cpp:316
NETCLASS * GetNetClass()
Definition: netinfo.h:101
void SetNetInfo(const NETINFO_LIST *aNetInfoList)
int GetSelectedNetcode()
void SetSelectedNetcode(int aNetcode)
void SetSelectedNet(const wxString &aNetname)
wxString GetSelectedNetname()
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition: padstack.h:313
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
Definition: undo_redo.cpp:163
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, bool aShowNetclass, bool aShowEdit)
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, bool aShowNetclass, bool aShowEdit)
void SetTrackSegmentWidth(PCB_TRACK *aItem, PICKED_ITEMS_LIST *aItemsListPicker, bool aUseDesignRules)
Modify one track segment width or one via diameter (using DRC control).
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetUndefinedLayerName(const wxString &aName)
void SetNotAllowedLayerSet(const LSET &aMask)
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:68
virtual int GetWidth() const
Definition: pcb_track.h:146
const PADSTACK & Padstack() const
Definition: pcb_track.h:453
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
EDA_ITEM * Front() const
Definition: selection.h:172
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
int GetIntValue()
Definition: unit_binder.h:129
virtual long long int GetValue()
Return the current value in Internal Units.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
Handle a list of polygons defining a copper zone.
Definition: zone.h:74
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:482
static wxString g_netclassFilter
static bool g_filterByNetclass
static int g_layerFilter
static bool g_filterByLayer
static bool g_filterByNet
static wxString g_netclassFilter
static bool g_filterByNetclass
static int g_layerFilter
static int g_trackWidthFilter
static bool g_filterSelected
static int g_viaSizeFilter
static bool g_filterByViaSize
static bool g_setToSpecifiedValues
static wxString g_netFilter
static bool g_modifyVias
static bool g_modifyTracks
static bool g_filterByTrackWidth
static bool g_filterByLayer
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:747
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_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:107
@ 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