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.

142 lines
5.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2009-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 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/string.h>
  25. #include <core/arraydim.h>
  26. #include <board_design_settings.h>
  27. #include <i18n_utility.h> // _HKI definition
  28. #include "stackup_predefined_prms.h"
  29. // A list of copper finish standard type names.
  30. // They are standard names in .gbdjob files, so avoid changing them or ensure they are
  31. // compatible with .gbrjob file spec.
  32. static wxString copperFinishType[] =
  33. {
  34. NotSpecifiedPrm(), // Not specified, not in .gbrjob file
  35. _HKI( "ENIG" ), // used in .gbrjob file
  36. _HKI( "ENEPIG" ), // used in .gbrjob file
  37. _HKI( "HAL SnPb" ), // used in .gbrjob file
  38. _HKI( "HAL lead-free" ), // used in .gbrjob file
  39. _HKI( "Hard gold" ), // used in .gbrjob file
  40. _HKI( "Immersion tin" ), // used in .gbrjob file
  41. _HKI( "Immersion nickel" ), // used in .gbrjob file
  42. _HKI( "Immersion silver" ), // used in .gbrjob file
  43. _HKI( "Immersion gold" ), // used in .gbrjob file
  44. _HKI( "HT_OSP" ), // used in .gbrjob file
  45. _HKI( "OSP" ), // used in .gbrjob file
  46. _HKI( "None" ), // used in .gbrjob file
  47. _HKI( "User defined" ) // keep this option at end
  48. };
  49. // A list of available colors for solder mask and silkscreen.
  50. // These names are used in .gbrjob file, so they are not fully free. Use only what is allowed in
  51. // .gbrjob files.
  52. // For other colors (user defined), the defined value is the html color syntax in .kicad_pcb files
  53. // and R<integer>G<integer>B<integer> in .gbrjob file.
  54. static std::vector<FAB_LAYER_COLOR> gbrjobColors =
  55. {
  56. { NotSpecifiedPrm(), wxColor( 80, 80, 80 ) }, // Not specified, not in .gbrjob file
  57. { _HKI( "Green" ), wxColor( 60, 150, 80 ) }, // used in .gbrjob file
  58. { _HKI( "Red" ), wxColor( 128, 0, 0 ) }, // used in .gbrjob file
  59. { _HKI( "Blue" ), wxColor( 0, 0, 128 ) }, // used in .gbrjob file
  60. { _HKI( "Purple" ), wxColor( 80, 0, 80 ) }, // used in .gbrjob file
  61. { _HKI( "Black" ), wxColor( 20, 20, 20 ) }, // used in .gbrjob file
  62. { _HKI( "White" ), wxColor( 200, 200, 200 ) }, // used in .gbrjob file
  63. { _HKI( "Yellow" ), wxColor( 128, 128, 0 ) }, // used in .gbrjob file
  64. { _HKI( "User defined" ), wxColor( 128, 128, 128 ) } // Free; the name is a dummy name here
  65. };
  66. // These are used primarily as a source for the 3D renderer. They are written
  67. // as R<integer>G<integer>B<integer> to the .gbrjob file.
  68. static std::vector<FAB_LAYER_COLOR> dielectricColors =
  69. {
  70. { NotSpecifiedPrm(), wxColor( 80, 80, 80, 255 ) },
  71. { _HKI( "FR4 natural" ), wxColor( 109, 116, 75, 212 ) },
  72. { _HKI( "PTFE natural" ), wxColor( 252, 252, 250, 230 ) },
  73. { _HKI( "Polyimide" ), wxColor( 205, 130, 0, 170 ) },
  74. { _HKI( "Phenolic natural" ), wxColor( 92, 17, 6, 230 ) },
  75. { _HKI( "Aluminum" ), wxColor( 213, 213, 213, 255 ) },
  76. { _HKI( "User defined" ), wxColor( 128, 128, 128, 212 ) }
  77. };
  78. wxArrayString GetStandardCopperFinishes( bool aTranslate )
  79. {
  80. wxArrayString list;
  81. for( unsigned ii = 0; ii < arrayDim( copperFinishType ); ii++ )
  82. list.Add( aTranslate ? wxGetTranslation( copperFinishType[ii] ) : copperFinishType[ii] );
  83. return list;
  84. }
  85. std::vector<FAB_LAYER_COLOR> dummy;
  86. const std::vector<FAB_LAYER_COLOR>& GetStandardColors( BOARD_STACKUP_ITEM_TYPE aType )
  87. {
  88. switch( aType )
  89. {
  90. case BS_ITEM_TYPE_SILKSCREEN: return gbrjobColors;
  91. case BS_ITEM_TYPE_SOLDERMASK: return gbrjobColors;
  92. case BS_ITEM_TYPE_DIELECTRIC: return dielectricColors;
  93. default: return dummy;
  94. }
  95. }
  96. int GetColorUserDefinedListIdx( BOARD_STACKUP_ITEM_TYPE aType )
  97. {
  98. // this is the last item in list
  99. return GetStandardColors( aType ).size() - 1;
  100. }
  101. bool IsColorNameNormalized( const wxString& aName )
  102. {
  103. static std::vector<wxString> list =
  104. {
  105. wxT( "Green" ), wxT( "Red" ), wxT( "Blue" ),
  106. wxT( "Black" ), wxT( "White" ), wxT( "Yellow" )
  107. };
  108. for( wxString& candidate : list )
  109. {
  110. if( candidate.CmpNoCase( aName ) == 0 )
  111. return true;
  112. }
  113. return false;
  114. }
  115. const wxString FAB_LAYER_COLOR::GetColorAsString() const
  116. {
  117. if( IsColorNameNormalized( m_colorName ) )
  118. return m_colorName;
  119. return wxString::Format( wxT( "R%dG%dB%d" ),
  120. int( m_color.r*255 ), int( m_color.g*255 ), int( m_color.b*255 ) );
  121. }