diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 5addcef628..a0e60c24f8 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -379,7 +379,7 @@ bool PANEL_SETUP_RULES::TransferDataFromWindow() { if( m_textEditor->SaveFile( rulesFilepath ) ) { - m_frame->GetBoard()->GetDesignSettings().m_DRCEngine->LoadRules( rulesFilepath ); + m_frame->GetBoard()->GetDesignSettings().m_DRCEngine->InitEngine( rulesFilepath ); return true; } } diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index 322042eaa3..6f952cd179 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -263,31 +263,25 @@ static wxString formatConstraint( const DRC_CONSTRAINT& constraint ) /** * @throws PARSE_ERROR */ -void DRC_ENGINE::LoadRules( const wxFileName& aPath ) +void DRC_ENGINE::loadRules( const wxFileName& aPath ) { if( aPath.FileExists() ) { - m_ruleConditions.clear(); - m_rules.clear(); + std::vector rules; FILE* fp = wxFopen( aPath.GetFullPath(), wxT( "rt" ) ); if( fp ) { - try - { - DRC_RULES_PARSER parser( fp, aPath.GetFullPath() ); - parser.Parse( m_rules, m_reporter ); - } - catch( PARSE_ERROR& pe ) - { - // Don't leave possibly malformed stuff around for us to trip over - m_ruleConditions.clear(); - m_rules.clear(); - - throw pe; - } + DRC_RULES_PARSER parser( fp, aPath.GetFullPath() ); + parser.Parse( rules, m_reporter ); } + + // Copy the rules into the member variable afterwards so that if Parse() throws then + // the possibly malformed rules won't contaminate the current ruleset. + + for( DRC_RULE* rule : rules ) + m_rules.push_back( rule ); } } @@ -381,8 +375,11 @@ void DRC_ENGINE::InitEngine( const wxFileName& aRulePath ) provider->SetDRCEngine( this ); } - LoadRules( aRulePath ); + m_ruleConditions.clear(); + m_rules.clear(); + loadImplicitRules(); + loadRules( aRulePath ); CompileRules(); diff --git a/pcbnew/drc/drc_engine.h b/pcbnew/drc/drc_engine.h index 721c6259fd..21be547edc 100644 --- a/pcbnew/drc/drc_engine.h +++ b/pcbnew/drc/drc_engine.h @@ -117,13 +117,6 @@ public: */ void SetLogReporter( REPORTER* aReporter ) { m_reporter = aReporter; } - /** - * Loads and parses a rule set from an sexpr text file. - * - * @throws PARSE_ERROR - */ - void LoadRules( const wxFileName& aPath ); - /** * Initializes the DRC engine. * @@ -177,6 +170,13 @@ private: m_rules.push_back(rule); } + /** + * Loads and parses a rule set from an sexpr text file. + * + * @throws PARSE_ERROR + */ + void loadRules( const wxFileName& aPath ); + void freeCompiledRules(); struct CONSTRAINT_WITH_CONDITIONS