]> Creatis software - bbtk.git/blob - kernel/src/bbtkVirtualExec.h
42217a7a1c88b3c53f7fa39121b34da6ab76891c
[bbtk.git] / kernel / src / bbtkVirtualExec.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkVirtualExec.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/01/30 09:28:16 $
7   Version:   $Revision: 1.4 $
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 /*BBTK_EXPORT*/ VirtualExec   // All methods are pure virtual
40   {
41
42   public:
43     typedef enum 
44     {
45        NoDialog,
46        TextDialog,
47        GraphicalDialog
48     }
49     DialogModeType;
50     
51 /*
52     /// Constructor
53     VirtualExec();
54
55     /// 
56     //  void SetFactory(Factory* f);
57       
58     /// Destructor
59     virtual ~VirtualExec() = 0;
60 */    
61     /// Sets the inputs of the workspace : 
62     virtual void SetInputs(const std::map<std::string,std::string>& m) = 0;
63
64     /// Puts the executer in "no exec" mode, 
65     /// which creates but does not execute pipelines 
66     virtual void SetNoExecMode(bool b) = 0;
67
68     virtual bool GetNoExecMode() const = 0;
69
70     /// Sets the mode of dialog of the executer for Root inputs 
71     virtual void SetDialogMode(DialogModeType t) = 0;
72
73     /// Starts a package block  
74     virtual void BeginPackage (const std::string &name ) = 0;
75
76     /// Ends a package block
77     virtual void EndPackage () = 0;
78
79     /// Starts the definition of a new ComplexBlackBox in package pack
80     /// scriptfilename is the file from which the def is read
81     virtual void Define (const std::string &name,
82                  const std::string& pack,
83                  const std::string &scriptfilename) = 0;
84
85     /// End the definition of a ComplexBlackBox
86     virtual void EndDefine () = 0;
87
88     /// Creates a new black box in current complex box
89     virtual void Create ( const std::string& boxType, const std::string&
90     boxName) = 0;
91
92     /// Destroys a black box
93     //virtual void Destroy (const std::string &boxName) = 0;
94
95     /// Connects the output boxOutput to the input boxInput
96     virtual void Connect (const std::string &boxfrom,
97                   const std::string &output,
98                   const std::string &boxto,
99                   const std::string &input) = 0;
100
101     /// Updates the box 
102     /// would 'Execute' be more meaningfull ?
103     virtual void Update (const std::string &box) = 0;
104
105     /// Defines an input of the current complex box
106     virtual void DefineInput (const std::string &name,
107                       const std::string &box,
108                       const std::string &input,
109                       const std::string &help) = 0;
110
111     /// Defines an output of the current complex box
112     virtual void DefineOutput (const std::string &name,
113                        const std::string &box,
114                        const std::string &output,
115                        const std::string &help) = 0;     
116   
117     /// sets the input of the box with the value
118     virtual void Set (const std::string &box, 
119               const std::string &input, 
120               const std::string &value) = 0;
121
122    /// gets the output of the box
123     virtual std::string Get (const std::string &box, 
124                      const std::string &output) = 0;
125
126     /// changes the workspace name
127     virtual void SetWorkspaceName( const std::string& n ) = 0;
128
129     ///Adds the authorName to the Box author list
130     virtual void Author(const std::string &authorName) = 0;
131
132     ///Adds the keywords to the Box keywords list
133     virtual void Keyword(const std::string &keywords) = 0;
134
135     /// The description string which explains what does the ComplexBox
136     virtual void Description(const std::string &d) = 0;
137
138     /// prints the list off the boxes of the current box
139     virtual void PrintBoxes() = 0;
140
141    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
142     virtual std::string ShowGraph(const std::string &nameblackbox, 
143                           const std::string &detailStr, 
144                           const std::string &levelStr,
145                           const std::string &output_file,
146                           const std::string &custom_header,
147                           const std::string &custom_title,
148                           bool system_display = true) = 0;
149
150         /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
151     virtual std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true) = 0;
152
153 /// Description of the actual pipeline
154         virtual void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr) = 0;
155
156         virtual void Reset() = 0;
157 /*
158   //  static const std::string& GetObjectDescription() = 0;
159   //  { static std::string s("VirtualExec"); return s; }
160 */
161   protected:
162
163   private:
164
165     /// Gets the current working black box 
166     virtual ComplexBlackBoxDescriptor* Current() = 0;
167     
168     /// Returns true when we are inside a define/endefine block
169     //    virtual bool InDefinitionBlock() = 0;
170
171     //==================================================================
172     // ATTRIBUTES
173      
174     /// The factory used
175     //   Factory* mFactory;
176
177     /// The Root Package
178     Package* mPackage;
179     
180     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
181     /// Its name in bbi is 'workspace'  
182     ComplexBlackBoxDescriptor* mRoot;
183     
184     /// Struct that stores info on user defined complex black boxes
185     struct CBBDefinition
186     {
187       ComplexBlackBoxDescriptor* box;
188       std::string package;
189       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
190         : box(d), package(p) {}
191     };
192
193     /// The stack of current working ComplexBlackBox
194     /// (is a stack for nested definitions)
195     /// only contains the root when outside a define/endefine block
196     std::deque<CBBDefinition> mCurrent;
197
198     /// flag which is true when we are inside a Define/EndDefine block
199     //    bool mDefineFlag;
200     
201     /// The input values of the Root ComplexBlackBox
202     std::map<std::string,std::string> mInputs;
203     
204     /// no exec mode flag
205     bool mNoExecMode;
206
207     /// Dialog mode
208     DialogModeType mDialogMode;
209   };
210 }
211 #endif