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.

304 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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright (C) 2004-2017 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. /**
  26. * @file footprint_wizard_frame_functions.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <class_drawpanel.h>
  31. #include <pcb_edit_frame.h>
  32. #include <dialog_helpers.h>
  33. #include <class_board.h>
  34. #include <class_module.h>
  35. #include <pcbnew.h>
  36. #include <pcbnew_id.h>
  37. #include "footprint_wizard_frame.h"
  38. #include <wildcards_and_files_ext.h>
  39. #include <dialogs/dialog_footprint_wizard_list.h>
  40. #include <base_units.h>
  41. void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
  42. {
  43. wxString msg;
  44. int page;
  45. switch( event.GetId() )
  46. {
  47. case ID_FOOTPRINT_WIZARD_NEXT:
  48. m_pageList->SetSelection( m_pageList->GetSelection() + 1, 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. msg << wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions error: id = " )
  60. << event.GetId();
  61. wxMessageBox( msg );
  62. break;
  63. }
  64. }
  65. /* Function OnLeftClick
  66. * Captures a left click event in the dialog
  67. *
  68. */
  69. void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  70. {
  71. }
  72. /* Function OnRightClick
  73. * Captures a right click event in the dialog
  74. *
  75. */
  76. bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  77. {
  78. return true;
  79. }
  80. /* Displays the name of the current opened library in the caption */
  81. void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
  82. {
  83. wxString msg;
  84. msg = _( "Footprint Wizard" );
  85. msg << wxT( " [" );
  86. if( !m_wizardName.IsEmpty() )
  87. msg << m_wizardName;
  88. else
  89. msg += _( "no wizard selected" );
  90. msg << wxT( "]" );
  91. SetTitle( msg );
  92. }
  93. void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
  94. {
  95. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  96. if( !footprintWizard )
  97. return;
  98. SetCurItem( NULL );
  99. // Delete the current footprint
  100. GetBoard()->m_Modules.DeleteAll();
  101. // Creates the module
  102. wxString msg;
  103. MODULE* module = footprintWizard->GetFootprint( &msg );
  104. DisplayBuildMessage( msg );
  105. if( module )
  106. {
  107. // Add the object to board
  108. GetBoard()->Add( module, ADD_APPEND );
  109. module->SetPosition( wxPoint( 0, 0 ) );
  110. }
  111. else
  112. {
  113. DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );)
  114. }
  115. m_canvas->Refresh();
  116. }
  117. void FOOTPRINT_WIZARD_FRAME::DisplayBuildMessage( wxString& aMessage )
  118. {
  119. m_buildMessageBox->SetValue( aMessage );
  120. }
  121. FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
  122. {
  123. if( m_wizardName.Length() == 0 )
  124. return NULL;
  125. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  126. if( !footprintWizard )
  127. {
  128. wxMessageBox( _( "Couldn't reload footprint wizard" ) );
  129. return NULL;
  130. }
  131. return footprintWizard;
  132. }
  133. MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
  134. {
  135. FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARD_LIST::GetWizard( m_wizardName );
  136. if( footprintWizard && m_modal_ret_val )
  137. {
  138. wxString msg;
  139. MODULE * footprint = footprintWizard->GetFootprint( &msg );
  140. DisplayBuildMessage( msg );
  141. return footprint;
  142. }
  143. return NULL;
  144. }
  145. void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
  146. {
  147. DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
  148. if( wizardSelector.ShowModal() != wxID_OK )
  149. return;
  150. FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
  151. if( footprintWizard )
  152. {
  153. m_wizardName = footprintWizard->GetName();
  154. m_wizardDescription = footprintWizard->GetDescription();
  155. footprintWizard->ResetParameters();
  156. }
  157. else
  158. {
  159. m_wizardName.Empty();
  160. m_wizardDescription.Empty();
  161. }
  162. ReloadFootprint();
  163. Zoom_Automatique( false );
  164. DisplayWizardInfos();
  165. ReCreatePageList();
  166. ReCreateParameterList();
  167. }
  168. void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
  169. {
  170. SelectFootprintWizard();
  171. }
  172. void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
  173. {
  174. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  175. if ( footprintWizard == NULL )
  176. return;
  177. footprintWizard->ResetParameters();
  178. // Reload
  179. ReCreateParameterList();
  180. ReloadFootprint();
  181. DisplayWizardInfos();
  182. }
  183. void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
  184. {
  185. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  186. if( !footprintWizard )
  187. return;
  188. if( m_parameterGridPage < 0 )
  189. return;
  190. wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
  191. wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
  192. bool has_changed = false;
  193. int count = m_parameterGrid->GetNumberRows();
  194. for( int prm_id = 0; prm_id < count; ++prm_id )
  195. {
  196. wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
  197. if( prmValues[prm_id] != value )
  198. {
  199. has_changed = true;
  200. prmValues[prm_id] = value;
  201. }
  202. }
  203. if( has_changed )
  204. {
  205. wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
  206. if( !res.IsEmpty() )
  207. wxMessageBox( res );
  208. ReloadFootprint();
  209. DisplayWizardInfos();
  210. }
  211. }
  212. /**
  213. * Function RedrawActiveWindow
  214. * Display the current selected component.
  215. * If the component is an alias, the ROOT component is displayed
  216. *
  217. */
  218. void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  219. {
  220. if( !GetBoard() )
  221. return;
  222. m_canvas->DrawBackGround( DC );
  223. GetBoard()->Draw( m_canvas, DC, GR_COPY );
  224. MODULE* module = GetBoard()->m_Modules;
  225. if( module )
  226. SetMsgPanel( module );
  227. m_canvas->DrawCrossHair( DC );
  228. ClearMsgPanel();
  229. if( module )
  230. SetMsgPanel( module );
  231. }