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