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 (C) 1992-2021 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 7
40#define CLASS_COUNT 10
41
42/* These values come from IPC2221
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" "A5" "A6" "A7"
50 * B1 - Internal Conductors
51 * B2 - External Conductors, uncoated, sea level to 3050 m
52 * B3 - External Conductors, uncoated, over 3050 m
53 * B4 - External Conductors, with permanent polymer coating (any elevation)
54 * A5 - External Conductors, with conformal coating over assembly (any elevation)
55 * A6 - External Component lead/termination, uncoated
56 * A7 - External Component lead termination, with conformal coating (any elevation)
57 */
58
59/* For voltages greater than 500V, the (per volt) table values
60 * must be added to the 500V values. For example, the elec-
61 * trical spacing for a Type B1 board with 600V is calculated
62 * as:
63 * 600V - 500V = 100V
64 * 0.25 mm + (100V x 0.0025
65 */
66static double clist[CLASS_COUNT][VALUE_COUNT] =
67{
68 { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.13 *
69 UNIT_MM,
70 0.13 * UNIT_MM }, // 0 ... 15V
71
72 { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.25 *
73 UNIT_MM,
74 0.13 * UNIT_MM }, // 16 ... 30V
75
76 { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 0.6 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.4 *
77 UNIT_MM,
78 0.13 * UNIT_MM }, // 31 ... 50V
79
80 { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 1.5 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.5 *
81 UNIT_MM,
82 0.13 * UNIT_MM }, // 51 ... 100V
83
84 { 0.2 * UNIT_MM, 0.6 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
85 UNIT_MM,
86 0.4 * UNIT_MM }, // 101 ... 150V
87
88 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
89 UNIT_MM,
90 0.4 * UNIT_MM }, // 151 ... 170V
91
92 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 6.4 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
93 UNIT_MM,
94 0.4 * UNIT_MM }, // 171 ... 250V
95
96 { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 12.5 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
97 UNIT_MM,
98 0.8 * UNIT_MM }, // 251 ... 300V
99
100 { 0.25 * UNIT_MM, 2.5 * UNIT_MM, 12.5 * UNIT_MM, 0.8 * UNIT_MM, 0.8 * UNIT_MM, 1.5 *
101 UNIT_MM,
102 0.8 * UNIT_MM }, // 301 ... 500V
103
104 // These last values are used to calculate spacing for voltage > 500V
105 // there are not the spacing
106 { 0.0025 * UNIT_MM, 0.005 * UNIT_MM, 0.025 * UNIT_MM, 0.00305 * UNIT_MM,
107 0.00305 * UNIT_MM, 0.00305 * UNIT_MM, 0.00305 * UNIT_MM }, // > 500V
108};
109
110
112 const wxPoint& pos, const wxSize& size,
113 long style, const wxString& name ) :
114 PANEL_ELECTRICAL_SPACING_IPC2221_BASE( parent, id, pos, size, style, name )
115{
116 // Autosize the row label column to be sure label are not truncated
117 m_gridElectricalSpacingValues->SetRowLabelSize( wxGRID_AUTOSIZE );
118
119 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
120 GetSizer()->SetSizeHints( this );
121}
122
123
125{
126}
127
128
130{
131 // TODO: Only the grid needs updating, but it isn't done automatically (https://trac.wxwidgets.org/ticket/19279)
132}
133
134
136{
139}
140
141
143{
146
148}
149
150
151
153{
155}
156
158{
160}
161
162
164{
165 wxString txt;
166 double voltage = 500.0; // to calculate values at V > 500V
167 txt = m_ElectricalSpacingVoltage->GetValue();
168
169 if( ! txt.IsEmpty() )
170 voltage = DoubleFromString( txt );
171
172 if( voltage < 500.0 )
173 voltage = 500.0;
174
175 txt.Printf( wxT( "%g" ), voltage );
176 m_ElectricalSpacingVoltage->SetValue( txt );
177
178 for( int ii = 0; ii < CLASS_COUNT-1; ii++ )
179 {
180 for( int jj = 0; jj < VALUE_COUNT; jj++ )
181 {
182 txt.Printf( wxT( "%g" ), clist[ii][jj] / aUnitScale );
183 m_gridElectricalSpacingValues->SetCellValue( ii, jj, txt );
184 }
185 }
186
187 for( int jj = 0; jj < VALUE_COUNT; jj++ )
188 {
189 double spacing = clist[CLASS_COUNT-2][jj];
190 double spacing_extra = clist[CLASS_COUNT-1][jj];
191 spacing += spacing_extra * ( voltage - 500.0 );
192 txt.Printf( wxT( "%g" ), spacing / aUnitScale );
193 m_gridElectricalSpacingValues->SetCellValue( CLASS_COUNT-1, jj, txt );
194 }
195
196 m_gridElectricalSpacingValues->SetRowLabelSize( wxGRID_AUTOSIZE );
197}
const char * name
Definition: DXF_plotter.cpp:57
Class PANEL_ELECTRICAL_SPACING_IPC2221_BASE.
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)
double GetUnitScale() override
Function GetUnitScale.
static BOARD_MIN_SIZE_VALUES clist[BRDCLASS_COUNT]
double DoubleFromString(const wxString &TextValue)
const double copper_resistivity
double DoubleFromString(const wxString &TextValue)
static double clist[CLASS_COUNT][VALUE_COUNT]
#define UNIT_MM
Definition: units_scales.h:34