X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkInterpreter.cxx;h=ede613aae17a55c7142de17f212c98ed20d9a02e;hb=4ad5b5ee44357ad873bc8c43230defb6d0a79879;hp=ab0075d2e84030d01bd0ac1bd3c5a16b0adf3d46;hpb=b9da3baf83b7791357c78322e3280314ec782f40;p=bbtk.git diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index ab0075d..ede613a 100644 --- a/kernel/src/bbtkInterpreter.cxx +++ b/kernel/src/bbtkInterpreter.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.cxx,v $ $ Language: C++ - Date: $Date: 2008/03/26 08:51:43 $ - Version: $Revision: 1.56 $ + Date: $Date: 2008/04/18 12:59:15 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -21,9 +21,12 @@ */ #include "bbtkInterpreter.h" +#include "bbtkExecuter.h" +#include "bbtkTranscriptor.h" #include "bbtkMessageManager.h" #include "bbtkConfigurationFile.h" #include "bbtkUtilities.h" +#include "bbtkWxBlackBox.h" #include #include #ifdef CMAKE_HAVE_TERMIOS_H @@ -36,25 +39,38 @@ namespace bbtk { - //Interpreter* Interpreter::mGlobalInterpreter = NULL; + //======================================================================= + Interpreter::Pointer Interpreter::New(const std::string& cpp_file) + { + bbtkDebugMessage("Kernel",9,"Interpreter::New()"<0 : Prints the 'echo' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1); bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0); bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <SetInterpreter(this); + if (cpp_file.size()!=0) + { + mExecuter = boost::static_pointer_cast(bbtk::Transcriptor::New(cpp_file)); + } + else + { + mExecuter = boost::static_pointer_cast(bbtk::Executer::New()); + } + + // Lock this pointer or will auto-destruct !! + mExecuter->SetInterpreter(MakePointer(this,true)); // For the time being, comment out previous line, and // uncomment next line to check Transcriptor @@ -64,215 +80,239 @@ bufferNb =0; // Builds the commands dict CommandInfoType info; - info.category = "new"; + info.keyword = "new"; info.argmin = 2; info.argmax = 2; info.code = cNew; info.syntax = "new "; info.help = "Creates a new black box of type with name "; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "delete"; + info.keyword = "delete"; info.argmin = 1; info.argmax = 1; info.code = cDelete; info.syntax = "delete "; info.help = "Deletes the black box of name "; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "connect"; + info.keyword = "newgui"; + info.argmin = 2; + info.argmax = 2; + info.code = cNewGUI; + info.syntax = "newgui "; + info.help = "Automatically creates a graphical user interface with name for the black box and connects it to the box inputs"; + mCommandDict[info.keyword] = info; + + info.keyword = "connect"; info.argmin = 2; info.argmax = 2; info.code = cConnect; info.syntax = "connect "; info.help = "Connects the ouput of black box to the input of black box "; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "print"; + info.keyword = "print"; info.argmin = 1; info.argmax = 1; info.code = cPrint; info.syntax = "print "; info.help = "Prints the string. Substitutes any token of the form '$box.output$' by the string adaptation of the output of the box (requires the right adaptor). No carriage return is issued at the end, use '\\n' to add carriage returns. The level of 'Echo' messages must be greater than 1 (see the command 'message')."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "exec"; + info.keyword = "exec"; info.argmin = 1; info.argmax = 2; info.code = cExec; info.syntax = "exec "; - info.help = "Executes the black box of name (and connected boxes if needed). If the special category 'freeze' is given then freezes any further execution command. 'unfreeze' reverts to normal execution mode."; - mCommandDict[info.category] = info; + info.help = "Executes the black box of name (and connected boxes if needed). If the special keyword 'freeze' is given then freezes any further execution command. 'unfreeze' reverts to normal execution mode."; + mCommandDict[info.keyword] = info; - info.category = "package"; + info.keyword = "package"; info.argmin = 1; info.argmax = 1; info.code = cPackage; info.syntax = "package "; info.help = "Begins the definition of a package."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "endpackage"; + info.keyword = "endpackage"; info.argmin = 0; info.argmax = 0; info.code = cEndPackage; info.syntax = "endpackage"; info.help = "Ends the definition of a package."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "define"; + info.keyword = "define"; info.argmin = 1; info.argmax = 2; info.code = cDefine; info.syntax = "define []"; info.help = "Begins the definition of a new type of complex black box called . If if provided will create it in the given package."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "endefine"; + info.keyword = "endefine"; info.argmin = 0; info.argmax = 0; info.code = cEndDefine; info.syntax = "endefine"; info.help = "Ends the definition of a new type of complex black box"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; + + info.keyword = "kind"; + info.argmin = 1; + info.argmax = 1; + info.code = cKind; + info.syntax = "kind "; + info.help = "Sets the kind of the currently defined complex black box"; + mCommandDict[info.keyword] = info; - info.category = "input"; + info.keyword = "input"; info.argmin = 3; info.argmax = 3; info.code = cInput; info.syntax = "input "; info.help = "Defines the input of the current working black box as being an alias for the input of the black box . defines the help string for the newly created input"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "output"; + info.keyword = "output"; info.argmin = 3; info.argmax = 3; info.code = cOutput; info.syntax = "output "; info.help = "Defines the output of the current working black box as being an alias for the output of the black box . defines the help string for the newly created output"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "set"; + info.keyword = "set"; info.argmin = 2; info.argmax = 2; info.code = cSet; info.syntax = "set "; info.help = "Sets the value of the input of the black box to . There must exist a string to the value type adaptor"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "config"; // JPR + info.keyword = "config"; // JPR info.argmin = 0; info.argmax = 0; info.code = cConfig; info.syntax = "config"; info.help = "Prints the value of all configuration parameters"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "index"; // LG + info.keyword = "index"; // LG info.argmin = 0; info.argmax = 2; info.code = cIndex; info.syntax = "index [ ['Initials'(default)|'Packages'|'Categories'|'Adaptors']]"; info.help = "Creates an html index of known boxes. If filename is provided then save it to the file 'filename'. The default index entries are the initial letters of the names of the boxes. If 'Packages' or 'Categories' is provided then the entries are either the packages names or the categories. If 'Adaptors' is provided then an alphabetical index of all adaptors is created."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "reset"; + info.keyword = "reset"; info.argmin = 0; info.argmax = 0; info.code = cReset; info.syntax = "reset"; info.help = "Deletes all boxes and unloads all packages (bbi is reset to its start state)"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "author"; + info.keyword = "author"; info.argmin = 1; info.argmax = 1; info.code = cAuthor; info.syntax = "author "; info.help = "Adds the string to the author information of the black box being defined"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "category"; //JP + info.keyword = "category"; //JP info.argmin = 1; info.argmax = 1; info.code = cCategory; info.syntax = "category "; info.help = "Adds the string to the category information of the black box being defined"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "description"; + info.keyword = "description"; info.argmin = 1; info.argmax = 1; info.code = cDescription; info.syntax = "description "; info.help = "Adds the string to the descriptive information of the black box being defined"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "help"; + info.keyword = "help"; info.argmin = 0; info.argmax = 2; info.code = cHelp; info.syntax = "help"; info.syntax = "\n (1) help \n (2) help \n (3) help packages [all]\n (4) help [all]\n (5) help \n (6) help "; info.help = "Effect :\n (1) Lists all available commands;\n (2) Prints help on a particular command; \n (3) Lists the packages loaded and their black boxes.\n Add 'all' to list adaptors; \n (4) Prints short help on the black boxes of a package.\n Add 'all' to include adaptors; \n (5) Prints full help on a black box type; \n (6) Prints information on the inputs, outputs and connections of a black box instance."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "message"; + info.keyword = "message"; info.argmin = 0; info.argmax = 2; info.code = cMessage; info.syntax = "message "; - info.help = "Sets the level of the kind of messages to .\n If kind='All' then sets the level for all kinds. If no kind nor level is passed then prints info on available kinds of messages and their current level."; mCommandDict[info.category] = info; + info.help = "Sets the level of the kind of messages to .\n If kind='All' then sets the level for all kinds. If no kind nor level is passed then prints info on available kinds of messages and their current level."; mCommandDict[info.keyword] = info; - info.category = "include"; + info.keyword = "include"; info.argmin = 1; info.argmax = 2; info.code = cInclude; info.syntax = "include [source]"; info.help = "Includes the file .\n 'source' : If the keyword 'source' is provided then informs bbi that the included file is the source of the current box definition (Advanced; used to get the right 'Include' field in html doc of packages 'appli' scripts)."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "quit"; + info.keyword = "quit"; info.argmin = 0; info.argmax = 0; info.code = cQuit; info.syntax = "quit"; info.help = "Quits the program (during script execution it stops the complete execution)"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "load"; + info.keyword = "load"; info.argmin = 1; info.argmax = 1; info.code = cLoad; info.syntax = "load "; info.help = "Loads the black box package "; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "unload"; + info.keyword = "unload"; info.argmin = 1; info.argmax = 1; info.code = cUnload; info.syntax = "unload "; info.help = "Unloads the black box package "; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; - info.category = "graph"; + info.keyword = "graph"; info.argmin = 0; info.argmax = 6; info.code = cGraph; info.syntax = "graph [ BlackBoxName [ Detail 0..1 [ Level 0..99999 [ Output html file [ Custom header [ Custom title ]]]]]] \n graph [ BlackBoxNameType [ Detail 0..1 [ Level 0..99999 [ Output html file [ Custom header [ Custom title ]]]]]]"; info.help = "Shows a graphical view of a bbtk pipeline.\n- BlackBoxName : name of the box to view. Default '.' : current box.\n- BlackBoxNameType : name of the type of box to view, ex : 'workspace')"; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; + + info.keyword = "object"; + info.argmin = 0; + info.argmax = 1; + info.code = cObject; + info.syntax = "object "; + info.help = "Provides debug info on object "; + mCommandDict[info.keyword] = info; /* - info.category = "workspace"; + info.keyword = "workspace"; info.argmin = 1; info.argmax = 2; info.code = cWorkspace; info.syntax = "workspace < ( freeze | unfreeze ) | ( rename ) >"; info.help = "Configures the workspace.\n 'freeze' allow to block execution commands while keeping definition commands active. 'unfreeze' turns back the worspace in 'normal' mode.\n 'rename' allow to set a new name to the workspace."; - mCommandDict[info.category] = info; + mCommandDict[info.keyword] = info; */ bbtkDebugDecTab("Interpreter",9); @@ -288,10 +328,9 @@ bufferNb =0; */ Interpreter::~Interpreter() { - bbtkDebugMessageInc("Interpreter",9,"Interpreter::~Interpreter()" < Interpreter::~Interpreter()" < words; SplitLine(line,words); @@ -643,7 +682,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) InterpretCommand(words,command); bbtkDebugMessage("Interpreter",9, - "Command='"<& } else { - bbtkError("'"<& script_paths.push_back(full_path); } } + if (script_paths.empty()) + { + bbtkError("no '"<::iterator i; @@ -1205,23 +1258,13 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) void Interpreter::LoadScript( std::string fullPathScriptName, std::string includeScriptName) { - Utilities::replace( fullPathScriptName , INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR); - - bool okScriptExist=false; - int iStrScript,sizeVecStricpt=mFileName.size(); - for ( iStrScript=0;iStrScriptclose(); - delete mFile.back(); - mFile.pop_back(); - bbtkDebugMessage("Interpreter",9, - " Closing file '"< in; + + Factory::Pointer F = mExecuter->GetFactory(); + /* + Package::Pointer user = F->GetPackage("user"); + */ + ComplexBlackBoxDescriptor::Pointer workspace = mExecuter->GetWorkspace(); + + if (workspace==0) + { + delete s; + bbtkError("Interpreter::CreateGUI : could not access the executer workspace"); + } + + + /* + (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get()); + */ + + BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname); + // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap(); + int nb = 0; + BlackBox::InputConnectorMapType::iterator i; + for (i=box->bbGetInputConnectorMap().begin(); + i!=box->bbGetInputConnectorMap().end(); + ++i) + { + // If the input is connected : continue + if (i->second->IsConnected()) continue; + // Get the input descriptor + const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first); + // If it is a "system" input : skip it + if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) || + ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) ) + continue; + bool widok = true; + std::string widget,adaptor; + // try to find a widget adaptor + if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""), + d->GetDataInfo(), + adaptor)) + { + // command to create the adaptor + (*s) << " new "<first<first<<".Label "<first<first<<".In \" " + <bbGetInputAsString(i->first)<<"\"" + << std::endl; + // store the input name + in.push_back(i->first); + (*s) << " connect "<first<<".Widget layout.Widget"<first<<"'"<first<<".BoxChange change.In"<FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""), + d->GetDataInfo(), + widget,adaptor) ) + { + // command to create the widget + (*s) << " new "<first<<"Widget"<first<first<<"Widget.Out " + <first<<".In"<first<<"Widget.Label "<first<first<<"Widget.In \" " + <bbGetInputAsString(i->first)<<"\""<< std::endl; + // store the input name + in.push_back(i->first); + (*s) << " connect "<first<<"Widget.Widget layout.Widget"<first<<"'"<first<<"Widget.BoxChange change.In"<FindAdaptor(DataInfo(typeid(std::string),""), + d->GetDataInfo(), + adaptor)) + { + // command to create the adaptor + (*s) << " new InputText "<first<first<<".Title "<first<first<<".In \" " + <bbGetInputAsString(i->first)<<"\""<< std::endl; + // store the input name + in.push_back(i->first); + (*s) << " connect "<first<<".Widget layout.Widget"<first<<"'"<first<<".BoxChange change.In"<first<<" " + <first<<".Out "<first<::iterator j; + for (j=in.begin();j!=in.end();++j) + { + // connect + (*s) << "connect "<GetObjectRecursiveSize(); + return s; + } + //========================================================================== }//namespace