From 5e4fb46aef515bf467e8a66437c8132009199076 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Thu, 8 Oct 2020 23:57:08 +0200 Subject: [PATCH] MINOPTMAX: added OptThenMin() method as syntax sugar --- include/core/minoptmax.h | 11 +++ pcbnew/router/pns_kicad_iface.cpp | 79 +++++++++++-------- pcbnew/router/pns_node.h | 25 +++++- pcbnew/router/pns_router.cpp | 4 +- pcbnew/router/pns_topology.h | 3 - .../test_cases/basic_hole_clearance/drc-rules | 10 --- 6 files changed, 81 insertions(+), 51 deletions(-) delete mode 100644 qa/drc_proto/test_cases/basic_hole_clearance/drc-rules diff --git a/include/core/minoptmax.h b/include/core/minoptmax.h index 5f45f70083..5daf60d278 100644 --- a/include/core/minoptmax.h +++ b/include/core/minoptmax.h @@ -42,6 +42,17 @@ 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/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 4b429fc170..a685338d91 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -44,6 +44,9 @@ #include #include +#include +#include + #include #include @@ -73,12 +76,14 @@ public: virtual bool CollideHoles( const PNS::ITEM* aA, const PNS::ITEM* aB, bool aNeedMTV, VECTOR2I* aMTV ) const override; - virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const override; - virtual int Clearance( int aNetCode ) const override; + virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override; + //virtual int Clearance( int aNetCode ) const override; virtual int DpCoupledNet( int aNet ) override; virtual int DpNetPolarity( int aNet ) override; virtual bool DpNetPair( PNS::ITEM* aItem, int& aNetP, int& aNetN ) override; + virtual bool QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB, int aLayer, PNS::CONSTRAINT* aConstraint ) override; + virtual wxString NetName( int aNet ) override; private: @@ -240,47 +245,53 @@ int PNS_PCBNEW_RULE_RESOLVER::localPadClearance( const PNS::ITEM* aItem ) const return i->second; } - -int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const +bool PNS_PCBNEW_RULE_RESOLVER::QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB, int aLayer, PNS::CONSTRAINT* aConstraint ) { - int net_a = aA->Net(); - int cl_a = Clearance( net_a ); - int net_b = aB->Net(); - int cl_b = Clearance( net_b ); + std::shared_ptr drcEngine = m_board->GetDesignSettings().m_DRCEngine; - // Pad clearance is 0 if the ITEM* is not a pad - int pad_a = localPadClearance( aA ); - int pad_b = localPadClearance( aB ); + if( !drcEngine ) + { + return false; + } - if( pad_a > 0 ) - cl_a = pad_a; + DRC_CONSTRAINT_TYPE_T hostRuleType; - if( pad_b > 0 ) - cl_b = pad_b; + switch ( aType ) + { + case PNS::CONSTRAINT_TYPE::CT_CLEARANCE: + hostRuleType = DRC_CONSTRAINT_TYPE_CLEARANCE; + break; + case PNS::CONSTRAINT_TYPE::CT_WIDTH: + hostRuleType = DRC_CONSTRAINT_TYPE_TRACK_WIDTH; + break; + case PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_GAP: + hostRuleType = DRC_CONSTRAINT_TYPE_DIFF_PAIR_GAP; + break; + case PNS::CONSTRAINT_TYPE::CT_LENGTH: + hostRuleType = DRC_CONSTRAINT_TYPE_LENGTH; + break; + default: + return false; // should not happen + } - return std::max( cl_a, cl_b ); + DRC_CONSTRAINT hostConstraint = drcEngine->EvalRulesForItems( hostRuleType, + aItemA->Parent(), + aItemB->Parent(), + (PCB_LAYER_ID) aLayer ); + + if( hostConstraint.IsNull() ) + return false; } -int PNS_PCBNEW_RULE_RESOLVER::Clearance( int aNetCode ) const +int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) { - if( aNetCode == -1 ) - { - return 0; - } - else if( aNetCode == 0 ) - { - return m_defaultClearance; - } - else if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() ) - { - return m_netClearanceCache[aNetCode].clearance; - } - else - { - wxFAIL_MSG( "PNS_PCBNEW_RULE_RESOLVER::Clearance: net not found in clearance cache." ); - return m_defaultClearance; - } + PNS::CONSTRAINT constraint; + bool ok = QueryConstraint( PNS::CONSTRAINT_TYPE::CT_CLEARANCE, aA, aB, aA->Layer(), &constraint ); + + assert( ok ); + + return constraint.m_Value.Min(); } diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index adccb165eb..10200f2937 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -54,6 +55,24 @@ class NODE; * An abstract function object, returning a design rule (clearance, diff pair gap, etc) required between two items. **/ +enum class CONSTRAINT_TYPE +{ + CT_CLEARANCE = 1, + CT_DIFF_PAIR_GAP = 2, + CT_LENGTH = 3, + CT_WIDTH = 4 +}; + +struct CONSTRAINT +{ + CONSTRAINT_TYPE m_Type; + MINOPTMAX m_Value; + bool m_Allowed; + wxString m_RuleName; + wxString m_FromName; + wxString m_ToName; +}; + class RULE_RESOLVER { public: @@ -62,12 +81,14 @@ public: virtual bool CollideHoles( const ITEM* aA, const ITEM* aB, bool aNeedMTV, VECTOR2I* aMTV ) const = 0; - virtual int Clearance( const ITEM* aA, const ITEM* aB ) const = 0; - virtual int Clearance( int aNetCode ) const = 0; + virtual int Clearance( const ITEM* aA, const ITEM* aB ) = 0; + //virtual int Clearance( int aNetCode ) const = 0; virtual int DpCoupledNet( int aNet ) = 0; virtual int DpNetPolarity( int aNet ) = 0; virtual bool DpNetPair( ITEM* aItem, int& aNetP, int& aNetN ) = 0; + virtual bool QueryConstraint( CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB, int aLayer, PNS::CONSTRAINT* aConstraint ) = 0; + virtual wxString NetName( int aNet ) = 0; }; diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 62f9c737b9..e1146ea1f8 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -330,7 +330,7 @@ void ROUTER::updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging ) for( auto item : added ) { - int clearance = GetRuleResolver()->Clearance( item->Net() ); + int clearance = 0; //GetRuleResolver()->Clearance( item->Net() ); m_iface->DisplayItem( item, -1, clearance, aDragging ); } @@ -364,7 +364,7 @@ void ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem ) continue; const LINE* l = static_cast( item ); - int clearance = GetRuleResolver()->Clearance( item->Net() ); + int clearance = 0; //GetRuleResolver()->Clearance( item->Net() ); m_iface->DisplayItem( l, -1, clearance ); diff --git a/pcbnew/router/pns_topology.h b/pcbnew/router/pns_topology.h index d0bfe9302b..c1847b92b2 100644 --- a/pcbnew/router/pns_topology.h +++ b/pcbnew/router/pns_topology.h @@ -58,9 +58,6 @@ public: const ITEM_SET AssembleTrivialPath( ITEM* aStart ); const DIFF_PAIR AssembleDiffPair( SEGMENT* aStart ); - int DpCoupledNet( int aNet ); - int DpNetPolarity( int aNet ); - const LINE DpCoupledLine( LINE* aLine ); bool AssembleDiffPair( ITEM* aStart, DIFF_PAIR& aPair ); const std::set AssembleCluster( ITEM* aStart, int aLayer ); diff --git a/qa/drc_proto/test_cases/basic_hole_clearance/drc-rules b/qa/drc_proto/test_cases/basic_hole_clearance/drc-rules deleted file mode 100644 index 883e7b655a..0000000000 --- a/qa/drc_proto/test_cases/basic_hole_clearance/drc-rules +++ /dev/null @@ -1,10 +0,0 @@ -(version 20200610) - -(condition (expression "A.type == 'Pad' && A.netname == 'Net3'") (rule "small_pad_hole_clearance") ) -(condition (expression "A.type == 'Pad' && A.netname == 'Net2'") (rule "big_pad_hole_clearance") ) - -(rule "small_pad_hole_clearance" (type "hole_clearance") (priority 1) (severity error) (min "0.1mm") ) -(rule "big_pad_hole_clearance" (type "hole_clearance") (priority 1) (severity error) (min "5mm" ) ) -(rule "default" (type "hole_clearance") (priority 0) (severity error) (min "0.5mm") ) - -