1 /*=========================================================================
4 Module: $RCSfile: bbtkExecuter.h,v $ $
6 Date: $Date: 2008/10/02 07:43:20 $
7 Version: $Revision: 1.15 $
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.
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.
17 =========================================================================*/
20 * \brief class Executer: level 0 of script execution (header)
23 * \class bbtk::Executer
24 * \brief class Executer: level 0 of script execution
27 #ifndef __bbtkExecuter_h__
28 #define __bbtkExecuter_h__
30 #include "bbtkVirtualExec.h"
32 #include "bbtkSystem.h"
33 #include "bbtkComplexBlackBox.h"
34 #include "bbtkFactory.h"
44 class /*BBTK_EXPORT*/ Executer : public VirtualExec
46 BBTK_OBJECT_INTERFACE(Executer);
47 typedef VirtualExec Superclass;
52 /// Gets the factory used by the executer
53 Factory::Pointer GetFactory() { return mFactory; }
54 /// Gets the factory used by the executer (const)
55 // const Factory::Pointer GetFactory() const { return mFactory; }
58 /// Sets the inputs of the workspace :
59 void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
61 /// Puts the executer in "no exec" mode,
62 /// which creates but does not execute pipelines
63 void SetNoExecMode(bool b) { mNoExecMode = b; }
65 bool GetNoExecMode() const { return mNoExecMode; }
67 /// Sets the mode of dialog of the executer for Root inputs
68 void SetDialogMode(DialogModeType t) { mDialogMode = t; }
70 void SetNoErrorMode(bool b) { mNoErrorMode = b; }
72 bool GetNoErrorMode() const { return mNoErrorMode; }
75 //=================================================================
77 void LoadPackage(const std::string &name );
80 void UnLoadPackage(const std::string &name );
82 /// Starts a package block
83 void BeginPackage (const std::string &name );
85 /// Ends a package block
88 /// Starts the definition of a new ComplexBlackBox in package pack
89 /// scriptfilename is the file from which the def is read
90 void Define (const std::string &name,
91 const std::string& pack,
92 const std::string &scriptfilename);
94 /// Sets the file name to use for the current definition
95 /// (Used to set it after the Define command)
96 void SetCurrentFileName (const std::string &name );
98 /// End the definition of a ComplexBlackBox
101 /// Sets the kind of the currently defined ComplexBlackBox
102 void Kind(const std::string& kind);
104 /// Creates a new black box in current complex box
105 void Create ( const std::string& boxType, const std::string& boxName);
107 /// Destroys a black box
108 void Destroy (const std::string &boxName);
110 /// Connects the output boxOutput to the input boxInput
111 void Connect (const std::string &boxfrom,
112 const std::string &output,
113 const std::string &boxto,
114 const std::string &input);
117 void Execute (const std::string &box);
119 /// Defines an input of the current complex box
120 void DefineInput (const std::string &name,
121 const std::string &box,
122 const std::string &input,
123 const std::string &help);
125 /// Defines an output of the current complex box
126 void DefineOutput (const std::string &name,
127 const std::string &box,
128 const std::string &output,
129 const std::string &help);
131 /// sets the input of the box with the value
132 void Set (const std::string &box,
133 const std::string &input,
134 const std::string &value);
136 /// gets the output of the box
137 std::string Get (const std::string &box,
138 const std::string &output);
140 /// changes the workspace name
141 void SetWorkspaceName( const std::string& n );
143 ///Adds the authorName to the Box author list
144 void Author(const std::string &authorName);
146 ///Adds the Categories to the Box category list
147 void Category(const std::string &category);
149 /// The description string which explains what does the ComplexBox
150 void Description(const std::string & d);
152 /// prints the list off the boxes of the current box
155 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
156 std::string ShowGraph(const std::string &nameblackbox,
157 const std::string &detailStr,
158 const std::string &levelStr,
159 const std::string &output_file,
160 const std::string &custom_header,
161 const std::string &custom_title,
162 bool system_display = true);
164 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
165 std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
167 /// Description of the actual pipeline
168 void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
170 /// Resets the workspace : destroys all boxes / unloads all packages
173 /// Sets the level of message for kind
174 void SetMessageLevel(const std::string &kind,
177 /// Prints help on the messages
181 void Print(const std::string & message);
183 // static const std::string& GetObjectDescription();
184 // { static std::string s("Executer"); return s; }
187 ComplexBlackBoxDescriptor::Pointer GetWorkspace()
188 { return mRootCBB.lock(); }
189 Package::Pointer GetUserPackage()
190 { return mRootPackage.lock(); }
192 /// Gets the current working black box
193 ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor()
194 { return mOpenDefinition.back().box; }
202 /// Returns true when we are inside a define/endefine block
203 // bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
205 //==================================================================
209 Factory::Pointer mFactory;
213 /// Contains the root ComplexBlabkBox
214 /// In which ComplexBlackBoxes are put by default
215 /// Its name in bbi is 'user'
216 Package::WeakPointer mRootPackage;
218 /// The root ComplexBlackBox
219 /// in which operations are done when outside a define/endefine block
220 /// Its name in bbi is 'workspace'
221 ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
223 /// Struct that stores info on user defined complex black boxes
226 ComplexBlackBoxDescriptor::Pointer box;
228 CBBDefinition(ComplexBlackBoxDescriptor::Pointer d,
229 const std::string& p )
230 : box(d), package(p) {}
233 /// The stack of current working ComplexBlackBox
234 /// (is a stack for nested definitions)
235 /// only contains the root cbb when outside a define/endefine block
236 std::deque<CBBDefinition> mOpenDefinition;
238 /// The stack of current working package
239 /// (is a stack for nested definitions)
240 std::deque<Package::WeakPointer> mOpenPackage;
242 /// The input values of the Root ComplexBlackBox
243 std::map<std::string,std::string> mInputs;
245 /// no exec mode flag
250 DialogModeType mDialogMode;
252 /// no error mode flag