Commit f79888f9 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

ScriptParser modified to give the possibility to exhibit in the interface some...

ScriptParser modified to give the possibility to exhibit in the interface some parameters of plug-ins used by a script.
parent ac6709f8
......@@ -112,9 +112,12 @@ bool AlgorithmSelector::populateTools( const QString &scriptFileName )
ScriptParser *script = new ScriptParser();
script->SetAvailableTools( this );
if( !script->ParseFile(scriptFileName) || script->GetCategory().isEmpty() || script->GetName().isEmpty() )
UIParamSet *toolParam = new UIParamSet( "Tool options", this );
if( !script->ParseFile(scriptFileName, toolParam) || script->GetCategory().isEmpty() || script->GetName().isEmpty() )
{
delete script;
delete toolParam;
return false;
}
......@@ -131,6 +134,7 @@ bool AlgorithmSelector::populateTools( const QString &scriptFileName )
if( !categoryDeclared )
{
delete script;
delete toolParam;
return false;
}
......@@ -138,10 +142,8 @@ bool AlgorithmSelector::populateTools( const QString &scriptFileName )
tool->script = script;
tool->scriptSourceFile = scriptFileName;
tool->scriptSourceModificationTime = QFileInfo(scriptFileName).lastModified();
tool->param = new UIParamSet( "Tool options", this );
//plugin->declareParameters( i, *tool.param );
tool->param = toolParam;
tool->param->SetHidden();
//tool.param->setMaximumWidth(360);
//connect( tool.param, SIGNAL(parameterUpdated(UIParam*)), tool.plugin, SLOT(updateParameter(UIParam*)) );
......@@ -504,7 +506,6 @@ void AlgorithmSelector::deleteProgressBars()
}
#include <iostream>
void AlgorithmSelector::recompileCurrentScript()
{
if( !m_SelectedTool || !m_SelectedTool->script )
......@@ -515,14 +516,24 @@ void AlgorithmSelector::recompileCurrentScript()
if( modificationTime <= m_SelectedTool->scriptSourceModificationTime )
return;
UIParamSet *toolParam = new UIParamSet( "Tool options", this );
ScriptParser *parser = new ScriptParser();
m_SelectedTool->isScriptBroken = !parser->ParseFile(m_SelectedTool->scriptSourceFile);
m_SelectedTool->isScriptBroken = !parser->ParseFile(m_SelectedTool->scriptSourceFile, toolParam);
if( m_SelectedTool->isScriptBroken )
{
delete parser;
delete toolParam;
}
else
{
m_ui->widgetToolGroupBoxes->layout()->removeWidget( m_SelectedTool->param );
delete m_SelectedTool->param;
m_SelectedTool->param = m_SelectedToolParam = toolParam;
m_ui->widgetToolGroupBoxes->layout()->addWidget( m_SelectedTool->param );
m_SelectedTool->param->SetVisible();
delete m_SelectedTool->script;
m_SelectedTool->script = parser;
m_SelectedTool->scriptSourceModificationTime = modificationTime;
......
......@@ -146,7 +146,7 @@ bool ScriptParser::ParseLoopBegin(VariableMap &declaredVariables, const QString
QString loopVar = parserLoopBeg.cap(2);
DeclareVariable(declaredVariables, loopVar, subParser);
if( !subParser->ParseSubScript(declaredVariables, script.mid(m_CurrentPos)) )
if( !subParser->ParseSubScript(declaredVariables, script.mid(m_CurrentPos), m_ShownParameters) )
{
delete subParser;
return false;
......@@ -344,7 +344,7 @@ bool ScriptParser::ParsePlugIn(VariableMap &declaredVariables, const QString &sc
error = false;
QRegExp parserPlugin( "(Tool|Import|Export|Script)\\.("+TOKEN+")("+INSIDE_BRACKETS+")?"+INSIDE_PARENTHESES );
QRegExp parserParams( STRING+"="+STRING+"(\\."+TOKEN+")?" );
QRegExp parserParams( STRING+"="+STRING+"(\\.Show\\(("+STRING+")?\\))?" );
if( parserPlugin.indexIn(script, m_CurrentPos) != m_CurrentPos )
return false;
......@@ -370,9 +370,9 @@ bool ScriptParser::ParsePlugIn(VariableMap &declaredVariables, const QString &sc
param.name = parserParams.cap(1);
param.value = parserParams.cap(2);
if( !parserParams.cap(3).isEmpty() && parserParams.cap(3) != ".Show" )
return false;
param.show = !parserParams.cap(3).isEmpty();
param.isShown = !parserParams.cap(3).isEmpty();
if( param.isShown )
param.shownName = parserParams.cap(5);
UIParam *p = m_ToolSelector->getToolByName(m_ToolsByScriptName[inst.plugin.name])->param->GetByName(param.name);
if( !p )
......@@ -418,6 +418,27 @@ bool ScriptParser::AddInstruction(VariableMap &declaredVariables, InstructionInf
inst->assignment = instInfo.assignment;
inst->plugin = instInfo.plugin;
inst->data = instInfo.data;
if( m_ShownParameters )
{
AlgorithmSelector::ToolDescriptor *tool = (AlgorithmSelector::ToolDescriptor*) m_ToolSelector->getToolByName(m_ToolsByScriptName[inst->plugin.name]);
UIParamSet toolParams("tmp", m_ToolSelector);
tool->plugin->declareParameters(tool->id, toolParams);
for( auto &p : inst->plugin.params )
if( p.isShown )
{
p.shownParam = toolParams.GetByName(p.name);
toolParams.Remove(p.shownParam);
p.shownParam->SetId(QString::number(m_ShownParameters->Count()));
p.shownParam->SetName(p.shownName.isEmpty()? p.name : p.shownName);
p.shownParam->SetValueString(p.value);
m_ShownParameters->Add(p.shownParam);
}
}
m_Instructions.push_back(inst);
}
else if( !instInfo.directive.name.isEmpty() )
......@@ -509,7 +530,7 @@ void ScriptParser::SetAvailableTools( AlgorithmSelector *toolSelector )
}
bool ScriptParser::ParseFile( const QString &filename )
bool ScriptParser::ParseFile( const QString &filename, UIParamSet *params )
{
QFile file(filename);
if( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
......@@ -518,11 +539,11 @@ bool ScriptParser::ParseFile( const QString &filename )
qint64 fileSize = file.size();
QString mappedFile = QString::fromStdString( std::string((char*) file.map(0, fileSize), (size_t)fileSize) );
return ParseScript( mappedFile );
return ParseScript( mappedFile, params );
}
bool ScriptParser::ParseSubScript( VariableMap &declaredVariables, const QString &inputScript )
bool ScriptParser::ParseSubScript( VariableMap &declaredVariables, const QString &inputScript, UIParamSet *params )
{
QString script = GetTrimmedScript( inputScript );
......@@ -530,6 +551,8 @@ bool ScriptParser::ParseSubScript( VariableMap &declaredVariables, const QString
delete inst;
m_Instructions.clear();
m_ShownParameters = params;
m_CurrentPos = 0;
int prevPos;
......@@ -580,12 +603,13 @@ bool ScriptParser::ParseSubScript( VariableMap &declaredVariables, const QString
}
bool ScriptParser::ParseScript( const QString &inputScript )
bool ScriptParser::ParseScript( const QString &inputScript, UIParamSet *params )
{
VariableMap declaredVariables;
declaredVariables["Project"] = Variable();
declaredVariables["Input"] = Variable();
return ParseSubScript( declaredVariables, inputScript );
return ParseSubScript( declaredVariables, inputScript, params );
}
......@@ -668,7 +692,7 @@ void ScriptParser::BindTool( InstructionPlugin *inst )
for( auto &p : inst->plugin.params )
{
p.backupValue = inst->toolDesc->param->ValueStringByName(p.name);
inst->toolDesc->param->SetValueStringByName(p.name,p.value);
inst->toolDesc->param->SetValueStringByName(p.name, p.shownParam? p.shownParam->ValueString() : p.value);
}
}
......
......@@ -46,7 +46,9 @@ class ScriptParser
QString name;
QString value;
QString backupValue;
bool show;
bool isShown = false;
QString shownName;
UIParam *shownParam = NULL;
};
struct PlugIn
......@@ -128,65 +130,67 @@ class ScriptParser
using VariableMap = QMap<QString,Variable>;
QString m_Name;
QString m_Description;
QString m_Category;
QString m_Name;
QString m_Description;
QString m_Category;
int m_CurrentPos;
QList<Instruction*> m_Instructions;
static QMap<QString,QString> m_ToolsByScriptName;
static AlgorithmSelector *m_ToolSelector;
int m_CurrentPos;
QList<Instruction*> m_Instructions;
static QMap<QString,QString> m_ToolsByScriptName;
static AlgorithmSelector *m_ToolSelector;
QString GetTrimmedScript( const QString &inputScript ) const;
UIParamSet *m_ShownParameters = NULL;
QString GetTrimmedScript( const QString &inputScript ) const;
bool ParseDirective(VariableMap &declaredVariables, const QString &script, InstructionInfo &inst, bool &error);
bool ParseDirective(VariableMap &declaredVariables, const QString &script, InstructionInfo &inst, bool &error);
bool ParseLoopBegin(VariableMap &declaredVariables, const QString &script, bool &error );
bool ParseLoopEnd( const QString &script );
bool ParseLoopBegin(VariableMap &declaredVariables, const QString &script, bool &error );
bool ParseLoopEnd( const QString &script );
QString ParseAssignment( const QString &script );
QString ParseAssignment( const QString &script );
DataFilter* ParseData(VariableMap &declaredVariables, const QString &script );
DataFilter* ParseDataFilterTree(const QString &script);
void DisplayDataFilterTree(DataFilter *data, QString offset = "");
bool DataFilterTreeSemanticCheck(VariableMap &declaredVariables, DataFilter *data, int depth = 0 );
DataFilter* ParseData(VariableMap &declaredVariables, const QString &script );
DataFilter* ParseDataFilterTree(const QString &script);
void DisplayDataFilterTree(DataFilter *data, QString offset = "");
bool DataFilterTreeSemanticCheck(VariableMap &declaredVariables, DataFilter *data, int depth = 0 );
bool ParsePlugIn(VariableMap &declaredVariables, const QString &script, InstructionInfo &inst, bool &error );
bool ParsePlugIn(VariableMap &declaredVariables, const QString &script, InstructionInfo &inst, bool &error );
bool AddInstruction(VariableMap &declaredVariables, InstructionInfo &instInfo);
bool AddInstruction( ScriptParser *subScript, const QString &loopVar, DataFilter *data );
bool AddInstruction(VariableMap &declaredVariables, InstructionInfo &instInfo);
bool AddInstruction( ScriptParser *subScript, const QString &loopVar, DataFilter *data );
QSet<GenericUIData*> GatherItemsFromTree( DataFilter *data, VariableMap &declaredVariables, const QSet<GenericUIData*> &items = QSet<GenericUIData*>() );
QList<GenericUIData*> GatherItems( VariableMap &declaredVariables, Instruction *inst, UIProject *project );
void BindTool( InstructionPlugin *inst );
void UnbindTool( InstructionPlugin *inst );
QSet<GenericUIData*> GatherItemsFromTree( DataFilter *data, VariableMap &declaredVariables, const QSet<GenericUIData*> &items = QSet<GenericUIData*>() );
QList<GenericUIData*> GatherItems( VariableMap &declaredVariables, Instruction *inst, UIProject *project );
void BindTool( InstructionPlugin *inst );
void UnbindTool( InstructionPlugin *inst );
bool ParseSubScript( VariableMap &declaredVariables, const QString &inputScript );
bool RunSubScript( VariableMap &declaredVariables, UIContext &context );
bool ParseSubScript( VariableMap &declaredVariables, const QString &inputScript, UIParamSet *params );
bool RunSubScript( VariableMap &declaredVariables, UIContext &context );
void SetVariable(VariableMap &declaredVariables, const QString &name, QList<GenericUIData*> &content, ScriptParser *scope);
void SetStringVariable(VariableMap &declaredVariables, const QString &name, QStringList &content, ScriptParser *scope);
void DeclareVariable(VariableMap &declaredVariables, const QString &name, ScriptParser *scope);
void DeleteVariablesInScope(VariableMap &declaredVariables, ScriptParser *scope);
void SetVariable(VariableMap &declaredVariables, const QString &name, QList<GenericUIData*> &content, ScriptParser *scope);
void SetStringVariable(VariableMap &declaredVariables, const QString &name, QStringList &content, ScriptParser *scope);
void DeclareVariable(VariableMap &declaredVariables, const QString &name, ScriptParser *scope);
void DeleteVariablesInScope(VariableMap &declaredVariables, ScriptParser *scope);
static bool NameMatches( const QString& name, const QString& filter );
static bool NameMatches( const QString& name, const QString& filter );
public:
~ScriptParser();
inline const QString& GetName() const { return m_Name; }
inline const QString& GetDescription() const { return m_Description; }
inline const QString& GetCategory() const { return m_Category; }
inline const QString& GetName() const { return m_Name; }
inline const QString& GetDescription() const { return m_Description; }
inline const QString& GetCategory() const { return m_Category; }
static QString GetToolScriptName( const QString &toolName );
static QString GetToolScriptString( const AlgorithmSelector::ToolDescriptor &desc );
static QString GetToolScriptName( const QString &toolName );
static QString GetToolScriptString( const AlgorithmSelector::ToolDescriptor &desc );
void SetAvailableTools( AlgorithmSelector *algoSelector );
void SetAvailableTools( AlgorithmSelector *algoSelector );
bool ParseFile( const QString &filename );
bool ParseScript( const QString &inputScript );
bool ParseFile( const QString &filename, UIParamSet *params = NULL );
bool ParseScript( const QString &inputScript, UIParamSet *params = NULL );
bool RunScript( UIContext &context );
bool RunScript( UIContext &context );
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment