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 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 
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  // Note:
236  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
237  // all wxAuiToolBarItems.
238  // However the wxAuiToolBarItems are not the owners of controls managed by
239  // them and therefore do not delete them
240  // So we do not recreate them after clearing the tools.
241 
242  wxString msg;
243 
244  wxWindowUpdateLocker dummy( this );
245 
246  if( m_mainToolBar )
247  m_mainToolBar->Clear();
248  else
249  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
250  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
251 
252 #define ADD_TOOL( id, xpm, tooltip ) \
253  m_mainToolBar->AddTool( id, wxEmptyString, KiScaledBitmap( xpm, this ), tooltip );
254 
255  // Set up toolbar
256  if( Kiface().IsSingle() )
257  {
258  ADD_TOOL( ID_NEW_BOARD, new_board_xpm, _( "New board" ) );
259  ADD_TOOL( ID_LOAD_FILE, open_brd_file_xpm, _( "Open existing board" ) );
260  }
261 
262  ADD_TOOL( ID_SAVE_BOARD, save_xpm, _( "Save board" ) );
263 
265  ADD_TOOL( ID_BOARD_SETUP_DIALOG, options_board_xpm, _( "Board setup" ) );
266 
268  ADD_TOOL( ID_SHEET_SET, sheetset_xpm, _( "Page settings for paper size and texts" ) );
269  ADD_TOOL( wxID_PRINT, print_button_xpm, _( "Print board" ) );
270  ADD_TOOL( ID_GEN_PLOT, plot_xpm, _( "Plot (HPGL, PostScript, or GERBER format)" ) );
271 
274  ADD_TOOL( wxID_UNDO, undo_xpm, msg );
276  ADD_TOOL( wxID_REDO, redo_xpm, msg );
277 
280  ADD_TOOL( ID_FIND_ITEMS, find_xpm, msg );
281 
284  ADD_TOOL( ID_ZOOM_REDRAW, zoom_redraw_xpm, msg );
286  ADD_TOOL( ID_ZOOM_IN, zoom_in_xpm, msg );
288  ADD_TOOL( ID_ZOOM_OUT, zoom_out_xpm, msg );
290  ADD_TOOL( ID_ZOOM_PAGE, zoom_fit_in_page_xpm, msg );
291 
292  m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
293  _( "Zoom to selection" ), wxITEM_CHECK );
294 
296  ADD_TOOL( ID_OPEN_MODULE_EDITOR, module_editor_xpm, _( "Open footprint editor" ) );
297  ADD_TOOL( ID_OPEN_MODULE_VIEWER, modview_icon_xpm, _( "Open footprint viewer" ) );
298 
300  ADD_TOOL( ID_GET_NETLIST, netlist_xpm, _( "Load netlist" ) );
301  ADD_TOOL( ID_UPDATE_PCB_FROM_SCH, update_pcb_from_sch_xpm, _( "Update PCB from schematic" ) );
302  ADD_TOOL( ID_DRC_CONTROL, erc_xpm, _( "Perform design rules check" ) );
303 
305 
306  if( m_SelLayerBox == nullptr )
307  {
309  m_SelLayerBox->SetBoardFrame( this );
310  }
311 
312  ReCreateLayerBox( false );
313  m_mainToolBar->AddControl( m_SelLayerBox );
314 
315  PrepareLayerIndicator(); // Initialize the bitmap with the active layer colors
317  SEL_LAYER_HELP );
318 
320  ADD_TOOL( ID_RUN_EESCHEMA, eeschema_xpm, _( "Open schematic in Eeschema" ) );
321 
322  // Access to the scripting console
323 #if defined(KICAD_SCRIPTING_WXPYTHON)
324  if( IsWxPythonLoaded() )
325  {
327 
328  m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
329  KiScaledBitmap( py_script_xpm, this ),
330  _( "Show/Hide the Python Scripting console" ), wxITEM_CHECK );
331 
332 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
333  AddActionPluginTools();
334 #endif
335  }
336 #endif
337 
338  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
339  m_mainToolBar->Realize();
340 
341 #undef ADD_TOOL
342 }
343 
344 
346 {
347  // Note:
348  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
349  // all wxAuiToolBarItems.
350  // However the wxAuiToolBarItems are not the owners of controls managed by
351  // them and therefore do not delete them
352  // So we do not recreate them after clearing the tools.
353 
354  wxWindowUpdateLocker dummy( this );
355 
356  if( m_optionsToolBar )
357  m_optionsToolBar->Clear();
358  else
359  m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
360  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
361 
362  m_optionsToolBar->AddTool( ID_TB_OPTIONS_DRC_OFF, wxEmptyString, KiScaledBitmap( drc_off_xpm, this ),
363  _( "Enable design rule checking" ), wxITEM_CHECK );
364  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiScaledBitmap( grid_xpm, this ),
365  _( "Hide grid" ), wxITEM_CHECK );
366  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
367  KiScaledBitmap( polar_coord_xpm, this ),
368  _( "Display polar coordinates" ), wxITEM_CHECK );
369  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
370  KiScaledBitmap( unit_inch_xpm, this ),
371  _( "Set units to inches" ), wxITEM_CHECK );
372  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
373  KiScaledBitmap( unit_mm_xpm, this ),
374  _( "Set units to millimeters" ), wxITEM_CHECK );
375 
376 #ifndef __APPLE__
377  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
378  KiScaledBitmap( cursor_shape_xpm, this ),
379  _( "Change cursor shape" ), wxITEM_CHECK );
380 #else
381  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
382  KiScaledBitmap( cursor_shape_xpm, this ),
383  _( "Change cursor shape (not supported in Legacy Toolset)" ),
384  wxITEM_CHECK );
385 #endif
386 
388  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_RATSNEST, wxEmptyString,
389  KiScaledBitmap( general_ratsnest_xpm, this ),
390  _( "Show board ratsnest" ), wxITEM_CHECK );
391 
393  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES, wxEmptyString, KiScaledBitmap( show_zone_xpm, this ),
394  _( "Show filled areas in zones" ), wxITEM_CHECK );
395  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, wxEmptyString,
396  KiScaledBitmap( show_zone_disable_xpm, this ),
397  _( "Do not show filled areas in zones" ) , wxITEM_CHECK );
399  KiScaledBitmap( show_zone_outline_only_xpm, this ),
400  _( "Show outlines of filled areas only in zones" ), wxITEM_CHECK );
401 
403  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString,
404  KiScaledBitmap( pad_sketch_xpm, this ),
405  _( "Show pads in outline mode" ), wxITEM_CHECK );
406 
407  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_VIAS_SKETCH, wxEmptyString,
408  KiScaledBitmap( via_sketch_xpm, this ),
409  _( "Show vias in outline mode" ), wxITEM_CHECK );
410 
411  m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, wxEmptyString,
412  KiScaledBitmap( showtrack_xpm, this ),
413  _( "Show tracks in outline mode" ),
414  wxITEM_CHECK );
415 
417  KiScaledBitmap( contrast_mode_xpm, this ),
418  _( "Enable high contrast display mode" ),
419  wxITEM_CHECK );
420 
421  // Tools to show/hide toolbars:
424  wxEmptyString,
425  KiScaledBitmap( layers_manager_xpm, this ),
427  wxITEM_CHECK );
429  wxEmptyString,
430  KiScaledBitmap( mw_toolbar_xpm, this ),
432  wxITEM_CHECK );
433 
434 
436  m_optionsToolBar->Realize();
437 }
438 
439 
441 {
442  wxWindowUpdateLocker dummy( this );
443 
444  if( m_drawToolBar )
445  m_drawToolBar->Clear();
446  else
447  m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
448  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
449 
450  // Set up toolbar
451  m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
452  _( "Select item" ), wxITEM_CHECK );
453 
455 
456  m_drawToolBar->AddTool( ID_PCB_HIGHLIGHT_BUTT, wxEmptyString, KiScaledBitmap( net_highlight_xpm, this ),
457  _( "Highlight net" ), wxITEM_CHECK );
458 
459  m_drawToolBar->AddTool( ID_PCB_SHOW_1_RATSNEST_BUTT, wxEmptyString,
460  KiScaledBitmap( tool_ratsnest_xpm, this ),
461  _( "Display local ratsnest" ), wxITEM_CHECK );
462 
464  m_drawToolBar->AddTool( ID_PCB_MODULE_BUTT, wxEmptyString, KiScaledBitmap( module_xpm, this ),
465  _( "Add footprints" ), wxITEM_CHECK );
466 
467  m_drawToolBar->AddTool( ID_TRACK_BUTT, wxEmptyString, KiScaledBitmap( add_tracks_xpm, this ),
468  _( "Route tracks" ), wxITEM_CHECK );
469 
470  m_drawToolBar->AddTool( ID_PCB_DRAW_VIA_BUTT, wxEmptyString, KiScaledBitmap( add_via_xpm, this ),
471  _( "Add vias" ), wxITEM_CHECK );
472 
473  m_drawToolBar->AddTool( ID_PCB_ZONES_BUTT, wxEmptyString, KiScaledBitmap( add_zone_xpm, this ),
474  _( "Add filled zones" ), wxITEM_CHECK );
475 
476  m_drawToolBar->AddTool( ID_PCB_KEEPOUT_AREA_BUTT, wxEmptyString,
477  KiScaledBitmap( add_keepout_area_xpm, this ),
478  _( "Add keepout areas" ), wxITEM_CHECK );
479 
481 
482  m_drawToolBar->AddTool( ID_PCB_ADD_LINE_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_segments_xpm, this ),
483  _( "Add graphic lines" ), wxITEM_CHECK );
484 
485  m_drawToolBar->AddTool( ID_PCB_CIRCLE_BUTT, wxEmptyString, KiScaledBitmap( add_circle_xpm, this ),
486  _( "Add graphic circle" ), wxITEM_CHECK );
487 
488  m_drawToolBar->AddTool( ID_PCB_ARC_BUTT, wxEmptyString, KiScaledBitmap( add_arc_xpm, this ),
489  _( "Add graphic arc" ), wxITEM_CHECK );
490 
491  m_drawToolBar->AddTool( ID_PCB_ADD_POLYGON_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_polygon_xpm, this ),
492  _( "Add graphic polygon" ), wxITEM_CHECK );
493 
494  m_drawToolBar->AddTool( ID_PCB_ADD_TEXT_BUTT, wxEmptyString, KiScaledBitmap( text_xpm, this ),
495  _( "Add text on copper layers or graphic text" ), wxITEM_CHECK );
496 
498  m_drawToolBar->AddTool( ID_PCB_DIMENSION_BUTT, wxEmptyString, KiScaledBitmap( add_dimension_xpm, this ),
499  _( "Add dimension" ), wxITEM_CHECK );
500 
501  m_drawToolBar->AddTool( ID_PCB_TARGET_BUTT, wxEmptyString, KiScaledBitmap( add_pcb_target_xpm, this ),
502  _( "Add layer alignment target" ), wxITEM_CHECK );
503 
505  m_drawToolBar->AddTool( ID_PCB_DELETE_ITEM_BUTT, wxEmptyString, KiScaledBitmap( delete_xpm, this ),
506  _( "Delete items" ), wxITEM_CHECK );
507 
509  m_drawToolBar->AddTool( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxEmptyString,
510  KiScaledBitmap( pcb_offset_xpm, this ),
511  _( "Place the auxiliary axis origin for some plot file formats,\n"
512  "and for drill and place files" ),
513  wxITEM_CHECK );
514 
515  m_drawToolBar->AddTool( ID_PCB_PLACE_GRID_COORD_BUTT, wxEmptyString,
516  KiScaledBitmap( grid_select_axis_xpm, this ),
517  _( "Set the origin point for the grid" ),
518  wxITEM_CHECK );
519 
520  m_drawToolBar->AddTool( ID_PCB_MEASUREMENT_TOOL, wxEmptyString,
521  KiScaledBitmap( measurement_xpm, this ),
522  _( "Measure distance" ),
523  wxITEM_CHECK );
524 
525  m_drawToolBar->Realize();
526 }
527 
528 
529 /* Create the auxiliary vertical right toolbar, showing tools for microwave applications
530  */
532 {
533  wxWindowUpdateLocker dummy(this);
534 
535  if( m_microWaveToolBar )
536  m_microWaveToolBar->Clear();
537  else
538  m_microWaveToolBar = new wxAuiToolBar( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition,
539  wxDefaultSize,
540  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
541 
542  // Set up toolbar
543  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString,
544  KiScaledBitmap( mw_add_line_xpm, this ),
545  _( "Create line of specified length for microwave applications" ),
546  wxITEM_CHECK );
547 
548  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString,
549  KiScaledBitmap( mw_add_gap_xpm, this ),
550  _( "Create gap of specified length for microwave applications" ),
551  wxITEM_CHECK );
552 
554 
555  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString,
556  KiScaledBitmap( mw_add_stub_xpm, this ),
557  _( "Create stub of specified length for microwave applications" ),
558  wxITEM_CHECK );
559 
560  m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString,
561  KiScaledBitmap( mw_add_stub_arc_xpm, this ),
562  _( "Create stub (arc) of specified length for microwave applications" ),
563  wxITEM_CHECK );
564 
566  KiScaledBitmap( mw_add_shape_xpm, this ),
567  _( "Create a polynomial shape for microwave applications" ),
568  wxITEM_CHECK );
569 
570  m_microWaveToolBar->Realize();
571 }
572 
573 
575 {
576  wxWindowUpdateLocker dummy( this );
577 
578  if( m_auxiliaryToolBar )
579  {
582 
583  // combobox sizes can have changed: apply new best sizes
584  wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
585  item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
587  item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
588 
589  m_auxiliaryToolBar->Realize();
590  m_auimgr.Update();
591  return;
592  }
593 
594  m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
595  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
596 
597  /* Set up toolbar items */
598 
599  // Creates box to display and choose tracks widths:
600  if( m_SelTrackWidthBox == nullptr )
601  m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar,
603  wxDefaultPosition, wxDefaultSize,
604  0, NULL );
605 
607  m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
608 
609  // Creates box to display and choose vias diameters:
610 
611  if( m_SelViaSizeBox == nullptr )
612  m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar,
614  wxDefaultPosition, wxDefaultSize,
615  0, NULL );
616 
618  m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
620 
621  // Creates box to display and choose strategy to handle tracks an vias sizes:
623  wxEmptyString,
624  KiScaledBitmap( auto_track_width_xpm, this ),
625  _( "Auto track width: when starting on an existing track "
626  "use its width\notherwise, use current width setting" ),
627  wxITEM_CHECK );
628 
629  // Add the box to display and select the current grid size:
631 
632  if( m_gridSelectBox == nullptr )
633  m_gridSelectBox = new wxChoice( m_auxiliaryToolBar,
635  wxDefaultPosition, wxDefaultSize,
636  0, NULL );
637 
639 
640  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
641 
642  // Add the box to display and select the current Zoom
644 
645  if( m_zoomSelectBox == nullptr )
646  m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar,
648  wxDefaultPosition, wxDefaultSize,
649  0, NULL );
650 
652  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
653 
654  // after adding the buttons to the toolbar, must call Realize()
655  m_auxiliaryToolBar->Realize();
656 }
657 
658 
659 void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, const bool aEdit )
660 {
661  if( aTrackWidthSelectBox == NULL )
662  return;
663 
664  wxString msg;
665  bool mmFirst = GetUserUnits() != INCHES;
666 
667  aTrackWidthSelectBox->Clear();
668 
669  for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
670  {
671  int size = GetDesignSettings().m_TrackWidthList[ii];
672 
673  double valueMils = To_User_Unit( INCHES, size ) * 1000;
674  double value_mm = To_User_Unit( MILLIMETRES, size );
675 
676  if( mmFirst )
677  msg.Printf( _( "Track: %.3f mm (%.2f mils)" ),
678  value_mm, valueMils );
679  else
680  msg.Printf( _( "Track: %.2f mils (%.3f mm)" ),
681  valueMils, value_mm );
682 
683  // Mark the netclass track width value (the first in list)
684  if( ii == 0 )
685  msg << wxT( " *" );
686 
687  aTrackWidthSelectBox->Append( msg );
688  }
689 
690  if( aEdit )
691  {
692  aTrackWidthSelectBox->Append( wxT( "---" ) );
693  aTrackWidthSelectBox->Append( _( "Edit pre-defined sizes..." ) );
694  }
695 
696  if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
698 
699  aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
700 }
701 
702 
703 void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, const bool aEdit )
704 {
705  if( aViaSizeSelectBox == NULL )
706  return;
707 
708  aViaSizeSelectBox->Clear();
709 
710  bool mmFirst = GetUserUnits() != INCHES;
711 
712  for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
713  {
715  wxString msg, mmStr, milsStr;
716 
717  double diam = To_User_Unit( MILLIMETRES, viaDimension.m_Diameter );
718  double hole = To_User_Unit( MILLIMETRES, viaDimension.m_Drill );
719 
720  if( hole > 0 )
721  mmStr.Printf( _( "%.2f / %.2f mm" ), diam, hole );
722  else
723  mmStr.Printf( _( "%.2f mm" ), diam );
724 
725  diam = To_User_Unit( INCHES, viaDimension.m_Diameter ) * 1000;
726  hole = To_User_Unit( INCHES, viaDimension.m_Drill ) * 1000;
727 
728  if( hole > 0 )
729  milsStr.Printf( _( "%.1f / %.1f mils" ), diam, hole );
730  else
731  milsStr.Printf( _( "%.1f mils" ), diam );
732 
733  msg.Printf( _( "Via: %s (%s)" ), mmFirst ? mmStr : milsStr, mmFirst ? milsStr : mmStr );
734 
735  // Mark the netclass via size value (the first in list)
736  if( ii == 0 )
737  msg << wxT( " *" );
738 
739  aViaSizeSelectBox->Append( msg );
740  }
741 
742  if( aEdit )
743  {
744  aViaSizeSelectBox->Append( wxT( "---" ) );
745  aViaSizeSelectBox->Append( _( "Edit pre-defined sizes..." ) );
746  }
747 
748  if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
750 
751  aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
752 }
753 
754 
755 void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
756 {
757  if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
758  return;
759 
760  m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
763 
764  if( aForceResizeToolbar )
765  {
766  // the layer box can have its size changed
767  // Update the aui manager, to take in account the new size
768  m_auimgr.Update();
769  }
770 }
771 
772 
773 void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
774 {
775  int id = event.GetId();
776  bool state = event.IsChecked();
777  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
778 
779  switch( id )
780  {
782  Settings().m_legacyDrcOn = !state;
783 
784  if( GetToolId() == ID_TRACK_BUTT )
785  {
786  if( Settings().m_legacyDrcOn )
787  m_canvas->SetCursor( wxCURSOR_PENCIL );
788  else
789  m_canvas->SetCursor( wxCURSOR_QUESTION_ARROW );
790  }
791  break;
792 
796  Compile_Ratsnest( NULL, true );
797 
798  if( IsGalCanvasActive() )
799  {
800  // keep the ratsnest layer enabled in view, so it shows up when an item is dragged
801  auto view = GetGalCanvas()->GetView();
803  view->SetLayerVisible( LAYER_RATSNEST, true );
804  }
805 
806  m_canvas->Refresh();
807  break;
808 
810  displ_opts->m_DisplayZonesMode = 0;
811  m_canvas->Refresh();
812  break;
813 
815  displ_opts->m_DisplayZonesMode = 1;
816  m_canvas->Refresh();
817  break;
818 
820  displ_opts->m_DisplayZonesMode = 2;
821  m_canvas->Refresh();
822  break;
823 
825  displ_opts->m_DisplayViaFill = !state;
826  m_canvas->Refresh();
827  break;
828 
830  displ_opts->m_DisplayPcbTrackFill = !state;
831  m_canvas->Refresh();
832  break;
833 
835  {
836  displ_opts->m_ContrastModeDisplay = state;
837  m_canvas->Refresh();
838  break;
839  }
840 
842  m_show_microwave_tools = state;
843  m_auimgr.GetPane( "MicrowaveToolbar" ).Show( m_show_microwave_tools );
844  m_auimgr.Update();
845  break;
846 
848  // show auxiliary Vertical layers and visibility manager toolbar
850  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
851  m_auimgr.Update();
852  break;
853 
854  default:
855  DisplayErrorMessage( this, "Invalid toolbar option",
856  "PCB_EDIT_FRAME::OnSelectOptionToolbar error \n (event not handled!)" );
857  break;
858  }
859 }
Struct VIA_DIMENSION is a small helper container to handle a stock of specific vias each with unique ...
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.
#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:257
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.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
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 ...
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
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
#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:151
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:49
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:928
#define HELP_ZOOM_REDRAW
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_auxiliaryToolBar
Auxiliary tool bar typically shown below the main tool bar at the top of the main window.
Definition: draw_frame.h:156
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:163
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
void OnSelectOptionToolbar(wxCommandEvent &event)
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' 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:291
Definition: common.h:161
wxChoice * m_zoomSelectBox
Definition: draw_frame.h:152
void ReCreateVToolbar() override
Helper dialog and control classes.
struct EDA_HOTKEY_CONFIG g_Board_Editor_Hotkeys_Descr[]
#define ICON_SCALE_KEY
Definition: pgm_base.h:46
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:160
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:126
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
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...
#define HELP_ZOOM_IN
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.
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
Definition: id.h:97
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
void ReCreateAuxiliaryToolbar() override
int GetToolId() const
Definition: draw_frame.h:526
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39