diff --git a/common/lset.cpp b/common/lset.cpp new file mode 100644 index 0000000000..b7776c6902 --- /dev/null +++ b/common/lset.cpp @@ -0,0 +1,634 @@ + + +#include +#include + + + +LSET::LSET( const LAYER_ID* aArray, unsigned aCount ) +{ + for( unsigned i=0; i +#include + +LSET::LSET( size_t aIdCount, ... ) +{ + va_list ap; + + va_start( ap, aIdCount ); + + for( size_t i=0; i 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; + else + break; + + int bit = nibble_ndx * 4; + + for( int ndx=0; 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; +} + + +LSEQ LSET::Seq( const LAYER_ID* aWishListSequence, unsigned aCount ) const +{ + LSEQ ret; + +#if defined(DEBUG) + LSET dup_detector; + + for( unsigned i=0; i 1 ) + return UNDEFINED_LAYER; + + for( unsigned i=0; i < size(); ++i ) + { + if( test( i ) ) + return LAYER_ID( i ); + } + + wxASSERT( 0 ); // set_count was verified as 1 above, what did you break? + + return UNDEFINED_LAYER; +} + + +LSET LSET::InternalCuMask() +{ + static const LAYER_ID cu_internals[] = { + 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, + }; + + static const LSET saved( cu_internals, DIM( cu_internals ) ); + 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; +} + + +LSET LSET::AllLayersMask() +{ + static const LSET saved = LSET().set(); + return saved; +} + + +LSET LSET::BackTechMask() +{ + // (SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK | ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK) + static const LSET saved( 6, B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab ); + return saved; +} + + +LSET LSET::FrontTechMask() +{ + // (SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT | ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT) + static const LSET saved( 6, F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab ); + return saved; +} + + +LSET LSET::AllTechMask() +{ + static const LSET saved = BackTechMask() | FrontTechMask(); + return saved; +} + + +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; +} + + +#if 0 +// layers order in dialogs (plot, print and toolbars) +// in same order than in setup layers dialog +// (Front or Top to Back or Bottom) +#define DECLARE_LAYERS_ORDER_LIST(list) const LAYER_ID list[] = {\ + F_Cu,\ + LAYER_N_15, LAYER_N_14, LAYER_N_13, LAYER_N_12,\ + LAYER_N_11, LAYER_N_10, LAYER_N_9, LAYER_N_8,\ + LAYER_N_7, LAYER_N_6, LAYER_N_5, LAYER_N_4,\ + LAYER_N_3, LAYER_N_2,\ + B_Cu,\ + 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,\ + UNUSED_LAYER_29, UNUSED_LAYER_30, UNUSED_LAYER_31\ +}; +#endif + + +LSEQ LSET::UIOrder() const +{ + LAYER_ID order[Margin+1]; + + // Assmuming that the LAYER_ID order is according to preferred UI order, as of + // today this is true. When that becomes not true, its easy to change the order + // in here to compensate. + + for( unsigned i=0; i