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.

355 lines
12 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
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) 1992-2015 jean-pierre.charras
  5. * Copyright (C) 1992-2015 Kicad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <wx/wx.h>
  25. #include <wx/config.h>
  26. #include <pgm_base.h>
  27. #include <pcb_calculator.h>
  28. #include <UnitSelector.h>
  29. #include <bitmaps.h>
  30. #define KEYWORD_FRAME_POSX wxT( "Pcb_calculator_Pos_x" )
  31. #define KEYWORD_FRAME_POSY wxT( "Pcb_calculator_Pos_y" )
  32. #define KEYWORD_FRAME_SIZEX wxT( "Pcb_calculator_Size_x" )
  33. #define KEYWORD_FRAME_SIZEY wxT( "Pcb_calculator_Size_y" )
  34. #define KEYWORD_TRANSLINE_SELECTION wxT( "Transline_selection" )
  35. #define KEYWORD_PAGE_SELECTION wxT( "Page_selection" )
  36. #define KEYWORD_COLORCODE_SELECTION wxT( "CC_selection" )
  37. #define KEYWORD_ATTENUATORS_SELECTION wxT( "Att_selection" )
  38. #define KEYWORD_BRDCLASS_SELECTION wxT( "BrdClass_selection" )
  39. #define KEYWORD_ELECTRICAL_SPACING_SELECTION wxT( "ElectSpacing_selection" )
  40. #define KEYWORD_ELECTRICAL_SPACING_VOLTAGE wxT( "ElectSpacing_voltage" )
  41. #define KEYWORD_REGUL_R1 wxT( "RegulR1" )
  42. #define KEYWORD_REGUL_R2 wxT( "RegulR2" )
  43. #define KEYWORD_REGUL_VREF wxT( "RegulVREF" )
  44. #define KEYWORD_REGUL_VOUT wxT( "RegulVOUT" )
  45. #define KEYWORD_REGUL_SELECTED wxT( "RegulName" )
  46. #define KEYWORD_REGUL_TYPE wxT( "RegulType" )
  47. #define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" )
  48. #define KEYWORD_DATAFILE_FILENAME wxT( "DataFilename" )
  49. // extention of pcb_calculator data filename:
  50. const wxString DataFileNameExt( wxT("pcbcalc") );
  51. PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  52. PCB_CALCULATOR_FRAME_BASE( aParent )
  53. {
  54. SetKiway( this, aKiway );
  55. m_currTransLine = NULL;
  56. m_currTransLineType = DEFAULT_TYPE;
  57. m_currAttenuator = NULL;
  58. m_RegulatorListChanged = false;
  59. m_TWMode = TW_MASTER_CURRENT;
  60. m_TWNested = false;
  61. // Populate transline list ordered like in dialog menu list
  62. const static TRANSLINE_TYPE_ID tltype_list[8] =
  63. {
  64. MICROSTRIP_TYPE, CPW_TYPE, GROUNDED_CPW_TYPE,
  65. RECTWAVEGUIDE_TYPE, COAX_TYPE, C_MICROSTRIP_TYPE,
  66. STRIPLINE_TYPE, TWISTEDPAIR_TYPE
  67. };
  68. for( int ii = 0; ii < 8; ii++ )
  69. m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
  70. // Populate attenuator list ordered like in dialog menu list
  71. m_attenuator_list.push_back( new ATTENUATOR_PI() );
  72. m_attenuator_list.push_back( new ATTENUATOR_TEE() );
  73. m_attenuator_list.push_back( new ATTENUATOR_BRIDGE() );
  74. m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
  75. m_currAttenuator = m_attenuator_list[0];
  76. wxConfigBase* config = GetNewConfig( Pgm().App().GetAppName() );
  77. LoadSettings( config );
  78. ReadDataFile();
  79. TranslineTypeSelection( m_currTransLineType );
  80. m_TranslineSelection->SetSelection( m_currTransLineType );
  81. TW_Init( config );
  82. SetAttenuator( m_AttenuatorsSelection->GetSelection() );
  83. ToleranceSelection( m_rbToleranceSelection->GetSelection() );
  84. BoardClassesUpdateData( m_BoardClassesUnitsSelector->GetUnitScale() );
  85. ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() );
  86. m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
  87. SelectLastSelectedRegulator();
  88. // Give an icon
  89. wxIcon icon;
  90. icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) );
  91. SetIcon( icon );
  92. GetSizer()->SetSizeHints( this );
  93. // Set previous size and position
  94. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  95. if( m_FramePos == wxDefaultPosition )
  96. Centre();
  97. }
  98. PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME()
  99. {
  100. for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
  101. delete m_transline_list[ii];
  102. for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
  103. delete m_attenuator_list[ii];
  104. /* This needed for OSX: avoids furter OnDraw processing after this
  105. * destructor and before the native window is destroyed
  106. */
  107. this->Freeze();
  108. }
  109. void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
  110. {
  111. if( m_RegulatorListChanged )
  112. {
  113. if( GetDataFilename().IsEmpty() )
  114. {
  115. int opt = wxMessageBox(
  116. _("Data modified, and no data filename to save modifications\n"\
  117. "Do you want to exit and abandon your change?"),
  118. _("Regulator list change"),
  119. wxYES_NO | wxICON_QUESTION );
  120. if( opt == wxNO )
  121. return;
  122. }
  123. else
  124. {
  125. if( !WriteDataFile() )
  126. {
  127. wxString msg;
  128. msg.Printf( _("Unable to write file<%s>\n"\
  129. "Do you want to exit and abandon your change?"),
  130. GetDataFilename().c_str() );
  131. int opt = wxMessageBox( msg, _("Write Data File Error"),
  132. wxYES_NO | wxICON_ERROR );
  133. if( opt == wxNO )
  134. return;
  135. }
  136. }
  137. }
  138. event.Skip();
  139. // Destroy();
  140. }
  141. void PCB_CALCULATOR_FRAME::LoadSettings( wxConfigBase* aCfg )
  142. {
  143. if( aCfg == NULL )
  144. return;
  145. EDA_BASE_FRAME::LoadSettings( aCfg );
  146. long ltmp;
  147. wxString msg;
  148. aCfg->Read( KEYWORD_TRANSLINE_SELECTION, &ltmp, (long) DEFAULT_TYPE );
  149. m_currTransLineType = (enum TRANSLINE_TYPE_ID) ltmp;
  150. aCfg->Read( KEYWORD_PAGE_SELECTION, &ltmp, 0 );
  151. m_Notebook->ChangeSelection( ltmp );
  152. aCfg->Read( KEYWORD_COLORCODE_SELECTION, &ltmp, 1 );
  153. m_rbToleranceSelection->SetSelection( ltmp );
  154. aCfg->Read( KEYWORD_ATTENUATORS_SELECTION, &ltmp, 0 );
  155. m_AttenuatorsSelection->SetSelection( ltmp );
  156. aCfg->Read( KEYWORD_BRDCLASS_SELECTION, &ltmp, 0 );
  157. m_BoardClassesUnitsSelector->SetSelection( ltmp );
  158. // Regul panel config:
  159. aCfg->Read( KEYWORD_REGUL_R1, &msg, wxT( "10" ) );
  160. m_RegulR1Value->SetValue( msg );
  161. aCfg->Read( KEYWORD_REGUL_R2, &msg, wxT( "10" ) );
  162. m_RegulR2Value->SetValue( msg );
  163. aCfg->Read( KEYWORD_REGUL_VREF, &msg, wxT( "3" ) );
  164. m_RegulVrefValue->SetValue( msg );
  165. aCfg->Read( KEYWORD_REGUL_VOUT, &msg, wxT( "12" ) );
  166. m_RegulVoutValue->SetValue( msg );
  167. aCfg->Read( KEYWORD_DATAFILE_FILENAME, &msg, wxT( "" ) );
  168. SetDataFilename( msg );
  169. aCfg->Read( KEYWORD_REGUL_SELECTED, &msg, wxT( "" ) );
  170. m_lastSelectedRegulatorName = msg;
  171. aCfg->Read( KEYWORD_REGUL_TYPE, &ltmp, 0 );
  172. m_choiceRegType->SetSelection( ltmp );
  173. aCfg->Read( KEYWORD_REGUL_LAST_PARAM, &ltmp, 0 );
  174. wxRadioButton * regprms[3] =
  175. { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout
  176. };
  177. if( (unsigned)ltmp >= 3 )
  178. ltmp = 0;
  179. for( int ii = 0; ii < 3; ii++ )
  180. regprms[ii]->SetValue( ltmp == ii );
  181. // Electrical panel config
  182. aCfg->Read( KEYWORD_ELECTRICAL_SPACING_SELECTION, &ltmp, 0 );
  183. m_ElectricalSpacingUnitsSelector->SetSelection( ltmp );
  184. aCfg->Read( KEYWORD_ELECTRICAL_SPACING_VOLTAGE, &msg, wxT( "500" ) );
  185. m_ElectricalSpacingVoltage->SetValue( msg );
  186. for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
  187. m_transline_list[ii]->ReadConfig( aCfg );
  188. for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
  189. m_attenuator_list[ii]->ReadConfig( aCfg );
  190. }
  191. void PCB_CALCULATOR_FRAME::SaveSettings( wxConfigBase* aCfg )
  192. {
  193. if( aCfg == NULL )
  194. return;
  195. EDA_BASE_FRAME::SaveSettings( aCfg );
  196. aCfg->Write( KEYWORD_TRANSLINE_SELECTION, (long) m_currTransLineType );
  197. aCfg->Write( KEYWORD_PAGE_SELECTION, m_Notebook->GetSelection() );
  198. aCfg->Write( KEYWORD_COLORCODE_SELECTION, m_rbToleranceSelection->GetSelection() );
  199. aCfg->Write( KEYWORD_ATTENUATORS_SELECTION, m_AttenuatorsSelection->GetSelection() );
  200. aCfg->Write( KEYWORD_BRDCLASS_SELECTION, m_BoardClassesUnitsSelector->GetSelection() );
  201. aCfg->Write( KEYWORD_REGUL_R1, m_RegulR1Value->GetValue() );
  202. aCfg->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() );
  203. aCfg->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() );
  204. aCfg->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() );
  205. aCfg->Write( KEYWORD_DATAFILE_FILENAME, GetDataFilename() );
  206. aCfg->Write( KEYWORD_REGUL_SELECTED, m_lastSelectedRegulatorName );
  207. aCfg->Write( KEYWORD_REGUL_TYPE,
  208. m_choiceRegType->GetSelection() );
  209. wxRadioButton * regprms[3] =
  210. { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout
  211. };
  212. for( int ii = 0; ii < 3; ii++ )
  213. {
  214. if( regprms[ii]->GetValue() )
  215. {
  216. aCfg->Write( KEYWORD_REGUL_LAST_PARAM, ii );
  217. break;
  218. }
  219. }
  220. aCfg->Write( KEYWORD_ELECTRICAL_SPACING_SELECTION,
  221. m_ElectricalSpacingUnitsSelector->GetSelection() );
  222. aCfg->Write( KEYWORD_ELECTRICAL_SPACING_VOLTAGE,
  223. m_ElectricalSpacingVoltage->GetValue() );
  224. TW_WriteConfig( aCfg );
  225. for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
  226. m_transline_list[ii]->WriteConfig( aCfg );
  227. for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
  228. m_attenuator_list[ii]->WriteConfig( aCfg );
  229. }
  230. /**
  231. * Function OnTranslineAnalyse
  232. * Run a new analyse for the current transline with current parameters
  233. * and displays the electrical parmeters
  234. */
  235. void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event )
  236. {
  237. if( m_currTransLine )
  238. {
  239. TransfDlgDataToTranslineParams();
  240. m_currTransLine->analyze();
  241. }
  242. }
  243. /**
  244. * Function OnTranslineSynthetize
  245. * Run a new synthezis for the current transline with current parameters
  246. * and displays the geometrical parmeters
  247. */
  248. void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
  249. {
  250. if( m_currTransLine )
  251. {
  252. TransfDlgDataToTranslineParams();
  253. m_currTransLine->synthesize();
  254. }
  255. }
  256. void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event )
  257. {
  258. wxPaintDC dc( m_panelDisplayshape );
  259. TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
  260. if( tr_ident )
  261. {
  262. wxSize size = m_panelDisplayshape->GetSize();
  263. size.x -= tr_ident->m_Icon->GetWidth();
  264. size.y -= tr_ident->m_Icon->GetHeight();
  265. dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
  266. }
  267. event.Skip();
  268. }
  269. /* returns the full filename of the selected pcb_calculator data file
  270. * the extention file is forced
  271. */
  272. const wxString PCB_CALCULATOR_FRAME::GetDataFilename()
  273. {
  274. if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
  275. return wxEmptyString;
  276. wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
  277. fn.SetExt( DataFileNameExt );
  278. return fn.GetFullPath();
  279. }
  280. /* Initialize the full filename of the selected pcb_calculator data file
  281. * force the standard extension of the file (.pcbcalc)
  282. * aFilename = the full filename, with or without extension
  283. */
  284. void PCB_CALCULATOR_FRAME::SetDataFilename( const wxString & aFilename)
  285. {
  286. if( aFilename.IsEmpty() )
  287. m_regulators_fileNameCtrl->SetValue( wxEmptyString );
  288. else
  289. {
  290. wxFileName fn( aFilename );
  291. fn.SetExt( DataFileNameExt );
  292. m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
  293. }
  294. }