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