]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
Some indentation
[bbtk.git] / kernel / src / bbtkExecuter.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkExecuter.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/02/14 20:26:54 $
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 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     /// Constructor
47     Executer();
48
49     ///
50     //  void SetFactory(Factory* f);
51
52     /// Destructor
53     ~Executer();
54     
55     /// Sets the inputs of the workspace : 
56     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
57
58     /// Puts the executer in "no exec" mode, 
59     /// which creates but does not execute pipelines 
60     void SetNoExecMode(bool b) { mNoExecMode = b; }
61
62     bool GetNoExecMode() const { return mNoExecMode; }
63
64     /// Sets the mode of dialog of the executer for Root inputs 
65     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
66
67     /// Starts a package block  
68     void BeginPackage (const std::string &name );
69
70     /// Ends a package block
71     void EndPackage ();
72
73     /// Starts the definition of a new ComplexBlackBox in package pack
74     /// scriptfilename is the file from which the def is read
75     void Define (const std::string &name,
76                  const std::string& pack,
77                  const std::string &scriptfilename);
78
79     /// Sets the file name to use for the current definition
80     /// (Used to set it after the Define command)
81     void SetCurrentFileName (const std::string &name );
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 author list
127     void Author(const std::string &authorName);
128
129     ///Adds the Categories to the Box category list
130     void Category(const std::string &category);
131
132     /// The description string which explains what does the ComplexBox
133     void Description(const std::string & d);
134
135     /// prints the list off the boxes of the current box
136     void PrintBoxes();
137
138    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
139     std::string ShowGraph(const std::string &nameblackbox, 
140                           const std::string &detailStr, 
141                           const std::string &levelStr,
142                           const std::string &output_file,
143                           const std::string &custom_header,
144                           const std::string &custom_title,
145                           bool system_display = true);
146
147    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
148     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
149
150    /// Description of the actual pipeline
151       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
152
153       void Reset();
154
155   //  static const std::string& GetObjectDescription();
156   //  { static std::string s("Executer"); return s; }
157
158   protected:
159
160   private:
161
162     /// Gets the current working black box 
163     ComplexBlackBoxDescriptor* Current() 
164         { return mOpenDefinition.back().box; }
165     
166     /// Returns true when we are inside a define/endefine block
167     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
168
169     //==================================================================
170     // ATTRIBUTES
171      
172     /// The factory used
173     //   Factory* mFactory;
174
175     /// The Root Package
176     Package* mPackage;
177     
178     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
179     /// Its name in bbi is 'workspace'  
180     ComplexBlackBoxDescriptor* mRoot;
181
182     /// Struct that stores info on user defined complex black boxes
183     struct CBBDefinition
184     {
185       ComplexBlackBoxDescriptor* box;
186       std::string package;
187       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
188         : box(d), package(p) {}
189     };
190
191     /// The stack of current working ComplexBlackBox
192     /// (is a stack for nested definitions)
193     /// only contains the root when outside a define/endefine block
194     std::deque<CBBDefinition> mOpenDefinition;
195
196     /// The stack of current working package
197     /// (is a stack for nested definitions)
198     std::deque<Package*> mOpenPackage;
199
200     /// flag which is true when we are inside a Define/EndDefine block
201     //    bool mDefineFlag;
202     
203     /// The input values of the Root ComplexBlackBox
204     std::map<std::string,std::string> mInputs;
205     
206     /// no exec mode flag
207     bool mNoExecMode;
208
209     /// Dialog mode
210     DialogModeType mDialogMode;
211   };
212 }
213 #endif