KiCad PCB EDA Suite
pcb_layer_widget.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) 2004-2017 Jean-Pierre Charras, jean-pierre.charras@gpisa-lab.inpg.fr
5  * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2010-2017 KiCad Developers, see change_log.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 <fctsys.h>
28 #include <pgm_base.h>
29 #include <pcb_draw_panel_gal.h>
30 #include <view/view.h>
31 #include <painter.h>
32 #include <confirm.h>
33 #include <pcb_edit_frame.h>
34 #include <pcb_display_options.h>
35 #include <tool/tool_manager.h>
36 #include <layer_widget.h>
37 #include <class_text_mod.h>
38 #include <widgets/indicator_icon.h>
39 #include <macros.h>
40 #include <menus_helpers.h>
42 #include <pcb_painter.h>
43 #include <pcb_view.h>
44 #include <class_board.h>
45 #include <pcb_layer_widget.h>
46 #include <pcbnew.h>
47 #include <collectors.h>
48 #include <pcbnew_id.h>
50 
51 
54 
55 #define RR LAYER_WIDGET::ROW // Render Row abbreviation to reduce source width
56 #define NOCOLOR COLOR4D::UNSPECIFIED // specify rows that do not have a color selector icon
57 
58  // text id color tooltip
59  RR( _( "Footprints Front" ), LAYER_MOD_FR, NOCOLOR, _( "Show footprints that are on board's front") ),
60  RR( _( "Footprints Back" ), LAYER_MOD_BK, NOCOLOR, _( "Show footprints that are on board's back") ),
61  RR( _( "Values" ), LAYER_MOD_VALUES, NOCOLOR, _( "Show footprint values") ),
62  RR( _( "References" ), LAYER_MOD_REFERENCES, NOCOLOR, _( "Show footprint references") ),
63  RR( _( "Footprint Text Front" ), LAYER_MOD_TEXT_FR, NOCOLOR, _( "Show footprint text on board's front" ) ),
64  RR( _( "Footprint Text Back" ), LAYER_MOD_TEXT_BK, NOCOLOR, _( "Show footprint text on board's back" ) ),
65  RR( _( "Hidden Text" ), LAYER_MOD_TEXT_INVISIBLE, WHITE, _( "Show footprint text marked as invisible" ) ),
66  RR( _( "Pads Front" ), LAYER_PAD_FR, WHITE, _( "Show footprint pads on board's front" ) ),
67  RR( _( "Pads Back" ), LAYER_PAD_BK, WHITE, _( "Show footprint pads on board's back" ) ),
68  RR( _( "Through Hole Pads" ), LAYER_PADS_TH, YELLOW, _( "Show through hole pads in specific color") ),
69  RR(),
70  RR( _( "Tracks" ), LAYER_TRACKS, NOCOLOR, _( "Show tracks" ) ),
71  RR( _( "Through Via" ), LAYER_VIA_THROUGH, WHITE, _( "Show through vias" ) ),
72  RR( _( "Bl/Buried Via" ), LAYER_VIA_BBLIND, WHITE, _( "Show blind or buried vias" ) ),
73  RR( _( "Micro Via" ), LAYER_VIA_MICROVIA, WHITE, _( "Show micro vias") ),
74  RR( _( "Non Plated Holes" ),LAYER_NON_PLATEDHOLES,WHITE, _( "Show non plated holes in specific color") ),
75  RR(),
76  RR( _( "Ratsnest" ), LAYER_RATSNEST, WHITE, _( "Show unconnected nets as a ratsnest") ),
77  RR( _( "No-Connects" ), LAYER_NO_CONNECTS, BLUE, _( "Show a marker on pads which have no net connected" ) ),
78  RR( _( "Anchors" ), LAYER_ANCHOR, WHITE, _( "Show footprint and text origins as a cross" ) ),
79  RR( _( "Worksheet" ), LAYER_WORKSHEET, DARKRED, _( "Show worksheet") ),
80  RR( _( "Cursor" ), LAYER_CURSOR, WHITE, _( "PCB Cursor" ), true, false ),
81  RR( _( "Aux items" ), LAYER_AUX_ITEMS, WHITE, _( "Auxiliary items (rulers, assistants, axes, etc.)" ), true, false ),
82  RR( _( "Grid" ), LAYER_GRID, WHITE, _( "Show the (x,y) grid dots" ) ),
83  RR( _( "Background" ), LAYER_PCB_BACKGROUND, BLACK, _( "PCB Background" ), true, false )
84 };
85 
86 static int s_allowed_in_FpEditor[] =
87 {
97  LAYER_GRID,
99 };
100 
101 
102 PCB_LAYER_WIDGET::PCB_LAYER_WIDGET( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner,
103  bool aFpEditorMode ) :
104  LAYER_WIDGET( aParent, aFocusOwner ),
105  myframe( aParent )
106 {
108  m_fp_editor_mode = aFpEditorMode;
109 
110  // Update default tabs labels
112 
113  //-----<Popup menu>-------------------------------------------------
114  // handle the popup menu over the layer window.
115  m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN,
116  wxMouseEventHandler( PCB_LAYER_WIDGET::onRightDownLayers ), NULL, this );
117 
118  // since Popupmenu() calls this->ProcessEvent() we must call this->Connect()
119  // and not m_LayerScrolledWindow->Connect()
120 
122  wxEVT_COMMAND_MENU_SELECTED,
123  wxCommandEventHandler( PCB_LAYER_WIDGET::onPopupSelection ), NULL, this );
124 }
125 
126 
128 {
130 }
131 
132 
134 {
135  for( unsigned ii = 0; ii < arrayDim( s_allowed_in_FpEditor ); ii++ )
136  if( s_allowed_in_FpEditor[ii] == aId )
137  return true;
138 
139  return false;
140 }
141 
142 
144 {
145  static LSET allowed = LSET::AllTechMask();
146  allowed.set( F_Cu ).set( B_Cu );
147  return allowed.test( aLayer );
148 }
149 
150 
152 {
153  // menu text is capitalized:
154  // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization
156  _( "Show All Copper Layers" ),
157  KiBitmap( select_layer_pair_xpm ) );
159  _( "Hide All Copper Layers But Active" ),
160  KiBitmap( select_w_layer_xpm ) );
162  _( "Always Hide All Copper Layers But Active" ),
163  KiBitmap( select_w_layer_xpm ) );
165  _( "Hide All Copper Layers" ),
166  KiBitmap( show_no_copper_layers_xpm ) );
167 
168  menu.AppendSeparator();
169 
171  _( "Show All Non Copper Layers" ),
172  KiBitmap( select_w_layer_xpm ) );
174  _( "Hide All Non Copper Layers" ),
175  KiBitmap( show_no_copper_layers_xpm ) );
176 
177  menu.AppendSeparator();
178 
179  AddMenuItem( &menu, ID_SHOW_NO_LAYERS, _( "Hide All Layers" ),
180  KiBitmap( show_no_layers_xpm ) );
181  AddMenuItem( &menu, ID_SHOW_ALL_LAYERS, _( "Show All Layers" ),
182  KiBitmap( show_all_layers_xpm ) );
183 
184  menu.AppendSeparator();
185 
186  AddMenuItem( &menu, ID_SHOW_ALL_FRONT, _( "Show All Front Layers" ),
187  KiBitmap( show_no_layers_xpm ) );
188 
189  AddMenuItem( &menu, ID_SHOW_ALL_BACK, _( "Show All Back Layers" ),
190  KiBitmap( show_all_layers_xpm ) );
191 }
192 
193 
194 void PCB_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
195 {
196  wxMenu menu;
197 
198  AddRightClickMenuItems( menu );
199  PopupMenu( &menu );
200 
201  passOnFocus();
202 }
203 
204 
205 void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
206 {
207  int rowCount;
208  int menuId = event.GetId();
209  bool visible;
210  bool force_active_layer_visible;
211 
213  force_active_layer_visible = ( menuId == ID_SHOW_NO_COPPER_LAYERS_BUT_ACTIVE ||
215 
216  switch( menuId )
217  {
218  case ID_SHOW_NO_LAYERS:
219  case ID_SHOW_ALL_LAYERS:
220  {
221  visible = ( menuId == ID_SHOW_ALL_LAYERS );
222  rowCount = GetLayerRowCount();
223 
224  for( int row=0; row<rowCount; ++row )
225  {
226  bool isLast;
227  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
228  PCB_LAYER_ID layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
229  cb->SetValue( visible );
230 
231  isLast = row == rowCount-1;
232 
233  OnLayerVisible( layer, visible, isLast );
234 
235  if( isLast )
236  break;
237  }
238  break;
239  }
240 
247  {
248 
249  // Search the last copper layer row index:
250  int lastCu = -1;
251  rowCount = GetLayerRowCount();
252  for( int row = rowCount-1; row>=0; --row )
253  {
254  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
255  PCB_LAYER_ID layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
256 
257  if( IsCopperLayer( layer ) )
258  {
259  lastCu = row;
260  break;
261  }
262  }
263 
264  // Enable/disable the copper layers visibility:
265  int startrow = 0;
266 
267  if( ( menuId == ID_SHOW_ALL_NON_COPPER ) ||
268  ( menuId == ID_HIDE_ALL_NON_COPPER ) )
269  {
270  startrow = lastCu + 1;
271  }
272 
273  for( int row = startrow; row<rowCount; ++row )
274  {
275  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
276  PCB_LAYER_ID layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
277 
278  visible = ( ( menuId == ID_SHOW_ALL_COPPER_LAYERS ) || ( menuId == ID_SHOW_ALL_NON_COPPER ) );
279 
280  if( force_active_layer_visible && (layer == myframe->GetActiveLayer() ) )
281  visible = true;
282 
283  cb->SetValue( visible );
284 
285  bool isLastLayer = (row == lastCu);
286 
287  if( ( menuId == ID_SHOW_ALL_NON_COPPER ) ||
288  ( menuId == ID_HIDE_ALL_NON_COPPER ) )
289  {
290  isLastLayer = false;
291  }
292  OnLayerVisible( layer, visible, isLastLayer );
293 
294  if( isLastLayer )
295  break;
296  }
297  break;
298  }
299 
300  case ID_SHOW_ALL_FRONT:
301  {
302  visible = false;
303  rowCount = GetLayerRowCount();
304 
305  for( int row=0; row<rowCount; ++row )
306  {
307  bool isLast;
308  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
309  PCB_LAYER_ID layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
310  isLast = ( row == rowCount-1 );
311 
312  if( layer == F_Paste || layer == F_SilkS ||
313  layer == F_Mask || layer == F_Cu ||
314  layer == F_Fab || layer == F_CrtYd || layer == Edge_Cuts )
315  {
316  visible = true;
317  }
318  else
319  {
320  visible = false;
321  }
322 
323  cb->SetValue( visible );
324  OnLayerVisible( layer, visible, isLast );
325 
326  if( isLast )
327  break;
328  }
329  break;
330  }
331  case ID_SHOW_ALL_BACK:
332  {
333  visible = false;
334  rowCount = GetLayerRowCount();
335 
336  for( int row=0; row<rowCount; ++row )
337  {
338  bool isLast;
339  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
340  PCB_LAYER_ID layer = ToLAYER_ID( getDecodedId( cb->GetId() ) );
341  isLast = ( row == rowCount-1 );
342 
343  if( layer == B_Paste || layer == B_SilkS ||
344  layer == B_Mask || layer == B_Cu ||
345  layer == B_Fab || layer == B_CrtYd || layer == Edge_Cuts )
346  {
347  visible = true;
348  }
349  else
350  {
351  visible = false;
352  }
353 
354  cb->SetValue( visible );
355  OnLayerVisible( layer, visible, isLast );
356 
357  if( isLast )
358  break;
359  }
360  break;
361  }
362  }
363 }
364 
365 
367 {
368  m_notebook->SetPageText( 0, _( "Layers" ) );
369  m_notebook->SetPageText( 1, _( "Items" ) );
370 }
371 
372 
374 {
375  BOARD* board = myframe->GetBoard();
376  auto settings = board->GetDesignSettings();
377 
378  ClearRenderRows();
379 
380  // Add "Items" tab rows to LAYER_WIDGET, after setting color and checkbox state.
381  // Because s_render_rows is created static, we must explicitly call
382  // wxGetTranslation for texts which are internationalized (tool tips
383  // and item names)
384  for( unsigned row=0; row<arrayDim(s_render_rows); ++row )
385  {
386  LAYER_WIDGET::ROW renderRow = s_render_rows[row];
387 
388  if( m_fp_editor_mode && !isAllowedInFpMode( renderRow.id ) )
389  continue;
390 
391  if( renderRow.id == LAYER_VIA_MICROVIA && !settings.m_MicroViasAllowed )
392  continue;
393 
394  if( renderRow.id == LAYER_VIA_BBLIND && !settings.m_BlindBuriedViaAllowed )
395  continue;
396 
397  if( !renderRow.spacer )
398  {
399  renderRow.tooltip = wxGetTranslation( s_render_rows[row].tooltip );
400  renderRow.rowName = wxGetTranslation( s_render_rows[row].rowName );
401 
402  if( renderRow.color != COLOR4D::UNSPECIFIED ) // does this row show a color?
403  {
404  // this window frame must have an established BOARD, i.e. after SetBoard()
405  renderRow.color = myframe->Settings().Colors().GetItemColor(
406  static_cast<GAL_LAYER_ID>( renderRow.id ) );
407  }
408 
409  if( renderRow.id == LAYER_RATSNEST )
410  renderRow.state =
411  static_cast<PCB_DISPLAY_OPTIONS*>( myframe->GetDisplayOptions() )->m_ShowGlobalRatsnest;
412  else
413  renderRow.state = board->IsElementVisible(
414  static_cast<GAL_LAYER_ID>( renderRow.id ) );
415  }
416 
417  AppendRenderRow( renderRow );
418  }
419 
420  UpdateLayouts();
421 }
422 
423 
425 {
426  BOARD* board = myframe->GetBoard();
427  int count = GetLayerRowCount();
428 
429  for( int row=0; row<count; ++row )
430  {
431  // this utilizes more implementation knowledge than ideal, eventually
432  // add member ROW getRow() or similar to base LAYER_WIDGET.
433 
434  wxWindow* w = getLayerComp( row, COLUMN_ICON_ACTIVE );
435 
436  PCB_LAYER_ID layerId = ToLAYER_ID( getDecodedId( w->GetId() ) );
437 
438  // this does not fire a UI event
439  setLayerCheckbox( layerId, board->IsLayerVisible( layerId ) );
440  }
441 }
442 
443 
444 #define ALPHA_EPSILON 0.04
445 
447 {
448  int count = GetLayerRowCount();
450  KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( mgr->GetView()->GetPainter() );
451  KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
452 
453  for( int row = 0; row < count; ++row )
454  {
455  // this utilizes more implementation knowledge than ideal, eventually
456  // add member ROW getRow() or similar to base LAYER_WIDGET.
457 
458  wxWindow* w = getLayerComp( row, COLUMN_ICON_ACTIVE );
459  PCB_LAYER_ID layerId = ToLAYER_ID( getDecodedId( w->GetId() ) );
460  KIGFX::COLOR4D screenColor = settings->GetLayerColor( layerId );
461 
462  COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( getLayerComp( row, COLUMN_COLORBM ) );
463  KIGFX::COLOR4D layerColor = swatch->GetSwatchColor();
464 
465  INDICATOR_ICON* indicator = static_cast<INDICATOR_ICON*>( getLayerComp( row, COLUMN_ALPHA_INDICATOR ) );
466 
467  if( std::abs( screenColor.a - layerColor.a ) > ALPHA_EPSILON )
468  {
469  if( screenColor.a < layerColor.a )
470  indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::DOWN );
471  else
472  indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::UP );
473  }
474  else
476  }
477 }
478 
479 
481 {
482  BOARD* brd = myframe->GetBoard();
483  LSET enabled = brd->GetEnabledLayers();
484 
485  ClearLayerRows();
486 
487  wxString dsc;
488 
489  // show all coppers first, with front on top, back on bottom, then technical layers
490  for( LSEQ cu_stack = enabled.CuStack(); cu_stack; ++cu_stack )
491  {
492  PCB_LAYER_ID layer = *cu_stack;
493 
494  switch( layer )
495  {
496  case F_Cu:
497  dsc = _( "Front copper layer" );
498  break;
499 
500  case B_Cu:
501  dsc = _( "Back copper layer" );
502  break;
503 
504  default:
505  dsc = _( "Inner copper layer" );
506  break;
507  }
508 
510  brd->GetLayerName( layer ), layer, myframe->Settings().Colors().GetLayerColor( layer ),
511  dsc, true ) );
512 
513  if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) )
514  {
515  getLayerComp( GetLayerRowCount()-1, COLUMN_COLOR_LYRNAME )->Enable( false );
516  getLayerComp( GetLayerRowCount()-1, COLUMN_COLORBM )->SetToolTip( wxEmptyString );
517  }
518  }
519 
520  UpdateLayouts();
521 
522 
523  // technical layers are shown in this order:
524  // Because they are static, wxGetTranslation must be explicitly
525  // called for tooltips.
526  static const struct {
527  PCB_LAYER_ID layerId;
528  wxString tooltip;
529  } non_cu_seq[] = {
530  { F_Adhes, _( "Adhesive on board's front" ) },
531  { B_Adhes, _( "Adhesive on board's back" ) },
532  { F_Paste, _( "Solder paste on board's front" ) },
533  { B_Paste, _( "Solder paste on board's back" ) },
534  { F_SilkS, _( "Silkscreen on board's front" ) },
535  { B_SilkS, _( "Silkscreen on board's back" ) },
536  { F_Mask, _( "Solder mask on board's front" ) },
537  { B_Mask, _( "Solder mask on board's back" ) },
538  { Dwgs_User, _( "Explanatory drawings" ) },
539  { Cmts_User, _( "Explanatory comments" ) },
540  { Eco1_User, _( "User defined meaning" ) },
541  { Eco2_User, _( "User defined meaning" ) },
542  { Edge_Cuts, _( "Board's perimeter definition" ) },
543  { Margin, _( "Board's edge setback outline" ) },
544  { F_CrtYd, _( "Footprint courtyards on board's front" ) },
545  { B_CrtYd, _( "Footprint courtyards on board's back" ) },
546  { F_Fab, _( "Footprint assembly on board's front" ) },
547  { B_Fab, _( "Footprint assembly on board's back" ) }
548  };
549 
550  for( unsigned i=0; i<arrayDim( non_cu_seq ); ++i )
551  {
552  PCB_LAYER_ID layer = non_cu_seq[i].layerId;
553 
554  if( !enabled[layer] )
555  continue;
556 
558  brd->GetLayerName( layer ), layer, myframe->Settings().Colors().GetLayerColor( layer ),
559  wxGetTranslation( non_cu_seq[i].tooltip ), true ) );
560 
561  if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) )
562  {
563  getLayerComp( GetLayerRowCount()-1, COLUMN_COLOR_LYRNAME )->Enable( false );
564  getLayerComp( GetLayerRowCount()-1, COLUMN_COLORBM )->SetToolTip( wxEmptyString );
565  }
566  }
567 }
568 
569 
570 //-----<LAYER_WIDGET callbacks>-------------------------------------------
571 
573 {
574  myframe->Settings().Colors().SetLayerColor( aLayer, aColor );
575 
576  KIGFX::VIEW* view = myframe->GetCanvas()->GetView();
578  view->UpdateLayerColor( aLayer );
579  view->UpdateLayerColor( GetNetnameLayer( aLayer ) );
580 
582 
583  myframe->GetCanvas()->Refresh();
584 
585  if( aLayer == LAYER_PCB_BACKGROUND )
586  myframe->SetDrawBgColor( aColor );
587 }
588 
589 
591 {
592  // the layer change from the PCB_LAYER_WIDGET can be denied by returning
593  // false from this function.
594  PCB_LAYER_ID layer = ToLAYER_ID( aLayer );
595 
596  if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) )
597  return false;
598 
599  myframe->SetActiveLayer( layer );
601 
603  OnLayerSelected();
604  else if( displ_opts->m_ContrastModeDisplay )
605  myframe->GetCanvas()->Refresh();
606 
607  return true;
608 }
609 
610 
612 {
614  return false;
615 
616  // postprocess after an active layer selection
617  // ensure active layer visible
618  wxCommandEvent event;
620  onPopupSelection( event );
621 
622  return true;
623 }
624 
625 
626 void PCB_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFinal )
627 {
628  BOARD* brd = myframe->GetBoard();
629 
630  LSET visibleLayers = brd->GetVisibleLayers();
631 
632  if( visibleLayers.test( aLayer ) != isVisible )
633  {
634  visibleLayers.set( aLayer, isVisible );
635 
636  brd->SetVisibleLayers( visibleLayers );
637 
638  // Layer visibility is not stored in .kicad_mod files
639  if( !m_fp_editor_mode )
640  myframe->OnModify();
641 
642  if( myframe->GetCanvas() )
643  myframe->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible );
644  }
645 
646  if( isFinal )
647  myframe->GetCanvas()->Refresh();
648 }
649 
650 
652 {
653  AddRightClickMenuItems( aMenu );
654 }
655 
656 
658 {
659  wxASSERT( aId > GAL_LAYER_ID_START && aId < GAL_LAYER_ID_END );
660 
661  myframe->Settings().Colors().SetItemColor( static_cast<GAL_LAYER_ID>( aId ), aColor );
662 
663  if( aId == LAYER_GRID )
664  myframe->GetCanvas()->GetGAL()->SetGridColor( aColor );
665 
666  KIGFX::VIEW* view = myframe->GetCanvas()->GetView();
668  view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // useful to update rastnest
669  view->UpdateLayerColor( aId );
670 
671  // plated-through-holes don't have their own color; they use the background color
672  if( aId == LAYER_PCB_BACKGROUND )
674 
677  myframe->GetCanvas()->Refresh();
678 }
679 
680 
681 void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
682 {
683  BOARD* brd = myframe->GetBoard();
684  wxASSERT( aId > GAL_LAYER_ID_START && aId < GAL_LAYER_ID_END );
685 
686  if( myframe->IsType( FRAME_PCB ) )
687  {
688  // The layer visibility status is saved in the board file so set the board
689  // modified state so the user has the option to save the changes.
690  if( brd->IsElementVisible( static_cast<GAL_LAYER_ID>( aId ) ) != isEnabled )
691  myframe->OnModify();
692  }
693 
694  brd->SetElementVisibility( static_cast<GAL_LAYER_ID>( aId ), isEnabled );
695 
696  if( aId == LAYER_GRID )
697  {
700  }
701  else if( aId == LAYER_RATSNEST )
702  {
703  // don't touch the layers. ratsnest is enabled on per-item basis.
705  myframe->GetCanvas()->GetView()->SetLayerVisible( aId, true );
706 
707  if( myframe->IsType( FRAME_PCB ) )
708  {
709  auto opt = static_cast<PCB_DISPLAY_OPTIONS*>( myframe->GetDisplayOptions() );
710  opt->m_ShowGlobalRatsnest = isEnabled;
712  }
713  }
714  else
715  myframe->GetCanvas()->GetView()->SetLayerVisible( aId, isEnabled );
716 
717  myframe->GetCanvas()->Refresh();
718  myframe->GetCanvas()->Refresh();
719 }
720 
721 //-----</LAYER_WIDGET callbacks>------------------------------------------
Definition: colors.h:57
#define COLUMN_COLOR_LYRNAME
Definition: layer_widget.h:55
void AddRightClickMenuItems(wxMenu &menu)
Function addRightClickMenuItems add menu items to a menu that should be shown when right-clicking the...
void SetIndicatorState(ICON_ID aIconId)
Sets the row indiciator to the given state.
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:241
wxAuiNotebook * m_notebook
Definition: layer_widget.h:123
to draw blind/buried vias
#define ALPHA_EPSILON
LSEQ CuStack() const
Function CuStack returns a sequence of copper layers in starting from the front/top and extending to ...
Definition: lset.cpp:150
show a marker on pads with no nets
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
KIGFX::COLOR4D GetSwatchColor() const
static int s_allowed_in_FpEditor[]
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
void SetItemColor(int aItemIdx, COLOR4D aColor)
Function SetItemColor sets the color for an item which is one of the item indices given in enum PCB_L...
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
Struct ROW provides all the data needed to add a row to a LAYER_WIDGET.
Definition: layer_widget.h:87
multilayer pads, usually with holes
bool OnLayerSelect(int aLayer) override
Function OnLayerSelect is called to notify client code whenever the user selects a different layer.
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
#define COLUMN_ALPHA_INDICATOR
Definition: layer_widget.h:56
This file is part of the common library.
static LSET ForbiddenFootprintLayers()
Function ForbiddenFootprintLayers Layers which are not allowed within footprint definitions.
Definition: lset.cpp:789
bool spacer
if true, this row is a spacer
Definition: layer_widget.h:95
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:251
handle color for not plated holes (holes, not pads)
anchor of items having an anchor point (texts, footprints)
virtual bool IsGridVisible() const
void UpdateLayouts()
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool isLayerAllowedInFpMode(PCB_LAYER_ID aLayer)
Function isLayerAllowedInFpMode.
bool isLast(CPTREE &aTree, CITER it)
Definition: ptree.cpp:122
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
PCB_BASE_FRAME * myframe
show modules values (when texts are visibles)
virtual COLOR4D getBackgroundLayerColor() override
Subclasses can override this to provide accurate representation of transparent colour swatches.
#define OFF
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
bool OnLayerSelected()
Function OnLayerSelected ensure the active layer is visible, and other layers not visible when m_alwa...
void SetLayerColor(LAYER_NUM aLayer, COLOR4D aColor)
Function SetLayerColor sets the color for aLayer.
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
void SetDrawBgColor(COLOR4D aColor) override
Add new GAL layers here.
void OnLayerRightClick(wxMenu &aMenu) override
Function OnLayerRightClick is called to notify client code about a layer being right-clicked.
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:746
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:226
#define abs(a)
Definition: auxiliary.h:84
void ClearRenderRows()
Function ClearRenderRows empties out the render rows.
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
Definition: colors.h:54
bool state
initial wxCheckBox state
Definition: layer_widget.h:92
void SetLayersManagerTabsText()
Function SetLayersManagerTabsText Update the layer manager tabs labels Useful when changing Language ...
void ClearLayerRows()
Function ClearLayerRows empties out the layer rows.
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
wxString tooltip
if not empty, use this tooltip on row
Definition: layer_widget.h:93
Auxiliary rendering target (noncached)
Definition: definitions.h:49
This file contains miscellaneous commonly used macros and functions.
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
show modules on front
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:61
Class TOOL_MANAGER.
Definition: tool_manager.h:50
void AppendRenderRow(const ROW &aRow)
Function AppendRenderRow appends a new row in the render portion of the widget.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
COLOR4D color
COLOR4D::UNSPECIFIED if none.
Definition: layer_widget.h:91
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
Class representing a row indicator icon for use in places like the layer widget.
double a
Alpha component.
Definition: color4d.h:304
#define COLUMN_ICON_ACTIVE
Definition: layer_widget.h:52
bool isAllowedInFpMode(int aId)
Function isAllowedInFpMode.
Class LSET is a set of PCB_LAYER_IDs.
Footprint text class description.
Auxiliary items (guides, rule, etc)
void setLayerCheckbox(LAYER_NUM aLayer, bool isVisible)
#define COLUMN_COLORBM
Definition: layer_widget.h:53
virtual PCB_RENDER_SETTINGS * GetSettings() override
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Definition: pcb_painter.h:238
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
virtual void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings)
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: painter.h:67
void OnLayerColorChange(int aLayer, COLOR4D aColor) override
Function OnLayerColorChange is called to notify client code about a layer color change.
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
PCB_GENERAL_SETTINGS & Settings()
to draw usual through hole vias
#define NOCOLOR
void AppendLayerRow(const ROW &aRow)
Function AppendLayerRow appends a new row in the layer portion of the widget.
void ReFillRender()
Function ReFillRender rebuilds Render for instance after the config is read.
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:125
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
void onRightDownLayers(wxMouseEvent &event)
Function OnRightDownLayers puts up a popup menu for the layer panel.
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:399
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
void UpdateDisplayOptions(PCB_DISPLAY_OPTIONS *aOptions)
Definition: pcb_view.cpp:113
#define _(s)
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SyncLayerAlphaIndicators()
Function SyncLayerAlphaIndicators updates each "Layer"s alpha indicator to show if the board is curre...
COLORS_DESIGN_SETTINGS & Colors()
static const LAYER_WIDGET::ROW s_render_rows[]
This is a read only template that is copied and modified before adding to LAYER_WIDGET.
void OnRenderColorChange(int aId, COLOR4D aColor) override
Function OnRenderColorChange is called to notify client code whenever the user changes a rendering co...
bool m_alwaysShowActiveCopperLayer
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
void UpdateLayerColor(int aLayer)
Function UpdateLayerColor() Applies the new coloring scheme held by RENDER_SETTINGS in case that it h...
Definition: view.cpp:777
void OnLayerVisible(int aLayer, bool isVisible, bool isFinal) override
Function OnLayerVisible is called to notify client code about a layer visibility change.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
Class LAYER_WIDGET is abstract and is used to manage a list of layers, with the notion of a "current"...
Definition: layer_widget.h:79
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:459
void SyncLayerVisibilities()
Function SyncLayerVisibilities updates each "Layer" checkbox in this layer widget according to each l...
virtual void ReCreateHToolbar()=0
smd pads, front layer
see class PGM_BASE
bool IsType(FRAME_T aType) const
#define COLUMN_COLOR_LYR_CB
Definition: layer_widget.h:54
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
wxString rowName
the prompt or layername
Definition: layer_widget.h:89
size_t i
Definition: json11.cpp:597
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
void SetGridVisibility(bool aVisibility)
Sets the visibility setting of the grid.
Definition: colors.h:49
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
Definition: colors.h:45
BOARD * GetBoard() const
Class VIEW.
Definition: view.h:61
void OnRenderEnable(int aId, bool isEnabled) override
Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable...
Definition: colors.h:68
Definition of PCB_DISPLAY_OPTIONS class.
int id
either a layer or "visible element" id
Definition: layer_widget.h:90
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
show modules references (when texts are visibles)
void onPopupSelection(wxCommandEvent &event)
#define RR
PCB_LAYER_WIDGET(PCB_BASE_FRAME *aParent, wxWindow *aFocusOwner, bool aFpEditorMode=false)
Constructor.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39