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.

391 lines
13 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
  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2011 jean-pierre.charras
  5. * Copyright (C) 1992-2011 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 <wx/filename.h>
  27. #include <pcb_calculator_frame_base.h>
  28. #include <pcb_calculator.h>
  29. #include <UnitSelector.h>
  30. extern double DoubleFromString( const wxString& TextValue );
  31. // these values come from QucsStudio ( by Michael Margraf )
  32. // Display a selection of usual Er, TanD, Rho values
  33. // format is <value><space><comment>
  34. /**
  35. * Function OnEpsilonR_Button
  36. * Shows a list of current relative dielectric constant(Er)
  37. * and set the selected value in main dialog frame
  38. */
  39. void PCB_CALCULATOR_FRAME::OnTranslineEpsilonR_Button( wxCommandEvent& event )
  40. {
  41. wxArrayString list;
  42. // EpsilonR ( relative dielectric constant) list
  43. list.Add( wxT( "4.5 FR4" ) );
  44. list.Add( wxT( "9.8 alumina (Al2O3)" ) );
  45. list.Add( wxT( "3.78 fused quartz" ) );
  46. list.Add( wxT( "3.38 RO4003" ) );
  47. list.Add( wxT( "2.2 RT/duroid 5880" ) );
  48. list.Add( wxT( "10.2 RT/duroid 6010LM" ) );
  49. list.Add( wxT( "2.1 teflon (PTFE)" ) );
  50. list.Add( wxT( "4.0 PVC" ) );
  51. list.Add( wxT( "2.3 PE" ) );
  52. list.Add( wxT( "6.6 beryllia (BeO)" ) );
  53. list.Add( wxT( "8.7 aluminum nitride" ) );
  54. list.Add( wxT( "11.9 silicon" ) );
  55. list.Add( wxT( "12.9 GaAs" ) );
  56. wxString value = wxGetSingleChoice( wxEmptyString,
  57. _("Relative Dielectric Constants"), list).BeforeFirst( ' ' );
  58. if( ! value.IsEmpty() )
  59. m_Value_EpsilonR->SetValue( value );
  60. }
  61. /**
  62. * Function OnTanD_Button
  63. * Shows a list of current dielectric loss factor (tangent delta)
  64. * and set the selected value in main dialog frame
  65. */
  66. void PCB_CALCULATOR_FRAME::OnTranslineTanD_Button( wxCommandEvent& event )
  67. {
  68. wxArrayString list;
  69. // List of current dielectric loss factor (tangent delta)
  70. list.Clear();
  71. list.Add( wxT( "2e-2 FR4 @ 1GHz" ) );
  72. list.Add( wxT( "3e-4 beryllia @ 10GHz" ) );
  73. list.Add( wxT( "2e-4 aluminia (Al2O3) @ 10GHz" ) );
  74. list.Add( wxT( "1e-4 fused quartz @ 10GHz" ) );
  75. list.Add( wxT( "2e-3 RO4003 @ 10GHz" ) );
  76. list.Add( wxT( "9e-4 RT/duroid 5880 @ 10GHz" ) );
  77. list.Add( wxT( "2e-4 teflon (PTFE) @ 1MHz" ) );
  78. list.Add( wxT( "5e-2 PVC @ 1MHz" ) );
  79. list.Add( wxT( "2e-4 PE @ 1MHz" ) );
  80. list.Add( wxT( "1e-3 aluminum nitride @ 10GHz" ) );
  81. list.Add( wxT( "0.015 silicon @ 10GHz" ) );
  82. list.Add( wxT( "0.002 GaAs @ 10GHz" ) );
  83. wxString value = wxGetSingleChoice( wxEmptyString,
  84. _("Dielectric Loss Factor"), list).BeforeFirst( ' ' );
  85. if( ! value.IsEmpty() )
  86. m_Value_TanD->SetValue( value );
  87. }
  88. /**
  89. * Function OnTranslineRho_Button
  90. * Shows a list of current Specific resistance list (rho)
  91. * and set the selected value in main dialog frame
  92. */
  93. void PCB_CALCULATOR_FRAME::OnTranslineRho_Button( wxCommandEvent& event )
  94. {
  95. wxArrayString list;
  96. // Specific resistance list in ohms*meters (rho):
  97. list.Clear();
  98. list.Add( wxT( "2.4e-8 gold" ) );
  99. list.Add( wxT( "1.72e-8 copper" ) );
  100. list.Add( wxT( "1.62e-8 silver" ) );
  101. list.Add( wxT( "12.4e-8 tin" ) );
  102. list.Add( wxT( "10.5e-8 platinum" ) );
  103. list.Add( wxT( "2.62e-8 aluminum" ) );
  104. list.Add( wxT( "6.9e-8 nickel" ) );
  105. list.Add( wxT( "3.9e-8 brass (66Cu 34Zn)" ) );
  106. list.Add( wxT( "9.71e-8 iron" ) );
  107. list.Add( wxT( "6.0e-8 zinc" ) );
  108. wxString value = wxGetSingleChoice( wxEmptyString,
  109. _("Specific Resistance"), list).BeforeFirst( ' ' );
  110. if( ! value.IsEmpty() )
  111. m_Value_Rho->SetValue( value );
  112. }
  113. // Minor helper struct to handle dialog items for a given parameter
  114. struct DLG_PRM_DATA
  115. {
  116. wxStaticText * name;
  117. wxTextCtrl * value;
  118. UNIT_SELECTOR * unit;
  119. };
  120. /**
  121. * Function TranslineTypeSelection
  122. * Must be called after selection of a new transline.
  123. * Update all values, labels and tool tips of parameters needed
  124. * by the new transline
  125. * Irrelevant parameters texts are blanked.
  126. * @param aType = the transline_type_id of the new selected transline
  127. */
  128. void PCB_CALCULATOR_FRAME::TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType )
  129. {
  130. wxString msg;
  131. #define DOUBLE_TO_CTLR( dlg_item, value ) { msg.Printf( wxT( "%g" ), value );\
  132. dlg_item->SetValue( msg ); }
  133. m_currTransLineType = aType;
  134. if( (m_currTransLineType < START_OF_LIST_TYPE )
  135. || ( m_currTransLineType >= END_OF_LIST_TYPE ) )
  136. m_currTransLineType = DEFAULT_TYPE;
  137. // This helper bitmap is shown for coupled microstrip only:
  138. m_bmCMicrostripZoddZeven->Show( aType == C_MICROSTRIP_TYPE );
  139. m_fgSizerZcomment->Show( aType == C_MICROSTRIP_TYPE );
  140. TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
  141. m_currTransLine = tr_ident->m_TLine;
  142. m_radioBtnPrm1->Show( tr_ident->m_HasPrmSelection );
  143. m_radioBtnPrm2->Show( tr_ident->m_HasPrmSelection );
  144. // Setup messages
  145. wxStaticText* left_msg_list[] =
  146. {
  147. m_left_message1, m_left_message2, m_left_message3,
  148. m_left_message4, m_left_message5, m_left_message6,
  149. m_left_message7, NULL
  150. };
  151. wxStaticText* msg_list[] =
  152. {
  153. m_Message1, m_Message2, m_Message3,
  154. m_Message4, m_Message5, m_Message6,
  155. m_Message7, NULL
  156. };
  157. unsigned jj = 0;
  158. for( ; jj < tr_ident->m_Messages.GetCount(); jj++ )
  159. {
  160. if( left_msg_list[jj] == NULL )
  161. break;
  162. left_msg_list[jj]->SetLabel( tr_ident->m_Messages[jj] );
  163. msg_list[jj]->SetLabel( wxEmptyString );
  164. }
  165. while( left_msg_list[jj] )
  166. {
  167. left_msg_list[jj]->SetLabel( wxEmptyString );
  168. msg_list[jj]->SetLabel( wxEmptyString );
  169. jj++;
  170. }
  171. // Init parameters dialog items
  172. struct DLG_PRM_DATA substrateprms[] =
  173. {
  174. { m_EpsilonR_label,m_Value_EpsilonR, NULL },
  175. { m_TanD_label,m_Value_TanD, NULL },
  176. { m_Rho_label, m_Value_Rho, NULL },
  177. { m_substrate_prm4_label,m_Substrate_prm4_Value, m_SubsPrm4_choiceUnit },
  178. { m_substrate_prm5_label,m_Substrate_prm5_Value, m_SubsPrm5_choiceUnit },
  179. { m_substrate_prm6_label,m_Substrate_prm6_Value, m_SubsPrm6_choiceUnit },
  180. { m_substrate_prm7_label,m_Substrate_prm7_Value, m_SubsPrm7_choiceUnit },
  181. { m_substrate_prm8_label,m_Substrate_prm8_Value, m_SubsPrm8_choiceUnit },
  182. { m_substrate_prm9_label,m_Substrate_prm9_Value, m_SubsPrm9_choiceUnit }
  183. };
  184. #define substrateprms_cnt (sizeof(substrateprms)/sizeof(substrateprms[0]))
  185. struct DLG_PRM_DATA physprms[] =
  186. {
  187. { m_phys_prm1_label,m_Phys_prm1_Value,m_choiceUnit_Param1 },
  188. { m_phys_prm2_label,m_Phys_prm2_Value,m_choiceUnit_Param2 },
  189. { m_phys_prm3_label,m_Phys_prm3_Value,m_choiceUnit_Param3 }
  190. };
  191. #define physprms_cnt (sizeof(physprms)/sizeof(physprms[0]))
  192. struct DLG_PRM_DATA elecprms[] =
  193. {
  194. { m_elec_prm1_label,m_Elec_prm1_Value, m_choiceUnit_ElecPrm1 },
  195. { m_elec_prm2_label,m_Elec_prm2_Value, m_choiceUnit_ElecPrm2 },
  196. { m_elec_prm3_label,m_Elec_prm3_Value, m_choiceUnit_ElecPrm3 }
  197. };
  198. #define elecprms_cnt (sizeof(elecprms)/sizeof(elecprms[0]))
  199. struct DLG_PRM_DATA frequencyprms[] =
  200. {
  201. { m_Frequency_label,m_Value_Frequency_Ctrl, m_choiceUnit_Frequency }
  202. };
  203. #define frequencyprms_cnt (sizeof(frequencyprms)/sizeof(frequencyprms[0]))
  204. unsigned idxsubs = 0;
  205. unsigned idxphys = 0;
  206. unsigned idxelec = 0;
  207. unsigned idxfreq = 0;
  208. for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
  209. {
  210. TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
  211. struct DLG_PRM_DATA * data = NULL;
  212. switch( prm->m_Type )
  213. {
  214. case PRM_TYPE_SUBS:
  215. wxASSERT( idxsubs < substrateprms_cnt );
  216. data = &substrateprms[idxsubs];
  217. idxsubs++;
  218. break;
  219. case PRM_TYPE_PHYS:
  220. wxASSERT( idxphys < physprms_cnt );
  221. data = &physprms[idxphys];
  222. idxphys++;
  223. break;
  224. case PRM_TYPE_ELEC:
  225. wxASSERT( idxelec < elecprms_cnt );
  226. data = &elecprms[idxelec];
  227. idxelec++;
  228. break;
  229. case PRM_TYPE_FREQUENCY:
  230. wxASSERT( idxfreq < frequencyprms_cnt );
  231. data = &frequencyprms[idxfreq];
  232. idxfreq++;
  233. break;
  234. }
  235. wxASSERT ( data );
  236. data->name->SetToolTip( prm->m_ToolTip );
  237. data->name->SetLabel( prm->m_Label );
  238. prm->m_ValueCtrl = data->value;
  239. if( prm->m_Id != DUMMY_PRM )
  240. {
  241. DOUBLE_TO_CTLR( data->value, prm->m_Value );
  242. data->value->Enable( true );
  243. }
  244. else
  245. {
  246. data->value->SetValue( wxEmptyString );
  247. data->value->Enable( false );
  248. }
  249. if( prm->m_ConvUnit )
  250. prm->m_UnitCtrl = data->unit;
  251. if( data->unit )
  252. {
  253. data->unit->Show( prm->m_ConvUnit );
  254. data->unit->Enable( prm->m_ConvUnit );
  255. data->unit->SetSelection( prm->m_UnitSelection );
  256. }
  257. }
  258. // Clear all unused params
  259. for( ; idxsubs < substrateprms_cnt; idxsubs++ )
  260. {
  261. substrateprms[idxsubs].name->SetLabel(wxEmptyString);
  262. substrateprms[idxsubs].name->SetToolTip(wxEmptyString);
  263. substrateprms[idxsubs].value->SetValue(wxEmptyString);
  264. substrateprms[idxsubs].value->Enable( false );
  265. if( substrateprms[idxsubs].unit)
  266. {
  267. substrateprms[idxsubs].unit->Show( false );
  268. substrateprms[idxsubs].unit->Enable( false );
  269. substrateprms[idxsubs].unit->SetSelection( 0 );
  270. }
  271. }
  272. for( ; idxphys < physprms_cnt; idxphys++ )
  273. {
  274. physprms[idxphys].name->SetLabel(wxEmptyString);
  275. physprms[idxphys].name->SetToolTip(wxEmptyString);
  276. physprms[idxphys].value->SetValue(wxEmptyString);
  277. physprms[idxphys].value->Enable( false );
  278. if( physprms[idxphys].unit)
  279. {
  280. physprms[idxphys].unit->Show( false );
  281. physprms[idxphys].unit->Enable( false );
  282. physprms[idxphys].unit->SetSelection( 0 );
  283. }
  284. }
  285. for( ; idxelec < elecprms_cnt; idxelec++)
  286. {
  287. elecprms[idxelec].name->SetLabel(wxEmptyString);
  288. elecprms[idxelec].name->SetToolTip(wxEmptyString);
  289. elecprms[idxelec].value->SetValue(wxEmptyString);
  290. elecprms[idxelec].value->Enable( false );
  291. if( elecprms[idxelec].unit)
  292. {
  293. elecprms[idxelec].unit->Show( false );
  294. elecprms[idxelec].unit->Enable( false );
  295. elecprms[idxelec].unit->SetSelection( 0 );
  296. }
  297. }
  298. for( ; idxfreq < frequencyprms_cnt; idxfreq++ )
  299. {
  300. frequencyprms[idxfreq].name->SetLabel(wxEmptyString);
  301. frequencyprms[idxfreq].name->SetToolTip(wxEmptyString);
  302. frequencyprms[idxfreq].value->SetValue(wxEmptyString);
  303. frequencyprms[idxfreq].value->Enable( false );
  304. if( frequencyprms[idxfreq].unit )
  305. {
  306. frequencyprms[idxfreq].unit->Show( false );
  307. frequencyprms[idxfreq].unit->Enable( false );
  308. frequencyprms[idxfreq].unit->SetSelection( 0 );
  309. }
  310. }
  311. }
  312. /**
  313. * Function TransfDlgDataToTranslineParams
  314. * Read values entered in dialog frame, and copy these values
  315. * in current transline parameters, converted in normalized units
  316. */
  317. void PCB_CALCULATOR_FRAME::TransfDlgDataToTranslineParams()
  318. {
  319. TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
  320. for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
  321. {
  322. TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
  323. wxTextCtrl * value_ctrl = (wxTextCtrl * ) prm->m_ValueCtrl;
  324. wxString value_txt = value_ctrl->GetValue();
  325. double value = DoubleFromString(value_txt);
  326. prm->m_Value = value;
  327. UNIT_SELECTOR * unit_ctrl = (UNIT_SELECTOR * ) prm->m_UnitCtrl;
  328. if( unit_ctrl )
  329. {
  330. prm->m_UnitSelection = unit_ctrl->GetSelection();
  331. value *= unit_ctrl->GetUnitScale();
  332. }
  333. prm->m_NormalizedValue = value;
  334. }
  335. }
  336. /**
  337. * Function OnTranslineSelection
  338. * Called on new transmission line selection
  339. */
  340. void PCB_CALCULATOR_FRAME::OnTranslineSelection( wxCommandEvent& event )
  341. {
  342. enum TRANSLINE_TYPE_ID id = (enum TRANSLINE_TYPE_ID) event.GetSelection();
  343. TranslineTypeSelection( id );
  344. // Texts and units choice widgets can have their size modified:
  345. // The new size must be taken in account
  346. m_panelTransline->GetSizer()->Layout();
  347. m_panelTransline->Refresh();
  348. }