]> Creatis software - bbtk.git/blob - kernel/src/bbtkVirtualExec.h
e736f9e8c7a8cf40c29f6b6f411f3054046b9b6d
[bbtk.git] / kernel / src / bbtkVirtualExec.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkVirtualExec.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/04/08 06:59:30 $
7   Version:   $Revision: 1.11 $
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 VirtualExec: level 0 of script execution (header)
21  */
22 /**
23  *  \class bbtk::VirtualExec 
24  *  \brief class VirtualExec: level 0 of script execution 
25  */
26   
27 #ifndef __bbtkVirtualExec_h__
28 #define __bbtkVirtualExec_h__
29
30 #include "bbtkSystem.h"
31 //#include "bbtkComplexBlackBox.h"
32 #include "bbtkFactory.h"
33 //#include <string>
34 //#include <deque>
35
36 namespace bbtk
37 {
38
39   class Interpreter;
40
41   class /*BBTK_EXPORT*/ VirtualExec   // All methods are pure virtual
42   {
43
44   public:
45     typedef enum
46     {
47        NoDialog,
48        TextDialog,
49        GraphicalDialog
50     }
51     DialogModeType;
52
53     VirtualExec() : mInterpreter(0) {}
54
55     virtual ~VirtualExec() {}
56
57     /// Sets the interpreter who uses it 
58     void SetInterpreter(Interpreter* i) { mInterpreter = i; }
59     /// Gets the interpreter who uses it 
60     Interpreter* GetInterpreter() { return mInterpreter; }
61     /// Gets the interpreter who uses it (const)
62     const Interpreter* GetInterpreter() const { return mInterpreter; }
63
64     /// Gets the factory used by the executer
65     virtual Factory* GetFactory() { return 0; }
66     /// Gets the factory used by the executer (const)
67     virtual const Factory* GetFactory() const { return 0; }
68     
69     /// Sets the inputs of the workspace : 
70     virtual void SetInputs(const std::map<std::string,std::string>& m) = 0;
71
72     /// Puts the executer in "no exec" mode, 
73     /// which creates but does not execute pipelines 
74     virtual void SetNoExecMode(bool b) = 0;
75
76     virtual bool GetNoExecMode() const = 0;
77
78     /// Sets the mode of dialog of the executer for Root inputs 
79     virtual void SetDialogMode(DialogModeType t) = 0;
80
81     //=================================================================
82    /// Loads a package
83     virtual void LoadPackage(const std::string &name ) = 0;
84
85     /// Unloads a package
86     virtual void UnLoadPackage(const std::string &name ) = 0;
87
88     /// Starts a package block  
89     virtual void BeginPackage (const std::string &name ) = 0;
90
91     /// Ends a package block
92     virtual void EndPackage () = 0;
93
94     /// Starts the definition of a new ComplexBlackBox in package pack
95     /// scriptfilename is the file from which the def is read
96     virtual void Define (const std::string &name,
97                  const std::string& pack,
98                  const std::string &scriptfilename) = 0;
99  
100     /// Sets the file name to use for the current definition
101     /// (Used to set it after the Define command)
102     virtual void SetCurrentFileName (const std::string &name ) = 0;
103
104     /// End the definition of a ComplexBlackBox
105     virtual void EndDefine () = 0;
106
107     /// Sets the kind of the currently defined ComplexBlackBox
108     virtual void Kind(const std::string& kind) = 0;
109
110     /// Creates a new black box in current complex box
111     virtual void Create ( const std::string& boxType, const std::string&
112     boxName) = 0;
113
114     /// Destroys a black box
115     virtual void Destroy (const std::string &boxName) = 0;
116
117     /// Connects the output boxOutput to the input boxInput
118     virtual void Connect (const std::string &boxfrom,
119                   const std::string &output,
120                   const std::string &boxto,
121                   const std::string &input) = 0;
122
123     /// Executes the box 
124     virtual void Execute (const std::string &box) = 0;
125
126     /// Defines an input of the current complex box
127     virtual void DefineInput (const std::string &name,
128                       const std::string &box,
129                       const std::string &input,
130                       const std::string &help) = 0;
131
132     /// Defines an output of the current complex box
133     virtual void DefineOutput (const std::string &name,
134                        const std::string &box,
135                        const std::string &output,
136                        const std::string &help) = 0;     
137   
138     /// sets the input of the box with the value
139     virtual void Set (const std::string &box, 
140               const std::string &input, 
141               const std::string &value) = 0;
142
143     /// gets the output of the box
144     virtual std::string Get (const std::string &box, 
145                      const std::string &output) = 0;
146
147     /// changes the workspace name
148     virtual void SetWorkspaceName( const std::string& n ) = 0;
149
150     ///Adds the authorName to the Box author list
151     virtual void Author(const std::string &authorName) = 0;
152
153     ///Adds the categories to the Box categoris list
154     virtual void Category(const std::string &categories) = 0;
155
156     /// The description string which explains what does the ComplexBox
157     virtual void Description(const std::string &d) = 0;
158
159     /// prints the list off the boxes of the current box
160     virtual void PrintBoxes() = 0;
161
162    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
163     virtual std::string ShowGraph(const std::string &nameblackbox, 
164                           const std::string &detailStr, 
165                           const std::string &levelStr,
166                           const std::string &output_file,
167                           const std::string &custom_header,
168                           const std::string &custom_title,
169                           bool system_display = true) = 0;
170
171    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
172     virtual std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true) = 0;
173
174     /// Description of the actual pipeline
175     virtual void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr) = 0;
176     
177     virtual void Reset() = 0;
178     
179     /// Sets the level of message for kind
180     virtual void SetMessageLevel(const std::string &kind, int level) = 0,;
181     
182     /// Prints help on the messages
183     virtual void HelpMessages() = 0;
184
185     /// Prints the string ... MORE : TO EXPLAIN 
186     virtual void Print(const std::string & message) = 0;
187
188     
189   //  static const std::string& GetObjectDescription() = 0;
190   //  { static std::string s("VirtualExec"); return s; }
191   protected:
192
193   private:
194
195    /// The interpreter which uses it (0 if none)
196     Interpreter* mInterpreter;
197     /*
198     /// Gets the current working black box 
199     virtual ComplexBlackBoxDescriptor* Current() = 0;
200     
201     /// Returns true when we are inside a define/endefine block
202     //    virtual bool InDefinitionBlock() = 0;
203
204     //==================================================================
205     // ATTRIBUTES
206      
207     /// The factory used
208     //   Factory* mFactory;
209
210     /// The Root Package
211     Package* mPackage;
212     
213     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
214     /// Its name in bbi is 'workspace'  
215     ComplexBlackBoxDescriptor* mRoot;
216
217     /// Struct that stores info on user defined complex black boxes
218     struct CBBDefinition
219     {
220       ComplexBlackBoxDescriptor* box;
221       std::string package;
222       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
223         : box(d), package(p) {}
224     };
225
226     /// The stack of current working ComplexBlackBox
227     /// (is a stack for nested definitions)
228     /// only contains the root when outside a define/endefine block
229     std::deque<CBBDefinition> mOpenDefinition;
230
231    /// The stack of current working package
232     /// (is a stack for nested definitions)
233     std::deque<Package*> mOpenPackage;
234
235     /// flag which is true when we are inside a Define/EndDefine block
236     //    bool mDefineFlag;
237     
238     /// The input values of the Root ComplexBlackBox
239     std::map<std::string,std::string> mInputs;
240     
241     /// no exec mode flag
242     bool mNoExecMode;
243
244     /// Dialog mode
245     DialogModeType mDialogMode;
246     */
247   };
248 }
249 #endif