KiCad PCB EDA Suite
toolbars_pcb_editor.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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <fctsys.h>
28 #include <kiface_i.h>
29 #include <help_common_strings.h>
30 #include <dialog_helpers.h>
31 #include <pcb_edit_frame.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <bitmaps.h>
35 #include <class_board.h>
36 #include <tool/actions.h>
37 #include <pcbnew.h>
38 #include <pcbnew_id.h>
39 #include <hotkeys.h>
40 #include <pcb_layer_box_selector.h>
41 #include <view/view.h>
42 
43 #include <wx/wupdlock.h>
44 #include <memory>
45 #include <pgm_base.h>
46 
47 extern bool IsWxPythonLoaded();
48 
49 #define SEL_LAYER_HELP _( \
50  "Show active layer selections\nand select layer pair for route and place via" )
51 
52 
53 /* Data to build the layer pair indicator button */
54 static std::unique_ptr<wxBitmap> LayerPairBitmap;
55 
56 #define BM_LAYERICON_SIZE 24
58 {
59  // 0 = draw pixel with active layer color
60  // 1 = draw pixel with top layer color (top/bottom layer used inautoroute and place via)
61  // 2 = draw pixel with bottom layer color
62  // 3 = draw pixel with via color
63  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 },
64  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 },
65  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
66  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
67  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
68  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
69  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
70  { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0 },
71  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 1, 1, 1, 1, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
72  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
73  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
74  { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 1, 1, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0 },
75  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
76  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
77  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
78  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
79  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
80  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
81  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
82  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
83  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
84  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
85 };
86 
87 
89 {
90  int ii, jj;
91  COLOR4D active_layer_color, Route_Layer_TOP_color,
92  Route_Layer_BOTTOM_color, via_color, background_color;
93  bool change = false;
94 
95  static int previous_requested_scale;
96  static COLOR4D previous_active_layer_color, previous_Route_Layer_TOP_color,
97  previous_Route_Layer_BOTTOM_color, previous_via_color,
98  previous_background_color;
99 
100  int requested_scale;
101  Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
102 
103  if( requested_scale != previous_requested_scale )
104  {
105  previous_requested_scale = requested_scale;
106  change = true;
107  }
108 
109  active_layer_color = Settings().Colors().GetLayerColor(GetActiveLayer());
110 
111  if( previous_active_layer_color != active_layer_color )
112  {
113  previous_active_layer_color = active_layer_color;
114  change = true;
115  }
116 
117  Route_Layer_TOP_color =
118  Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_TOP );
119 
120  if( previous_Route_Layer_TOP_color != Route_Layer_TOP_color )
121  {
122  previous_Route_Layer_TOP_color = Route_Layer_TOP_color;
123  change = true;
124  }
125 
126  Route_Layer_BOTTOM_color =
127  Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
128 
129  if( previous_Route_Layer_BOTTOM_color != Route_Layer_BOTTOM_color )
130  {
131  previous_Route_Layer_BOTTOM_color = Route_Layer_BOTTOM_color;
132  change = true;
133  }
134 
135  int via_type = GetDesignSettings().m_CurrentViaType;
136  via_color = Settings().Colors().GetItemColor( LAYER_VIAS + via_type );
137 
138  if( previous_via_color != via_color )
139  {
140  previous_via_color = via_color;
141  change = true;
142  }
143 
144  background_color = Settings().Colors().GetItemColor( LAYER_PCB_BACKGROUND );
145 
146  if( previous_background_color != background_color )
147  {
148  previous_background_color = background_color;
149  change = true;
150  }
151 
152  if( !change && LayerPairBitmap )
153  return;
154 
155  LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
156 
157  /* Draw the icon, with colors according to the active layer and layer
158  * pairs for via command (change layer)
159  */
160  wxMemoryDC iconDC;
161  iconDC.SelectObject( *LayerPairBitmap );
162  wxBrush brush;
163  wxPen pen;
164  int buttonColor = -1;
165 
166  brush.SetStyle( wxBRUSHSTYLE_SOLID );
167  brush.SetColour( background_color.WithAlpha(1.0).ToColour() );
168  iconDC.SetBrush( brush );
169  iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
170 
171  for( ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
172  {
173  for( jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
174  {
175  if( s_BitmapLayerIcon[ii][jj] != buttonColor )
176  {
177  switch( s_BitmapLayerIcon[ii][jj] )
178  {
179  default:
180  case 0:
181  pen.SetColour( active_layer_color.ToColour() );
182  break;
183 
184  case 1:
185  pen.SetColour( Route_Layer_TOP_color.ToColour() );
186  break;
187 
188  case 2:
189  pen.SetColour( Route_Layer_BOTTOM_color.ToColour() );
190  break;
191 
192  case 3:
193  pen.SetColour( via_color.ToColour() );
194  break;
195  }
196 
197  buttonColor = s_BitmapLayerIcon[ii][jj];
198  iconDC.SetPen( pen );
199  }
200 
201  iconDC.DrawPoint( jj, ii );
202  }
203  }
204 
205  /* Deselect the Tool Bitmap from DC,
206  * in order to delete the MemoryDC safely without deleting the bitmap */
207  iconDC.SelectObject( wxNullBitmap );
208 
209  // Scale the bitmap
210  const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
211  wxImage image = LayerPairBitmap->ConvertToImage();
212 
213  // "NEAREST" causes less mixing of colors
214  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
215  wxIMAGE_QUALITY_NEAREST );
216 
217  LayerPairBitmap = std::make_unique<wxBitmap>( image );
218 
219  if( m_mainToolBar )
220  {
222  m_mainToolBar->Refresh();
223  }
224 }
225 
226 
228 {
229  // Note:
230  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
231  // all wxAuiToolBarItems.
232  // However the wxAuiToolBarItems are not the owners of controls managed by
233  // them and therefore do not delete them
234  // So we do not recreate them after clearing the tools.
235 
236  wxString msg;
237 
238  wxWindowUpdateLocker dummy( this );
239 
240  if( m_mainToolBar )
241  m_mainToolBar->Clear();
242  else
243  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
244  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
245 
246 #define ADD_TOOL( id, xpm, tooltip ) \
247  m_mainToolBar->AddTool( id, wxEmptyString, KiScaledBitmap( xpm, this ), tooltip );
248 
249  // Set up toolbar
250  if( Kiface().IsSingle() )
251  {
252  ADD_TOOL( ID_NEW_BOARD, new_board_xpm, _( "New board" ) );
253  ADD_TOOL( ID_LOAD_FILE, open_brd_file_xpm, _( "Open existing board" ) );
254  }
255 
256  ADD_TOOL( ID_SAVE_BOARD, save_xpm, _( "Save board" ) );
257 
259  ADD_TOOL( ID_BOARD_SETUP_DIALOG, options_board_xpm, _( "Board setup" ) );
260 
262  ADD_TOOL( ID_SHEET_SET, sheetset_xpm, _( "Page settings for paper size and texts" ) );
263  ADD_TOOL( wxID_PRINT, print_button_xpm, _( "Print board" ) );
264  ADD_TOOL( ID_GEN_PLOT, plot_xpm, _( "Plot (HPGL, PostScript, or GERBER format)" ) );
265 
268  ADD_TOOL( wxID_UNDO, undo_xpm, msg );
270  ADD_TOOL( wxID_REDO, redo_xpm, msg );
271 
274  ADD_TOOL( ID_FIND_ITEMS, find_xpm, msg );
275 
276  m_mainToolBar->AddSeparator();
282 
284  ADD_TOOL( ID_OPEN_MODULE_EDITOR, module_editor_xpm, _( "Open footprint editor" ) );
285  ADD_TOOL( ID_OPEN_MODULE_VIEWER, modview_icon_xpm, _( "Open footprint viewer" ) );
286 
288  ADD_TOOL( ID_UPDATE_PCB_FROM_SCH, update_pcb_from_sch_xpm, _( "Update PCB from schematic" ) );
289  ADD_TOOL( ID_DRC_CONTROL, erc_xpm, _( "Perform design rules check" ) );
290 
292 
293  if( m_SelLayerBox == nullptr )
294  {
296  m_SelLayerBox->SetBoardFrame( this );
297  }
298 
299  ReCreateLayerBox( false );
300  m_mainToolBar->AddControl( m_SelLayerBox );
301 
302  PrepareLayerIndicator(); // Initialize the bitmap with the active layer colors
304  SEL_LAYER_HELP );
305 
307  ADD_TOOL( ID_RUN_EESCHEMA, eeschema_xpm, _( "Open schematic in Eeschema" ) );
308 
309  // Access to the scripting console
310 #if defined(KICAD_SCRIPTING_WXPYTHON)
311  if( IsWxPythonLoaded() )
312  {
314 
315  m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
316  KiScaledBitmap( py_script_xpm, this ),
317  _( "Show/Hide the Python Scripting console" ), wxITEM_CHECK );
318 
319 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
320  AddActionPluginTools();
321 #endif
322  }
323 #endif
324 
325  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
326  m_mainToolBar->Realize();
327 
328 #undef ADD_TOOL
329 }
330 
331 
333 {
334  // Note:
335  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
336  // all wxAuiToolBarItems.
337  // However the wxAuiToolBarItems are not the owners of controls managed by
338  // them and therefore do not delete them
339  // So we do not recreate them after clearing the tools.
340 
341  wxWindowUpdateLocker dummy( this );
342 
343  if( m_optionsToolBar )
344  m_optionsToolBar->Clear();
345  else
347  wxDefaultPosition, wxDefaultSize,
348  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
349 
350  m_optionsToolBar->AddTool( ID_TB_OPTIONS_DRC_OFF, wxEmptyString, KiScaledBitmap( drc_off_xpm, this ),
351  _( "Enable design rule checking" ), wxITEM_CHECK );
353 
354  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
355  KiScaledBitmap( polar_coord_xpm, this ),
356  _( "Display polar coordinates" ), wxITEM_CHECK );
357 
361 
363  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_RATSNEST, wxEmptyString,
364  KiScaledBitmap( general_ratsnest_xpm, this ),
365  _( "Show board ratsnest" ), wxITEM_CHECK );
366  m_optionsToolBar->AddTool( ID_TB_OPTIONS_CURVED_RATSNEST_LINES, wxEmptyString,
367  KiScaledBitmap( curved_ratsnest_xpm, this ),
368  _( "Show ratsnest with curved lines" ),
369  wxITEM_CHECK );
370 
372  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES, wxEmptyString, KiScaledBitmap( show_zone_xpm, this ),
373  _( "Show filled areas in zones" ), wxITEM_CHECK );
374  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, wxEmptyString,
375  KiScaledBitmap( show_zone_disable_xpm, this ),
376  _( "Do not show filled areas in zones" ) , wxITEM_CHECK );
378  KiScaledBitmap( show_zone_outline_only_xpm, this ),
379  _( "Show outlines of filled areas only in zones" ), wxITEM_CHECK );
380 
382  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString,
383  KiScaledBitmap( pad_sketch_xpm, this ),
384  _( "Show pads in outline mode" ), wxITEM_CHECK );
385 
386  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_VIAS_SKETCH, wxEmptyString,
387  KiScaledBitmap( via_sketch_xpm, this ),
388  _( "Show vias in outline mode" ), wxITEM_CHECK );
389 
390  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, wxEmptyString,
391  KiScaledBitmap( showtrack_xpm, this ),
392  _( "Show tracks in outline mode" ),
393  wxITEM_CHECK );
394 
396  KiScaledBitmap( contrast_mode_xpm, this ),
397  _( "Enable high contrast display mode" ),
398  wxITEM_CHECK );
399 
400  // Tools to show/hide toolbars:
403  wxEmptyString,
404  KiScaledBitmap( layers_manager_xpm, this ),
406  wxITEM_CHECK );
408  wxEmptyString,
409  KiScaledBitmap( mw_toolbar_xpm, this ),
411  wxITEM_CHECK );
412 
413 
415  m_optionsToolBar->Realize();
416 }
417 
418 
420 {
421  wxWindowUpdateLocker dummy( this );
422 
423  if( m_drawToolBar )
424  m_drawToolBar->Clear();
425  else
426  m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
427  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
428 
429  // Set up toolbar
430  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
431  _( "Select item" ), wxITEM_CHECK );
432 
434 
435  m_drawToolBar->AddTool( ID_PCB_HIGHLIGHT_BUTT, wxEmptyString, KiScaledBitmap( net_highlight_xpm, this ),
436  _( "Highlight net" ), wxITEM_CHECK );
437 
438  m_drawToolBar->AddTool( ID_PCB_SHOW_1_RATSNEST_BUTT, wxEmptyString,
439  KiScaledBitmap( tool_ratsnest_xpm, this ),
440  _( "Display local ratsnest" ), wxITEM_CHECK );
441 
443  m_drawToolBar->AddTool( ID_PCB_MODULE_BUTT, wxEmptyString, KiScaledBitmap( module_xpm, this ),
444  _( "Add footprints" ), wxITEM_CHECK );
445 
446  m_drawToolBar->AddTool( ID_TRACK_BUTT, wxEmptyString, KiScaledBitmap( add_tracks_xpm, this ),
447  _( "Route tracks" ), wxITEM_CHECK );
448 
449  m_drawToolBar->AddTool( ID_PCB_DRAW_VIA_BUTT, wxEmptyString, KiScaledBitmap( add_via_xpm, this ),
450  _( "Add vias" ), wxITEM_CHECK );
451 
452  m_drawToolBar->AddTool( ID_PCB_ZONES_BUTT, wxEmptyString, KiScaledBitmap( add_zone_xpm, this ),
453  _( "Add filled zones" ), wxITEM_CHECK );
454 
455  m_drawToolBar->AddTool( ID_PCB_KEEPOUT_AREA_BUTT, wxEmptyString,
456  KiScaledBitmap( add_keepout_area_xpm, this ),
457  _( "Add keepout areas" ), wxITEM_CHECK );
458 
460 
461  m_drawToolBar->AddTool( ID_PCB_ADD_LINE_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_segments_xpm, this ),
462  _( "Add graphic lines" ), wxITEM_CHECK );
463 
464  m_drawToolBar->AddTool( ID_PCB_CIRCLE_BUTT, wxEmptyString, KiScaledBitmap( add_circle_xpm, this ),
465  _( "Add graphic circle" ), wxITEM_CHECK );
466 
467  m_drawToolBar->AddTool( ID_PCB_ARC_BUTT, wxEmptyString, KiScaledBitmap( add_arc_xpm, this ),
468  _( "Add graphic arc" ), wxITEM_CHECK );
469 
470  m_drawToolBar->AddTool( ID_PCB_ADD_POLYGON_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_polygon_xpm, this ),
471  _( "Add graphic polygon" ), wxITEM_CHECK );
472 
473  m_drawToolBar->AddTool( ID_PCB_ADD_TEXT_BUTT, wxEmptyString, KiScaledBitmap( text_xpm, this ),
474  _( "Add text on copper layers or graphic text" ), wxITEM_CHECK );
475 
477  m_drawToolBar->AddTool( ID_PCB_DIMENSION_BUTT, wxEmptyString, KiScaledBitmap( add_dimension_xpm, this ),
478  _( "Add dimension" ), wxITEM_CHECK );
479 
480  m_drawToolBar->AddTool( ID_PCB_TARGET_BUTT, wxEmptyString, KiScaledBitmap( add_pcb_target_xpm, this ),
481  _( "Add layer alignment target" ), wxITEM_CHECK );
482 
484  m_drawToolBar->AddTool( ID_PCB_DELETE_ITEM_BUTT, wxEmptyString, KiScaledBitmap( delete_xpm, this ),
485  _( "Delete items" ), wxITEM_CHECK );
486 
488  m_drawToolBar->AddTool( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxEmptyString,
489  KiScaledBitmap( pcb_offset_xpm, this ),
490  _( "Place the auxiliary axis origin for some plot file formats,\n"
491  "and for drill and place files" ),
492  wxITEM_CHECK );
493 
494  m_drawToolBar->AddTool( ID_PCB_PLACE_GRID_COORD_BUTT, wxEmptyString,
495  KiScaledBitmap( grid_select_axis_xpm, this ),
496  _( "Set the origin point for the grid" ),
497  wxITEM_CHECK );
498 
499  m_drawToolBar->AddTool( ID_PCB_MEASUREMENT_TOOL, wxEmptyString,
500  KiScaledBitmap( measurement_xpm, this ),
501  _( "Measure distance" ),
502  wxITEM_CHECK );
503 
504  m_drawToolBar->Realize();
505 }
506 
507 
508 /* Create the auxiliary vertical right toolbar, showing tools for microwave applications
509  */
511 {
512  wxWindowUpdateLocker dummy(this);
513 
514  if( m_microWaveToolBar )
515  m_microWaveToolBar->Clear();
516  else
517  m_microWaveToolBar = new wxAuiToolBar( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition,
518  wxDefaultSize,
519  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
520 
521  // Set up toolbar
522  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString,
523  KiScaledBitmap( mw_add_line_xpm, this ),
524  _( "Create line of specified length for microwave applications" ),
525  wxITEM_CHECK );
526 
527  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString,
528  KiScaledBitmap( mw_add_gap_xpm, this ),
529  _( "Create gap of specified length for microwave applications" ),
530  wxITEM_CHECK );
531 
533 
534  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString,
535  KiScaledBitmap( mw_add_stub_xpm, this ),
536  _( "Create stub of specified length for microwave applications" ),
537  wxITEM_CHECK );
538 
539  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString,
540  KiScaledBitmap( mw_add_stub_arc_xpm, this ),
541  _( "Create stub (arc) of specified length for microwave applications" ),
542  wxITEM_CHECK );
543 
545  KiScaledBitmap( mw_add_shape_xpm, this ),
546  _( "Create a polynomial shape for microwave applications" ),
547  wxITEM_CHECK );
548 
549  m_microWaveToolBar->Realize();
550 }
551 
552 
554 {
555  wxWindowUpdateLocker dummy( this );
556 
557  if( m_auxiliaryToolBar )
558  {
561 
562  // combobox sizes can have changed: apply new best sizes
563  wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
564  item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
566  item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
567 
568  m_auxiliaryToolBar->Realize();
569  m_auimgr.Update();
570  return;
571  }
572 
574  wxDefaultPosition, wxDefaultSize,
575  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
576 
577  /* Set up toolbar items */
578 
579  // Creates box to display and choose tracks widths:
580  if( m_SelTrackWidthBox == nullptr )
581  m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar,
583  wxDefaultPosition, wxDefaultSize,
584  0, NULL );
585 
587  m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
588 
589  // Creates box to display and choose vias diameters:
590 
591  if( m_SelViaSizeBox == nullptr )
592  m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar,
594  wxDefaultPosition, wxDefaultSize,
595  0, NULL );
596 
598  m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
600 
601  // Creates box to display and choose strategy to handle tracks an vias sizes:
603  wxEmptyString,
604  KiScaledBitmap( auto_track_width_xpm, this ),
605  _( "Auto track width: when starting on an existing track "
606  "use its width\notherwise, use current width setting" ),
607  wxITEM_CHECK );
608 
609  // Add the box to display and select the current grid size:
611 
612  if( m_gridSelectBox == nullptr )
613  m_gridSelectBox = new wxChoice( m_auxiliaryToolBar,
615  wxDefaultPosition, wxDefaultSize,
616  0, NULL );
617 
619 
620  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
621 
622  // Add the box to display and select the current Zoom
624 
625  if( m_zoomSelectBox == nullptr )
626  m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar,
628  wxDefaultPosition, wxDefaultSize,
629  0, NULL );
630 
632  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
633 
634  // after adding the buttons to the toolbar, must call Realize()
635  m_auxiliaryToolBar->Realize();
636 }
637 
638 
639 void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, const bool aEdit )
640 {
641  if( aTrackWidthSelectBox == NULL )
642  return;
643 
644  wxString msg;
645  bool mmFirst = GetUserUnits() != INCHES;
646 
647  aTrackWidthSelectBox->Clear();
648 
649  for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
650  {
651  int size = GetDesignSettings().m_TrackWidthList[ii];
652 
653  double valueMils = To_User_Unit( INCHES, size ) * 1000;
654  double value_mm = To_User_Unit( MILLIMETRES, size );
655 
656  if( mmFirst )
657  msg.Printf( _( "Track: %.3f mm (%.2f mils)" ),
658  value_mm, valueMils );
659  else
660  msg.Printf( _( "Track: %.2f mils (%.3f mm)" ),
661  valueMils, value_mm );
662 
663  // Mark the netclass track width value (the first in list)
664  if( ii == 0 )
665  msg << wxT( " *" );
666 
667  aTrackWidthSelectBox->Append( msg );
668  }
669 
670  if( aEdit )
671  {
672  aTrackWidthSelectBox->Append( wxT( "---" ) );
673  aTrackWidthSelectBox->Append( _( "Edit pre-defined sizes..." ) );
674  }
675 
676  if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
678 
679  aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
680 }
681 
682 
683 void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, const bool aEdit )
684 {
685  if( aViaSizeSelectBox == NULL )
686  return;
687 
688  aViaSizeSelectBox->Clear();
689 
690  bool mmFirst = GetUserUnits() != INCHES;
691 
692  for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
693  {
695  wxString msg, mmStr, milsStr;
696 
697  double diam = To_User_Unit( MILLIMETRES, viaDimension.m_Diameter );
698  double hole = To_User_Unit( MILLIMETRES, viaDimension.m_Drill );
699 
700  if( hole > 0 )
701  mmStr.Printf( _( "%.2f / %.2f mm" ), diam, hole );
702  else
703  mmStr.Printf( _( "%.2f mm" ), diam );
704 
705  diam = To_User_Unit( INCHES, viaDimension.m_Diameter ) * 1000;
706  hole = To_User_Unit( INCHES, viaDimension.m_Drill ) * 1000;
707 
708  if( hole > 0 )
709  milsStr.Printf( _( "%.1f / %.1f mils" ), diam, hole );
710  else
711  milsStr.Printf( _( "%.1f mils" ), diam );
712 
713  msg.Printf( _( "Via: %s (%s)" ), mmFirst ? mmStr : milsStr, mmFirst ? milsStr : mmStr );
714 
715  // Mark the netclass via size value (the first in list)
716  if( ii == 0 )
717  msg << wxT( " *" );
718 
719  aViaSizeSelectBox->Append( msg );
720  }
721 
722  if( aEdit )
723  {
724  aViaSizeSelectBox->Append( wxT( "---" ) );
725  aViaSizeSelectBox->Append( _( "Edit pre-defined sizes..." ) );
726  }
727 
728  if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
730 
731  aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
732 }
733 
734 
735 void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
736 {
737  if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
738  return;
739 
740  m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
743 
744  if( aForceResizeToolbar )
745  {
746  // the layer box can have its size changed
747  // Update the aui manager, to take in account the new size
748  m_auimgr.Update();
749  }
750 }
751 
752 
753 void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
754 {
755  int id = event.GetId();
756  bool state = event.IsChecked();
757  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
758 
759  switch( id )
760  {
762  Settings().m_legacyDrcOn = !state;
763 
764  if( GetToolId() == ID_TRACK_BUTT )
765  {
766  if( Settings().m_legacyDrcOn )
767  m_canvas->SetCursor( wxCURSOR_PENCIL );
768  else
769  m_canvas->SetCursor( wxCURSOR_QUESTION_ARROW );
770  }
771  break;
772 
776  Compile_Ratsnest( NULL, true );
777 
778  if( IsGalCanvasActive() )
779  {
780  // keep the ratsnest layer enabled in view, so it shows up when an item is dragged
781  auto view = GetGalCanvas()->GetView();
783  view->SetLayerVisible( LAYER_RATSNEST, true );
784  }
785 
786  m_canvas->Refresh();
787  break;
788 
790  displ_opts->m_DisplayZonesMode = 0;
791  m_canvas->Refresh();
792  break;
793 
795  displ_opts->m_DisplayZonesMode = 1;
796  m_canvas->Refresh();
797  break;
798 
800  displ_opts->m_DisplayZonesMode = 2;
801  m_canvas->Refresh();
802  break;
803 
805  displ_opts->m_DisplayViaFill = !state;
806  m_canvas->Refresh();
807  break;
808 
810  displ_opts->m_DisplayPcbTrackFill = !state;
811  m_canvas->Refresh();
812  break;
813 
815  {
816  displ_opts->m_ContrastModeDisplay = state;
817  m_canvas->Refresh();
818  break;
819  }
820 
822  displ_opts->m_DisplayRatsnestLinesCurved = !state;
823  m_canvas->Refresh();
824  break;
825 
827  m_show_microwave_tools = state;
828  m_auimgr.GetPane( "MicrowaveToolbar" ).Show( m_show_microwave_tools );
829  m_auimgr.Update();
830  break;
831 
833  // show auxiliary Vertical layers and visibility manager toolbar
835  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
836  m_auimgr.Update();
837  break;
838 
839  default:
840  DisplayErrorMessage( this, "Invalid toolbar option",
841  "PCB_EDIT_FRAME::OnSelectOptionToolbar error \n (event not handled!)" );
842  break;
843  }
844 }
Struct VIA_DIMENSION is a small helper container to handle a stock of specific vias each with unique ...
Class ACTION_TOOLBAR.
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
VIATYPE_T m_CurrentViaType
(VIA_BLIND_BURIED, VIA_THROUGH, VIA_MICROVIA)
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
static TOOL_ACTION zoomInCenter
Definition: actions.h:60
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:258
static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE]
ACTION_TOOLBAR * m_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window.
Definition: draw_frame.h:159
This file is part of the common library.
#define HELP_SHOW_HIDE_MICROWAVE_TOOLS
std::vector< int > m_TrackWidthList
ACTION_TOOLBAR * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:166
EDA_HOTKEY_CONFIG * m_hotkeys
static const bool TOGGLE
static TOOL_ACTION zoomTool
Definition: actions.h:65
Class BOARD to handle a board.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
wxChoice * m_SelViaSizeBox
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:89
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
Function Add() Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:63
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building le new one, from the new layers names ...
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:255
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox, const bool aEdit=true)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY
Class to display a pcb layer list in a wxBitmapComboBox.
wxAuiManager m_auimgr
bool m_show_microwave_tools
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
ACTION_TOOLBAR * m_mainToolBar
Definition: draw_frame.h:156
void ReCreateHToolbar() override
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
#define BM_LAYERICON_SIZE
wxChoice * m_SelTrackWidthBox
static TOOL_ACTION imperialUnits
Definition: actions.h:102
wxChoice * m_gridSelectBox
Definition: draw_frame.h:153
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
static TOOL_ACTION zoomOutCenter
Definition: actions.h:61
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
Pcbnew hotkeys.
Auxiliary rendering target (noncached)
Definition: definitions.h:49
#define SEL_LAYER_HELP
bool m_show_layer_manager_tools
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:924
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
wxAuiToolBar * m_microWaveToolBar
The auxiliary right vertical tool bar used to access the microwave tools.
void OnSelectOptionToolbar(wxCommandEvent &event)
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:596
static TOOL_ACTION toggleGrid
Definition: actions.h:98
PCB_GENERAL_SETTINGS & Settings()
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
Definition: common.h:158
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:154
void ReCreateVToolbar() override
Helper dialog and control classes.
struct EDA_HOTKEY_CONFIG g_Board_Editor_Hotkeys_Descr[]
PCB_EDIT_FRAME::OnSelectOptionToolbar ID_PCB_MEASUREMENT_TOOL
#define ICON_SCALE_KEY
Definition: pgm_base.h:46
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:190
COLORS_DESIGN_SETTINGS & Colors()
void UpdateGridSelectBox()
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:53
bool IsWxPythonLoaded()
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:128
static TOOL_ACTION metricUnits
Definition: actions.h:103
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
#define HELP_REDO
const int scale
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value)
see class PGM_BASE
#define ADD_TOOL(id, xpm, tooltip)
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox, const bool aEdit=true)
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
static TOOL_ACTION zoomRedraw
Definition: actions.h:57
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
#define HELP_SHOW_HIDE_LAYERMANAGER
void ReCreateOptToolbar() override
#define HELP_UNDO
These strings are used in menus and tools, that do the same command But they are internationalized,...
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
std::vector< VIA_DIMENSION > m_ViasDimensionsList
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
Definition: id.h:97
static const char * text_xpm[]
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:68
PCB_LAYER_BOX_SELECTOR * m_SelLayerBox
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void updateZoomSelectBox()
static std::unique_ptr< wxBitmap > LayerPairBitmap
strings common to toolbars and menubar
#define HELP_FIND
void ReCreateAuxiliaryToolbar() override
int GetToolId() const
Definition: draw_frame.h:524
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
ACTION_TOOLBAR * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:163