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.

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