]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
Feature #1774
[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 "bbtkVirtualExec.h"
51
52 #include "bbtkSystem.h"
53 #include "bbtkComplexBlackBox.h"
54 #include "bbtkFactory.h"
55 #include <string>
56 #include <deque>
57
58 namespace bbtk
59 {
60
61   class Interpreter;
62
63
64   class /*BBTK_EXPORT*/ Executer : public VirtualExec
65   {
66     BBTK_OBJECT_INTERFACE(Executer);
67     typedef VirtualExec Superclass;
68   public:
69     static Pointer New();
70     
71
72     /// Gets the factory used by the executer
73     Factory::Pointer GetFactory() { return mFactory; }
74     /// Gets the factory used by the executer (const)
75     //    const Factory::Pointer GetFactory() const { return mFactory; }
76
77
78     /// Sets the inputs of the workspace : 
79     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
80
81     /// Puts the executer in "no exec" mode, 
82     /// which creates but does not execute pipelines 
83     void SetNoExecMode(bool b) { mNoExecMode = b; }
84
85     bool GetNoExecMode() const { return mNoExecMode; }
86
87     /// Sets the mode of dialog of the executer for Root inputs 
88     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
89
90     void SetNoErrorMode(bool b) { mNoErrorMode = b; }
91
92     bool GetNoErrorMode() const { return mNoErrorMode; }
93
94
95     //=================================================================
96     /// Loads a package
97     void LoadPackage(const std::string &name );
98
99     /// Unloads a package
100     void UnLoadPackage(const std::string &name );
101
102     /// Starts a package block  
103     void BeginPackage (const std::string &name );
104
105     /// Ends a package block
106     void EndPackage ();
107
108     /// Starts the definition of a new ComplexBlackBox in package pack
109     /// scriptfilename is the file from which the def is read
110     void Define (const std::string &name,
111                  const std::string& pack,
112                  const std::string &scriptfilename);
113
114     /// Sets the file name to use for the current definition
115     /// (Used to set it after the Define command)
116     void SetCurrentFileName (const std::string &name );
117
118         //Set type of script
119         void SetTypeOfScript_Application();
120  
121           
122           
123     /// End the definition of a ComplexBlackBox
124     void EndDefine ();
125
126     /// Sets the kind of the currently defined ComplexBlackBox
127     void Kind(const std::string& kind);
128
129     /// Creates a new black box in current complex box
130     void Create ( const std::string& boxType, const std::string& boxName);
131
132     /// Destroys a black box
133     void Destroy (const std::string &boxName);
134
135     /// Clears the currently defined ComplexBlackBox
136     void Clear();
137
138     /// Connects the output boxOutput to the input boxInput
139     void Connect (const std::string &boxfrom,
140                   const std::string &output,
141                   const std::string &boxto,
142                   const std::string &input);
143
144     /// Executes the box 
145     void Execute (const std::string &box);
146
147     /// Defines an input of the current complex box
148     void DefineInput (const std::string &name,
149                       const std::string &box,
150                       const std::string &input,
151                       const std::string &help);
152
153     /// Defines an output of the current complex box
154     void DefineOutput (const std::string &name,
155                        const std::string &box,
156                        const std::string &output,
157                        const std::string &help);     
158
159     /// sets the input of the box with the value
160     void Set (const std::string &box, 
161               const std::string &input, 
162               const std::string &value);
163
164     /// gets the output of the box
165     std::string Get (const std::string &box, 
166                      const std::string &output);
167
168     /// changes the workspace name
169     void SetWorkspaceName( const std::string& n );
170
171     ///Adds the authorName to the Box author list
172     void Author(const std::string &authorName);
173
174     ///Adds the Categories to the Box category list
175     void Category(const std::string &category);
176
177     /// The description string which explains what does the ComplexBox
178     void Description(const std::string & d);
179
180
181
182
183
184
185     /// prints the list off the boxes of the current box
186     void PrintHelpListBoxes();
187
188    /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
189     std::string ShowGraph(const std::string &nameblackbox, 
190                           const std::string &detailStr, 
191                           const std::string &levelStr,
192                           const std::string &output_file,
193                           const std::string &custom_header,
194                           const std::string &custom_title,
195                           bool system_display = true);
196
197     /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
198     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
199     
200     /// Prints help on a black box
201     void PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
202     
203
204
205
206
207
208     /// Resets the workspace : destroys all boxes / unloads all packages
209     void Reset();
210
211     /// Sets the level of message for kind
212     void SetMessageLevel(const std::string &kind,
213                          int level);
214
215    /// Prints help on the messages
216     void HelpMessages();
217     
218
219     void Print(const std::string & message);
220
221   //  static const std::string& GetObjectDescription();
222   //  { static std::string s("Executer"); return s; }
223
224
225     ComplexBlackBoxDescriptor::Pointer GetWorkspace() 
226     { return mRootCBB.lock(); }
227     Package::Pointer GetUserPackage() 
228     { return mRootPackage.lock(); }
229
230     /// Gets the current working black box 
231     ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor() 
232     { return mOpenDefinition.back().box; }
233     
234
235   protected:
236
237   private:
238
239     
240     /// Returns true when we are inside a define/endefine block
241     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
242
243     //==================================================================
244     // ATTRIBUTES
245      
246     /// The factory used
247     Factory::Pointer mFactory;
248     
249  
250     /// The Root Package 
251     /// Contains the root ComplexBlabkBox
252     /// In which ComplexBlackBoxes are put by default
253     /// Its name in bbi is 'user'
254     Package::WeakPointer mRootPackage;
255     
256     /// The root ComplexBlackBox
257     /// in which operations are done when outside a define/endefine block
258     /// Its name in bbi is 'workspace'  
259     ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
260
261     /// Struct that stores info on user defined complex black boxes
262     struct CBBDefinition
263     {
264       ComplexBlackBoxDescriptor::Pointer box;
265       std::string package;
266       CBBDefinition(ComplexBlackBoxDescriptor::Pointer d, 
267                     const std::string& p )
268         : box(d), package(p) {}
269     };
270
271     /// The stack of current working ComplexBlackBox
272     /// (is a stack for nested definitions)
273     /// only contains the root cbb when outside a define/endefine block
274     std::deque<CBBDefinition> mOpenDefinition;
275
276     /// The stack of current working package
277     /// (is a stack for nested definitions)
278     std::deque<Package::WeakPointer> mOpenPackage;
279
280     /// The input values of the Root ComplexBlackBox
281     std::map<std::string,std::string> mInputs;
282     
283     /// no exec mode flag
284     bool mNoExecMode;
285
286
287     /// Dialog mode
288     DialogModeType mDialogMode;
289
290     /// no error mode flag
291     bool mNoErrorMode;
292
293   };
294 }
295 #endif