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