]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreter.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkInterpreter.cxx
index c925050a17fd99e20bf257351e8fcd94a2d11f9f..febbd934840929bd6dc0002b8ca00ab0d83bd772 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/04/08 06:59:30 $
-  Version:   $Revision: 1.58 $
+  Date:      $Date: 2008/04/09 11:16:57 $
+  Version:   $Revision: 1.59 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -615,7 +615,7 @@ printf("EED Interpreter::InterpretLine %s \n", line.c_str() );
 void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
 {
     bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine(\""<<line<<"\")"<<std::endl);
-    bbtkMessage("Echo",2,"\""<<line<<"\""<<std::endl);
+    bbtkMessage("Echo",2,line<<std::endl);
 
     std::vector<std::string> words;
     SplitLine(line,words);
@@ -800,6 +800,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
 
       case cReset :  
         this->mExecuter->Reset();
+       mFileNameHistory.clear();
         break;
 
       case cInclude :
@@ -1240,23 +1241,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;iStrScript<sizeVecStricpt;iStrScript++)
-     {
-        if (mFileName[iStrScript] == fullPathScriptName )
-        {
-           okScriptExist=true;
-        } // if
-     } // for
-
-     if (find(mFileName.begin(),mFileName.end(),fullPathScriptName)!=mFileName.end())
-//    if (okScriptExist==true)
+     Utilities::replace( fullPathScriptName , 
+                        INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
+   
+     if (find(mFileNameHistory.begin(),
+             mFileNameHistory.end(),
+             fullPathScriptName)!=mFileNameHistory.end())
      {
-           bbtkMessage("Interpreter",1,"file '"<<fullPathScriptName
-                   <<"' already open : I do not open it once more to prevent recursive inclusion"<<std::endl);
         return;
      }
 
@@ -1274,6 +1265,7 @@ void Interpreter::SwitchToStream( std::stringstream* stream )
 
     mFile.push_back(s);
     mFileName.push_back(fullPathScriptName);
+    mFileNameHistory.push_back(fullPathScriptName);
     mIncludeFileName.push_back(includeScriptName);
     mLine.push_back(0);
 
@@ -1326,16 +1318,6 @@ void Interpreter::SwitchToStream( std::stringstream* stream )
     while (mFile.size() != 0) 
     {
        CloseCurrentFile();
-    /*
-      mFile.back()->close();
-      delete mFile.back();
-      mFile.pop_back();
-      bbtkDebugMessage("Interpreter",9,
-                      " Closing file '"<<mFileName.back()<<"'"<<std::endl);
-      mFileName.pop_back();
-      mIncludeFileName.pop_back();
-      mLine.pop_back();
-*/
     }
     bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
                       <<std::endl);
@@ -1925,26 +1907,51 @@ void  Interpreter::NewGUI(const std::string& boxname,
       if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
           ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
        continue;
+      bool widok = true;
+      std::string widget,adaptor;
       // try to find a widget adaptor
-      std::string adaptor;
-      if (F->FindWidgetAdaptor(DataInfo(typeid(Void),""),
+      if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
                               d->GetDataInfo(),
                               adaptor))
        {
-         // store the input name
-         in.push_back(i->first);
          // command to create the adaptor
          (*s) << "  new "<<adaptor<<" "<<i->first<<std::endl;
-         // command to create the output
-         (*s) << "  output "<<i->first<<" "
-              <<i->first<<".Out "<<i->first<<std::endl;
-           //         <<" Output of the widget which allows to set "
-           //<i->first<<"'"<<std::endl;
          // Sets the label of the widget adaptor to the name of the input
          (*s) << "  set "<<i->first<<".Label "<<i->first<<std::endl;
+         // Sets the initial value of the widget to the value of the input
+         (*s) << "  set "<<i->first<<".In \""
+              <<box->bbGetInputAsString(i->first)<<"\""
+              << std::endl;
+         // store the input name
+         in.push_back(i->first);
          (*s) << "  connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
+           //<i->first<<"'"<<std::endl;
          (*s) << "  connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
        }
+      // try to find a two pieces adaptor
+      else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
+                                    d->GetDataInfo(),
+                                    widget,adaptor) )
+       {
+         // command to create the widget
+         (*s) << "  new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
+         // command to create the adaptor
+         (*s) << "  new "<<adaptor<<" "<<i->first<<std::endl;
+         // connect the two
+         (*s) << "  connect "<<i->first<<"Widget.Out "
+              <<i->first<<".In"<<std::endl;
+         // Sets the label of the widget adaptor to the name of the input
+         (*s) << "  set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
+         // Sets the initial value of the widget to the value of the input
+         (*s) << "  set "<<i->first<<"Widget.In \""
+              <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
+         // store the input name
+         in.push_back(i->first);
+         (*s) << "  connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
+           //<i->first<<"'"<<std::endl;
+         (*s) << "  connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
+
+       }
       // try to find an adaptor from string 
       // If found then can create a text input which 
       // will be automatically adapted 
@@ -1952,21 +1959,32 @@ void  Interpreter::NewGUI(const std::string& boxname,
                               d->GetDataInfo(),
                               adaptor))
        {
-         // store the input name
-         in.push_back(i->first);
          // command to create the adaptor
          (*s) << "  new InputText "<<i->first<<std::endl;
-         // command to create the output
-         (*s) << "  output "<<i->first<<" "
-              <<i->first<<".Out "<<i->first<<std::endl;
-           //         <<" Output of the widget which allows to set "
-           //<i->first<<"'"<<std::endl;
          // Sets the label of the widget adaptor to the name of the input
          (*s) << "  set "<<i->first<<".Title "<<i->first<<std::endl;
+         // Sets the initial value of the widget to the value of the input
+         (*s) << "  set "<<i->first<<".In \""
+              <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
+         // store the input name
+         in.push_back(i->first);
          (*s) << "  connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
+           //<i->first<<"'"<<std::endl;
          (*s) << "  connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
-       }
 
+       }
+      else 
+       {
+         widok = false;
+       }
+      if (widok)
+       {
+         // command to create the output
+         (*s) << "  output "<<i->first<<" "
+              <<i->first<<".Out "<<i->first<<std::endl;
+           //         <<" Output of the widget which allows to set "
+         
+       }
     }   
   // Inputs for window properties
   (*s) << "  input WinTitle layout.WinTitle Title"<<std::endl;