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.

326 lines
11 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
  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2015 Kicad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file pcb_calculator.h
  25. */
  26. #ifndef PCB_CALCULATOR_H
  27. #define PCB_CALCULATOR_H
  28. #include <pcb_calculator_frame_base.h>
  29. #include <transline.h> // Included for SUBST_PRMS_ID definition.
  30. #include <transline_ident.h>
  31. #include <attenuator_classes.h>
  32. #include <class_regulator_data.h>
  33. extern const wxString PcbCalcDataFileExt;
  34. /* Class PCB_CALCULATOR_FRAME_BASE
  35. This is the main frame for this application
  36. */
  37. class PCB_CALCULATOR_FRAME : public PCB_CALCULATOR_FRAME_BASE
  38. {
  39. public:
  40. REGULATOR_LIST m_RegulatorList; // the list of known regulator
  41. private:
  42. bool m_RegulatorListChanged; // set to true when m_RegulatorList
  43. // was modified, and the corresponging file
  44. // must be rewritten
  45. enum // Which dimension is controlling the track
  46. { // width / current calculations:
  47. TW_MASTER_CURRENT, // the maximum current,
  48. TW_MASTER_EXT_WIDTH, // the external trace width,
  49. TW_MASTER_INT_WIDTH // or the internal trace width?
  50. } m_TWMode;
  51. bool m_TWNested; // Used to stop events caused by setting the answers.
  52. enum TRANSLINE_TYPE_ID m_currTransLineType;
  53. TRANSLINE * m_currTransLine; // a pointer to the active transline
  54. // List of translines: ordered like in dialog menu list
  55. std::vector <TRANSLINE_IDENT *> m_transline_list;
  56. ATTENUATOR * m_currAttenuator;
  57. // List ofattenuators: ordered like in dialog menu list
  58. std::vector <ATTENUATOR *> m_attenuator_list;
  59. wxString m_lastSelectedRegulatorName; // last regulator name selected
  60. public:
  61. PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
  62. ~PCB_CALCULATOR_FRAME();
  63. private:
  64. // Event handlers
  65. void OnClosePcbCalc( wxCloseEvent& event ) override;
  66. // These 3 functions are called by the OnPaint event, to draw
  67. // icons that show the current item on the specific panels
  68. void OnPaintTranslinePanel( wxPaintEvent& event ) override;
  69. void OnPaintAttenuatorPanel( wxPaintEvent& event ) override;
  70. // Config read-write, virtual from EDA_BASE_FRAME
  71. void LoadSettings( wxConfigBase* aCfg ) override;
  72. void SaveSettings( wxConfigBase* aCfg ) override;
  73. // R/W data files:
  74. bool ReadDataFile();
  75. bool WriteDataFile();
  76. /**
  77. * @return the full filename of the selected pcb_calculator data file
  78. */
  79. const wxString GetDataFilename();
  80. /**
  81. * Initialize the full filename of the selected pcb_calculator data file
  82. * force the standard extension of the file (.pcbcalc)
  83. * @param aFilename = the full filename, with or without extension
  84. */
  85. void SetDataFilename( const wxString & aFilename);
  86. // Trace width / maximum current capability calculations.
  87. /**
  88. * Function TW_Init
  89. * Read config and init dialog widgets values
  90. */
  91. void TW_Init( wxConfigBase* aCfg );
  92. /**
  93. * Function TW_WriteConfig
  94. * Write Track width prameters in config
  95. */
  96. void TW_WriteConfig( wxConfigBase* aCfg );
  97. /**
  98. * Function OnTWParametersChanged
  99. * Called when the user changes the general parameters (i.e., anything that
  100. * is not one of the controlling values). This update the calculations.
  101. */
  102. void OnTWParametersChanged( wxCommandEvent& event ) override;
  103. /**
  104. * Function OnTWCalculateFromCurrent
  105. * Called when the user changes the desired maximum current. This sets the
  106. * current as the controlling value and performs the calculations.
  107. */
  108. void OnTWCalculateFromCurrent( wxCommandEvent& event ) override;
  109. /**
  110. * Function OnTWCalculateFromExtWidth
  111. * Called when the user changes the desired external trace width. This sets
  112. * the external width as the controlling value and performs the calculations.
  113. */
  114. void OnTWCalculateFromExtWidth( wxCommandEvent& event ) override;
  115. /**
  116. * Function OnTWCalculateFromIntWidth
  117. * Called when the user changes the desired internal trace width. This sets
  118. * the internal width as the controlling value and performs the calculations.
  119. */
  120. void OnTWCalculateFromIntWidth( wxCommandEvent& event ) override;
  121. /**
  122. * Function TWCalculateWidth
  123. * Calculate track width required based on given current and temperature rise.
  124. */
  125. double TWCalculateWidth( double aCurrent, double aThickness, double aDeltaT_C,
  126. bool aUseInternalLayer );
  127. /**
  128. * Function TWCalculateCurrent
  129. * Calculate maximum current based on given width and temperature rise.
  130. */
  131. double TWCalculateCurrent( double aWidth, double aThickness, double aDeltaT_C,
  132. bool aUseInternalLayer );
  133. /**
  134. * Function TWDisplayValues
  135. * Displays the results of a calculation (including resulting values such
  136. * as the resistance and power loss).
  137. */
  138. void TWDisplayValues( double aCurrent, double aExtWidth, double aIntWidth,
  139. double aExtThickness, double aIntThickness );
  140. /**
  141. * Function TWUpdateModeDisplay
  142. * Updates the fields to show whether the maximum current, external trace
  143. * width, or internal trace width is currently the controlling parameter.
  144. */
  145. void TWUpdateModeDisplay();
  146. // Electrical spacing panel:
  147. void OnElectricalSpacingUnitsSelection( wxCommandEvent& event ) override;
  148. void OnElectricalSpacingRefresh( wxCommandEvent& event ) override;
  149. void ElectricalSpacingUpdateData( double aUnitScale );
  150. // Transline functions:
  151. /**
  152. * Function OnTranslineSelection
  153. * Called on new transmission line selection
  154. */
  155. void OnTranslineSelection( wxCommandEvent& event ) override;
  156. /**
  157. * Function OnTranslineAnalyse
  158. * Run a new analyse for the current transline with current parameters
  159. * and displays the electrical parmeters
  160. */
  161. void OnTranslineAnalyse( wxCommandEvent& event ) override;
  162. /**
  163. * Function OnTranslineSynthetize
  164. * Run a new synthezis for the current transline with current parameters
  165. * and displays the geometrical parmeters
  166. */
  167. void OnTranslineSynthetize( wxCommandEvent& event ) override;
  168. /**
  169. * Function OnTranslineEpsilonR_Button
  170. * Shows a list of current relative dielectric constant(Er)
  171. * and set the selected value in main dialog frame
  172. */
  173. void OnTranslineEpsilonR_Button( wxCommandEvent& event ) override;
  174. /**
  175. * Function OnTranslineTanD_Button
  176. * Shows a list of current dielectric loss factor (tangent delta)
  177. * and set the selected value in main dialog frame
  178. */
  179. void OnTranslineTanD_Button( wxCommandEvent& event ) override;
  180. /**
  181. * Function OnTranslineRho_Button
  182. * Shows a list of current Specific resistance list (rho)
  183. * and set the selected value in main dialog frame
  184. */
  185. void OnTranslineRho_Button( wxCommandEvent& event ) override;
  186. /**
  187. * Function TranslineTypeSelection
  188. * Must be called after selection of a new transline.
  189. * Update all values, labels and tool tips of parameters needed
  190. * by the new transline
  191. * Irrelevant parameters texts are blanked.
  192. * @param aType = the TRANSLINE_TYPE_ID of the new selected transline
  193. */
  194. void TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType );
  195. /**
  196. * Function TransfDlgDataToTranslineParams
  197. * Read values entered in dialog frame, and transfert these
  198. * values in current transline parameters, converted in normalized units
  199. */
  200. void TransfDlgDataToTranslineParams();
  201. // Color Code panel
  202. void OnToleranceSelection( wxCommandEvent& event ) override;
  203. void ToleranceSelection( int aSelection );
  204. // Attenuators Panel
  205. void OnAttenuatorSelection( wxCommandEvent& event ) override;
  206. void SetAttenuator( unsigned aIdx );
  207. void OnCalculateAttenuator( wxCommandEvent& event ) override;
  208. void TransfPanelDataToAttenuator();
  209. void TransfAttenuatorDataToPanel();
  210. void TransfAttenuatorResultsToPanel();
  211. // Regulators Panel
  212. void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
  213. void OnRegulTypeSelection( wxCommandEvent& event ) override;
  214. void OnRegulatorSelection( wxCommandEvent& event ) override;
  215. void OnDataFileSelection( wxCommandEvent& event ) override;
  216. void OnAddRegulator( wxCommandEvent& event ) override;
  217. void OnEditRegulator( wxCommandEvent& event ) override;
  218. void OnRemoveRegulator( wxCommandEvent& event ) override;
  219. /**
  220. * Function RegulatorPageUpdate:
  221. * Update the regulator page dialog display:
  222. * enable the current regulator drawings and the formula used for calculations
  223. */
  224. void RegulatorPageUpdate();
  225. /**
  226. * Function SelectLastSelectedRegulator
  227. * select in choice box the last selected regulator
  228. * (name in m_lastSelectedRegulatorName)
  229. * and update the displayed values.
  230. * if m_lastSelectedRegulatorName is empty, just calls
  231. * RegulatorPageUpdate()
  232. */
  233. void SelectLastSelectedRegulator();
  234. void RegulatorsSolve();
  235. public:
  236. // Read/write params values and results
  237. /**
  238. * Function SetPrmValue
  239. * Read/write params values and results
  240. * @param aPrmId = param id to write
  241. * @param aValue = valmue to write
  242. */
  243. void SetPrmValue( enum PRMS_ID aPrmId, double aValue );
  244. /**
  245. * Function SetResult
  246. * Puts the text into the given result line.
  247. * @param aLineNumber = the line (0 to 5) wher to display the text
  248. * @param aText = the text to display
  249. */
  250. void SetResult( int aLineNumber, const wxString & aText );
  251. /**
  252. * Function GetPrmValue
  253. * Returns a param value.
  254. * @param aPrmId = param id to write
  255. * @return the value always in normalized unit (meter, Hz, Ohm, radian)
  256. */
  257. double GetPrmValue( enum PRMS_ID aPrmId );
  258. /**
  259. * Function IsPrmSelected
  260. * @return true if the param aPrmId is selected
  261. * Has meaning only for params that have a radio button
  262. */
  263. bool IsPrmSelected( enum PRMS_ID aPrmId );
  264. // Board classes panel:
  265. void OnBoardClassesUnitsSelection( wxCommandEvent& event ) override;
  266. void BoardClassesUpdateData( double aUnitScale );
  267. };
  268. extern const wxString DataFileNameExt;
  269. #endif // PCB_CALCULATOR_H