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.

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