]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.h
Fixed :
[bbtk.git] / kernel / src / bbtkTranscriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkTranscriptor.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/03/26 08:27:19 $
7   Version:   $Revision: 1.7 $
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 Transcriptor: level 0 of script C++ translation (header)
21  */
22 /**
23  *  \class bbtk::Transcriptor 
24  *  \brief class Transcriptor: level 0 of script C++ translation 
25  */
26  
27 #ifndef __bbtkTranscriptor_h__
28 #define __bbtkTranscriptor_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 #include <iostream>
38
39 namespace bbtk
40 {
41
42   class /*BBTK_EXPORT*/ Transcriptor : public VirtualExec
43   {
44
45   public:
46
47     /// Constructor
48     Transcriptor(std::string filename);
49
50     /// Destructor
51     ~Transcriptor( );
52    
53     /// Sets the inputs of the workspace : 
54     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
55
56     /// Puts the executer in "no exec" mode, 
57     /// which creates but does not execute pipelines 
58
59     //void SetNoExecMode(bool b) { mNoExecMode = b; }
60     void SetNoExecMode(bool b)
61     {
62        if (b)
63           m_Fp << "  e->SetNoExecMode(true);" << std::endl;
64        else
65           m_Fp << "  e->SetNoExecMode(false);" << std::endl;       
66     }
67
68     bool GetNoExecMode() const { return mNoExecMode; }
69     /*
70     bool GetNoExecMode() const
71     {
72       // cannot compile, since ethos is 'const' !
73       //m_Fp << "e->GetNoExecMode(true);" << std::endl;
74     }
75     */
76     /// Sets the mode of dialog of the executer for Root inputs 
77     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
78
79     /// Loads a package
80     void LoadPackage(const std::string &name );
81
82     /// Unloads a package
83     void UnLoadPackage(const std::string &name );
84
85     /// Starts a package block  
86     void BeginPackage (const std::string &name );
87
88     /// Ends a package block
89     void EndPackage ();
90
91     /// Starts the definition of a new ComplexBlackBox in package pack
92     /// scriptfilename is the file from which the def is read
93     void Define (const std::string &name,
94                  const std::string& pack,
95                  const std::string &scriptfilename);
96
97     /// Sets the file name to use for the current definition
98     /// (Used to set it after the Define command)
99     void SetCurrentFileName (const std::string &name );
100
101     /// End the definition of a ComplexBlackBox
102     void EndDefine ();
103
104     /// Creates a new black box in current complex box
105     void Create ( const std::string& boxType, const std::string& boxName);
106
107     /// Destroys a black box
108     void Destroy (const std::string &boxName);
109
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);
115
116     /// Updates the box 
117     void Execute(const std::string &box);
118
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);
124
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);     
130   
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);
135
136     /// gets the output of the box
137     std::string Get (const std::string &box, 
138                      const std::string &output);
139
140     /// changes the workspace name
141     void SetWorkspaceName( const std::string& n );
142
143     ///Adds the authorName to the Box author list
144     void Author(const std::string &authorName);
145
146     ///Adds the Categories to the Box category list
147     void Category(const std::string &category);
148
149     /// The description string which explains what does the ComplexBox
150     void Description(const std::string & d);
151
152     /// prints the list off the boxes of the current box
153     void PrintBoxes();
154
155    /// Generate a HTML with a gif file with the actual 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);
163
164    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
165     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
166
167    /// Description of the actual pipeline
168       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
169
170       void Reset();
171  
172   /// Sets the level of message for kind
173     void SetMessageLevel(const std::string &kind,
174                          int level);
175
176    /// Prints help on the messages
177     void HelpMessages();
178     
179     /// Prints the string ... MORE : TO EXPLAIN 
180     void Print(const std::string & message);
181
182   //  static const std::string& GetObjectDescription()
183   //  { static std::string s("Executer"); return s; }
184
185   protected:
186
187   private:
188
189     /// Gets the current working black box 
190     ComplexBlackBoxDescriptor* Current() 
191         { return mOpenDefinition.back().box; }
192     
193     /// Returns true when we are inside a define/endefine block
194     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
195
196     //==================================================================
197     // ATTRIBUTES
198      
199     /// The factory used
200     //   Factory* mFactory;
201
202     /// The Root Package
203     Package* mPackage;
204     
205     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
206     /// Its name in bbi is 'workspace'  
207     ComplexBlackBoxDescriptor* mRoot;
208
209     /// Struct that stores info on user defined complex black boxes
210     struct CBBDefinition
211     {
212       ComplexBlackBoxDescriptor* box;
213       std::string package;
214       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
215         : box(d), package(p) {}
216     };
217
218     /// The stack of current working ComplexBlackBox
219     /// (is a stack for nested definitions)
220     /// only contains the root when outside a define/endefine block
221     std::deque<CBBDefinition> mOpenDefinition;
222
223     /// The stack of current working package
224     /// (is a stack for nested definitions)
225     std::deque<Package*> mOpenPackage;
226
227     /// flag which is true when we are inside a Define/EndDefine block
228     //    bool mDefineFlag;
229     
230     /// The input values of the Root ComplexBlackBox
231     std::map<std::string,std::string> mInputs;
232     
233     /// no exec mode flag
234     bool mNoExecMode;
235
236     /// Dialog mode
237     DialogModeType mDialogMode;
238     
239     /// File Pointer, to hold generated C++ code.
240     // std::ofstream *m_Fp;
241     std::ofstream m_Fp;
242   };
243 }
244 #endif