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