KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_galvanic_corrosion.cpp
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-2023 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
23#include <math/util.h> // for KiROUND
24#include <string_utils.h>
25#include <i18n_utility.h> // For _HKI definition in galvanic_corrosion_help.h
28
29extern double DoubleFromString( const wxString& TextValue );
30
31
32CORROSION_TABLE_ENTRY::CORROSION_TABLE_ENTRY( const wxString& aName, const wxString& aSymbol,
33 double aPotential )
34{
35 m_name = aName;
36 m_symbol = aSymbol;
37 m_potential = aPotential;
38}
39
41 const wxPoint& pos, const wxSize& size,
42 long style, const wxString& name ) :
43 PANEL_GALVANIC_CORROSION_BASE( parent, id, pos, size, style, name )
44{
45 m_entries.clear();
46 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Platinum" ), "Pt", -0.57 ) );
47 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Gold" ), "Au", -0.44 ) );
48 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Titanium" ), "Ti", -0.32 ) );
49 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Stainless steel 18-9" ), "X8CrNiS18-9", -0.32 ) );
50 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Silver" ), "Ag", -0.22 ) );
51 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Mercury" ), "Hg", -0.22 ) );
52 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Nickel" ), "Ni", -0.14 ) );
53 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Copper" ), "Cu", 0.0 ) );
54 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Copper-Aluminium" ), "CuAl10", 0.03 ) );
55 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Brass" ), "CuZn39Pb", 0.08 ) );
56 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Bronze" ), "CuSn12", 0.2 ) );
57 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Tin" ), "Sn", 0.23 ) );
58 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Lead" ), "Pb", 0.27 ) );
59 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Aluminium-Copper" ), "AlCu4Mg", 0.37 ) );
60 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Cast iron" ), "", 0.38 ) );
61 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Carbon steel" ), "", 0.43 ) );
62 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Aluminium" ), "Al", 0.52 ) );
63 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Cadmium" ), "Cd", 0.53 ) );
64 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Iron" ), "Fe", 0.535 ) );
65 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Chrome" ), "Cr", 0.63 ) );
66 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Zinc" ), "Zn", 0.83 ) );
67 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Manganese" ), "Mn", 0.9 ) );
68 m_entries.emplace_back( CORROSION_TABLE_ENTRY( _( "Magnesium" ), "Mg", 1.38 ) );
69
70 // Resize the table
71
72 m_table->DeleteCols( 0, m_table->GetNumberCols() );
73 m_table->DeleteRows( 0, m_table->GetNumberRows() );
74 m_table->AppendCols( (int) m_entries.size() );
75 m_table->AppendRows( (int) m_entries.size() );
76
77 // show markdown formula explanation in lower help panel
78 wxString msg;
79 ConvertMarkdown2Html( wxGetTranslation( galvanic_corrosion_help ), msg );
80 m_helpText->SetPage( msg );
81
82 m_symbolicStatus = true;
84
85 fillTable();
86}
87
88
90{
91}
92
94{
95 // Update the HTML window with the help text
97}
98
99
101{
104
105 bool refill_table = m_symbolicStatus != aCfg->m_CorrosionTable.show_symbols;
108 m_radioBtnName->SetValue( !m_symbolicStatus );
109
110 if( refill_table )
111 fillTable();
112}
113
114
116{
117 aCfg->m_CorrosionTable.threshold_voltage = wxString( "" ) << m_corFilterValue;
119}
120
122{
123
124 if( m_radioBtnSymbol->GetValue() )
125 {
126 m_symbolicStatus = true;
127 }
128 else if( m_radioBtnName->GetValue() )
129 {
130 m_symbolicStatus = false;
131 }
132
133 fillTable();
134}
135
136
138{
140 fillTable();
141}
142
143
145{
146
147 // Fill the table with data
148 int i = 0;
149 wxColour color_ok( 122, 166, 194 );
150 wxColour color_text( 0, 0, 0 );
151 wxString value;
152 wxString label;
153
154 for( const CORROSION_TABLE_ENTRY& entryA : m_entries )
155 {
156 int j = 0;
157
158 if( m_symbolicStatus == true )
159 {
160 if( entryA.m_symbol.size() > 0 )
161 {
162 label = entryA.m_symbol;
163 }
164 else
165 {
166 label = entryA.m_name;
167 }
168 }
169 else
170 {
171 if( entryA.m_name.size() > 0 )
172 {
173 label = entryA.m_name;
174 }
175 else
176 {
177 label = entryA.m_symbol;
178 }
179 }
180
181 m_table->SetRowLabelAlignment( wxALIGN_RIGHT, wxALIGN_CENTER );
182 m_table->SetRowLabelValue( i, label );
183 m_table->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTER );
184 m_table->SetColLabelValue( i, label );
185 m_table->SetCellAlignment( i, j, wxALIGN_CENTER, wxALIGN_CENTER );
186
187 for( const CORROSION_TABLE_ENTRY& entryB : m_entries )
188 {
189 double diff = entryA.m_potential - entryB.m_potential;
190 int diff_temp = KiROUND( abs( diff * 84 ) );
191 value = "";
192 value << diff * 1000; // Let's display it in mV instead of V.
193 m_table->SetCellValue( i, j, value );
194
195 // Overide anything that could come from a dark them
196 m_table->SetCellTextColour( i, j, color_text );
197
198 if( abs( diff ) == 0 )
199 {
200 m_table->SetCellBackgroundColour( i, j, wxColor( 193, 231, 255 ) );
201 }
202 else if( ( KiROUND( abs( diff * 1000 ) ) ) > m_corFilterValue )
203 {
204
205 if( diff > 0 )
206 {
207 m_table->SetCellBackgroundColour( i, j, wxColour( 202 - diff_temp,
208 206 - diff_temp,
209 225 - diff_temp ) );
210 }
211 else if( diff < 0 )
212 {
213 m_table->SetCellBackgroundColour( i, j, wxColour( 255 - diff_temp,
214 217 - diff_temp,
215 194 - diff_temp ) );
216 }
217 }
218 else
219 {
220 m_table->SetCellBackgroundColour( i, j, color_ok );
221 }
222
223 m_table->SetReadOnly( i, j, true );
224 j++;
225 }
226
227 i++;
228 }
229
230 m_table->SetColLabelTextOrientation( wxVERTICAL );
231
232 m_table->SetColLabelSize( wxGRID_AUTOSIZE );
233 m_table->SetRowLabelSize( wxGRID_AUTOSIZE );
234 m_table->AutoSizeColumns();
235 m_table->AutoSizeRows();
236
237 Layout();
238}
const char * name
Definition: DXF_plotter.cpp:57
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
wxString m_symbol
Chemical symbol (Cu), not translatable.
wxString m_name
Translatable name ( Copper )
double m_potential
potential in volts, relative to copper
CORROSION_TABLE_ENTRY(const wxString &aName, const wxString &aSymbol, double aPotential)
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:50
void ThemeChanged()
Definition: html_window.cpp:75
Class PANEL_GALVANIC_CORROSION_BASE.
void OnNomenclatureChange(wxCommandEvent &aEvent) override
PANEL_GALVANIC_CORROSION(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::vector< CORROSION_TABLE_ENTRY > m_entries
void ThemeChanged() override
Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appr...
void OnCorFilterChange(wxCommandEvent &aEvent) override
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
#define _(s)
Some functions to handle hotkeys in KiCad.
double DoubleFromString(const wxString &TextValue)
wxString galvanic_corrosion_help
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)