You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.3 KiB

  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. #include <wx/app.h>
  25. #include <wx/config.h>
  26. #include <pcb_calculator_frame_base.h>
  27. #include <pcb_calculator.h>
  28. #include <UnitSelector.h>
  29. #include <units_scales.h>
  30. extern double ReturnDoubleFromString( const wxString& TextValue );
  31. #define VALUE_COUNT 7
  32. #define CLASS_COUNT 10
  33. /* These values come from IPC2221
  34. * there are 10 voltage classes:
  35. * "0 ... 15V" "16 ... 30V" "31 ... 50V" "51 ... 100V"
  36. * "101 ... 150V" "151 ... 170V" "171 ... 250V"
  37. * "251 ... 300V" "301 ... 500V" " > 500V"
  38. * and for each voltage class
  39. * there ar e 7 cases:
  40. * "B1" "B2" "B3" "B4" "A5" "A6" "A7"
  41. * B1 - Internal Conductors
  42. * B2 - External Conductors, uncoated, sea level to 3050 m
  43. * B3 - External Conductors, uncoated, over 3050 m
  44. * B4 - External Conductors, with permanent polymer coating (any elevation)
  45. * A5 - External Conductors, with conformal coating over assembly (any elevation)
  46. * A6 - External Component lead/termination, uncoated
  47. * A7 - External Component lead termination, with conformal coating (any elevation)
  48. */
  49. /* For voltages greater than 500V, the (per volt) table values
  50. * must be added to the 500V values. For example, the elec-
  51. * trical spacing for a Type B1 board with 600V is calculated
  52. * as:
  53. * 600V - 500V = 100V
  54. * 0.25 mm + (100V x 0.0025
  55. */
  56. static double clist[CLASS_COUNT][VALUE_COUNT] =
  57. {
  58. { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.13 *
  59. UNIT_MM,
  60. 0.13 * UNIT_MM }, // 0 ... 15V
  61. { 0.05 * UNIT_MM, 0.1 * UNIT_MM, 0.1 * UNIT_MM, 0.05 * UNIT_MM, 0.13 * UNIT_MM, 0.25 *
  62. UNIT_MM,
  63. 0.13 * UNIT_MM }, // 16 ... 30V
  64. { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 0.6 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.4 *
  65. UNIT_MM,
  66. 0.13 * UNIT_MM }, // 31 ... 50V
  67. { 0.1 * UNIT_MM, 0.6 * UNIT_MM, 1.5 * UNIT_MM, 0.13 * UNIT_MM, 0.13 * UNIT_MM, 0.5 *
  68. UNIT_MM,
  69. 0.13 * UNIT_MM }, // 51 ... 100V
  70. { 0.2 * UNIT_MM, 0.6 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
  71. UNIT_MM,
  72. 0.4 * UNIT_MM }, // 101 ... 150V
  73. { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 3.2 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
  74. UNIT_MM,
  75. 0.4 * UNIT_MM }, // 151 ... 170V
  76. { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 6.4 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
  77. UNIT_MM,
  78. 0.4 * UNIT_MM }, // 171 ... 250V
  79. { 0.2 * UNIT_MM, 1.25 * UNIT_MM, 12.5 * UNIT_MM, 0.4 * UNIT_MM, 0.4 * UNIT_MM, 0.8 *
  80. UNIT_MM,
  81. 0.8 * UNIT_MM }, // 251 ... 300V
  82. { 0.25 * UNIT_MM, 2.5 * UNIT_MM, 12.5 * UNIT_MM, 0.8 * UNIT_MM, 0.8 * UNIT_MM, 1.5 *
  83. UNIT_MM,
  84. 0.8 * UNIT_MM }, // 301 ... 500V
  85. // These last values are used to calculate spacing for voltage > 500V
  86. // there are not the spacing
  87. { 0.0025 * UNIT_MM, 0.005 * UNIT_MM, 0.025 * UNIT_MM, 0.00305 * UNIT_MM,
  88. 0.00305 * UNIT_MM, 0.00305 * UNIT_MM, 0.00305 * UNIT_MM }, // > 500V
  89. };
  90. void PCB_CALCULATOR_FRAME::OnElectricalSpacingUnitsSelection( wxCommandEvent& event )
  91. {
  92. ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() );
  93. }
  94. void PCB_CALCULATOR_FRAME::OnElectricalSpacingRefresh( wxCommandEvent& event )
  95. {
  96. ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() );
  97. }
  98. void PCB_CALCULATOR_FRAME::ElectricalSpacingUpdateData( double aUnitScale )
  99. {
  100. wxString txt;
  101. double voltage = 500.0; // to calculate values at V > 500V
  102. txt = m_ElectricalSpacingVoltage->GetValue();
  103. if( ! txt.IsEmpty() )
  104. voltage = ReturnDoubleFromString(txt);
  105. if( voltage < 500.0 )
  106. voltage = 500.0;
  107. txt.Printf( wxT( "%g" ), voltage );
  108. m_ElectricalSpacingVoltage->SetValue( txt );
  109. for( int ii = 0; ii < CLASS_COUNT-1; ii++ )
  110. {
  111. for( int jj = 0; jj < VALUE_COUNT; jj++ )
  112. {
  113. txt.Printf( wxT( "%g" ), clist[ii][jj] / aUnitScale );
  114. m_gridElectricalSpacingValues->SetCellValue( ii, jj, txt );
  115. }
  116. }
  117. for( int jj = 0; jj < VALUE_COUNT; jj++ )
  118. {
  119. double spacing = clist[CLASS_COUNT-2][jj];
  120. double spacing_extra = clist[CLASS_COUNT-1][jj];
  121. spacing += spacing_extra * ( voltage - 500.0 );
  122. txt.Printf( wxT( "%g" ), spacing / aUnitScale );
  123. m_gridElectricalSpacingValues->SetCellValue( CLASS_COUNT-1, jj, txt );
  124. }
  125. }