From 5a1b1c544afa27fc6a200684654d4be15862fe63 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 29 Jul 2020 12:26:27 +0100 Subject: [PATCH] Add layer to rule grammar. --- common/drc_rules.keywords | 3 ++ pcbnew/dialogs/panel_setup_rules.cpp | 9 +++-- pcbnew/drc/drc_rule.h | 2 + pcbnew/drc/drc_rule_parser.cpp | 55 +++++++++++++++++++--------- pcbnew/drc/drc_rule_parser.h | 5 +-- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/common/drc_rules.keywords b/common/drc_rules.keywords index 9ff5b10de3..6fcea5f956 100644 --- a/common/drc_rules.keywords +++ b/common/drc_rules.keywords @@ -8,6 +8,8 @@ disallow footprint graphic hole +inner +layer match_area match_layer match_netclass @@ -17,6 +19,7 @@ micro_via min npth opt +outer pad pth rule diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index ad64e57b6f..7e7d266255 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -150,8 +150,9 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) m_textEditor->AutoCompCancel(); sexprs.push( partial ); - if( sexprs.size() - && ( sexprs.top() == "constraint" || sexprs.top() == "disallow" ) ) + if( sexprs.size() && ( sexprs.top() == "constraint" + || sexprs.top() == "disallow" + || sexprs.top() == "layer" ) ) { partial = wxEmptyString; context = SEXPR_TOKEN; @@ -174,7 +175,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) if( sexprs.empty() ) tokens = "rule version"; else if( sexprs.top() == "rule" ) - tokens = "condition constraint disallow"; + tokens = "condition constraint disallow layer"; else if( sexprs.top() == "constraint" ) tokens = "max min opt"; } @@ -186,6 +187,8 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) tokens = "annulus_width clearance hole track_width"; else if( sexprs.top() == "disallow" ) tokens = "buried_via graphic hole micro_via pad text track via zone"; + else if( sexprs.top() == "layer" ) + tokens = "inner outer \"x\""; } else if( context == STRING && expr_context == STRUCT_REF ) { diff --git a/pcbnew/drc/drc_rule.h b/pcbnew/drc/drc_rule.h index 05ebac687b..862cace343 100644 --- a/pcbnew/drc/drc_rule.h +++ b/pcbnew/drc/drc_rule.h @@ -89,6 +89,7 @@ public: LIBEVAL::ERROR_STATUS GetCompilationError(); public: + LSET m_LayerCondition; wxString m_Expression; wxString m_TargetRuleName; @@ -129,6 +130,7 @@ public: MINOPTMAX m_TrackConstraint; int m_MinHole; + LSET m_LayerCondition; DRC_RULE_CONDITION m_Condition; }; diff --git a/pcbnew/drc/drc_rule_parser.cpp b/pcbnew/drc/drc_rule_parser.cpp index d00a331caa..b15d535784 100644 --- a/pcbnew/drc/drc_rule_parser.cpp +++ b/pcbnew/drc/drc_rule_parser.cpp @@ -39,7 +39,6 @@ DRC_RULES_PARSER::DRC_RULES_PARSER( BOARD* aBoard, const wxString& aSource, m_requiredVersion( 0 ), m_tooRecent( false ) { - initLayerMap(); } @@ -49,20 +48,6 @@ DRC_RULES_PARSER::DRC_RULES_PARSER( BOARD* aBoard, FILE* aFile, const wxString& m_requiredVersion( 0 ), m_tooRecent( false ) { - initLayerMap(); -} - - -void DRC_RULES_PARSER::initLayerMap() -{ - for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer ) - { - std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) ); - m_layerMap[ untranslated ] = PCB_LAYER_ID( layer ); - - std::string userName = m_board->GetLayerName( PCB_LAYER_ID( layer ) ).ToStdString(); - m_layerMap[ userName ] = PCB_LAYER_ID( layer ); - } } @@ -95,7 +80,7 @@ void DRC_RULES_PARSER::Parse( std::vector& aRules ) break; default: - Expecting( "selector or rule" ); + Expecting( "rule" ); } } } @@ -159,6 +144,10 @@ DRC_RULE* DRC_RULES_PARSER::parseDRC_RULE() NeedRIGHT(); break; + case T_layer: + rule->m_LayerCondition = parseLayer(); + break; + default: Expecting( "disallow, constraint or condition" ); } @@ -258,4 +247,36 @@ void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult } aResult = evaluator.Result(); -}; +} + + +LSET DRC_RULES_PARSER::parseLayer() +{ + LSET retVal; + int tok = NextTok(); + + if( tok == T_outer ) + { + retVal = LSET::ExternalCuMask(); + } + else if( tok == T_inner ) + { + retVal = LSET::InternalCuMask(); + } + else + { + wxString layerName = FromUTF8(); + PCB_LAYER_ID layer = ENUM_MAP::Instance().ToEnum( layerName ); + + if( layer == UNDEFINED_LAYER ) + { + wxString msg = wxString::Format( _( "Unrecognized layer '%s' " ), layerName ); + THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); + } + + retVal.set( layer ); + } + + NeedRIGHT(); + return retVal; +} diff --git a/pcbnew/drc/drc_rule_parser.h b/pcbnew/drc/drc_rule_parser.h index 87f0f82ab3..404188bac4 100644 --- a/pcbnew/drc/drc_rule_parser.h +++ b/pcbnew/drc/drc_rule_parser.h @@ -46,19 +46,16 @@ public: void Parse( std::vector& aRules ); private: - void initLayerMap(); - DRC_RULE* parseDRC_RULE(); void parseConstraint( DRC_RULE* aRule ); void parseValueWithUnits( const wxString& aExpr, int& aResult ); + LSET parseLayer(); private: BOARD* m_board; int m_requiredVersion; bool m_tooRecent; - - std::unordered_map m_layerMap; }; #endif // DRC_RULE_PARSER_H