From ac73c99842771956eb33630b1535aa9bff52ca07 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 1 Sep 2020 18:35:22 +0100 Subject: [PATCH] Code completion for netclasses and netnames. Fixes https://gitlab.com/kicad/code/kicad/issues/5441 --- pcbnew/dialogs/panel_setup_rules.cpp | 28 ++++++++++++++++++++++++++-- pcbnew/dialogs/panel_setup_rules.h | 4 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 1d81791b11..aa218107b8 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -49,6 +49,9 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFr for( size_t i = 0; i < wxSTC_STYLE_MAX; ++i ) m_textEditor->StyleSetFont( i, fixedFont ); + m_netClassRegex.Compile( "NetClass\\s*[!=]=\\s*$", wxRE_ADVANCED ); + m_netNameRegex.Compile( "NetName\\s*[!=]=\\s*$", wxRE_ADVANCED ); + m_compileButton->SetBitmap( KiBitmap( drc_xpm ) ); m_textEditor->Bind( wxEVT_STC_CHARADDED, &PANEL_SETUP_RULES::onScintillaCharAdded, this ); @@ -94,6 +97,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) std::stack sexprs; wxString partial; + wxString last; int context = NONE; int expr_context = NONE; @@ -122,6 +126,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) } else if( c == '\'' ) { + last = partial; partial = wxEmptyString; expr_context = STRING; } @@ -138,6 +143,7 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) } else if( c == '"' ) { + last = partial; partial = wxEmptyString; context = STRING; } @@ -223,9 +229,9 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) tokens = "inner outer \"x\""; } } - else if( context == STRING && expr_context == STRUCT_REF ) + else if( context == STRING && !sexprs.empty() && sexprs.top() == "condition" ) { - if( !sexprs.empty() && sexprs.top() == "condition" ) + if( expr_context == STRUCT_REF ) { PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); std::set propNames; @@ -250,6 +256,24 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) for( const wxString& funcSig : functions.GetSignatures() ) tokens += " " + funcSig; } + else if( expr_context == STRING ) + { + if( m_netClassRegex.Matches( last ) ) + { + BOARD* board = m_frame->GetBoard(); + BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings(); + + for( const std::pair& entry : bds.GetNetClasses() ) + tokens += " " + entry.first; + } + else if( m_netNameRegex.Matches( last ) ) + { + BOARD* board = m_frame->GetBoard(); + + for( const wxString& netnameCandidate : board->GetNetClassAssignmentCandidates() ) + tokens += " " + netnameCandidate; + } + } } if( !tokens.IsEmpty() ) diff --git a/pcbnew/dialogs/panel_setup_rules.h b/pcbnew/dialogs/panel_setup_rules.h index b26026aeaa..5b984f3916 100644 --- a/pcbnew/dialogs/panel_setup_rules.h +++ b/pcbnew/dialogs/panel_setup_rules.h @@ -25,6 +25,7 @@ #ifndef PANEL_SETUP_RULES_H #define PANEL_SETUP_RULES_H +#include #include class DRC; @@ -41,6 +42,9 @@ private: SCINTILLA_TRICKS* m_scintillaTricks; wxString m_originalText; + wxRegEx m_netClassRegex; + wxRegEx m_netNameRegex; + public: PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_RULES( ) override;