2014-06-25 14:24:02 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 2014-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-06-25 14:24:02 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <bitset> // for bitset, __bitset<>::ref...
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdarg>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <iostream> // for string, endl, basic_ost...
|
|
|
|
#include <stddef.h> // for size_t
|
2014-06-25 14:24:02 +00:00
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for Clamp
|
|
|
|
#include <layers_id_colors_and_visibility.h> // for LSET, PCB_LAYER_ID, LSEQ
|
|
|
|
#include <macros.h> // for arrayDim
|
|
|
|
#include <wx/debug.h> // for wxASSERT, wxASSERT_MSG
|
|
|
|
#include <wx/wx.h> // for wxT, wxChar
|
2014-06-24 18:31:41 +00:00
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
LSET::LSET( const PCB_LAYER_ID* aArray, unsigned aCount ) :
|
2014-06-29 20:33:29 +00:00
|
|
|
BASE_SET()
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
for( unsigned i=0; i<aCount; ++i )
|
|
|
|
set( aArray[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-18 02:43:54 +00:00
|
|
|
LSET::LSET( unsigned aIdCount, int aFirst, ... ) :
|
2014-06-29 20:33:29 +00:00
|
|
|
BASE_SET()
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
2014-06-29 18:09:32 +00:00
|
|
|
// The constructor, without the mandatory aFirst argument, could have been confused
|
2017-03-13 03:19:33 +00:00
|
|
|
// by the compiler with the LSET( PCB_LAYER_ID ). With aFirst, that ambiguity is not
|
2014-06-29 18:09:32 +00:00
|
|
|
// present. Therefore aIdCount must always be >=1.
|
|
|
|
wxASSERT_MSG( aIdCount > 0, wxT( "aIdCount must be >= 1" ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
set( aFirst );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
if( --aIdCount )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
2014-06-29 18:09:32 +00:00
|
|
|
va_list ap;
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
va_start( ap, aFirst );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
for( unsigned i=0; i<aIdCount; ++i )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID id = (PCB_LAYER_ID) va_arg( ap, int );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
assert( unsigned( id ) < PCB_LAYER_ID_COUNT );
|
2014-06-29 18:09:32 +00:00
|
|
|
|
|
|
|
set( id );
|
|
|
|
}
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
va_end( ap );
|
|
|
|
}
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 00:20:45 +00:00
|
|
|
/**
|
|
|
|
* NOTE: These names must not be translated or changed. They are used as tokens in the board
|
|
|
|
* file format because the ordinal value of the PCB_LAYER_ID enum was not stable over time.
|
|
|
|
* @see LayerName() for what should be used to display the default name of a layer in the GUI.
|
|
|
|
*/
|
2017-03-13 03:19:33 +00:00
|
|
|
const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
const wxChar* txt;
|
|
|
|
|
|
|
|
// using a switch to explicitly show the mapping more clearly
|
|
|
|
switch( aLayerId )
|
|
|
|
{
|
|
|
|
case F_Cu: txt = wxT( "F.Cu" ); break;
|
|
|
|
case In1_Cu: txt = wxT( "In1.Cu" ); break;
|
|
|
|
case In2_Cu: txt = wxT( "In2.Cu" ); break;
|
|
|
|
case In3_Cu: txt = wxT( "In3.Cu" ); break;
|
|
|
|
case In4_Cu: txt = wxT( "In4.Cu" ); break;
|
|
|
|
case In5_Cu: txt = wxT( "In5.Cu" ); break;
|
|
|
|
case In6_Cu: txt = wxT( "In6.Cu" ); break;
|
|
|
|
case In7_Cu: txt = wxT( "In7.Cu" ); break;
|
|
|
|
case In8_Cu: txt = wxT( "In8.Cu" ); break;
|
|
|
|
case In9_Cu: txt = wxT( "In9.Cu" ); break;
|
|
|
|
case In10_Cu: txt = wxT( "In10.Cu" ); break;
|
|
|
|
case In11_Cu: txt = wxT( "In11.Cu" ); break;
|
|
|
|
case In12_Cu: txt = wxT( "In12.Cu" ); break;
|
|
|
|
case In13_Cu: txt = wxT( "In13.Cu" ); break;
|
|
|
|
case In14_Cu: txt = wxT( "In14.Cu" ); break;
|
|
|
|
case In15_Cu: txt = wxT( "In15.Cu" ); break;
|
|
|
|
case In16_Cu: txt = wxT( "In16.Cu" ); break;
|
|
|
|
case In17_Cu: txt = wxT( "In17.Cu" ); break;
|
|
|
|
case In18_Cu: txt = wxT( "In18.Cu" ); break;
|
|
|
|
case In19_Cu: txt = wxT( "In19.Cu" ); break;
|
|
|
|
case In20_Cu: txt = wxT( "In20.Cu" ); break;
|
|
|
|
case In21_Cu: txt = wxT( "In21.Cu" ); break;
|
|
|
|
case In22_Cu: txt = wxT( "In22.Cu" ); break;
|
|
|
|
case In23_Cu: txt = wxT( "In23.Cu" ); break;
|
|
|
|
case In24_Cu: txt = wxT( "In24.Cu" ); break;
|
|
|
|
case In25_Cu: txt = wxT( "In25.Cu" ); break;
|
|
|
|
case In26_Cu: txt = wxT( "In26.Cu" ); break;
|
|
|
|
case In27_Cu: txt = wxT( "In27.Cu" ); break;
|
|
|
|
case In28_Cu: txt = wxT( "In28.Cu" ); break;
|
|
|
|
case In29_Cu: txt = wxT( "In29.Cu" ); break;
|
|
|
|
case In30_Cu: txt = wxT( "In30.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
|
2014-07-06 16:59:26 +00:00
|
|
|
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;
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2018-12-07 00:24:27 +00:00
|
|
|
// Rescue
|
|
|
|
case Rescue: txt = wxT( "Rescue" ); break;
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
default:
|
2017-03-13 03:19:33 +00:00
|
|
|
std::cout << aLayerId << std::endl;
|
2014-06-24 18:31:41 +00:00
|
|
|
wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
|
|
|
|
txt = wxT( "BAD INDEX!" ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSEQ LSET::CuStack() const
|
|
|
|
{
|
|
|
|
// desired sequence
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID sequence[] = {
|
2014-06-24 18:31:41 +00:00
|
|
|
F_Cu,
|
|
|
|
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,
|
|
|
|
B_Cu, // 31
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
return Seq( sequence, arrayDim( sequence ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSEQ LSET::Technicals( LSET aSetToOmit ) const
|
|
|
|
{
|
|
|
|
// desired sequence
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID sequence[] = {
|
2014-06-24 18:31:41 +00:00
|
|
|
F_Adhes,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_Adhes,
|
2014-06-24 18:31:41 +00:00
|
|
|
F_Paste,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_Paste,
|
2014-06-24 18:31:41 +00:00
|
|
|
F_SilkS,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_SilkS,
|
2014-06-24 18:31:41 +00:00
|
|
|
F_Mask,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_Mask,
|
2014-06-24 18:31:41 +00:00
|
|
|
F_CrtYd,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_CrtYd,
|
2014-06-24 18:31:41 +00:00
|
|
|
F_Fab,
|
2018-01-12 03:32:14 +00:00
|
|
|
B_Fab,
|
2014-06-24 18:31:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LSET subset = ~aSetToOmit & *this;
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
return subset.Seq( sequence, arrayDim( sequence ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSEQ LSET::Users() const
|
|
|
|
{
|
|
|
|
// desired
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID sequence[] = {
|
2014-06-24 18:31:41 +00:00
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
|
|
|
Eco2_User,
|
|
|
|
Edge_Cuts,
|
|
|
|
Margin,
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
return Seq( sequence, arrayDim( sequence ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-12 03:32:14 +00:00
|
|
|
LSEQ LSET::TechAndUserUIOrder() const
|
|
|
|
{
|
|
|
|
static const PCB_LAYER_ID sequence[] = {
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
return Seq( sequence, arrayDim( sequence ) );
|
2018-01-12 03:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
std::string LSET::FmtBin() const
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
int bit_count = size();
|
|
|
|
|
|
|
|
for( int bit=0; bit<bit_count; ++bit )
|
|
|
|
{
|
|
|
|
if( bit )
|
|
|
|
{
|
|
|
|
if( !( bit % 8 ) )
|
|
|
|
ret += '|';
|
|
|
|
else if( !( bit % 4 ) )
|
|
|
|
ret += '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += (*this)[bit] ? '1' : '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// reverse of string
|
|
|
|
return std::string( ret.rbegin(), ret.rend() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LSET::FmtHex() const
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
|
2019-12-21 02:04:34 +00:00
|
|
|
size_t nibble_count = ( size() + 3 ) / 4;
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2019-12-21 02:04:34 +00:00
|
|
|
for( size_t nibble = 0; nibble < nibble_count; ++nibble )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
2019-12-21 02:04:34 +00:00
|
|
|
unsigned int ndx = 0;
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2019-12-21 02:04:34 +00:00
|
|
|
// test 4 consecutive bits and set ndx to 0-15
|
2019-12-26 03:37:25 +00:00
|
|
|
for( size_t nibble_bit = 0; nibble_bit < 4; ++nibble_bit )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
2019-12-21 02:04:34 +00:00
|
|
|
size_t nibble_pos = nibble_bit + ( nibble * 4 );
|
|
|
|
// make sure it's not extra bits that dont exist in the bitset but need to in the hex format
|
|
|
|
if( nibble_pos >= size() )
|
2019-12-25 16:34:12 +00:00
|
|
|
break;
|
|
|
|
|
2019-12-21 02:04:34 +00:00
|
|
|
if( ( *this )[nibble_pos] )
|
2019-12-25 16:34:12 +00:00
|
|
|
ndx |= ( 1 << nibble_bit );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( nibble && !( nibble % 8 ) )
|
|
|
|
ret += '_';
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
assert( ndx < arrayDim( hex ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
|
|
|
ret += hex[ndx];
|
|
|
|
}
|
|
|
|
|
|
|
|
// reverse of string
|
|
|
|
return std::string( ret.rbegin(), ret.rend() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LSET::ParseHex( const char* aStart, int aCount )
|
|
|
|
{
|
|
|
|
LSET tmp;
|
|
|
|
|
|
|
|
const char* rstart = aStart + aCount - 1;
|
|
|
|
const char* rend = aStart - 1;
|
|
|
|
|
|
|
|
const int bitcount = size();
|
|
|
|
|
|
|
|
int nibble_ndx = 0;
|
|
|
|
|
|
|
|
while( rstart > rend )
|
|
|
|
{
|
|
|
|
int cc = *rstart--;
|
|
|
|
|
|
|
|
if( cc == '_' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int nibble;
|
|
|
|
|
|
|
|
if( cc >= '0' && cc <= '9' )
|
|
|
|
nibble = cc - '0';
|
|
|
|
else if( cc >= 'a' && cc <= 'f' )
|
|
|
|
nibble = cc - 'a' + 10;
|
2014-06-25 14:24:02 +00:00
|
|
|
else if( cc >= 'A' && cc <= 'F' )
|
|
|
|
nibble = cc - 'A' + 10;
|
2014-06-24 18:31:41 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
int bit = nibble_ndx * 4;
|
|
|
|
|
|
|
|
for( int ndx=0; bit<bitcount && ndx<4; ++bit, ++ndx )
|
|
|
|
if( nibble & (1<<ndx) )
|
|
|
|
tmp.set( bit );
|
|
|
|
|
|
|
|
if( bit >= bitcount )
|
|
|
|
break;
|
|
|
|
|
|
|
|
++nibble_ndx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int byte_count = aStart + aCount - 1 - rstart;
|
|
|
|
|
|
|
|
assert( byte_count >= 0 );
|
|
|
|
|
|
|
|
if( byte_count > 0 )
|
|
|
|
*this = tmp;
|
|
|
|
|
|
|
|
return byte_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
LSEQ LSET::Seq( const PCB_LAYER_ID* aWishListSequence, unsigned aCount ) const
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
LSEQ ret;
|
|
|
|
|
2014-06-25 14:24:02 +00:00
|
|
|
#if defined(DEBUG) && 0
|
2014-06-24 18:31:41 +00:00
|
|
|
LSET dup_detector;
|
|
|
|
|
|
|
|
for( unsigned i=0; i<aCount; ++i )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID id = aWishListSequence[i];
|
2014-06-24 18:31:41 +00:00
|
|
|
|
|
|
|
if( test( id ) )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !dup_detector[id], wxT( "Duplicate in aWishListSequence" ) );
|
|
|
|
dup_detector[id] = true;
|
|
|
|
|
|
|
|
ret.push_back( id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
for( unsigned i=0; i<aCount; ++i )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID id = aWishListSequence[i];
|
2014-06-24 18:31:41 +00:00
|
|
|
|
|
|
|
if( test( id ) )
|
|
|
|
ret.push_back( id );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSEQ LSET::Seq() const
|
|
|
|
{
|
|
|
|
LSEQ ret;
|
|
|
|
|
2020-08-10 21:52:22 +00:00
|
|
|
ret.reserve( size() );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < size(); ++i )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
2020-08-10 21:52:22 +00:00
|
|
|
if( test( i ) )
|
2017-03-13 03:19:33 +00:00
|
|
|
ret.push_back( PCB_LAYER_ID( i ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-10 14:15:02 +00:00
|
|
|
LSEQ LSET::SeqStackupBottom2Top() const
|
|
|
|
{
|
|
|
|
// bottom-to-top stack-up layers
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID sequence[] = {
|
2014-08-10 14:15:02 +00:00
|
|
|
B_Fab,
|
|
|
|
B_CrtYd,
|
|
|
|
B_Adhes,
|
|
|
|
B_SilkS,
|
|
|
|
B_Paste,
|
|
|
|
B_Mask,
|
|
|
|
B_Cu,
|
|
|
|
In30_Cu,
|
|
|
|
In29_Cu,
|
|
|
|
In28_Cu,
|
|
|
|
In27_Cu,
|
|
|
|
In26_Cu,
|
|
|
|
In25_Cu,
|
|
|
|
In24_Cu,
|
|
|
|
In23_Cu,
|
|
|
|
In22_Cu,
|
|
|
|
In21_Cu,
|
|
|
|
In20_Cu,
|
|
|
|
In19_Cu,
|
|
|
|
In18_Cu,
|
|
|
|
In17_Cu,
|
|
|
|
In16_Cu,
|
|
|
|
In15_Cu,
|
|
|
|
In14_Cu,
|
|
|
|
In13_Cu,
|
|
|
|
In12_Cu,
|
|
|
|
In11_Cu,
|
|
|
|
In10_Cu,
|
|
|
|
In9_Cu,
|
|
|
|
In8_Cu,
|
|
|
|
In7_Cu,
|
|
|
|
In6_Cu,
|
|
|
|
In5_Cu,
|
|
|
|
In4_Cu,
|
|
|
|
In3_Cu,
|
|
|
|
In2_Cu,
|
|
|
|
In1_Cu,
|
|
|
|
F_Cu,
|
|
|
|
F_Mask,
|
|
|
|
F_Paste,
|
|
|
|
F_SilkS,
|
|
|
|
F_Adhes,
|
|
|
|
F_CrtYd,
|
|
|
|
F_Fab,
|
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
|
|
|
Eco2_User,
|
|
|
|
Margin,
|
|
|
|
Edge_Cuts,
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
return Seq( sequence, arrayDim( sequence ) );
|
2014-08-10 14:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
switch( aLayerId )
|
|
|
|
{
|
|
|
|
case B_Cu: return F_Cu;
|
|
|
|
case F_Cu: return B_Cu;
|
|
|
|
|
|
|
|
case B_SilkS: return F_SilkS;
|
|
|
|
case F_SilkS: return B_SilkS;
|
|
|
|
|
|
|
|
case B_Adhes: return F_Adhes;
|
|
|
|
case F_Adhes: return B_Adhes;
|
|
|
|
|
|
|
|
case B_Mask: return F_Mask;
|
|
|
|
case F_Mask: return B_Mask;
|
|
|
|
|
|
|
|
case B_Paste: return F_Paste;
|
|
|
|
case F_Paste: return B_Paste;
|
|
|
|
|
|
|
|
case B_CrtYd: return F_CrtYd;
|
|
|
|
case F_CrtYd: return B_CrtYd;
|
|
|
|
|
|
|
|
case B_Fab: return F_Fab;
|
|
|
|
case F_Fab: return B_Fab;
|
|
|
|
|
2015-12-27 15:51:13 +00:00
|
|
|
default: // change internal layer if aCopperLayersCount is >= 4
|
|
|
|
if( IsCopperLayer( aLayerId ) && aCopperLayersCount >= 4 )
|
|
|
|
{
|
|
|
|
// internal copper layers count is aCopperLayersCount-2
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID fliplayer = PCB_LAYER_ID(aCopperLayersCount - 2 - ( aLayerId - In1_Cu ) );
|
2015-12-27 15:51:13 +00:00
|
|
|
// Ensure fliplayer has a value which does not crash pcbnew:
|
|
|
|
if( fliplayer < F_Cu )
|
|
|
|
fliplayer = F_Cu;
|
|
|
|
|
|
|
|
if( fliplayer > B_Cu )
|
|
|
|
fliplayer = B_Cu;
|
|
|
|
|
|
|
|
return fliplayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No change for the other layers
|
2014-06-24 18:31:41 +00:00
|
|
|
return aLayerId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-27 15:51:13 +00:00
|
|
|
LSET FlipLayerMask( LSET aMask, int aCopperLayersCount )
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
// layers on physical outside of a board:
|
|
|
|
const static LSET and_mask( 16, // !! update count
|
|
|
|
B_Cu, F_Cu,
|
|
|
|
B_SilkS, F_SilkS,
|
|
|
|
B_Adhes, F_Adhes,
|
|
|
|
B_Mask, F_Mask,
|
|
|
|
B_Paste, F_Paste,
|
|
|
|
B_Adhes, F_Adhes,
|
|
|
|
B_CrtYd, F_CrtYd,
|
|
|
|
B_Fab, F_Fab
|
|
|
|
);
|
|
|
|
|
|
|
|
LSET newMask = aMask & ~and_mask;
|
|
|
|
|
|
|
|
if( aMask[B_Cu] )
|
|
|
|
newMask.set( F_Cu );
|
|
|
|
|
|
|
|
if( aMask[F_Cu] )
|
|
|
|
newMask.set( B_Cu );
|
|
|
|
|
|
|
|
if( aMask[B_SilkS] )
|
|
|
|
newMask.set( F_SilkS );
|
|
|
|
|
|
|
|
if( aMask[F_SilkS] )
|
|
|
|
newMask.set( B_SilkS );
|
|
|
|
|
|
|
|
if( aMask[B_Adhes] )
|
|
|
|
newMask.set( F_Adhes );
|
|
|
|
|
|
|
|
if( aMask[F_Adhes] )
|
|
|
|
newMask.set( B_Adhes );
|
|
|
|
|
|
|
|
if( aMask[B_Mask] )
|
|
|
|
newMask.set( F_Mask );
|
|
|
|
|
|
|
|
if( aMask[F_Mask] )
|
|
|
|
newMask.set( B_Mask );
|
|
|
|
|
|
|
|
if( aMask[B_Paste] )
|
|
|
|
newMask.set( F_Paste );
|
|
|
|
|
|
|
|
if( aMask[F_Paste] )
|
|
|
|
newMask.set( B_Paste );
|
|
|
|
|
|
|
|
if( aMask[B_Adhes] )
|
|
|
|
newMask.set( F_Adhes );
|
|
|
|
|
|
|
|
if( aMask[F_Adhes] )
|
|
|
|
newMask.set( B_Adhes );
|
|
|
|
|
|
|
|
if( aMask[B_CrtYd] )
|
|
|
|
newMask.set( F_CrtYd );
|
|
|
|
|
|
|
|
if( aMask[F_CrtYd] )
|
|
|
|
newMask.set( B_CrtYd );
|
|
|
|
|
|
|
|
if( aMask[B_Fab] )
|
|
|
|
newMask.set( F_Fab );
|
|
|
|
|
|
|
|
if( aMask[F_Fab] )
|
|
|
|
newMask.set( B_Fab );
|
|
|
|
|
2015-12-27 15:51:13 +00:00
|
|
|
if( aCopperLayersCount >= 4 ) // Internal layers exist
|
|
|
|
{
|
2017-09-27 07:59:12 +00:00
|
|
|
LSET internalMask = aMask & LSET::InternalCuMask();
|
2015-12-27 15:51:13 +00:00
|
|
|
|
|
|
|
if( internalMask != LSET::InternalCuMask() )
|
2017-09-27 07:59:12 +00:00
|
|
|
{
|
|
|
|
// the mask does not include all internal layers. Therefore
|
2015-12-27 15:51:13 +00:00
|
|
|
// the flipped mask for internal copper layers must be built
|
|
|
|
int innerLayerCnt = aCopperLayersCount -2;
|
|
|
|
|
2017-09-27 07:59:12 +00:00
|
|
|
// the flipped mask is the innerLayerCnt bits rewritten in reverse order
|
|
|
|
// ( bits innerLayerCnt to 1 rewritten in bits 1 to innerLayerCnt )
|
2015-12-27 15:51:13 +00:00
|
|
|
for( int ii = 0; ii < innerLayerCnt; ii++ )
|
|
|
|
{
|
2017-09-27 07:59:12 +00:00
|
|
|
if( internalMask[innerLayerCnt - ii] )
|
|
|
|
{
|
2015-12-27 15:51:13 +00:00
|
|
|
newMask.set( ii + In1_Cu );
|
2017-09-27 07:59:12 +00:00
|
|
|
}
|
2015-12-27 15:51:13 +00:00
|
|
|
else
|
2017-09-27 07:59:12 +00:00
|
|
|
{
|
2015-12-27 15:51:13 +00:00
|
|
|
newMask.reset( ii + In1_Cu );
|
2017-09-27 07:59:12 +00:00
|
|
|
}
|
2015-12-27 15:51:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
return newMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID LSET::ExtractLayer() const
|
2014-06-24 18:31:41 +00:00
|
|
|
{
|
|
|
|
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 ) )
|
2017-03-13 03:19:33 +00:00
|
|
|
return PCB_LAYER_ID( i );
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT( 0 ); // set_count was verified as 1 above, what did you break?
|
|
|
|
|
|
|
|
return UNDEFINED_LAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-22 20:40:53 +00:00
|
|
|
LSET LSET::FrontAssembly()
|
|
|
|
{
|
|
|
|
static const PCB_LAYER_ID front_assembly[] = {
|
|
|
|
F_SilkS,
|
|
|
|
F_Mask,
|
2020-05-26 17:57:22 +00:00
|
|
|
F_Fab,
|
2020-07-11 17:42:00 +00:00
|
|
|
F_CrtYd
|
2020-05-22 20:40:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const LSET saved( front_assembly, arrayDim( front_assembly ) );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::BackAssembly()
|
|
|
|
{
|
|
|
|
static const PCB_LAYER_ID back_assembly[] = {
|
|
|
|
B_SilkS,
|
|
|
|
B_Mask,
|
2020-05-26 17:57:22 +00:00
|
|
|
B_Fab,
|
2020-07-11 17:42:00 +00:00
|
|
|
B_CrtYd
|
2020-05-22 20:40:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const LSET saved( back_assembly, arrayDim( back_assembly ) );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
LSET LSET::InternalCuMask()
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
static const PCB_LAYER_ID cu_internals[] = {
|
2014-06-24 18:31:41 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
static const LSET saved( cu_internals, arrayDim( cu_internals ) );
|
2014-06-24 18:31:41 +00:00
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::AllCuMask( int aCuLayerCount )
|
|
|
|
{
|
|
|
|
// retain all in static as the full set, which is a common case.
|
|
|
|
static const LSET all = InternalCuMask().set( F_Cu ).set( B_Cu );
|
|
|
|
|
|
|
|
if( aCuLayerCount == MAX_CU_LAYERS )
|
|
|
|
return all;
|
|
|
|
|
|
|
|
// subtract out some Cu layers not wanted in the mask.
|
|
|
|
LSET ret = all;
|
|
|
|
int clear_count = MAX_CU_LAYERS - aCuLayerCount;
|
|
|
|
|
|
|
|
clear_count = Clamp( 0, clear_count, MAX_CU_LAYERS - 2 );
|
|
|
|
|
|
|
|
for( LAYER_NUM elem=In30_Cu; clear_count; --elem, --clear_count )
|
|
|
|
{
|
|
|
|
ret.set( elem, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::AllNonCuMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = LSET().set() & ~AllCuMask();
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
LSET LSET::ExternalCuMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 2, F_Cu, B_Cu );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
LSET LSET::AllLayersMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = LSET().set();
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::BackTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 6, B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
LSET LSET::BackBoardTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 4, B_SilkS, B_Mask, B_Adhes, B_Paste );
|
|
|
|
return saved;
|
|
|
|
}
|
2014-06-24 18:31:41 +00:00
|
|
|
|
|
|
|
LSET LSET::FrontTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 6, F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
LSET LSET::FrontBoardTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 4, F_SilkS, F_Mask, F_Adhes, F_Paste );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
LSET LSET::AllTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = BackTechMask() | FrontTechMask();
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
LSET LSET::AllBoardTechMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = BackBoardTechMask() | FrontBoardTechMask();
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
LSET LSET::UserMask()
|
|
|
|
{
|
|
|
|
static const LSET saved( 6,
|
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
|
|
|
Eco2_User,
|
|
|
|
Edge_Cuts,
|
|
|
|
Margin
|
|
|
|
);
|
|
|
|
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::FrontMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = FrontTechMask().set( F_Cu );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LSET::BackMask()
|
|
|
|
{
|
|
|
|
static const LSET saved = BackTechMask().set( B_Cu );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-26 17:58:27 +00:00
|
|
|
LSET LSET::ForbiddenFootprintLayers()
|
|
|
|
{
|
|
|
|
static const LSET saved = InternalCuMask().set( Edge_Cuts ).set( Margin );
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-24 02:29:05 +00:00
|
|
|
LSET LSET::ForbiddenTextLayers()
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2018-11-01 23:33:03 +00:00
|
|
|
static const LSET saved( 1, Edge_Cuts );
|
2018-08-21 19:01:07 +00:00
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2014-06-24 18:31:41 +00:00
|
|
|
LSEQ LSET::UIOrder() const
|
|
|
|
{
|
2018-01-12 03:32:14 +00:00
|
|
|
LSEQ order = CuStack();
|
|
|
|
LSEQ techuser = TechAndUserUIOrder();
|
|
|
|
order.insert( order.end(), techuser.begin(), techuser.end() );
|
2014-06-24 18:31:41 +00:00
|
|
|
|
2018-01-12 03:32:14 +00:00
|
|
|
return order;
|
2014-06-24 18:31:41 +00:00
|
|
|
}
|
2014-06-29 13:05:51 +00:00
|
|
|
|
2014-06-29 18:09:32 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID ToLAYER_ID( int aLayer )
|
2014-06-29 18:09:32 +00:00
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
wxASSERT( aLayer < GAL_LAYER_ID_END );
|
2017-03-13 03:19:33 +00:00
|
|
|
return PCB_LAYER_ID( aLayer );
|
2014-06-29 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
|
|
|
|
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 ) )
|
2020-08-23 15:59:40 +00:00
|
|
|
ret.push_back( static_cast<GAL_LAYER_ID>( i + GAL_LAYER_ID_START ) );
|
2020-07-11 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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_NON_PLATEDHOLES,
|
|
|
|
LAYER_MOD_TEXT_FR,
|
|
|
|
LAYER_MOD_TEXT_BK,
|
|
|
|
// LAYER_MOD_TEXT_INVISIBLE, // Invisible text hidden by default
|
|
|
|
LAYER_ANCHOR,
|
|
|
|
LAYER_PAD_FR,
|
|
|
|
LAYER_PAD_BK,
|
|
|
|
LAYER_RATSNEST,
|
|
|
|
LAYER_GRID,
|
|
|
|
LAYER_GRID_AXES,
|
|
|
|
LAYER_NO_CONNECTS,
|
|
|
|
LAYER_MOD_FR,
|
|
|
|
LAYER_MOD_BK,
|
|
|
|
LAYER_MOD_VALUES,
|
|
|
|
LAYER_MOD_REFERENCES,
|
|
|
|
LAYER_TRACKS,
|
|
|
|
LAYER_PADS_TH,
|
|
|
|
LAYER_PADS_PLATEDHOLES,
|
|
|
|
LAYER_VIAS_HOLES,
|
|
|
|
LAYER_DRC_ERROR,
|
|
|
|
LAYER_DRC_WARNING,
|
|
|
|
// LAYER_DRC_EXCLUSION, // DRC exclusions hidden by default
|
|
|
|
LAYER_WORKSHEET,
|
|
|
|
LAYER_GP_OVERLAY,
|
|
|
|
LAYER_SELECT_OVERLAY,
|
|
|
|
LAYER_PCB_BACKGROUND,
|
|
|
|
LAYER_CURSOR,
|
|
|
|
LAYER_AUX_ITEMS,
|
|
|
|
LAYER_DRAW_BITMAPS,
|
|
|
|
LAYER_PADS,
|
|
|
|
LAYER_ZONES,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GAL_SET saved( visible, arrayDim( visible ) );
|
|
|
|
return saved;
|
|
|
|
}
|