1 /*=========================================================================
3 Module: $RCSfile: bbtkExecuter.h,v $
5 Date: $Date: 2008/12/12 12:11:21 $
6 Version: $Revision: 1.17 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief class Executer: level 0 of script execution (header)
36 * \class bbtk::Executer
37 * \brief class Executer: level 0 of script execution
40 #ifndef __bbtkExecuter_h__
41 #define __bbtkExecuter_h__
43 #include "bbtkVirtualExec.h"
45 #include "bbtkSystem.h"
46 #include "bbtkComplexBlackBox.h"
47 #include "bbtkFactory.h"
57 class /*BBTK_EXPORT*/ Executer : public VirtualExec
59 BBTK_OBJECT_INTERFACE(Executer);
60 typedef VirtualExec Superclass;
65 /// Gets the factory used by the executer
66 Factory::Pointer GetFactory() { return mFactory; }
67 /// Gets the factory used by the executer (const)
68 // const Factory::Pointer GetFactory() const { return mFactory; }
71 /// Sets the inputs of the workspace :
72 void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
74 /// Puts the executer in "no exec" mode,
75 /// which creates but does not execute pipelines
76 void SetNoExecMode(bool b) { mNoExecMode = b; }
78 bool GetNoExecMode() const { return mNoExecMode; }
80 /// Sets the mode of dialog of the executer for Root inputs
81 void SetDialogMode(DialogModeType t) { mDialogMode = t; }
83 void SetNoErrorMode(bool b) { mNoErrorMode = b; }
85 bool GetNoErrorMode() const { return mNoErrorMode; }
88 //=================================================================
90 void LoadPackage(const std::string &name );
93 void UnLoadPackage(const std::string &name );
95 /// Starts a package block
96 void BeginPackage (const std::string &name );
98 /// Ends a package block
101 /// Starts the definition of a new ComplexBlackBox in package pack
102 /// scriptfilename is the file from which the def is read
103 void Define (const std::string &name,
104 const std::string& pack,
105 const std::string &scriptfilename);
107 /// Sets the file name to use for the current definition
108 /// (Used to set it after the Define command)
109 void SetCurrentFileName (const std::string &name );
111 /// End the definition of a ComplexBlackBox
114 /// Sets the kind of the currently defined ComplexBlackBox
115 void Kind(const std::string& kind);
117 /// Creates a new black box in current complex box
118 void Create ( const std::string& boxType, const std::string& boxName);
120 /// Destroys a black box
121 void Destroy (const std::string &boxName);
123 /// Clears the currently defined ComplexBlackBox
126 /// Connects the output boxOutput to the input boxInput
127 void Connect (const std::string &boxfrom,
128 const std::string &output,
129 const std::string &boxto,
130 const std::string &input);
133 void Execute (const std::string &box);
135 /// Defines an input of the current complex box
136 void DefineInput (const std::string &name,
137 const std::string &box,
138 const std::string &input,
139 const std::string &help);
141 /// Defines an output of the current complex box
142 void DefineOutput (const std::string &name,
143 const std::string &box,
144 const std::string &output,
145 const std::string &help);
147 /// sets the input of the box with the value
148 void Set (const std::string &box,
149 const std::string &input,
150 const std::string &value);
152 /// gets the output of the box
153 std::string Get (const std::string &box,
154 const std::string &output);
156 /// changes the workspace name
157 void SetWorkspaceName( const std::string& n );
159 ///Adds the authorName to the Box author list
160 void Author(const std::string &authorName);
162 ///Adds the Categories to the Box category list
163 void Category(const std::string &category);
165 /// The description string which explains what does the ComplexBox
166 void Description(const std::string & d);
168 /// prints the list off the boxes of the current box
171 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
172 std::string ShowGraph(const std::string &nameblackbox,
173 const std::string &detailStr,
174 const std::string &levelStr,
175 const std::string &output_file,
176 const std::string &custom_header,
177 const std::string &custom_title,
178 bool system_display = true);
180 /// Generate a HTML with a gif file with the current pipeline (Graphviz-dot needed). Returns the file path
181 std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
183 /// Description of the actual pipeline
184 void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
186 /// Resets the workspace : destroys all boxes / unloads all packages
189 /// Sets the level of message for kind
190 void SetMessageLevel(const std::string &kind,
193 /// Prints help on the messages
197 void Print(const std::string & message);
199 // static const std::string& GetObjectDescription();
200 // { static std::string s("Executer"); return s; }
203 ComplexBlackBoxDescriptor::Pointer GetWorkspace()
204 { return mRootCBB.lock(); }
205 Package::Pointer GetUserPackage()
206 { return mRootPackage.lock(); }
208 /// Gets the current working black box
209 ComplexBlackBoxDescriptor::Pointer GetCurrentDescriptor()
210 { return mOpenDefinition.back().box; }
218 /// Returns true when we are inside a define/endefine block
219 // bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
221 //==================================================================
225 Factory::Pointer mFactory;
229 /// Contains the root ComplexBlabkBox
230 /// In which ComplexBlackBoxes are put by default
231 /// Its name in bbi is 'user'
232 Package::WeakPointer mRootPackage;
234 /// The root ComplexBlackBox
235 /// in which operations are done when outside a define/endefine block
236 /// Its name in bbi is 'workspace'
237 ComplexBlackBoxDescriptor::WeakPointer mRootCBB;
239 /// Struct that stores info on user defined complex black boxes
242 ComplexBlackBoxDescriptor::Pointer box;
244 CBBDefinition(ComplexBlackBoxDescriptor::Pointer d,
245 const std::string& p )
246 : box(d), package(p) {}
249 /// The stack of current working ComplexBlackBox
250 /// (is a stack for nested definitions)
251 /// only contains the root cbb when outside a define/endefine block
252 std::deque<CBBDefinition> mOpenDefinition;
254 /// The stack of current working package
255 /// (is a stack for nested definitions)
256 std::deque<Package::WeakPointer> mOpenPackage;
258 /// The input values of the Root ComplexBlackBox
259 std::map<std::string,std::string> mInputs;
261 /// no exec mode flag
266 DialogModeType mDialogMode;
268 /// no error mode flag