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.

1004 lines
23 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
4 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2014-2022 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 <bitset> // for bitset, __bitset<>::ref...
  25. #include <cassert>
  26. #include <cstdarg>
  27. #include <iostream> // for string, endl, basic_ost...
  28. #include <stddef.h> // for size_t
  29. #include <core/arraydim.h>
  30. #include <math/util.h> // for Clamp
  31. #include <layer_ids.h> // for LSET, PCB_LAYER_ID, LSEQ
  32. #include <macros.h> // for arrayDim
  33. #include <wx/debug.h> // for wxASSERT, wxASSERT_MSG
  34. #include <wx/string.h>
  35. LSET::LSET( const PCB_LAYER_ID* aArray, unsigned aCount ) :
  36. BASE_SET()
  37. {
  38. for( unsigned i=0; i<aCount; ++i )
  39. set( aArray[i] );
  40. }
  41. LSET::LSET( unsigned aIdCount, int aFirst, ... ) :
  42. BASE_SET()
  43. {
  44. // The constructor, without the mandatory aFirst argument, could have been confused
  45. // by the compiler with the LSET( PCB_LAYER_ID ). With aFirst, that ambiguity is not
  46. // present. Therefore aIdCount must always be >=1.
  47. wxASSERT_MSG( aIdCount > 0, wxT( "aIdCount must be >= 1" ) );
  48. set( aFirst );
  49. if( --aIdCount )
  50. {
  51. va_list ap;
  52. va_start( ap, aFirst );
  53. for( unsigned i=0; i<aIdCount; ++i )
  54. {
  55. PCB_LAYER_ID id = (PCB_LAYER_ID) va_arg( ap, int );
  56. assert( unsigned( id ) < PCB_LAYER_ID_COUNT );
  57. set( id );
  58. }
  59. va_end( ap );
  60. }
  61. }
  62. /**
  63. * NOTE: These names must not be translated or changed. They are used as tokens in the board
  64. * file format because the ordinal value of the PCB_LAYER_ID enum was not stable over time.
  65. * @see LayerName() for what should be used to display the default name of a layer in the GUI.
  66. */
  67. const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
  68. {
  69. const wxChar* txt;
  70. // using a switch to explicitly show the mapping more clearly
  71. switch( aLayerId )
  72. {
  73. case F_Cu: txt = wxT( "F.Cu" ); break;
  74. case In1_Cu: txt = wxT( "In1.Cu" ); break;
  75. case In2_Cu: txt = wxT( "In2.Cu" ); break;
  76. case In3_Cu: txt = wxT( "In3.Cu" ); break;
  77. case In4_Cu: txt = wxT( "In4.Cu" ); break;
  78. case In5_Cu: txt = wxT( "In5.Cu" ); break;
  79. case In6_Cu: txt = wxT( "In6.Cu" ); break;
  80. case In7_Cu: txt = wxT( "In7.Cu" ); break;
  81. case In8_Cu: txt = wxT( "In8.Cu" ); break;
  82. case In9_Cu: txt = wxT( "In9.Cu" ); break;
  83. case In10_Cu: txt = wxT( "In10.Cu" ); break;
  84. case In11_Cu: txt = wxT( "In11.Cu" ); break;
  85. case In12_Cu: txt = wxT( "In12.Cu" ); break;
  86. case In13_Cu: txt = wxT( "In13.Cu" ); break;
  87. case In14_Cu: txt = wxT( "In14.Cu" ); break;
  88. case In15_Cu: txt = wxT( "In15.Cu" ); break;
  89. case In16_Cu: txt = wxT( "In16.Cu" ); break;
  90. case In17_Cu: txt = wxT( "In17.Cu" ); break;
  91. case In18_Cu: txt = wxT( "In18.Cu" ); break;
  92. case In19_Cu: txt = wxT( "In19.Cu" ); break;
  93. case In20_Cu: txt = wxT( "In20.Cu" ); break;
  94. case In21_Cu: txt = wxT( "In21.Cu" ); break;
  95. case In22_Cu: txt = wxT( "In22.Cu" ); break;
  96. case In23_Cu: txt = wxT( "In23.Cu" ); break;
  97. case In24_Cu: txt = wxT( "In24.Cu" ); break;
  98. case In25_Cu: txt = wxT( "In25.Cu" ); break;
  99. case In26_Cu: txt = wxT( "In26.Cu" ); break;
  100. case In27_Cu: txt = wxT( "In27.Cu" ); break;
  101. case In28_Cu: txt = wxT( "In28.Cu" ); break;
  102. case In29_Cu: txt = wxT( "In29.Cu" ); break;
  103. case In30_Cu: txt = wxT( "In30.Cu" ); break;
  104. case B_Cu: txt = wxT( "B.Cu" ); break;
  105. // Technicals
  106. case B_Adhes: txt = wxT( "B.Adhes" ); break;
  107. case F_Adhes: txt = wxT( "F.Adhes" ); break;
  108. case B_Paste: txt = wxT( "B.Paste" ); break;
  109. case F_Paste: txt = wxT( "F.Paste" ); break;
  110. case B_SilkS: txt = wxT( "B.SilkS" ); break;
  111. case F_SilkS: txt = wxT( "F.SilkS" ); break;
  112. case B_Mask: txt = wxT( "B.Mask" ); break;
  113. case F_Mask: txt = wxT( "F.Mask" ); break;
  114. // Users
  115. case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
  116. case Cmts_User: txt = wxT( "Cmts.User" ); break;
  117. case Eco1_User: txt = wxT( "Eco1.User" ); break;
  118. case Eco2_User: txt = wxT( "Eco2.User" ); break;
  119. case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
  120. case Margin: txt = wxT( "Margin" ); break;
  121. // Footprint
  122. case F_CrtYd: txt = wxT( "F.CrtYd" ); break;
  123. case B_CrtYd: txt = wxT( "B.CrtYd" ); break;
  124. case F_Fab: txt = wxT( "F.Fab" ); break;
  125. case B_Fab: txt = wxT( "B.Fab" ); break;
  126. // User definable layers.
  127. case User_1: txt = wxT( "User.1" ); break;
  128. case User_2: txt = wxT( "User.2" ); break;
  129. case User_3: txt = wxT( "User.3" ); break;
  130. case User_4: txt = wxT( "User.4" ); break;
  131. case User_5: txt = wxT( "User.5" ); break;
  132. case User_6: txt = wxT( "User.6" ); break;
  133. case User_7: txt = wxT( "User.7" ); break;
  134. case User_8: txt = wxT( "User.8" ); break;
  135. case User_9: txt = wxT( "User.9" ); break;
  136. // Rescue
  137. case Rescue: txt = wxT( "Rescue" ); break;
  138. default:
  139. std::cout << aLayerId << std::endl;
  140. wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
  141. txt = wxT( "BAD INDEX!" ); break;
  142. }
  143. return txt;
  144. }
  145. LSEQ LSET::CuStack() const
  146. {
  147. // desired sequence
  148. static const PCB_LAYER_ID sequence[] = {
  149. F_Cu,
  150. In1_Cu,
  151. In2_Cu,
  152. In3_Cu,
  153. In4_Cu,
  154. In5_Cu,
  155. In6_Cu,
  156. In7_Cu,
  157. In8_Cu,
  158. In9_Cu,
  159. In10_Cu,
  160. In11_Cu,
  161. In12_Cu,
  162. In13_Cu,
  163. In14_Cu,
  164. In15_Cu,
  165. In16_Cu,
  166. In17_Cu,
  167. In18_Cu,
  168. In19_Cu,
  169. In20_Cu,
  170. In21_Cu,
  171. In22_Cu,
  172. In23_Cu,
  173. In24_Cu,
  174. In25_Cu,
  175. In26_Cu,
  176. In27_Cu,
  177. In28_Cu,
  178. In29_Cu,
  179. In30_Cu,
  180. B_Cu, // 31
  181. };
  182. return Seq( sequence, arrayDim( sequence ) );
  183. }
  184. LSEQ LSET::Technicals( LSET aSetToOmit ) const
  185. {
  186. // desired sequence
  187. static const PCB_LAYER_ID sequence[] = {
  188. F_Adhes,
  189. B_Adhes,
  190. F_Paste,
  191. B_Paste,
  192. F_SilkS,
  193. B_SilkS,
  194. F_Mask,
  195. B_Mask,
  196. F_CrtYd,
  197. B_CrtYd,
  198. F_Fab,
  199. B_Fab,
  200. };
  201. LSET subset = ~aSetToOmit & *this;
  202. return subset.Seq( sequence, arrayDim( sequence ) );
  203. }
  204. LSEQ LSET::Users() const
  205. {
  206. // desired
  207. static const PCB_LAYER_ID sequence[] = {
  208. Dwgs_User,
  209. Cmts_User,
  210. Eco1_User,
  211. Eco2_User,
  212. Edge_Cuts,
  213. Margin,
  214. User_1,
  215. User_2,
  216. User_3,
  217. User_4,
  218. User_5,
  219. User_6,
  220. User_7,
  221. User_8,
  222. User_9
  223. };
  224. return Seq( sequence, arrayDim( sequence ) );
  225. }
  226. LSEQ LSET::TechAndUserUIOrder() const
  227. {
  228. static const PCB_LAYER_ID sequence[] = {
  229. F_Adhes,
  230. B_Adhes,
  231. F_Paste,
  232. B_Paste,
  233. F_SilkS,
  234. B_SilkS,
  235. F_Mask,
  236. B_Mask,
  237. Dwgs_User,
  238. Cmts_User,
  239. Eco1_User,
  240. Eco2_User,
  241. Edge_Cuts,
  242. Margin,
  243. F_CrtYd,
  244. B_CrtYd,
  245. F_Fab,
  246. B_Fab,
  247. User_1,
  248. User_2,
  249. User_3,
  250. User_4,
  251. User_5,
  252. User_6,
  253. User_7,
  254. User_8,
  255. User_9
  256. };
  257. return Seq( sequence, arrayDim( sequence ) );
  258. }
  259. std::string LSET::FmtBin() const
  260. {
  261. std::string ret;
  262. int bit_count = size();
  263. for( int bit=0; bit<bit_count; ++bit )
  264. {
  265. if( bit )
  266. {
  267. if( !( bit % 8 ) )
  268. ret += '|';
  269. else if( !( bit % 4 ) )
  270. ret += '_';
  271. }
  272. ret += (*this)[bit] ? '1' : '0';
  273. }
  274. // reverse of string
  275. return std::string( ret.rbegin(), ret.rend() );
  276. }
  277. std::string LSET::FmtHex() const
  278. {
  279. std::string ret;
  280. static const char hex[] = "0123456789abcdef";
  281. size_t nibble_count = ( size() + 3 ) / 4;
  282. for( size_t nibble = 0; nibble < nibble_count; ++nibble )
  283. {
  284. unsigned int ndx = 0;
  285. // test 4 consecutive bits and set ndx to 0-15
  286. for( size_t nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
  287. {
  288. size_t nibble_pos = nibble_bit + ( nibble * 4 );
  289. // make sure it's not extra bits that don't exist in the bitset but need to in the
  290. // hex format
  291. if( nibble_pos >= size() )
  292. break;
  293. if( ( *this )[nibble_pos] )
  294. ndx |= ( 1 << nibble_bit );
  295. }
  296. if( nibble && !( nibble % 8 ) )
  297. ret += '_';
  298. assert( ndx < arrayDim( hex ) );
  299. ret += hex[ndx];
  300. }
  301. // reverse of string
  302. return std::string( ret.rbegin(), ret.rend() );
  303. }
  304. int LSET::ParseHex( const char* aStart, int aCount )
  305. {
  306. LSET tmp;
  307. const char* rstart = aStart + aCount - 1;
  308. const char* rend = aStart - 1;
  309. const int bitcount = size();
  310. int nibble_ndx = 0;
  311. while( rstart > rend )
  312. {
  313. int cc = *rstart--;
  314. if( cc == '_' )
  315. continue;
  316. int nibble;
  317. if( cc >= '0' && cc <= '9' )
  318. nibble = cc - '0';
  319. else if( cc >= 'a' && cc <= 'f' )
  320. nibble = cc - 'a' + 10;
  321. else if( cc >= 'A' && cc <= 'F' )
  322. nibble = cc - 'A' + 10;
  323. else
  324. break;
  325. int bit = nibble_ndx * 4;
  326. for( int ndx=0; bit<bitcount && ndx<4; ++bit, ++ndx )
  327. if( nibble & (1<<ndx) )
  328. tmp.set( bit );
  329. if( bit >= bitcount )
  330. break;
  331. ++nibble_ndx;
  332. }
  333. int byte_count = aStart + aCount - 1 - rstart;
  334. assert( byte_count >= 0 );
  335. if( byte_count > 0 )
  336. *this = tmp;
  337. return byte_count;
  338. }
  339. LSEQ LSET::Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const
  340. {
  341. LSEQ ret;
  342. #if defined(DEBUG) && 0
  343. LSET dup_detector;
  344. for( unsigned i=0; i<aCount; ++i )
  345. {
  346. PCB_LAYER_ID id = aWishListSequence[i];
  347. if( test( id ) )
  348. {
  349. wxASSERT_MSG( !dup_detector[id], wxT( "Duplicate in aWishListSequence" ) );
  350. dup_detector[id] = true;
  351. ret.push_back( id );
  352. }
  353. }
  354. #else
  355. for( unsigned i=0; i<aCount; ++i )
  356. {
  357. PCB_LAYER_ID id = aWishListSequence[i];
  358. if( test( id ) )
  359. ret.push_back( id );
  360. }
  361. #endif
  362. return ret;
  363. }
  364. LSEQ LSET::Seq( const LSEQ& aSequence ) const
  365. {
  366. LSEQ ret;
  367. for( LSEQ seq = aSequence; seq; ++seq )
  368. {
  369. if( test( *seq ) )
  370. ret.push_back( *seq );
  371. }
  372. return ret;
  373. }
  374. LSEQ LSET::Seq() const
  375. {
  376. LSEQ ret;
  377. ret.reserve( size() );
  378. for( unsigned i = 0; i < size(); ++i )
  379. {
  380. if( test( i ) )
  381. ret.push_back( PCB_LAYER_ID( i ) );
  382. }
  383. return ret;
  384. }
  385. LSEQ LSET::SeqStackupBottom2Top() const
  386. {
  387. // bottom-to-top stack-up layers
  388. static const PCB_LAYER_ID sequence[] = {
  389. User_9,
  390. User_8,
  391. User_7,
  392. User_6,
  393. User_5,
  394. User_4,
  395. User_3,
  396. User_2,
  397. User_1,
  398. B_Fab,
  399. B_CrtYd,
  400. B_Adhes,
  401. B_SilkS,
  402. B_Paste,
  403. B_Mask,
  404. B_Cu,
  405. In30_Cu,
  406. In29_Cu,
  407. In28_Cu,
  408. In27_Cu,
  409. In26_Cu,
  410. In25_Cu,
  411. In24_Cu,
  412. In23_Cu,
  413. In22_Cu,
  414. In21_Cu,
  415. In20_Cu,
  416. In19_Cu,
  417. In18_Cu,
  418. In17_Cu,
  419. In16_Cu,
  420. In15_Cu,
  421. In14_Cu,
  422. In13_Cu,
  423. In12_Cu,
  424. In11_Cu,
  425. In10_Cu,
  426. In9_Cu,
  427. In8_Cu,
  428. In7_Cu,
  429. In6_Cu,
  430. In5_Cu,
  431. In4_Cu,
  432. In3_Cu,
  433. In2_Cu,
  434. In1_Cu,
  435. F_Cu,
  436. F_Mask,
  437. F_Paste,
  438. F_SilkS,
  439. F_Adhes,
  440. F_CrtYd,
  441. F_Fab,
  442. Dwgs_User,
  443. Cmts_User,
  444. Eco1_User,
  445. Eco2_User,
  446. Margin,
  447. Edge_Cuts,
  448. };
  449. return Seq( sequence, arrayDim( sequence ) );
  450. }
  451. PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
  452. {
  453. switch( aLayerId )
  454. {
  455. case B_Cu: return F_Cu;
  456. case F_Cu: return B_Cu;
  457. case B_SilkS: return F_SilkS;
  458. case F_SilkS: return B_SilkS;
  459. case B_Adhes: return F_Adhes;
  460. case F_Adhes: return B_Adhes;
  461. case B_Mask: return F_Mask;
  462. case F_Mask: return B_Mask;
  463. case B_Paste: return F_Paste;
  464. case F_Paste: return B_Paste;
  465. case B_CrtYd: return F_CrtYd;
  466. case F_CrtYd: return B_CrtYd;
  467. case B_Fab: return F_Fab;
  468. case F_Fab: return B_Fab;
  469. default: // change internal layer if aCopperLayersCount is >= 4
  470. if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
  471. {
  472. // internal copper layers count is aCopperLayersCount-2
  473. PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
  474. // Ensure fliplayer has a value which does not crash Pcbnew:
  475. if( fliplayer < F_Cu )
  476. fliplayer = F_Cu;
  477. if( fliplayer > B_Cu )
  478. fliplayer = B_Cu;
  479. return fliplayer;
  480. }
  481. // No change for the other layers
  482. return aLayerId;
  483. }
  484. }
  485. LSET FlipLayerMask( LSET aMask, int aCopperLayersCount )
  486. {
  487. // layers on physical outside of a board:
  488. const static LSET and_mask( 16, // !! update count
  489. B_Cu, F_Cu,
  490. B_SilkS, F_SilkS,
  491. B_Adhes, F_Adhes,
  492. B_Mask, F_Mask,
  493. B_Paste, F_Paste,
  494. B_Adhes, F_Adhes,
  495. B_CrtYd, F_CrtYd,
  496. B_Fab, F_Fab
  497. );
  498. LSET newMask = aMask & ~and_mask;
  499. if( aMask[B_Cu] )
  500. newMask.set( F_Cu );
  501. if( aMask[F_Cu] )
  502. newMask.set( B_Cu );
  503. if( aMask[B_SilkS] )
  504. newMask.set( F_SilkS );
  505. if( aMask[F_SilkS] )
  506. newMask.set( B_SilkS );
  507. if( aMask[B_Adhes] )
  508. newMask.set( F_Adhes );
  509. if( aMask[F_Adhes] )
  510. newMask.set( B_Adhes );
  511. if( aMask[B_Mask] )
  512. newMask.set( F_Mask );
  513. if( aMask[F_Mask] )
  514. newMask.set( B_Mask );
  515. if( aMask[B_Paste] )
  516. newMask.set( F_Paste );
  517. if( aMask[F_Paste] )
  518. newMask.set( B_Paste );
  519. if( aMask[B_Adhes] )
  520. newMask.set( F_Adhes );
  521. if( aMask[F_Adhes] )
  522. newMask.set( B_Adhes );
  523. if( aMask[B_CrtYd] )
  524. newMask.set( F_CrtYd );
  525. if( aMask[F_CrtYd] )
  526. newMask.set( B_CrtYd );
  527. if( aMask[B_Fab] )
  528. newMask.set( F_Fab );
  529. if( aMask[F_Fab] )
  530. newMask.set( B_Fab );
  531. if( aCopperLayersCount >= 4 ) // Internal layers exist
  532. {
  533. LSET internalMask = aMask & LSET::InternalCuMask();
  534. if( internalMask != LSET::InternalCuMask() )
  535. {
  536. // the mask does not include all internal layers. Therefore
  537. // the flipped mask for internal copper layers must be built
  538. int innerLayerCnt = aCopperLayersCount -2;
  539. // the flipped mask is the innerLayerCnt bits rewritten in reverse order
  540. // ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
  541. for( int ii = 0; ii < innerLayerCnt; ii++ )
  542. {
  543. if( internalMask[innerLayerCnt - ii] )
  544. {
  545. newMask.set( ii + In1_Cu );
  546. }
  547. else
  548. {
  549. newMask.reset( ii + In1_Cu );
  550. }
  551. }
  552. }
  553. }
  554. return newMask;
  555. }
  556. PCB_LAYER_ID LSET::ExtractLayer() const
  557. {
  558. unsigned set_count = count();
  559. if( !set_count )
  560. return UNSELECTED_LAYER;
  561. else if( set_count > 1 )
  562. return UNDEFINED_LAYER;
  563. for( unsigned i=0; i < size(); ++i )
  564. {
  565. if( test( i ) )
  566. return PCB_LAYER_ID( i );
  567. }
  568. wxASSERT( 0 ); // set_count was verified as 1 above, what did you break?
  569. return UNDEFINED_LAYER;
  570. }
  571. LSET LSET::FrontAssembly()
  572. {
  573. static const PCB_LAYER_ID front_assembly[] = {
  574. F_SilkS,
  575. F_Mask,
  576. F_Fab,
  577. F_CrtYd
  578. };
  579. static const LSET saved( front_assembly, arrayDim( front_assembly ) );
  580. return saved;
  581. }
  582. LSET LSET::BackAssembly()
  583. {
  584. static const PCB_LAYER_ID back_assembly[] = {
  585. B_SilkS,
  586. B_Mask,
  587. B_Fab,
  588. B_CrtYd
  589. };
  590. static const LSET saved( back_assembly, arrayDim( back_assembly ) );
  591. return saved;
  592. }
  593. LSET LSET::InternalCuMask()
  594. {
  595. static const PCB_LAYER_ID cu_internals[] = {
  596. In1_Cu,
  597. In2_Cu,
  598. In3_Cu,
  599. In4_Cu,
  600. In5_Cu,
  601. In6_Cu,
  602. In7_Cu,
  603. In8_Cu,
  604. In9_Cu,
  605. In10_Cu,
  606. In11_Cu,
  607. In12_Cu,
  608. In13_Cu,
  609. In14_Cu,
  610. In15_Cu,
  611. In16_Cu,
  612. In17_Cu,
  613. In18_Cu,
  614. In19_Cu,
  615. In20_Cu,
  616. In21_Cu,
  617. In22_Cu,
  618. In23_Cu,
  619. In24_Cu,
  620. In25_Cu,
  621. In26_Cu,
  622. In27_Cu,
  623. In28_Cu,
  624. In29_Cu,
  625. In30_Cu,
  626. };
  627. static const LSET saved( cu_internals, arrayDim( cu_internals ) );
  628. return saved;
  629. }
  630. LSET LSET::AllCuMask( int aCuLayerCount )
  631. {
  632. // retain all in static as the full set, which is a common case.
  633. static const LSET all = InternalCuMask().set( F_Cu ).set( B_Cu );
  634. if( aCuLayerCount == MAX_CU_LAYERS )
  635. return all;
  636. // subtract out some Cu layers not wanted in the mask.
  637. LSET ret = all;
  638. int clear_count = MAX_CU_LAYERS - aCuLayerCount;
  639. clear_count = Clamp( 0, clear_count, MAX_CU_LAYERS - 2 );
  640. for( int elem = In30_Cu; clear_count; --elem, --clear_count )
  641. ret.set( elem, false );
  642. return ret;
  643. }
  644. LSET LSET::AllNonCuMask()
  645. {
  646. static const LSET saved = LSET().set() & ~AllCuMask();
  647. return saved;
  648. }
  649. LSET LSET::ExternalCuMask()
  650. {
  651. static const LSET saved( 2, F_Cu, B_Cu );
  652. return saved;
  653. }
  654. LSET LSET::AllLayersMask()
  655. {
  656. static const LSET saved = LSET().set();
  657. return saved;
  658. }
  659. LSET LSET::BackTechMask()
  660. {
  661. static const LSET saved( 6, B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab );
  662. return saved;
  663. }
  664. LSET LSET::BackBoardTechMask()
  665. {
  666. static const LSET saved( 4, B_SilkS, B_Mask, B_Adhes, B_Paste );
  667. return saved;
  668. }
  669. LSET LSET::FrontTechMask()
  670. {
  671. static const LSET saved( 6, F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab );
  672. return saved;
  673. }
  674. LSET LSET::FrontBoardTechMask()
  675. {
  676. static const LSET saved( 4, F_SilkS, F_Mask, F_Adhes, F_Paste );
  677. return saved;
  678. }
  679. LSET LSET::AllTechMask()
  680. {
  681. static const LSET saved = BackTechMask() | FrontTechMask();
  682. return saved;
  683. }
  684. LSET LSET::AllBoardTechMask()
  685. {
  686. static const LSET saved = BackBoardTechMask() | FrontBoardTechMask();
  687. return saved;
  688. }
  689. LSET LSET::UserMask()
  690. {
  691. static const LSET saved( 6,
  692. Dwgs_User,
  693. Cmts_User,
  694. Eco1_User,
  695. Eco2_User,
  696. Edge_Cuts,
  697. Margin
  698. );
  699. return saved;
  700. }
  701. LSET LSET::PhysicalLayersMask()
  702. {
  703. static const LSET saved = AllBoardTechMask() | AllCuMask();
  704. return saved;
  705. }
  706. LSET LSET::UserDefinedLayers()
  707. {
  708. static const LSET saved( 9,
  709. User_1,
  710. User_2,
  711. User_3,
  712. User_4,
  713. User_5,
  714. User_6,
  715. User_7,
  716. User_8,
  717. User_9
  718. );
  719. return saved;
  720. }
  721. LSET LSET::FrontMask()
  722. {
  723. static const LSET saved = FrontTechMask().set( F_Cu );
  724. return saved;
  725. }
  726. LSET LSET::BackMask()
  727. {
  728. static const LSET saved = BackTechMask().set( B_Cu );
  729. return saved;
  730. }
  731. LSET LSET::SideSpecificMask()
  732. {
  733. static const LSET saved = BackTechMask() | FrontTechMask() | AllCuMask();
  734. return saved;
  735. }
  736. LSET LSET::ForbiddenFootprintLayers()
  737. {
  738. static const LSET saved = InternalCuMask();
  739. return saved;
  740. }
  741. LSEQ LSET::UIOrder() const
  742. {
  743. LSEQ order = CuStack();
  744. LSEQ techuser = TechAndUserUIOrder();
  745. order.insert( order.end(), techuser.begin(), techuser.end() );
  746. return order;
  747. }
  748. PCB_LAYER_ID ToLAYER_ID( int aLayer )
  749. {
  750. wxASSERT( aLayer < GAL_LAYER_ID_END );
  751. return PCB_LAYER_ID( aLayer );
  752. }
  753. GAL_SET::GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount ) : GAL_SET()
  754. {
  755. for( unsigned i = 0; i < aCount; ++i )
  756. set( aArray[i] );
  757. }
  758. std::vector<GAL_LAYER_ID> GAL_SET::Seq() const
  759. {
  760. std::vector<GAL_LAYER_ID> ret;
  761. for( size_t i = 0; i < size(); ++i )
  762. {
  763. if( test( i ) )
  764. ret.push_back( static_cast<GAL_LAYER_ID>( i + GAL_LAYER_ID_START ) );
  765. }
  766. return ret;
  767. }
  768. GAL_SET GAL_SET::DefaultVisible()
  769. {
  770. static const GAL_LAYER_ID visible[] = {
  771. LAYER_VIAS,
  772. LAYER_VIA_MICROVIA,
  773. LAYER_VIA_BBLIND,
  774. LAYER_VIA_THROUGH,
  775. LAYER_NON_PLATEDHOLES,
  776. LAYER_MOD_TEXT,
  777. // LAYER_MOD_TEXT_INVISIBLE, // Invisible text hidden by default
  778. LAYER_ANCHOR,
  779. LAYER_PAD_FR,
  780. LAYER_PAD_BK,
  781. LAYER_RATSNEST,
  782. LAYER_GRID,
  783. LAYER_GRID_AXES,
  784. LAYER_MOD_FR,
  785. LAYER_MOD_BK,
  786. LAYER_MOD_VALUES,
  787. LAYER_MOD_REFERENCES,
  788. LAYER_TRACKS,
  789. LAYER_PADS_TH,
  790. LAYER_PAD_PLATEDHOLES,
  791. LAYER_PAD_HOLEWALLS,
  792. LAYER_VIA_HOLES,
  793. LAYER_VIA_HOLEWALLS,
  794. LAYER_DRC_ERROR,
  795. LAYER_DRC_WARNING,
  796. // LAYER_DRC_EXCLUSION, // DRC exclusions hidden by default
  797. LAYER_DRAWINGSHEET,
  798. LAYER_GP_OVERLAY,
  799. LAYER_SELECT_OVERLAY,
  800. LAYER_PCB_BACKGROUND,
  801. LAYER_CURSOR,
  802. LAYER_AUX_ITEMS,
  803. LAYER_DRAW_BITMAPS,
  804. LAYER_PADS,
  805. LAYER_ZONES,
  806. LAYER_LOCKED_ITEM_SHADOW,
  807. LAYER_CONFLICTS_SHADOW
  808. };
  809. static const GAL_SET saved( visible, arrayDim( visible ) );
  810. return saved;
  811. }