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.

312 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 <bitmaps.h>
  34. #include <gerbview_id.h>
  35. #include <hotkeys.h>
  36. #include <class_GERBER.h>
  37. #include <class_gbr_layer_box_selector.h>
  38. #include <class_DCodeSelectionbox.h>
  39. #include <dialog_helpers.h>
  40. void GERBVIEW_FRAME::ReCreateHToolbar( void )
  41. {
  42. int ii;
  43. wxString msg;
  44. if( m_mainToolBar != NULL )
  45. return;
  46. m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  47. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
  48. // Set up toolbar
  49. m_mainToolBar->AddTool( ID_GERBVIEW_ERASE_ALL, wxEmptyString,
  50. KiBitmap( gerbview_clear_layers_xpm ),
  51. _( "Erase all layers" ) );
  52. m_mainToolBar->AddTool( wxID_FILE, wxEmptyString, KiBitmap( gerber_file_xpm ),
  53. _( "Load a new Gerber file on the current layer. Previous data will be deleted" ) );
  54. m_mainToolBar->AddTool( ID_GERBVIEW_LOAD_DRILL_FILE, wxEmptyString,
  55. KiBitmap( gerbview_drill_file_xpm ),
  56. _( "Load an excellon drill file on the current layer. Previous data will be deleted" ) );
  57. m_mainToolBar->AddSeparator();
  58. m_mainToolBar->AddTool( ID_GERBVIEW_SET_PAGE_BORDER, wxEmptyString, KiBitmap( sheetset_xpm ),
  59. _( "Show/hide frame reference and select paper size for printing" ) );
  60. m_mainToolBar->AddSeparator();
  61. m_mainToolBar->AddTool( wxID_PRINT, wxEmptyString, KiBitmap( print_button_xpm ),
  62. _( "Print layers" ) );
  63. m_mainToolBar->AddSeparator();
  64. msg = AddHotkeyName( _( "Zoom in" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_IN, IS_COMMENT );
  65. m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiBitmap( zoom_in_xpm ), msg );
  66. msg = AddHotkeyName( _( "Zoom out" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_OUT, IS_COMMENT );
  67. m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiBitmap( zoom_out_xpm ), msg );
  68. msg = AddHotkeyName( _( "Redraw view" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_REDRAW, IS_COMMENT );
  69. m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiBitmap( zoom_redraw_xpm ), msg );
  70. msg = AddHotkeyName( _( "Zoom auto" ), s_Gerbview_Hokeys_Descr, HK_ZOOM_AUTO, IS_COMMENT );
  71. m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ), msg );
  72. m_mainToolBar->AddSeparator();
  73. m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( m_mainToolBar,
  74. ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
  75. wxDefaultPosition, wxSize( 150, -1 ), 0,NULL);
  76. m_SelLayerBox->Resync();
  77. m_mainToolBar->AddControl( m_SelLayerBox );
  78. m_mainToolBar->AddSeparator();
  79. m_DCodesList.Alloc(TOOLS_MAX_COUNT+1);
  80. m_DCodesList.Add( _( "No tool" ) );
  81. for( ii = FIRST_DCODE; ii < TOOLS_MAX_COUNT; ii++ )
  82. {
  83. msg = _( "Tool " );
  84. msg << ii;
  85. m_DCodesList.Add( msg );
  86. }
  87. m_DCodeSelector = new DCODE_SELECTION_BOX( m_mainToolBar,
  88. ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
  89. wxDefaultPosition, wxSize( 150, -1 ),
  90. m_DCodesList );
  91. m_mainToolBar->AddControl( m_DCodeSelector );
  92. m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
  93. wxSize(150,-1), wxTE_READONLY );
  94. m_mainToolBar->AddControl( m_TextInfo );
  95. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  96. m_mainToolBar->Realize();
  97. }
  98. void GERBVIEW_FRAME::ReCreateVToolbar( void )
  99. {
  100. if( m_drawToolBar )
  101. return;
  102. m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  103. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
  104. // Set up toolbar
  105. m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiBitmap( cursor_xpm ) );
  106. m_drawToolBar->AddSeparator();
  107. m_drawToolBar->Realize();
  108. }
  109. void GERBVIEW_FRAME::ReCreateOptToolbar( void )
  110. {
  111. if( m_optionsToolBar )
  112. return;
  113. // creation of tool bar options
  114. m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  115. wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_VERTICAL );
  116. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiBitmap( grid_xpm ),
  117. _( "Turn grid off" ), wxITEM_CHECK );
  118. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
  119. KiBitmap( polar_coord_xpm ),
  120. _( "Turn polar coordinate on" ), wxITEM_CHECK );
  121. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
  122. KiBitmap( unit_inch_xpm ),
  123. _( "Set units to inches" ), wxITEM_CHECK );
  124. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
  125. KiBitmap( unit_mm_xpm ),
  126. _( "Set units to millimeters" ), wxITEM_CHECK );
  127. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
  128. KiBitmap( cursor_shape_xpm ),
  129. _( "Change cursor shape" ), wxITEM_CHECK );
  130. m_optionsToolBar->AddSeparator();
  131. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH, wxEmptyString,
  132. KiBitmap( pad_sketch_xpm ),
  133. _( "Show spots in sketch mode" ), wxITEM_CHECK );
  134. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LINES_SKETCH, wxEmptyString,
  135. KiBitmap( showtrack_xpm ),
  136. _( "Show lines in sketch mode" ), wxITEM_CHECK );
  137. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH, wxEmptyString,
  138. KiBitmap( opt_show_polygon_xpm ),
  139. _( "Show polygons in sketch mode" ),
  140. wxITEM_CHECK );
  141. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_NEGATIVE_ITEMS, wxEmptyString,
  142. KiBitmap( gerbview_show_negative_objects_xpm ),
  143. _( "Show negatives objects in ghost color" ),
  144. wxITEM_CHECK );
  145. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_DCODES, wxEmptyString,
  146. KiBitmap( show_dcodenumber_xpm ),
  147. _( "Show dcode number" ), wxITEM_CHECK );
  148. // tools to select draw mode in GerbView
  149. m_optionsToolBar->AddSeparator();
  150. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_0, wxEmptyString,
  151. KiBitmap( gbr_select_mode0_xpm ),
  152. _( "Show layers in raw mode \
  153. (could have problems with negative items when more than one gerber file is shown)" ),
  154. wxITEM_CHECK );
  155. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_1, wxEmptyString,
  156. KiBitmap( gbr_select_mode1_xpm ),
  157. _( "Show layers in stacked mode \
  158. (show negative items without artifacts, sometimes slow)" ),
  159. wxITEM_CHECK );
  160. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GBR_MODE_2, wxEmptyString,
  161. KiBitmap( gbr_select_mode2_xpm ),
  162. _( "Show layers in transparency mode \
  163. (show negative items without artifacts, sometimes slow)" ),
  164. wxITEM_CHECK );
  165. // Tools to show/hide toolbars:
  166. m_optionsToolBar->AddSeparator();
  167. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
  168. wxEmptyString,
  169. KiBitmap( layers_manager_xpm ),
  170. _( "Show/hide the layers manager toolbar" ),
  171. wxITEM_CHECK );
  172. m_optionsToolBar->Realize();
  173. }
  174. void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
  175. {
  176. switch( aEvent.GetId() )
  177. {
  178. case ID_TB_OPTIONS_SHOW_GBR_MODE_0:
  179. aEvent.Check( GetDisplayMode() == 0 );
  180. break;
  181. case ID_TB_OPTIONS_SHOW_GBR_MODE_1:
  182. aEvent.Check( GetDisplayMode() == 1 );
  183. break;
  184. case ID_TB_OPTIONS_SHOW_GBR_MODE_2:
  185. aEvent.Check( GetDisplayMode() == 2 );
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. void GERBVIEW_FRAME::OnUpdateCoordType( wxUpdateUIEvent& aEvent )
  192. {
  193. aEvent.Check( m_DisplayOptions.m_DisplayPolarCood );
  194. }
  195. void GERBVIEW_FRAME::OnUpdateFlashedItemsDrawMode( wxUpdateUIEvent& aEvent )
  196. {
  197. aEvent.Check( !m_DisplayOptions.m_DisplayFlashedItemsFill );
  198. }
  199. void GERBVIEW_FRAME::OnUpdateLinesDrawMode( wxUpdateUIEvent& aEvent )
  200. {
  201. aEvent.Check( !m_DisplayOptions.m_DisplayLinesFill );
  202. }
  203. void GERBVIEW_FRAME::OnUpdatePolygonsDrawMode( wxUpdateUIEvent& aEvent )
  204. {
  205. aEvent.Check( !m_DisplayOptions.m_DisplayPolygonsFill );
  206. }
  207. void GERBVIEW_FRAME::OnUpdateShowDCodes( wxUpdateUIEvent& aEvent )
  208. {
  209. aEvent.Check( IsElementVisible( DCODES_VISIBLE ) );
  210. }
  211. void GERBVIEW_FRAME::OnUpdateShowNegativeItems( wxUpdateUIEvent& aEvent )
  212. {
  213. aEvent.Check( IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
  214. }
  215. void GERBVIEW_FRAME::OnUpdateShowLayerManager( wxUpdateUIEvent& aEvent )
  216. {
  217. aEvent.Check( m_show_layer_manager_tools );
  218. if( m_optionsToolBar )
  219. {
  220. if( m_show_layer_manager_tools )
  221. m_optionsToolBar->SetToolShortHelp( aEvent.GetId(), _("Hide layers manager" ) );
  222. else
  223. m_optionsToolBar->SetToolShortHelp( aEvent.GetId(), _("Show layers manager" ) );
  224. }
  225. }
  226. void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
  227. {
  228. LAYER_NUM layer = getActiveLayer();
  229. GERBER_IMAGE* gerber = g_GERBER_List[layer];
  230. int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
  231. if( m_DCodeSelector && m_DCodeSelector->GetSelectedDCodeId() != selected )
  232. m_DCodeSelector->SetDCodeSelection( selected );
  233. aEvent.Enable( gerber != NULL );
  234. }
  235. void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
  236. {
  237. if( m_SelLayerBox && (m_SelLayerBox->GetSelection() != getActiveLayer()) )
  238. {
  239. m_SelLayerBox->SetSelection( getActiveLayer() );
  240. }
  241. }