1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <bitset> // for bitset, __bitset<>::ref...
#include <cassert>
#include <cstdarg>
#include <iostream> // for string, endl, basic_ost...
#include <cstddef> // for size_t
#include <map>
#include <core/arraydim.h>
#include <layer_ids.h> // for PCB_LAYER_ID
#include <layer_range.h>
#include <lseq.h>
#include <macros.h> // for arrayDim
#include <wx/debug.h> // for wxASSERT, wxASSERT_MSG
#include <wx/string.h>
#include <lset.h>
LSET::LSET( std::initializer_list<PCB_LAYER_ID> aList ) :
LSET()
{
for( PCB_LAYER_ID layer : aList )
{
if( layer >= 0 )
set( layer );
}
}
LSET::LSET( const std::vector<PCB_LAYER_ID>& aList ) :
LSET()
{
for( PCB_LAYER_ID layer : aList )
{
if( layer >= 0 )
set( layer );
}
}
LSET::LSET( const LSEQ& aSeq ) :
LSET()
{
for( PCB_LAYER_ID layer : aSeq )
{
if( layer >= 0 )
set( layer );
}
}
LSET::LSET( const LAYER_RANGE& aRange )
{
for( PCB_LAYER_ID layer : aRange )
{
if( layer >= 0 )
set( layer );
}
}
int LSET::LayerCount( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, int aCopperLayerCount )
{
int start = aStart;
int end = aEnd;
// Both layers need to be copper
wxCHECK( IsCopperLayer( aStart ) && IsCopperLayer( aEnd ), aCopperLayerCount );
if( aStart == B_Cu )
std::swap( start, end );
if( aStart == aEnd )
return 1;
if( aStart == F_Cu )
{
if ( aEnd == B_Cu )
return aCopperLayerCount;
else
return ( end - start ) / 2 - 1;
}
else if ( aEnd == B_Cu )
{
// Add 1 for the B_Cu layer
return aCopperLayerCount - start / 2 + 1;
}
return ( end - start ) / 2;
}
int LSET::NameToLayer( wxString& aName )
{
std::map<wxString, PCB_LAYER_ID> layerMap = {
{ "F.Cu", F_Cu },
{ "B.Cu", B_Cu },
{ "F.Adhes", F_Adhes },
{ "B.Adhes", B_Adhes },
{ "F.Paste", F_Paste },
{ "B.Paste", B_Paste },
{ "F.SilkS", F_SilkS },
{ "B.SilkS", B_SilkS },
{ "F.Mask", F_Mask },
{ "B.Mask", B_Mask },
{ "Dwgs.User", Dwgs_User },
{ "Cmts.User", Cmts_User },
{ "Eco1.User", Eco1_User },
{ "Eco2.User", Eco2_User },
{ "Edge.Cuts", Edge_Cuts },
{ "Margin", Margin },
{ "F.CrtYd", F_CrtYd },
{ "B.CrtYd", B_CrtYd },
{ "F.Fab", F_Fab },
{ "B.Fab", B_Fab },
{ "Rescue", Rescue },
{ "B.Cu", B_Cu },
};
if( auto it = layerMap.find( aName ); it != layerMap.end() )
return static_cast<int>( it->second );
if( aName.StartsWith( "User." ) )
{
long offset;
if( aName.Mid( 5 ).ToLong( &offset ) && offset > 0 )
return static_cast<int>( User_1 ) + ( offset - 1 ) * 2;
}
if( aName.StartsWith( "In" ) )
{
long offset;
wxString str_num = aName.Mid( 2 );
str_num.RemoveLast( 3 ); // Removes .Cu
if( str_num.ToLong( &offset ) && offset > 0 )
return static_cast<int>( In1_Cu ) + ( offset - 1 ) * 2;
}
return -1;
}
bool LSET::IsBetween( PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aLayer )
{
if( aLayer == aStart || aLayer == aEnd )
return true;
int start = std::min( aStart, aEnd );
int end = std::max( aStart, aEnd );
int layer = aLayer;
if( end == B_Cu )
{
//Reassign the end layer to the largest possible positive even number
end = std::numeric_limits<PCB_LAYER_ID>::max() & ~1;
}
return !( layer & 1 ) && ( layer >= start ) && ( layer <= end );
}
wxString LSET::Name( PCB_LAYER_ID aLayerId )
{
wxString txt;
// using a switch to explicitly show the mapping more clearly
switch( aLayerId )
{
case F_Cu: txt = wxT( "F.Cu" ); break;
case B_Cu: txt = wxT( "B.Cu" ); break;
// Technicals
case B_Adhes: txt = wxT( "B.Adhes" ); break;
case F_Adhes: txt = wxT( "F.Adhes" ); break;
case B_Paste: txt = wxT( "B.Paste" ); break;
case F_Paste: txt = wxT( "F.Paste" ); break;
case B_SilkS: txt = wxT( "B.SilkS" ); break;
case F_SilkS: txt = wxT( "F.SilkS" ); break;
case B_Mask: txt = wxT( "B.Mask" ); break;
case F_Mask: txt = wxT( "F.Mask" ); break;
// Users
case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
case Cmts_User: txt = wxT( "Cmts.User" ); break;
case Eco1_User: txt = wxT( "Eco1.User" ); break;
case Eco2_User: txt = wxT( "Eco2.User" ); break;
case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
case Margin: txt = wxT( "Margin" ); break;
// Footprint
case F_CrtYd: txt = wxT( "F.CrtYd" ); break;
case B_CrtYd: txt = wxT( "B.CrtYd" ); break;
case F_Fab: txt = wxT( "F.Fab" ); break;
case B_Fab: txt = wxT( "B.Fab" ); break;
// Rescue
case Rescue: txt = wxT( "Rescue" ); break;
default:
if( aLayerId < 0 )
txt = wxT( "UNDEFINED" );
else if( static_cast<int>( aLayerId ) & 1 )
{
int offset = ( aLayerId - Rescue ) / 2;
txt = wxString::Format( wxT( "User.%d" ), offset );
}
else
{
int offset = ( aLayerId - B_Cu ) / 2;
txt = wxString::Format( wxT( "In%d.Cu" ), offset );
}
}
return txt;
}
LSEQ LSET::CuStack() const
{
LSEQ ret;
ret.reserve( 32 );
for( auto it = copper_layers_begin(); it != copper_layers_end(); ++it )
ret.push_back( *it );
return ret;
}
LSEQ LSET::TechAndUserUIOrder() const
{
LSEQ ret;
ret.reserve( 32 );
ret = Seq( {
F_Adhes,
B_Adhes,
F_Paste,
B_Paste,
F_SilkS,
B_SilkS,
F_Mask,
B_Mask,
Dwgs_User,
Cmts_User,
Eco1_User,
Eco2_User,
Edge_Cuts,
Margin,
F_CrtYd,
B_CrtYd,
F_Fab,
B_Fab
} );
for( auto it = non_copper_layers_begin(); it != non_copper_layers_end(); ++it )
{
if( *it >= User_1 )
ret.push_back( *it );
}
return ret;
}
LSEQ LSET::Seq( const LSEQ& aSequence ) const
{
LSEQ ret;
for( PCB_LAYER_ID layer : aSequence )
{
if( test( layer ) )
ret.push_back( layer );
}
return ret;
}
LSEQ LSET::Seq() const
{
LSEQ ret;
ret.reserve( size() );
for( unsigned i = 0; i < size(); ++i )
{
if( test( i ) )
ret.push_back( PCB_LAYER_ID( i ) );
}
return ret;
}
LSEQ LSET::SeqStackupTop2Bottom( PCB_LAYER_ID aSelectedLayer ) const
{
LSEQ base_sequence = Seq( {
Edge_Cuts,
Margin,
Dwgs_User,
Cmts_User,
Eco1_User,
Eco2_User
} );
LSEQ top_tech_sequence = Seq( {
F_Fab,
F_SilkS,
F_Paste,
F_Adhes,
F_Mask,
F_CrtYd,
} );
LSEQ bottom_tech_sequence = Seq( {
B_CrtYd,
B_Mask,
B_Adhes,
B_Paste,
B_SilkS,
B_Fab,
} );
LSEQ seq = Seq( base_sequence );
for( auto it = non_copper_layers_begin(); it != non_copper_layers_end(); ++it )
{
if( *it >= User_1 )
seq.push_back( *it );
}
std::copy( top_tech_sequence.begin(), top_tech_sequence.end(), std::back_inserter( seq ) );
for( auto it = copper_layers_begin(); it != copper_layers_end(); ++it )
seq.push_back( *it );
std::copy( bottom_tech_sequence.begin(), bottom_tech_sequence.end(),
std::back_inserter( seq ) );
if( aSelectedLayer != UNDEFINED_LAYER )
{
auto it = std::find( seq.begin(), seq.end(), aSelectedLayer );
if( it != seq.end() )
{
seq.erase( it );
seq.insert( seq.begin(), aSelectedLayer );
}
}
return seq;
}
LSEQ LSET::SeqStackupForPlotting() const
{
// bottom-to-top stack-up layers
// Note that the bottom technical layers are flipped so that when plotting a bottom-side view,
// they appear in the correct sequence.
LSEQ bottom_tech_sequence = Seq( {
B_Cu,
B_Mask,
B_Paste,
B_SilkS,
B_Adhes,
B_CrtYd,
B_Fab,
} );
// Copper layers go here
LSEQ top_tech_sequence = Seq( {
F_Mask,
F_Paste,
F_SilkS,
F_Adhes,
F_CrtYd,
F_Fab,
} );
LSEQ user_sequence = Seq( {
Dwgs_User,
Cmts_User,
Eco1_User,
Eco2_User,
} );
// User layers go here
LSEQ base_sequence = Seq( {
Margin,
Edge_Cuts,
} );
LSEQ seq = Seq( bottom_tech_sequence );
std::vector<PCB_LAYER_ID> temp_layers;
// We are going to reverse the copper layers and then add them to the sequence
// because the plotting order is bottom-to-top
for( auto it = copper_layers_begin(); it != copper_layers_end(); ++it )
{
// Skip B_Cu because it is already in the sequence (if it exists)
if( *it != B_Cu )
temp_layers.push_back( *it );
}
for( auto it = temp_layers.rbegin(); it != temp_layers.rend(); ++it )
seq.push_back( *it );
std::copy( top_tech_sequence.begin(), top_tech_sequence.end(), std::back_inserter( seq ) );
std::copy( user_sequence.begin(), user_sequence.end(), std::back_inserter( seq ) );
temp_layers.clear();
for( auto it = non_copper_layers_begin(); it != non_copper_layers_end(); ++it )
{
if( *it >= User_1 )
temp_layers.push_back( *it );
}
for( auto it = temp_layers.rbegin(); it != temp_layers.rend(); ++it )
{
seq.push_back( *it );
}
std::copy( base_sequence.begin(), base_sequence.end(), std::back_inserter( seq ) );
return seq;
}
LSET& LSET::FlipStandardLayers( int aCopperLayersCount )
{
LSET oldMask = *this;
reset();
// Mapping for Copper and Non-Copper layers
const std::map<PCB_LAYER_ID, PCB_LAYER_ID> flip_map =
{
{F_Cu, B_Cu},
{B_Cu, F_Cu},
{F_SilkS, B_SilkS},
{B_SilkS, F_SilkS},
{F_Adhes, B_Adhes},
{B_Adhes, F_Adhes},
{F_Mask, B_Mask},
{B_Mask, F_Mask},
{F_Paste, B_Paste},
{B_Paste, F_Paste},
{F_CrtYd, B_CrtYd},
{B_CrtYd, F_CrtYd},
{F_Fab, B_Fab},
{B_Fab, F_Fab}
};
for( const auto& pair : flip_map )
{
if( oldMask.test( pair.first ) )
set( pair.second );
oldMask.set( pair.first, false );
}
if( aCopperLayersCount >= 4 )
{
LSET internalMask = oldMask & InternalCuMask();
int innerLayerCount = aCopperLayersCount - 2;
for( int ii = 1; ii <= innerLayerCount; ii++ )
{
if( internalMask.test( ( innerLayerCount - ii + 1 ) * 2 + B_Cu ) )
{
set( ii * 2 + B_Cu );
}
}
}
oldMask.ClearCopperLayers();
// Copy across any remaining, non-side-specific layers
for( PCB_LAYER_ID layer : oldMask )
set( layer );
return *this;
}
PCB_LAYER_ID LSET::ExtractLayer() const
{
unsigned set_count = count();
if( !set_count )
return UNSELECTED_LAYER;
else if( set_count > 1 )
return UNDEFINED_LAYER;
for( unsigned i=0; i < size(); ++i )
{
if( test( i ) )
return PCB_LAYER_ID( i );
}
wxASSERT( 0 ); // set_count was verified as 1 above, what did you break?
return UNDEFINED_LAYER;
}
const LSET& LSET::FrontAssembly()
{
static LSET saved( { F_SilkS, F_Mask, F_Fab, F_CrtYd } );
return saved;
}
const LSET& LSET::BackAssembly()
{
static LSET saved( { B_SilkS, B_Mask, B_Fab, B_CrtYd } );
return saved;
}
const LSET& LSET::InternalCuMask()
{
static LSET saved( { In1_Cu, In2_Cu, In3_Cu, In4_Cu, In5_Cu, In6_Cu,
In7_Cu, In8_Cu, In9_Cu, In10_Cu, In11_Cu, In12_Cu,
In13_Cu, In14_Cu, In15_Cu, In16_Cu, In17_Cu, In18_Cu,
In19_Cu, In20_Cu, In21_Cu, In22_Cu, In23_Cu, In24_Cu,
In25_Cu, In26_Cu, In27_Cu, In28_Cu, In29_Cu, In30_Cu } );
return saved;
}
LSET allCuMask( int aCuLayerCount )
{
LSET ret;
for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, aCuLayerCount ) )
ret.set( layer );
return ret;
}
LSET LSET::AllCuMask( int aCuLayerCount )
{
static LSET savedMax = allCuMask( MAX_CU_LAYERS );
static LSET cache;
static int cacheCuLayerCount = -1;
if( aCuLayerCount == MAX_CU_LAYERS )
return savedMax;
if( aCuLayerCount != cacheCuLayerCount )
{
cache = allCuMask( aCuLayerCount );
cacheCuLayerCount = aCuLayerCount;
}
return cache;
}
LSET allNonCuMask()
{
LSET mask = LSET().set();
for( auto it = mask.copper_layers_begin(); it != mask.copper_layers_end(); ++it )
mask.reset( *it );
return mask;
}
LSET LSET::AllNonCuMask()
{
static LSET saved = allNonCuMask();
return saved;
}
const LSET& LSET::ExternalCuMask()
{
static LSET saved( { F_Cu, B_Cu } );
return saved;
}
const LSET& LSET::AllLayersMask()
{
static LSET saved = LSET().set();
return saved;
}
const LSET& LSET::BackTechMask()
{
static LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab } );
return saved;
}
const LSET& LSET::BackBoardTechMask()
{
static LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste } );
return saved;
}
const LSET& LSET::FrontTechMask()
{
static LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab } );
return saved;
}
const LSET& LSET::FrontBoardTechMask()
{
static LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste } );
return saved;
}
const LSET& LSET::AllTechMask()
{
static LSET saved = BackTechMask() | FrontTechMask();
return saved;
}
const LSET& LSET::AllBoardTechMask()
{
static LSET saved = BackBoardTechMask() | FrontBoardTechMask();
return saved;
}
const LSET& LSET::UserMask()
{
static LSET saved( { Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts, Margin } );
return saved;
}
const LSET& LSET::PhysicalLayersMask()
{
static LSET saved = AllBoardTechMask() | AllCuMask();
return saved;
}
LSET LSET::UserDefinedLayersMask( int aUserDefinedLayerCount )
{
LSET ret;
size_t layer = User_1;
for( int ulayer = 1; ulayer <= aUserDefinedLayerCount; ulayer++ )
{
if( layer > ret.size() )
break;
ret.set( layer );
layer += 2;
}
return ret;
}
const LSET& LSET::FrontMask()
{
static LSET saved = LSET( FrontTechMask() ).set( F_Cu );
return saved;
}
const LSET& LSET::BackMask()
{
static LSET saved = LSET( BackTechMask() ).set( B_Cu );
return saved;
}
const LSET& LSET::SideSpecificMask()
{
static LSET saved = BackTechMask() | FrontTechMask() | AllCuMask();
return saved;
}
const LSET& LSET::ForbiddenFootprintLayers()
{
static LSET saved = LSET( InternalCuMask() ).set( In1_Cu, false );
return saved;
}
LSEQ LSET::UIOrder() const
{
LSEQ order = CuStack();
LSEQ techuser = TechAndUserUIOrder();
order.insert( order.end(), techuser.begin(), techuser.end() );
return order;
}
PCB_LAYER_ID ToLAYER_ID( int aLayer )
{
// We use std::numeric_limits<int>::max() to represent B_Cu for the connectivity_rtree
if( aLayer == std::numeric_limits<int>::max() )
return B_Cu;
wxASSERT( aLayer < GAL_LAYER_ID_END );
return PCB_LAYER_ID( aLayer );
}
GAL_SET::GAL_SET( const GAL_LAYER_ID* aArray, unsigned aCount ) : GAL_SET()
{
for( unsigned i = 0; i < aCount; ++i )
set( aArray[i] );
}
std::vector<GAL_LAYER_ID> GAL_SET::Seq() const
{
std::vector<GAL_LAYER_ID> ret;
for( size_t i = 0; i < size(); ++i )
{
if( test( i ) )
ret.push_back( static_cast<GAL_LAYER_ID>( i + GAL_LAYER_ID_START ) );
}
return ret;
}
GAL_SET GAL_SET::DefaultVisible()
{
static const GAL_LAYER_ID visible[] = {
LAYER_VIAS,
LAYER_VIA_MICROVIA,
LAYER_VIA_BBLIND,
LAYER_VIA_THROUGH,
// LAYER_HIDDEN_TEXT, // DEPCREATED SINCE 9.0. Invisible text hidden by default
LAYER_ANCHOR,
LAYER_RATSNEST,
LAYER_GRID,
LAYER_GRID_AXES,
LAYER_FOOTPRINTS_FR,
LAYER_FOOTPRINTS_BK,
LAYER_FP_TEXT,
LAYER_FP_VALUES,
LAYER_FP_REFERENCES,
LAYER_TRACKS,
LAYER_PAD_PLATEDHOLES,
LAYER_NON_PLATEDHOLES,
LAYER_PAD_HOLEWALLS,
LAYER_VIA_HOLES,
LAYER_VIA_HOLEWALLS,
LAYER_DRC_ERROR,
LAYER_DRC_WARNING,
LAYER_DRC_SHAPE1,
LAYER_DRC_SHAPE2,
// LAYER_DRC_EXCLUSION, // DRC exclusions hidden by default
LAYER_DRAWINGSHEET,
LAYER_GP_OVERLAY,
LAYER_SELECT_OVERLAY,
LAYER_PCB_BACKGROUND,
LAYER_CURSOR,
LAYER_AUX_ITEMS,
LAYER_DRAW_BITMAPS,
LAYER_PADS,
LAYER_ZONES,
LAYER_FILLED_SHAPES,
LAYER_LOCKED_ITEM_SHADOW,
LAYER_CONFLICTS_SHADOW
};
static const GAL_SET saved( visible, arrayDim( visible ) );
return saved;
}
#ifndef SWIG // Skip SWIG generators for the iterators because it requires a default constructor
// Custom iterators for Copper and Non-Copper layers
LSET::copper_layers_iterator::copper_layers_iterator( const BASE_SET& set, size_t index ) :
BASE_SET::set_bits_iterator( set, index )
{
m_index = ( index + 1 ) & ~1;
advance_to_next_set_copper_bit();
}
PCB_LAYER_ID LSET::copper_layers_iterator::operator*() const
{
return static_cast<PCB_LAYER_ID>( m_index );
}
LSET::copper_layers_iterator& LSET::copper_layers_iterator::operator++()
{
next_copper_layer();
advance_to_next_set_copper_bit();
return *this;
}
void LSET::copper_layers_iterator::next_copper_layer()
{
if( m_index == F_Cu )
{
m_index += 4;
}
else if( m_index == B_Cu )
{
m_index = m_baseSet.size();
return;
}
else
{
m_index += 2;
if( m_index >= m_baseSet.size() )
m_index = B_Cu;
}
}
void LSET::copper_layers_iterator::advance_to_next_set_copper_bit()
{
while( m_index < m_baseSet.size() && !m_baseSet.test( m_index ) )
next_copper_layer();
}
LSET::non_copper_layers_iterator::non_copper_layers_iterator( const BASE_SET& set, size_t index ) :
BASE_SET::set_bits_iterator( set, index )
{
advance_to_next_set_non_copper_bit();
}
PCB_LAYER_ID LSET::non_copper_layers_iterator::operator*() const
{
return static_cast<PCB_LAYER_ID>( m_index );
}
LSET::non_copper_layers_iterator& LSET::non_copper_layers_iterator::operator++()
{
++m_index;
advance_to_next_set_non_copper_bit();
return *this;
}
void LSET::non_copper_layers_iterator::advance_to_next_set_non_copper_bit()
{
while( m_index < m_baseSet.size() && ( m_index % 2 != 1 || !m_baseSet.test( m_index ) ) )
{
++m_index;
}
}
LSET::copper_layers_iterator LSET::copper_layers_begin() const
{
return copper_layers_iterator( *this, 0 );
}
LSET::copper_layers_iterator LSET::copper_layers_end() const
{
return copper_layers_iterator( *this, size() );
}
LSET::non_copper_layers_iterator LSET::non_copper_layers_begin() const
{
return non_copper_layers_iterator( *this, 0 );
}
LSET::non_copper_layers_iterator LSET::non_copper_layers_end() const
{
return non_copper_layers_iterator( *this, size() );
}
LSET& LSET::ClearCopperLayers()
{
for( size_t ii = 0; ii < size(); ii += 2 )
reset( ii );
return *this;
}
LSET& LSET::ClearNonCopperLayers()
{
for( size_t ii = 1; ii < size(); ii += 2 )
reset( ii );
return *this;
}
LSET& LSET::ClearUserDefinedLayers()
{
for( size_t ii = User_1; ii < size(); ii += 2 )
reset( ii );
return *this;
}
#endif
|