KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-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#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 VACCUM_PERMEABILITY 1.256637e-6
30#define RELATIVE_PERMEABILITY 1
31
32// The default current density in ampere by mm2 (3A/mm2 is common to make transformers)
33#define AMP_DENSITY_BY_MM2 3.0
34
35CABLE_SIZE_ENTRY::CABLE_SIZE_ENTRY( const wxString& aName, double aRadius_meter ) :
36 m_Name( aName ), m_Radius( aRadius_meter )
37{
38}
39
40
41PANEL_CABLE_SIZE::PANEL_CABLE_SIZE( wxWindow* parent, wxWindowID id, const wxPoint& pos,
42 const wxSize& size, long style, const wxString& name ) :
43 PANEL_CABLE_SIZE_BASE( parent, id, pos, size, style, name )
44{
46
47 m_stUnitOhmMeter->SetLabel( wxT( "Ω⋅m" ) );
48 m_stUnitDegC->SetLabel( wxT( "°C" ) );
49 m_stUnitOhm->SetLabel( wxT( "Ω" ) );
50 m_stUnitmmSq->SetLabel( wxT( "mm²" ) );
51 m_stUnitAmp_mmSq->SetLabel( wxT( "A/mm²" ) );
52
53 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
54 GetSizer()->SetSizeHints( this );
55
56 // Set internal state flags:
57 m_updatingUI = false;
58 m_updatingDiameter = false;
59 m_updatingArea = false;
61 m_updatingFrequency = false;
62 m_updatingAmpacity = false;
63 m_updatingCurrent = false;
64 m_updatingLength = false;
66 m_updatingRVdrop = false;
67 m_updatingPower = false;
69
70 m_imperial = false;
71
72 // Initialize variables to a reasonable value (stored in normalized units)
73 m_diameter = 0.001; // i.e. 1 mm2
75 m_current = 1.0;
76 m_length = 1.0;
77 m_conductorMaterialResitivity = 1.72e-8; //Initialized for copper
78 m_conductorMaterialResitivityRef = 1.72e-8; //Initialized for copper at 20 deg C
81
82 updateAll( m_diameter / 2 );
83}
84
85
87{
88}
89
90
92{
93 m_entries.clear();
94 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG0000" ), 0.005842 ) );
95 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG000" ), 0.00520192 ) );
96 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG00" ), 0.00463296 ) );
97 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG0" ), 0.00412623 ) );
98 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG1" ), 0.00367411 ) );
99 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG2" ), 0.00327152 ) );
100 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG3" ), 0.00291338 ) );
101 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG4" ), 0.00259461 ) );
102 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG5" ), 0.00231013 ) );
103 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG6" ), 0.00205740 ) );
104 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG7" ), 0.00183261 ) );
105 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG8" ), 0.00163195 ) );
106 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG9" ), 0.00145288 ) );
107 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG10" ), 0.00129413 ) );
108 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG11" ), 0.00115189 ) );
109 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG12" ), 0.00102616 ) );
110 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG13" ), 0.0009144 ) );
111 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG14" ), 0.00081407 ) );
112 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG15" ), 0.00072517 ) );
113 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG16" ), 0.00064516 ) );
114 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG17" ), 0.00057531 ) );
115 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG18" ), 0.00051181 ) );
116 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG19" ), 0.00045593 ) );
117 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG20" ), 0.0004046 ) );
118 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG21" ), 0.00036195 ) );
119 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG22" ), 0.00032258 ) );
120 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG23" ), 0.00028702 ) );
121 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG24" ), 0.00025527 ) );
122 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG25" ), 0.00022773 ) );
123 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG26" ), 0.00020193 ) );
124 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG27" ), 0.00018034 ) );
125 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG28" ), 0.00016002 ) );
126 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG29" ), 0.00014351 ) );
127 m_entries.emplace_back( CABLE_SIZE_ENTRY( _( "AWG30" ), 0.000127 ) );
128
129 for( CABLE_SIZE_ENTRY entry : m_entries )
130 {
131 m_sizeChoice->Append( entry.m_Name );
132 }
133}
134
135
136void PANEL_CABLE_SIZE::OnUpdateUnit( wxCommandEvent& aEvent )
137{
138 printAll();
139}
140
141
143{
144 aCfg->m_cableSize.diameterUnit = m_diameterUnit->GetSelection();
145 aCfg->m_cableSize.linResUnit = m_linResistanceUnit->GetSelection();
146 aCfg->m_cableSize.frequencyUnit = m_frequencyUnit->GetSelection();
147 aCfg->m_cableSize.lengthUnit = m_lengthUnit->GetSelection();
148 aCfg->m_cableSize.conductorMaterialResitivity = wxString( "" )
153}
154
155#include <wx/log.h>
157{
158 m_diameterUnit->SetSelection( aCfg->m_cableSize.diameterUnit );
159 m_linResistanceUnit->SetSelection( aCfg->m_cableSize.linResUnit );
160 m_frequencyUnit->SetSelection( aCfg->m_cableSize.frequencyUnit );
161 m_lengthUnit->SetSelection( aCfg->m_cableSize.lengthUnit );
165
166 int amp_per_mm2_choice = aCfg->m_cableSize.currentDensityChoice;
167
168 // Ensure validity of amp_per_mm2_choice
169 if( amp_per_mm2_choice < m_slCurrentDensity->GetMin()
170 || amp_per_mm2_choice > m_slCurrentDensity->GetMax() )
171 {
172 amp_per_mm2_choice = AMP_DENSITY_BY_MM2;
173 }
174
175 m_slCurrentDensity->SetValue( amp_per_mm2_choice );
176 m_amp_by_mm2 = amp_per_mm2_choice;
177
178 wxString value = wxString( "" ) << m_conductorMaterialResitivity;
179
180 if( m_textCtrlConductorResistivity->IsEmpty() || value == "nan" )
181 {
182 // Initialize m_textCtrl to fill UI space
183 // Working variable initialized earlier
184 m_textCtrlConductorResistivity->SetValue( "1.72e-8" );
185 m_conductorTempCtrl->SetValue( "20" );
186 }
187
188 if( m_textCtrlConductorThermCoef->IsEmpty() )
189 {
190 // Initialize m_textCtrl to fill UI space
191 // Working variable initialized earlier
192 m_textCtrlConductorThermCoef->SetValue( "3.93e-3" );
193 }
194
195 updateAll( m_diameter / 2 );
196}
197
198
199void PANEL_CABLE_SIZE::onUpdateCurrentDensity( wxScrollEvent& aEvent )
200{
201 m_amp_by_mm2 = m_slCurrentDensity->GetValue();
202
203 // Update displayed values depending on the current density (mainly Ampacity)
204 updateAll( m_diameter / 2 );
205}
206
207
208void PANEL_CABLE_SIZE::OnCableSizeChange( wxCommandEvent& aEvent )
209{
210 if( !m_updatingUI )
211 {
212 double value;
213 int index = m_sizeChoice->GetSelection();
214
215 if( ( index >= 0 ) && ( index < m_entries.size() ) )
216 {
217 value = m_entries.at( index ).m_Radius;
218 updateAll( value );
219 }
220 }
221}
222
223
225{
226 if( !m_updatingUI )
227 {
229
232 updateAll( m_diameter / 2 );
234 }
235}
236
237
239{
240 wxArrayString list = StandardCableConductorList();
241
242 // Shows a list of current Specific resistance list (rho) and select a value
243 wxString value = wxGetSingleChoice( wxEmptyString,
244 _( "Electrical Resistivity in Ohm*m at 20 deg C" ), list )
245 .BeforeFirst( ' ' );
246
247 if( !value.IsEmpty() )
248 m_textCtrlConductorResistivity->ChangeValue( value );
249
251}
252
254{
255 if( !m_updatingUI )
256 {
259 updateAll( m_diameter / 2 );
260 }
261}
262
264{
265 wxArrayString list = StandardCableTempCoefList();
266
267 // Shows a list of current Specific resistance list (rho) and select a value
268 wxString value = wxGetSingleChoice( wxEmptyString, _( "Temperature coefficient" ), list )
269 .BeforeFirst( ' ' );
270
271 if( !value.IsEmpty() )
272 m_textCtrlConductorThermCoef->ChangeValue( value );
273
275}
276
277void PANEL_CABLE_SIZE::OnDiameterChange( wxCommandEvent& aEvent )
278{
279 if( !m_updatingUI )
280 {
281 m_updatingDiameter = true;
282 double value;
283
284 if( m_diameterCtrl->GetValue().ToDouble( &value ) )
285 {
286 updateAll( value / 2 * m_diameterUnit->GetUnitScale() );
287 m_sizeChoice->SetSelection( -1 );
288 }
289 m_updatingDiameter = false;
290 }
291}
292
293
294void PANEL_CABLE_SIZE::OnLinResistanceChange( wxCommandEvent& aEvent )
295{
296 if( !m_updatingUI )
297 {
299 double value;
300
301 if( m_linResistanceCtrl->GetValue().ToDouble( &value ) )
302 {
304 / ( value * m_linResistanceUnit->GetUnitScale() ) / M_PI ) );
305 m_sizeChoice->SetSelection( -1 );
306 }
308 }
309}
310
311
312void PANEL_CABLE_SIZE::OnAreaChange( wxCommandEvent& aEvent )
313{
314 if( !m_updatingUI )
315 {
316 m_updatingArea = true;
317 double value;
318
319 if( m_areaCtrl->GetValue().ToDouble( &value ) )
320 {
321 updateAll( sqrt( value / M_PI / M2_to_MM2 ) );
322 m_sizeChoice->SetSelection( -1 );
323 }
324 m_updatingArea = false;
325 }
326}
327
328
329void PANEL_CABLE_SIZE::OnFrequencyChange( wxCommandEvent& aEvent )
330{
331 if( !m_updatingUI )
332 {
333 m_updatingFrequency = true;
334 double value;
335
336 if( m_frequencyCtrl->GetValue().ToDouble( &value ) )
337 {
340 m_sizeChoice->SetSelection( -1 );
341 }
342 m_updatingFrequency = false;
343 }
344}
345
346
347void PANEL_CABLE_SIZE::OnAmpacityChange( wxCommandEvent& aEvent )
348{
349 if( !m_updatingUI )
350 {
351 m_updatingAmpacity = true;
352 double value;
353
354 if( m_AmpacityCtrl->GetValue().ToDouble( &value ) )
355 {
356 double radius = sqrt( value * m2_by_ampere() / M_PI );
357 updateAll( radius );
358 m_sizeChoice->SetSelection( -1 );
359 }
360 m_updatingAmpacity = false;
361 }
362}
363
364void PANEL_CABLE_SIZE::OnConductorTempChange( wxCommandEvent& aEvent )
365{
366 if( !m_updatingUI )
367 {
368 double value;
369
370 if( m_conductorTempCtrl->GetValue().ToDouble( &value ) )
371 {
373 updateAll( m_diameter / 2 );
374 }
375 }
376}
377
378
379void PANEL_CABLE_SIZE::OnCurrentChange( wxCommandEvent& aEvent )
380{
381 if( !m_updatingUI )
382 {
383 double value;
384 m_updatingCurrent = true;
385
386 if( m_currentCtrl->GetValue().ToDouble( &value ) )
387 {
388 m_current = value;
390 }
391 m_updatingCurrent = false;
392 }
393}
394
395
396void PANEL_CABLE_SIZE::OnLengthChange( wxCommandEvent& aEvent )
397{
398 if( !m_updatingUI )
399 {
400 double value;
401 m_updatingLength = true;
402
403 if( m_lengthCtrl->GetValue().ToDouble( &value ) )
404 {
407 }
408 m_updatingLength = false;
409 }
410}
411
412
413void PANEL_CABLE_SIZE::OnResistanceDcChange( wxCommandEvent& aEvent )
414{
415 if( !m_updatingUI )
416 {
417 double value;
419
420 if( m_resistanceDcCtrl->GetValue().ToDouble( &value ) )
421 {
422 updateAll( sqrt( m_conductorMaterialResitivity / value * m_length / M_PI ) );
423 m_sizeChoice->SetSelection( -1 );
424 }
426 }
427}
428
429
430void PANEL_CABLE_SIZE::OnVDropChange( wxCommandEvent& aEvent )
431{
432 if( !m_updatingUI )
433 {
434 double value;
435 m_updatingRVdrop = true;
436
437 if( m_vDropCtrl->GetValue().ToDouble( &value ) )
438 {
440 * m_length * m_current / M_PI ) );
441 m_sizeChoice->SetSelection( -1 );
442 }
443 m_updatingRVdrop = false;
444 }
445}
446
447
448void PANEL_CABLE_SIZE::OnPowerChange( wxCommandEvent& aEvent )
449{
450 if( !m_updatingUI )
451 {
452 double value;
453 m_updatingPower = true;
454
455 if( m_powerCtrl->GetValue().ToDouble( &value ) )
456 {
458 * m_length * m_current * m_current / M_PI ) );
459 m_sizeChoice->SetSelection( -1 );
460 }
461 m_updatingPower = false;
462 }
463}
464
465
467{
468 m_updatingUI = true;
469
470 wxString value;
471 wxString tooltipString;
472
473 if( !m_updatingDiameter )
474 {
475 value = wxString( "" ) << m_diameter / m_diameterUnit->GetUnitScale();
476 m_diameterCtrl->SetValue( value );
477 }
478
479 if( !m_updatingArea )
480 {
481 value = wxString( "" ) << m_area * M2_to_MM2;
482 m_areaCtrl->SetValue( value );
483 }
484
485 if( !m_updatingAmpacity )
486 {
487 value = wxString( "" ) << m_ampacity;
488 m_AmpacityCtrl->SetValue( value );
489 }
490
492 {
493 value = wxString( "" ) << m_maxFrequency / m_frequencyUnit->GetUnitScale();
494 m_frequencyCtrl->SetValue( value );
495 }
496
498 {
499 value = wxString( "" ) << m_linearResistance / m_linResistanceUnit->GetUnitScale();
500 m_linResistanceCtrl->SetValue( value );
501 }
502
503 if( !m_updatingLength )
504 {
505 value = wxString( "" ) << m_length / m_lengthUnit->GetUnitScale();
506 m_lengthCtrl->SetValue( value );
507 }
508
510 {
511 //This is not really to update m_textCtrlConductorResistivity since we do not override user's input
512 //rather than update its tooltip
513 //value = wxString( "" ) << m_conductorMaterialResitivity;
514 value = wxString( "" ) << m_conductorMaterialResitivityRef;
515 m_textCtrlConductorResistivity->SetValue( value );
516 tooltipString = wxString( "Resistivity for " )
517 << m_conductorTemperature << wxString( " deg C is" )
518 << m_conductorMaterialResitivity << wxString( " Ohm*m" );
519 m_textCtrlConductorResistivity->SetToolTip( tooltipString );
520 }
521
522 if( !m_updatingCurrent )
523 {
524 value = wxString( "" ) << m_current;
525 m_currentCtrl->SetValue( value );
526 }
527
529 {
530 value = wxString( "" ) << m_resistanceDc;
531 m_resistanceDcCtrl->SetValue( value );
532 }
533
534 if( !m_updatingRVdrop )
535 {
536 value = wxString( "" ) << m_voltageDrop * m_vDropUnit->GetUnitScale();
537 m_vDropCtrl->SetValue( value );
538 }
539
540 if( !m_updatingPower )
541 {
542 value = wxString( "" ) << m_dissipatedPower * m_powerUnit->GetUnitScale();
543 m_powerCtrl->SetValue( value );
544 }
545
546 m_updatingUI = false;
547}
548
549
550void PANEL_CABLE_SIZE::updateAll( double aRadius )
551{
552 // Update wire properties
553 m_diameter = aRadius * 2;
554 m_area = M_PI * aRadius * aRadius;
559 // max frequency is when skin depth = radius
561 / ( M_PI * aRadius * aRadius * VACCUM_PERMEABILITY * RELATIVE_PERMEABILITY );
562
564
565 // Update application-specific values
569
570 printAll();
571}
572
574{
578
579 printAll();
580}
const char * name
Definition: DXF_plotter.cpp:57
CABLE_SIZE_ENTRY(const wxString &aName, double aRadius_meter)
Class PANEL_CABLE_SIZE_BASE.
UNIT_SELECTOR_LEN_CABLE * m_lengthUnit
UNIT_SELECTOR_POWER * m_powerUnit
UNIT_SELECTOR_FREQUENCY * m_frequencyUnit
wxTextCtrl * m_textCtrlConductorResistivity
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 onUpdateCurrentDensity(wxScrollEvent &aEvent) override
void OnLinResistanceChange(wxCommandEvent &aEvent) override
void OnAmpacityChange(wxCommandEvent &aEvent) override
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:390
#define AMP_DENSITY_BY_MM2
double DoubleFromString(const wxString &TextValue)
#define RELATIVE_PERMEABILITY
#define VACCUM_PERMEABILITY
#define M2_to_MM2