KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_electrical_spacing_iec60664.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) 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
20/* see
21 * http://www.desmith.net/NMdS/Electronics/TraceWidth.html
22 * http://www.ultracad.com/articles/pcbtemp.pdf
23 * for more info
24 */
27#include <string_utils.h>
28#include "iec60664.h"
29#include <wx/string.h>
30#include <widgets/html_window.h>
31#include <bitmaps.h>
32
33
34#include <i18n_utility.h> // For _HKI definition in iec60664_help.h
35wxString iec60664help =
36#include "iec60664_help.h"
37
38extern double DoubleFromString( const wxString& TextValue );
39
41 wxWindowID id,
42 const wxPoint& pos,
43 const wxSize& size,
44 long style,
45 const wxString& name ) :
46 PANEL_ELECTRICAL_SPACING_IEC60664_BASE( parent, id, pos, size, style, name )
47{
48 m_OVCchoice->SetSelection( 0 );
49 m_insulationType->SetSelection( 0 );
50 m_pollutionDegree->SetSelection( 0 );
51 m_materialGroup->SetSelection( 0 );
52
53 wxString msg;
54 ConvertMarkdown2Html( wxGetTranslation( iec60664help ), msg );
55 m_panelHelp->SetPage( msg );
56
57 m_creepageclearanceBitmap->SetBitmap( KiBitmapBundle( BITMAPS::creepage_clearance ) );
58
59 Layout();
60}
61
62
64{
65}
66
67
69{
70 m_creepageclearanceBitmap->SetBitmap( KiBitmapBundle( BITMAPS::creepage_clearance ) );
71}
72
73
75{
76 if( !aCfg )
77 return;
78
84
85 aCfg->m_Electrical.iec60664_OVC = m_OVCchoice->GetSelection();
89
90 aCfg->m_Electrical.iec60664_pcbMaterial = m_pcbMaterial->GetValue() ? 1 : 0;
91}
92
93
95{
96 if( !aCfg )
97 return;
98
99 m_ratedVoltage->SetValue( wxString( "" ) << aCfg->m_Electrical.iec60664_ratedVoltage );
100 m_RMSVoltage->SetValue( wxString( "" ) << aCfg->m_Electrical.iec60664_RMSvoltage );
101 m_transientOvervoltage->SetValue( wxString( "" ) << aCfg->m_Electrical.iec60664_transientOV );
102 m_peakVoltage->SetValue( wxString( "" ) << aCfg->m_Electrical.iec60664_peakOV );
103 m_altitude->SetValue( wxString( "" ) << aCfg->m_Electrical.iec60664_altitude );
104
105 m_OVCchoice->SetSelection( aCfg->m_Electrical.iec60664_OVC );
109
110 m_pcbMaterial->SetValue( aCfg->m_Electrical.iec60664_pcbMaterial ? true : false );
111
114}
115
116
118{
120
121 switch( m_OVCchoice->GetSelection() )
122 {
123 case 0: ovc = IEC60664::OV_CATEGORY::OV_I; break;
124 case 1: ovc = IEC60664::OV_CATEGORY::OV_II; break;
125 case 2: ovc = IEC60664::OV_CATEGORY::OV_III; break;
126 default: ovc = IEC60664::OV_CATEGORY::OV_IV; break;
127 }
128
129 wxString string = m_ratedVoltage->GetValue();
130 double value = 0;
131
132 if( string.ToDouble( &value ) )
133 {
134 IEC60664 cal;
135 cal.SetOvervoltageCategory( ovc );
136 cal.SetRatedVoltage( value );
137 string = "";
138 double result = cal.GetRatedImpulseWithstandVoltage();
139
140 if( result >= 0 )
141 string << result / 1000;
142 else
143 string << _( "Error" );
144
145 m_impulseVotlage1TxtCtrl->SetValue( string );
146 }
147}
148
149
151{
153}
154
155
157{
161
162 switch( m_insulationType->GetSelection() )
163 {
164 case 0: insul = IEC60664::INSULATION_TYPE::FUNCTIONAL; break;
165 case 1: insul = IEC60664::INSULATION_TYPE::BASIC; break;
166 default: insul = IEC60664::INSULATION_TYPE::REINFORCED; break;
167 }
168
169 switch( m_pollutionDegree->GetSelection() )
170 {
171 case 0: pd = IEC60664::POLLUTION_DEGREE::PD1; break;
172 case 1: pd = IEC60664::POLLUTION_DEGREE::PD2; break;
173 case 2: pd = IEC60664::POLLUTION_DEGREE::PD3; break;
174 default: pd = IEC60664::POLLUTION_DEGREE::PD4; break;
175 }
176
177 switch( m_materialGroup->GetSelection() )
178 {
179 case 0: mg = IEC60664::MATERIAL_GROUP::MG_I; break;
180 case 1: mg = IEC60664::MATERIAL_GROUP::MG_II; break;
181 case 2: mg = IEC60664::MATERIAL_GROUP::MG_IIIa; break;
182 default: mg = IEC60664::MATERIAL_GROUP::MG_IIIb; break;
183 }
184
185 double altitude = 0;
186 double transientV = 0;
187 double RMSV = 0;
188 double peakV = 0;
189
190 if( m_altitude->GetValue().ToDouble( &altitude )
191 && m_transientOvervoltage->GetValue().ToDouble( &transientV )
192 && m_peakVoltage->GetValue().ToDouble( &peakV )
193 && m_RMSVoltage->GetValue().ToDouble( &RMSV ) )
194 {
195 IEC60664 cal;
196 cal.SetPollutionDegree( pd );
197 cal.SetMaterialGroup( mg );
198 cal.SetInsulationType( insul );
199 cal.SetAltitude( altitude );
200 cal.SetTransientVoltage( transientV );
201 cal.SetPeakVoltage( peakV );
202 cal.SetRMSVoltage( RMSV );
203 cal.SetPCBMaterial( m_pcbMaterial->GetValue() );
204
205 cal.Compute();
206
207 double groove = cal.GetMinGrooveWidth();
208 double creepage = cal.GetCreepageDistance();
209 double clearange = cal.GetClearanceDistance();
210
211 wxString string;
212
213 if( groove >= 0 )
214 string << groove;
215 else
216 string << _( "Error" );
217
218 m_minGrooveWidth->SetValue( string );
219
220 string.Clear();
221
222 if( creepage >= 0 )
223 string << creepage;
224 else
225 string << _( "Error" );
226
227 m_creepage->SetValue( string );
228
229 string.Clear();
230
231 if( clearange >= 0 )
232 string << clearange;
233 else
234 string << _( "Error" );
235
236 m_clearance->SetValue( string );
237 }
238 else
239 {
240 m_minGrooveWidth->SetValue( _( "Error" ) );
241 m_creepage->SetValue( _( "Error" ) );
242 m_clearance->SetValue( _( "Error" ) );
243 }
244}
245
246
248{
250}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:50
void SetPollutionDegree(const POLLUTION_DEGREE aPD)
Definition: iec60664.h:80
double GetCreepageDistance()
Definition: iec60664.h:97
double GetRatedImpulseWithstandVoltage()
Definition: iec60664.cpp:595
void SetRatedVoltage(const double aV)
Definition: iec60664.h:87
void SetRMSVoltage(const double aV)
Definition: iec60664.h:88
void SetPCBMaterial(const bool aPCB)
Definition: iec60664.h:81
POLLUTION_DEGREE
Definition: iec60664.h:35
void SetTransientVoltage(const double aV)
Definition: iec60664.h:90
double GetMinGrooveWidth()
Definition: iec60664.h:95
void SetAltitude(const double aAltitude)
Definition: iec60664.h:79
void SetPeakVoltage(const double aV)
Definition: iec60664.h:89
INSULATION_TYPE
Definition: iec60664.h:60
bool Compute()
Definition: iec60664.cpp:1320
OV_CATEGORY
Definition: iec60664.h:43
MATERIAL_GROUP
Definition: iec60664.h:51
void SetMaterialGroup(const MATERIAL_GROUP aMG)
Definition: iec60664.h:82
void SetInsulationType(const INSULATION_TYPE aIns)
Definition: iec60664.h:84
void SetOvervoltageCategory(const OV_CATEGORY aOV)
Definition: iec60664.h:85
double GetClearanceDistance()
Definition: iec60664.h:96
Class PANEL_ELECTRICAL_SPACING_IEC60664_BASE.
void UpdateClearanceCreepage(wxCommandEvent &event) override
void UpdateTransientImpulse(wxCommandEvent &event) override
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
PANEL_ELECTRICAL_SPACING_IEC60664(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
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.
#define _(s)
Some functions to handle hotkeys in KiCad.
double DoubleFromString(const wxString &TextValue)
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)