]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
#3205 BBTK Feature New Normal - branch vtk7itk4wx3-mxecc
[bbtk.git] / kernel / src / bbtkExecuter.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkExecuter.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.20 $
34 =========================================================================*/
35
36                                                                       
37
38 /**
39  *  \file 
40  *  \brief class Executer: level 0 of script execution (header)
41  */
42 /**
43  *  \class bbtk::Executer 
44  *  \brief class Executer: level 0 of script execution 
45  */
46  
47 #ifndef __bbtkExecuter_h__
48 #define __bbtkExecuter_h__
49
50 #include "bbtkFactory.h"
51
52 #include "bbtkSystem.h"
53 #include "bbtkComplexBlackBox.h"
54 #include <string>
55 #include <deque>
56
57 namespace bbtk
58 {
59
60   class Interpreter;
61
62
63   class /*BBTK_EXPORT*/ Executer : public VirtualExec
64   {
65     BBTK_OBJECT_INTERFACE(Executer);
66     typedef VirtualExec Superclass;
67   public:
68     static Pointer New();
69     
70
71     /// Gets the factory used by the executer
72     Factory::Pointer GetFactory() { return mFactory; }
73     /// Gets the factory used by the executer (const)
74     //    const Factory::Pointer GetFactory() const { return mFactory; }
75
76
77     /// Sets the inputs of the workspace : 
78     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
79
80     /// Puts the executer in "no exec" mode, 
81     /// which creates but does not execute pipelines 
82     void SetNoExecMode(bool b) { mNoExecMode = b; }
83
84     bool GetNoExecMode() const { return mNoExecMode; }
85
86     /// Sets the mode of dialog of the executer for Root inputs 
87     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
88
89     void SetNoErrorMode(bool b) { mNoErrorMode = b; }
90
91     bool GetNoErrorMode() const { return mNoErrorMode; }
92
93
94     //=================================================================
95     /// Loads a package
96     void LoadPackage(const std::string &name );
97
98     /// Unloads a package
99     void UnLoadPackage(const std::string &name );
100
101     /// Starts a package block  
102     void BeginPackage (const std::string &name );
103
104     /// Ends a package block
105     void EndPackage ();
106
107     /// Starts the definition of a new ComplexBlackBox in package pack
108     /// scriptfilename is the file from which the def is read
109     void Define (const std::string &name,
110                  const std::string& pack,
111                  const std::string &scriptfilename);
112
113     /// Sets the file name to use for the current definition
114     /// (Used to set it after the Define command)
115     void SetCurrentFileName (const std::string &name );
116
117         //Set type of script
118         void SetTypeOfScript_Application();
119  
120           
121           
122     /// End the definition of a ComplexBlackBox
123     void EndDefine ();
124
125     /// Sets the kind of the currently defined ComplexBlackBox
126     void Kind(const std::string& kind);
127
128     /// Creates a new black box in current complex box
129     void Create ( const std::string& boxType, const std::string& boxName);
130
131     /// Destroys a black box
132     void Destroy (const std::string &boxName);
133
134     /// Clears the currently defined ComplexBlackBox
135     void Clear();
136
137     /// Connects the output boxOutput to the input boxInput
138     void Connect (const std::string &boxfrom,
139                   const std::string &output,
140                   const std::string &boxto,
141                   const std::string &input);
142
143     /// Executes the box 
144     void Execute (const std::string &box);
145
146     /// Defines an input of the current complex box
147     void DefineInput (const std::string &name,
148                       const std::string &box,
149                       const std::string &input,
150                       const std::string &help);
151
152     /// Defines an output of the current complex box
153     void DefineOutput (const std::string &name,
154                        const std::string &box,
155                        const std::string &output,
156                        const std::string &help);     
157
158     /// sets the input of the box with the value
159     void Set (const std::string &box, 
160               const std::string &input, 
161               const std::string &value);
162
163     /// gets the output of the box
164     std::string Get (const std::string &box, 
165                      const std::string &output);
166
167     /// changes the workspace name
168     void SetWorkspaceName( const std::string& n );
169
170     ///Adds the authorName to the Box author list
171     void Author(const std::string &authorName);
172
173     ///Adds the Categories to the Box category list
174     void Category(const std::string &category);
175
176     /// The description string which explains what does the ComplexBox
177     void Description(const std::string & d);
178
179
180
181
182
183
184     /// prints the list off the boxes of the current box
185     void PrintHelpListBoxes();
186
187    /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
188     std::string ShowGraph(const std::string &nameblackbox, 
189                           const std::string &detailStr, 
190                           const std::string &levelStr,
191                           const std::string &output_file,
192                           const std::string &custom_header,
193                           const std::string &custom_title,
194                           bool system_display = true);
195
196     /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
197     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
198     
199     /// Prints help on a black box
200     void PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
201     
202
203
204
205
206
207     /// Resets the workspace : destroys all boxes / unloads all packages
208     void Reset();
209
210     /// Sets the level of message for kind
211     void SetMessageLevel(const std::string &kind,
212                          int level);
213
214    /// Prints help on the messages
215     void HelpMessages();
216     
217
218     void Print(const std::string & message);
219
220   //  static const std::string& GetObjectDescription();
221   //  { static std::string s("Executer"); return s; }
222
223
224     ComplexBlackBoxDescriptor::Pointer GetWorkspace() 
225     { return mRootCBB.lock(); }
226     Package::Pointer GetUserPackage() 
227     { return mRootPackage.lock(); }
228
229     /// Gets the current working black box 
230     ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor() 
231     { return mOpenDefinition.back().box; }
232     
233
234   protected:
235
236   private:
237
238     
239     /// Returns true when we are inside a define/endefine block
240     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
241
242     //==================================================================
243     // ATTRIBUTES
244      
245     /// The factory used
246     Factory::Pointer mFactory;
247     
248  
249     /// The Root Package 
250     /// Contains the root ComplexBlabkBox
251     /// In which ComplexBlackBoxes are put by default
252     /// Its name in bbi is 'user'
253     Package::WeakPointer mRootPackage;
254     
255     /// The root ComplexBlackBox
256     /// in which operations are done when outside a define/endefine block
257     /// Its name in bbi is 'workspace'  
258     ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
259
260     /// Struct that stores info on user defined complex black boxes
261     struct CBBDefinition
262     {
263       ComplexBlackBoxDescriptor::Pointer box;
264       std::string package;
265       CBBDefinition(ComplexBlackBoxDescriptor::Pointer d, 
266                     const std::string& p )
267         : box(d), package(p) {}
268     };
269
270     /// The stack of current working ComplexBlackBox
271     /// (is a stack for nested definitions)
272     /// only contains the root cbb when outside a define/endefine block
273     std::deque<CBBDefinition> mOpenDefinition;
274
275     /// The stack of current working package
276     /// (is a stack for nested definitions)
277     std::deque<Package::WeakPointer> mOpenPackage;
278
279     /// The input values of the Root ComplexBlackBox
280     std::map<std::string,std::string> mInputs;
281     
282     /// no exec mode flag
283     bool mNoExecMode;
284
285
286     /// Dialog mode
287     DialogModeType mDialogMode;
288
289     /// no error mode flag
290     bool mNoErrorMode;
291
292   };
293 }
294 #endif