KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_electrical_spacing_ipc2221.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 The 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>
31#include <units_scales.h>
32
33extern double DoubleFromString( const wxString& TextValue );
34
35// The IPC2221 formula used to calculate track width is valid only for copper material
36const double copper_resistivity = 1.72e-8;
37
38
39#define VALUE_COUNT 8
40#define CLASS_COUNT 10
41
42/* These values come from IPC2221C Dec 2023
43 * there are 10 voltage classes:
44 * "0 ... 15V" "16 ... 30V" "31 ... 50V" "51 ... 100V"
45 * "101 ... 150V" "151 ... 170V" "171 ... 250V"
46 * "251 ... 300V" "301 ... 500V" " > 500V"
47 * and for each voltage class
48 * there ar e 7 cases:
49 * "B1" "B2" "B3" "B4" "B5" "A6" "A7" "A8"
50 * B1 - Internal Conductors
51 * B2 - External Conductors, uncoated, sea level to 3050 m
52 * B3 - External Conductors, uncoated, over 3050 m or a vacuum
53 * B4 - External Conductors, with permanent polymer coating (any elevation)
54 * B5 - External Conductors, with conformal (any elevation or in a vacuum)
55 * A6 - External Component lead termination, with conformal coating (any elevation or in a vacuum)
56 * A7 - External Component lead/termination, uncoated, sea level to 3050 m
57 * A8 - External Component lead/termination, uncoated, over 3050m or in a vacuum
58 */
59
60/* For voltages greater than 500V, the (per volt) table values
61 * must be added to the 500V values. For example, the elec-
62 * trical spacing for a Type B1 board with 600V is calculated
63 * as:
64 * 600V - 500V = 100V
65 * 0.25 mm + (100V x 0.0025
66 */
67static double clist[CLASS_COUNT][VALUE_COUNT] =
68{
69 { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.075 * UNIT_MM, 0.075 * UNIT_MM, 0.13 * UNIT_MM,
70 0.13 * UNIT_MM, 0.13 * UNIT_MM, }, // 0 ... 15
71 { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.075 * UNIT_MM, 0.075 * UNIT_MM, 0.13 * UNIT_MM,
72 0.25 * UNIT_MM, 0.25 * UNIT_MM, }, // 16 ... 30
73 { 0.1 * UNIT_MM, 0.64 * UNIT_MM, 0.64 * UNIT_MM, 0.3 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM,
74 0.4 * UNIT_MM, 0.8 * UNIT_MM, }, // 31 ... 50
75 { 0.1 * UNIT_MM, 0.64 * UNIT_MM, 1.5 * UNIT_MM, 0.3 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM,
76 0.5 * UNIT_MM, 1 * UNIT_MM, }, // 51 ... 100
77 { 0.2 * UNIT_MM, 0.64 * UNIT_MM, 3.2 * UNIT_MM, 0.8 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM,
78 0.8 * UNIT_MM, 1.6 * UNIT_MM, }, // 101 ... 150
79 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 3.2 * UNIT_MM, 0.8 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM,
80 0.8 * UNIT_MM, 1.6 * UNIT_MM, }, // 151 ... 170
81 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 6.4 * UNIT_MM, 0.8 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM,
82 0.8 * UNIT_MM, 1.6 * UNIT_MM, }, // 171 ... 250
83 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 12.5 * UNIT_MM, 0.8 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM,
84 0.8 * UNIT_MM, 1.6 * UNIT_MM, }, // 251 ... 300
85 { 0.25 * UNIT_MM, 2.5 * UNIT_MM, 12.5 * UNIT_MM, 1.6 * UNIT_MM, 0.8 * UNIT_MM, 0.8 * UNIT_MM,
86 1.5 * UNIT_MM, 3 * UNIT_MM, }, // 301 ... 500
87
88
89 // These last values are used to calculate spacing for voltage > 500V
90 // there are not the spacing
91 { 0.0025 * UNIT_MM, 0.005 * UNIT_MM, 0.025 * UNIT_MM, 0.00305 * UNIT_MM, 0.00305 * UNIT_MM,
92 0.00305 * UNIT_MM, 0.00305 * UNIT_MM, 0.0061 * UNIT_MM, }, // >500
93
94};
95
96
98 const wxPoint& pos, const wxSize& size,
99 long style, const wxString& name ) :
100 PANEL_ELECTRICAL_SPACING_IPC2221_BASE( parent, id, pos, size, style, name )
101{
102 // Autosize the row label column to be sure label are not truncated
103 m_gridElectricalSpacingValues->SetRowLabelSize( wxGRID_AUTOSIZE );
104
105 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
106 GetSizer()->SetSizeHints( this );
107}
108
109
113
114
116{
117 // TODO: Only the grid needs updating, but it isn't done automatically (https://trac.wxwidgets.org/ticket/19279)
118}
119
120
126
127
135
136
137
142
147
148
150{
151 wxString txt;
152 double voltage = 500.0; // to calculate values at V > 500V
153 txt = m_ElectricalSpacingVoltage->GetValue();
154
155 if( ! txt.IsEmpty() )
156 voltage = DoubleFromString( txt );
157
158 if( voltage < 500.0 )
159 voltage = 500.0;
160
161 txt.Printf( wxT( "%g" ), voltage );
162 m_ElectricalSpacingVoltage->SetValue( txt );
163
164 for( int ii = 0; ii < CLASS_COUNT-1; ii++ )
165 {
166 for( int jj = 0; jj < VALUE_COUNT; jj++ )
167 {
168 txt.Printf( wxT( "%g" ), clist[ii][jj] / aUnitScale );
169 m_gridElectricalSpacingValues->SetCellValue( ii, jj, txt );
170 }
171 }
172
173 for( int jj = 0; jj < VALUE_COUNT; jj++ )
174 {
175 double spacing = clist[CLASS_COUNT-2][jj];
176 double spacing_extra = clist[CLASS_COUNT-1][jj];
177 spacing += spacing_extra * ( voltage - 500.0 );
178 txt.Printf( wxT( "%g" ), spacing / aUnitScale );
179 m_gridElectricalSpacingValues->SetCellValue( CLASS_COUNT-1, jj, txt );
180 }
181
182 m_gridElectricalSpacingValues->SetRowLabelSize( wxGRID_AUTOSIZE );
183}
const char * name
PANEL_ELECTRICAL_SPACING_IPC2221_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1300, 450), 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 LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
void OnElectricalSpacingRefresh(wxCommandEvent &event) override
void OnElectricalSpacingUnitsSelection(wxCommandEvent &event) override
PANEL_ELECTRICAL_SPACING_IPC2221(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
static BOARD_MIN_SIZE_VALUES clist[BRDCLASS_COUNT]
double DoubleFromString(const wxString &TextValue)
const double copper_resistivity
double DoubleFromString(const wxString &TextValue)
#define UNIT_MM