]> Creatis software - bbtk.git/commitdiff
Add unfinished version of bbtkTranscriptor
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Thu, 14 Feb 2008 11:38:58 +0000 (11:38 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Thu, 14 Feb 2008 11:38:58 +0000 (11:38 +0000)
(I wouldn't like to loose it ...)

kernel/src/bbtkExecuter.cxx
kernel/src/bbtkFactory.cxx
kernel/src/bbtkFactory.h
kernel/src/bbtkTranscriptor.cxx [new file with mode: 0644]
kernel/src/bbtkTranscriptor.h

index 2bb24d8e12b8eec87092a6d6b6056a061313c206..7564baf85337198a81111d65f2c6478aef454ea2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkExecuter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/02/06 10:53:02 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2008/02/14 11:38:58 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@
 namespace bbtk
 {  
 /**
- *  
+ *
  */
   Executer::Executer()
     : mPackage(0),
@@ -53,7 +53,7 @@ namespace bbtk
   } 
 
 /**
- *  
+ *
  */
   Executer::~Executer()
   {
@@ -61,9 +61,9 @@ namespace bbtk
      if (mRoot) 
      {
         mPackage->UnRegisterBlackBox("workspace");
-        delete mRoot;    
+        delete mRoot;
      }
-     if (mPackage) 
+     if (mPackage)
      {
         GetGlobalFactory()->UnLoadPackage("user");
      }
@@ -72,7 +72,7 @@ namespace bbtk
   
 
 /**
- *  
+ *
  */
   void Executer::Reset()
   {
@@ -84,10 +84,10 @@ namespace bbtk
     // all user defined CBB otherwise any instance 
     // of a user CBB that is in the 'workspace' would try to 
     // access a user CBB descriptor which has been previously freed
-    if (mRoot) 
+    if (mRoot)
     {
        mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
-       delete mRoot;    
+       delete mRoot;
     }
     if (mPackage) 
     {
@@ -111,7 +111,7 @@ namespace bbtk
     mOpenPackage.push_back(mPackage);
     bbtkDebugDecTab("Kernel",9);
   }
-  
+
   /// changes the workspace name
   void Executer::SetWorkspaceName( const std::string& n )
   {
@@ -165,7 +165,6 @@ namespace bbtk
   {
     mOpenDefinition.back().box->SetScriptFileName(name);
   }
-  
 
   void Executer::EndDefine ()
   {
@@ -206,20 +205,19 @@ namespace bbtk
   {
      Current()->Add(nodeType,nodeName);
   }
-  
 
   /*
     void Executer::Remove (const std::string &nodeName)
   {
     // Current()->RemoveBlackBox(nodeName);
   }
-  */    
+  */
 
 /**
- *  
+ *
  */
   void Executer::Connect (const std::string &nodeFrom, 
-                          const std::string &outputLabel, 
+                          const std::string &outputLabel,
                           const std::string &nodeTo, 
                           const std::string &inputLabel)
   {
@@ -227,7 +225,7 @@ namespace bbtk
   }
 
  /**
- *  
+ *
  */ 
   void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
   {
@@ -244,9 +242,9 @@ namespace bbtk
         Current()->AddToExecutionList(nodeName) ;
      }
   }
-    
+
 /**
- *  
+ *
  */
   void Executer::DefineInput ( const std::string &name,
                                const std::string &box,
@@ -290,7 +288,6 @@ namespace bbtk
           mess += ")";
           std::string title(name);
           title += " ?";
-    
           std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
           Set(box,input,ans); 
        }
@@ -300,7 +297,7 @@ namespace bbtk
     Current()->DefineInput(name,box,input,help);
 
   }
-  
+
  /**
  *  
  */ 
@@ -348,8 +345,8 @@ namespace bbtk
   }
 
   /**
-   *  
-   */ 
+   *
+   */
   std::string Executer::Get(const std::string &box,
                             const std::string &output)
   {
@@ -381,7 +378,7 @@ namespace bbtk
         a->bbDelete();
         return r;
       }
-    else 
+    else
       {
        b->bbExecute();
        return b->bbGetOutput(output).unsafe_get<std::string>();
@@ -497,7 +494,7 @@ namespace bbtk
     {
          blackbox=Current()->GetPrototype();
     }
-    else 
+    else
     {
          blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
     }
@@ -506,21 +503,20 @@ namespace bbtk
 
     if (blackbox)
       {      
-       // Don't pollute the file store with  "temp_dir" directories ...    
+       // Don't pollute the file store with  "temp_dir" directories ...
        std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
        char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
-       
+
        std::string directory = default_doc_dir; 
        if (c != '/' && c !='\\') directory = directory + "/";
 
-       directory = directory +  "temp_dir"; 
-       
+       directory = directory +  "temp_dir";
        //std::string directory("temp_dir");
        std::string filename(directory + "/" + "bbtk_graph_pipeline");
        std::string filename_html(filename+".html");
        std::string command0("mkdir \""+directory + "\"");
 
-#if defined(_WIN32)  
+#if defined(_WIN32)
        std::string command2("start ");
 #else 
        std::string command2("gnome-open ");
@@ -543,7 +539,7 @@ namespace bbtk
            } 
 
            blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
-           s << "</body></html>\n";      
+           s << "</body></html>\n";
          }
        s.close();
        
@@ -554,7 +550,6 @@ namespace bbtk
       {
        bbtkMessageInc("Help",1,"No black box: \""
                       <<nameblackbox<<"\" " <<std::endl);
-       
       }
     return page;
   }
index ab82b885600f5583cb2f412fb7c77492f2785bb1..9f1e96f91576a358d0317f6c6f3f2c0f6f154e36 100644 (file)
@@ -4,8 +4,8 @@ Program:   bbtk
 Module:    $RCSfile: bbtkFactory.cxx,v $
 Language:  C++
 
-Date:      $Date: 2008/02/12 12:55:16 $
-Version:   $Revision: 1.18 $
+Date:      $Date: 2008/02/14 11:38:58 $
+Version:   $Revision: 1.19 $
                                                                                 
 
 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
@@ -582,7 +582,7 @@ namespace bbtk
   //===================================================================
 
   //===================================================================
-  /// Prints help on the black box of type <name> 
+  /// Prints help on the black box of type <name>
   /// Returns the package to which it belongs
   void Factory::HelpBlackBox(const std::string& name, 
                             std::string& package,
@@ -598,7 +598,7 @@ namespace bbtk
       if (i->second.mPackage->ContainsBlackBox(name)) 
         {
           i->second.mPackage->HelpBlackBox(name,full);
-         package = i->second.mPackage->GetName();
+             package = i->second.mPackage->GetName();
           found = true;
         }
       }
index 0a7f39e6f2f0a1adca70e8a842cc671b20862bfd..a4f84e73f6f7d0c015484d8e1f05f0c28e7cdc44 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkFactory.h,v $
   Language:  C++
-  Date:      $Date: 2008/02/12 12:55:16 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2008/02/14 11:38:58 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
@@ -170,7 +170,7 @@ namespace bbtk
 
   inline void HelpBlackBox(const std::string& name, std::string& package,
                           bool full=true
-                          ) 
+                          )
   {
     GetGlobalFactory()->HelpBlackBox(name, package, full);
   }
diff --git a/kernel/src/bbtkTranscriptor.cxx b/kernel/src/bbtkTranscriptor.cxx
new file mode 100644 (file)
index 0000000..93b2f69
--- /dev/null
@@ -0,0 +1,678 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbtkTranscriptor.cxx,v $ $
+  Language:  C++
+  Date:      $Date: 2008/02/14 11:38:58 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+/**
+ *  \file 
+ *  \brief class Transcriptor: level 0 of script execution (code)
+ */
+
+#include "bbtkTranscriptor.h"
+#include "bbtkMessageManager.h"
+#include "bbtkFactory.h"
+#include "bbtkUtilities.h"
+#include <fstream>
+
+//#ifdef _USE_WXWIDGETS_
+//#include <wx/textdlg.h>
+//#endif
+
+//#include "bbtkWxBlackBox.h"
+
+#include "bbtkConfigurationFile.h"
+
+namespace bbtk
+{
+/**
+ *
+ */
+  Transcriptor::Transcriptor(std::string filename)
+    : mPackage(0),
+      mRoot(0),
+      mNoExecMode(false),
+      mDialogMode(NoDialog)
+  {
+    //VirtualExec();    
+    bbtkDebugMessageInc("Kernel",9,"Transcriptor::Transcriptor()" <<std::endl);
+    Reset();
+    bbtkDebugDecTab("Kernel",9);
+    
+    //std::ofstream *m_Fp = new std::ofstream();
+    m_Fp.open (filename.c_str(), std::ios::out );
+
+    m_Fp << "#include \"bbtkExecuter.h\""                   << std::endl;
+    m_Fp << "main(int argc, char *argv[]) {"                << std::endl;
+    m_Fp << "  bbtk::Executer *e = new bbtk::Executer();"   << std::endl;
+  } 
+
+/**
+ *
+ */
+  Transcriptor::~Transcriptor()
+  {
+     bbtkDebugMessageInc("Kernel",9,"Transcriptor::~Transcriptor()" <<std::endl);
+     if (mRoot) 
+     {
+        mPackage->UnRegisterBlackBox("workspace");
+        delete mRoot;    
+     }
+     if (mPackage) 
+     {
+        GetGlobalFactory()->UnLoadPackage("user");
+     }
+
+     if(m_Fp)
+     {
+        bbtkDebugDecTab("Kernel",9);
+        m_Fp << " }"   << std::endl;
+        m_Fp.close();
+       // delete m_Fp;
+     }
+  }
+
+
+// ========================= Begin of Battelfield ========================================================================
+
+
+/**
+ *  
+ */
+  void Transcriptor::Reset()
+  {
+
+     m_Fp << "e->Reset( );" << std::endl;
+  /*
+    bbtkDebugMessageInc("Kernel",9,"Transcriptor::Reset()" <<std::endl);
+
+    // The 'user' package must be closed before all other 
+    // because box destructors must not be unloaded when bb are deleted!
+    // Similarly, the 'workspace' CBB must be destroyed before 
+    // all user defined CBB otherwise any instance 
+    // of a user CBB that is in the 'workspace' would try to 
+    // access a user CBB descriptor which has been previously freed
+    if (mRoot) 
+    {
+       mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
+       delete mRoot;    
+    }
+    if (mPackage) 
+    {
+       GetGlobalFactory()->UnLoadPackage("user");
+    }
+    GetGlobalFactory()->Reset();
+    // Create user package
+    mPackage = new Package("user","internal to bbi",
+                           "User defined black boxes",
+                           "",
+                           BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+    // Create user workspace
+    mRoot = new ComplexBlackBoxDescriptor("workspace"); //,f);
+    mRoot->AddToAuthor("bbi (internal)");
+    mRoot->AddToDescription("User's workspace");
+    mOpenDefinition.push_back(CBBDefinition(mRoot,"user"));
+    // Register it into the user package
+    mPackage->RegisterBlackBox(mRoot);
+    // Insert the user package in the factory
+    InsertPackage(mPackage);
+    mOpenPackage.push_back(mPackage);
+    bbtkDebugDecTab("Kernel",9);
+    */
+  }
+
+  /// changes the workspace name
+  void Transcriptor::SetWorkspaceName( const std::string& n )
+  {
+  
+     m_Fp << "// ==> SetWorkspaceName() called here" << std::endl;    
+   // mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), n );
+  }
+
+  void Transcriptor::BeginPackage (const std::string &name)
+  {
+     m_Fp << "// ==> BeginPackage() called here" << std::endl;  
+  /*
+     bbtkDebugMessageInc("Kernel",9,"Executer::BeginPackage(\""<<name<<"\")"
+                        <<std::endl);
+     Package* p;
+     try 
+      {
+       p = GetGlobalFactory()->GetPackage(name);
+      }
+    catch (Exception e)
+      {
+       p = new Package(name,
+                       "",
+                       "",
+                       "",
+                       BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+       InsertPackage(p);
+      }
+     mOpenPackage.push_back(p);
+ */
+  }
+
+  void Transcriptor::EndPackage()
+  {
+     m_Fp << "// ==> EndPackage() called here" << std::endl;    
+   // if (mOpenPackage.size()>1) mOpenPackage.pop_back();
+  }
+
+  void Transcriptor::Define (const std::string &name,
+                        const std::string &pack,
+                        const std::string &scriptfilename)
+  {
+     m_Fp << "// on Define, Define() called here" << std::endl;   
+  /*
+    bbtkDebugMessageInc("Kernel",9,"Executer::Define(\""<<name<<
+                       ","<<pack<<"\")" 
+                        <<std::endl);
+
+    ComplexBlackBoxDescriptor* b = new ComplexBlackBoxDescriptor(name);
+    b->SetScriptFileName(scriptfilename);
+    mOpenDefinition.push_back( CBBDefinition( b, pack ) );
+    
+    bbtkDebugDecTab("Kernel",9);
+ */
+  }
+
+  /// Sets the file name to use for the current definition
+  /// (Used to set it after the Define command)
+  void Transcriptor::SetCurrentFileName (const std::string &name )
+  
+  {
+    m_Fp << "// ==>on Include : SetCurrentFileName( ) called here" << std::endl;
+   // mOpenDefinition.back().box->SetScriptFileName(name);
+  }
+
+  void Transcriptor::EndDefine ()
+  {
+    m_Fp << "// ==> on EndDefine, EndDefine( ); called here " << std::endl;
+
+  /*
+    bbtkDebugMessageInc("Kernel",9,"Executer::EndDefine(\""
+                        <<Current()->GetTypeName()<<"\")" 
+                        <<std::endl);
+    // Does current package exist ?
+    Package* p;
+    std::string pname(mOpenDefinition.back().package);
+    if (pname.size()>0)
+    {
+      try
+      {
+           p = GetGlobalFactory()->GetPackage(pname);
+      }
+      catch (Exception e)
+      {
+            p = new Package(pname,
+                       "",
+                       "",
+                       "",
+                       BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+           InsertPackage(p);
+      }
+    }
+    else
+    {
+          p = mOpenPackage.back();
+    }
+    p->RegisterBlackBox(Current());
+
+    mOpenDefinition.pop_back();
+    */
+
+  }
+
+
+  void Transcriptor::Create ( const std::string& nodeType, 
+                              const std::string& nodeName)
+  {
+    // Current()->Add(nodeType,nodeName);
+     m_Fp << "e->Add(" << nodeType << ", " <<  nodeName << ");" << std::endl;
+  }
+
+
+  /*
+    void Transcriptor::Remove (const std::string &nodeName)
+  {
+    /// \todo Remove
+    // Current()->RemoveBlackBox(nodeName);
+    //  m_Fp << "e->Remove(" <<  nodeName << ");" << std::endl;
+  }
+  */ 
+
+/**
+ *  
+ */
+  void Transcriptor::Connect (const std::string &nodeFrom, 
+                          const std::string &outputLabel, 
+                          const std::string &nodeTo, 
+                          const std::string &inputLabel)
+  {
+    //Current()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
+     m_Fp << "e->Connect("<< nodeFrom << ", " <<  outputLabel << ", "
+          << nodeTo  << ", " << inputLabel<< ");" << std::endl;
+  }
+
+ /**
+ *  
+ */ 
+  void Transcriptor::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
+  {
+ // if in root
+     if (Current()==mRoot) 
+     {
+        if (!mNoExecMode) 
+        {
+           Current()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
+        }
+     }
+     else 
+     {
+        Current()->AddToExecutionList(nodeName) ;
+     }
+  }
+    
+/**
+ *  
+ */
+  void Transcriptor::DefineInput ( const std::string &name,
+                               const std::string &box,
+                               const std::string &input,
+                               const std::string& help)
+  {
+    // If the input is defined in the Root box
+    if (Current()==mRoot) 
+    {  
+       m_Fp << "// ==> Some extra work to do when Current()==mRoot" << std::endl;
+
+    }
+       m_Fp << "e->DefineInput("<< name << ", " <<  box << ", "
+          << input << ", " << help << ");" << std::endl;
+
+
+  /*
+    // If the input is defined in the Root box
+    if (Current()==mRoot) 
+      {
+      // If the dialog mode is set to NoDialog
+      // and the user passed the name in the Inputs map 
+      // then the associated value is set to the box.input
+      // This is the way command line parameters are passed to the Root box
+         if (mDialogMode == NoDialog) 
+         {
+         // find if name is in mInputs
+            std::map<std::string,std::string>::iterator i;
+            i = mInputs.find(name);
+            if (i!=mInputs.end()) {
+               Set(box,input,(*i).second);
+            }
+         }
+        // If the dialog mode is set to TextDialog
+        // The user is prompted for the value
+        else if (mDialogMode == TextDialog) 
+        {
+           std::cout << name << "=";
+           std::string ans;
+           std::cin >> ans;
+           Set(box,input,ans);
+        }
+#ifdef _USE_WXWIDGETS_
+       // If the dialog mode is set to GraphicalDialog
+       // A dialog box is pop up
+       else if (mDialogMode == GraphicalDialog) 
+       {
+          std::string mess("Enter the value of '");
+          mess += name;
+          mess += "' (";
+          mess += help;
+          mess += ")";
+          std::string title(name);
+          title += " ?";
+
+          std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
+          Set(box,input,ans); 
+       }
+#endif
+    }
+
+    Current()->DefineInput(name,box,input,help);
+*/
+
+  }
+  
+ /**
+ *  
+ */ 
+   void Transcriptor::DefineOutput ( const std::string &name,
+                                 const std::string &box,
+                                 const std::string &output,
+                                 const std::string& help)
+  {
+   // Current()->DefineOutput(name,box,output,help);
+       m_Fp << "e->DefineOutput("<< name << ", " <<  box << ", "
+          << output << ", " << help << ");" << std::endl;
+  }
+
+  /**
+   *  
+   */ 
+  void Transcriptor::Set (const std::string &box,
+                      const std::string &input,
+                      const std::string &value)
+  {
+  
+    m_Fp << "// ==> Set() called here"                   << std::endl;  
+/*
+    BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
+    // Looks for the adaptor
+
+    if ( b->bbGetInputType(input) !=  typeid(std::string) ) 
+      {
+         BlackBox* a = 
+         NewAdaptor(typeid(std::string),
+                    b->bbGetInputType(input),
+                    "tmp");
+         if (!a) 
+         {
+            bbtkError("No <"<<
+                      TypeName(b->bbGetInputType(input))
+                      <<"> to <std::string> found");
+         }
+         std::string v(value);
+         a->bbSetInput("In",v);
+         a->bbExecute();
+         b->bbSetInput(input,a->bbGetOutput("Out"));
+         a->bbDelete();
+      }
+    else 
+      {
+      std::string v(value);
+      b->bbSetInput(input,v);
+      }
+*/
+  }
+
+  /**
+   *  
+   */ 
+  std::string Transcriptor::Get(const std::string &box,
+                            const std::string &output)
+  {
+  
+    m_Fp << "// ==> Get() called here"                   << std::endl;  
+/*    
+    BlackBox* b = Current()->GetPrototype()->bbGetBlackBox(box);
+    // Looks for the adaptor
+    if (b->bbGetOutputType(output) != typeid(std::string)) 
+      {
+      BlackBox* a = 
+          NewAdaptor(
+             b->bbGetOutputType(output),
+             typeid(std::string),
+             "tmp");
+      if (!a) 
+        {
+        bbtkError("No <"<<
+                   TypeName(b->bbGetOutputType(output))
+                   <<"> to <std::string> found");
+        }
+        b->bbExecute();
+
+        a->bbSetInput("In",b->bbGetOutput(output));
+        a->bbExecute();
+        std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
+       //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
+       //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
+       //             << std::endl;
+       //std::string v(value);
+       //b->bbSetInput(input,a->bbGetOutput("Out"));
+        a->bbDelete();
+        return r;
+      }
+    else 
+      {
+       b->bbExecute();
+       return b->bbGetOutput(output).unsafe_get<std::string>();
+       // std::string v = *((std::string*)b->bbGetOutput(output)) ;
+       // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
+       //   << std::endl;
+       // b->bbSetInput(input,&v);
+      }
+*/
+  }
+
+
+  void Transcriptor::Author(const std::string &authorName)
+  {
+    //Current()->AddToAuthor(authorName,Current()==mRoot);
+    if (Current()==mRoot)    
+       m_Fp << "e->AddToAuthor(" << authorName << ", true)" << std::endl;
+    else
+       m_Fp << "e->AddToAuthor(" << authorName << ", false)" << std::endl;
+  }
+
+  void Transcriptor::Category(const std::string &category)
+  {           
+    //Current()->AddToCategory(category,Current()==mRoot);
+    if (Current()==mRoot)    
+       m_Fp << "e->AddToCategory(" << category << ", true)" << std::endl;
+    else
+       m_Fp << "e->AddToCategory(" << category << ", false)" << std::endl;
+  }
+
+  void Transcriptor::Description(const std::string &d)
+  {
+    // Current()->AddToDescription(d,Current()==mRoot);
+    if (Current()==mRoot)    
+       m_Fp << "e->AddToDescription(" << d << ", true)" << std::endl;
+    else
+       m_Fp << "e->AddToDescription(" << d << ", false)" << std::endl;    
+  }
+
+
+  /// prints the list of the boxes of the current descriptor
+  void Transcriptor::PrintBoxes()
+  { 
+    m_Fp << "// ==> :PrintBoxes() called here"                   << std::endl;           
+ /* 
+    bbtkMessageInc("Help",1,"The black box descriptor \""
+                   <<Current()->GetTypeName()<<"\" contains : "<<std::endl);
+    Current()->PrintBlackBoxes();
+    bbtkDecTab("Help",1);
+ */
+ }
+
+// =========================End of Battelfield ========================================================================
+
+  std::string Transcriptor::ShowGraph(const std::string &nameblackbox, 
+                                 const std::string &detailStr, 
+                                 const std::string &levelStr,
+                                 const std::string &output_html,
+                                 const std::string &custom_header,
+                                 const std::string &custom_title,
+                                 bool system_display )
+  {
+    int detail =       atoi(detailStr.c_str());
+    int level  =       atoi(levelStr.c_str());
+
+    std::string filename_rootHtml (output_html) ;
+    std::string simplefilename_rootHtml ( Utilities::get_file_name(output_html));
+
+    bool relative_link = true;
+
+    // No output provided : automatic generation
+    if (output_html.length() == 0)
+      {
+       // Don't pollute the file store with  "temp_dir" directories ...    
+       std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
+       
+       char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
+       
+       std::string directory = default_doc_dir; 
+       if (c != '/' && c !='\\') directory = directory + "/";
+       directory = directory +  "temp_dir";    
+       
+       filename_rootHtml = directory + "/" + "User.html";
+       simplefilename_rootHtml = "User.html" ;
+
+       // Creating directory
+       std::string command0("mkdir \"" +directory + "\"");
+       system( command0.c_str() );
+
+       relative_link = false;
+      }
+
+    Package* p;
+    try
+    {
+          p = GetGlobalFactory()->GetPackage(nameblackbox);
+    }
+    catch (Exception e)
+    {
+          p = mPackage;
+    }
+    // Generating documentation-help of workspace
+    p->SetDocURL(filename_rootHtml);
+    p->SetDocRelativeURL(simplefilename_rootHtml);
+
+    p->CreateHtmlPage(filename_rootHtml,"bbi","user package",custom_header,custom_title,detail,level,relative_link);
+
+    std::string page = filename_rootHtml;
+    /*
+    try 
+    {
+         ShowGraphTypes(nameblackbox);
+    }
+    catch (bbtk::Exception a)
+    {
+         std::cout <<"EXC"<<std::endl;
+         page = ShowGraphInstances(nameblackbox,detail,level,system_display);
+    }
+    */
+    return page;
+  }
+
+  /// Generate a png file with the actual pipeline (Graphviz-dot needed)
+  std::string Transcriptor::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
+                                   bool system_display)
+  {
+
+    BlackBox* blackbox=NULL;
+    if (nameblackbox==".")
+    {
+         blackbox=Current()->GetPrototype();
+    }
+    else 
+    {
+         blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+    }
+    
+    std::string page;
+
+    if (blackbox)
+      {      
+       // Don't pollute the file store with  "temp_dir" directories ...    
+       std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
+       char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
+       
+       std::string directory = default_doc_dir; 
+       if (c != '/' && c !='\\') directory = directory + "/";
+
+       directory = directory +  "temp_dir"; 
+       
+       //std::string directory("temp_dir");
+       std::string filename(directory + "/" + "bbtk_graph_pipeline");
+       std::string filename_html(filename+".html");
+       std::string command0("mkdir \""+directory + "\"");
+
+#if defined(_WIN32)  
+       std::string command2("start ");
+#else 
+       std::string command2("gnome-open ");
+#endif
+
+       command2=command2+filename_html;
+       page = filename_html;
+       // 1. Generate Html Diagram
+       std::ofstream s;
+       s.open(filename_html.c_str());
+       if (s.good()) 
+         {
+           s << "<html><head><title>BBtk graph diagram</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\n";
+           s << "<body bgcolor=\"#FFFFFF\" text=\"#000000\"> \n\n";
+           if ( blackbox->bbGetName()=="workspacePrototype" )
+             {
+               s << "<center>Current workspace</center>";
+             } else {
+             s << "<center>" << blackbox->bbGetName()<< "</center>";
+           } 
+
+           blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
+           s << "</body></html>\n";      
+         }
+       s.close();
+       
+       // 2. Starting Browser
+       if (system_display) system( command2.c_str() );      
+      } 
+    else 
+      {
+       bbtkMessageInc("Help",1,"No black box: \""
+                      <<nameblackbox<<"\" " <<std::endl);
+       
+      }
+    return page;
+  }
+
+void Transcriptor::ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr)
+  {
+       bool found=false;
+
+       int detail = atoi(detailStr.c_str());
+       int level  = atoi(levelStr.c_str());
+       BlackBox* blackbox=NULL;
+       if (nameblackbox.compare(".")==0)
+       {
+          blackbox=Current()->GetPrototype();
+       } else {
+          blackbox = Current()->GetPrototype()->bbFindBlackBox(nameblackbox);
+       }
+
+       if (blackbox)
+       {
+          found=true;
+          blackbox->bbShowRelations(blackbox,detail,level); //,mFactory);
+       }
+
+       if (!found) 
+       {
+          bbtkError("Blackbox Name not found.. <"  <<nameblackbox<<">");
+       }
+  }
+
+  /*
+  /// sets the level of message
+  void Transcriptor::Message(const std::string &kind,
+                         const std::string& level)
+  {
+    int l;
+    sscanf(level.c_str(),"%d",&l);
+    bbtk::MessageManager::SetMessageLevel(kind,l);
+  }
+  */
+
+
+}//namespace
index c0a2c4f2a4dd4eab2aca849c0fd626dcb74db2b9..edb9eb26c94950917858dd8dd4b9e6c877feefda 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkTranscriptor.h,v $ $
   Language:  C++
-  Date:      $Date: 2008/02/05 12:16:55 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2008/02/14 11:38:59 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -85,6 +85,10 @@ namespace bbtk
                 const std::string& pack,
                 const std::string &scriptfilename);
 
+    /// Sets the file name to use for the current definition
+    /// (Used to set it after the Define command)
+    void SetCurrentFileName (const std::string &name );
+
     /// End the definition of a ComplexBlackBox
     void EndDefine ();