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.

282 lines
10 KiB

16 years ago
16 years ago
  1. /****************************************************************
  2. * toolbars_update_user_interface.cpp
  3. ****************************************************************/
  4. /*
  5. * function to update toolbars UI after changing parameters
  6. */
  7. #include "fctsys.h"
  8. #include "appl_wxstruct.h"
  9. #include "common.h"
  10. #include "class_drawpanel.h"
  11. #include "pcbnew.h"
  12. #include "wxPcbStruct.h"
  13. #include "bitmaps.h"
  14. #include "pcbnew_id.h"
  15. #include "drc_stuff.h"
  16. #include "3d_viewer.h"
  17. #include "class_board_design_settings.h"
  18. /* helper to convert an integer value to a string, using mils or mm
  19. * according to g_UnitMetric value
  20. */
  21. static wxString ReturnStringValue( int aValue )
  22. {
  23. wxString text;
  24. const wxChar* format;
  25. double value = To_User_Unit( g_UnitMetric, aValue, PCB_INTERNAL_UNIT );
  26. if( g_UnitMetric == INCHES )
  27. {
  28. format = wxT( " %.1f" );
  29. value *= 1000;
  30. }
  31. else
  32. format = wxT( " %.3f" );
  33. text.Printf( format, value );
  34. if( g_UnitMetric == INCHES )
  35. text += _( " mils" );
  36. else
  37. text += _( " mm" );
  38. return text;
  39. }
  40. /**
  41. * Function AuxiliaryToolBar_DesignRules_Update_UI
  42. * update the displayed values: track widths, via sizes, clearance, Netclass name
  43. * used when a netclass is selected
  44. */
  45. void WinEDA_PcbFrame::AuxiliaryToolBar_DesignRules_Update_UI()
  46. {
  47. wxString nclname = GetBoard()->m_CurrentNetClassName;
  48. wxString msg = _( "NetClass: " ) + nclname;
  49. m_NetClassSelectedBox->Clear();
  50. m_NetClassSelectedBox->AppendText( msg );
  51. NETCLASS* netclass = GetBoard()->m_NetClasses.Find( nclname );
  52. if( m_ClearanceBox )
  53. {
  54. wxString msg = _( "Clearance" ) + ReturnStringValue( netclass->GetClearance() );
  55. m_ClearanceBox->Clear();
  56. m_ClearanceBox->AppendText( msg );
  57. }
  58. }
  59. /**
  60. * Function AuxiliaryToolBar_Update_UI
  61. * update the displayed values on auxiliary horizontal toolbar
  62. * (track width, via sizes, clearance ...
  63. * Display format for track and via lists
  64. * first item = current selected class value
  65. * next items (if any) = ordered list of sizes (extra sizes).
  66. * So the current selected class value can be same as an other extra value
  67. */
  68. void WinEDA_PcbFrame::AuxiliaryToolBar_Update_UI()
  69. {
  70. wxString msg;
  71. AuxiliaryToolBar_DesignRules_Update_UI();
  72. m_AuxiliaryToolBar->ToggleTool( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH,
  73. GetBoard()->GetBoardDesignSettings()->m_UseConnectedTrackWidth );
  74. if( m_SelTrackWidthBox && m_TrackAndViasSizesList_Changed )
  75. {
  76. m_SelTrackWidthBox->Clear();
  77. for( unsigned ii = 0; ii < GetBoard()->m_TrackWidthList.size(); ii++ )
  78. {
  79. msg = _( "Track" ) + ReturnStringValue( GetBoard()->m_TrackWidthList[ii] );
  80. if( ii == 0 )
  81. msg << _( " *" );
  82. m_SelTrackWidthBox->Append( msg );
  83. }
  84. }
  85. if( GetBoard()->m_TrackWidthSelector >= GetBoard()->m_TrackWidthList.size() )
  86. GetBoard()->m_TrackWidthSelector = 0;
  87. m_SelTrackWidthBox->SetSelection( GetBoard()->m_TrackWidthSelector );
  88. if( m_SelViaSizeBox && m_TrackAndViasSizesList_Changed )
  89. {
  90. m_SelViaSizeBox->Clear();
  91. for( unsigned ii = 0; ii < GetBoard()->m_ViasDimensionsList.size(); ii++ )
  92. {
  93. msg = _( "Via" );
  94. msg << ReturnStringValue( GetBoard()->m_ViasDimensionsList[ii].m_Diameter );
  95. if( GetBoard()->m_ViasDimensionsList[ii].m_Drill )
  96. msg << wxT("/") << ReturnStringValue( GetBoard()->m_ViasDimensionsList[ii].m_Drill );
  97. if( ii == 0 )
  98. msg << _( " *" );
  99. m_SelViaSizeBox->Append( msg );
  100. }
  101. }
  102. if( GetBoard()->m_ViaSizeSelector >= GetBoard()->m_ViasDimensionsList.size() )
  103. GetBoard()->m_ViaSizeSelector = 0;
  104. m_SelViaSizeBox->SetSelection( GetBoard()->m_ViaSizeSelector );
  105. if( m_SelZoomBox )
  106. {
  107. bool not_found = true;
  108. for( unsigned jj = 0; jj < GetScreen()->m_ZoomList.GetCount(); jj++ )
  109. {
  110. if( GetScreen()->GetZoom() == GetScreen()->m_ZoomList[jj] )
  111. {
  112. m_SelZoomBox->SetSelection( jj + 1 );
  113. not_found = false;
  114. break;
  115. }
  116. }
  117. if( not_found )
  118. m_SelZoomBox->SetSelection( -1 );
  119. }
  120. if( m_SelGridBox )
  121. m_SelGridBox->SetSelection( m_LastGridSizeId );
  122. m_TrackAndViasSizesList_Changed = false;
  123. }
  124. /*
  125. * Enable or disable the toolbar's controls, depending on the current
  126. * state.
  127. *
  128. * @todo: All of this should be perform in appropriate wxUpdateUIEvent
  129. * handles. This is not how it how updating user interface controls
  130. * is handle in wxWidgets.
  131. */
  132. void WinEDA_PcbFrame::SetToolbars()
  133. {
  134. bool state;
  135. if( m_ID_current_state == ID_TRACK_BUTT )
  136. {
  137. if( Drc_On )
  138. DrawPanel->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
  139. else
  140. DrawPanel->SetCursor( wxCursor( wxCURSOR_QUESTION_ARROW ) );
  141. }
  142. if( m_HToolBar == NULL )
  143. return;
  144. m_HToolBar->EnableTool( ID_SAVE_BOARD, GetScreen()->IsModify() );
  145. state = GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE;
  146. m_HToolBar->EnableTool( wxID_CUT, state );
  147. m_HToolBar->EnableTool( wxID_COPY, state );
  148. m_HToolBar->EnableTool( wxID_PASTE, false );
  149. state = GetScreen()->GetUndoCommandCount() > 0;
  150. m_HToolBar->EnableTool( wxID_UNDO, state );
  151. state = GetScreen()->GetRedoCommandCount() > 0;
  152. m_HToolBar->EnableTool( wxID_REDO, state );
  153. if( m_OptionsToolBar )
  154. {
  155. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_DRC_OFF,
  156. !Drc_On );
  157. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_DRC_OFF,
  158. Drc_On ?
  159. _( "Disable design rule checking" ) :
  160. _( "Enable design rule checking" ) );
  161. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_MM,
  162. g_UnitMetric == MILLIMETRE ? TRUE : false );
  163. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_UNIT_INCH,
  164. g_UnitMetric == INCHES ? TRUE : false );
  165. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_POLAR_COORD,
  166. DisplayOpt.DisplayPolarCood );
  167. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_POLAR_COORD,
  168. DisplayOpt.DisplayPolarCood ?
  169. _( "Display rectangular coordinates" ) :
  170. _( "Display polar coordinates" ) );
  171. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_GRID, IsGridVisible( ) );
  172. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_GRID,
  173. IsGridVisible( ) ?
  174. _( "Hide grid" ) :
  175. _( "Show grid" ) );
  176. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SELECT_CURSOR,
  177. m_CursorShape );
  178. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_RATSNEST,
  179. GetBoard()->IsElementVisible(RATSNEST_VISIBLE) );
  180. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_RATSNEST,
  181. GetBoard()->IsElementVisible(RATSNEST_VISIBLE) ?
  182. _( "Hide board ratsnest" ) :
  183. _( "Show board ratsnest" ) );
  184. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_MODULE_RATSNEST,
  185. g_Show_Module_Ratsnest );
  186. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_MODULE_RATSNEST,
  187. g_Show_Module_Ratsnest ?
  188. _( "Hide module ratsnest" ) :
  189. _( "Show module ratsnest" ) );
  190. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_AUTO_DEL_TRACK,
  191. g_AutoDeleteOldTrack );
  192. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_AUTO_DEL_TRACK,
  193. g_AutoDeleteOldTrack ?
  194. _( "Disable auto delete old track" ) :
  195. _( "Enable auto delete old track" ) );
  196. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH,
  197. !m_DisplayPadFill );
  198. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_PADS_SKETCH,
  199. m_DisplayPadFill ?
  200. _( "Show pads in outline mode" ) :
  201. _( "Show pads in fill mode" ) );
  202. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_VIAS_SKETCH,
  203. !m_DisplayViaFill );
  204. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_VIAS_SKETCH,
  205. m_DisplayViaFill ?
  206. _( "Show vias in outline mode" ) :
  207. _( "Show vias in fill mode" ) );
  208. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH,
  209. !m_DisplayPcbTrackFill );
  210. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH,
  211. m_DisplayPcbTrackFill ?
  212. _( "Show tracks in outline mode" ) :
  213. _( "Show tracks in fill mode" ) );
  214. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
  215. DisplayOpt.ContrastModeDisplay );
  216. m_OptionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
  217. DisplayOpt.ContrastModeDisplay ?
  218. _( "Normal contrast display mode" ) :
  219. _( "High contrast display mode" ) );
  220. m_OptionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR1,
  221. m_auimgr.GetPane(wxT("m_AuxVToolBar")).IsShown() );
  222. }
  223. if( m_AuxiliaryToolBar )
  224. AuxiliaryToolBar_Update_UI();
  225. syncLayerBox();
  226. PrepareLayerIndicator();
  227. DisplayUnitsMsg();
  228. if(m_auimgr.GetManagedWindow())
  229. m_auimgr.Update();
  230. }