]> 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/10/02 07:43:20 $
7   Version:   $Revision: 1.15 $
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     BBTK_OBJECT_INTERFACE(Executer);
47     typedef VirtualExec Superclass;
48   public:
49     static Pointer New();
50     
51
52     /// Gets the factory used by the executer
53     Factory::Pointer GetFactory() { return mFactory; }
54     /// Gets the factory used by the executer (const)
55     //    const Factory::Pointer GetFactory() const { return mFactory; }
56
57
58     /// Sets the inputs of the workspace : 
59     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
60
61     /// Puts the executer in "no exec" mode, 
62     /// which creates but does not execute pipelines 
63     void SetNoExecMode(bool b) { mNoExecMode = b; }
64
65     bool GetNoExecMode() const { return mNoExecMode; }
66
67     /// Sets the mode of dialog of the executer for Root inputs 
68     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
69
70     void SetNoErrorMode(bool b) { mNoErrorMode = b; }
71
72     bool GetNoErrorMode() const { return mNoErrorMode; }
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
187     ComplexBlackBoxDescriptor::Pointer GetWorkspace() 
188     { return mRootCBB.lock(); }
189     Package::Pointer GetUserPackage() 
190     { return mRootPackage.lock(); }
191
192     /// Gets the current working black box 
193     ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor() 
194     { return mOpenDefinition.back().box; }
195     
196
197   protected:
198
199   private:
200
201     
202     /// Returns true when we are inside a define/endefine block
203     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
204
205     //==================================================================
206     // ATTRIBUTES
207      
208     /// The factory used
209     Factory::Pointer mFactory;
210     
211  
212     /// The Root Package 
213     /// Contains the root ComplexBlabkBox
214     /// In which ComplexBlackBoxes are put by default
215     /// Its name in bbi is 'user'
216     Package::WeakPointer mRootPackage;
217     
218     /// The root ComplexBlackBox
219     /// in which operations are done when outside a define/endefine block
220     /// Its name in bbi is 'workspace'  
221     ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
222
223     /// Struct that stores info on user defined complex black boxes
224     struct CBBDefinition
225     {
226       ComplexBlackBoxDescriptor::Pointer box;
227       std::string package;
228       CBBDefinition(ComplexBlackBoxDescriptor::Pointer d, 
229                     const std::string& p )
230         : box(d), package(p) {}
231     };
232
233     /// The stack of current working ComplexBlackBox
234     /// (is a stack for nested definitions)
235     /// only contains the root cbb when outside a define/endefine block
236     std::deque<CBBDefinition> mOpenDefinition;
237
238     /// The stack of current working package
239     /// (is a stack for nested definitions)
240     std::deque<Package::WeakPointer> mOpenPackage;
241
242     /// The input values of the Root ComplexBlackBox
243     std::map<std::string,std::string> mInputs;
244     
245     /// no exec mode flag
246     bool mNoExecMode;
247
248
249     /// Dialog mode
250     DialogModeType mDialogMode;
251
252     /// no error mode flag
253     bool mNoErrorMode;
254
255   };
256 }
257 #endif