]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
b77a3c9eb6cd57e55380def5fab3ee95bba8013a
[bbtk.git] / kernel / src / bbtkExecuter.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkExecuter.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/03/07 08:40:14 $
7   Version:   $Revision: 1.10 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief class Executer: level 0 of script execution (header)
21  */
22 /**
23  *  \class bbtk::Executer 
24  *  \brief class Executer: level 0 of script execution 
25  */
26  
27 #ifndef __bbtkExecuter_h__
28 #define __bbtkExecuter_h__
29
30 #include "bbtkVirtualExec.h"
31
32 #include "bbtkSystem.h"
33 #include "bbtkComplexBlackBox.h"
34 #include "bbtkFactory.h"
35 #include <string>
36 #include <deque>
37
38 namespace bbtk
39 {
40
41   class Interpreter;
42
43
44   class /*BBTK_EXPORT*/ Executer : public VirtualExec
45   {
46
47   public:
48
49     /// Constructor
50     Executer();
51     /// Destructor
52     ~Executer();
53     
54
55     /// Gets the factory used by the executer
56     Factory* GetFactory() { return mFactory; }
57     /// Gets the factory used by the executer (const)
58     const Factory* GetFactory() const { return mFactory; }
59
60
61     /// Sets the inputs of the workspace : 
62     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
63
64     /// Puts the executer in "no exec" mode, 
65     /// which creates but does not execute pipelines 
66     void SetNoExecMode(bool b) { mNoExecMode = b; }
67
68     bool GetNoExecMode() const { return mNoExecMode; }
69
70     /// Sets the mode of dialog of the executer for Root inputs 
71     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
72
73     /// Starts a package block  
74     void BeginPackage (const std::string &name );
75
76     /// Ends a package block
77     void EndPackage ();
78
79     /// Starts the definition of a new ComplexBlackBox in package pack
80     /// scriptfilename is the file from which the def is read
81     void Define (const std::string &name,
82                  const std::string& pack,
83                  const std::string &scriptfilename);
84
85     /// Sets the file name to use for the current definition
86     /// (Used to set it after the Define command)
87     void SetCurrentFileName (const std::string &name );
88
89     /// End the definition of a ComplexBlackBox
90     void EndDefine ();
91
92     /// Creates a new black box in current complex box
93     void Create ( const std::string& boxType, const std::string& boxName);
94
95     /// Destroys a black box
96     void Destroy (const std::string &boxName);
97
98     /// Connects the output boxOutput to the input boxInput
99     void Connect (const std::string &boxfrom,
100                   const std::string &output,
101                   const std::string &boxto,
102                   const std::string &input);
103
104     /// Updates the box 
105     /// would 'Execute' be more meaningfull ?
106     void Update (const std::string &box);
107
108     /// Defines an input of the current complex box
109     void DefineInput (const std::string &name,
110                       const std::string &box,
111                       const std::string &input,
112                       const std::string &help);
113
114     /// Defines an output of the current complex box
115     void DefineOutput (const std::string &name,
116                        const std::string &box,
117                        const std::string &output,
118                        const std::string &help);     
119
120     /// sets the input of the box with the value
121     void Set (const std::string &box, 
122               const std::string &input, 
123               const std::string &value);
124
125     /// gets the output of the box
126     std::string Get (const std::string &box, 
127                      const std::string &output);
128
129     /// changes the workspace name
130     void SetWorkspaceName( const std::string& n );
131
132     ///Adds the authorName to the Box author list
133     void Author(const std::string &authorName);
134
135     ///Adds the Categories to the Box category list
136     void Category(const std::string &category);
137
138     /// The description string which explains what does the ComplexBox
139     void Description(const std::string & d);
140
141     /// prints the list off the boxes of the current box
142     void PrintBoxes();
143
144    /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
145     std::string ShowGraph(const std::string &nameblackbox, 
146                           const std::string &detailStr, 
147                           const std::string &levelStr,
148                           const std::string &output_file,
149                           const std::string &custom_header,
150                           const std::string &custom_title,
151                           bool system_display = true);
152
153    /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
154     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
155
156    /// Description of the actual pipeline
157       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
158
159       void Reset();
160
161   //  static const std::string& GetObjectDescription();
162   //  { static std::string s("Executer"); return s; }
163
164   protected:
165
166   private:
167
168     /// Gets the current working black box 
169     ComplexBlackBoxDescriptor* Current() 
170         { return mOpenDefinition.back().box; }
171     
172     /// Returns true when we are inside a define/endefine block
173     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
174
175     //==================================================================
176     // ATTRIBUTES
177      
178     /// The factory used
179     Factory* mFactory;
180     
181  
182     /// The Root Package 
183     /// Contains the root ComplexBlabkBox
184     /// In which ComplexBlackBoxes are put by default
185     /// Its name in bbi is 'user'
186     Package* mRootPackage;
187     
188     /// The root ComplexBlackBox
189     /// in which operations are done when outside a define/endefine block
190     /// Its name in bbi is 'workspace'  
191     ComplexBlackBoxDescriptor* mRootCBB;
192
193     /// Struct that stores info on user defined complex black boxes
194     struct CBBDefinition
195     {
196       ComplexBlackBoxDescriptor* box;
197       std::string package;
198       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
199         : box(d), package(p) {}
200     };
201
202     /// The stack of current working ComplexBlackBox
203     /// (is a stack for nested definitions)
204     /// only contains the root cbb when outside a define/endefine block
205     std::deque<CBBDefinition> mOpenDefinition;
206
207     /// The stack of current working package
208     /// (is a stack for nested definitions)
209     std::deque<Package*> mOpenPackage;
210
211     /// The input values of the Root ComplexBlackBox
212     std::map<std::string,std::string> mInputs;
213     
214     /// no exec mode flag
215     bool mNoExecMode;
216
217     /// Dialog mode
218     DialogModeType mDialogMode;
219   };
220 }
221 #endif