diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 2c8a07c35b..21e0332e4f 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -29,9 +29,11 @@ #include #include #include +#include PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) : PANEL_SETUP_RULES_BASE( aParent->GetTreebook() ), + m_Parent( aParent ), m_frame( aFrame ), m_scintillaTricks( nullptr ) { @@ -174,15 +176,35 @@ bool PANEL_SETUP_RULES::TransferDataToWindow() if( rulesFile.FileExists() ) m_textEditor->LoadFile( rulesFile.GetFullPath() ); + m_originalText = m_textEditor->GetText(); + return true; } bool PANEL_SETUP_RULES::TransferDataFromWindow() { + if( m_originalText == m_textEditor->GetText() ) + return true; + + try + { + std::vector dummySelectors; + std::vector dummyRules; + + DRC_RULES_PARSER parser( m_frame->GetBoard(), m_textEditor->GetText(), _( "DRC rules" ) ); + + parser.Parse( dummySelectors, dummyRules ); + } + catch( PARSE_ERROR& pe ) + { + m_Parent->SetError( pe.What(), this, m_textEditor, pe.lineNumber, pe.byteIndex ); + return false; + } + if( m_textEditor->SaveFile( m_frame->Prj().AbsolutePath( "drc-rules" ) ) ) { - m_frame->GetToolManager()->GetTool()->Reset( TOOL_BASE::MODEL_RELOAD ); + m_frame->GetToolManager()->GetTool()->LoadRules(); return true; } diff --git a/pcbnew/dialogs/panel_setup_rules.h b/pcbnew/dialogs/panel_setup_rules.h index 69d00a7aa9..1ac5aa9009 100644 --- a/pcbnew/dialogs/panel_setup_rules.h +++ b/pcbnew/dialogs/panel_setup_rules.h @@ -36,8 +36,10 @@ class SCINTILLA_TRICKS; class PANEL_SETUP_RULES : public PANEL_SETUP_RULES_BASE { private: + PAGED_DIALOG* m_Parent; PCB_EDIT_FRAME* m_frame; SCINTILLA_TRICKS* m_scintillaTricks; + wxString m_originalText; public: PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); diff --git a/pcbnew/drc/drc_rule_parser.cpp b/pcbnew/drc/drc_rule_parser.cpp index 5a290297a4..64999125bc 100644 --- a/pcbnew/drc/drc_rule_parser.cpp +++ b/pcbnew/drc/drc_rule_parser.cpp @@ -31,11 +31,28 @@ using namespace DRCRULE_T; +DRC_RULES_PARSER::DRC_RULES_PARSER( BOARD* aBoard, const wxString& aSource, + const wxString& aSourceDescr ) : + DRC_RULES_LEXER( aSource, aSourceDescr ), + m_board( aBoard ), + m_requiredVersion( 0 ), + m_tooRecent( false ) +{ + initLayerMap(); +} + + DRC_RULES_PARSER::DRC_RULES_PARSER( BOARD* aBoard, FILE* aFile, const wxString& aFilename ) : DRC_RULES_LEXER( aFile, aFilename ), m_board( aBoard ), m_requiredVersion( 0 ), m_tooRecent( false ) +{ + initLayerMap(); +} + + +void DRC_RULES_PARSER::initLayerMap() { for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer ) { diff --git a/pcbnew/drc/drc_rule_parser.h b/pcbnew/drc/drc_rule_parser.h index 3a154e68a5..a8d4c80025 100644 --- a/pcbnew/drc/drc_rule_parser.h +++ b/pcbnew/drc/drc_rule_parser.h @@ -40,11 +40,14 @@ class BOARD_ITEM; class DRC_RULES_PARSER : public DRC_RULES_LEXER { public: + DRC_RULES_PARSER( BOARD* aBoard, const wxString& aSource, const wxString& aSourceDescr ); DRC_RULES_PARSER( BOARD* aBoard, FILE* aFile, const wxString& aFilename ); void Parse( std::vector& aSelectors, std::vector& aRules ); private: + void initLayerMap(); + DRC_SELECTOR* parseDRC_SELECTOR( wxString* aRuleName ); DRC_RULE* parseDRC_RULE();