You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
12 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file toolbars_gerber.cpp
  27. * @brief Build tool bars
  28. */
  29. #include <fctsys.h>
  30. #include <common.h>
  31. #include <macros.h>
  32. #include <gerbview.h>
  33. #include <gerbview_frame.h>
  34. #include <bitmaps.h>
  35. #include <gerbview_id.h>
  36. #include <hotkeys.h>
  37. #include <class_GERBER.h>
  38. #include <class_gbr_layer_box_selector.h>
  39. #include <class_DCodeSelectionbox.h>
  40. #include <dialog_helpers.h>
  41. void GERBVIEW_FRAME::ReCreateHToolbar( void )
  42. {
  43. int ii;
  44. wxString msg;
  45. if( m_mainToolBar != NULL )
  46. return;
  47. m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  48. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
  49. // Set up toolbar
  50. m_mainToolBar->AddTool( ID_GERBVIEW_ERASE_ALL, wxEmptyString,
  51. KiBitmap( gerbview_clear_layers_xpm ),
  52. _( "Erase all layers" ) );
  53. m_mainToolBar->AddTool( wxID_FILE, wxEmptyString, KiBitmap( gerber_file_xpm ),
  54. _( "Load a new Gerber file on the current layer. Previous data will be deleted" ) );
  55. m_mainToolBar->AddTool( ID_GERBVIEW_LOAD_DRILL_FILE, wxEmptyString,
  56. KiBitmap( gerbview_drill_file_xpm ),
  57. _( "Load an excellon drill file on the current layer. Previous data will be deleted" ) );
  58. m_mainToolBar->AddSeparator();
  59. m_mainToolBar->AddTool( ID_GERBVIEW_SET_PAGE_BORDER, wxEmptyString, KiBitmap( sheetset_xpm ),
  60. _( "Show/hide frame reference and select paper size for printing" ) );
  61. m_mainToolBar->AddSeparator();
  62. m_mainToolBar->AddTool( wxID_PRINT, wxEmptyString, KiBitmap( print_button_xpm ),
  63. _( "Print layers" ) );
  64. m_mainToolBar->AddSeparator();
  65. msg = AddHotkeyName( _( "Zoom in" ), GerbviewHokeysDescr, HK_ZOOM_IN, IS_COMMENT );
  66. m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiBitmap( zoom_in_xpm ), msg );
  67. msg = AddHotkeyName( _( "Zoom out" ), GerbviewHokeysDescr, HK_ZOOM_OUT, IS_COMMENT );
  68. m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiBitmap( zoom_out_xpm ), msg );
  69. msg = AddHotkeyName( _( "Redraw view" ), GerbviewHokeysDescr, HK_ZOOM_REDRAW, IS_COMMENT );
  70. m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiBitmap( zoom_redraw_xpm ), msg );
  71. msg = AddHotkeyName( _( "Zoom auto" ), GerbviewHokeysDescr, HK_ZOOM_AUTO, IS_COMMENT );
  72. m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ), msg );
  73. m_mainToolBar->AddSeparator();
  74. m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( m_mainToolBar,
  75. ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
  76. wxDefaultPosition, wxSize( 150, -1 ), 0,NULL);
  77. m_SelLayerBox->Resync();
  78. m_mainToolBar->AddControl( m_SelLayerBox );
  79. m_mainToolBar->AddSeparator();
  80. m_DCodesList.Alloc(TOOLS_MAX_COUNT+1);
  81. m_DCodesList.Add( _( "No tool" ) );
  82. for( ii = FIRST_DCODE; ii < TOOLS_MAX_COUNT; ii++ )
  83. {
  84. msg = _( "Tool " );
  85. msg << ii;
  86. m_DCodesList.Add( msg );
  87. }
  88. m_DCodeSelector = new DCODE_SELECTION_BOX( m_mainToolBar,
  89. ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
  90. wxDefaultPosition, wxSize( 150, -1 ),
  91. m_DCodesList );
  92. m_mainToolBar->AddControl( m_DCodeSelector );
  93. m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
  94. wxSize(150,-1), wxTE_READONLY );
  95. m_mainToolBar->AddControl( m_TextInfo );
  96. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  97. m_mainToolBar->Realize();
  98. }
  99. void GERBVIEW_FRAME::ReCreateVToolbar( void )
  100. {
  101. if( m_drawToolBar )
  102. return;
  103. m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  104. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
  105. // Set up toolbar
  106. m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiBitmap( cursor_xpm ) );
  107. m_drawToolBar->AddSeparator();
  108. m_drawToolBar->Realize();
  109. }
  110. void GERBVIEW_FRAME::ReCreateOptToolbar( void )
  111. {
  112. if( m_optionsToolBar )
  113. return;
  114. // creation of tool bar options
  115. m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  116. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
  117. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiBitmap( grid_xpm ),
  118. _( "Turn grid off" ), wxITEM_CHECK );
  119. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
  120. KiBitmap( polar_coord_xpm ),
  121. _( "Turn polar coordinate on" ), wxITEM_CHECK );
  122. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
  123. KiBitmap( unit_inch_xpm ),
  124. _( "Set units to inches" ), wxITEM_CHECK );
  125. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
  126. KiBitmap( unit_mm_xpm ),
  127. _( "Set units to millimeters" ), wxITEM_CHECK );
  128. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
  129. KiBitmap( cursor_shape_xpm ),
  130. _( "Change cursor shape" ), wxITEM_CHECK );
  131. m_optionsToolBar->AddSeparator();
  132. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH, wxEmptyString,
  133. KiBitmap( pad_sketch_xpm ),
  134. _( "Show spots in sketch mode" ), wxITEM_CHECK );
  135. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LINES_SKETCH, wxEmptyString,
  136. KiBitmap( showtrack_xpm ),
  137. _( "Show lines in sketch mode" ), wxITEM_CHECK );
  138. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH, wxEmptyString,
  139. KiBitmap( opt_show_polygon_xpm ),
  140. _( "Show polygons in sketch mode" ),
  141. wxITEM_CHECK );
  142. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS, wxEmptyString,
  143. KiBitmap( gerbview_show_negative_objects_xpm ),
  144. _( "Show negatives objects in ghost color" ),
  145. wxITEM_CHECK );
  146. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_DCODES, wxEmptyString,
  147. KiBitmap( show_dcodenumber_xpm ),
  148. _( "Show dcode number" ), wxITEM_CHECK );
  149. // tools to select draw mode in GerbView
  150. m_optionsToolBar->AddSeparator();
  151. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_0, wxEmptyString,
  152. KiBitmap( gbr_select_mode0_xpm ),
  153. _( "Show layers in raw mode \
  154. (could have problems with negative items when more than one gerber file is shown)" ),
  155. wxITEM_CHECK );
  156. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_1, wxEmptyString,
  157. KiBitmap( gbr_select_mode1_xpm ),
  158. _( "Show layers in stacked mode \
  159. (show negative items without artifacts, sometimes slow)" ),
  160. wxITEM_CHECK );
  161. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_2, wxEmptyString,
  162. KiBitmap( gbr_select_mode2_xpm ),
  163. _( "Show layers in transparency mode \
  164. (show negative items without artifacts, sometimes slow)" ),
  165. wxITEM_CHECK );
  166. // Tools to show/hide toolbars:
  167. m_optionsToolBar->AddSeparator();
  168. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
  169. wxEmptyString,
  170. KiBitmap( layers_manager_xpm ),
  171. _( "Show/hide the layers manager toolbar" ),
  172. wxITEM_CHECK );
  173. m_optionsToolBar->Realize();
  174. }
  175. void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
  176. {
  177. switch( aEvent.GetId() )
  178. {
  179. case ID_TB_OPTIONS_SHOW_GBR_MODE_0:
  180. aEvent.Check( GetDisplayMode() == 0 );
  181. break;
  182. case ID_TB_OPTIONS_SHOW_GBR_MODE_1:
  183. aEvent.Check( GetDisplayMode() == 1 );
  184. break;
  185. case ID_TB_OPTIONS_SHOW_GBR_MODE_2:
  186. aEvent.Check( GetDisplayMode() == 2 );
  187. break;
  188. default:
  189. break;
  190. }
  191. }
  192. void GERBVIEW_FRAME::OnUpdateCoordType( wxUpdateUIEvent& aEvent )
  193. {
  194. aEvent.Check( m_DisplayOptions.m_DisplayPolarCood );
  195. }
  196. void GERBVIEW_FRAME::OnUpdateFlashedItemsDrawMode( wxUpdateUIEvent& aEvent )
  197. {
  198. aEvent.Check( !m_DisplayOptions.m_DisplayFlashedItemsFill );
  199. }
  200. void GERBVIEW_FRAME::OnUpdateLinesDrawMode( wxUpdateUIEvent& aEvent )
  201. {
  202. aEvent.Check( !m_DisplayOptions.m_DisplayLinesFill );
  203. }
  204. void GERBVIEW_FRAME::OnUpdatePolygonsDrawMode( wxUpdateUIEvent& aEvent )
  205. {
  206. aEvent.Check( !m_DisplayOptions.m_DisplayPolygonsFill );
  207. }
  208. void GERBVIEW_FRAME::OnUpdateShowDCodes( wxUpdateUIEvent& aEvent )
  209. {
  210. aEvent.Check( IsElementVisible( DCODES_VISIBLE ) );
  211. }
  212. void GERBVIEW_FRAME::OnUpdateShowNegativeItems( wxUpdateUIEvent& aEvent )
  213. {
  214. aEvent.Check( IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
  215. }
  216. void GERBVIEW_FRAME::OnUpdateShowLayerManager( wxUpdateUIEvent& aEvent )
  217. {
  218. aEvent.Check( m_show_layer_manager_tools );
  219. if( m_optionsToolBar )
  220. {
  221. if( m_show_layer_manager_tools )
  222. m_optionsToolBar->SetToolShortHelp( aEvent.GetId(), _("Hide layers manager" ) );
  223. else
  224. m_optionsToolBar->SetToolShortHelp( aEvent.GetId(), _("Show layers manager" ) );
  225. }
  226. }
  227. void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
  228. {
  229. int layer = getActiveLayer();
  230. GERBER_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
  231. int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
  232. if( m_DCodeSelector && m_DCodeSelector->GetSelectedDCodeId() != selected )
  233. m_DCodeSelector->SetDCodeSelection( selected );
  234. aEvent.Enable( gerber != NULL );
  235. }
  236. void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
  237. {
  238. if( m_SelLayerBox && (m_SelLayerBox->GetSelection() != getActiveLayer()) )
  239. {
  240. m_SelLayerBox->SetSelection( getActiveLayer() );
  241. }
  242. }