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.

275 lines
7.1 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-2020 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. wxFAIL_MSG( wxString::Format(
  58. "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = %d",
  59. event.GetId() ) );
  60. break;
  61. }
  62. }
  63. /* Displays the name of the current opened library in the caption */
  64. void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
  65. {
  66. wxString msg;
  67. msg = _( "Footprint Wizard" );
  68. msg << wxT( " [" );
  69. if( !m_wizardName.IsEmpty() )
  70. msg << m_wizardName;
  71. else
  72. msg += _( "no wizard selected" );
  73. msg << wxT( "]" );
  74. SetTitle( msg );
  75. }
  76. void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
  77. {
  78. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  79. if( !footprintWizard )
  80. return;
  81. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  82. // Delete the current footprint
  83. GetBoard()->DeleteAllModules();
  84. // Creates the module
  85. wxString msg;
  86. MODULE* module = footprintWizard->GetFootprint( &msg );
  87. DisplayBuildMessage( msg );
  88. if( module )
  89. {
  90. // Add the object to board
  91. GetBoard()->Add( module, ADD_MODE::APPEND );
  92. module->SetPosition( wxPoint( 0, 0 ) );
  93. }
  94. updateView();
  95. GetCanvas()->Refresh();
  96. }
  97. void FOOTPRINT_WIZARD_FRAME::DisplayBuildMessage( wxString& aMessage )
  98. {
  99. m_buildMessageBox->SetValue( aMessage );
  100. }
  101. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
  102. {
  103. if( m_wizardName.Length() == 0 )
  104. return NULL;
  105. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  106. if( !footprintWizard )
  107. {
  108. wxMessageBox( _( "Couldn't reload footprint wizard" ) );
  109. return NULL;
  110. }
  111. return footprintWizard;
  112. }
  113. MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
  114. {
  115. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  116. if( footprintWizard && m_modal_ret_val )
  117. {
  118. wxString msg;
  119. MODULE * footprint = footprintWizard->GetFootprint( &msg );
  120. DisplayBuildMessage( msg );
  121. return footprint;
  122. }
  123. return NULL;
  124. }
  125. void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
  126. {
  127. DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
  128. if( wizardSelector.ShowModal() != wxID_OK )
  129. return;
  130. FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
  131. if( footprintWizard )
  132. {
  133. m_wizardName = footprintWizard->GetName();
  134. m_wizardDescription = footprintWizard->GetDescription();
  135. footprintWizard->ResetParameters();
  136. }
  137. else
  138. {
  139. m_wizardName.Empty();
  140. m_wizardDescription.Empty();
  141. }
  142. ReloadFootprint();
  143. Zoom_Automatique( false );
  144. DisplayWizardInfos();
  145. ReCreatePageList();
  146. ReCreateParameterList();
  147. }
  148. void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
  149. {
  150. SelectFootprintWizard();
  151. updateView();
  152. }
  153. void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
  154. {
  155. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  156. if ( footprintWizard == NULL )
  157. return;
  158. footprintWizard->ResetParameters();
  159. // Reload
  160. ReCreateParameterList();
  161. ReloadFootprint();
  162. DisplayWizardInfos();
  163. }
  164. // This is a flag to avoid reentering of ParametersUpdated
  165. // that can happen in some cases
  166. static bool lock_update_prms = false;
  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. if( lock_update_prms )
  175. return;
  176. wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
  177. wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
  178. bool has_changed = false;
  179. int count = m_parameterGrid->GetNumberRows();
  180. for( int prm_id = 0; prm_id < count; ++prm_id )
  181. {
  182. wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
  183. if( prmValues[prm_id] != value )
  184. {
  185. has_changed = true;
  186. prmValues[prm_id] = value;
  187. }
  188. }
  189. if( has_changed )
  190. {
  191. wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
  192. if( !res.IsEmpty() )
  193. wxMessageBox( res );
  194. ReloadFootprint();
  195. DisplayWizardInfos();
  196. // The python script can have modified some other parameters.
  197. // So rebuild the current parameter list with new values, just in case.
  198. //
  199. // On wxWidgets 3.0.5, ReCreateParameterList() generates a EVT_GRID_CMD_CELL_CHANGED
  200. // that call ParametersUpdated() and creating an infinite loop
  201. // Note also it happens **only for languages using a comma** instead of a point
  202. // for floating point separator
  203. // It does not happen on wxWidgets 3.1.4
  204. //
  205. // So lock the next call.
  206. lock_update_prms = true;
  207. ReCreateParameterList();
  208. }
  209. // unlock ParametersUpdated() now the update is finished
  210. lock_update_prms = false;
  211. }