KiCad PCB EDA Suite
panel_eseries.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) 2011 jean-pierre.charras
5 * Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21/* see
22 * http://www.desmith.net/NMdS/Electronics/TraceWidth.html
23 * http://www.ultracad.com/articles/pcbtemp.pdf
24 * for more info
25 */
26
29#include <string_utils.h>
30#include <wx/msgdlg.h>
31
32#include <i18n_utility.h> // For _HKI definition in eseries_help.h
33wxString eseries_help =
34#include "eseries_help.h"
35
36
37extern double DoubleFromString( const wxString& TextValue );
38
39PANEL_E_SERIES::PANEL_E_SERIES( wxWindow* parent, wxWindowID id, const wxPoint& pos,
40 const wxSize& size, long style, const wxString& name ) :
41 PANEL_E_SERIES_BASE( parent, id, pos, size, style, name )
42{
43 m_reqResUnits->SetLabel( wxT( "kΩ" ) );
44 m_exclude1Units->SetLabel( wxT( "kΩ" ) );
45 m_exclude2Units->SetLabel( wxT( "kΩ" ) );
46
47 wxSize minSize = m_ResRequired->GetMinSize();
48 int minWidth = m_ResRequired->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
49
50 m_ResRequired->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
51 m_ResExclude1->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
52 m_ResExclude2->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
53
54 minSize = m_ESeriesError2R->GetMinSize();
55 minWidth = m_ESeriesError2R->GetTextExtent( wxT( "XX" ) + _( "Exact" ) ).GetWidth();
56
57 m_ESeriesError2R->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
58 m_ESeriesError3R->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
59 m_ESeriesError4R->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
60
61 // show markdown formula explanation in lower help panel
62 wxString msg;
63 ConvertMarkdown2Html( wxGetTranslation( eseries_help ), msg );
65
66 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
67 GetSizer()->SetSizeHints( this );
68}
69
70
72{
73}
74
75
77{
78 // Update the HTML window with the help text
80}
81
82
84{
85}
86
87
89{
90}
91
92
93void PANEL_E_SERIES::OnCalculateESeries( wxCommandEvent& event )
94{
95 double reqr; // required resistor stored in local copy
96 double error, err3 = 0;
97 wxString es, fs; // error and formula strings
98
99 wxBusyCursor dummy;
100
101 reqr = ( 1000 * DoubleFromString( m_ResRequired->GetValue() ) );
102 m_eSeries.SetRequiredValue( reqr ); // keep a local copy of required resistor value
103 m_eSeries.NewCalc(); // assume all values available
104 /*
105 * Exclude itself. For the case, a value from the available series is found as required value,
106 * the calculator assumes this value needs a replacement for the reason of being not available.
107 * Two further exclude values can be entered to exclude and are skipped as not being available.
108 * All values entered in KiloOhms are converted to Ohm for internal calculation
109 */
110 m_eSeries.Exclude( 1000 * DoubleFromString( m_ResRequired->GetValue()));
111 m_eSeries.Exclude( 1000 * DoubleFromString( m_ResExclude1->GetValue()));
112 m_eSeries.Exclude( 1000 * DoubleFromString( m_ResExclude2->GetValue()));
113
114 try
115 {
117 }
118 catch (std::out_of_range const& exc)
119 {
120 wxString msg;
121 msg << "Internal error: " << exc.what();
122
123 wxMessageBox( msg );
124 return;
125 }
126
127 fs = m_eSeries.GetResults()[S2R].e_name; // show 2R solution formula string
128 m_ESeries_Sol2R->SetValue( fs );
129 error = reqr + m_eSeries.GetResults()[S2R].e_value; // absolute value of solution
130 error = ( reqr / error - 1 ) * 100; // error in percent
131
132 if( error )
133 {
134 if( std::abs( error ) < 0.01 )
135 es.Printf( "<%.2f", 0.01 );
136 else
137 es.Printf( "%+.2f",error);
138 }
139 else
140 {
141 es = _( "Exact" );
142 }
143
144 m_ESeriesError2R->SetValue( es ); // anyway show 2R error string
145
146 if( m_eSeries.GetResults()[S3R].e_use ) // if 3R solution available
147 {
148 err3 = reqr + m_eSeries.GetResults()[S3R].e_value; // calculate the 3R
149 err3 = ( reqr / err3 - 1 ) * 100; // error in percent
150
151 if( err3 )
152 {
153 if( std::abs( err3 ) < 0.01 )
154 es.Printf( "<%.2f", 0.01 );
155 else
156 es.Printf( "%+.2f",err3);
157 }
158 else
159 {
160 es = _( "Exact" );
161 }
162
163 m_ESeriesError3R->SetValue( es ); // show 3R error string
164 fs = m_eSeries.GetResults()[S3R].e_name;
165 m_ESeries_Sol3R->SetValue( fs ); // show 3R formula string
166 }
167 else // nothing better than 2R found
168 {
169 fs = _( "Not worth using" );
170 m_ESeries_Sol3R->SetValue( fs );
171 m_ESeriesError3R->SetValue( wxEmptyString );
172 }
173
174 fs = wxEmptyString;
175
176 if( m_eSeries.GetResults()[S4R].e_use ) // show 4R solution if available
177 {
178 fs = m_eSeries.GetResults()[S4R].e_name;
179
180 error = reqr + m_eSeries.GetResults()[S4R].e_value; // absolute value of solution
181 error = ( reqr / error - 1 ) * 100; // error in percent
182
183 if( error )
184 es.Printf( "%+.2f",error );
185 else
186 es = _( "Exact" );
187
188 m_ESeriesError4R->SetValue( es );
189 }
190 else // no 4R solution
191 {
192 fs = _( "Not worth using" );
193 es = wxEmptyString;
194 m_ESeriesError4R->SetValue( es );
195 }
196
197 m_ESeries_Sol4R->SetValue( fs );
198}
199
200
201void PANEL_E_SERIES::OnESeriesSelection( wxCommandEvent& event )
202{
203 if( event.GetEventObject() == m_e1 )
205 else if( event.GetEventObject() == m_e3 )
207 else if( event.GetEventObject() == m_e12 )
209 else if( event.GetEventObject() == m_e24 )
211 else
213}
const char * name
Definition: DXF_plotter.cpp:56
void SetSeries(uint32_t aSeries)
Interface for CheckBox, RadioButton, RequriedResistor and calculated Results.
Definition: eseries.h:115
void Exclude(double aValue)
If any value of the selected E-series not available, it can be entered as an exclude value.
Definition: eseries.cpp:145
void Calculate()
called on calculate button to execute all the 2R, 3R and 4R calculations
Definition: eseries.cpp:333
void NewCalc()
initialize next calculation and erase results from previous calculation
Definition: eseries.cpp:232
void SetRequiredValue(double aValue)
Definition: eseries.h:116
const std::array< R_DATA, S4R+1 > & GetResults()
Definition: eseries.h:119
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
void ThemeChanged()
Definition: html_window.cpp:63
Class PANEL_E_SERIES_BASE.
wxTextCtrl * m_ESeries_Sol2R
wxTextCtrl * m_ESeriesError4R
wxTextCtrl * m_ESeriesError3R
wxTextCtrl * m_ESeries_Sol3R
HTML_WINDOW * m_panelESeriesHelp
wxRadioButton * m_e12
wxRadioButton * m_e24
wxTextCtrl * m_ResExclude1
wxTextCtrl * m_ESeries_Sol4R
wxTextCtrl * m_ResExclude2
wxRadioButton * m_e1
wxStaticText * m_exclude2Units
wxRadioButton * m_e3
wxStaticText * m_reqResUnits
wxStaticText * m_exclude1Units
wxTextCtrl * m_ResRequired
wxTextCtrl * m_ESeriesError2R
PANEL_E_SERIES(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnCalculateESeries(wxCommandEvent &event) override
Called on calculate button and executes all E-series calculations.
void OnESeriesSelection(wxCommandEvent &event) override
Radio Buttons to select the E-series for the resistor calculator.
void ThemeChanged() override
Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appr...
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
E_SERIES m_eSeries
Definition: panel_eseries.h:55
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
@ S3R
Definition: eseries.h:67
@ S2R
Definition: eseries.h:67
@ S4R
Definition: eseries.h:67
@ E6
Definition: eseries.h:62
@ E3
Definition: eseries.h:62
@ E24
Definition: eseries.h:62
@ E1
Definition: eseries.h:62
@ E12
Definition: eseries.h:62
Some functions to handle hotkeys in KiCad.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418
double DoubleFromString(const wxString &TextValue)
wxString eseries_help
std::vector< FAB_LAYER_COLOR > dummy
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)