KiCad PCB EDA Suite
panel_cable_size.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-2022 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#include <wx/choicdlg.h>
20
21#include <common_data.h>
24#include <string_utils.h>
26
27extern double DoubleFromString( const wxString& TextValue );
28
29#define M2_to_MM2 1000000.0
30
31#define VACCUM_PERMEABILITY 1.256637e-6
32#define RELATIVE_PERMEABILITY 1
33
34
35CABLE_SIZE_ENTRY::CABLE_SIZE_ENTRY( wxString aName, double aRadius_meter ) :
36 m_Name( aName ),
37 m_Radius( aRadius_meter )
38{
39}
40
41
42PANEL_CABLE_SIZE::PANEL_CABLE_SIZE( wxWindow* parent, wxWindowID id, const wxPoint& pos,
43 const wxSize& size, long style, const wxString& name ) :
44 PANEL_CABLE_SIZE_BASE( parent, id, pos, size, style, name )
45{
46 m_entries.clear();
47 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG0000" ), 0.005842 ) );
48 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG000" ), 0.00520192 ) );
49 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG00" ), 0.00463296 ) );
50 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG0" ), 0.00412623 ) );
51 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG1" ), 0.00367411 ) );
52 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG2" ), 0.00327152 ) );
53 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG3" ), 0.00291338 ) );
54 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG4" ), 0.00259461 ) );
55 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG5" ), 0.00231013 ) );
56 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG6" ), 0.00205740 ) );
57 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG7" ), 0.00183261 ) );
58 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG8" ), 0.00163195 ) );
59 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG9" ), 0.00145288 ) );
60 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG10" ), 0.00129413 ) );
61 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG11" ), 0.00115189 ) );
62 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG12" ), 0.00102616 ) );
63 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG13" ), 0.0009144 ) );
64 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG14" ), 0.00081407 ) );
65 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG15" ), 0.00072517 ) );
66 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG16" ), 0.00064516 ) );
67 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG17" ), 0.00057531 ) );
68 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG18" ), 0.00051181 ) );
69 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG19" ), 0.00045593 ) );
70 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG20" ), 0.0004046 ) );
71 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG21" ), 0.00036195 ) );
72 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG22" ), 0.00032258 ) );
73 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG23" ), 0.00028702 ) );
74 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG24" ), 0.00025527 ) );
75 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG25" ), 0.00022773 ) );
76 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG26" ), 0.00020193 ) );
77 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG27" ), 0.00018034 ) );
78 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG28" ), 0.00016002 ) );
79 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG29" ), 0.00014351 ) );
80 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG30" ), 0.000127 ) );
81
82 for( CABLE_SIZE_ENTRY entry : m_entries )
83 {
84 m_sizeChoice->Append( entry.m_Name );
85 }
86
87 m_staticText16412->SetLabel( wxT( "Ω⋅m" ) );
88 m_staticText181->SetLabel( wxT( "°C" ) );
89 m_staticText161211->SetLabel( wxT( "Ω" ) );
90 m_staticText1641->SetLabel( wxT( "mm²" ) );
91
92 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
93 GetSizer()->SetSizeHints( this );
94
95 // Set internal state flags:
96 m_updatingUI = false;
97 m_updatingDiameter = false;
98 m_updatingArea = false;
100 m_updatingFrequency = false;
101 m_updatingAmpacity = false;
102 m_updatingCurrent = false;
103 m_updatingLength = false;
105 m_updatingRVdrop = false;
106 m_updatingPower = false;
108
109 m_imperial = false;
110
111 // Initialize variables to a reasonable value
112 // Stored in normalized units
113
114 m_diameter = 0.001;
116 m_current = 1.0;
117 m_length = 1.0;
118 m_conductorMaterialResitivity = 1.72e-8; //Initialized for copper
119 m_conductorMaterialResitivityRef = 1.72e-8; //Initialized for copper at 20 deg C
121
122 updateAll( m_diameter / 2 );
123}
124
125
126void PANEL_CABLE_SIZE::OnUpdateUnit( wxCommandEvent& aEvent )
127{
128 printAll();
129}
130
131
133{
134}
135
136
138{
139 aCfg->m_cableSize.diameterUnit = m_diameterUnit->GetSelection();
140 aCfg->m_cableSize.linResUnit = m_linResistanceUnit->GetSelection();
141 aCfg->m_cableSize.frequencyUnit = m_frequencyUnit->GetSelection();
142 aCfg->m_cableSize.lengthUnit = m_lengthUnit->GetSelection();
143 aCfg->m_cableSize.conductorMaterialResitivity = wxString( "" )
147}
148
149
151{
152 m_diameterUnit->SetSelection( aCfg->m_cableSize.diameterUnit );
153 m_linResistanceUnit->SetSelection( aCfg->m_cableSize.linResUnit );
154 m_frequencyUnit->SetSelection( aCfg->m_cableSize.frequencyUnit );
155 m_lengthUnit->SetSelection( aCfg->m_cableSize.lengthUnit );
159
160 wxString value = wxString( "" ) << m_conductorMaterialResitivity;
161
162 if( m_textCtrlConductorResistivity->IsEmpty() || value == "nan" )
163 {
164 //Initialize m_textCtrl to fill UI space
165 //Working variable initialized earlier
166 m_textCtrlConductorResistivity->SetValue( "1.72e-8" );
167 m_conductorTempCtrl->SetValue( "20" );
168 }
169
170 if( m_textCtrlConductorThermCoef->IsEmpty() )
171 {
172 //Initialize m_textCtrl to fill UI space
173 //Working variable initialized earlier
174 m_textCtrlConductorThermCoef->SetValue( "3.93e-3" );
175 }
176}
177
178void PANEL_CABLE_SIZE::OnCableSizeChange( wxCommandEvent& aEvent )
179{
180 if( !m_updatingUI )
181 {
182 double value;
183 int index = m_sizeChoice->GetSelection();
184
185 if( ( index >= 0 ) && ( index < m_entries.size() ) )
186 {
187 value = m_entries.at( index ).m_Radius;
188 updateAll( value );
189 }
190 }
191}
192
194{
195 if( !m_updatingUI )
196 {
198
201 updateAll( m_diameter / 2 );
203 }
204}
205
207{
208 wxArrayString list = StandardCableConductorList();
209
210 // Shows a list of current Specific resistance list (rho) and select a value
211 wxString value = wxGetSingleChoice( wxEmptyString,
212 _( "Electrical Resistivity in Ohm*m at 20 deg C" ), list )
213 .BeforeFirst( ' ' );
214
215 if( !value.IsEmpty() )
216 m_textCtrlConductorResistivity->ChangeValue( value );
217
219}
220
222{
223 if( !m_updatingUI )
224 {
227 updateAll( m_diameter / 2 );
228 }
229}
230
232{
233 wxArrayString list = StandardCableTempCoefList();
234
235 // Shows a list of current Specific resistance list (rho) and select a value
236 wxString value = wxGetSingleChoice( wxEmptyString, _( "Temperature coefficient" ), list )
237 .BeforeFirst( ' ' );
238
239 if( !value.IsEmpty() )
240 m_textCtrlConductorThermCoef->ChangeValue( value );
242}
243
244void PANEL_CABLE_SIZE::OnDiameterChange( wxCommandEvent& aEvent )
245{
246 if( !m_updatingUI )
247 {
248 m_updatingDiameter = true;
249 double value;
250
251 if( m_diameterCtrl->GetValue().ToDouble( &value ) )
252 {
253 updateAll( value / 2 * m_diameterUnit->GetUnitScale() );
254 m_sizeChoice->SetSelection( -1 );
255 }
256 m_updatingDiameter = false;
257 }
258}
259
260
261void PANEL_CABLE_SIZE::OnLinResistanceChange( wxCommandEvent& aEvent )
262{
263 if( !m_updatingUI )
264 {
266 double value;
267
268 if( m_linResistanceCtrl->GetValue().ToDouble( &value ) )
269 {
271 / ( value * m_linResistanceUnit->GetUnitScale() ) / M_PI ) );
272 m_sizeChoice->SetSelection( -1 );
273 }
275 }
276}
277
278
279void PANEL_CABLE_SIZE::OnAreaChange( wxCommandEvent& aEvent )
280{
281 if( !m_updatingUI )
282 {
283 m_updatingArea = true;
284 double value;
285
286 if( m_areaCtrl->GetValue().ToDouble( &value ) )
287 {
288 updateAll( sqrt( value / M_PI / M2_to_MM2 ) );
289 m_sizeChoice->SetSelection( -1 );
290 }
291 m_updatingArea = false;
292 }
293}
294
295
296void PANEL_CABLE_SIZE::OnFrequencyChange( wxCommandEvent& aEvent )
297{
298 if( !m_updatingUI )
299 {
300 m_updatingFrequency = true;
301 double value;
302
303 if( m_frequencyCtrl->GetValue().ToDouble( &value ) )
304 {
307 m_sizeChoice->SetSelection( -1 );
308 }
309 m_updatingFrequency = false;
310 }
311}
312
313
314void PANEL_CABLE_SIZE::OnAmpacityChange( wxCommandEvent& aEvent )
315{
316 if( !m_updatingUI )
317 {
318 m_updatingAmpacity = true;
319 double value;
320
321 if( m_AmpacityCtrl->GetValue().ToDouble( &value ) )
322 {
323 // Based on the 700 circular mils per amp rule of the thumb
324 // The long number is the sq m to circular mils conversion
325 updateAll( sqrt( value * 700 / 1973525241.77 / M_PI ) );
326 m_sizeChoice->SetSelection( -1 );
327 }
328 m_updatingAmpacity = false;
329 }
330}
331
332void PANEL_CABLE_SIZE::OnConductorTempChange( wxCommandEvent& aEvent )
333{
334 if( !m_updatingUI )
335 {
336 double value;
337
338 if( m_conductorTempCtrl->GetValue().ToDouble( &value ) )
339 {
341 updateAll( m_diameter / 2 );
342 }
343 }
344}
345
346
347void PANEL_CABLE_SIZE::OnCurrentChange( wxCommandEvent& aEvent )
348{
349 if( !m_updatingUI )
350 {
351 double value;
352 m_updatingCurrent = true;
353
354 if( m_currentCtrl->GetValue().ToDouble( &value ) )
355 {
356 m_current = value;
358 }
359 m_updatingCurrent = false;
360 }
361}
362
363
364void PANEL_CABLE_SIZE::OnLengthChange( wxCommandEvent& aEvent )
365{
366 if( !m_updatingUI )
367 {
368 double value;
369 m_updatingLength = true;
370
371 if( m_lengthCtrl->GetValue().ToDouble( &value ) )
372 {
375 }
376 m_updatingLength = false;
377 }
378}
379
380
381void PANEL_CABLE_SIZE::OnResistanceDcChange( wxCommandEvent& aEvent )
382{
383 if( !m_updatingUI )
384 {
385 double value;
387
388 if( m_resistanceDcCtrl->GetValue().ToDouble( &value ) )
389 {
390 updateAll( sqrt( m_conductorMaterialResitivity / value * m_length / M_PI ) );
391 m_sizeChoice->SetSelection( -1 );
392 }
394 }
395}
396
397
398void PANEL_CABLE_SIZE::OnVDropChange( wxCommandEvent& aEvent )
399{
400 if( !m_updatingUI )
401 {
402 double value;
403 m_updatingRVdrop = true;
404
405 if( m_vDropCtrl->GetValue().ToDouble( &value ) )
406 {
408 * m_length * m_current / M_PI ) );
409 m_sizeChoice->SetSelection( -1 );
410 }
411 m_updatingRVdrop = false;
412 }
413}
414
415
416void PANEL_CABLE_SIZE::OnPowerChange( wxCommandEvent& aEvent )
417{
418 if( !m_updatingUI )
419 {
420 double value;
421 m_updatingPower = true;
422
423 if( m_powerCtrl->GetValue().ToDouble( &value ) )
424 {
426 * m_length * m_current * m_current / M_PI ) );
427 m_sizeChoice->SetSelection( -1 );
428 }
429 m_updatingPower = false;
430 }
431}
432
433
435{
436 m_updatingUI = true;
437
438 wxString value;
439 wxString tooltipString;
440
441 if( !m_updatingDiameter )
442 {
443 value = wxString( "" ) << m_diameter / m_diameterUnit->GetUnitScale();
444 m_diameterCtrl->SetValue( value );
445 }
446
447 if( !m_updatingArea )
448 {
449 value = wxString( "" ) << m_area * M2_to_MM2;
450 m_areaCtrl->SetValue( value );
451 }
452
453 if( !m_updatingAmpacity )
454 {
455 value = wxString( "" ) << m_ampacity;
456 m_AmpacityCtrl->SetValue( value );
457 }
458
460 {
461 value = wxString( "" ) << m_maxFrequency / m_frequencyUnit->GetUnitScale();
462 m_frequencyCtrl->SetValue( value );
463 }
464
466 {
467 value = wxString( "" ) << m_linearResistance / m_linResistanceUnit->GetUnitScale();
468 m_linResistanceCtrl->SetValue( value );
469 }
470
471 if( !m_updatingLength )
472 {
473 value = wxString( "" ) << m_length / m_lengthUnit->GetUnitScale();
474 m_lengthCtrl->SetValue( value );
475 }
476
478 {
479 //This is not really to update m_textCtrlConductorResistivity since we do not override user's input
480 //rather than update its tooltip
481 //value = wxString( "" ) << m_conductorMaterialResitivity;
482 value = wxString( "" ) << m_conductorMaterialResitivityRef;
483 m_textCtrlConductorResistivity->SetValue( value );
484 tooltipString = wxString( "Resistivity for " )
485 << m_conductorTemperature << wxString( " deg C is" )
486 << m_conductorMaterialResitivity << wxString( " Ohm*m" );
487 m_textCtrlConductorResistivity->SetToolTip( tooltipString );
488 }
489
490 if( !m_updatingCurrent )
491 {
492 value = wxString( "" ) << m_current;
493 m_currentCtrl->SetValue( value );
494 }
495
497 {
498 value = wxString( "" ) << m_resistanceDc;
499 m_resistanceDcCtrl->SetValue( value );
500 }
501
502 if( !m_updatingRVdrop )
503 {
504 value = wxString( "" ) << m_voltageDrop * m_vDropUnit->GetUnitScale();
505 m_vDropCtrl->SetValue( value );
506 }
507
508 if( !m_updatingPower )
509 {
510 value = wxString( "" ) << m_dissipatedPower * m_powerUnit->GetUnitScale();
511 m_powerCtrl->SetValue( value );
512 }
513
514 m_updatingUI = false;
515}
516
517
518void PANEL_CABLE_SIZE::updateAll( double aRadius )
519{
520 // Update wire properties
521 m_diameter = aRadius * 2;
522 m_area = M_PI * aRadius * aRadius;
527 // max frequency is when skin depth = radius
529 / ( M_PI * aRadius * aRadius * VACCUM_PERMEABILITY * RELATIVE_PERMEABILITY );
530
531 // Based on the 700 circular mils per amp rule of the thumb
532 // The long number is the sq m to circular mils conversion
533 m_ampacity = ( m_area * 1973525241.77 ) / 700;
534
535 // Update application-specific values
539
540 printAll();
541}
542
544{
548
549 printAll();
550}
const char * name
Definition: DXF_plotter.cpp:56
CABLE_SIZE_ENTRY(wxString aName, double aRadius_meter)
Class PANEL_CABLE_SIZE_BASE.
UNIT_SELECTOR_LEN_CABLE * m_lengthUnit
wxStaticText * m_staticText161211
UNIT_SELECTOR_POWER * m_powerUnit
UNIT_SELECTOR_FREQUENCY * m_frequencyUnit
wxTextCtrl * m_textCtrlConductorResistivity
wxStaticText * m_staticText16412
UNIT_SELECTOR_LEN * m_diameterUnit
UNIT_SELECTOR_VOLTAGE * m_vDropUnit
UNIT_SELECTOR_LINEAR_RESISTANCE * m_linResistanceUnit
wxTextCtrl * m_textCtrlConductorThermCoef
void updateAll(double aRadius)
void OnCurrentChange(wxCommandEvent &aEvent) override
double m_conductorMaterialThermalCoef
void OnFrequencyChange(wxCommandEvent &aEvent) override
void OnResistanceDcChange(wxCommandEvent &aEvent) override
bool m_updatingConductorMaterialResitivity
void OnCableSizeChange(wxCommandEvent &aEvent) override
void OnUpdateUnit(wxCommandEvent &aEvent) override
void OnConductorResistivity_Button(wxCommandEvent &aEvent) override
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
void OnVDropChange(wxCommandEvent &aEvent) override
void OnConductorThermCoefChange(wxCommandEvent &aEvent) override
double m_conductorMaterialResitivity
void OnAreaChange(wxCommandEvent &aEvent) override
void OnPowerChange(wxCommandEvent &aEvent) override
double m_conductorMaterialResitivityRef
void OnDiameterChange(wxCommandEvent &aEvent) override
void OnConductorResistivityChange(wxCommandEvent &aEvent) override
void OnConductorThermCoefChange_Button(wxCommandEvent &aEvent) override
void OnLinResistanceChange(wxCommandEvent &aEvent) override
void OnAmpacityChange(wxCommandEvent &aEvent) override
double m_conductorTemperature
void OnConductorTempChange(wxCommandEvent &aEvent) override
std::vector< CABLE_SIZE_ENTRY > m_entries
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
void OnLengthChange(wxCommandEvent &aEvent) override
PANEL_CABLE_SIZE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
wxArrayString StandardCableConductorList()
wxArrayString StandardCableTempCoefList()
#define _(s)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418
#define M2_to_MM2
double DoubleFromString(const wxString &TextValue)
#define RELATIVE_PERMEABILITY
#define VACCUM_PERMEABILITY