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