Code completion hookup to property manager.
This commit is contained in:
parent
c52df811ae
commit
fd647a1fa9
|
@ -170,8 +170,10 @@ private:
|
||||||
size_t nextId = 0;
|
size_t nextId = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = DEFAULT )
|
PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = DEFAULT ) :
|
||||||
: m_id( nextId ), m_name( aName ), m_display( aDisplay ),
|
m_id( nextId ),
|
||||||
|
m_name( aName ),
|
||||||
|
m_display( aDisplay ),
|
||||||
m_availFunc( [](INSPECTABLE*)->bool { return true; } )
|
m_availFunc( [](INSPECTABLE*)->bool { return true; } )
|
||||||
{
|
{
|
||||||
++nextId;
|
++nextId;
|
||||||
|
|
|
@ -70,11 +70,13 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
||||||
STRING,
|
STRING,
|
||||||
SEXPR_OPEN,
|
SEXPR_OPEN,
|
||||||
SEXPR_TOKEN,
|
SEXPR_TOKEN,
|
||||||
|
STRUCT_REF
|
||||||
};
|
};
|
||||||
|
|
||||||
std::stack<wxString> sexprs;
|
std::stack<wxString> sexprs;
|
||||||
wxString partial;
|
wxString partial;
|
||||||
int context = NONE;
|
int context = NONE;
|
||||||
|
int expr_context = NONE;
|
||||||
|
|
||||||
for( ; i < currentPos; ++i )
|
for( ; i < currentPos; ++i )
|
||||||
{
|
{
|
||||||
|
@ -83,20 +85,39 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
||||||
if( c == '\\' )
|
if( c == '\\' )
|
||||||
{
|
{
|
||||||
i++; // skip escaped char
|
i++; // skip escaped char
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else if( context == STRING )
|
||||||
if( context == STRING )
|
|
||||||
{
|
{
|
||||||
if( c == '"' )
|
if( c == '"' )
|
||||||
|
{
|
||||||
context = NONE;
|
context = NONE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
partial += c;
|
{
|
||||||
|
if( expr_context == STRING )
|
||||||
continue;
|
{
|
||||||
|
if( c == '\'' )
|
||||||
|
expr_context = NONE;
|
||||||
|
else
|
||||||
|
partial += c;
|
||||||
|
}
|
||||||
|
else if( c == '\'' )
|
||||||
|
{
|
||||||
|
partial = wxEmptyString;
|
||||||
|
expr_context = STRING;
|
||||||
|
}
|
||||||
|
else if( c == '.' )
|
||||||
|
{
|
||||||
|
partial = wxEmptyString;
|
||||||
|
expr_context = STRUCT_REF;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partial += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if( c == '"' )
|
||||||
if( c == '"' )
|
|
||||||
{
|
{
|
||||||
partial = wxEmptyString;
|
partial = wxEmptyString;
|
||||||
context = STRING;
|
context = STRING;
|
||||||
|
@ -153,20 +174,42 @@ void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
||||||
tokens = "condition constraint disallow";
|
tokens = "condition constraint disallow";
|
||||||
else if( sexprs.top() == "constraint" )
|
else if( sexprs.top() == "constraint" )
|
||||||
tokens = "max min opt";
|
tokens = "max min opt";
|
||||||
|
|
||||||
if( !tokens.IsEmpty() )
|
|
||||||
m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, ' ' ) );
|
|
||||||
}
|
}
|
||||||
else if( context == SEXPR_TOKEN )
|
else if( context == SEXPR_TOKEN )
|
||||||
{
|
{
|
||||||
if( sexprs.top() == "constraint" )
|
if( sexprs.empty() )
|
||||||
|
/* badly formed grammar */;
|
||||||
|
else if( sexprs.top() == "constraint" )
|
||||||
tokens = "annulus_width clearance hole track_width";
|
tokens = "annulus_width clearance hole track_width";
|
||||||
else if( sexprs.top() == "disallow" )
|
else if( sexprs.top() == "disallow" )
|
||||||
tokens = "buried_via graphic hole micro_via pad text track via zone";
|
tokens = "buried_via graphic hole micro_via pad text track via zone";
|
||||||
|
|
||||||
if( !tokens.IsEmpty() )
|
|
||||||
m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, ' ' ) );
|
|
||||||
}
|
}
|
||||||
|
else if( context == STRING && expr_context == STRUCT_REF )
|
||||||
|
{
|
||||||
|
if( !sexprs.empty() && sexprs.top() == "condition" )
|
||||||
|
{
|
||||||
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
||||||
|
std::set<wxString> propNames;
|
||||||
|
|
||||||
|
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
||||||
|
{
|
||||||
|
const PROPERTY_LIST& props = propMgr.GetProperties( cls.type );
|
||||||
|
|
||||||
|
for( PROPERTY_BASE* prop : props )
|
||||||
|
{
|
||||||
|
wxString ref( prop->Name() );
|
||||||
|
ref.Replace( " ", "_" );
|
||||||
|
propNames.insert( ref );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( const wxString& propName : propNames )
|
||||||
|
tokens += " " + propName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !tokens.IsEmpty() )
|
||||||
|
m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, ' ' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -156,16 +156,17 @@ LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::createFuncCall( LIBEVAL::COMPILER* aCom
|
||||||
|
|
||||||
|
|
||||||
LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler,
|
LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler,
|
||||||
const std::string& var, const std::string& field )
|
const std::string& aVar,
|
||||||
|
const std::string& aField )
|
||||||
{
|
{
|
||||||
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
||||||
PCB_EXPR_VAR_REF* vref = nullptr;
|
PCB_EXPR_VAR_REF* vref = nullptr;
|
||||||
|
|
||||||
if( var == "A" )
|
if( aVar == "A" )
|
||||||
{
|
{
|
||||||
vref = new PCB_EXPR_VAR_REF( 0 );
|
vref = new PCB_EXPR_VAR_REF( 0 );
|
||||||
}
|
}
|
||||||
else if( var == "B" )
|
else if( aVar == "B" )
|
||||||
{
|
{
|
||||||
vref = new PCB_EXPR_VAR_REF( 1 );
|
vref = new PCB_EXPR_VAR_REF( 1 );
|
||||||
}
|
}
|
||||||
|
@ -175,9 +176,12 @@ LIBEVAL::VAR_REF* PCB_EXPR_UCODE::createVarRef( LIBEVAL::COMPILER *aCompiler,
|
||||||
return vref;
|
return vref;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( field.empty() ) // return reference to base object
|
if( aField.empty() ) // return reference to base object
|
||||||
return vref;
|
return vref;
|
||||||
|
|
||||||
|
std::string field( aField );
|
||||||
|
std::replace( field.begin(), field.end(), '_', ' ');
|
||||||
|
|
||||||
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
||||||
{
|
{
|
||||||
if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
|
if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
|
||||||
|
|
|
@ -41,7 +41,7 @@ class PCB_EXPR_UCODE : public LIBEVAL::UCODE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler,
|
virtual LIBEVAL::VAR_REF* createVarRef( LIBEVAL::COMPILER *aCompiler,
|
||||||
const std::string& var, const std::string& field ) override;
|
const std::string& aVar, const std::string& aField ) override;
|
||||||
|
|
||||||
virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler, const std::string& name ) override;
|
virtual FUNC_PTR createFuncCall( LIBEVAL::COMPILER* aCompiler, const std::string& name ) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue