]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
No longer 'Categories', only 'Kinds'!
[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/05 11:07:42 $
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 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     /// End the definition of a ComplexBlackBox
80     void EndDefine ();
81
82     /// Creates a new black box in current complex box
83     void Create ( const std::string& boxType, const std::string& boxName);
84
85     /// Destroys a black box
86     void Destroy (const std::string &boxName);
87
88     /// Connects the output boxOutput to the input boxInput
89     void Connect (const std::string &boxfrom,
90                   const std::string &output,
91                   const std::string &boxto,
92                   const std::string &input);
93
94     /// Updates the box 
95     /// would 'Execute' be more meaningfull ?
96     void Update (const std::string &box);
97
98     /// Defines an input of the current complex box
99     void DefineInput (const std::string &name,
100                       const std::string &box,
101                       const std::string &input,
102                       const std::string &help);
103
104     /// Defines an output of the current complex box
105     void DefineOutput (const std::string &name,
106                        const std::string &box,
107                        const std::string &output,
108                        const std::string &help);     
109   
110     /// sets the input of the box with the value
111     void Set (const std::string &box, 
112               const std::string &input, 
113               const std::string &value);
114
115     /// gets the output of the box
116     std::string Get (const std::string &box, 
117                      const std::string &output);
118
119     /// changes the workspace name
120     void SetWorkspaceName( const std::string& n );
121
122     ///Adds the authorName to the Box author list
123     void Author(const std::string &authorName);
124
125     ///Adds the Keywords to the Box keyword list
126     void Keyword(const std::string &keyword);
127
128     /// The description string which explains what does the ComplexBox
129     void Description(const std::string & d);
130
131     /// prints the list off the boxes of the current box
132     void PrintBoxes();
133
134    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
135     std::string ShowGraph(const std::string &nameblackbox, 
136                           const std::string &detailStr, 
137                           const std::string &levelStr,
138                           const std::string &output_file,
139                           const std::string &custom_header,
140                           const std::string &custom_title,
141                           bool system_display = true);
142
143    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
144     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
145
146    /// Description of the actual pipeline
147       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
148
149       void Reset();
150
151   //  static const std::string& GetObjectDescription();
152   //  { static std::string s("Executer"); return s; }
153
154   protected:
155
156   private:
157
158     /// Gets the current working black box 
159     ComplexBlackBoxDescriptor* Current() 
160         { return mOpenDefinition.back().box; }
161     
162     /// Returns true when we are inside a define/endefine block
163     //    bool InDefinitionBlock() { return (mOpenDefinition.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> mOpenDefinition;
191
192     /// The stack of current working package
193     /// (is a stack for nested definitions)
194     std::deque<Package*> mOpenPackage;
195
196     /// flag which is true when we are inside a Define/EndDefine block
197     //    bool mDefineFlag;
198     
199     /// The input values of the Root ComplexBlackBox
200     std::map<std::string,std::string> mInputs;
201     
202     /// no exec mode flag
203     bool mNoExecMode;
204
205     /// Dialog mode
206     DialogModeType mDialogMode;
207   };
208 }
209 #endif