From f582783b27e54d8623b1072f5ba3ed8e59a7c84b Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Thu, 13 Aug 2020 00:19:34 +0200 Subject: [PATCH] qa/drc_proto: updated DRC rule file format to the last version, post-rebase fixes too --- qa/drc_proto/drc_engine.cpp | 69 +++++++++++-------- qa/drc_proto/drc_engine.h | 25 ++++--- qa/drc_proto/drc_rule.cpp | 3 +- qa/drc_proto/drc_rule.h | 3 +- qa/drc_proto/drc_rule_parser.cpp | 2 + .../drc_test_provider_edge_clearance.cpp | 4 +- .../test_cases/basic_clearance/drc-rules | 11 ++- 7 files changed, 68 insertions(+), 49 deletions(-) diff --git a/qa/drc_proto/drc_engine.cpp b/qa/drc_proto/drc_engine.cpp index a20ffda867..0d3bfa236c 100644 --- a/qa/drc_proto/drc_engine.cpp +++ b/qa/drc_proto/drc_engine.cpp @@ -37,6 +37,17 @@ #include +void drcPrintDebugMessage( int level, wxString msg, const char *function, int line ) +{ + wxString valueStr; + if( wxGetEnv( "DRC_DEBUG", &valueStr ) ) + { + int setLevel = wxAtoi( valueStr ); + if( level <= setLevel ) + fprintf(stderr,"[%-30s:%-5d] %s", function, line, (const char *) msg.c_str() ); + } +} + test::DRC_ENGINE::DRC_ENGINE( BOARD* aBoard, BOARD_DESIGN_SETTINGS *aSettings ) : m_board( aBoard ), m_designSettings ( aSettings ), @@ -125,29 +136,32 @@ bool test::DRC_ENGINE::CompileRules() for( auto provider : m_testProviders ) { ReportAux( wxString::Format( "- Provider: '%s': ", provider->GetName() ) ); + drc_dbg(11, "do prov %s", provider->GetName() ); for ( auto id : provider->GetMatchingConstraintIds() ) { - if( m_ruleMap.find(id) == m_ruleMap.end() ) - m_ruleMap[id] = new RULE_SET; + drc_dbg(11, "do id %d", id); + if( m_constraintMap.find(id) == m_constraintMap.end() ) + m_constraintMap[id] = new CONSTRAINT_SET; - m_ruleMap[ id ]->provider = provider; + m_constraintMap[ id ]->provider = provider; for( auto rule : m_rules ) { - drc_dbg(10, "Scan provider %s rule %s", provider->GetName() ); + drc_dbg(11, "Scan provider %s, rule %s", provider->GetName(), rule->GetName() ); if( ! rule->IsEnabled() ) continue; for( auto& constraint : rule->Constraints() ) { + drc_dbg(11, "scan constraint id %d\n", constraint.GetType() ); if( constraint.GetType() != id ) continue; - ReportAux( wxString::Format( " |- Rule: '%s' ", rule->m_Name ) ); + ReportAux( wxString::Format( " |- Rule: '%s' ", rule->GetName() ) ); - auto rcons = new RULE_WITH_CONDITIONS; + auto rcons = new CONSTRAINT_WITH_CONDITIONS; if( rule->IsConditional() ) { @@ -159,8 +173,9 @@ bool test::DRC_ENGINE::CompileRules() ReportAux( wxString::Format( " |- condition: '%s' compile: %s", condition->GetExpression(), compileOk ? "OK" : "ERROR") ); } - rcons->rule = rule; - m_ruleMap[ id ]->sortedRules.push_back( rcons ); + rcons->constraint = constraint; + rcons->parentRule = rule; + m_constraintMap[ id ]->sortedConstraints.push_back( rcons ); } } @@ -215,10 +230,17 @@ void test::DRC_ENGINE::RunTests( ) const test::DRC_CONSTRAINT& test::DRC_ENGINE::EvalRulesForItems( test::DRC_CONSTRAINT_TYPE_T aConstraintId, BOARD_ITEM* a, BOARD_ITEM* b, PCB_LAYER_ID aLayer ) { test::DRC_RULE* rv; - auto ruleset = m_ruleMap[ aConstraintId ]; + auto ruleset = m_constraintMap[ aConstraintId ]; - for( auto rcond : ruleset->sortedRules ) + for( auto rcond : ruleset->sortedConstraints ) { + if( rcond->conditions.size() == 0 ) // uconditional + { + drc_dbg( 8, " -> rule '%s' matches (unconditional)\n", + rcond->constraint.GetParentRule()->GetName() + ); + return rcond->constraint; + } for( auto condition : rcond->conditions ) { drc_dbg( 8, " -> check condition '%s'\n", @@ -228,13 +250,10 @@ const test::DRC_CONSTRAINT& test::DRC_ENGINE::EvalRulesForItems( test::DRC_CONST if( result ) { drc_dbg( 8, " -> rule '%s' matches, triggered by condition '%s'\n", - rcond->rule->GetName(), + rcond->constraint.GetParentRule()->GetName(), condition->GetExpression() ); - for( const DRC_CONSTRAINT& c : rcond->rule->Constraints() ) - { - if( c.GetType() == aConstraintId ) - return c; - } + + return rcond->constraint; } } } @@ -313,24 +332,16 @@ test::DRC_CONSTRAINT test::DRC_ENGINE::GetWorstGlobalConstraint( test::DRC_CONST std::vector test::DRC_ENGINE::QueryConstraintsById( test::DRC_CONSTRAINT_TYPE_T constraintID ) { std::vector rv; - - for( auto rule : m_ruleMap[constraintID]->sortedRules ) - { - assert( rule ); - assert( rule->rule ); - - for( const DRC_CONSTRAINT& c : rule->constraints ) - if( c.GetType() == constraintID ) - rv.push_back( c ); - } - + for ( auto c : m_constraintMap[constraintID]->sortedConstraints ) + rv.push_back(c->constraint); return rv; } -bool test::DRC_ENGINE::HasCorrectRulesForId( test::DRC_CONSTRAINT_TYPE_T ruleID ) +bool test::DRC_ENGINE::HasCorrectRulesForId( test::DRC_CONSTRAINT_TYPE_T constraintID ) { - return m_ruleMap[ruleID]->sortedRules.size() != 0; + //drc_dbg(10,"hascorrect id %d size %d\n", ruleID, m_ruleMap[ruleID]->sortedRules.size( ) ); + return m_constraintMap[constraintID]->sortedConstraints.size() != 0; } diff --git a/qa/drc_proto/drc_engine.h b/qa/drc_proto/drc_engine.h index 21b304e569..873ed5bafa 100644 --- a/qa/drc_proto/drc_engine.h +++ b/qa/drc_proto/drc_engine.h @@ -53,12 +53,11 @@ class NETLIST; class PROGRESS_REPORTER; class REPORTER; -//#ifdef DEBUG + +void drcPrintDebugMessage( int level, wxString msg, const char *function, int line ); + #define drc_dbg(level, fmt, ...) \ - wxLogTrace( "drc_proto", fmt, __VA_ARGS__ ); -//#else -//#define drc_dbg(level, fmt, ...) -//#endif + drcPrintDebugMessage(level, wxString::Format( fmt, __VA_ARGS__ ), __FUNCTION__, __LINE__ ); namespace test { @@ -213,20 +212,20 @@ private: void freeCompiledRules(); - struct RULE_WITH_CONDITIONS + struct CONSTRAINT_WITH_CONDITIONS { std::vector conditions; - test::DRC_RULE* rule; - std::vector constraints; + test::DRC_RULE* parentRule; + test::DRC_CONSTRAINT constraint; }; - struct RULE_SET + struct CONSTRAINT_SET { - std::vector sortedRules; + std::vector sortedConstraints; DRC_TEST_PROVIDER* provider; }; - typedef std::unordered_map RULE_MAP; + typedef std::unordered_map CONSTRAINT_MAP; void inferImplicitRules(); @@ -240,8 +239,8 @@ private: std::vector m_ruleConditions; std::vector m_rules; std::vector m_testProviders; - std::unordered_map m_implicitRules; - RULE_MAP m_ruleMap; + std::unordered_map m_implicitRules; + CONSTRAINT_MAP m_constraintMap; REPORTER* m_reporter; PROGRESS_REPORTER* m_progressReporter; diff --git a/qa/drc_proto/drc_rule.cpp b/qa/drc_proto/drc_rule.cpp index 1d485e70b4..81a7bb9940 100644 --- a/qa/drc_proto/drc_rule.cpp +++ b/qa/drc_proto/drc_rule.cpp @@ -44,8 +44,9 @@ test::DRC_RULE::~DRC_RULE() { } -void test::DRC_RULE::AddConstraint( const DRC_CONSTRAINT& aConstraint ) +void test::DRC_RULE::AddConstraint( DRC_CONSTRAINT& aConstraint ) { + aConstraint.SetParentRule( this ); m_constraints.push_back( aConstraint ); } diff --git a/qa/drc_proto/drc_rule.h b/qa/drc_proto/drc_rule.h index 10e2fd5c2f..a6a3d070b8 100644 --- a/qa/drc_proto/drc_rule.h +++ b/qa/drc_proto/drc_rule.h @@ -122,6 +122,7 @@ class DRC_CONSTRAINT // fixme: needed? bool Allowed() const { return m_Allow; } + void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; } DRC_RULE* GetParentRule() const { return m_parentRule; } DRC_CONSTRAINT_TYPE_T GetType() const { return m_Type; } @@ -160,7 +161,7 @@ public: return m_constraints; } - void AddConstraint( const DRC_CONSTRAINT& aConstraint ); + void AddConstraint( DRC_CONSTRAINT& aConstraint ); bool IsConditional() const { diff --git a/qa/drc_proto/drc_rule_parser.cpp b/qa/drc_proto/drc_rule_parser.cpp index 4b2f42191f..334f2d5b4e 100644 --- a/qa/drc_proto/drc_rule_parser.cpp +++ b/qa/drc_proto/drc_rule_parser.cpp @@ -401,6 +401,8 @@ void test::DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule ) parseUnknown(); } } + + aRule->AddConstraint( constraint ); } diff --git a/qa/drc_proto/drc_test_provider_edge_clearance.cpp b/qa/drc_proto/drc_test_provider_edge_clearance.cpp index af617f5b78..c65f863dc5 100644 --- a/qa/drc_proto/drc_test_provider_edge_clearance.cpp +++ b/qa/drc_proto/drc_test_provider_edge_clearance.cpp @@ -126,12 +126,12 @@ bool test::DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run() for( auto outlineItem : boardOutline ) { - //printf("RefT %d\n", outlineItem->Type() ); + drc_dbg(12, "RefT %d %p\n", outlineItem->Type(), outlineItem ); auto refShape = outlineItem->GetEffectiveShape(); for( auto boardItem : boardItems ) { -// printf("BoardT %d\n", boardItem->Type() ); + drc_dbg(12, "BoardT %d %p\n", boardItem->Type(), boardItem ); auto shape = boardItem->GetEffectiveShape(); diff --git a/qa/drc_proto/test_cases/basic_clearance/drc-rules b/qa/drc_proto/test_cases/basic_clearance/drc-rules index 1b26dbbd2d..bbacaab192 100644 --- a/qa/drc_proto/test_cases/basic_clearance/drc-rules +++ b/qa/drc_proto/test_cases/basic_clearance/drc-rules @@ -1,6 +1,11 @@ (version 20200610) -(condition (expression "A.type == 'Pad' && B.type == 'Pad' && (A.onlayer('B.Cu'))") (rule "pad2pad_clearance_back") ) -(rule "pad2pad_clearance_back" (type "clearance") (priority 1) (severity error) (min "1mm") ) -(rule "default" (type "clearance") (priority 0) (severity error) (min "0.2mm") ) +(rule "pad2pad_clearance_back" + (condition "A.type == 'Pad' && B.type == 'Pad' && (A.onlayer('B.Cu'))" ) + (constraint clearance (min "1mm") ) +) + +(rule "default" + (constraint clearance (min "0.2mm") ) +)