KiCad PCB EDA Suite
electrical_spacing_values.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) 2011 Kicad Developers, see change_log.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 2
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
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <wx/app.h>
26 
27 #include "pcb_calculator_frame.h"
28 #include "units_scales.h"
29 
30 extern double DoubleFromString( const wxString& TextValue );
31 
32 
33 #define VALUE_COUNT 7
34 #define CLASS_COUNT 10
35 
36 /* These values come from IPC2221
37  * there are 10 voltage classes:
38  * "0 ... 15V" "16 ... 30V" "31 ... 50V" "51 ... 100V"
39  * "101 ... 150V" "151 ... 170V" "171 ... 250V"
40  * "251 ... 300V" "301 ... 500V" " > 500V"
41  * and for each voltage class
42  * there ar e 7 cases:
43  * "B1" "B2" "B3" "B4" "A5" "A6" "A7"
44  * B1 - Internal Conductors
45  * B2 - External Conductors, uncoated, sea level to 3050 m
46  * B3 - External Conductors, uncoated, over 3050 m
47  * B4 - External Conductors, with permanent polymer coating (any elevation)
48  * A5 - External Conductors, with conformal coating over assembly (any elevation)
49  * A6 - External Component lead/termination, uncoated
50  * A7 - External Component lead termination, with conformal coating (any elevation)
51  */
52 
53 /* For voltages greater than 500V, the (per volt) table values
54  * must be added to the 500V values. For example, the elec-
55  * trical spacing for a Type B1 board with 600V is calculated
56  * as:
57  * 600V - 500V = 100V
58  * 0.25 mm + (100V x 0.0025
59  */
60 static double clist[CLASS_COUNT][VALUE_COUNT] =
61 {
62  { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.13 *
63  UNIT_MM,
64  0.13 * UNIT_MM }, // 0 ... 15V
65 
66  { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.25 *
67  UNIT_MM,
68  0.13 * UNIT_MM }, // 16 ... 30V
69 
70  { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 0.6 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.4 *
71  UNIT_MM,
72  0.13 * UNIT_MM }, // 31 ... 50V
73 
74  { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 1.5 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.5 *
75  UNIT_MM,
76  0.13 * UNIT_MM }, // 51 ... 100V
77 
78  { 0.2 * UNIT_MM, 0.6 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
79  UNIT_MM,
80  0.4 * UNIT_MM }, // 101 ... 150V
81 
82  { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
83  UNIT_MM,
84  0.4 * UNIT_MM }, // 151 ... 170V
85 
86  { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 6.4 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
87  UNIT_MM,
88  0.4 * UNIT_MM }, // 171 ... 250V
89 
90  { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 12.5 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
91  UNIT_MM,
92  0.8 * UNIT_MM }, // 251 ... 300V
93 
94  { 0.25 * UNIT_MM, 2.5 * UNIT_MM, 12.5 * UNIT_MM, 0.8 * UNIT_MM, 0.8 * UNIT_MM, 1.5 *
95  UNIT_MM,
96  0.8 * UNIT_MM }, // 301 ... 500V
97 
98  // These last values are used to calculate spacing for voltage > 500V
99  // there are not the spacing
100  { 0.0025 * UNIT_MM, 0.005 * UNIT_MM, 0.025 * UNIT_MM, 0.00305 * UNIT_MM,
101  0.00305 * UNIT_MM, 0.00305 * UNIT_MM, 0.00305 * UNIT_MM }, // > 500V
102 };
103 
104 
106 {
108 }
109 
111 {
113 }
114 
115 
117 {
118  wxString txt;
119  double voltage = 500.0; // to calculate values at V > 500V
120  txt = m_ElectricalSpacingVoltage->GetValue();
121 
122  if( ! txt.IsEmpty() )
123  voltage = DoubleFromString(txt);
124 
125  if( voltage < 500.0 )
126  voltage = 500.0;
127 
128  txt.Printf( wxT( "%g" ), voltage );
129  m_ElectricalSpacingVoltage->SetValue( txt );
130 
131  for( int ii = 0; ii < CLASS_COUNT-1; ii++ )
132  {
133  for( int jj = 0; jj < VALUE_COUNT; jj++ )
134  {
135  txt.Printf( wxT( "%g" ), clist[ii][jj] / aUnitScale );
136  m_gridElectricalSpacingValues->SetCellValue( ii, jj, txt );
137  }
138  }
139 
140  for( int jj = 0; jj < VALUE_COUNT; jj++ )
141  {
142  double spacing = clist[CLASS_COUNT-2][jj];
143  double spacing_extra = clist[CLASS_COUNT-1][jj];
144  spacing += spacing_extra * ( voltage - 500.0 );
145  txt.Printf( wxT( "%g" ), spacing / aUnitScale );
146  m_gridElectricalSpacingValues->SetCellValue( CLASS_COUNT-1, jj, txt );
147  }
148 
149  m_gridElectricalSpacingValues->SetRowLabelSize( wxGRID_AUTOSIZE );
150 }
double DoubleFromString(const wxString &TextValue)
#define CLASS_COUNT
void OnElectricalSpacingRefresh(wxCommandEvent &event) override
#define VALUE_COUNT
void OnElectricalSpacingUnitsSelection(wxCommandEvent &event) override
void ElectricalSpacingUpdateData(double aUnitScale)
virtual double GetUnitScale() override
Function GetUnitScale.
UNIT_SELECTOR_LEN * m_ElectricalSpacingUnitsSelector
#define UNIT_MM
Definition: units_scales.h:31
static double clist[CLASS_COUNT][VALUE_COUNT]