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.

260 lines
6.5 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. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es
  5. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright (C) 2004-2018 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. #include <fctsys.h>
  26. #include <gr_basic.h>
  27. #include <pcb_edit_frame.h>
  28. #include <dialog_helpers.h>
  29. #include <class_board.h>
  30. #include <class_module.h>
  31. #include <pcbnew.h>
  32. #include <pcbnew_id.h>
  33. #include "footprint_wizard_frame.h"
  34. #include <wildcards_and_files_ext.h>
  35. #include <dialogs/dialog_footprint_wizard_list.h>
  36. #include <base_units.h>
  37. #include <widgets/wx_grid.h>
  38. #include <tool/tool_manager.h>
  39. void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
  40. {
  41. wxString msg;
  42. int page;
  43. switch( event.GetId() )
  44. {
  45. case ID_FOOTPRINT_WIZARD_NEXT:
  46. m_pageList->SetSelection( m_pageList->GetSelection() + 1, true );
  47. ClickOnPageList( event );
  48. break;
  49. case ID_FOOTPRINT_WIZARD_PREVIOUS:
  50. page = m_pageList->GetSelection() - 1;
  51. if( page < 0 )
  52. page = 0;
  53. m_pageList->SetSelection( page, true );
  54. ClickOnPageList( event );
  55. break;
  56. default:
  57. wxLogDebug( wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d" ),
  58. event.GetId() );
  59. break;
  60. }
  61. }
  62. /* Displays the name of the current opened library in the caption */
  63. void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
  64. {
  65. wxString msg;
  66. msg = _( "Footprint Wizard" );
  67. msg << wxT( " [" );
  68. if( !m_wizardName.IsEmpty() )
  69. msg << m_wizardName;
  70. else
  71. msg += _( "no wizard selected" );
  72. msg << wxT( "]" );
  73. SetTitle( msg );
  74. }
  75. void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
  76. {
  77. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  78. if( !footprintWizard )
  79. return;
  80. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  81. // Delete the current footprint
  82. GetBoard()->DeleteAllModules();
  83. // Creates the module
  84. wxString msg;
  85. MODULE* module = footprintWizard->GetFootprint( &msg );
  86. DisplayBuildMessage( msg );
  87. if( module )
  88. {
  89. // Add the object to board
  90. GetBoard()->Add( module, ADD_MODE::APPEND );
  91. module->SetPosition( wxPoint( 0, 0 ) );
  92. }
  93. else
  94. {
  95. DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
  96. }
  97. updateView();
  98. GetCanvas()->Refresh();
  99. }
  100. void FOOTPRINT_WIZARD_FRAME::DisplayBuildMessage( wxString& aMessage )
  101. {
  102. m_buildMessageBox->SetValue( aMessage );
  103. }
  104. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
  105. {
  106. if( m_wizardName.Length() == 0 )
  107. return NULL;
  108. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  109. if( !footprintWizard )
  110. {
  111. wxMessageBox( _( "Couldn't reload footprint wizard" ) );
  112. return NULL;
  113. }
  114. return footprintWizard;
  115. }
  116. MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
  117. {
  118. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  119. if( footprintWizard && m_modal_ret_val )
  120. {
  121. wxString msg;
  122. MODULE * footprint = footprintWizard->GetFootprint( &msg );
  123. DisplayBuildMessage( msg );
  124. return footprint;
  125. }
  126. return NULL;
  127. }
  128. void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
  129. {
  130. DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
  131. if( wizardSelector.ShowModal() != wxID_OK )
  132. return;
  133. FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
  134. if( footprintWizard )
  135. {
  136. m_wizardName = footprintWizard->GetName();
  137. m_wizardDescription = footprintWizard->GetDescription();
  138. footprintWizard->ResetParameters();
  139. }
  140. else
  141. {
  142. m_wizardName.Empty();
  143. m_wizardDescription.Empty();
  144. }
  145. ReloadFootprint();
  146. Zoom_Automatique( false );
  147. DisplayWizardInfos();
  148. ReCreatePageList();
  149. ReCreateParameterList();
  150. }
  151. void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
  152. {
  153. SelectFootprintWizard();
  154. updateView();
  155. }
  156. void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
  157. {
  158. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  159. if ( footprintWizard == NULL )
  160. return;
  161. footprintWizard->ResetParameters();
  162. // Reload
  163. ReCreateParameterList();
  164. ReloadFootprint();
  165. DisplayWizardInfos();
  166. }
  167. void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
  168. {
  169. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  170. if( !footprintWizard )
  171. return;
  172. if( m_parameterGridPage < 0 )
  173. return;
  174. wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
  175. wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
  176. bool has_changed = false;
  177. int count = m_parameterGrid->GetNumberRows();
  178. for( int prm_id = 0; prm_id < count; ++prm_id )
  179. {
  180. wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
  181. if( prmValues[prm_id] != value )
  182. {
  183. has_changed = true;
  184. prmValues[prm_id] = value;
  185. }
  186. }
  187. if( has_changed )
  188. {
  189. wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
  190. if( !res.IsEmpty() )
  191. wxMessageBox( res );
  192. ReloadFootprint();
  193. DisplayWizardInfos();
  194. // The python script can have modified some other parameters.
  195. // So rebuild the current parameter list with new values, just in case.
  196. ReCreateParameterList();
  197. }
  198. }