Corrosion table update

This commit is contained in:
aris-kimi 2022-10-03 18:03:03 +00:00 committed by jean-pierre charras
parent 230762053d
commit 788ecd91cd
8 changed files with 300 additions and 40 deletions

View File

@ -19,6 +19,10 @@
#include <calculator_panels/panel_corrosion.h>
#include <pcb_calculator_settings.h>
#include <widgets/unit_selector.h>
#include <math/util.h> // for KiROUND
extern double DoubleFromString( const wxString& TextValue );
#define CORROSION_VOLTAGE_1 0.3
#define CORROSION_VOLTAGE_2 0.5
@ -69,13 +73,48 @@ PANEL_CORROSION::PANEL_CORROSION( wxWindow* parent, wxWindowID id, const wxPoint
m_table->AppendCols( m_entries.size() );
m_table->AppendRows( m_entries.size() );
m_corFilterValue = 0;
FillTable();
// Needed on wxWidgets 3.0 to ensure sizers are correctly set
GetSizer()->SetSizeHints( this );
}
PANEL_CORROSION::~PANEL_CORROSION()
{
}
void PANEL_CORROSION::ThemeChanged()
{
}
void PANEL_CORROSION::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg )
{
m_corFilterCtrl->SetValue( aCfg->m_CorrosionTable.threshold_voltage );
m_corFilterValue = DoubleFromString( m_corFilterCtrl->GetValue() );
}
void PANEL_CORROSION::SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg )
{
aCfg->m_CorrosionTable.threshold_voltage = wxString( "" ) << m_corFilterValue;
}
void PANEL_CORROSION::OnCorFilterChange( wxCommandEvent& aEvent )
{
m_corFilterValue = DoubleFromString( m_corFilterCtrl->GetValue() );
FillTable();
}
void PANEL_CORROSION::FillTable()
{
// Fill the table with data
int i = 0;
wxColour color_ok( 189, 255, 189 );
wxColour color_w1( 255, 255, 157 );
wxColour color_w2( 250, 191, 9 );
wxColour color_w3( 255, 83, 83 );
wxColour color_ok( 122, 166, 194 );
wxColour color_text( 0, 0, 0 );
wxString value;
@ -97,6 +136,7 @@ PANEL_CORROSION::PANEL_CORROSION( wxWindow* parent, wxWindowID id, const wxPoint
for( CORROSION_TABLE_ENTRY entryB : m_entries )
{
double diff = entryA.m_potential - entryB.m_potential;
int diff_temp = KiROUND( abs( diff * 100 ) );
value = "";
value << diff * 1000; // Let's display it in mV instead of V.
m_table->SetCellValue( i, j, value );
@ -104,17 +144,14 @@ PANEL_CORROSION::PANEL_CORROSION( wxWindow* parent, wxWindowID id, const wxPoint
// Overide anything that could come from a dark them
m_table->SetCellTextColour( i, j, color_text );
if( abs( diff ) > CORROSION_VOLTAGE_3 )
if( ( abs( diff ) ) == 0 )
{
m_table->SetCellBackgroundColour( i, j, color_w3 );
m_table->SetCellBackgroundColour( i, j, wxColor( 193, 231, 255 ) );
}
else if( abs( diff ) > CORROSION_VOLTAGE_2 )
else if( ( KiROUND( abs( diff * 1000 ) ) ) > m_corFilterValue )
{
m_table->SetCellBackgroundColour( i, j, color_w2 );
}
else if( abs( diff ) > CORROSION_VOLTAGE_1 )
{
m_table->SetCellBackgroundColour( i, j, color_w1 );
m_table->SetCellBackgroundColour(
i, j, wxColour( 202 - diff_temp, 206 - diff_temp, 225 - diff_temp ) );
}
else
{
@ -125,33 +162,12 @@ PANEL_CORROSION::PANEL_CORROSION( wxWindow* parent, wxWindowID id, const wxPoint
}
i++;
}
m_table->SetColLabelTextOrientation( wxVERTICAL );
m_table->SetColLabelSize( wxGRID_AUTOSIZE );
m_table->SetRowLabelSize( wxGRID_AUTOSIZE );
m_table->AutoSizeColumns();
m_table->AutoSizeRows();
// Needed on wxWidgets 3.0 to ensure sizers are correctly set
GetSizer()->SetSizeHints( this );
}
PANEL_CORROSION::~PANEL_CORROSION()
{
}
void PANEL_CORROSION::ThemeChanged()
{
}
void PANEL_CORROSION::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg )
{
}
void PANEL_CORROSION::SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg )
{
Refresh();
}

View File

@ -50,6 +50,10 @@ public:
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override;
void ThemeChanged() override;
void OnCorFilterChange( wxCommandEvent& aEvent ) override;
private:
double m_corFilterValue;
void FillTable();
};
#endif

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -51,15 +51,38 @@ PANEL_CORROSION_BASE::PANEL_CORROSION_BASE( wxWindow* parent, wxWindowID id, con
bSizer7->Fit( m_scrolledWindow1 );
bSizer6->Add( m_scrolledWindow1, 1, wxEXPAND | wxALL, 5 );
m_staticText16 = new wxStaticText( this, wxID_ANY, _("When two metals are in contact, there will be a potential difference between them that will lead to corrosion.\nIn order to avoid corrosion, it is good practice to keep the difference below 300mV.\n\nOne of the metal will be anodic (+) and will be attacked. The other one will be cathodic and will be protected.\nIn the table below, if the number is positive then the row is anodic and the column is cathodic. \n\nYou can use an interface metal, just like with the ENIG surface finish that uses nickel as an interface between gold and copper to prevent corrosion."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText16 = new wxStaticText( this, wxID_ANY, _("This table shows the difference in electrochemical potential between various metals and alloys. A positive number indicates that the row is anodic and the column is cathodic.\nGalvanic corrosion affects different metals in contact and under certain conditions.\nThe anode of an electrochemical pair gets oxidized and eaten away, while the cathode gets dissolved metals plated onto it but stays protected.\nEN 50310 suggests a voltage difference below 300mV. Known practices make use of a third interface metal in between the main pair(ie the ENIG surface finish)."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText16->Wrap( -1 );
bSizer6->Add( m_staticText16, 0, wxALL, 5 );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
m_staticText2 = new wxStaticText( this, wxID_ANY, _("Threshold voltage:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 );
bSizer3->Add( m_staticText2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_corFilterCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizer3->Add( m_corFilterCtrl, 0, wxALL, 5 );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("mV"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 );
bSizer3->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT, 5 );
bSizer6->Add( bSizer3, 0, wxEXPAND, 5 );
this->SetSizer( bSizer6 );
this->Layout();
// Connect Events
m_corFilterCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CORROSION_BASE::OnCorFilterChange ), NULL, this );
}
PANEL_CORROSION_BASE::~PANEL_CORROSION_BASE()
{
// Disconnect Events
m_corFilterCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_CORROSION_BASE::OnCorFilterChange ), NULL, this );
}

View File

@ -242,7 +242,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">When two metals are in contact, there will be a potential difference between them that will lead to corrosion.&#x0A;In order to avoid corrosion, it is good practice to keep the difference below 300mV.&#x0A;&#x0A;One of the metal will be anodic (+) and will be attacked. The other one will be cathodic and will be protected.&#x0A;In the table below, if the number is positive then the row is anodic and the column is cathodic. &#x0A;&#x0A;You can use an interface metal, just like with the ENIG surface finish that uses nickel as an interface between gold and copper to prevent corrosion.</property>
<property name="label">This table shows the difference in electrochemical potential between various metals and alloys. A positive number indicates that the row is anodic and the column is cathodic.&#x0A;Galvanic corrosion affects different metals in contact and under certain conditions.&#x0A;The anode of an electrochemical pair gets oxidized and eaten away, while the cathode gets dissolved metals plated onto it but stays protected.&#x0A;EN 50310 suggests a voltage difference below 300mV. Known practices make use of a third interface metal in between the main pair(ie the ENIG surface finish).</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
@ -271,6 +271,204 @@
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer3</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Threshold voltage:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText2</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_corFilterCtrl</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnText">OnCorFilterChange</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">mV</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText3</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
</object>
</object>
</object>
</object>
</object>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5)
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -20,6 +20,7 @@
#include <wx/sizer.h>
#include <wx/scrolwin.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
///////////////////////////////////////////////////////////////////////////
@ -36,6 +37,13 @@ class PANEL_CORROSION_BASE : public CALCULATOR_PANEL
wxScrolledWindow* m_scrolledWindow1;
wxGrid* m_table;
wxStaticText* m_staticText16;
wxStaticText* m_staticText2;
wxTextCtrl* m_corFilterCtrl;
wxStaticText* m_staticText3;
// Virtual event handlers, override them in your derived class
virtual void OnCorFilterChange( wxCommandEvent& event ) { event.Skip(); }
public:

View File

@ -116,7 +116,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
AddCalculator( new PANEL_BOARD_CLASS( m_treebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ),
_("Board Classes") );
AddCalculator( new PANEL_CORROSION( m_treebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ),
_( "Galvanic corrosion" ) );
_( "Galvanic Corrosion" ) );
LoadSettings( config() );

View File

@ -236,6 +236,10 @@ PCB_CALCULATOR_SETTINGS::PCB_CALCULATOR_SETTINGS() :
m_params.emplace_back( new PARAM<wxString>( "via_size.pulse_rise_time",
&m_ViaSize.pulse_rise_time, "1" ) );
m_params.emplace_back( new PARAM<wxString>( "corrosion_table.threshold_voltage",
&m_CorrosionTable.threshold_voltage, "0" ) );
}

View File

@ -140,6 +140,11 @@ public:
wxString pulse_rise_time;
};
struct CORROSION_TABLE
{
wxString threshold_voltage;
};
PCB_CALCULATOR_SETTINGS();
virtual ~PCB_CALCULATOR_SETTINGS() {}
@ -171,6 +176,8 @@ public:
TRANSMISSION_LINE m_TransLine;
VIA_SIZE m_ViaSize;
CORROSION_TABLE m_CorrosionTable;
};
#endif