2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkExecuter.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.20 $
34 =========================================================================*/
40 * \brief class Executer: level 0 of script execution (header)
43 * \class bbtk::Executer
44 * \brief class Executer: level 0 of script execution
47 #ifndef __bbtkExecuter_h__
48 #define __bbtkExecuter_h__
50 #include "bbtkVirtualExec.h"
52 #include "bbtkSystem.h"
53 #include "bbtkComplexBlackBox.h"
54 #include "bbtkFactory.h"
64 class /*BBTK_EXPORT*/ Executer : public VirtualExec
66 BBTK_OBJECT_INTERFACE(Executer);
67 typedef VirtualExec Superclass;
72 /// Gets the factory used by the executer
73 Factory::Pointer GetFactory() { return mFactory; }
74 /// Gets the factory used by the executer (const)
75 // const Factory::Pointer GetFactory() const { return mFactory; }
78 /// Sets the inputs of the workspace :
79 void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
81 /// Puts the executer in "no exec" mode,
82 /// which creates but does not execute pipelines
83 void SetNoExecMode(bool b) { mNoExecMode = b; }
85 bool GetNoExecMode() const { return mNoExecMode; }
87 /// Sets the mode of dialog of the executer for Root inputs
88 void SetDialogMode(DialogModeType t) { mDialogMode = t; }
90 void SetNoErrorMode(bool b) { mNoErrorMode = b; }
92 bool GetNoErrorMode() const { return mNoErrorMode; }
95 //=================================================================
97 void LoadPackage(const std::string &name );
100 void UnLoadPackage(const std::string &name );
102 /// Starts a package block
103 void BeginPackage (const std::string &name );
105 /// Ends a package block
108 /// Starts the definition of a new ComplexBlackBox in package pack
109 /// scriptfilename is the file from which the def is read
110 void Define (const std::string &name,
111 const std::string& pack,
112 const std::string &scriptfilename);
114 /// Sets the file name to use for the current definition
115 /// (Used to set it after the Define command)
116 void SetCurrentFileName (const std::string &name );
119 void SetTypeOfScript_Application();
123 /// End the definition of a ComplexBlackBox
126 /// Sets the kind of the currently defined ComplexBlackBox
127 void Kind(const std::string& kind);
129 /// Creates a new black box in current complex box
130 void Create ( const std::string& boxType, const std::string& boxName);
132 /// Destroys a black box
133 void Destroy (const std::string &boxName);
135 /// Clears the currently defined ComplexBlackBox
138 /// Connects the output boxOutput to the input boxInput
139 void Connect (const std::string &boxfrom,
140 const std::string &output,
141 const std::string &boxto,
142 const std::string &input);
145 void Execute (const std::string &box);
147 /// Defines an input of the current complex box
148 void DefineInput (const std::string &name,
149 const std::string &box,
150 const std::string &input,
151 const std::string &help);
153 /// Defines an output of the current complex box
154 void DefineOutput (const std::string &name,
155 const std::string &box,
156 const std::string &output,
157 const std::string &help);
159 /// sets the input of the box with the value
160 void Set (const std::string &box,
161 const std::string &input,
162 const std::string &value);
164 /// gets the output of the box
165 std::string Get (const std::string &box,
166 const std::string &output);
168 /// changes the workspace name
169 void SetWorkspaceName( const std::string& n );
171 ///Adds the authorName to the Box author list
172 void Author(const std::string &authorName);
174 ///Adds the Categories to the Box category list
175 void Category(const std::string &category);
177 /// The description string which explains what does the ComplexBox
178 void Description(const std::string & d);
185 /// prints the list off the boxes of the current box
186 void PrintHelpListBoxes();
188 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
189 std::string ShowGraph(const std::string &nameblackbox,
190 const std::string &detailStr,
191 const std::string &levelStr,
192 const std::string &output_file,
193 const std::string &custom_header,
194 const std::string &custom_title,
195 bool system_display = true);
197 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
198 std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
200 /// Prints help on a black box
201 void PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
208 /// Resets the workspace : destroys all boxes / unloads all packages
211 /// Sets the level of message for kind
212 void SetMessageLevel(const std::string &kind,
215 /// Prints help on the messages
219 void Print(const std::string & message);
221 // static const std::string& GetObjectDescription();
222 // { static std::string s("Executer"); return s; }
225 ComplexBlackBoxDescriptor::Pointer GetWorkspace()
226 { return mRootCBB.lock(); }
227 Package::Pointer GetUserPackage()
228 { return mRootPackage.lock(); }
230 /// Gets the current working black box
231 ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor()
232 { return mOpenDefinition.back().box; }
240 /// Returns true when we are inside a define/endefine block
241 // bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
243 //==================================================================
247 Factory::Pointer mFactory;
251 /// Contains the root ComplexBlabkBox
252 /// In which ComplexBlackBoxes are put by default
253 /// Its name in bbi is 'user'
254 Package::WeakPointer mRootPackage;
256 /// The root ComplexBlackBox
257 /// in which operations are done when outside a define/endefine block
258 /// Its name in bbi is 'workspace'
259 ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
261 /// Struct that stores info on user defined complex black boxes
264 ComplexBlackBoxDescriptor::Pointer box;
266 CBBDefinition(ComplexBlackBoxDescriptor::Pointer d,
267 const std::string& p )
268 : box(d), package(p) {}
271 /// The stack of current working ComplexBlackBox
272 /// (is a stack for nested definitions)
273 /// only contains the root cbb when outside a define/endefine block
274 std::deque<CBBDefinition> mOpenDefinition;
276 /// The stack of current working package
277 /// (is a stack for nested definitions)
278 std::deque<Package::WeakPointer> mOpenPackage;
280 /// The input values of the Root ComplexBlackBox
281 std::map<std::string,std::string> mInputs;
283 /// no exec mode flag
288 DialogModeType mDialogMode;
290 /// no error mode flag