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