KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_copper_zones.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/radiobut.h>
27#include <kiface_base.h>
28#include <confirm.h>
29#include <pcb_edit_frame.h>
30#include <pcbnew_settings.h>
31#include <zones.h>
32#include <widgets/unit_binder.h>
33#include <zone.h>
34#include <pad.h>
35#include <board.h>
36#include <trigo.h>
37#include <eda_pattern_match.h>
38
40#include <string_utils.h>
41
42
44{
45public:
47 CONVERT_SETTINGS* aConvertSettings );
48
50 { delete m_gap; }
51
52private:
53 using NET_FILTER = std::unique_ptr<EDA_PATTERN_MATCH>;
54 using NET_FILTER_LIST = std::vector<NET_FILTER>;
55
56 static constexpr int INVALID_NET_CODE{ 0 };
57
58 static constexpr int DEFAULT_SORT_CONFIG{ -1 };
59 static constexpr int NO_PERSISTENT_SORT_MODE{ 0 };
60 static constexpr int HIDE_ANONYMOUS_NETS{ 1 << 0 };
61 static constexpr int SORT_BY_PAD_COUNT{ 1 << 1 };
62
63 bool TransferDataToWindow() override;
64 bool TransferDataFromWindow() override;
65
69 bool AcceptOptions();
70
71 void OnStyleSelection( wxCommandEvent& event ) override;
72 void OnLayerSelection( wxDataViewEvent& event ) override;
73 void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
74 void OnShowNetNameFilterChange( wxCommandEvent& event ) override;
75 void OnUpdateUI( wxUpdateUIEvent& ) override;
76 void OnNetSelectionUpdated( wxCommandEvent& event ) override;
77 void OnRemoveIslandsSelection( wxCommandEvent& event ) override;
78 void OnPadInZoneSelection( wxCommandEvent& event ) override;
79
80 void readNetInformation();
82 wxArrayString buildListOfNetsToDisplay();
83 void sortNetsByPadCount( std::vector<NETINFO_ITEM*>& nets, const int maxNetCode );
85 int ensureSelectedNetIsVisible( int selectedNetCode, wxArrayString& netsList );
86 void displayNetsList( const wxArrayString& netNamesList, int selectIndex );
88 wxString getUnescapedNetName( const NETINFO_ITEM* net );
89 void sortNetsIfRequired();
91 void updateInfoBar();
94
95private:
97
102
107
113
120
121 wxStaticText* m_gapLabel;
122 wxTextCtrl* m_gapCtrl;
123 wxStaticText* m_gapUnits;
125
126 std::map<wxString, int> m_netNameToNetCode;
127 std::vector<NETINFO_ITEM*> m_netInfoItemList;
128
130 wxRadioButton* m_rbCenterline;
131 wxRadioButton* m_rbEnvelope;
133};
134
135
137 CONVERT_SETTINGS* aConvertSettings )
138{
139 DIALOG_COPPER_ZONE dlg( aCaller, aSettings, aConvertSettings );
140
141 // TODO: why does this need QuasiModal?
142 return dlg.ShowQuasiModal();
143}
144
145
146// The pad count for each netcode, stored in a buffer for a fast access.
147// This is needed by the sort function sortNetsByNodes()
148static std::vector<int> padCountListByNet;
149
150
151// Sort nets by decreasing pad count.
152// For same pad count, sort by alphabetic names
153static bool sortNetsByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
154{
155 int countA = padCountListByNet[a->GetNetCode()];
156 int countB = padCountListByNet[b->GetNetCode()];
157
158 if( countA == countB )
159 return a->GetNetname() < b->GetNetname();
160 else
161 return countB < countA;
162}
163
164
165// Sort nets by alphabetic names
166static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
167{
168 return a->GetNetname() < b->GetNetname();
169}
170
171
173 CONVERT_SETTINGS* aConvertSettings ) :
174 DIALOG_COPPER_ZONE_BASE( aParent ),
175 m_cornerSmoothingType( ZONE_SETTINGS::SMOOTHING_UNDEFINED ),
191 m_convertSettings( aConvertSettings ),
192 m_rbCenterline( nullptr ),
193 m_rbEnvelope( nullptr ),
194 m_cbDeleteOriginals( nullptr )
195{
196 m_Parent = aParent;
197
198 m_ptr = aSettings;
199 m_settings = *aSettings;
200 m_settings.SetupLayersList( m_layers, m_Parent, LSET::AllCuMask( aParent->GetBoard()->GetCopperLayerCount() ) );
202
203 switch( m_settings.m_TeardropType )
204 {
205 case TEARDROP_TYPE::TD_NONE:
206 // standard copper zone
207 break;
208
209 case TEARDROP_TYPE::TD_VIAPAD:
210 SetTitle( _( "Teardrop on Vias/Pads Properties" ) );
211 break;
212
213 case TEARDROP_TYPE::TD_TRACKEND:
214 SetTitle( _( "Teardrop on Tracks Properties" ) );
215 break;
216
217 default:
218 SetTitle( _( "Teardrop Properties" ) );
219 break;
220 }
221
222 if( aConvertSettings )
223 {
224 wxStaticBox* bConvertBox = new wxStaticBox( this, wxID_ANY, _( "Conversion Settings" ) );
225 wxStaticBoxSizer* bConvertSizer = new wxStaticBoxSizer( bConvertBox, wxVERTICAL );
226
227 m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
228 bConvertSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
229
230 bConvertSizer->AddSpacer( 2 );
231 m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
232 bConvertSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
233
234 m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
235 m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
236 m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
237 m_gap = new UNIT_BINDER( m_Parent, m_gapLabel, m_gapCtrl, m_gapUnits );
238 m_gap->SetValue( m_convertSettings->m_Gap );
239
240 wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
241 hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 5 );
242 hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 5 );
243 hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL|wxLEFT, 5 );
244 bConvertSizer->AddSpacer( 2 );
245 bConvertSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
246
247 bConvertSizer->AddSpacer( 6 );
248 m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) );
249 bConvertSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
250
251 GetSizer()->Insert( 0, bConvertSizer, 0, wxALL|wxEXPAND, 10 );
252
253 wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
254 wxLI_HORIZONTAL );
255 GetSizer()->Insert( 1, line, 0, wxLEFT|wxRIGHT|wxEXPAND, 10 );
256
257 SetTitle( _( "Convert to Copper Zone" ) );
258 }
259 else
260 {
261 m_gapLabel = nullptr;
262 m_gapCtrl = nullptr;
263 m_gapUnits = nullptr;
264 m_gap = nullptr;
265 }
266
269
270 m_netSortingByPadCount = true; // false = alphabetic sort, true = pad count sort
271
272 m_ShowNetNameFilter->SetHint( _( "Filter" ) );
273
274 m_cbRemoveIslands->Bind( wxEVT_CHOICE,
275 [&]( wxCommandEvent& )
276 {
277 // Area mode is index 2
278 m_islandThreshold.Enable( m_cbRemoveIslands->GetSelection() == 2 );
279 } );
280
282
284}
285
286
288{
290 {
291 if( m_convertSettings->m_Strategy == BOUNDING_HULL )
292 m_rbEnvelope->SetValue( true );
293 else
294 m_rbCenterline->SetValue( true );
295
296 m_cbDeleteOriginals->SetValue( m_convertSettings->m_DeleteOriginals );
297 m_gap->Enable( m_rbEnvelope->GetValue() );
298 }
299
300 m_cbLocked->SetValue( m_settings.m_Locked );
301 m_cornerSmoothingChoice->SetSelection( m_settings.GetCornerSmoothingType() );
302 m_cornerRadius.SetValue( m_settings.GetCornerRadius() );
303 m_PriorityLevelCtrl->SetValue( m_settings.m_ZonePriority );
304
305 if( m_isTeardrop ) // outlines are never smoothed: they have already the right shape
306 {
307 m_cornerSmoothingChoice->SetSelection( 0 );
308 m_cornerSmoothingChoice->Enable( false );
309 m_cornerRadius.SetValue( 0 );
310 m_cornerRadius.Enable( false );
311 }
312
313 switch( m_settings.m_ZoneBorderDisplayStyle )
314 {
315 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: m_OutlineDisplayCtrl->SetSelection( 0 ); break;
318 case ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER: break; // Not used for standard zones
319 }
320
321 m_outlineHatchPitch.SetValue( m_settings.m_BorderHatchPitch );
322
323 m_clearance.SetValue( m_settings.m_ZoneClearance );
324 m_minWidth.SetValue( m_settings.m_ZoneMinThickness );
325
326 switch( m_settings.GetPadConnection() )
327 {
328 default:
329 case ZONE_CONNECTION::THERMAL: m_PadInZoneOpt->SetSelection( 1 ); break;
330 case ZONE_CONNECTION::THT_THERMAL: m_PadInZoneOpt->SetSelection( 2 ); break;
331 case ZONE_CONNECTION::NONE: m_PadInZoneOpt->SetSelection( 3 ); break;
332 case ZONE_CONNECTION::FULL: m_PadInZoneOpt->SetSelection( 0 ); break;
333 }
334
335 if( m_isTeardrop )
336 {
337 m_PadInZoneOpt->SetSelection( 0 );
338 m_PadInZoneOpt->Enable( false );
339 }
340
341 // Do not enable/disable antipad clearance and spoke width. They might be needed if
342 // a footprint or pad overrides the zone to specify a thermal connection.
343 m_antipadClearance.SetValue( m_settings.m_ThermalReliefGap );
344 m_spokeWidth.SetValue( m_settings.m_ThermalReliefSpokeWidth );
345
347 m_islandThreshold.SetDoubleValue( static_cast<double>( m_settings.GetMinIslandArea() ) );
348
349 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings.GetIslandRemovalMode() ) );
350
351 m_islandThreshold.Enable( m_settings.GetIslandRemovalMode() == ISLAND_REMOVAL_MODE::AREA );
352
354
357
359
360 // Initialize information required to display nets list
362
364 m_GridStyleCtrl->SetSelection( 1 );
365 else
366 m_GridStyleCtrl->SetSelection( 0 );
367
368 m_GridStyleCtrl->Enable( !m_isTeardrop );
369
371 m_gridStyleRotation.SetAngleValue( m_settings.m_HatchOrientation );
372 m_gridStyleThickness.SetValue( m_settings.m_HatchThickness );
373 m_gridStyleGap.SetValue( m_settings.m_HatchGap );
374
375 m_spinCtrlSmoothLevel->SetValue( m_settings.m_HatchSmoothingLevel );
376 m_spinCtrlSmoothValue->SetValue( m_settings.m_HatchSmoothingValue );
377
378 m_tcZoneName->SetValue( m_settings.m_Name );
379
381
382 // Enable/Disable some widgets
383 wxCommandEvent event;
384 OnStyleSelection( event );
385 OnNetSelectionUpdated( event );
386 OnPadInZoneSelection( event );
387
388 Fit();
389
390 return true;
391}
392
393
395{
396 const NETINFO_LIST& netInfoList = m_Parent->GetBoard()->GetNetInfo();
397
398 m_netInfoItemList.clear();
399 m_netInfoItemList.reserve( netInfoList.GetNetCount() );
400
401 m_netNameToNetCode.clear();
402 m_netNameToNetCode[ _( "<no net>" ) ] = INVALID_NET_CODE;
403
405
406 for( NETINFO_ITEM* net : netInfoList )
407 {
408 const int netCode = net->GetNetCode();
409 const wxString& netName = getUnescapedNetName( net );
410
411 m_netNameToNetCode[netName] = netCode;
412
413 if( netCode > INVALID_NET_CODE && net->IsCurrent() )
414 {
415 m_netInfoItemList.push_back( net );
416 m_maxNetCode = std::max( netCode, m_maxNetCode );
417 }
418 }
419
421}
422
423
424void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
425{
426 if( m_cornerSmoothingType != m_cornerSmoothingChoice->GetSelection() )
427 {
429
431 m_cornerRadiusLabel->SetLabel( _( "Chamfer distance:" ) );
432 else
433 m_cornerRadiusLabel->SetLabel( _( "Fillet radius:" ) );
434 }
435
437
438 if( m_gap )
439 m_gap->Enable( m_rbEnvelope->GetValue() );
440}
441
442
443void DIALOG_COPPER_ZONE::OnNetSelectionUpdated( wxCommandEvent& event )
444{
446
448
449 // When info bar is updated, the nets-list shrinks.
450 // Therefore, we need to reestablish the list and maintain the
451 // correct selection
453
454 // Zones with no net never have islands removed
456 {
457 if( m_cbRemoveIslands->IsEnabled() )
458 m_settings.SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
459
460 m_cbRemoveIslands->SetSelection( 1 );
461 m_staticText40->Enable( false );
462 m_cbRemoveIslands->Enable( false );
463 }
464 else if( !m_cbRemoveIslands->IsEnabled() )
465 {
466 m_cbRemoveIslands->SetSelection( static_cast<int>( m_settings.GetIslandRemovalMode() ) );
467 m_staticText40->Enable( true );
468 m_cbRemoveIslands->Enable( true );
469 }
470}
471
472
474{
475 m_islandThreshold.Enable( m_cbRemoveIslands->GetSelection() == 2 );
476}
477
478
479void DIALOG_COPPER_ZONE::OnPadInZoneSelection( wxCommandEvent& event )
480{
481 int selection = m_PadInZoneOpt->GetSelection();
482 bool enabled = selection == 1 || selection == 2;
483 m_antipadClearance.Enable( enabled );
484 m_spokeWidth.Enable( enabled );
485}
486
487
489{
490 if( m_GridStyleCtrl->GetSelection() > 0 )
492 else
494
495 if( !AcceptOptions() )
496 return false;
497
499 {
500 if( m_rbEnvelope->GetValue() )
501 m_convertSettings->m_Strategy = BOUNDING_HULL;
502 else
503 m_convertSettings->m_Strategy = CENTERLINE;
504
505 m_convertSettings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
506 m_convertSettings->m_Gap = m_gap->GetIntValue();
507 }
508
509 m_settings.m_HatchOrientation = m_gridStyleRotation.GetAngleValue();
510 m_settings.m_HatchThickness = m_gridStyleThickness.GetIntValue();
511 m_settings.m_HatchGap = m_gridStyleGap.GetIntValue();
512 m_settings.m_HatchSmoothingLevel = m_spinCtrlSmoothLevel->GetValue();
513 m_settings.m_HatchSmoothingValue = m_spinCtrlSmoothValue->GetValue();
514
515 *m_ptr = m_settings;
516 return true;
517}
518
519
521{
522 if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
523 return false;
524
525 if( !m_minWidth.Validate( pcbIUScale.mmToIU( ZONE_THICKNESS_MIN_VALUE_MM ), INT_MAX ) )
526 return false;
527
528 if( !m_cornerRadius.Validate( 0, INT_MAX ) )
529 return false;
530
531 if( !m_spokeWidth.Validate( 0, INT_MAX ) )
532 return false;
533
535
536 if( m_settings.m_FillMode == ZONE_FILL_MODE::HATCH_PATTERN )
537 {
538 int minThickness = m_minWidth.GetIntValue();
539
540 if( !m_gridStyleThickness.Validate( minThickness, INT_MAX ) )
541 return false;
542
543 if( !m_gridStyleGap.Validate( minThickness, INT_MAX ) )
544 return false;
545 }
546
547 switch( m_PadInZoneOpt->GetSelection() )
548 {
549 case 3: m_settings.SetPadConnection( ZONE_CONNECTION::NONE ); break;
550 case 2: m_settings.SetPadConnection( ZONE_CONNECTION::THT_THERMAL ); break;
551 case 1: m_settings.SetPadConnection( ZONE_CONNECTION::THERMAL ); break;
552 case 0: m_settings.SetPadConnection( ZONE_CONNECTION::FULL ); break;
553 }
554
555 switch( m_OutlineDisplayCtrl->GetSelection() )
556 {
557 case 0: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
558 case 1: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
559 case 2: m_settings.m_ZoneBorderDisplayStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
560 }
561
564 return false;
565
566 m_settings.m_BorderHatchPitch = m_outlineHatchPitch.GetIntValue();
567
568 m_settings.m_ZoneClearance = m_clearance.GetIntValue();
569 m_settings.m_ZoneMinThickness = m_minWidth.GetIntValue();
570
571 m_settings.SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
572
573 if( m_settings.GetCornerSmoothingType() == ZONE_SETTINGS::SMOOTHING_NONE )
574 m_settings.SetCornerRadius( 0 );
575 else
576 m_settings.SetCornerRadius( m_cornerRadius.GetIntValue() );
577
578 m_settings.m_ZonePriority = m_PriorityLevelCtrl->GetValue();
579
580 m_settings.m_Locked = m_cbLocked->GetValue();
581
582 m_settings.m_ThermalReliefGap = m_antipadClearance.GetValue();
583 m_settings.m_ThermalReliefSpokeWidth = m_spokeWidth.GetValue();
584
585 if( m_settings.m_ThermalReliefSpokeWidth < m_settings.m_ZoneMinThickness )
586 {
587 DisplayError( this, _( "Thermal spoke width cannot be smaller than the minimum width." ) );
588 return false;
589 }
590
592
593 m_settings.SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
594 m_settings.SetMinIslandArea( m_islandThreshold.GetValue() );
595
596 // Get the layer selection for this zone
597 int layers = 0;
598
599 for( int ii = 0; ii < m_layers->GetItemCount(); ++ii )
600 {
601 if( m_layers->GetToggleValue( (unsigned) ii, 0 ) )
602 layers++;
603 }
604
605 if( layers == 0 )
606 {
607 DisplayError( this, _( "No layer selected." ) );
608 return false;
609 }
610
612
613 m_settings.m_Name = m_tcZoneName->GetValue();
614
615 return true;
616}
617
618
620{
621 const int netSelection = m_ListNetNameSelection->GetSelection();
622
623 if( netSelection > 0 )
624 {
625 const wxString& selectedNetName = m_ListNetNameSelection->GetString( netSelection );
627 }
628 else
629 {
631 }
632}
633
634
635void DIALOG_COPPER_ZONE::OnStyleSelection( wxCommandEvent& event )
636{
637 bool enable = m_GridStyleCtrl->GetSelection() >= 1;
638 m_tcGridStyleThickness->Enable( enable );
639 m_tcGridStyleGap->Enable( enable );
640 m_tcGridStyleOrientation->Enable( enable );
641 m_spinCtrlSmoothLevel->Enable( enable );
642 m_spinCtrlSmoothValue->Enable( enable );
643}
644
645
646void DIALOG_COPPER_ZONE::OnLayerSelection( wxDataViewEvent& event )
647{
648 if( event.GetColumn() != 0 )
649 return;
650
651 int row = m_layers->ItemToRow( event.GetItem() );
652
653 bool checked = m_layers->GetToggleValue( row, 0 );
654
655 wxVariant layerID;
656 m_layers->GetValue( layerID, row, 2 );
657
658 m_settings.m_Layers.set( ToLAYER_ID( layerID.GetInteger() ), checked );
659}
660
661
666
667
669{
670 // These configurations are persistent across multiple invocations of
671 // this dialog
672 int newConfig = NO_PERSISTENT_SORT_MODE;
673
675 newConfig |= HIDE_ANONYMOUS_NETS;
676
678 newConfig |= SORT_BY_PAD_COUNT;
679
680 if( PCBNEW_SETTINGS* cfg = m_Parent->GetPcbNewSettings() )
681 cfg->m_Zones.net_sort_mode = newConfig;
682}
683
684
686{
687 if( PCBNEW_SETTINGS* cfg = m_Parent->GetPcbNewSettings() )
688 {
689 int sortMode = cfg->m_Zones.net_sort_mode;
690
691 if( sortMode == DEFAULT_SORT_CONFIG )
692 sortMode = HIDE_ANONYMOUS_NETS;
693
696 }
697}
698
699
704
705
707{
709
710 wxArrayString listOfNets = buildListOfNetsToDisplay();
711
712 const int selectedNet = ensureSelectedNetIsVisible( m_currentlySelectedNetcode, listOfNets );
713
714 displayNetsList( listOfNets, selectedNet );
715}
716
717
719{
721
722 // Hide nets filter criteria
724
725 // Nets sort criteria
727}
728
729
731{
732 wxString netNameShowFilter = m_ShowNetNameFilter->GetValue();
733
734 if( netNameShowFilter.Len() == 0 )
735 netNameShowFilter = wxT( "*" );
736
737 wxStringTokenizer showFilters( netNameShowFilter.Lower(), "," );
738
739 m_showNetsFilter.clear();
740
741 while( showFilters.HasMoreTokens() )
742 {
743 wxString filter = showFilters.GetNextToken().Trim( false ).Trim( true );
744
745 if( !filter.IsEmpty() )
746 {
747 m_showNetsFilter.emplace_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
748 m_showNetsFilter.back()->SetPattern( filter );
749 }
750 }
751}
752
753
755{
757
758 wxArrayString netNames;
759
760 for( NETINFO_ITEM* net : m_netInfoItemList )
761 {
762 if( m_hideAutoGeneratedNets && net->HasAutoGeneratedNetname() )
763 continue;
764
765 const wxString& netName = getUnescapedNetName( net );
766
767 for( const NET_FILTER& filter : m_showNetsFilter )
768 {
769 if( filter->Find( netName.Lower() ) )
770 {
771 netNames.Add( netName );
772 break;
773 }
774 }
775 }
776
777 netNames.Insert( _( "<no net>" ), INVALID_NET_CODE );
778
779 return netNames;
780}
781
782
790
791
792void DIALOG_COPPER_ZONE::sortNetsByPadCount( std::vector<NETINFO_ITEM*>& nets,
793 const int maxNetCode )
794{
795 const std::vector<PAD*> pads = m_Parent->GetBoard()->GetPads();
796
797 padCountListByNet.clear();
798
799 // +1 is required for <no-net> item
800 padCountListByNet.assign( maxNetCode + 1, 0 );
801
802 for( PAD* pad : pads )
803 {
804 const int netCode = pad->GetNetCode();
805
806 if( netCode > INVALID_NET_CODE )
807 padCountListByNet[netCode]++;
808 }
809
810 sort( nets.begin(), nets.end(), sortNetsByNodes );
811}
812
813
814void DIALOG_COPPER_ZONE::displayNetsList( const wxArrayString& netNamesList, int selectIndex )
815{
816 m_ListNetNameSelection->Clear();
817 m_ListNetNameSelection->InsertItems( netNamesList, 0 );
818 m_ListNetNameSelection->SetSelection( selectIndex );
819 m_ListNetNameSelection->EnsureVisible( selectIndex );
820}
821
822
823int DIALOG_COPPER_ZONE::ensureSelectedNetIsVisible( int selectedNetCode, wxArrayString& netsList )
824{
825 int selectedIndex = 0;
826
827 if( selectedNetCode > INVALID_NET_CODE )
828 {
829 NETINFO_ITEM* selectedNet = m_Parent->GetBoard()->FindNet( selectedNetCode );
830
831 if( selectedNet )
832 {
833 const wxString& netName = getUnescapedNetName( selectedNet );
834 selectedIndex = netsList.Index( netName );
835
836 if( wxNOT_FOUND == selectedIndex )
837 {
838 // the currently selected net must *always* be visible.
839 // <no net> is the zero'th index, so pick next lowest
840 netsList.Insert( netName, 1 );
841 selectedIndex = 1;
842 }
843 }
844 }
845
846 return selectedIndex;
847}
848
849
851{
852 return UnescapeString( net->GetNetname() );
853}
854
855
857{
859 && !m_copperZoneInfo->IsShown()
861 {
862 m_copperZoneInfo->ShowMessage( _( "<no net> will result in an isolated copper island." ),
863 wxICON_WARNING );
864 }
865 else if( m_copperZoneInfo->IsShown() )
866 {
867 m_copperZoneInfo->Dismiss();
868 }
869}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
int GetCopperLayerCount() const
Definition board.cpp:875
DIALOG_COPPER_ZONE_BASE(wxWindow *parent, wxWindowID id=ID_DIALOG_COPPER_ZONE_BASE, const wxString &title=_("Copper Zone Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxSpinCtrlDouble * m_spinCtrlSmoothValue
bool TransferDataFromWindow() override
void OnStyleSelection(wxCommandEvent &event) override
std::map< wxString, int > m_netNameToNetCode
NET_FILTER_LIST m_showNetsFilter
void OnNetSortingOptionSelected(wxCommandEvent &event) override
DIALOG_COPPER_ZONE(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
wxArrayString buildListOfNetsToDisplay()
void sortNetsByPadCount(std::vector< NETINFO_ITEM * > &nets, const int maxNetCode)
int ensureSelectedNetIsVisible(int selectedNetCode, wxArrayString &netsList)
wxRadioButton * m_rbCenterline
bool TransferDataToWindow() override
wxString getUnescapedNetName(const NETINFO_ITEM *net)
void OnLayerSelection(wxDataViewEvent &event) override
CONVERT_SETTINGS * m_convertSettings
void OnShowNetNameFilterChange(wxCommandEvent &event) override
void OnRemoveIslandsSelection(wxCommandEvent &event) override
static constexpr int HIDE_ANONYMOUS_NETS
std::vector< NET_FILTER > NET_FILTER_LIST
static constexpr int INVALID_NET_CODE
void OnPadInZoneSelection(wxCommandEvent &event) override
std::unique_ptr< EDA_PATTERN_MATCH > NET_FILTER
PCB_BASE_FRAME * m_Parent
static constexpr int SORT_BY_PAD_COUNT
static constexpr int DEFAULT_SORT_CONFIG
std::vector< NETINFO_ITEM * > m_netInfoItemList
void OnUpdateUI(wxUpdateUIEvent &) override
void displayNetsList(const wxArrayString &netNamesList, int selectIndex)
void OnNetSelectionUpdated(wxCommandEvent &event) override
static constexpr int NO_PERSISTENT_SORT_MODE
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:82
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...
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:582
Handle the data for a net.
Definition netinfo.h:54
const wxString & GetNetname() const
Definition netinfo.h:112
int GetNetCode() const
Definition netinfo.h:106
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:330
unsigned GetNetCount() const
Definition netinfo.h:353
Definition pad.h:54
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
ZONE_SETTINGS handles zones parameters.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:169
This file is part of the common library.
static bool sortNetsByNodes(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings, CONVERT_SETTINGS *aConvertSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
static bool sortNetsByNames(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
static std::vector< int > padCountListByNet
#define _(s)
Abstract pattern-matching tool and implementations.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
@ CENTERLINE
@ BOUNDING_HULL
wxString UnescapeString(const wxString &aSource)
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .
Definition trigo.h:196
ISLAND_REMOVAL_MODE
Whether or not to remove isolated islands from a zone.
#define ZONE_CLEARANCE_MAX_VALUE_MM
Definition zones.h:38
@ THERMAL
Use thermal relief for pads.
Definition zones.h:50
@ THT_THERMAL
Thermal relief only for THT pads.
Definition zones.h:52
@ NONE
Pads are not covered.
Definition zones.h:49
@ FULL
pads are covered by copper
Definition zones.h:51
#define ZONE_BORDER_HATCH_MINDIST_MM
Definition zones.h:40
#define ZONE_THICKNESS_MIN_VALUE_MM
Definition zones.h:36
#define ZONE_BORDER_HATCH_MAXDIST_MM
Definition zones.h:41