]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
fc177e254bccff63993aab000714051de0cebccc
[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/22 09:40:10 $
7   Version:   $Revision: 1.14 $
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
71
72     //=================================================================
73     /// Loads a package
74     void LoadPackage(const std::string &name );
75
76     /// Unloads a package
77     void UnLoadPackage(const std::string &name );
78
79     /// Starts a package block  
80     void BeginPackage (const std::string &name );
81
82     /// Ends a package block
83     void EndPackage ();
84
85     /// Starts the definition of a new ComplexBlackBox in package pack
86     /// scriptfilename is the file from which the def is read
87     void Define (const std::string &name,
88                  const std::string& pack,
89                  const std::string &scriptfilename);
90
91     /// Sets the file name to use for the current definition
92     /// (Used to set it after the Define command)
93     void SetCurrentFileName (const std::string &name );
94
95     /// End the definition of a ComplexBlackBox
96     void EndDefine ();
97
98     /// Sets the kind of the currently defined ComplexBlackBox
99     void Kind(const std::string& kind);
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
184     ComplexBlackBoxDescriptor::Pointer GetWorkspace() 
185     { return mRootCBB.lock(); }
186     Package::Pointer GetUserPackage() 
187     { return mRootPackage.lock(); }
188
189     /// Gets the current working black box 
190     ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor() 
191     { return mOpenDefinition.back().box; }
192     
193
194   protected:
195
196   private:
197
198     
199     /// Returns true when we are inside a define/endefine block
200     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
201
202     //==================================================================
203     // ATTRIBUTES
204      
205     /// The factory used
206     Factory::Pointer mFactory;
207     
208  
209     /// The Root Package 
210     /// Contains the root ComplexBlabkBox
211     /// In which ComplexBlackBoxes are put by default
212     /// Its name in bbi is 'user'
213     Package::WeakPointer mRootPackage;
214     
215     /// The root ComplexBlackBox
216     /// in which operations are done when outside a define/endefine block
217     /// Its name in bbi is 'workspace'  
218     ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
219
220     /// Struct that stores info on user defined complex black boxes
221     struct CBBDefinition
222     {
223       ComplexBlackBoxDescriptor::Pointer box;
224       std::string package;
225       CBBDefinition(ComplexBlackBoxDescriptor::Pointer d, 
226                     const std::string& p )
227         : box(d), package(p) {}
228     };
229
230     /// The stack of current working ComplexBlackBox
231     /// (is a stack for nested definitions)
232     /// only contains the root cbb when outside a define/endefine block
233     std::deque<CBBDefinition> mOpenDefinition;
234
235     /// The stack of current working package
236     /// (is a stack for nested definitions)
237     std::deque<Package::WeakPointer> mOpenPackage;
238
239     /// The input values of the Root ComplexBlackBox
240     std::map<std::string,std::string> mInputs;
241     
242     /// no exec mode flag
243     bool mNoExecMode;
244
245     /// Dialog mode
246     DialogModeType mDialogMode;
247   };
248 }
249 #endif