]> Creatis software - bbtk.git/blob - kernel/src/bbtkExecuter.h
Move some general usage methods to Utilities, to avoid dupplicate code :
[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 16:55:04 $
7   Version:   $Revision: 1.2 $
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 the definition of a new ComplexBlackBox in package pack
68     /// scriptfilename is the file from which the def is read
69     void Define (const std::string &name,
70                  const std::string& pack,
71                  const std::string &scriptfilename);
72
73     /// End the definition of a ComplexBlackBox
74     void EndDefine ();
75
76     /// Creates a new black box in current complex box
77     void Create ( const std::string& boxType, const std::string& boxName);
78
79     /// Destroys a black box
80     void Destroy (const std::string &boxName);
81
82     /// Connects the output boxOutput to the input boxInput
83     void Connect (const std::string &boxfrom,
84                   const std::string &output,
85                   const std::string &boxto,
86                   const std::string &input);
87
88     /// Updates the box 
89     /// would 'Execute' be more meaningfull ?
90     void Update (const std::string &box);
91
92     /// Defines an input of the current complex box
93     void DefineInput (const std::string &name,
94                       const std::string &box,
95                       const std::string &input,
96                       const std::string &help);
97
98     /// Defines an output of the current complex box
99     void DefineOutput (const std::string &name,
100                        const std::string &box,
101                        const std::string &output,
102                        const std::string &help);     
103   
104     /// sets the input of the box with the value
105     void Set (const std::string &box, 
106               const std::string &input, 
107               const std::string &value);
108
109     /// gets the output of the box
110     std::string Get (const std::string &box, 
111                      const std::string &output);
112
113     /// changes the workspace name
114     void SetWorkspaceName( const std::string& n );
115
116     ///Adds the authorName to the Box's author list
117     void Author(const std::string &authorName);
118
119     /// The description string which explains what does the ComplexBox
120     void Description(const std::string & d);
121
122     /// prints the list off the boxes of the current box
123     void PrintBoxes();
124
125    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
126     std::string ShowGraph(const std::string &nameblackbox, 
127                           const std::string &detailStr, 
128                           const std::string &levelStr,
129                           const std::string &output_file,
130                           const std::string &custom_header,
131                           const std::string &custom_title,
132                           bool system_display = true);
133
134    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
135     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
136
137    /// Description of the actual pipeline
138       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
139
140       void Reset();
141
142   //  static const std::string& GetObjectDescription() 
143   //  { static std::string s("Executer"); return s; }
144
145   protected:
146
147   private:
148
149     /// Gets the current working black box 
150     ComplexBlackBoxDescriptor* Current() { return mCurrent.back().box; }
151     
152     /// Returns true when we are inside a define/endefine block
153     //    bool InDefinitionBlock() { return (mCurrent.size()>1); }
154
155     //==================================================================
156     // ATTRIBUTES
157      
158     /// The factory used
159     //   Factory* mFactory;
160
161     /// The Root Package
162     Package* mPackage;
163     
164     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
165     /// Its name in bbi is 'workspace'  
166     ComplexBlackBoxDescriptor* mRoot;
167
168     /// Struct that stores info on user defined complex black boxes
169     struct CBBDefinition
170     {
171       ComplexBlackBoxDescriptor* box;
172       std::string package;
173       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
174         : box(d), package(p) {}
175     };
176
177     /// The stack of current working ComplexBlackBox
178     /// (is a stack for nested definitions)
179     /// only contains the root when outside a define/endefine block
180     std::deque<CBBDefinition> mCurrent;
181
182     /// flag which is true when we are inside a Define/EndDefine block
183     //    bool mDefineFlag;
184     
185     /// The input values of the Root ComplexBlackBox
186     std::map<std::string,std::string> mInputs;
187     
188     /// no exec mode flag
189     bool mNoExecMode;
190
191     /// Dialog mode
192     DialogModeType mDialogMode;
193   };
194 }
195 #endif