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.

226 lines
6.3 KiB

14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net>
  5. * Copyright (C) 1992-2008 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. * This file contains the global constants and variables used in the PCB
  26. * applications Pcbnew, CvPcb, and GervView. The goal of this was to
  27. * unobfuscate the original header file design that made it very difficult
  28. * to figure out where these variables lived. Ideally, they should be pushed
  29. * back into the application layer.
  30. */
  31. #include <fctsys.h>
  32. #include <pcbcommon.h>
  33. #include <plot_common.h>
  34. #include <class_board.h>
  35. #include <class_pad.h>
  36. #include <class_zone_settings.h>
  37. #include <class_board_design_settings.h>
  38. class MODULE;
  39. /* Look up Table for conversion copper layer count -> general copper layer
  40. * mask: */
  41. LAYER_MSK g_TabAllCopperLayerMask[NB_COPPER_LAYERS] = {
  42. 0x0001, 0x8001, 0x8003, 0x8007,
  43. 0x800F, 0x801F, 0x803F, 0x807F,
  44. 0x80FF, 0x81FF, 0x83FF, 0x87FF,
  45. 0x8FFF, 0x9FFF, 0xCFFF, 0xFFFF
  46. };
  47. DISPLAY_OPTIONS DisplayOpt; // Display options for board items
  48. int g_AnchorColor = BLUE;
  49. int g_ModuleTextCMPColor = LIGHTGRAY;
  50. int g_ModuleTextCUColor = MAGENTA;
  51. int g_ModuleTextNOVColor = DARKGRAY;
  52. int g_PadCUColor = GREEN;
  53. int g_PadCMPColor = RED;
  54. /**
  55. * Used in track creation, a list of track segments currently being created,
  56. * with the newest track at the end of the list, sorted by new-ness. e.g. use
  57. * TRACK->Back() to get the next older track, TRACK->Next() to get the next
  58. * newer track.
  59. */
  60. DLIST<TRACK> g_CurrentTrackList;
  61. LAYER_NUM FlipLayer( LAYER_NUM oldlayer )
  62. {
  63. switch( oldlayer )
  64. {
  65. case LAYER_N_BACK:
  66. return LAYER_N_FRONT;
  67. case LAYER_N_FRONT:
  68. return LAYER_N_BACK;
  69. case SILKSCREEN_N_BACK:
  70. return SILKSCREEN_N_FRONT;
  71. case SILKSCREEN_N_FRONT:
  72. return SILKSCREEN_N_BACK;
  73. case ADHESIVE_N_BACK:
  74. return ADHESIVE_N_FRONT;
  75. case ADHESIVE_N_FRONT:
  76. return ADHESIVE_N_BACK;
  77. case SOLDERMASK_N_BACK:
  78. return SOLDERMASK_N_FRONT;
  79. case SOLDERMASK_N_FRONT:
  80. return SOLDERMASK_N_BACK;
  81. case SOLDERPASTE_N_BACK:
  82. return SOLDERPASTE_N_FRONT;
  83. case SOLDERPASTE_N_FRONT:
  84. return SOLDERPASTE_N_BACK;
  85. // No change for the other layers
  86. default:
  87. return oldlayer;
  88. }
  89. }
  90. LAYER_MSK FlipLayerMask( LAYER_MSK aMask )
  91. {
  92. LAYER_MSK newMask;
  93. newMask = aMask & ~(LAYER_BACK | LAYER_FRONT |
  94. SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT |
  95. ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT |
  96. SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT |
  97. SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT |
  98. ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT);
  99. if( aMask & LAYER_BACK )
  100. newMask |= LAYER_FRONT;
  101. if( aMask & LAYER_FRONT )
  102. newMask |= LAYER_BACK;
  103. if( aMask & SILKSCREEN_LAYER_BACK )
  104. newMask |= SILKSCREEN_LAYER_FRONT;
  105. if( aMask & SILKSCREEN_LAYER_FRONT )
  106. newMask |= SILKSCREEN_LAYER_BACK;
  107. if( aMask & ADHESIVE_LAYER_BACK )
  108. newMask |= ADHESIVE_LAYER_FRONT;
  109. if( aMask & ADHESIVE_LAYER_FRONT )
  110. newMask |= ADHESIVE_LAYER_BACK;
  111. if( aMask & SOLDERMASK_LAYER_BACK )
  112. newMask |= SOLDERMASK_LAYER_FRONT;
  113. if( aMask & SOLDERMASK_LAYER_FRONT )
  114. newMask |= SOLDERMASK_LAYER_BACK;
  115. if( aMask & SOLDERPASTE_LAYER_BACK )
  116. newMask |= SOLDERPASTE_LAYER_FRONT;
  117. if( aMask & SOLDERPASTE_LAYER_FRONT )
  118. newMask |= SOLDERPASTE_LAYER_BACK;
  119. if( aMask & ADHESIVE_LAYER_BACK )
  120. newMask |= ADHESIVE_LAYER_FRONT;
  121. if( aMask & ADHESIVE_LAYER_FRONT )
  122. newMask |= ADHESIVE_LAYER_BACK;
  123. return newMask;
  124. }
  125. LAYER_NUM ExtractLayer( LAYER_MSK aMask )
  126. {
  127. if( aMask == NO_LAYERS )
  128. return UNSELECTED_LAYER;
  129. LAYER_NUM candidate = UNDEFINED_LAYER;
  130. // Scan all the layers and take note of the first set; if other are
  131. // then found return UNDEFINED_LAYER
  132. for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i )
  133. {
  134. if( aMask & GetLayerMask( i ) )
  135. {
  136. if( candidate == UNDEFINED_LAYER )
  137. candidate = i;
  138. else
  139. return UNDEFINED_LAYER;
  140. }
  141. }
  142. return candidate;
  143. }
  144. wxString LayerMaskDescribe( const BOARD *aBoard, LAYER_MSK aMask )
  145. {
  146. // Try the single or no- layer case (easy)
  147. LAYER_NUM layer = ExtractLayer( aMask );
  148. switch( layer )
  149. {
  150. case UNSELECTED_LAYER:
  151. return _( "No layers" );
  152. case UNDEFINED_LAYER:
  153. break;
  154. default:
  155. return aBoard->GetLayerName( layer );
  156. }
  157. // Try to be smart and useful, starting with outer copper
  158. // (which are more important than internal ones)
  159. wxString layerInfo;
  160. if( aMask & LAYER_FRONT )
  161. AccumulateDescription( layerInfo, aBoard->GetLayerName( LAYER_N_FRONT ) );
  162. if( aMask & LAYER_BACK )
  163. AccumulateDescription( layerInfo, aBoard->GetLayerName( LAYER_N_BACK ) );
  164. if( aMask & INTERNAL_CU_LAYERS )
  165. AccumulateDescription( layerInfo, _("Internal" ) );
  166. if( aMask & ALL_NO_CU_LAYERS )
  167. AccumulateDescription( layerInfo, _("Non-copper" ) );
  168. return layerInfo;
  169. }
  170. void AccumulateDescription( wxString &aDesc, const wxString &aItem )
  171. {
  172. if( !aDesc.IsEmpty() )
  173. aDesc << wxT(", ");
  174. aDesc << aItem;
  175. }