KiCad PCB EDA Suite
pcb_calculator_frame.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2021 Kicad Developers, see AUTHORS.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 3
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 along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PCB_CALCULATOR_H
21 #define PCB_CALCULATOR_H
22 
23 #include "transline/transline.h" // Included for SUBST_PRMS_ID definition.
24 #include "transline_ident.h"
26 
28 #include "class_regulator_data.h"
29 
30 extern const wxString PcbCalcDataFileExt;
31 
32 class APP_SETTINGS_BASE;
33 class KIWAY;
35 
36 
37 /*
38  * Class PCB_CALCULATOR_FRAME_BASE
39  * This is the main frame for this application
40  */
42 {
43 public:
44  REGULATOR_LIST m_RegulatorList; // the list of known regulator
45 
46  PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
48 
49 private:
50  // Event handlers
51  void OnClosePcbCalc( wxCloseEvent& event ) override;
52 
53  void OnUpdateUI( wxUpdateUIEvent& event ) override;
54 
55  // Config read-write, virtual from EDA_BASE_FRAME
56  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
57  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
58 
59  // R/W data files:
60  bool ReadDataFile();
61  bool WriteDataFile();
62 
66  const wxString GetDataFilename();
67 
73  void SetDataFilename( const wxString& aFilename );
74 
78  void initTrackWidthPanel();
79  void initESeriesPanel();
80  void initColorCodePanel();
81  void initViaSizePanel();
82 
86  void OnCalculateESeries( wxCommandEvent& event ) override;
87 
92  void OnESeriesSelection( wxCommandEvent& event ) override;
93 
98  void writeTrackWidthConfig();
99 
105  void OnTWParametersChanged( wxCommandEvent& event ) override;
106 
112  void OnTWCalculateFromCurrent( wxCommandEvent& event ) override;
113 
119  void OnTWCalculateFromExtWidth( wxCommandEvent& event ) override;
120 
126  void OnTWCalculateFromIntWidth( wxCommandEvent& event ) override;
127 
133  void OnTWResetButtonClick( wxCommandEvent& event ) override;
134 
139  double TWCalculateWidth( double aCurrent, double aThickness, double aDeltaT_C,
140  bool aUseInternalLayer );
141 
146  double TWCalculateCurrent( double aWidth, double aThickness, double aDeltaT_C,
147  bool aUseInternalLayer );
148 
154  void TWDisplayValues( double aCurrent, double aExtWidth, double aIntWidth,
155  double aExtThickness, double aIntThickness );
156 
162  void TWUpdateModeDisplay();
163 
168  void writeViaSizeConfig();
169 
174  void OnViaCalculate( wxCommandEvent& event ) override;
175 
179  void OnViaEpsilonR_Button( wxCommandEvent& event ) override;
180 
184  void OnViaRho_Button( wxCommandEvent& event ) override;
185 
189  void onUpdateViaCalcErrorText( wxUpdateUIEvent& event ) override;
190 
195  void OnViaResetButtonClick( wxCommandEvent& event ) override;
196 
201  void VSDisplayValues( double aViaResistance, double aVoltageDrop, double aPowerLoss,
202  double aEstimatedAmpacity, double aThermalResistance,
203  double aCapacitance, double aTimeDegradation, double aInductance,
204  double aReactance );
205 
206  // Electrical spacing panel:
207  void OnElectricalSpacingUnitsSelection( wxCommandEvent& event ) override;
208  void OnElectricalSpacingRefresh( wxCommandEvent& event ) override;
209  void ElectricalSpacingUpdateData( double aUnitScale );
210 
215  void OnTranslineSelection( wxCommandEvent& event ) override;
216 
221  void OnTransLineResetButtonClick( wxCommandEvent& event ) override;
222 
228  void OnTranslineAnalyse( wxCommandEvent& event ) override;
229 
235  void OnTranslineSynthetize( wxCommandEvent& event ) override;
236 
242  void OnTranslineEpsilonR_Button( wxCommandEvent& event ) override;
243 
249  void OnTranslineTanD_Button( wxCommandEvent& event ) override;
250 
256  void OnTranslineRho_Button( wxCommandEvent& event ) override;
257 
264  void TranslineTypeSelection( enum TRANSLINE_TYPE_ID aType );
265 
272 
273  // Color Code panel
274  void OnToleranceSelection( wxCommandEvent& event ) override;
275  void ToleranceSelection( int aSelection );
276 
277  // Attenuators Panel
278  void OnAttenuatorSelection( wxCommandEvent& event ) override;
279  void SetAttenuator( unsigned aIdx );
280  void OnCalculateAttenuator( wxCommandEvent& event ) override;
284 
285  // Regulators Panel
286  void OnRegulatorCalcButtonClick( wxCommandEvent& event ) override;
287  void OnRegulatorResetButtonClick( wxCommandEvent& event ) override;
288  void OnRegulTypeSelection( wxCommandEvent& event ) override;
289  void OnRegulatorSelection( wxCommandEvent& event ) override;
290  void OnDataFileSelection( wxCommandEvent& event ) override;
291  void OnAddRegulator( wxCommandEvent& event ) override;
292  void OnEditRegulator( wxCommandEvent& event ) override;
293  void OnRemoveRegulator( wxCommandEvent& event ) override;
294 
300  void RegulatorPageUpdate();
301 
307 
308  void RegulatorsSolve();
309 
315 
316 public:
317  // Read/write params values and results
318 
325  void SetPrmValue( enum PRMS_ID aPrmId, double aValue );
326 
333  void SetResult( int aLineNumber, const wxString& aText );
334 
340  void SetPrmBgColor( enum PRMS_ID aPrmId, const KIGFX::COLOR4D* aCol );
347  double GetPrmValue( enum PRMS_ID aPrmId ) const;
348 
354  bool IsPrmSelected( enum PRMS_ID aPrmId ) const;
355 
356  // Board classes panel:
357  void OnBoardClassesUnitsSelection( wxCommandEvent& event ) override;
358  void BoardClassesUpdateData( double aUnitScale );
359 
360  // Calculator doesn't host a tool framework
361  wxWindow* GetToolCanvas() const override
362  {
363  return nullptr;
364  }
365 
366 private:
367  bool m_RegulatorListChanged; // Set when m_RegulatorList is modified and the corresponging file
368  // must be rewritten
369 
370  enum // Which dimension is controlling the track width / current
371  { // calculations:
372  TW_MASTER_CURRENT, // the maximum current,
373  TW_MASTER_EXT_WIDTH, // the external trace width,
374  TW_MASTER_INT_WIDTH // or the internal trace width?
375  } m_TWMode;
376 
377  bool m_TWNested; // Used to stop events caused by setting the answers.
378 
381  std::vector<TRANSLINE_IDENT*> m_transline_list;
382 
384  std::vector<ATTENUATOR*> m_attenuator_list;
385 
387 
389  wxBitmap* m_ccValuesBitmap;
392 
394  bool m_macHack;
395 };
396 
397 
398 extern const wxString DataFileNameExt;
399 
400 #endif // PCB_CALCULATOR_H
void ToleranceSelection(int aSelection)
Definition: colorcode.cpp:44
const wxString DataFileNameExt
void OnESeriesSelection(wxCommandEvent &event) override
Radio Buttons to select the E-serie for the resistor calculator.
Definition: eserie.cpp:382
void RegulatorPageUpdate()
Function RegulatorPageUpdate: Update the regulator page dialog display: enable the current regulator ...
void OnRegulatorSelection(wxCommandEvent &event) override
void OnTWParametersChanged(wxCommandEvent &event) override
Function OnTWParametersChanged Called when the user changes the general parameters (i....
void OnTransLineResetButtonClick(wxCommandEvent &event) override
Function OnTransLineResetButtonClick Called when the user clicks the reset button; sets the parameter...
void VSDisplayValues(double aViaResistance, double aVoltageDrop, double aPowerLoss, double aEstimatedAmpacity, double aThermalResistance, double aCapacitance, double aTimeDegradation, double aInductance, double aReactance)
Function VSDisplayValues Displays the results of the calculation.
Definition: via.cpp:247
PCB_CALCULATOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
void OnRegulatorResetButtonClick(wxCommandEvent &event) override
double TWCalculateCurrent(double aWidth, double aThickness, double aDeltaT_C, bool aUseInternalLayer)
Function TWCalculateCurrent Calculate maximum current based on given width and temperature rise.
void initViaSizePanel()
Definition: via.cpp:127
void OnTWResetButtonClick(wxCommandEvent &event) override
Function OnTWResetButtonClick Called when the user clicks the reset button.
void OnRegulTypeSelection(wxCommandEvent &event) override
enum PCB_CALCULATOR_FRAME::@39 m_TWMode
Class PCB_CALCULATOR_FRAME_BASE.
void OnUpdateUI(wxUpdateUIEvent &event) override
double TWCalculateWidth(double aCurrent, double aThickness, double aDeltaT_C, bool aUseInternalLayer)
Function TWCalculateWidth Calculate track width required based on given current and temperature rise.
void OnRemoveRegulator(wxCommandEvent &event) override
void OnRegulatorCalcButtonClick(wxCommandEvent &event) override
void SetResult(int aLineNumber, const wxString &aText)
Function SetResult Puts the text into the given result line.
void OnTWCalculateFromCurrent(wxCommandEvent &event) override
Function OnTWCalculateFromCurrent Called when the user changes the desired maximum current.
void TWUpdateModeDisplay()
Function TWUpdateModeDisplay Updates the fields to show whether the maximum current,...
void OnTWCalculateFromIntWidth(wxCommandEvent &event) override
Function OnTWCalculateFromIntWidth Called when the user changes the desired internal trace width.
void OnTranslineAnalyse(wxCommandEvent &event) override
Function OnTranslineAnalyse Run a new analyse for the current transline with current parameters and d...
void OnToleranceSelection(wxCommandEvent &event) override
Definition: colorcode.cpp:38
const wxString GetDataFilename()
void writeTrackWidthConfig()
Function writeTrackWidthConfig Write Track width parameters in config.
void OnTranslineEpsilonR_Button(wxCommandEvent &event) override
Function OnTranslineEpsilonR_Button Shows a list of current relative dielectric constant(Er) and set ...
bool IsPrmSelected(enum PRMS_ID aPrmId) const
Function IsPrmSelected.
void OnAddRegulator(wxCommandEvent &event) override
void SetPrmBgColor(enum PRMS_ID aPrmId, const KIGFX::COLOR4D *aCol)
Function SetPrgmBgColor Set the background color of a parameter.
void OnViaCalculate(wxCommandEvent &event) override
Function OnViaCalculate Called when the user changes any value in the via calcultor.
Definition: via.cpp:181
void OnElectricalSpacingRefresh(wxCommandEvent &event) override
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
void initESeriesPanel()
Definition: eserie.cpp:394
void initTrackWidthPanel()
Panel-specific initializers.
Contains structures for storage of regulator data.
void OnTranslineTanD_Button(wxCommandEvent &event) override
Function OnTranslineTanD_Button Shows a list of current dielectric loss factor (tangent delta) and se...
void OnViaRho_Button(wxCommandEvent &event) override
Function OnViaRho_Button.
Definition: via.cpp:77
PRMS_ID
Definition: transline.h:37
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void TransfDlgDataToTranslineParams()
Function TransfDlgDataToTranslineParams Read values entered in dialog frame, and transfert these valu...
void TransfPanelDataToAttenuator()
Definition: attenuators.cpp:66
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
void OnElectricalSpacingUnitsSelection(wxCommandEvent &event) override
void OnDataFileSelection(wxCommandEvent &event) override
void OnTranslineSynthetize(wxCommandEvent &event) override
Function OnTranslineSynthetize Run a new synthezis for the current transline with current parameters ...
void OnCalculateESeries(wxCommandEvent &event) override
Called on calculate button and executes all E-series calculations.
Definition: eserie.cpp:289
void OnClosePcbCalc(wxCloseEvent &event) override
enum TRANSLINE_TYPE_ID m_currTransLineType
TRANSLINE_TYPE_ID
void TranslineTypeSelection(enum TRANSLINE_TYPE_ID aType)
Function TranslineTypeSelection Must be called after selection of a new transline.
void OnEditRegulator(wxCommandEvent &event) override
void OnViaResetButtonClick(wxCommandEvent &event) override
Function OnViaResetButtonClick Called when the user clicks the reset button; sets the parameters to t...
Definition: via.cpp:102
double GetPrmValue(enum PRMS_ID aPrmId) const
Function GetPrmValue Returns a param value.
void OnViaEpsilonR_Button(wxCommandEvent &event) override
Function OnViaEpsilonR_Button.
Definition: via.cpp:63
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ElectricalSpacingUpdateData(double aUnitScale)
void OnCalculateAttenuator(wxCommandEvent &event) override
Definition: attenuators.cpp:58
void SetDataFilename(const wxString &aFilename)
Initialize the full filename of the selected pcb_calculator data file force the standard extension of...
REGULATOR_LIST m_RegulatorList
void OnAttenuatorSelection(wxCommandEvent &event) override
Definition: attenuators.cpp:37
void SetAttenuator(unsigned aIdx)
Definition: attenuators.cpp:44
std::vector< TRANSLINE_IDENT * > m_transline_list
wxWindow * GetToolCanvas() const override
Canvas access.
void OnBoardClassesUnitsSelection(wxCommandEvent &event) override
void OnTranslineSelection(wxCommandEvent &event) override
Function OnTranslineSelection Called on new transmission line selection.
void onUpdateViaCalcErrorText(wxUpdateUIEvent &event) override
Update the Error message in Via calculation panel.
Definition: via.cpp:88
void OnTWCalculateFromExtWidth(wxCommandEvent &event) override
Function OnTWCalculateFromExtWidth Called when the user changes the desired external trace width.
void writeViaSizeConfig()
Function writeViaSizeConfig Write Via Size parameters in config.
Definition: via.cpp:157
void Regulators_WriteConfig(PCB_CALCULATOR_SETTINGS *aCfg)
Write regulators parameters in config.
void TransfAttenuatorDataToPanel()
Definition: attenuators.cpp:79
void TWDisplayValues(double aCurrent, double aExtWidth, double aIntWidth, double aExtThickness, double aIntThickness)
Function TWDisplayValues Displays the results of a calculation (including resulting values such as th...
void SelectLastSelectedRegulator()
Function SelectLastSelectedRegulator If m_lastSelectedRegulatorName is empty, just calls RegulatorPag...
void SetPrmValue(enum PRMS_ID aPrmId, double aValue)
Function SetPrmValue Read/write params values and results.
void TransfAttenuatorResultsToPanel()
const wxString PcbCalcDataFileExt
void BoardClassesUpdateData(double aUnitScale)
std::vector< ATTENUATOR * > m_attenuator_list
void OnTranslineRho_Button(wxCommandEvent &event) override
Function OnTranslineRho_Button Shows a list of current Specific resistance list (rho) and set the sel...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98