]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
Fixed :
[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/26 08:27:19 $
7   Version:   $Revision: 1.11 $
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
74
75     //=================================================================
76     /// Loads a package
77     void LoadPackage(const std::string &name );
78
79     /// Unloads a package
80     void UnLoadPackage(const std::string &name );
81
82     /// Starts a package block  
83     void BeginPackage (const std::string &name );
84
85     /// Ends a package block
86     void EndPackage ();
87
88     /// Starts the definition of a new ComplexBlackBox in package pack
89     /// scriptfilename is the file from which the def is read
90     void Define (const std::string &name,
91                  const std::string& pack,
92                  const std::string &scriptfilename);
93
94     /// Sets the file name to use for the current definition
95     /// (Used to set it after the Define command)
96     void SetCurrentFileName (const std::string &name );
97
98     /// End the definition of a ComplexBlackBox
99     void EndDefine ();
100
101     /// Creates a new black box in current complex box
102     void Create ( const std::string& boxType, const std::string& boxName);
103
104     /// Destroys a black box
105     void Destroy (const std::string &boxName);
106
107     /// Connects the output boxOutput to the input boxInput
108     void Connect (const std::string &boxfrom,
109                   const std::string &output,
110                   const std::string &boxto,
111                   const std::string &input);
112
113     /// Executes the box 
114     void Execute (const std::string &box);
115
116     /// Defines an input of the current complex box
117     void DefineInput (const std::string &name,
118                       const std::string &box,
119                       const std::string &input,
120                       const std::string &help);
121
122     /// Defines an output of the current complex box
123     void DefineOutput (const std::string &name,
124                        const std::string &box,
125                        const std::string &output,
126                        const std::string &help);     
127
128     /// sets the input of the box with the value
129     void Set (const std::string &box, 
130               const std::string &input, 
131               const std::string &value);
132
133     /// gets the output of the box
134     std::string Get (const std::string &box, 
135                      const std::string &output);
136
137     /// changes the workspace name
138     void SetWorkspaceName( const std::string& n );
139
140     ///Adds the authorName to the Box author list
141     void Author(const std::string &authorName);
142
143     ///Adds the Categories to the Box category list
144     void Category(const std::string &category);
145
146     /// The description string which explains what does the ComplexBox
147     void Description(const std::string & d);
148
149     /// prints the list off the boxes of the current box
150     void PrintBoxes();
151
152    /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
153     std::string ShowGraph(const std::string &nameblackbox, 
154                           const std::string &detailStr, 
155                           const std::string &levelStr,
156                           const std::string &output_file,
157                           const std::string &custom_header,
158                           const std::string &custom_title,
159                           bool system_display = true);
160
161     /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
162     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
163     
164     /// Description of the actual pipeline
165     void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
166     
167     /// Resets the workspace : destroys all boxes / unloads all packages
168     void Reset();
169
170     /// Sets the level of message for kind
171     void SetMessageLevel(const std::string &kind,
172                          int level);
173
174    /// Prints help on the messages
175     void HelpMessages();
176     
177
178     void Print(const std::string & message);
179
180   //  static const std::string& GetObjectDescription();
181   //  { static std::string s("Executer"); return s; }
182
183   protected:
184
185   private:
186
187     /// Gets the current working black box 
188     ComplexBlackBoxDescriptor* Current() 
189         { return mOpenDefinition.back().box; }
190     
191     /// Returns true when we are inside a define/endefine block
192     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
193
194     //==================================================================
195     // ATTRIBUTES
196      
197     /// The factory used
198     Factory* mFactory;
199     
200  
201     /// The Root Package 
202     /// Contains the root ComplexBlabkBox
203     /// In which ComplexBlackBoxes are put by default
204     /// Its name in bbi is 'user'
205     Package* mRootPackage;
206     
207     /// The root ComplexBlackBox
208     /// in which operations are done when outside a define/endefine block
209     /// Its name in bbi is 'workspace'  
210     ComplexBlackBoxDescriptor* mRootCBB;
211
212     /// Struct that stores info on user defined complex black boxes
213     struct CBBDefinition
214     {
215       ComplexBlackBoxDescriptor* box;
216       std::string package;
217       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
218         : box(d), package(p) {}
219     };
220
221     /// The stack of current working ComplexBlackBox
222     /// (is a stack for nested definitions)
223     /// only contains the root cbb when outside a define/endefine block
224     std::deque<CBBDefinition> mOpenDefinition;
225
226     /// The stack of current working package
227     /// (is a stack for nested definitions)
228     std::deque<Package*> mOpenPackage;
229
230     /// The input values of the Root ComplexBlackBox
231     std::map<std::string,std::string> mInputs;
232     
233     /// no exec mode flag
234     bool mNoExecMode;
235
236     /// Dialog mode
237     DialogModeType mDialogMode;
238   };
239 }
240 #endif