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.

268 lines
5.8 KiB

12 years ago
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. #define NEXT_PART 1
  19. #define NEW_PART 0
  20. #define PREVIOUS_PART -1
  21. void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
  22. {
  23. wxString msg;
  24. int page;
  25. switch( event.GetId() )
  26. {
  27. case ID_FOOTPRINT_WIZARD_NEXT:
  28. m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
  29. ClickOnPageList( event );
  30. break;
  31. case ID_FOOTPRINT_WIZARD_PREVIOUS:
  32. page = m_pageList->GetSelection() - 1;
  33. if( page < 0 )
  34. page = 0;
  35. m_pageList->SetSelection( page, true );
  36. ClickOnPageList( event );
  37. break;
  38. default:
  39. msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
  40. << event.GetId();
  41. wxMessageBox( msg );
  42. break;
  43. }
  44. }
  45. /* Function OnLeftClick
  46. * Captures a left click event in the dialog
  47. *
  48. */
  49. void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  50. {
  51. }
  52. /* Function OnRightClick
  53. * Captures a right click event in the dialog
  54. *
  55. */
  56. bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  57. {
  58. return true;
  59. }
  60. /* Displays the name of the current opened library in the caption */
  61. void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
  62. {
  63. wxString msg;
  64. msg = _( "Footprint Wizard" );
  65. msg << wxT( " [" );
  66. if( !m_wizardName.IsEmpty() )
  67. msg << m_wizardName;
  68. else
  69. msg += _( "no wizard selected" );
  70. msg << wxT( "]" );
  71. SetTitle( msg );
  72. }
  73. void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
  74. {
  75. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  76. if( !footprintWizard )
  77. return;
  78. SetCurItem( NULL );
  79. // Delete the current footprint
  80. GetBoard()->m_Modules.DeleteAll();
  81. // Creates the module
  82. MODULE* module = footprintWizard->GetModule();
  83. if( module )
  84. {
  85. // Add the object to board
  86. GetBoard()->Add( module, ADD_APPEND );
  87. module->SetPosition( wxPoint( 0, 0 ) );
  88. }
  89. else
  90. {
  91. DBG(printf( "footprintWizard->GetModule() returns NULL\n" );)
  92. }
  93. m_canvas->Refresh();
  94. }
  95. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
  96. {
  97. if( m_wizardName.Length()==0 )
  98. return NULL;
  99. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
  100. if( !footprintWizard )
  101. {
  102. wxMessageBox( _( "Couldn't reload footprint wizard" ) );
  103. return NULL;
  104. }
  105. return footprintWizard;
  106. }
  107. MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
  108. {
  109. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
  110. if( footprintWizard && m_modal_ret_val )
  111. {
  112. return footprintWizard->GetModule();
  113. }
  114. return NULL;
  115. }
  116. void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
  117. {
  118. DIALOG_FOOTPRINT_WIZARD_LIST* selectWizard =
  119. new DIALOG_FOOTPRINT_WIZARD_LIST( this );
  120. if( selectWizard->ShowModal() != wxID_OK )
  121. return;
  122. FOOTPRINT_WIZARD* footprintWizard = selectWizard->GetWizard();
  123. if( footprintWizard )
  124. {
  125. m_wizardName = footprintWizard->GetName();
  126. m_wizardDescription = footprintWizard->GetDescription();
  127. }
  128. else
  129. {
  130. m_wizardName = wxT( "" );
  131. m_wizardDescription = wxT( "" );
  132. }
  133. ReloadFootprint();
  134. Zoom_Automatique( false );
  135. DisplayWizardInfos();
  136. ReCreatePageList();
  137. ReCreateParameterList();
  138. }
  139. void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
  140. {
  141. SelectFootprintWizard();
  142. }
  143. /**
  144. * Function SelectCurrentFootprint
  145. * Selects the current footprint name and display it
  146. */
  147. void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
  148. {
  149. int page = m_pageList->GetSelection();
  150. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  151. if( !footprintWizard )
  152. return;
  153. if( page<0 )
  154. return;
  155. int n = m_parameterGrid->GetNumberRows();
  156. wxArrayString arr;
  157. wxArrayString ptList = footprintWizard->GetParameterTypes( page );
  158. for( int i = 0; i<n; i++ )
  159. {
  160. wxString value = m_parameterGrid->GetCellValue( i, 1 );
  161. // if this parameter is expected to be an internal
  162. // unit convert it back from the user format
  163. if( ptList[i]==wxT( "IU" ) )
  164. {
  165. LOCALE_IO toggle;
  166. double dValue;
  167. value.ToDouble( &dValue );
  168. // convert from mils to inches where it's needed
  169. if( g_UserUnit==INCHES )
  170. dValue = dValue / 1000.0;
  171. dValue = From_User_Unit( g_UserUnit, dValue );
  172. value.Printf( wxT( "%f" ), dValue );
  173. }
  174. // If our locale is set to use , for decimal point, just change it
  175. // to be scripting compatible
  176. arr.Add( value );
  177. }
  178. wxString res = footprintWizard->SetParameterValues( page, arr );
  179. ReloadFootprint();
  180. DisplayWizardInfos();
  181. }
  182. /**
  183. * Function RedrawActiveWindow
  184. * Display the current selected component.
  185. * If the component is an alias, the ROOT component is displayed
  186. *
  187. */
  188. void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  189. {
  190. if( !GetBoard() )
  191. return;
  192. m_canvas->DrawBackGround( DC );
  193. GetBoard()->Draw( m_canvas, DC, GR_COPY );
  194. MODULE* module = GetBoard()->m_Modules;
  195. if( module )
  196. SetMsgPanel( module );
  197. m_canvas->DrawCrossHair( DC );
  198. ClearMsgPanel();
  199. if( module )
  200. SetMsgPanel( module );
  201. }