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.

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