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.

305 lines
6.9 KiB

Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
  1. /**
  2. * @file footprint_wizard.cpp
  3. */
  4. #include <fctsys.h>
  5. #include <gr_basic.h>
  6. #include <class_drawpanel.h>
  7. #include <wxPcbStruct.h>
  8. #include <dialog_helpers.h>
  9. #include <3d_viewer.h>
  10. #include <class_board.h>
  11. #include <class_module.h>
  12. #include <pcbnew.h>
  13. #include <pcbnew_id.h>
  14. #include "footprint_wizard_frame.h"
  15. #include <wildcards_and_files_ext.h>
  16. #include <dialogs/dialog_footprint_wizard_list.h>
  17. #include <base_units.h>
  18. void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
  19. {
  20. wxString msg;
  21. int page;
  22. switch( event.GetId() )
  23. {
  24. case ID_FOOTPRINT_WIZARD_NEXT:
  25. m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
  26. ClickOnPageList( event );
  27. break;
  28. case ID_FOOTPRINT_WIZARD_PREVIOUS:
  29. page = m_pageList->GetSelection() - 1;
  30. if( page < 0 )
  31. page = 0;
  32. m_pageList->SetSelection( page, true );
  33. ClickOnPageList( event );
  34. break;
  35. default:
  36. msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
  37. << event.GetId();
  38. wxMessageBox( msg );
  39. break;
  40. }
  41. }
  42. /* Function OnLeftClick
  43. * Captures a left click event in the dialog
  44. *
  45. */
  46. void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  47. {
  48. }
  49. /* Function OnRightClick
  50. * Captures a right click event in the dialog
  51. *
  52. */
  53. bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  54. {
  55. return true;
  56. }
  57. /* Displays the name of the current opened library in the caption */
  58. void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
  59. {
  60. wxString msg;
  61. msg = _( "Footprint Wizard" );
  62. msg << wxT( " [" );
  63. if( !m_wizardName.IsEmpty() )
  64. msg << m_wizardName;
  65. else
  66. msg += _( "no wizard selected" );
  67. msg << wxT( "]" );
  68. SetTitle( msg );
  69. }
  70. void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
  71. {
  72. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  73. if( !footprintWizard )
  74. return;
  75. SetCurItem( NULL );
  76. // Delete the current footprint
  77. GetBoard()->m_Modules.DeleteAll();
  78. // Creates the module
  79. wxString msg;
  80. MODULE* module = footprintWizard->GetFootprint( &msg );
  81. DisplayBuildMessage( msg );
  82. if( module )
  83. {
  84. // Add the object to board
  85. GetBoard()->Add( module, ADD_APPEND );
  86. module->SetPosition( wxPoint( 0, 0 ) );
  87. }
  88. else
  89. {
  90. DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
  91. }
  92. m_canvas->Refresh();
  93. }
  94. void FOOTPRINT_WIZARD_FRAME::DisplayBuildMessage( wxString& aMessage )
  95. {
  96. if( m_messagesFrame == NULL )
  97. {
  98. // Prepare the window to display the message generated by the footprint script builder
  99. m_messagesFrame = new FOOTPRINT_WIZARD_MESSAGES( this, config() );
  100. m_messagesFrame->Show( true );
  101. }
  102. m_messagesFrame->ClearScreen();
  103. if( !aMessage.IsEmpty() )
  104. m_messagesFrame->PrintMessage( aMessage );
  105. }
  106. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
  107. {
  108. if( m_wizardName.Length() == 0 )
  109. return NULL;
  110. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
  111. if( !footprintWizard )
  112. {
  113. wxMessageBox( _( "Couldn't reload footprint wizard" ) );
  114. return NULL;
  115. }
  116. return footprintWizard;
  117. }
  118. MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
  119. {
  120. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
  121. if( footprintWizard && m_modal_ret_val )
  122. {
  123. wxString msg;
  124. MODULE * footprint = footprintWizard->GetFootprint( &msg );
  125. DisplayBuildMessage( msg );
  126. return footprint;
  127. }
  128. return NULL;
  129. }
  130. void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
  131. {
  132. DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
  133. if( wizardSelector.ShowModal() != wxID_OK )
  134. return;
  135. FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
  136. if( footprintWizard )
  137. {
  138. m_wizardName = footprintWizard->GetName();
  139. m_wizardDescription = footprintWizard->GetDescription();
  140. }
  141. else
  142. {
  143. m_wizardName.Empty();
  144. m_wizardDescription.Empty();
  145. }
  146. ReloadFootprint();
  147. Zoom_Automatique( false );
  148. DisplayWizardInfos();
  149. ReCreatePageList();
  150. ReCreateParameterList();
  151. }
  152. void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
  153. {
  154. SelectFootprintWizard();
  155. }
  156. void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
  157. {
  158. int page = m_pageList->GetSelection();
  159. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  160. if( !footprintWizard )
  161. return;
  162. if( page < 0 )
  163. return;
  164. wxArrayString prmValues = footprintWizard->GetParameterValues( page );
  165. wxArrayString ptList = footprintWizard->GetParameterTypes( page );
  166. bool has_changed = false;
  167. int count = m_parameterGrid->GetNumberRows();
  168. // Skip extra event, useless
  169. if( event.GetString() == m_parameterGrid->GetCellValue( event.GetRow(), m_columnPrmValue ) )
  170. return;
  171. for( int prm_id = 0; prm_id < count; ++prm_id )
  172. {
  173. wxString value = m_parameterGrid->GetCellValue( prm_id, m_columnPrmValue );
  174. // if this parameter is expected to be an internal
  175. // unit convert it back from the user format
  176. if( ptList[prm_id]==wxT( "IU" ) )
  177. {
  178. // If our locale is set to use, for decimal point, just change it
  179. // to be scripting compatible
  180. LOCALE_IO toggle;
  181. double dValue;
  182. value.ToDouble( &dValue );
  183. // convert from mils to inches where it's needed
  184. if( g_UserUnit==INCHES )
  185. dValue = dValue / 1000.0;
  186. dValue = From_User_Unit( g_UserUnit, dValue );
  187. // Internal units are int. Print them as int.
  188. value.Printf( "%d", KiROUND( dValue ) );
  189. if( prmValues[prm_id].EndsWith(".0") )
  190. {
  191. prmValues[prm_id].RemoveLast();
  192. prmValues[prm_id].RemoveLast();
  193. }
  194. }
  195. if( prmValues[prm_id] != value )
  196. {
  197. has_changed = true;
  198. prmValues[prm_id] = value;
  199. }
  200. }
  201. if( has_changed )
  202. {
  203. wxString res = footprintWizard->SetParameterValues( page, prmValues );
  204. if( !res.IsEmpty() )
  205. wxMessageBox( res );
  206. ReloadFootprint();
  207. DisplayWizardInfos();
  208. }
  209. }
  210. /**
  211. * Function RedrawActiveWindow
  212. * Display the current selected component.
  213. * If the component is an alias, the ROOT component is displayed
  214. *
  215. */
  216. void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  217. {
  218. if( !GetBoard() )
  219. return;
  220. m_canvas->DrawBackGround( DC );
  221. GetBoard()->Draw( m_canvas, DC, GR_COPY );
  222. MODULE* module = GetBoard()->m_Modules;
  223. if( module )
  224. SetMsgPanel( module );
  225. m_canvas->DrawCrossHair( DC );
  226. ClearMsgPanel();
  227. if( module )
  228. SetMsgPanel( module );
  229. }