Pcb_calculator, PANEL_CABLE_SIZE: fix some issues created by non initialized vars.

This commit is contained in:
jean-pierre charras 2022-07-25 08:58:31 +02:00
parent e10158ff10
commit 493b42588a
5 changed files with 52 additions and 28 deletions

View File

@ -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 );
}
}

View File

@ -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<CABLE_SIZE_ENTRY> 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<CABLE_SIZE_ENTRY> 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

View File

@ -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 );

View File

@ -226,7 +226,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChoice">OnSizeChange</event>
<event name="OnChoice">OnCableSizeChange</event>
</object>
</object>
<object class="sizeritem" expanded="0">

View File

@ -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(); }