From 493b42588aeb29d956c8ba050489435553701ab7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 25 Jul 2022 08:58:31 +0200 Subject: [PATCH] Pcb_calculator, PANEL_CABLE_SIZE: fix some issues created by non initialized vars. --- .../calculator_panels/panel_cable_size.cpp | 43 ++++++++++++++++--- .../calculator_panels/panel_cable_size.h | 29 ++++++------- .../panel_cable_size_base.cpp | 4 +- .../panel_cable_size_base.fbp | 2 +- .../calculator_panels/panel_cable_size_base.h | 2 +- 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/pcb_calculator/calculator_panels/panel_cable_size.cpp b/pcb_calculator/calculator_panels/panel_cable_size.cpp index 9ad102ddae..62c4d57602 100644 --- a/pcb_calculator/calculator_panels/panel_cable_size.cpp +++ b/pcb_calculator/calculator_panels/panel_cable_size.cpp @@ -24,15 +24,15 @@ #define M2_to_MM2 1000000.0 -#define COPPER_RESISTIVITY 1.72e-8 // ohm meter +#define COPPER_RESISTIVITY 1.72e-8 // ohm meter #define VACCUM_PERMEABILITY 1.256637e-6 #define RELATIVE_PERMEABILITY 1 -CABLE_SIZE_ENTRY::CABLE_SIZE_ENTRY( wxString aName, double aRadius ) +CABLE_SIZE_ENTRY::CABLE_SIZE_ENTRY( wxString aName, double aRadius_meter ) : + m_Name( aName ), + m_Radius( aRadius_meter ) { - m_name = aName; - m_radius = aRadius; } @@ -78,8 +78,37 @@ PANEL_CABLE_SIZE::PANEL_CABLE_SIZE( wxWindow* parent, wxWindowID id, const wxPoi for( CABLE_SIZE_ENTRY entry : m_entries ) { - m_sizeChoice->Append( entry.m_name ); + m_sizeChoice->Append( entry.m_Name ); } + + // Set internal state flags: + m_updatingUI = false; + m_updatingUI = false; + m_updatingDiameter = false; + m_updatingArea = false; + m_updatingLinResistance = false; + m_updatingFrequency = false; + m_updatingAmpacity = false; + m_updatingCurrent = false; + m_updatingLength = false; + m_updatingResistance = false; + m_updatingRVdrop = false; + m_updatingPower = false; + + m_imperial = false; + + // Initialize variables to a reasonable value + // Stored in normalized units + m_diameter = 0.001; + m_current = 1.0; + m_length = 1.0; + m_area = m_diameter * m_diameter / 4 * 3.14156; + m_linearResistance = 0.000813269; + m_maxFrequency = 17.4272; + m_resistance = 0.0218997; + m_voltageDrop = 0.0218997; + m_dissipatedPower = 0.0218997; + m_ampacity = 1.0; } @@ -111,7 +140,7 @@ void PANEL_CABLE_SIZE::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) m_lengthUnit->SetSelection( aCfg->m_cableSize.lengthUnit ); } -void PANEL_CABLE_SIZE::OnSizeChange( wxCommandEvent& aEvent ) +void PANEL_CABLE_SIZE::OnCableSizeChange( wxCommandEvent& aEvent ) { if( !m_updatingUI ) { @@ -121,7 +150,7 @@ void PANEL_CABLE_SIZE::OnSizeChange( wxCommandEvent& aEvent ) if( ( index >= 0 ) && ( index < m_entries.size() ) ) { - value = m_entries.at( index ).m_radius; + value = m_entries.at( index ).m_Radius; updateAll( value ); } } diff --git a/pcb_calculator/calculator_panels/panel_cable_size.h b/pcb_calculator/calculator_panels/panel_cable_size.h index d9bedfe43e..d40781b0dd 100644 --- a/pcb_calculator/calculator_panels/panel_cable_size.h +++ b/pcb_calculator/calculator_panels/panel_cable_size.h @@ -28,9 +28,10 @@ class PCB_CALCULATOR_SETTINGS; class CABLE_SIZE_ENTRY { public: - CABLE_SIZE_ENTRY( wxString aName, double aRadius ); - wxString m_name; - double m_radius; // stored in m + CABLE_SIZE_ENTRY( wxString aName, double aRadius_meter ); + + wxString m_Name; + double m_Radius; // stored in meters }; class PANEL_CABLE_SIZE : public PANEL_CABLE_SIZE_BASE @@ -46,7 +47,7 @@ public: void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override; void ThemeChanged() override{}; - void OnSizeChange( wxCommandEvent& aEvent ) override; + void OnCableSizeChange( wxCommandEvent& aEvent ) override; void OnUpdateUnit( wxCommandEvent& aEvent ) override; void OnDiameterChange( wxCommandEvent& aEvent ) override; @@ -61,6 +62,13 @@ public: void OnPowerChange( wxCommandEvent& aEvent ) override; private: + void updateAll( double aRadius ); + void updateApplication(); + void printAll(); + +private: + std::vector m_entries; + bool m_updatingUI; bool m_updatingDiameter; bool m_updatingArea; @@ -72,17 +80,9 @@ private: bool m_updatingResistance; bool m_updatingRVdrop; bool m_updatingPower; - void updateAll( double aRadius ); - void updateApplication(); - void printAll(); bool m_imperial; - - std::vector m_entries; - - void onParameterUpdate( wxCommandEvent& aEvent ); - // Stored in normalized units double m_diameter; double m_current; @@ -94,11 +94,6 @@ private: double m_voltageDrop; double m_dissipatedPower; double m_ampacity; - /* - void updateRow( int aRow, bool aInit=false ); - void updateRows(); - void OnUpdateLength(); -*/ }; #endif diff --git a/pcb_calculator/calculator_panels/panel_cable_size_base.cpp b/pcb_calculator/calculator_panels/panel_cable_size_base.cpp index 3da142ead7..e0caed0fb8 100644 --- a/pcb_calculator/calculator_panels/panel_cable_size_base.cpp +++ b/pcb_calculator/calculator_panels/panel_cable_size_base.cpp @@ -189,7 +189,7 @@ PANEL_CABLE_SIZE_BASE::PANEL_CABLE_SIZE_BASE( wxWindow* parent, wxWindowID id, c this->Layout(); // Connect Events - m_sizeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnSizeChange ), NULL, this ); + m_sizeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnCableSizeChange ), NULL, this ); m_diameterCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnDiameterChange ), NULL, this ); m_diameterUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnUpdateUnit ), NULL, this ); m_areaCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnAreaChange ), NULL, this ); @@ -209,7 +209,7 @@ PANEL_CABLE_SIZE_BASE::PANEL_CABLE_SIZE_BASE( wxWindow* parent, wxWindowID id, c PANEL_CABLE_SIZE_BASE::~PANEL_CABLE_SIZE_BASE() { // Disconnect Events - m_sizeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnSizeChange ), NULL, this ); + m_sizeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnCableSizeChange ), NULL, this ); m_diameterCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnDiameterChange ), NULL, this ); m_diameterUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnUpdateUnit ), NULL, this ); m_areaCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CABLE_SIZE_BASE::OnAreaChange ), NULL, this ); diff --git a/pcb_calculator/calculator_panels/panel_cable_size_base.fbp b/pcb_calculator/calculator_panels/panel_cable_size_base.fbp index 6051673eda..b82a248000 100644 --- a/pcb_calculator/calculator_panels/panel_cable_size_base.fbp +++ b/pcb_calculator/calculator_panels/panel_cable_size_base.fbp @@ -226,7 +226,7 @@ - OnSizeChange + OnCableSizeChange diff --git a/pcb_calculator/calculator_panels/panel_cable_size_base.h b/pcb_calculator/calculator_panels/panel_cable_size_base.h index 28dae9ed3d..242c9ae0af 100644 --- a/pcb_calculator/calculator_panels/panel_cable_size_base.h +++ b/pcb_calculator/calculator_panels/panel_cable_size_base.h @@ -73,7 +73,7 @@ class PANEL_CABLE_SIZE_BASE : public CALCULATOR_PANEL wxStaticText* m_staticText16121211; // Virtual event handlers, override them in your derived class - virtual void OnSizeChange( wxCommandEvent& event ) { event.Skip(); } + virtual void OnCableSizeChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnDiameterChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnUpdateUnit( wxCommandEvent& event ) { event.Skip(); } virtual void OnAreaChange( wxCommandEvent& event ) { event.Skip(); }