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