]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.cxx
#2536 BBTK Feature New Normal wt-version Package
[bbtk.git] / kernel / src / bbtkExecuter.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkExecuter.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.34 $
34 =========================================================================*/
35
36                                                                       
37
38 /**
39  *  \file 
40  *  \brief class Executer: level 0 of script execution (code)
41  */
42
43 #include "bbtkExecuter.h"
44 #include "bbtkMessageManager.h"
45 #include "bbtkFactory.h"
46 #include "bbtkUtilities.h"
47 //#include "bbtkWx.h"
48 #include <fstream>
49
50 #ifdef USE_WXWIDGETS
51 #include <wx/textdlg.h>
52 #endif
53
54 #include "bbtkWxBlackBox.h"
55
56 #include "bbtkConfigurationFile.h"
57
58 namespace bbtk
59 {
60   //=======================================================================
61   Executer::Pointer Executer::New()
62   {
63     bbtkDebugMessage("object",9,"Executer::New()"<<std::endl);
64     return MakePointer(new Executer());
65   }
66   //=======================================================================
67
68   //=======================================================================
69   Executer::Executer()
70     : 
71     mFactory(),
72     mRootPackage(),
73     mRootCBB(),
74     mNoExecMode(false),
75     mDialogMode(NoDialog),
76     mNoErrorMode(false)
77   {
78     bbtkDebugMessage("object",2,"==> Executer()" <<std::endl);
79     mFactory = Factory::New();
80     // The smart pointer on this is not made yet (is made by New) 
81     // -> create it to pass it to the factory
82     // We have to "lock" the smart pointer because the factory
83     // only keeps a weak pointer on the executer
84     // -> this would auto-destroy !!
85     mFactory->SetExecuter(MakePointer(this,true));
86     Reset();
87     bbtkDebugMessage("object",2,"<== Executer()" <<std::endl);
88   }
89   //=======================================================================
90
91   //=======================================================================
92   Executer::~Executer()
93   {
94      bbtkDebugMessage("object",2,"==> ~Executer()" <<std::endl);
95      mOpenDefinition.clear();
96      mOpenPackage.clear();
97      mFactory->Reset();
98      mFactory.reset();
99      bbtkDebugMessage("object",2,"<== ~Executer()" <<std::endl);
100   }
101   //=======================================================================
102
103   //=======================================================================
104    /// Loads a package
105     void Executer::LoadPackage(const std::string &name )
106    {
107      GetFactory()->LoadPackage(name);
108    }
109   //=======================================================================
110
111   //=======================================================================
112     /// Unloads a package
113     void Executer::UnLoadPackage(const std::string &name )
114     {
115       GetFactory()->UnLoadPackage(name);
116     }
117   //=======================================================================
118
119   //=======================================================================
120   void Executer::Reset()
121   {
122     bbtkDebugMessage("kernel",9,"==> Executer::Reset()" <<std::endl);
123
124     //    GetFactory()->Check();
125  
126     mOpenDefinition.clear();
127     mOpenPackage.clear();
128
129     //  Wx::DestroyTopWindow();
130
131     GetFactory()->Reset();
132 #if(USE_WXWIDGETS)
133     Wx::ProcessPendingEvents();
134 #endif
135
136  
137     // Create user package
138     Package::Pointer p =
139       Package::New("user","internal","User defined black boxes","");
140     // Insert the user package in the factory
141     GetFactory()->InsertPackage(p);
142     // And in the list of open packages
143     mOpenPackage.push_back(p);
144     mRootPackage = p;
145
146     // Create user workspace
147     ComplexBlackBoxDescriptor::Pointer r = 
148       ComplexBlackBoxDescriptor::New("workspace"); 
149     //    mRootCBB->Reference();
150     r->SetFactory(GetFactory());
151     r->AddToAuthor("bbtk");
152     r->AddToDescription("User's workspace");
153     mOpenDefinition.push_back(CBBDefinition(r,"user"));
154     // Register it into the user package
155     p->Register(r);
156     mRootCBB = r;
157
158     //    Object::PrintObjectListInfo();
159     //  GetFactory()->CheckPackages();
160     bbtkDebugMessage("kernel",9,"<== Executer::Reset()" <<std::endl);
161   }
162   //=======================================================================
163
164
165   //=======================================================================
166   /// changes the workspace name
167   void Executer::SetWorkspaceName( const std::string& n )
168   {
169     GetUserPackage()->ChangeDescriptorName( GetWorkspace()->GetTypeName(), n );
170   }
171   //=======================================================================
172
173   //=======================================================================
174   void Executer::BeginPackage (const std::string &name)
175   {
176      bbtkDebugMessage("kernel",9,"==> Executer::BeginPackage(\""<<name<<"\")"
177                         <<std::endl);
178      Package::Pointer p;
179      try 
180       {
181          p = GetFactory()->GetPackage(name);
182       }
183     catch (Exception e)
184       {
185         p = Package::New(name,"","","");
186         GetFactory()->InsertPackage(p);
187       }
188      mOpenPackage.push_back(p);
189
190      bbtkDebugMessage("kernel",9,"<== Executer::BeginPackage(\""<<name<<"\")"
191                       <<std::endl);
192   }
193   //=======================================================================
194
195   //=======================================================================
196   void Executer::EndPackage()
197   {
198     if (mOpenPackage.size()>1) mOpenPackage.pop_back();
199   }
200   //=======================================================================
201
202   //=======================================================================
203   void Executer::Define (const std::string &name,
204                          const std::string &pack,
205                          const std::string &scriptfilename)
206   {
207     bbtkDebugMessage("kernel",9,"==> Executer::Define(\""<<name<<
208                      ","<<pack<<"\")"
209                      <<std::endl);
210
211     ComplexBlackBoxDescriptor::Pointer b 
212       = ComplexBlackBoxDescriptor::New(name);
213     b->SetFactory(GetFactory());
214     b->SetScriptFileName(scriptfilename);
215     mOpenDefinition.push_back( CBBDefinition( b, pack ) );
216     
217     bbtkDebugMessage("kernel",9,"<== Executer::Define(\""<<name<<
218                      ","<<pack<<"\")"
219                      <<std::endl);
220   }
221   //=======================================================================
222
223   //=======================================================================
224   /// Sets the file name to use for the current definition
225   /// (Used to set it after the Define command)
226   void Executer::SetCurrentFileName (const std::string &name )
227   {
228     mOpenDefinition.back().box->SetScriptFileName(name);
229   }
230   //=======================================================================
231
232         void Executer::SetTypeOfScript_Application ()
233         {
234                 mOpenDefinition.back().box->SetTypeOfScript_Application();
235         }
236         
237         
238         
239   //=======================================================================
240   void Executer::Clear()
241   {
242     bbtkDebugMessage("kernel",9,"==> Executer::Clear()" <<std::endl);
243     GetCurrentDescriptor()->GetPrototype()->Clear();
244     bbtkDebugMessage("kernel",9,"<== Executer::Clear()" <<std::endl);
245   }
246   //=======================================================================
247
248   //=======================================================================
249   void Executer::EndDefine ()
250   {
251     bbtkDebugMessage("kernel",9,"==> Executer::EndDefine(\""
252                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
253                      <<std::endl);
254     // Does current package exist ?
255     Package::Pointer p;
256     std::string pname(mOpenDefinition.back().package);
257     if (pname.size()>0)
258       {
259         try
260           {
261             p = GetFactory()->GetPackage(pname);
262           }
263         catch (Exception e)
264           {
265             p = Package::New(pname,"","","");
266             GetFactory()->InsertPackage(p);
267           }
268       }
269     else
270       {
271         p = mOpenPackage.back().lock();
272       }
273     // Register the descriptor in the current package
274     p->Register(GetCurrentDescriptor());
275     
276     bbtkDebugMessage("kernel",9,"<== Executer::EndDefine(\""
277                      <<GetCurrentDescriptor()->GetTypeName()<<"\")" 
278                      <<std::endl);
279     mOpenDefinition.pop_back();
280   }
281   //======================================================================= 
282
283   //=======================================================================  
284   void Executer::Kind(const std::string& kind)
285   {
286     if (kind=="ADAPTOR")
287       {
288         GetCurrentDescriptor()->AddToCategory("adaptor");
289         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::ADAPTOR);
290       }
291     else if (kind=="DEFAULT_ADAPTOR")
292       {
293         GetCurrentDescriptor()->AddToCategory("adaptor");
294         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);
295       }
296     if (kind=="GUI")
297       {
298         GetCurrentDescriptor()->AddToCategory("gui");
299         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::GUI);
300       }
301     else if (kind=="DEFAULT_GUI")
302       {
303         GetCurrentDescriptor()->AddToCategory("gui");
304         GetCurrentDescriptor()->SetKind(bbtk::BlackBoxDescriptor::DEFAULT_GUI);
305       }
306     else
307       {
308         bbtkError("Unknown box kind : '"<<kind<<"'. "
309                   <<"Valid kinds are 'ADAPTOR','DEFAULT_ADAPTOR',"
310                   <<"'GUI','DEFAULT_GUI'");
311       }
312   }
313   //=======================================================================
314
315   //=======================================================================
316   void Executer::Create ( const std::string& nodeType, 
317                           const std::string& nodeName)
318   {
319      GetCurrentDescriptor()->Add(nodeType,nodeName);
320   }
321   //=======================================================================
322
323   //=======================================================================
324   void Executer::Destroy(const std::string &boxName)
325   {
326     GetCurrentDescriptor()->Remove(boxName,true);
327   }
328   //=======================================================================
329
330   //=======================================================================
331   void Executer::Connect (const std::string &nodeFrom,
332                           const std::string &outputLabel,
333                           const std::string &nodeTo, 
334                           const std::string &inputLabel)
335   {
336     GetCurrentDescriptor()->Connect(nodeFrom, outputLabel, nodeTo, inputLabel);
337   }
338   //=======================================================================
339
340   //=======================================================================
341   void Executer::Execute (const std::string &nodeName) 
342   {
343     // if in root
344     if (GetCurrentDescriptor()==GetWorkspace()) 
345      {
346         if (!mNoExecMode) 
347         {
348            GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(nodeName)->bbExecute(true);
349         }
350      }
351      else 
352      {
353         GetCurrentDescriptor()->AddToExecutionList(nodeName) ;
354      }
355   }
356   //=======================================================================
357
358   //=======================================================================
359   void Executer::DefineInput ( const std::string &name,
360                                const std::string &box,
361                                const std::string &input,
362                                const std::string& help)
363   {
364     // If the input is defined in the Root box
365     if (GetCurrentDescriptor()==GetWorkspace()) 
366       {
367       // If the dialog mode is set to NoDialog
368       // and the user passed the name in the Inputs map 
369       // then the associated value is set to the box.input
370       // This is the way command line parameters are passed to the Root box
371          if (mDialogMode == NoDialog) 
372          {
373          // find if name is in mInputs
374             std::map<std::string,std::string>::iterator i;
375             i = mInputs.find(name);
376             if (i!=mInputs.end()) {
377                Set(box,input,(*i).second);
378             }
379          }
380         // If the dialog mode is set to TextDialog
381         // The user is prompted for the value
382         else if (mDialogMode == TextDialog) 
383         {
384            std::cout << name << "=";
385            std::string ans;
386            std::cin >> ans;
387            Set(box,input,ans);
388         }
389 #ifdef USE_WXWIDGETS
390        // If the dialog mode is set to GraphicalDialog
391        // A dialog box is pop up
392        else if (mDialogMode == GraphicalDialog) 
393        {
394           std::string mess("Enter the value of '");
395           mess += name;
396           mess += "' (";
397           mess += help;
398           mess += ")";
399           std::string title(name);
400           title += " ?";
401           std::string ans = wx2std ( wxGetTextFromUser( std2wx (mess), std2wx(title)));
402           Set(box,input,ans); 
403        }
404 #endif
405     }
406
407     GetCurrentDescriptor()->DefineInput(name,box,input,help);
408
409   }
410   //=======================================================================
411
412   //=======================================================================
413    void Executer::DefineOutput ( const std::string &name,
414                                  const std::string &box,
415                                  const std::string &output,
416                                  const std::string& help)
417   {
418     GetCurrentDescriptor()->DefineOutput(name,box,output,help);
419   }
420   //=======================================================================
421
422   //=======================================================================
423   void Executer::Set (const std::string &box,
424                       const std::string &input,
425                       const std::string &value)
426   {
427     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
428     // Looks for the adaptor
429
430     if ( ( b->bbGetInputType(input) != typeid(bbtk::any<bbtk::thing>) )&&
431          ( b->bbGetInputType(input) != typeid(std::string) ) )
432       {
433         BlackBox::Pointer a =
434            GetFactory()->NewAdaptor(typeid(std::string),
435                                     b->bbGetInputType(input),
436                                     "tmp");
437          if (!a) 
438            {
439              bbtkError("No <"<<
440                        TypeName(b->bbGetInputType(input))
441                        <<"> to <std::string> found");
442            }
443          std::string v(value);
444          a->bbSetInput("In",v);
445          a->bbExecute();
446          b->bbSetInput(input,a->bbGetOutput("Out"));
447          //         a->Delete();
448       }
449     else 
450       {
451       std::string v(value);
452       b->bbSetInput(input,v);
453       }
454   }
455   //=======================================================================
456
457   //=======================================================================
458   std::string Executer::Get(const std::string &box,
459                             const std::string &output)
460   {
461     BlackBox::Pointer b = GetCurrentDescriptor()->GetPrototype()->bbGetBlackBox(box);
462     // Looks for the adaptor
463     if (b->bbGetOutputType(output) != typeid(std::string)) 
464       {
465         BlackBox::Pointer a =
466           GetFactory()->NewAdaptor(
467                                    b->bbGetOutputType(output),
468                                    typeid(std::string),
469                                    "tmp");
470         if (!a) 
471           {
472             bbtkError("No <"<<
473                       TypeName(b->bbGetOutputType(output))
474                       <<"> to <std::string> found");
475           }
476         b->bbExecute();
477         
478         a->bbSetInput("In",b->bbGetOutput(output));
479         a->bbExecute();
480         std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
481         //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
482         //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
483         //             << std::endl;
484         //std::string v(value);
485         //b->bbSetInput(input,a->bbGetOutput("Out"));
486         //        a->bbDelete();
487         return r;
488       }
489     else
490       {
491         b->bbExecute();
492         return b->bbGetOutput(output).unsafe_get<std::string>();
493         // std::string v = *((std::string*)b->bbGetOutput(output)) ;
494         // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
495         //   << std::endl;
496         // b->bbSetInput(input,&v);
497       }
498   }
499   //=======================================================================
500
501   //=======================================================================
502   void Executer::Author(const std::string &authorName)
503   {
504     GetCurrentDescriptor()->AddToAuthor(authorName,GetCurrentDescriptor()==GetWorkspace());
505   }
506   //=======================================================================
507
508   //=======================================================================
509   void Executer::Category(const std::string &category)
510   {
511     GetCurrentDescriptor()->AddToCategory(category,GetCurrentDescriptor()==GetWorkspace());
512   }
513   //=======================================================================
514
515   //=======================================================================
516   void Executer::Description(const std::string &d)
517   {
518     GetCurrentDescriptor()->AddToDescription(d,GetCurrentDescriptor()==GetWorkspace());
519   }
520   //=======================================================================
521
522
523
524   //=======================================================================
525   /// prints the list of the boxes of the current descriptor
526   void Executer::PrintHelpListBoxes()
527   {
528     bbtkMessage("help",1,"The black box descriptor \""
529                 <<GetCurrentDescriptor()->GetTypeName()<<"\" contains : "<<std::endl);
530     GetCurrentDescriptor()->PrintBlackBoxes();
531  }
532   //=======================================================================
533
534   //=======================================================================
535   std::string Executer::ShowGraph(const std::string &nameblackbox, 
536                                   const std::string &detailStr, 
537                                   const std::string &levelStr,
538                                   const std::string &output_html,
539                                   const std::string &custom_header,
540                                   const std::string &custom_title,
541                                   bool system_display )
542   {
543     int detail  =       atoi(detailStr.c_str());
544     int level   =       atoi(levelStr.c_str());
545           bool relative_link = true;
546
547     Package::Pointer p;
548     try
549     {
550        p = GetFactory()->GetPackage(nameblackbox);
551     }
552     catch (Exception e)
553     {
554       p = GetUserPackage();
555     }
556           
557       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
558       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
559       doc_path += "bbdoc";
560       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
561           
562           std::string pack_name(p->GetName());
563           std::string pack_path = doc_path + pack_name;
564           // Creating directory
565           if ( ! bbtk::Utilities::FileExists(pack_path) )
566           {
567                   std::string command("mkdir \"" +pack_path+ "\"");
568                   system( command.c_str() );
569           }
570           std::string pack_index(pack_path);
571           pack_index += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
572           pack_index += "index.html"; 
573           
574           
575     // Generating documentation-help of workspace
576         p->SetDocURL(pack_index);
577     p->SetDocRelativeURL("index.html");
578         p->CreateHtmlPage(pack_index,"bbtk","user package",custom_header,custom_title,detail,level,relative_link);
579           
580     /*
581     try 
582     {
583        ShowGraphTypes(nameblackbox);
584     }
585     catch (bbtk::Exception a)
586     {
587        std::cout <<"EXC"<<std::endl;
588        page = ShowGraphInstances(nameblackbox,detail,level,system_display);
589     }
590     */
591     return pack_index;
592   }
593   //=======================================================================
594
595   //=======================================================================
596   /// Generate a png file with the actual pipeline (Graphviz-dot needed)
597   std::string Executer::ShowGraphInstances(const std::string &nameblackbox, int detail, int level,
598                                            bool system_display)
599   {
600
601     BlackBox::Pointer blackbox;
602     if (nameblackbox==".")
603     {
604        blackbox = GetCurrentDescriptor()->GetPrototype();
605     }
606     else
607     {
608        blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
609     }
610     
611     std::string page;
612
613     if (blackbox)
614       {      
615         // Don't pollute the file store with  "temp_dir" directories ...
616         std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
617         char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
618
619         std::string directory = default_doc_dir; 
620         if (c != '/' && c !='\\') directory = directory + "/";
621
622         directory = directory +  "temp_dir";
623         //std::string directory("temp_dir");
624         std::string filename(directory + "/" + "bbtk_graph_pipeline");
625         std::string filename_html(filename+".html");
626         std::string command0("mkdir \""+directory + "\"");
627
628 #if defined(_WIN32)
629         std::string command2("start ");
630 #else 
631         std::string command2("gnome-open ");
632 #endif
633
634         command2=command2+filename_html;
635         page = filename_html;
636         // 1. Generate Html Diagram
637         std::ofstream s;
638         s.open(filename_html.c_str());
639         if (s.good()) 
640           {
641             s << "<html><head><title>BBtk graph diagram</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>\n";
642             s << "<body bgcolor=\"#FFFFFF\" text=\"#000000\"> \n\n";
643             if ( blackbox->bbGetName()=="workspacePrototype" )
644               {
645                 s << "<center>Current workspace</center>";
646               } else {
647               s << "<center>" << blackbox->bbGetName()<< "</center>";
648             } 
649             blackbox->bbInsertHTMLGraph( s, detail, level, true, directory, false );
650             s << "</body></html>\n";
651           }
652         s.close();
653         
654         // 2. Starting Browser
655         if (system_display) system( command2.c_str() );      
656       } 
657     else 
658       {
659         bbtkMessage("help",1,"No black box: \""
660                     <<nameblackbox<<"\" " <<std::endl);
661       }
662     return page;
663   }
664   //=======================================================================
665
666   //=======================================================================
667   void Executer::PrintHelpBlackBox(const std::string &nameblackbox, 
668                                const std::string &detailStr, 
669                                const std::string &levelStr)
670   {
671     bool found=false;
672     
673     int detail = atoi(detailStr.c_str());
674     int level  = atoi(levelStr.c_str());
675     BlackBox::Pointer blackbox;
676     if (nameblackbox.compare(".")==0)
677       {
678         blackbox=GetCurrentDescriptor()->GetPrototype();
679       } 
680     else 
681       {
682         blackbox = GetCurrentDescriptor()->GetPrototype()->bbFindBlackBox(nameblackbox);
683       }
684     
685     if (blackbox)
686       {
687         found=true;
688         blackbox->bbPrintHelp(blackbox,detail,level); //,mFactory);
689       }
690     
691     if (!found) 
692       {
693         bbtkError("box with name '"  <<nameblackbox<<"' unknown");
694       }
695   }
696   //=======================================================================
697
698   //=======================================================================
699   /// sets the level of message
700   void Executer::SetMessageLevel(const std::string &kind,
701                                  int level)
702   {
703     bbtk::MessageManager::SetMessageLevel(kind,level);
704   }
705   //=======================================================================
706
707   //=======================================================================
708   /// Prints help on the messages
709   void  Executer::HelpMessages()
710   {
711     bbtk::MessageManager::PrintInfo();
712   }
713   //=======================================================================
714
715   //=======================================================================
716   ///
717   void Executer::Print(const std::string &str)
718   {  
719     if (GetNoExecMode() &&  (GetCurrentDescriptor()==GetWorkspace()) ) return;
720     if (GetCurrentDescriptor()!=GetWorkspace()) return;
721
722     bbtkDebugMessage("kernel",9,"Executer::Print(\""<<str<<"\")"<<std::endl);
723
724  // TO DO :
725  // InterpretLine ("load std")
726  // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande 
727  // InterpretLine("new Print _P_") 
728  // InterpretLine("connect _C_.Out _P_.In")
729  // int num = 1
730  
731
732     std::vector<std::string> chains;
733     std::string delimiters("$");
734
735     // Skip delimiters at beginning.
736     std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
737     bool is_text = true;
738     if (lastPos>0) is_text = false;
739
740     // Find first delimiter.
741     std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
742
743     while (std::string::npos != pos || std::string::npos != lastPos)
744     {
745        if (is_text) 
746        {
747           // Found a text token, add it to the vector.
748           chains.push_back(str.substr(lastPos, pos - lastPos));
749  // std::string token = str.substr(lastPos, pos - lastPos)
750  // InterpretLine("set _C_.In%num% %token%")
751  
752        }
753        else 
754        {
755
756        // is an output (between $$) : decode 
757          std::string tok,box,output;
758          tok = str.substr(lastPos, pos - lastPos);
759          Utilities::SplitAroundFirstDot(tok,box,output);
760          chains.push_back( Get(box,output) );
761
762 // InterpretLine("connect %tok% _C_.In%num%") 
763
764        }
765         // Skip delimiters.  Note the "not_of"
766        lastPos = str.find_first_not_of(delimiters, pos);
767         // Find next delimiter
768        pos = str.find_first_of(delimiters, lastPos);
769     //
770        is_text = !is_text;
771 // num ++;
772      }
773 // InterpretLine("exec _P_")
774 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
775
776     std::vector<std::string>::iterator i;
777     for (i= chains.begin(); i!=chains.end(); ++i) 
778       {
779         Utilities::SubsBackslashN(*i);
780         bbtkMessage("output",1,*i);
781       }
782     bbtkMessage("output",1,std::endl);
783   }
784   //==========================================================================
785
786   //==========================================================================
787   std::string Executer::GetObjectName() const
788   {
789     return std::string("Executer");
790   }
791   //==========================================================================
792   
793   //==========================================================================
794   std::string  Executer::GetObjectInfo() const 
795   {
796     std::stringstream i;
797     return i.str();
798   }
799   //==========================================================================
800   //==========================================================================
801 size_t  Executer::GetObjectSize() const 
802 {
803   size_t s = Superclass::GetObjectSize();
804   s += Executer::GetObjectInternalSize();
805   return s;
806   }
807   //==========================================================================
808   //==========================================================================
809 size_t  Executer::GetObjectInternalSize() const 
810 {
811   size_t s = sizeof(Executer);
812   return s;
813   }
814   //==========================================================================
815   //==========================================================================
816   size_t  Executer::GetObjectRecursiveSize() const 
817   {
818     size_t s = Superclass::GetObjectRecursiveSize();
819     s += Executer::GetObjectInternalSize();
820     s += mFactory->GetObjectRecursiveSize();
821     return s;
822   }
823   //==========================================================================
824 }//namespace