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