diff --git a/common/lset.cpp b/common/lset.cpp index 0c3ebd6b0d..98c1a45919 100644 --- a/common/lset.cpp +++ b/common/lset.cpp @@ -544,23 +544,23 @@ PCB_LAYER_ID LSET::ExtractLayer() const } -LSET LSET::FrontAssembly() +const LSET& LSET::FrontAssembly() { - static const LSET saved( { F_SilkS, F_Mask, F_Fab, F_CrtYd } ); + static LSET saved( { F_SilkS, F_Mask, F_Fab, F_CrtYd } ); return saved; } -LSET LSET::BackAssembly() +const LSET& LSET::BackAssembly() { - static const LSET saved( { B_SilkS, B_Mask, B_Fab, B_CrtYd } ); + static LSET saved( { B_SilkS, B_Mask, B_Fab, B_CrtYd } ); return saved; } -LSET LSET::InternalCuMask() +const LSET& LSET::InternalCuMask() { - static const LSET saved( { In1_Cu, In2_Cu, In3_Cu, In4_Cu, In5_Cu, In6_Cu, + 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, @@ -591,73 +591,72 @@ LSET LSET::AllNonCuMask() } -LSET LSET::ExternalCuMask() +const LSET& LSET::ExternalCuMask() { - static const LSET saved( { F_Cu, B_Cu } ); + static LSET saved( { F_Cu, B_Cu } ); return saved; } -LSET LSET::AllLayersMask() +const LSET& LSET::AllLayersMask() { - static const LSET saved = LSET().set(); + static LSET saved = LSET().set(); return saved; } -LSET LSET::BackTechMask() +const LSET& LSET::BackTechMask() { - static const LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab } ); + static LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste, B_CrtYd, B_Fab } ); return saved; } -LSET LSET::BackBoardTechMask() +const LSET& LSET::BackBoardTechMask() { - static const LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste } ); + static LSET saved( { B_SilkS, B_Mask, B_Adhes, B_Paste } ); return saved; } -LSET LSET::FrontTechMask() +const LSET& LSET::FrontTechMask() { - static const LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab } ); + static LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste, F_CrtYd, F_Fab } ); return saved; } -LSET LSET::FrontBoardTechMask() +const LSET& LSET::FrontBoardTechMask() { - static const LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste } ); + static LSET saved( { F_SilkS, F_Mask, F_Adhes, F_Paste } ); return saved; } -LSET LSET::AllTechMask() +const LSET& LSET::AllTechMask() { - static const LSET saved = BackTechMask() | FrontTechMask(); + static LSET saved = BackTechMask() | FrontTechMask(); return saved; } -LSET LSET::AllBoardTechMask() +const LSET& LSET::AllBoardTechMask() { - static const LSET saved = BackBoardTechMask() | FrontBoardTechMask(); + static LSET saved = BackBoardTechMask() | FrontBoardTechMask(); return saved; } -LSET LSET::UserMask() +const LSET& LSET::UserMask() { - static const LSET saved( { Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts, Margin } ); - + static LSET saved( { Dwgs_User, Cmts_User, Eco1_User, Eco2_User, Edge_Cuts, Margin } ); return saved; } -LSET LSET::PhysicalLayersMask() +const LSET& LSET::PhysicalLayersMask() { - static const LSET saved = AllBoardTechMask() | AllCuMask(); + static LSET saved = AllBoardTechMask() | AllCuMask(); return saved; } @@ -680,31 +679,30 @@ LSET LSET::UserDefinedLayersMask( int aUserDefinedLayerCount ) } -LSET LSET::FrontMask() +const LSET& LSET::FrontMask() { - static const LSET saved = FrontTechMask().set( F_Cu ); + static LSET saved = LSET( FrontTechMask() ).set( F_Cu ); return saved; } -LSET LSET::BackMask() +const LSET& LSET::BackMask() { - static const LSET saved = BackTechMask().set( B_Cu ); + static LSET saved = LSET( BackTechMask() ).set( B_Cu ); return saved; } -LSET LSET::SideSpecificMask() +const LSET& LSET::SideSpecificMask() { - static const LSET saved = BackTechMask() | FrontTechMask() | AllCuMask(); + static LSET saved = BackTechMask() | FrontTechMask() | AllCuMask(); return saved; } -LSET LSET::ForbiddenFootprintLayers() +const LSET& LSET::ForbiddenFootprintLayers() { - static LSET saved = InternalCuMask(); - saved.set( In1_Cu, false ); + static LSET saved = LSET( InternalCuMask() ).set( In1_Cu, false ); return saved; } diff --git a/include/board_design_settings.h b/include/board_design_settings.h index fdd515d0a7..e290f3b16f 100644 --- a/include/board_design_settings.h +++ b/include/board_design_settings.h @@ -571,7 +571,7 @@ public: * * @return the enabled layers in bit-mapped form. */ - inline LSET GetEnabledLayers() const + inline const LSET& GetEnabledLayers() const { return m_enabledLayers; } diff --git a/include/lset.h b/include/lset.h index af2fc8284e..4ab472b80c 100644 --- a/include/lset.h +++ b/include/lset.h @@ -102,17 +102,17 @@ public: * Return a complete set of internal copper layers which is all Cu layers * except #F_Cu and #B_Cu. */ - static LSET InternalCuMask(); + static const LSET& InternalCuMask(); /** * Return a complete set of all top assembly layers which is all #F_SilkS and #F_Mask. */ - static LSET FrontAssembly(); + static const LSET& FrontAssembly(); /** * Return a complete set of all bottom assembly layers which is all #B_SilkS and #B_Mask. */ - static LSET BackAssembly(); + static const LSET& BackAssembly(); /** * Return a mask holding the requested number of Cu PCB_LAYER_IDs. @@ -122,67 +122,67 @@ public: /** * Return a mask holding the Front and Bottom layers. */ - static LSET ExternalCuMask(); + static const LSET& ExternalCuMask(); /** * Return a mask holding all layer minus CU layers. */ static LSET AllNonCuMask(); - static LSET AllLayersMask(); + static const LSET& AllLayersMask(); /** * Return a mask holding all technical layers (no CU layer) on front side. */ - static LSET FrontTechMask(); + static const LSET& FrontTechMask(); /** * Return a mask holding technical layers used in a board fabrication * (no CU layer) on front side. */ - static LSET FrontBoardTechMask(); + static const LSET& FrontBoardTechMask(); /** * Return a mask holding all technical layers (no CU layer) on back side. */ - static LSET BackTechMask(); + static const LSET& BackTechMask(); /** * Return a mask holding technical layers used in a board fabrication * (no CU layer) on Back side. */ - static LSET BackBoardTechMask(); + static const LSET& BackBoardTechMask(); /** * Return a mask holding all technical layers (no CU layer) on both side. */ - static LSET AllTechMask(); + static const LSET& AllTechMask(); /** * Return a mask holding board technical layers (no CU layer) on both side. */ - static LSET AllBoardTechMask(); + static const LSET& AllBoardTechMask(); /** * Return a mask holding all technical layers and the external CU layer on front side. */ - static LSET FrontMask(); + static const LSET& FrontMask(); /** * Return a mask holding all technical layers and the external CU layer on back side. */ - static LSET BackMask(); + static const LSET& BackMask(); - static LSET SideSpecificMask(); + static const LSET& SideSpecificMask(); - static LSET UserMask(); + static const LSET& UserMask(); /** * Return a mask holding all layers which are physically realized. * * Equivalent to the copper layers + the board tech mask. */ - static LSET PhysicalLayersMask(); + static const LSET& PhysicalLayersMask(); /** * Return a mask with the requested number of user defined layers. @@ -197,7 +197,7 @@ public: * Currently internal copper layers and Margin. */ - static LSET ForbiddenFootprintLayers(); + static const LSET& ForbiddenFootprintLayers(); /** * Return a sequence of copper layers in starting from the front/top diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 25f6efdfbb..30e40f1e02 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -828,7 +828,7 @@ int BOARD::LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const } -LSET BOARD::GetEnabledLayers() const +const LSET& BOARD::GetEnabledLayers() const { return GetDesignSettings().GetEnabledLayers(); } @@ -842,7 +842,7 @@ bool BOARD::IsLayerVisible( PCB_LAYER_ID aLayer ) const } -LSET BOARD::GetVisibleLayers() const +const LSET& BOARD::GetVisibleLayers() const { return m_project ? m_project->GetLocalSettings().m_VisibleLayers : LSET::AllLayersMask(); } diff --git a/pcbnew/board.h b/pcbnew/board.h index 472cd37092..f3e7cca22b 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -607,7 +607,7 @@ public: * * @return the enabled layers in bit-mapped form. */ - LSET GetEnabledLayers() const; + const LSET& GetEnabledLayers() const; LSET GetLayerSet() const override { return GetEnabledLayers(); } /** @@ -640,7 +640,7 @@ public: * * @return the visible layers in bit-mapped form. */ - LSET GetVisibleLayers() const; + const LSET& GetVisibleLayers() const; /** * A proxy function that calls the correspondent function in m_BoardSettings diff --git a/pcbnew/drc/drc_test_provider_misc.cpp b/pcbnew/drc/drc_test_provider_misc.cpp index 803bd802a9..eb705498bd 100644 --- a/pcbnew/drc/drc_test_provider_misc.cpp +++ b/pcbnew/drc/drc_test_provider_misc.cpp @@ -168,7 +168,7 @@ void DRC_TEST_PROVIDER_MISC::testDisabledLayers() return true; }; - LSET disabledLayers = m_board->GetEnabledLayers().flip(); + LSET disabledLayers = LSET( m_board->GetEnabledLayers() ).flip(); // Perform the test only for copper layers disabledLayers &= LSET::AllCuMask(); diff --git a/pcbnew/drc/drc_test_provider_physical_clearance.cpp b/pcbnew/drc/drc_test_provider_physical_clearance.cpp index 8fc2a16dca..f6417fc7f9 100644 --- a/pcbnew/drc/drc_test_provider_physical_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_physical_clearance.cpp @@ -148,10 +148,10 @@ bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run() if( item->HasHole() ) { if( layers.Contains( F_Cu ) ) - layers |= LSET::FrontBoardTechMask().set( F_CrtYd ); + layers |= LSET( LSET::FrontBoardTechMask() ).set( F_CrtYd ); if( layers.Contains( B_Cu ) ) - layers |= LSET::BackBoardTechMask().set( B_CrtYd ); + layers |= LSET( LSET::BackBoardTechMask() ).set( B_CrtYd ); if( layers.Contains( F_Cu ) && layers.Contains( B_Cu ) ) layers |= LSET::AllCuMask(); @@ -671,10 +671,10 @@ int DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem( BOARD_ITEM* aItem LSET layers = aItem->GetLayerSet(); if( layers.Contains( F_Cu ) ) - layers |= LSET::FrontBoardTechMask().set( F_CrtYd ); + layers |= LSET( LSET::FrontBoardTechMask() ).set( F_CrtYd ); if( layers.Contains( B_Cu ) ) - layers |= LSET::BackBoardTechMask().set( B_CrtYd ); + layers |= LSET( LSET::BackBoardTechMask() ).set( B_CrtYd ); if( layers.Contains( F_Cu ) && layers.Contains( B_Cu ) ) layers |= LSET::AllCuMask(); @@ -694,10 +694,10 @@ int DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem( BOARD_ITEM* aItem LSET layers = aOther->GetLayerSet(); if( layers.Contains( F_Cu ) ) - layers |= LSET::FrontBoardTechMask().set( F_CrtYd ); + layers |= LSET( LSET::FrontBoardTechMask() ).set( F_CrtYd ); if( layers.Contains( B_Cu ) ) - layers |= LSET::BackBoardTechMask().set( B_CrtYd ); + layers |= LSET( LSET::BackBoardTechMask() ).set( B_CrtYd ); if( layers.Contains( F_Cu ) && layers.Contains( B_Cu ) ) layers |= LSET::AllCuMask(); diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index ae813fde26..de077b148b 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -342,7 +342,7 @@ PCB_LAYER_ID PAD::GetPrincipalLayer() const bool PAD::FlashLayer( LSET aLayers ) const { - for( PCB_LAYER_ID layer : aLayers.Seq() ) + for( PCB_LAYER_ID layer : aLayers ) { if( FlashLayer( layer ) ) return true; @@ -1760,7 +1760,7 @@ double PAD::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const return LOD_HIDE; // Handle Render tab switches - const PCB_LAYER_ID& pcbLayer = static_cast( aLayer ); + //const PCB_LAYER_ID& pcbLayer = static_cast( aLayer ); if( !IsFlipped() && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) ) return LOD_HIDE; @@ -1768,11 +1768,13 @@ double PAD::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const if( IsFlipped() && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) ) return LOD_HIDE; - LSET visible = board->GetVisibleLayers() & board->GetEnabledLayers(); - if( IsHoleLayer( aLayer ) ) { - if( !( visible & LSET::PhysicalLayersMask() ).any() ) + LSET visiblePhysical = board->GetVisibleLayers(); + visiblePhysical &= board->GetEnabledLayers(); + visiblePhysical &= LSET::PhysicalLayersMask(); + + if( !visiblePhysical.any() ) return LOD_HIDE; } else if( IsNetnameLayer( aLayer ) ) @@ -1785,6 +1787,9 @@ double PAD::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const } else { + LSET visible = board->GetVisibleLayers(); + visible &= board->GetEnabledLayers(); + // Hide netnames unless pad is flashed to a visible layer if( !FlashLayer( visible ) ) return LOD_HIDE; @@ -1807,8 +1812,10 @@ double PAD::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const } } - VECTOR2L padSize = GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM - ? VECTOR2L( GetSize( pcbLayer ) ) : GetBoundingBox().GetSize(); + /*VECTOR2L padSize = GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM + ? VECTOR2L( GetSize( pcbLayer ) ) : GetBoundingBox().GetSize();*/ + + VECTOR2L padSize = GetBoundingBox().GetSize(); int64_t minSide = std::min( padSize.x, padSize.y ); diff --git a/pcbnew/padstack.cpp b/pcbnew/padstack.cpp index e66abdf4ea..0d2935e309 100644 --- a/pcbnew/padstack.cpp +++ b/pcbnew/padstack.cpp @@ -1036,11 +1036,13 @@ const PADSTACK::COPPER_LAYER_PROPS& PADSTACK::CopperLayer( PCB_LAYER_ID aLayer ) { PCB_LAYER_ID layer = EffectiveLayerFor( aLayer ); - wxCHECK_MSG( m_copperProps.contains( layer ), m_copperProps.at( ALL_LAYERS ), + auto it = m_copperProps.find( layer ); + + wxCHECK_MSG( it != m_copperProps.end(), m_copperProps.at( ALL_LAYERS ), "Attempt to retrieve layer " + std::string( magic_enum::enum_name( layer ) ) + " from a " "padstack that does not contain it" ); - return m_copperProps.at( layer ); + return it->second; } diff --git a/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp b/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp index b30843bbe1..74ba2faf7b 100644 --- a/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp +++ b/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp @@ -2495,7 +2495,7 @@ void PCB_IO_EAGLE::packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aC pad->SetDrillSize( sz ); pad->SetSize( PADSTACK::ALL_LAYERS, sz ); - pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) ); + pad->SetLayerSet( LSET( LSET::AllCuMask() ).set( B_Mask ).set( F_Mask ) ); } diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp index 0b7f0e2825..004e691b36 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp @@ -1159,7 +1159,7 @@ BOARD* PCB_IO_KICAD_SEXPR_PARSER::parseBOARD_unchecked() } // Make sure the destination layer is enabled, even if not in the file - m_board->SetEnabledLayers( m_board->GetEnabledLayers().set( destLayer ) ); + m_board->SetEnabledLayers( LSET( m_board->GetEnabledLayers() ).set( destLayer ) ); const auto visitItem = [&]( BOARD_ITEM& curr_item ) { diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index 9db7b992bd..2e22166ba3 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -1228,15 +1228,10 @@ void PCB_VIA::SanitizeLayers() bool PCB_VIA::FlashLayer( LSET aLayers ) const { - for( size_t ii = 0; ii < aLayers.size(); ++ii ) + for( PCB_LAYER_ID layer : aLayers ) { - if( aLayers.test( ii ) ) - { - PCB_LAYER_ID layer = PCB_LAYER_ID( ii ); - - if( FlashLayer( layer ) ) - return true; - } + if( FlashLayer( layer ) ) + return true; } return false; diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index f1e5491d5d..56eca47fa0 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -374,22 +374,22 @@ LAYER_PRESET APPEARANCE_CONTROLS::presetAllLayers( _HKI( "All Layers" ), LSET::AllLayersMask(), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetAllCopper( _HKI( "All Copper Layers" ), - LSET::AllCuMask().set( Edge_Cuts ), false ); + LSET( LSET::AllCuMask() ).set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetInnerCopper( _HKI( "Inner Copper Layers" ), - LSET::InternalCuMask().set( Edge_Cuts ), false ); + LSET( LSET::InternalCuMask() ).set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetFront( _HKI( "Front Layers" ), - LSET::FrontMask().set( Edge_Cuts ), false ); + LSET( LSET::FrontMask() ).set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetFrontAssembly( _HKI( "Front Assembly View" ), - LSET::FrontAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), F_SilkS, false ); + LSET( LSET::FrontAssembly() ).set( Edge_Cuts ), GAL_SET::DefaultVisible(), F_SilkS, false ); LAYER_PRESET APPEARANCE_CONTROLS::presetBack( _HKI( "Back Layers" ), - LSET::BackMask().set( Edge_Cuts ), true ); + LSET( LSET::BackMask() ).set( Edge_Cuts ), true ); LAYER_PRESET APPEARANCE_CONTROLS::presetBackAssembly( _HKI( "Back Assembly View" ), - LSET::BackAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), B_SilkS, true ); + LSET( LSET::BackAssembly() ).set( Edge_Cuts ), GAL_SET::DefaultVisible(), B_SilkS, true ); // this one is only used to store the object visibility settings of the last used // built-in layer preset