]> Creatis software - bbtk.git/blob - kernel/src/bbtkVirtualExec.h
928a8674708f8eb4a32b4839f147f4e51c5062cc
[bbtk.git] / kernel / src / bbtkVirtualExec.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkVirtualExec.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/03/26 14:47:36 $
7   Version:   $Revision: 1.10 $
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     /// Creates a new black box in current complex box
108     virtual void Create ( const std::string& boxType, const std::string&
109     boxName) = 0;
110
111     /// Destroys a black box
112     virtual void Destroy (const std::string &boxName) = 0;
113
114     /// Connects the output boxOutput to the input boxInput
115     virtual void Connect (const std::string &boxfrom,
116                   const std::string &output,
117                   const std::string &boxto,
118                   const std::string &input) = 0;
119
120     /// Executes the box 
121     virtual void Execute (const std::string &box) = 0;
122
123     /// Defines an input of the current complex box
124     virtual void DefineInput (const std::string &name,
125                       const std::string &box,
126                       const std::string &input,
127                       const std::string &help) = 0;
128
129     /// Defines an output of the current complex box
130     virtual void DefineOutput (const std::string &name,
131                        const std::string &box,
132                        const std::string &output,
133                        const std::string &help) = 0;     
134   
135     /// sets the input of the box with the value
136     virtual void Set (const std::string &box, 
137               const std::string &input, 
138               const std::string &value) = 0;
139
140     /// gets the output of the box
141     virtual std::string Get (const std::string &box, 
142                      const std::string &output) = 0;
143
144     /// changes the workspace name
145     virtual void SetWorkspaceName( const std::string& n ) = 0;
146
147     ///Adds the authorName to the Box author list
148     virtual void Author(const std::string &authorName) = 0;
149
150     ///Adds the categories to the Box categoris list
151     virtual void Category(const std::string &categories) = 0;
152
153     /// The description string which explains what does the ComplexBox
154     virtual void Description(const std::string &d) = 0;
155
156     /// prints the list off the boxes of the current box
157     virtual void PrintBoxes() = 0;
158
159    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
160     virtual std::string ShowGraph(const std::string &nameblackbox, 
161                           const std::string &detailStr, 
162                           const std::string &levelStr,
163                           const std::string &output_file,
164                           const std::string &custom_header,
165                           const std::string &custom_title,
166                           bool system_display = true) = 0;
167
168    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
169     virtual std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true) = 0;
170
171     /// Description of the actual pipeline
172     virtual void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr) = 0;
173     
174     virtual void Reset() = 0;
175     
176     /// Sets the level of message for kind
177     virtual void SetMessageLevel(const std::string &kind, int level) = 0,;
178     
179     /// Prints help on the messages
180     virtual void HelpMessages() = 0;
181
182     /// Prints the string ... MORE : TO EXPLAIN 
183     virtual void Print(const std::string & message) = 0;
184
185     
186   //  static const std::string& GetObjectDescription() = 0;
187   //  { static std::string s("VirtualExec"); return s; }
188   protected:
189
190   private:
191
192    /// The interpreter which uses it (0 if none)
193     Interpreter* mInterpreter;
194     /*
195     /// Gets the current working black box 
196     virtual ComplexBlackBoxDescriptor* Current() = 0;
197     
198     /// Returns true when we are inside a define/endefine block
199     //    virtual bool InDefinitionBlock() = 0;
200
201     //==================================================================
202     // ATTRIBUTES
203      
204     /// The factory used
205     //   Factory* mFactory;
206
207     /// The Root Package
208     Package* mPackage;
209     
210     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
211     /// Its name in bbi is 'workspace'  
212     ComplexBlackBoxDescriptor* mRoot;
213
214     /// Struct that stores info on user defined complex black boxes
215     struct CBBDefinition
216     {
217       ComplexBlackBoxDescriptor* box;
218       std::string package;
219       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
220         : box(d), package(p) {}
221     };
222
223     /// The stack of current working ComplexBlackBox
224     /// (is a stack for nested definitions)
225     /// only contains the root when outside a define/endefine block
226     std::deque<CBBDefinition> mOpenDefinition;
227
228    /// The stack of current working package
229     /// (is a stack for nested definitions)
230     std::deque<Package*> mOpenPackage;
231
232     /// flag which is true when we are inside a Define/EndDefine block
233     //    bool mDefineFlag;
234     
235     /// The input values of the Root ComplexBlackBox
236     std::map<std::string,std::string> mInputs;
237     
238     /// no exec mode flag
239     bool mNoExecMode;
240
241     /// Dialog mode
242     DialogModeType mDialogMode;
243     */
244   };
245 }
246 #endif