KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_layers.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 Isaac Marino Bavaresco, [email protected]
5 * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2009-2024 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
27#include <confirm.h>
28#include <core/arraydim.h>
29#include <core/kicad_algo.h>
30#include <pcb_edit_frame.h>
31#include <tool/tool_manager.h>
32#include <tools/pcb_actions.h>
33#include <board.h>
34#include <collectors.h>
35#include <footprint.h>
36#include <pad.h>
37#include <pcb_track.h>
38#include <panel_setup_layers.h>
40
41#include <wx/choicdlg.h>
42#include <wx/msgdlg.h>
43#include <eda_list_dialog.h>
44
45
46// some define to choose how copper layers widgets are shown
47
48// if defined, display only active copper layers
49// if not displays always 1=the full set (32 copper layers)
50#define HIDE_INACTIVE_LAYERS
51
52
54{
55 // Layers that are put out into the dialog UI, coordinate with wxformbuilder and
56 // getCTLs( int aLayerNumber )
57 static const PCB_LAYER_ID layers[] = {
58 F_CrtYd,
59 F_Fab,
60 F_Adhes,
61 F_Paste,
62 F_SilkS,
63 F_Mask,
64 F_Cu,
65
66 In1_Cu,
67 In2_Cu,
68 In3_Cu,
69 In4_Cu,
70 In5_Cu,
71 In6_Cu,
72 In7_Cu,
73 In8_Cu,
74 In9_Cu,
75 In10_Cu,
76 In11_Cu,
77 In12_Cu,
78 In13_Cu,
79 In14_Cu,
80 In15_Cu,
81
82 In16_Cu,
83 In17_Cu,
84 In18_Cu,
85 In19_Cu,
86 In20_Cu,
87 In21_Cu,
88 In22_Cu,
89 In23_Cu,
90 In24_Cu,
91 In25_Cu,
92 In26_Cu,
93 In27_Cu,
94 In28_Cu,
95 In29_Cu,
96 In30_Cu,
97
98 B_Cu,
99 B_Mask,
100 B_SilkS,
101 B_Paste,
102 B_Adhes,
103 B_Fab,
104 B_CrtYd,
105
106 Edge_Cuts,
107 Margin,
108 Eco2_User,
109 Eco1_User,
110 Cmts_User,
111 Dwgs_User,
112
113 User_1,
114 User_2,
115 User_3,
116 User_4,
117 User_5,
118 User_6,
119 User_7,
120 User_8,
121 User_9,
122 };
123
124 return LSEQ( layers, layers + arrayDim( layers ) );
125}
126
127
128PANEL_SETUP_LAYERS::PANEL_SETUP_LAYERS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) :
129 PANEL_SETUP_LAYERS_BASE( aParentWindow ),
130 m_frame( aFrame ),
131 m_physicalStackup( nullptr ),
132 m_initialized( false )
133{
134 m_pcb = aFrame->GetBoard();
135}
136
137
139{
140#define RETURN_COPPER( x ) return PANEL_SETUP_LAYERS_CTLs( x##Name, x##CheckBox, x##Choice )
141#define RETURN_AUX( x ) return PANEL_SETUP_LAYERS_CTLs( x##Name, x##CheckBox, x##StaticText )
142#define RETURN_MANDATORY( x ) return PANEL_SETUP_LAYERS_CTLs( x##Name, nullptr, x##StaticText )
143#define RETURN_USER( x ) return PANEL_SETUP_LAYERS_CTLs( x##Name, x##CheckBox, x##Type )
144
145 switch( aLayerNumber )
146 {
147 case F_CrtYd: RETURN_MANDATORY( m_CrtYdFront );
148 case F_Fab: RETURN_AUX( m_FabFront );
149 case F_Adhes: RETURN_AUX( m_AdhesFront );
150 case F_Paste: RETURN_AUX( m_SoldPFront );
151 case F_SilkS: RETURN_AUX( m_SilkSFront );
152 case F_Mask: RETURN_AUX( m_MaskFront );
153 case F_Cu: RETURN_COPPER( m_Front );
154
155 case In1_Cu: RETURN_COPPER( m_In1 );
156 case In2_Cu: RETURN_COPPER( m_In2 );
157 case In3_Cu: RETURN_COPPER( m_In3 );
158 case In4_Cu: RETURN_COPPER( m_In4 );
159 case In5_Cu: RETURN_COPPER( m_In5 );
160 case In6_Cu: RETURN_COPPER( m_In6 );
161 case In7_Cu: RETURN_COPPER( m_In7 );
162 case In8_Cu: RETURN_COPPER( m_In8 );
163 case In9_Cu: RETURN_COPPER( m_In9 );
164 case In10_Cu: RETURN_COPPER( m_In10 );
165 case In11_Cu: RETURN_COPPER( m_In11 );
166 case In12_Cu: RETURN_COPPER( m_In12 );
167 case In13_Cu: RETURN_COPPER( m_In13 );
168 case In14_Cu: RETURN_COPPER( m_In14 );
169 case In15_Cu: RETURN_COPPER( m_In15 );
170
171 case In16_Cu: RETURN_COPPER( m_In16 );
172 case In17_Cu: RETURN_COPPER( m_In17 );
173 case In18_Cu: RETURN_COPPER( m_In18 );
174 case In19_Cu: RETURN_COPPER( m_In19 );
175 case In20_Cu: RETURN_COPPER( m_In20 );
176 case In21_Cu: RETURN_COPPER( m_In21 );
177 case In22_Cu: RETURN_COPPER( m_In22 );
178 case In23_Cu: RETURN_COPPER( m_In23 );
179 case In24_Cu: RETURN_COPPER( m_In24 );
180 case In25_Cu: RETURN_COPPER( m_In25 );
181 case In26_Cu: RETURN_COPPER( m_In26 );
182 case In27_Cu: RETURN_COPPER( m_In27 );
183 case In28_Cu: RETURN_COPPER( m_In28 );
184 case In29_Cu: RETURN_COPPER( m_In29 );
185 case In30_Cu: RETURN_COPPER( m_In30 );
186
187 case B_Cu: RETURN_COPPER( m_Back );
188 case B_Mask: RETURN_AUX( m_MaskBack );
189 case B_SilkS: RETURN_AUX( m_SilkSBack );
190 case B_Paste: RETURN_AUX( m_SoldPBack );
191 case B_Adhes: RETURN_AUX( m_AdhesBack );
192 case B_Fab: RETURN_AUX( m_FabBack );
193 case B_CrtYd: RETURN_MANDATORY( m_CrtYdBack );
194
195 case Edge_Cuts: RETURN_MANDATORY( m_PCBEdges );
196 case Margin: RETURN_AUX( m_Margin );
197 case Eco2_User: RETURN_AUX( m_Eco2 );
198 case Eco1_User: RETURN_AUX( m_Eco1 );
199 case Cmts_User: RETURN_AUX( m_Comments );
200 case Dwgs_User: RETURN_AUX( m_Drawings );
201
202 case User_1: RETURN_USER( m_User1 );
203 case User_2: RETURN_USER( m_User2 );
204 case User_3: RETURN_USER( m_User3 );
205 case User_4: RETURN_USER( m_User4 );
206 case User_5: RETURN_USER( m_User5 );
207 case User_6: RETURN_USER( m_User6 );
208 case User_7: RETURN_USER( m_User7 );
209 case User_8: RETURN_USER( m_User8 );
210 case User_9: RETURN_USER( m_User9 );
211
212 default:
213 wxASSERT_MSG( 0, wxT( "bad layer id" ) );
214 return PANEL_SETUP_LAYERS_CTLs( nullptr, nullptr, nullptr );
215 }
216}
217
218
219wxControl* PANEL_SETUP_LAYERS::getName( int aLayer )
220{
221 return getCTLs( aLayer ).name;
222}
223
224
225wxCheckBox* PANEL_SETUP_LAYERS::getCheckBox( int aLayer )
226{
227 return getCTLs( aLayer ).checkbox;
228}
229
230
231wxChoice* PANEL_SETUP_LAYERS::getChoice( int aLayer )
232{
233 return (wxChoice*) getCTLs( aLayer ).choice;
234}
235
236
238{
240
241 // Rescue may be enabled, but should not be shown in this dialog
243
245
248
252
253 m_initialized = true;
254
255 return true;
256}
257
258
259void PANEL_SETUP_LAYERS::SyncCopperLayers( int aNumCopperLayers )
260{
261 setCopperLayerCheckBoxes( aNumCopperLayers );
262}
263
264
266{
267 for( int layer : { F_CrtYd, B_CrtYd, Edge_Cuts, Margin } )
268 setLayerCheckBox( layer, true );
269}
270
271
273{
274 for( PCB_LAYER_ID layer : LSET::UserDefinedLayers().Seq() )
275 {
276 bool state = m_pcb->IsLayerEnabled( layer );
277
278#ifdef HIDE_INACTIVE_LAYERS
279 // This code hides inactive copper layers, or redisplays hidden layers which are now needed.
280 PANEL_SETUP_LAYERS_CTLs ctl = getCTLs( layer );
281
282 // All user-defined layers should have a checkbox
283 wxASSERT( ctl.checkbox );
284
285 ctl.name->Show( state );
286 ctl.checkbox->Show( state );
287 ctl.choice->Show( state );
288#endif
289
290 setLayerCheckBox( layer, state );
291 }
292
293#ifdef HIDE_INACTIVE_LAYERS
294 // Send an size event to force sizers to be updated,
295 // because the number of copper layers can have changed.
296 wxSizeEvent evt_size( m_LayersListPanel->GetSize() );
297 m_LayersListPanel->GetEventHandler()->ProcessEvent( evt_size );
298#endif
299}
300
301
303{
304 // Set all the board's layer names into the dialog by calling BOARD::GetLayerName(),
305 // which will call BOARD::GetStandardLayerName() for non-coppers.
306
307 for( PCB_LAYER_ID layer : dlg_layers() )
308 {
309 wxControl* ctl = getName( layer );
310
311 if( ctl )
312 {
313 wxString lname = m_pcb->GetLayerName( layer );
314
315 if( auto textCtl = dynamic_cast<wxTextCtrl*>( ctl ) )
316 textCtl->ChangeValue( lname ); // wxTextCtrl
317 else
318 ctl->SetLabel( lname ); // wxStaticText
319 }
320 }
321}
322
323
325{
326 // The check boxes
327 for( PCB_LAYER_ID layer : dlg_layers() )
328 setLayerCheckBox( layer, enabledLayers[layer] );
329}
330
331
333{
334 for( PCB_LAYER_ID cu_layer : LSET::AllCuMask().Seq() )
335 {
336 wxChoice* ctl = getChoice( cu_layer );
337 ctl->SetStringSelection( LAYER::ShowType( m_pcb->GetLayerType( cu_layer ) ) );
338 }
339
340 for( int ii = User_1; ii <= User_9; ++ii )
341 {
342 switch( m_pcb->GetLayerType( ToLAYER_ID( ii ) ) )
343 {
344 case LT_AUX: getChoice( ii )->SetSelection( 0 ); break;
345 case LT_FRONT: getChoice( ii )->SetSelection( 1 ); break;
346 case LT_BACK: getChoice( ii )->SetSelection( 2 ); break;
347 default: getChoice( ii )->SetSelection( 0 ); break;
348 }
349 }
350}
351
352
354{
355 LSET layerMaskResult;
356
357 for( PCB_LAYER_ID layer : dlg_layers() )
358 {
359 wxCheckBox* ctl = getCheckBox( layer );
360
361 if( !ctl || ctl->GetValue() )
362 layerMaskResult.set( layer );
363 }
364
365 return layerMaskResult;
366}
367
368
369void PANEL_SETUP_LAYERS::setLayerCheckBox( int aLayer, bool isChecked )
370{
371 PANEL_SETUP_LAYERS_CTLs ctl = getCTLs( aLayer );
372
373 if( !ctl.checkbox )
374 return;
375
376 ctl.checkbox->SetValue( isChecked );
377}
378
379
381{
382 if( copperCount > 0 )
383 {
384 setLayerCheckBox( F_Cu, true );
385 --copperCount;
386 }
387
388 if( copperCount > 0 )
389 {
390 setLayerCheckBox( B_Cu, true );
391 --copperCount;
392 }
393
394 for( PCB_LAYER_ID layer : LSET::InternalCuMask().Seq() )
395 {
396 bool state = copperCount > 0;
397
398#ifdef HIDE_INACTIVE_LAYERS
399 // This code hides inactive copper layers, or redisplays hidden layers which are now needed.
400 PANEL_SETUP_LAYERS_CTLs ctl = getCTLs( layer );
401
402 // Inner layers should have a checkbox
403 wxASSERT( ctl.checkbox );
404
405 ctl.name->Show( state );
406 ctl.checkbox->Show( state );
407 ctl.choice->Show( state );
408#endif
409
410 setLayerCheckBox( layer, state );
411 --copperCount;
412 }
413
414#ifdef HIDE_INACTIVE_LAYERS
415 // Send an size event to force sizers to be updated,
416 // because the number of copper layers can have changed.
417 wxSizeEvent evt_size( m_LayersListPanel->GetSize() );
418 m_LayersListPanel->GetEventHandler()->ProcessEvent( evt_size );
419#endif
420}
421
422
423void PANEL_SETUP_LAYERS::OnCheckBox( wxCommandEvent& event )
424{
426}
427
428
429void PANEL_SETUP_LAYERS::DenyChangeCheckBox( wxCommandEvent& event )
430{
431 wxObject* source = event.GetEventObject();
432
433 for( PCB_LAYER_ID layer : LSET::AllCuMask().Seq() )
434 {
435 wxCheckBox* copper = getCheckBox( layer );
436
437 if( source == copper )
438 {
439 DisplayError( wxGetTopLevelParent( this ),
440 _( "Use the Physical Stackup page to change the number of "
441 "copper layers." ) );
442
443 copper->SetValue( true );
444 return;
445 }
446 }
447}
448
449
451{
452 if( !testLayerNames() )
453 return false;
454
455 // Make sure we have the latest copper layer count
458
459 wxString msg;
460 bool modified = false;
461
462 // Check for removed layers with items which will get deleted from the board.
463 LSEQ removedLayers = getRemovedLayersWithItems();
464
465 // Check for non-copper layers in use in footprints, and therefore not removable.
466 LSEQ notremovableLayers = getNonRemovableLayers();
467
468 if( !notremovableLayers.empty() )
469 {
470 for( unsigned int ii = 0; ii < notremovableLayers.size(); ii++ )
471 msg << m_pcb->GetLayerName( notremovableLayers[ii] ) << wxT( "\n" );
472
473 if( !IsOK( wxGetTopLevelParent( this ),
474 wxString::Format( _( "Footprints have some items on removed layers:\n"
475 "%s\n"
476 "These items will be no longer accessible\n"
477 "Do you wish to continue?" ), msg ) ) )
478 {
479 return false;
480 }
481 }
482
483 if( !removedLayers.empty()
484 && !IsOK( wxGetTopLevelParent( this ),
485 _( "Items have been found on removed layers. This operation will "
486 "delete all items from removed layers and cannot be undone.\n"
487 "Do you wish to continue?" ) ) )
488 {
489 return false;
490 }
491
492 // Delete all objects on layers that have been removed. Leaving them in copper layers
493 // can (will?) result in DRC errors and it pollutes the board file with cruft.
494 bool hasRemovedBoardItems = false;
495
496 if( !removedLayers.empty() )
497 {
499
500 PCB_LAYER_COLLECTOR collector;
501
502 for( PCB_LAYER_ID layer_id : removedLayers )
503 {
504 collector.SetLayerId( layer_id );
506
507 // Bye-bye items on removed layer.
508 for( int i = 0; i < collector.GetCount(); i++ )
509 {
510 BOARD_ITEM* item = collector[i];
511
512 // Do not remove/change an item owned by a footprint
513 if( item->GetParentFootprint() )
514 continue;
515
516 // Do not remove footprints
517 if( item->Type() == PCB_FOOTPRINT_T )
518 continue;
519
520 LSET layers = item->GetLayerSet();
521
522 layers.reset( layer_id );
523 hasRemovedBoardItems = true;
524 modified = true;
525
526 if( layers.any() )
527 {
528 item->SetLayerSet( layers );
529 }
530 else
531 {
532 m_pcb->Remove( item );
533 delete item;
534 }
535 }
536 }
537
538 // Undo state may have copies of pointers deleted above
540 }
541
543
544 LSET previousEnabled = m_pcb->GetEnabledLayers();
545
546 if( m_enabledLayers != previousEnabled )
547 {
549
550 LSET changedLayers = m_enabledLayers ^ previousEnabled;
551
552 /*
553 * Ensure enabled layers are also visible. This is mainly to avoid mistakes if some
554 * enabled layers are not visible when exiting this dialog.
555 */
556 m_pcb->SetVisibleLayers( m_pcb->GetVisibleLayers() | changedLayers );
557
558 /*
559 * Ensure items with through holes have all inner copper layers. (For historical reasons
560 * this is NOT trimmed to the currently-enabled inner layers.)
561 */
562 for( FOOTPRINT* fp : m_pcb->Footprints() )
563 {
564 for( PAD* pad : fp->Pads() )
565 {
566 if( pad->HasHole() && pad->IsOnCopperLayer() )
567 pad->SetLayerSet( pad->GetLayerSet() | LSET::InternalCuMask() );
568 }
569 }
570
571 // Tracks do not change their layer
572 // Vias layers are defined by the starting layer and the ending layer, so
573 // they are not modified by adding a layer.
574 // So do nothing for tracks/vias
575
576 modified = true;
577 }
578
579 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
580 {
581 if( m_enabledLayers[layer] )
582 {
583 const wxString& newLayerName = GetLayerName( layer );
584
585 if( m_pcb->GetLayerName( layer ) != newLayerName )
586 {
587 m_pcb->SetLayerName( layer, newLayerName );
588 modified = true;
589 }
590
591 if( IsCopperLayer( layer ) )
592 {
593 LAYER_T t;
594
595 switch( getChoice( layer )->GetCurrentSelection() )
596 {
597 case 0: t = LT_SIGNAL; break;
598 case 1: t = LT_POWER; break;
599 case 2: t = LT_MIXED; break;
600 case 3: t = LT_JUMPER; break;
601 default: t = LT_UNDEFINED; break;
602 }
603
604 if( m_pcb->GetLayerType( layer ) != t )
605 {
606 m_pcb->SetLayerType( layer, t );
607 modified = true;
608 }
609 }
610 else if( layer >= User_1 && layer <= User_9 )
611 {
612 LAYER_T t;
613
614 switch( getChoice( layer )->GetCurrentSelection() )
615 {
616 case 0: t = LT_AUX; break;
617 case 1: t = LT_FRONT; break;
618 case 2: t = LT_BACK; break;
619 default: t = LT_UNDEFINED; break;
620 }
621
622 if( m_pcb->GetLayerType( layer ) != t )
623 {
624 m_pcb->SetLayerType( layer, t );
625 modified = true;
626 }
627 }
628 }
629 }
630
631 for( PCB_LAYER_ID layer : LSET::UserDefinedLayers().Seq() )
632 {
633 const wxString& newLayerName = GetLayerName( layer );
634
635 if( m_enabledLayers[ layer ] && m_pcb->GetLayerName( layer ) != newLayerName )
636 {
637 m_pcb->SetLayerName( layer, newLayerName );
638 modified = true;
639 }
640 }
641
642 // If some board items are deleted: Rebuild the connectivity, because it is likely some
643 // tracks and vias were removed
644 if( hasRemovedBoardItems )
646
647 if( modified )
648 m_frame->OnModify();
649
650 return true;
651}
652
653
655{
656 wxControl* control = getName( aLayer );
657
658 if( auto textCtl = dynamic_cast<wxTextCtrl*>( control ) )
659 return textCtl->GetValue().Trim();
660 else
661 return control->GetLabel();
662}
663
664
665static bool hasOneOf( const wxString& str, const wxString& chars )
666{
667 for( unsigned i=0; i<chars.Len(); ++i )
668 {
669 if( str.Find( chars[i] ) != wxNOT_FOUND )
670 return true;
671 }
672
673 return false;
674}
675
676
678{
679 std::vector<wxString> names;
680 wxTextCtrl* ctl;
681
682 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
683 {
684 // we _can_ rely on m_enabledLayers being current here:
685
686 if( !m_enabledLayers[layer] )
687 continue;
688
689 wxString name = GetLayerName( layer );
690
691 ctl = (wxTextCtrl*) getName( layer );
692
693 // Check name for legality:
694 // 1) Cannot be blank.
695 // 2) Cannot have blanks.
696 // 3) Cannot have " chars
697 // 4) Cannot be 'signal'
698 // 5) Must be unique.
699 // 6) Cannot have illegal chars in filenames ( some filenames are built from layer names )
700 // like : % $ \ " / :
701 wxString badchars = wxFileName::GetForbiddenChars( wxPATH_DOS );
702 badchars.Append( '%' );
703
704 if( !name )
705 {
706 PAGED_DIALOG::GetDialog( this )->SetError( _( "Layer must have a name." ), this, ctl );
707 return false;
708 }
709
710 if( hasOneOf( name, badchars ) )
711 {
712 wxString msg = wxString::Format(_( "%s are forbidden in layer names." ), badchars );
713 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, ctl );
714 return false;
715 }
716
717 if( name == wxT( "signal" ) )
718 {
719 PAGED_DIALOG::GetDialog( this )->SetError( _( "Layer name \"signal\" is reserved." ),
720 this, ctl );
721 return false;
722 }
723
724 for( const wxString& existingName : names )
725 {
726 if( name == existingName )
727 {
728 wxString msg = wxString::Format(_( "Layer name '%s' already in use." ), name );
729 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, ctl );
730 return false;
731 }
732 }
733
734 names.push_back( name );
735 }
736
737 return true;
738}
739
740
742{
743 LSEQ removedLayers;
744 LSET newLayers = GetUILayerMask();
745 LSET curLayers = m_pcb->GetEnabledLayers();
746
747 if( newLayers == curLayers ) // Return an empty list if no change
748 return removedLayers;
749
750 PCB_LAYER_COLLECTOR collector;
751 LSEQ newLayerSeq = newLayers.Seq();
752
753 for( PCB_LAYER_ID layer_id : curLayers.Seq() )
754 {
755 if( !alg::contains( newLayerSeq, layer_id ) )
756 {
757 collector.SetLayerId( layer_id );
759
760 if( collector.GetCount() != 0 )
761 {
762 // Skip items owned by footprints and footprints when building
763 // the actual list of removed layers: these items are not removed
764 for( int i = 0; i < collector.GetCount(); i++ )
765 {
766 BOARD_ITEM* item = collector[i];
767
768 if( dynamic_cast<FOOTPRINT*>( item )
769 || dynamic_cast<FOOTPRINT*>( item->GetParentFootprint() ) )
770 continue;
771
772 removedLayers.push_back( layer_id );
773 break;
774 }
775 }
776 }
777 }
778
779 return removedLayers;
780}
781
782
784{
785 // Build the list of non-copper layers in use in footprints.
786 LSEQ inUseLayers;
787 LSET newLayers = GetUILayerMask();
788 LSET curLayers = m_pcb->GetEnabledLayers();
789
790 if( newLayers == curLayers ) // Return an empty list if no change
791 return inUseLayers;
792
793 PCB_LAYER_COLLECTOR collector;
794 LSEQ newLayerSeq = newLayers.Seq();
795
796 for( PCB_LAYER_ID layer_id : curLayers.Seq() )
797 {
798 if( IsCopperLayer( layer_id ) ) // Copper layers are not taken into account here
799 continue;
800
801 if( !alg::contains( newLayerSeq, layer_id ) )
802 {
803 collector.SetLayerId( layer_id );
805
806 if( collector.GetCount() != 0 )
807 inUseLayers.push_back( layer_id );
808 }
809 }
810
811 return inUseLayers;
812}
813
814
816{
817 BOARD* savedBoard = m_pcb;
818
819 m_pcb = aBoard;
821
822 m_pcb = savedBoard;
823}
824
825
826bool PANEL_SETUP_LAYERS::CheckCopperLayerCount( BOARD* aWorkingBoard, BOARD* aImportedBoard )
827{
828 /*
829 * This function warns users if they are going to delete inner copper layers because
830 * they're importing settings from a board with less copper layers than the board
831 * already loaded. We want to return "true" as default on the assumption no layer will
832 * actually be deleted.
833 */
834 bool okToDeleteCopperLayers = true;
835
836 // Get the number of copper layers in the loaded board and the "import settings" board
837 int currNumLayers = aWorkingBoard->GetCopperLayerCount();
838 int newNumLayers = aImportedBoard->GetCopperLayerCount();
839
840 if( newNumLayers < currNumLayers )
841 {
842 wxString msg = wxString::Format( _( "Imported settings have fewer copper layers than "
843 "the current board (%i instead of %i).\n\n"
844 "Continue and delete the extra inner copper layers "
845 "from the current board?" ),
846 newNumLayers,
847 currNumLayers );
848
849 wxWindow* topLevelParent = wxGetTopLevelParent( this );
850
851 wxMessageDialog dlg( topLevelParent, msg, _( "Inner Layers To Be Deleted" ),
852 wxICON_WARNING | wxSTAY_ON_TOP | wxYES | wxNO | wxNO_DEFAULT );
853
854 if( wxID_NO == dlg.ShowModal() )
855 okToDeleteCopperLayers = false;
856 }
857
858 return okToDeleteCopperLayers;
859}
860
861
862void PANEL_SETUP_LAYERS::addUserDefinedLayer( wxCommandEvent& aEvent )
863{
864 wxArrayString headers;
865 headers.Add( _( "Layers" ) );
866
867 // Build the available user-defined layers list:
868 std::vector<wxArrayString> list;
869
870 for( PCB_LAYER_ID layer : LSET::UserDefinedLayers().Seq() )
871 {
872 wxCheckBox* checkBox = getCheckBox( layer );
873
874 if( checkBox && checkBox->IsShown() )
875 continue;
876
877 wxArrayString available_user_layer;
878 available_user_layer.Add( LayerName( layer ) );
879
880 list.emplace_back( available_user_layer );
881 }
882
883 if( list.empty() )
884 {
886 _( "All user-defined layers have already been added." ) );
887 return;
888 }
889
890 EDA_LIST_DIALOG dlg( PAGED_DIALOG::GetDialog( this ), _( "Add User-defined Layer" ),
891 headers, list );
892 dlg.SetListLabel( _( "Select layer to add:" ) );
893 dlg.HideFilter();
894
895 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetTextSelection().IsEmpty() )
896 return;
897
899
900 for( PCB_LAYER_ID layer2 : LSET::UserDefinedLayers().Seq() )
901 {
902 if( LayerName( layer2 ) == dlg.GetTextSelection() )
903 {
904 layer = layer2;
905 break;
906 }
907 }
908
909 wxCHECK( layer >= User_1 && layer <= User_9, /* void */ );
910
911 LSET newLayer( layer );
912
913 m_enabledLayers |= newLayer;
914
915 PANEL_SETUP_LAYERS_CTLs ctl = getCTLs( layer );
916
917 // All user-defined layers should have a checkbox
918 wxASSERT( ctl.checkbox );
919 ctl.checkbox->SetValue( true );
920
921 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( ctl.name );
922
923 wxCHECK( textCtrl, /* void */ );
924 textCtrl->ChangeValue( LSET::Name( layer ) );
925
926 wxChoice* userLayerType = dynamic_cast<wxChoice*>( ctl.choice );
927
928 wxCHECK( userLayerType, /* void */ );
929 userLayerType->SetSelection( 0 );
930
931 ctl.name->Show( true );
932 ctl.checkbox->Show( true );
933 ctl.choice->Show( true );
934
935 wxSizeEvent evt_size( m_LayersListPanel->GetSize() );
936 m_LayersListPanel->GetEventHandler()->ProcessEvent( evt_size );
937}
938
939
const char * name
Definition: DXF_plotter.cpp:57
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
LAYER_T
The allowed types of layers, same as Specctra DSN spec.
Definition: board.h:152
@ LT_POWER
Definition: board.h:155
@ LT_FRONT
Definition: board.h:159
@ LT_MIXED
Definition: board.h:156
@ LT_BACK
Definition: board.h:160
@ LT_UNDEFINED
Definition: board.h:153
@ LT_JUMPER
Definition: board.h:157
@ LT_AUX
Definition: board.h:158
@ LT_SIGNAL
Definition: board.h:154
BASE_SET & set(size_t pos=std::numeric_limits< size_t >::max(), bool value=true)
Definition: base_set.h:61
bool any() const
Definition: base_set.h:55
BASE_SET & reset(size_t pos=std::numeric_limits< size_t >::max())
Definition: base_set.h:76
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:264
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:245
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:253
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:757
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:771
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:777
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:186
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:783
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition: board.cpp:610
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition: board.cpp:591
int GetCopperLayerCount() const
Definition: board.cpp:733
const FOOTPRINTS & Footprints() const
Definition: board.h:330
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:789
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
Definition: board.cpp:624
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:575
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition: board.cpp:1120
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
A dialog which shows:
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
static const std::vector< KICAD_T > BoardLevelItems
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition: collectors.h:238
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition: collectors.h:253
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
static LSET AllLayersMask()
Definition: lset.cpp:767
static LSET UserDefinedLayers()
Return a mask with all of the allowable user defined layers.
Definition: lset.cpp:829
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:392
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:721
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:732
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:63
Definition: pad.h:54
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
Class PANEL_SETUP_LAYERS_BASE.
wxScrolledWindow * m_LayersListPanel
wxString GetLayerName(int layer)
PANEL_SETUP_LAYERS_CTLs getCTLs(int aLayerNumber)
void showSelectedLayerCheckBoxes(LSET enableLayerMask)
bool CheckCopperLayerCount(BOARD *aWorkingBoard, BOARD *aImportedBoard)
Check and warn if inner copper layers will be deleted.
void DenyChangeCheckBox(wxCommandEvent &event) override
bool TransferDataToWindow() override
virtual void addUserDefinedLayer(wxCommandEvent &aEvent) override
void SyncCopperLayers(int aNumCopperLayers)
Called when switching to this tab to make sure that any changes to the copper layer count made on the...
void setLayerCheckBox(int layer, bool isChecked)
PANEL_SETUP_BOARD_STACKUP * m_physicalStackup
PCB_EDIT_FRAME * m_frame
LSEQ getNonRemovableLayers()
Return a list of layers in use in footprints, and therefore not removable.
void setCopperLayerCheckBoxes(int copperCount)
wxControl * getName(int aLayer)
wxChoice * getChoice(int aLayer)
LSEQ getRemovedLayersWithItems()
Return a list of layers removed from the board that contain items.
bool TransferDataFromWindow() override
void OnCheckBox(wxCommandEvent &event) override
PANEL_SETUP_LAYERS(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame)
void ImportSettingsFrom(BOARD *aBoard)
wxCheckBox * getCheckBox(int aLayer)
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
BOARD * GetBoard() const
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
Collect all BOARD_ITEM objects on a given layer.
Definition: collectors.h:552
void Collect(BOARD_ITEM *aBoard, const std::vector< KICAD_T > &aTypes)
Test a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:536
void SetLayerId(PCB_LAYER_ID aLayerId)
Definition: collectors.h:558
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:250
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:531
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ In22_Cu
Definition: layer_ids.h:86
@ In11_Cu
Definition: layer_ids.h:75
@ In29_Cu
Definition: layer_ids.h:93
@ In30_Cu
Definition: layer_ids.h:94
@ User_8
Definition: layer_ids.h:130
@ F_CrtYd
Definition: layer_ids.h:117
@ In17_Cu
Definition: layer_ids.h:81
@ B_Adhes
Definition: layer_ids.h:97
@ Edge_Cuts
Definition: layer_ids.h:113
@ Dwgs_User
Definition: layer_ids.h:109
@ F_Paste
Definition: layer_ids.h:101
@ In9_Cu
Definition: layer_ids.h:73
@ Cmts_User
Definition: layer_ids.h:110
@ User_6
Definition: layer_ids.h:128
@ User_7
Definition: layer_ids.h:129
@ In19_Cu
Definition: layer_ids.h:83
@ In7_Cu
Definition: layer_ids.h:71
@ In28_Cu
Definition: layer_ids.h:92
@ In26_Cu
Definition: layer_ids.h:90
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ User_5
Definition: layer_ids.h:127
@ Eco1_User
Definition: layer_ids.h:111
@ F_Mask
Definition: layer_ids.h:107
@ In21_Cu
Definition: layer_ids.h:85
@ In23_Cu
Definition: layer_ids.h:87
@ B_Paste
Definition: layer_ids.h:100
@ In15_Cu
Definition: layer_ids.h:79
@ In2_Cu
Definition: layer_ids.h:66
@ User_9
Definition: layer_ids.h:131
@ F_Fab
Definition: layer_ids.h:120
@ In10_Cu
Definition: layer_ids.h:74
@ Margin
Definition: layer_ids.h:114
@ F_SilkS
Definition: layer_ids.h:104
@ In4_Cu
Definition: layer_ids.h:68
@ B_CrtYd
Definition: layer_ids.h:116
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ Eco2_User
Definition: layer_ids.h:112
@ In16_Cu
Definition: layer_ids.h:80
@ In24_Cu
Definition: layer_ids.h:88
@ In1_Cu
Definition: layer_ids.h:65
@ Rescue
Definition: layer_ids.h:133
@ User_3
Definition: layer_ids.h:125
@ User_1
Definition: layer_ids.h:123
@ B_SilkS
Definition: layer_ids.h:103
@ In13_Cu
Definition: layer_ids.h:77
@ User_4
Definition: layer_ids.h:126
@ In8_Cu
Definition: layer_ids.h:72
@ In14_Cu
Definition: layer_ids.h:78
@ User_2
Definition: layer_ids.h:124
@ In12_Cu
Definition: layer_ids.h:76
@ In27_Cu
Definition: layer_ids.h:91
@ In6_Cu
Definition: layer_ids.h:70
@ In5_Cu
Definition: layer_ids.h:69
@ In3_Cu
Definition: layer_ids.h:67
@ In20_Cu
Definition: layer_ids.h:84
@ F_Cu
Definition: layer_ids.h:64
@ In18_Cu
Definition: layer_ids.h:82
@ In25_Cu
Definition: layer_ids.h:89
@ B_Fab
Definition: layer_ids.h:119
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:875
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
#define RETURN_AUX(x)
#define RETURN_MANDATORY(x)
static LSEQ dlg_layers()
#define RETURN_COPPER(x)
#define RETURN_USER(x)
static bool hasOneOf(const wxString &str, const wxString &chars)
std::deque< BOARD_ITEM * > GetCurrentSelection()
Get the list of selected objects.
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
Definition: board.cpp:637
The 3 UI control pointers for a single board layer.
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86