diff --git a/include/core/minoptmax.h b/include/core/minoptmax.h index 5daf60d278..38ad8d601e 100644 --- a/include/core/minoptmax.h +++ b/include/core/minoptmax.h @@ -28,9 +28,9 @@ template class MINOPTMAX { public: - T Min() const { assert( m_hasMin ); return m_min; }; - T Max() const { assert( m_hasMax ); return m_max; }; - T Opt() const { assert( m_hasOpt ); return m_opt; }; + T Min() const { return m_hasMin ? m_min : 0; }; + T Max() const { return m_hasMax ? m_max : std::numeric_limits::max(); }; + T Opt() const { return m_hasOpt ? m_opt : Min(); }; bool HasMin() const { return m_hasMin; } bool HasMax() const { return m_hasMax; } @@ -42,17 +42,6 @@ public: bool IsNull() const { return m_isNull; } - T OptThenMin() const - { - if( m_hasOpt ) - return m_opt; - else if( m_hasMin ) - return m_min; - - assert( m_hasMin ); - return 0; - } - private: bool m_isNull; T m_min; diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index cf55ac0d47..d839133e5b 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -83,20 +83,32 @@ DRC_ENGINE::~DRC_ENGINE() } -static bool isKeepoutZone( const BOARD_ITEM* aItem ) +static bool isKeepoutZone( const BOARD_ITEM* aItem, bool aCheckFlags ) { - if( aItem && ( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T ) ) - { - const ZONE* zone = static_cast( aItem ); + if( !aItem ) + return false; - return zone->GetIsRuleArea() && ( zone->GetDoNotAllowTracks() - || zone->GetDoNotAllowVias() - || zone->GetDoNotAllowPads() - || zone->GetDoNotAllowCopperPour() - || zone->GetDoNotAllowFootprints() ); + if( aItem->Type() != PCB_ZONE_T && aItem->Type() != PCB_FP_ZONE_T ) + return false; + + const ZONE* zone = static_cast( aItem ); + + if( !zone->GetIsRuleArea() ) + return false; + + if( aCheckFlags ) + { + if( !zone->GetDoNotAllowTracks() + && !zone->GetDoNotAllowVias() + && !zone->GetDoNotAllowPads() + && !zone->GetDoNotAllowCopperPour() + && !zone->GetDoNotAllowFootprints() ) + { + return false; + } } - return false; + return true; } @@ -361,7 +373,7 @@ void DRC_ENGINE::loadImplicitRules() for( ZONE* zone : m_board->Zones() ) { - if( isKeepoutZone( zone ) ) + if( isKeepoutZone( zone, true ) ) keepoutZones.push_back( zone ); } @@ -369,7 +381,7 @@ void DRC_ENGINE::loadImplicitRules() { for( ZONE* zone : footprint->Zones() ) { - if( isKeepoutZone( zone ) ) + if( isKeepoutZone( zone, true ) ) keepoutZones.push_back( zone ); } } @@ -711,8 +723,8 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI const BOARD_CONNECTED_ITEM* bc = b && b->IsConnected() ? static_cast( b ) : nullptr; - bool a_is_unconnected = a && !ac; - bool b_is_unconnected = b && !bc; + bool a_is_non_copper = a && ( !a->IsOnCopperLayer() || isKeepoutZone( a, false ) ); + bool b_is_non_copper = b && ( !b->IsOnCopperLayer() || isKeepoutZone( b, false ) ); const DRC_CONSTRAINT* constraintRef = nullptr; bool implicit = false; @@ -723,7 +735,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI int overrideA = 0; int overrideB = 0; - if( ac && !b_is_unconnected && ac->GetLocalClearanceOverrides( nullptr ) > 0 ) + if( ac && !b_is_non_copper && ac->GetLocalClearanceOverrides( nullptr ) > 0 ) { overrideA = ac->GetLocalClearanceOverrides( &m_msg ); @@ -733,7 +745,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI MessageTextFromValue( UNITS, overrideA ) ) ) } - if( bc && !a_is_unconnected && bc->GetLocalClearanceOverrides( nullptr ) > 0 ) + if( bc && !a_is_non_copper && bc->GetLocalClearanceOverrides( nullptr ) > 0 ) { overrideB = bc->GetLocalClearanceOverrides( &m_msg ); @@ -800,7 +812,7 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI if( aConstraintId == CLEARANCE_CONSTRAINT ) { - if( implicit && ( a_is_unconnected || b_is_unconnected ) ) + if( implicit && ( a_is_non_copper || b_is_non_copper ) ) { REPORT( _( "Board and netclass clearances apply only to connected items." ) ); return true; diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 6161c75578..3d98481859 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -390,7 +390,7 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_WIDTH, aStartItem, nullptr, aStartItem->Layer(), &constraint ) ) { - trackWidth = constraint.m_Value.OptThenMin(); + trackWidth = constraint.m_Value.Opt(); found = true; // Note: allowed to override anything, including bds.m_TrackMinWidth } } @@ -410,13 +410,13 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_VIA_DIAMETER, aStartItem, nullptr, aStartItem->Layer(), &constraint ) ) { - viaDiameter = constraint.m_Value.OptThenMin(); + viaDiameter = constraint.m_Value.Opt(); } if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_VIA_HOLE, aStartItem, nullptr, aStartItem->Layer(), &constraint ) ) { - viaDrill = constraint.m_Value.OptThenMin(); + viaDrill = constraint.m_Value.Opt(); } } else @@ -437,14 +437,14 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_WIDTH, aStartItem, nullptr, aStartItem->Layer(), &constraint ) ) { - diffPairWidth = constraint.m_Value.OptThenMin(); + diffPairWidth = constraint.m_Value.Opt(); } if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_GAP, aStartItem, nullptr, aStartItem->Layer(), &constraint ) ) { - diffPairGap = constraint.m_Value.OptThenMin(); - diffPairViaGap = constraint.m_Value.OptThenMin(); + diffPairGap = constraint.m_Value.Opt(); + diffPairViaGap = constraint.m_Value.Opt(); } } else if( bds.UseCustomDiffPairDimensions() ) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 9d82f07253..6e4088e4c2 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -884,13 +884,13 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent ) nullptr, currentLayer ); if( !constraint.IsNull() ) - sizes.SetViaDiameter( constraint.m_Value.OptThenMin() ); + sizes.SetViaDiameter( constraint.m_Value.Opt() ); constraint = bds.m_DRCEngine->EvalRulesForItems( HOLE_SIZE_CONSTRAINT, &dummyVia, nullptr, currentLayer ); if( !constraint.IsNull() ) - sizes.SetViaDrill( constraint.m_Value.OptThenMin() ); + sizes.SetViaDrill( constraint.m_Value.Opt() ); } else {