KiCad PCB EDA Suite
tool_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=2015 Wayne Stambaugh <stambaughw@verizon.net>
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 
32 #include <fctsys.h>
33 #include <kiface_i.h>
34 #include <help_common_strings.h>
35 #include <dialog_helpers.h>
36 #include <pcb_edit_frame.h>
37 #include <class_drawpanel.h>
38 #include <confirm.h>
39 #include <bitmaps.h>
40 
41 #include <class_board.h>
42 
43 #include <pcbnew.h>
44 #include <pcbnew_id.h>
45 #include <hotkeys.h>
46 #include <pcb_layer_box_selector.h>
47 #include <view/view.h>
48 
49 #include <wx/wupdlock.h>
50 #include <memory>
51 #include <pgm_base.h>
52 
53 extern bool IsWxPythonLoaded();
54 
55 #define SEL_LAYER_HELP _( \
56  "Show active layer selections\nand select layer pair for route and place via" )
57 
58 
59 /* Data to build the layer pair indicator button */
60 static std::unique_ptr<wxBitmap> LayerPairBitmap;
61 
62 #define BM_LAYERICON_SIZE 24
64 {
65  // 0 = draw pixel with active layer color
66  // 1 = draw pixel with top layer color (top/bottom layer used inautoroute and place via)
67  // 2 = draw pixel with bottom layer color
68  // 3 = draw pixel with via color
69  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 },
70  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 },
71  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
72  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
73  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
74  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
75  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
76  { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0 },
77  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 1, 1, 1, 1, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
78  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
79  { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
80  { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 1, 1, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0 },
81  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
82  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 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  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
86  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
87  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
88  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
89  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
90  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
91 };
92 
93 
95 {
96  int ii, jj;
97  COLOR4D active_layer_color, Route_Layer_TOP_color,
98  Route_Layer_BOTTOM_color, via_color, background_color;
99  bool change = false;
100 
101  static int previous_requested_scale;
102  static COLOR4D previous_active_layer_color, previous_Route_Layer_TOP_color,
103  previous_Route_Layer_BOTTOM_color, previous_via_color,
104  previous_background_color;
105 
106  int requested_scale;
107  Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
108 
109  if( requested_scale != previous_requested_scale )
110  {
111  previous_requested_scale = requested_scale;
112  change = true;
113  }
114 
115  active_layer_color = Settings().Colors().GetLayerColor(GetActiveLayer());
116 
117  if( previous_active_layer_color != active_layer_color )
118  {
119  previous_active_layer_color = active_layer_color;
120  change = true;
121  }
122 
123  Route_Layer_TOP_color =
124  Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_TOP );
125 
126  if( previous_Route_Layer_TOP_color != Route_Layer_TOP_color )
127  {
128  previous_Route_Layer_TOP_color = Route_Layer_TOP_color;
129  change = true;
130  }
131 
132  Route_Layer_BOTTOM_color =
133  Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
134 
135  if( previous_Route_Layer_BOTTOM_color != Route_Layer_BOTTOM_color )
136  {
137  previous_Route_Layer_BOTTOM_color = Route_Layer_BOTTOM_color;
138  change = true;
139  }
140 
141  int via_type = GetDesignSettings().m_CurrentViaType;
142  via_color = Settings().Colors().GetItemColor( LAYER_VIAS + via_type );
143 
144  if( previous_via_color != via_color )
145  {
146  previous_via_color = via_color;
147  change = true;
148  }
149 
150  background_color = Settings().Colors().GetItemColor( LAYER_PCB_BACKGROUND );
151 
152  if( previous_background_color != background_color )
153  {
154  previous_background_color = background_color;
155  change = true;
156  }
157 
158  if( !change && LayerPairBitmap )
159  return;
160 
161  LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
162 
163  /* Draw the icon, with colors according to the active layer and layer
164  * pairs for via command (change layer)
165  */
166  wxMemoryDC iconDC;
167  iconDC.SelectObject( *LayerPairBitmap );
168  wxBrush brush;
169  wxPen pen;
170  int buttonColor = -1;
171 
172  brush.SetStyle( wxBRUSHSTYLE_SOLID );
173  brush.SetColour( background_color.WithAlpha(1.0).ToColour() );
174  iconDC.SetBrush( brush );
175  iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
176 
177  for( ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
178  {
179  for( jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
180  {
181  if( s_BitmapLayerIcon[ii][jj] != buttonColor )
182  {
183  switch( s_BitmapLayerIcon[ii][jj] )
184  {
185  default:
186  case 0:
187  pen.SetColour( active_layer_color.ToColour() );
188  break;
189 
190  case 1:
191  pen.SetColour( Route_Layer_TOP_color.ToColour() );
192  break;
193 
194  case 2:
195  pen.SetColour( Route_Layer_BOTTOM_color.ToColour() );
196  break;
197 
198  case 3:
199  pen.SetColour( via_color.ToColour() );
200  break;
201  }
202 
203  buttonColor = s_BitmapLayerIcon[ii][jj];
204  iconDC.SetPen( pen );
205  }
206 
207  iconDC.DrawPoint( jj, ii );
208  }
209  }
210 
211  /* Deselect the Tool Bitmap from DC,
212  * in order to delete the MemoryDC safely without deleting the bitmap */
213  iconDC.SelectObject( wxNullBitmap );
214 
215  // Scale the bitmap
216  const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
217  wxImage image = LayerPairBitmap->ConvertToImage();
218 
219  // "NEAREST" causes less mixing of colors
220  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
221  wxIMAGE_QUALITY_NEAREST );
222 
223  LayerPairBitmap = std::make_unique<wxBitmap>( image );
224 
225  if( m_mainToolBar )
226  {
228  m_mainToolBar->Refresh();
229  }
230 }
231 
232 
234 {
235  wxString msg;
236 
237  wxWindowUpdateLocker dummy( this );
238 
239  if( m_mainToolBar )
240  m_mainToolBar->Clear();
241  else
242  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
243  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
244 
245 #define ADD_TOOL( id, xpm, tooltip ) \
246  m_mainToolBar->AddTool( id, wxEmptyString, KiScaledBitmap( xpm, this ), tooltip );
247 
248  // Set up toolbar
249  if( Kiface().IsSingle() )
250  {
251  ADD_TOOL( ID_NEW_BOARD, new_board_xpm, _( "New board" ) );
252  ADD_TOOL( ID_LOAD_FILE, open_brd_file_xpm, _( "Open existing board" ) );
253  }
254 
255  ADD_TOOL( ID_SAVE_BOARD, save_xpm, _( "Save board" ) );
256 
258  ADD_TOOL( ID_BOARD_SETUP_DIALOG, options_board_xpm, _( "Board setup" ) );
259 
261  ADD_TOOL( ID_SHEET_SET, sheetset_xpm, _( "Page settings for paper size and texts" ) );
262  ADD_TOOL( wxID_PRINT, print_button_xpm, _( "Print board" ) );
263  ADD_TOOL( ID_GEN_PLOT, plot_xpm, _( "Plot (HPGL, PostScript, or GERBER format)" ) );
264 
267  ADD_TOOL( wxID_UNDO, undo_xpm, msg );
269  ADD_TOOL( wxID_REDO, redo_xpm, msg );
270 
273  ADD_TOOL( ID_FIND_ITEMS, find_xpm, msg );
274 
277  ADD_TOOL( ID_ZOOM_REDRAW, zoom_redraw_xpm, msg );
279  ADD_TOOL( ID_ZOOM_IN, zoom_in_xpm, msg );
281  ADD_TOOL( ID_ZOOM_OUT, zoom_out_xpm, msg );
283  ADD_TOOL( ID_ZOOM_PAGE, zoom_fit_in_page_xpm, msg );
284 
285  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
286  _( "Zoom to selection" ), wxITEM_CHECK );
287 
289  ADD_TOOL( ID_OPEN_MODULE_EDITOR, module_editor_xpm, _( "Open footprint editor" ) );
290  ADD_TOOL( ID_OPEN_MODULE_VIEWER, modview_icon_xpm, _( "Open footprint viewer" ) );
291 
293  ADD_TOOL( ID_GET_NETLIST, netlist_xpm, _( "Read netlist" ) );
294  ADD_TOOL( ID_UPDATE_PCB_FROM_SCH, update_pcb_from_sch_xpm, _( "Update PCB from schematic" ) );
295  ADD_TOOL( ID_DRC_CONTROL, erc_xpm, _( "Perform design rules check" ) );
296 
298 
299  if( m_SelLayerBox == NULL )
300  {
302  m_SelLayerBox->SetBoardFrame( this );
303  }
304 
305  ReCreateLayerBox( false );
306  m_mainToolBar->AddControl( m_SelLayerBox );
307 
308  PrepareLayerIndicator(); // Initialize the bitmap with the active layer colors
310  SEL_LAYER_HELP );
311 
313  ADD_TOOL( ID_RUN_EESCHEMA, eeschema_xpm, _( "Open schematic in Eeschema" ) );
314 
315  // Access to the scripting console
316 #if defined(KICAD_SCRIPTING_WXPYTHON)
317  if( IsWxPythonLoaded() )
318  {
320 
321  m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
322  KiScaledBitmap( py_script_xpm, this ),
323  _( "Show/Hide the Python Scripting console" ), wxITEM_CHECK );
324 
325 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
326  AddActionPluginTools();
327 #endif
328  }
329 #endif
330 
331  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
332  m_mainToolBar->Realize();
333 
334 #undef ADD_TOOL
335 }
336 
337 
339 {
340  wxWindowUpdateLocker dummy( this );
341 
342  if( m_optionsToolBar )
343  m_optionsToolBar->Clear();
344  else
345  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
346  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
347 
348  m_optionsToolBar->AddTool( ID_TB_OPTIONS_DRC_OFF, wxEmptyString, KiScaledBitmap( drc_off_xpm, this ),
349  _( "Enable design rule checking" ), wxITEM_CHECK );
350  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiScaledBitmap( grid_xpm, this ),
351  _( "Hide grid" ), wxITEM_CHECK );
352  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
353  KiScaledBitmap( polar_coord_xpm, this ),
354  _( "Display polar coordinates" ), wxITEM_CHECK );
355  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
356  KiScaledBitmap( unit_inch_xpm, this ),
357  _( "Set units to inches" ), wxITEM_CHECK );
358  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
359  KiScaledBitmap( unit_mm_xpm, this ),
360  _( "Set units to millimeters" ), wxITEM_CHECK );
361 
362 #ifndef __APPLE__
363  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
364  KiScaledBitmap( cursor_shape_xpm, this ),
365  _( "Change cursor shape" ), wxITEM_CHECK );
366 #else
367  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
368  KiScaledBitmap( cursor_shape_xpm, this ),
369  _( "Change cursor shape (not supported in Legacy Toolset)" ),
370  wxITEM_CHECK );
371 #endif
372 
374  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_RATSNEST, wxEmptyString,
375  KiScaledBitmap( general_ratsnest_xpm, this ),
376  _( "Show board ratsnest" ), wxITEM_CHECK );
377 
379  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES, wxEmptyString, KiScaledBitmap( show_zone_xpm, this ),
380  _( "Show filled areas in zones" ), wxITEM_CHECK );
381  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, wxEmptyString,
382  KiScaledBitmap( show_zone_disable_xpm, this ),
383  _( "Do not show filled areas in zones" ) , wxITEM_CHECK );
385  KiScaledBitmap( show_zone_outline_only_xpm, this ),
386  _( "Show outlines of filled areas only in zones" ), wxITEM_CHECK );
387 
389  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString,
390  KiScaledBitmap( pad_sketch_xpm, this ),
391  _( "Show pads in outline mode" ), wxITEM_CHECK );
392 
393  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_VIAS_SKETCH, wxEmptyString,
394  KiScaledBitmap( via_sketch_xpm, this ),
395  _( "Show vias in outline mode" ), wxITEM_CHECK );
396 
397  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, wxEmptyString,
398  KiScaledBitmap( showtrack_xpm, this ),
399  _( "Show tracks in outline mode" ),
400  wxITEM_CHECK );
401 
403  KiScaledBitmap( contrast_mode_xpm, this ),
404  _( "Enable high contrast display mode" ),
405  wxITEM_CHECK );
406 
407  // Tools to show/hide toolbars:
410  wxEmptyString,
411  KiScaledBitmap( layers_manager_xpm, this ),
413  wxITEM_CHECK );
415  wxEmptyString,
416  KiScaledBitmap( mw_toolbar_xpm, this ),
418  wxITEM_CHECK );
419 
420 
422  m_optionsToolBar->Realize();
423 }
424 
425 
427 {
428  wxWindowUpdateLocker dummy( this );
429 
430  if( m_drawToolBar )
431  m_drawToolBar->Clear();
432  else
433  m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
434  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
435 
436  // Set up toolbar
437  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
438  wxEmptyString, wxITEM_CHECK );
439 
441 
442  m_drawToolBar->AddTool( ID_PCB_HIGHLIGHT_BUTT, wxEmptyString, KiScaledBitmap( net_highlight_xpm, this ),
443  _( "Highlight net" ), wxITEM_CHECK );
444 
445  m_drawToolBar->AddTool( ID_PCB_SHOW_1_RATSNEST_BUTT, wxEmptyString,
446  KiScaledBitmap( tool_ratsnest_xpm, this ),
447  _( "Display local ratsnest" ), wxITEM_CHECK );
448 
450  m_drawToolBar->AddTool( ID_PCB_MODULE_BUTT, wxEmptyString, KiScaledBitmap( module_xpm, this ),
451  _( "Add footprints" ), wxITEM_CHECK );
452 
453  m_drawToolBar->AddTool( ID_TRACK_BUTT, wxEmptyString, KiScaledBitmap( add_tracks_xpm, this ),
454  _( "Route tracks" ), wxITEM_CHECK );
455 
456  m_drawToolBar->AddTool( ID_PCB_DRAW_VIA_BUTT, wxEmptyString, KiScaledBitmap( add_via_xpm, this ),
457  _( "Add vias" ), wxITEM_CHECK );
458 
459  m_drawToolBar->AddTool( ID_PCB_ZONES_BUTT, wxEmptyString, KiScaledBitmap( add_zone_xpm, this ),
460  _( "Add filled zones" ), wxITEM_CHECK );
461 
462  m_drawToolBar->AddTool( ID_PCB_KEEPOUT_AREA_BUTT, wxEmptyString,
463  KiScaledBitmap( add_keepout_area_xpm, this ),
464  _( "Add keepout areas" ), wxITEM_CHECK );
465 
467 
468  m_drawToolBar->AddTool( ID_PCB_ADD_LINE_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_segments_xpm, this ),
469  _( "Add graphic lines" ), wxITEM_CHECK );
470 
471  m_drawToolBar->AddTool( ID_PCB_CIRCLE_BUTT, wxEmptyString, KiScaledBitmap( add_circle_xpm, this ),
472  _( "Add graphic circle" ), wxITEM_CHECK );
473 
474  m_drawToolBar->AddTool( ID_PCB_ARC_BUTT, wxEmptyString, KiScaledBitmap( add_arc_xpm, this ),
475  _( "Add graphic arc" ), wxITEM_CHECK );
476 
477  m_drawToolBar->AddTool( ID_PCB_ADD_POLYGON_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_polygon_xpm, this ),
478  _( "Add graphic polygon" ), wxITEM_CHECK );
479 
480  m_drawToolBar->AddTool( ID_PCB_ADD_TEXT_BUTT, wxEmptyString, KiScaledBitmap( text_xpm, this ),
481  _( "Add text on copper layers or graphic text" ), wxITEM_CHECK );
482 
484  m_drawToolBar->AddTool( ID_PCB_DIMENSION_BUTT, wxEmptyString, KiScaledBitmap( add_dimension_xpm, this ),
485  _( "Add dimension" ), wxITEM_CHECK );
486 
487  m_drawToolBar->AddTool( ID_PCB_TARGET_BUTT, wxEmptyString, KiScaledBitmap( add_pcb_target_xpm, this ),
488  _( "Add layer alignment target" ), wxITEM_CHECK );
489 
491  m_drawToolBar->AddTool( ID_PCB_DELETE_ITEM_BUTT, wxEmptyString, KiScaledBitmap( delete_xpm, this ),
492  _( "Delete items" ), wxITEM_CHECK );
493 
495  m_drawToolBar->AddTool( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxEmptyString,
496  KiScaledBitmap( pcb_offset_xpm, this ),
497  _( "Place the auxiliary axis origin for some plot file formats,\n"
498  "and for drill and place files" ),
499  wxITEM_CHECK );
500 
501  m_drawToolBar->AddTool( ID_PCB_PLACE_GRID_COORD_BUTT, wxEmptyString,
502  KiScaledBitmap( grid_select_axis_xpm, this ),
503  _( "Set the origin point for the grid" ),
504  wxITEM_CHECK );
505 
506  m_drawToolBar->AddTool( ID_PCB_MEASUREMENT_TOOL, wxEmptyString,
507  KiScaledBitmap( measurement_xpm, this ),
508  _( "Measure distance" ),
509  wxITEM_CHECK );
510 
511  m_drawToolBar->Realize();
512 }
513 
514 
515 /* Create the auxiliary vertical right toolbar, showing tools for microwave applications
516  */
518 {
519  wxWindowUpdateLocker dummy(this);
520 
521  if( m_microWaveToolBar )
522  m_microWaveToolBar->Clear();
523  else
524  m_microWaveToolBar = new wxAuiToolBar( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition,
525  wxDefaultSize,
526  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
527 
528  // Set up toolbar
529  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString,
530  KiScaledBitmap( mw_add_line_xpm, this ),
531  _( "Create line of specified length for microwave applications" ),
532  wxITEM_CHECK );
533 
534  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString,
535  KiScaledBitmap( mw_add_gap_xpm, this ),
536  _( "Create gap of specified length for microwave applications" ),
537  wxITEM_CHECK );
538 
540 
541  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString,
542  KiScaledBitmap( mw_add_stub_xpm, this ),
543  _( "Create stub of specified length for microwave applications" ),
544  wxITEM_CHECK );
545 
546  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString,
547  KiScaledBitmap( mw_add_stub_arc_xpm, this ),
548  _( "Create stub (arc) of specified length for microwave applications" ),
549  wxITEM_CHECK );
550 
552  KiScaledBitmap( mw_add_shape_xpm, this ),
553  _( "Create a polynomial shape for microwave applications" ),
554  wxITEM_CHECK );
555 
556  m_microWaveToolBar->Realize();
557 }
558 
559 
561 {
562  wxWindowUpdateLocker dummy( this );
563 
564  if( m_auxiliaryToolBar )
565  {
568 
569  // combobox sizes can have changed: apply new best sizes
570  wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
571  item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
573  item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
574 
575  m_auxiliaryToolBar->Realize();
576  m_auimgr.Update();
577  return;
578  }
579 
580  m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
581  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
582 
583  /* Set up toolbar items */
584 
585  // Creates box to display and choose tracks widths:
586  m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar,
588  wxDefaultPosition, wxDefaultSize,
589  0, NULL );
591  m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
592 
593  // Creates box to display and choose vias diameters:
594  m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar,
596  wxDefaultPosition, wxDefaultSize,
597  0, NULL );
599  m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
601 
602  // Creates box to display and choose strategy to handle tracks an vias sizes:
604  wxEmptyString,
605  KiScaledBitmap( auto_track_width_xpm, this ),
606  _( "Auto track width: when starting on an existing track "
607  "use its width\notherwise, use current width setting" ),
608  wxITEM_CHECK );
609 
610  // Add the box to display and select the current grid size:
612  m_gridSelectBox = new wxChoice( m_auxiliaryToolBar,
614  wxDefaultPosition, wxDefaultSize,
615  0, NULL );
617  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
618 
619  // Add the box to display and select the current Zoom
621  m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar,
623  wxDefaultPosition, wxDefaultSize,
624  0, NULL );
626  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
627 
628  // after adding the buttons to the toolbar, must call Realize()
629  m_auxiliaryToolBar->Realize();
630 }
631 
632 
633 void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox )
634 {
635  if( aTrackWidthSelectBox == NULL )
636  return;
637 
638  wxString msg;
639  bool mmFirst = GetUserUnits() != INCHES;
640 
641  aTrackWidthSelectBox->Clear();
642 
643  for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
644  {
645  int size = GetDesignSettings().m_TrackWidthList[ii];
646 
647  double valueMils = To_User_Unit( INCHES, size ) * 1000;
648  double value_mm = To_User_Unit( MILLIMETRES, size );
649 
650  if( mmFirst )
651  msg.Printf( _( "Track: %.3f mm (%.2f mils)" ),
652  value_mm, valueMils );
653  else
654  msg.Printf( _( "Track: %.2f mils (%.3f mm)" ),
655  valueMils, value_mm );
656 
657  // Mark the netclass track width value (the first in list)
658  if( ii == 0 )
659  msg << wxT( " *" );
660 
661  aTrackWidthSelectBox->Append( msg );
662  }
663 
664  aTrackWidthSelectBox->Append( wxT( "---" ) );
665  aTrackWidthSelectBox->Append( _( "Edit pre-defined sizes..." ) );
666 
667  if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
669 
670  aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
671 }
672 
673 
674 void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox )
675 {
676  if( aViaSizeSelectBox == NULL )
677  return;
678 
679  aViaSizeSelectBox->Clear();
680 
681  bool mmFirst = GetUserUnits() != INCHES;
682 
683  for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
684  {
686  wxString msg, mmStr, milsStr;
687 
688  double diam = To_User_Unit( MILLIMETRES, viaDimension.m_Diameter );
689  double hole = To_User_Unit( MILLIMETRES, viaDimension.m_Drill );
690 
691  if( hole > 0 )
692  mmStr.Printf( _( "%.2f / %.2f mm" ), diam, hole );
693  else
694  mmStr.Printf( _( "%.2f mm" ), diam );
695 
696  diam = To_User_Unit( INCHES, viaDimension.m_Diameter ) * 1000;
697  hole = To_User_Unit( INCHES, viaDimension.m_Drill ) * 1000;
698 
699  if( hole > 0 )
700  milsStr.Printf( _( "%.1f / %.1f mils" ), diam, hole );
701  else
702  milsStr.Printf( _( "%.1f mils" ), diam );
703 
704  msg.Printf( _( "Via: %s (%s)" ), mmFirst ? mmStr : milsStr, mmFirst ? milsStr : mmStr );
705 
706  // Mark the netclass via size value (the first in list)
707  if( ii == 0 )
708  msg << wxT( " *" );
709 
710  aViaSizeSelectBox->Append( msg );
711  }
712 
713  aViaSizeSelectBox->Append( wxT( "---" ) );
714  aViaSizeSelectBox->Append( _( "Edit pre-defined sizes..." ) );
715 
716  if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
718 
719  aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
720 }
721 
722 
723 void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
724 {
725  if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
726  return;
727 
728  m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
731 
732  if( aForceResizeToolbar )
733  {
734  // the layer box can have its size changed
735  // Update the aui manager, to take in account the new size
736  m_auimgr.Update();
737  }
738 }
739 
740 
741 void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
742 {
743  int id = event.GetId();
744  bool state = event.IsChecked();
745  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
746 
747  switch( id )
748  {
750  Settings().m_legacyDrcOn = !state;
751 
752  if( GetToolId() == ID_TRACK_BUTT )
753  {
754  if( Settings().m_legacyDrcOn )
755  m_canvas->SetCursor( wxCURSOR_PENCIL );
756  else
757  m_canvas->SetCursor( wxCURSOR_QUESTION_ARROW );
758  }
759  break;
760 
764  Compile_Ratsnest( NULL, true );
765 
766  if( IsGalCanvasActive() )
767  {
768  // keep the ratsnest layer enabled in view, so it shows up when an item is dragged
769  auto view = GetGalCanvas()->GetView();
771  view->SetLayerVisible( LAYER_RATSNEST, true );
772  }
773 
774  m_canvas->Refresh();
775  break;
776 
778  displ_opts->m_DisplayZonesMode = 0;
779  m_canvas->Refresh();
780  break;
781 
783  displ_opts->m_DisplayZonesMode = 1;
784  m_canvas->Refresh();
785  break;
786 
788  displ_opts->m_DisplayZonesMode = 2;
789  m_canvas->Refresh();
790  break;
791 
793  displ_opts->m_DisplayViaFill = !state;
794  m_canvas->Refresh();
795  break;
796 
798  displ_opts->m_DisplayPcbTrackFill = !state;
799  m_canvas->Refresh();
800  break;
801 
803  {
804  displ_opts->m_ContrastModeDisplay = state;
805  m_canvas->Refresh();
806  break;
807  }
808 
810  m_show_microwave_tools = state;
811  m_auimgr.GetPane( "MicrowaveToolbar" ).Show( m_show_microwave_tools );
812  m_auimgr.Update();
813  break;
814 
816  // show auxiliary Vertical layers and visibility manager toolbar
818  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
819  m_auimgr.Update();
820  break;
821 
822  default:
823  DisplayErrorMessage( this, "Invalid toolbar option",
824  "PCB_EDIT_FRAME::OnSelectOptionToolbar error \n (event not handled!)" );
825  break;
826  }
827 }
Struct VIA_DIMENSION is a small helper container to handle a stock of specific vias each with unique ...
void UpdateTrackWidthSelectBox(wxChoice *aTrackWidthSelectBox)
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)
#define BM_LAYERICON_SIZE
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
void PrepareLayerIndicator()
This file is part of the common library.
#define HELP_SHOW_HIDE_MICROWAVE_TOOLS
std::vector< int > m_TrackWidthList
EDA_HOTKEY_CONFIG * m_hotkeys
#define ADD_TOOL(id, xpm, tooltip)
#define HELP_ZOOM_FIT
void ReCreateMicrowaveVToolbar()
Class BOARD to handle a board.
wxChoice * m_SelViaSizeBox
Definition: id.h:241
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 ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building le new one, from the new layers names ...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
Class to display a pcb layer list in a wxBitmapComboBox.
wxAuiManager m_auimgr
bool m_show_microwave_tools
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void ReCreateHToolbar() override
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
#define SEL_LAYER_HELP
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
bool IsWxPythonLoaded()
wxChoice * m_SelTrackWidthBox
wxChoice * m_gridSelectBox
Definition: draw_frame.h:148
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
#define HELP_ZOOM_OUT
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:42
bool m_show_layer_manager_tools
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
#define HELP_ZOOM_REDRAW
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
wxAuiToolBar * m_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window...
Definition: draw_frame.h:153
wxAuiToolBar * m_microWaveToolBar
The auxiliary right vertical tool bar used to access the microwave tools.
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:160
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
void OnSelectOptionToolbar(wxCommandEvent &event)
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
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:284
Definition: common.h:160
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:149
void ReCreateVToolbar() override
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:233
Helper dialog and control classes.
struct EDA_HOTKEY_CONFIG g_Board_Editor_Hotkeys_Descr[]
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:921
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
#define ICON_SCALE_KEY
Definition: pgm_base.h:45
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:157
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
COLORS_DESIGN_SETTINGS & Colors()
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:53
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
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
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...
#define HELP_ZOOM_IN
#define HELP_SHOW_HIDE_LAYERMANAGER
int GetToolId() const
Definition: draw_frame.h:519
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
void ReCreateOptToolbar() override
#define HELP_UNDO
These strings are used in menus and tools, that do the same command But they are internationalized, and therefore must be created at run time, on the fly.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
static std::unique_ptr< wxBitmap > LayerPairBitmap
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
void UpdateViaSizeSelectBox(wxChoice *aViaSizeSelectBox)
Definition: id.h:97
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
static const char * text_xpm[]
static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE]
PCB_LAYER_BOX_SELECTOR * m_SelLayerBox
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
strings common to toolbars and menubar
#define HELP_FIND
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void ReCreateAuxiliaryToolbar() override
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39