]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.h
3d819ce9b2c4a4a5c0b6f5016b2602c860109543
[bbtk.git] / kernel / src / bbtkTranscriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkTranscriptor.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/02/20 11:58:32 $
7   Version:   $Revision: 1.6 $
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     /// Starts a package block  
80     void BeginPackage (const std::string &name );
81
82     /// Ends a package block
83     void EndPackage ();
84
85     /// Starts the definition of a new ComplexBlackBox in package pack
86     /// scriptfilename is the file from which the def is read
87     void Define (const std::string &name,
88                  const std::string& pack,
89                  const std::string &scriptfilename);
90
91     /// Sets the file name to use for the current definition
92     /// (Used to set it after the Define command)
93     void SetCurrentFileName (const std::string &name );
94
95     /// End the definition of a ComplexBlackBox
96     void EndDefine ();
97
98     /// Creates a new black box in current complex box
99     void Create ( const std::string& boxType, const std::string& boxName);
100
101     /// Destroys a black box
102     void Destroy (const std::string &boxName);
103
104     /// Connects the output boxOutput to the input boxInput
105     void Connect (const std::string &boxfrom,
106                   const std::string &output,
107                   const std::string &boxto,
108                   const std::string &input);
109
110     /// Updates the box 
111     /// would 'Execute' be more meaningfull ?
112     void Update (const std::string &box);
113
114     /// Defines an input of the current complex box
115     void DefineInput (const std::string &name,
116                       const std::string &box,
117                       const std::string &input,
118                       const std::string &help);
119
120     /// Defines an output of the current complex box
121     void DefineOutput (const std::string &name,
122                        const std::string &box,
123                        const std::string &output,
124                        const std::string &help);     
125   
126     /// sets the input of the box with the value
127     void Set (const std::string &box, 
128               const std::string &input, 
129               const std::string &value);
130
131     /// gets the output of the box
132     std::string Get (const std::string &box, 
133                      const std::string &output);
134
135     /// changes the workspace name
136     void SetWorkspaceName( const std::string& n );
137
138     ///Adds the authorName to the Box author list
139     void Author(const std::string &authorName);
140
141     ///Adds the Categories to the Box category list
142     void Category(const std::string &category);
143
144     /// The description string which explains what does the ComplexBox
145     void Description(const std::string & d);
146
147     /// prints the list off the boxes of the current box
148     void PrintBoxes();
149
150    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
151     std::string ShowGraph(const std::string &nameblackbox, 
152                           const std::string &detailStr, 
153                           const std::string &levelStr,
154                           const std::string &output_file,
155                           const std::string &custom_header,
156                           const std::string &custom_title,
157                           bool system_display = true);
158
159    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
160     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
161
162    /// Description of the actual pipeline
163       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
164
165       void Reset();
166
167   //  static const std::string& GetObjectDescription()
168   //  { static std::string s("Executer"); return s; }
169
170   protected:
171
172   private:
173
174     /// Gets the current working black box 
175     ComplexBlackBoxDescriptor* Current() 
176         { return mOpenDefinition.back().box; }
177     
178     /// Returns true when we are inside a define/endefine block
179     //    bool InDefinitionBlock() { return (mOpenDefinition.size()>1); }
180
181     //==================================================================
182     // ATTRIBUTES
183      
184     /// The factory used
185     //   Factory* mFactory;
186
187     /// The Root Package
188     Package* mPackage;
189     
190     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
191     /// Its name in bbi is 'workspace'  
192     ComplexBlackBoxDescriptor* mRoot;
193
194     /// Struct that stores info on user defined complex black boxes
195     struct CBBDefinition
196     {
197       ComplexBlackBoxDescriptor* box;
198       std::string package;
199       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
200         : box(d), package(p) {}
201     };
202
203     /// The stack of current working ComplexBlackBox
204     /// (is a stack for nested definitions)
205     /// only contains the root when outside a define/endefine block
206     std::deque<CBBDefinition> mOpenDefinition;
207
208     /// The stack of current working package
209     /// (is a stack for nested definitions)
210     std::deque<Package*> mOpenPackage;
211
212     /// flag which is true when we are inside a Define/EndDefine block
213     //    bool mDefineFlag;
214     
215     /// The input values of the Root ComplexBlackBox
216     std::map<std::string,std::string> mInputs;
217     
218     /// no exec mode flag
219     bool mNoExecMode;
220
221     /// Dialog mode
222     DialogModeType mDialogMode;
223     
224     /// File Pointer, to hold generated C++ code.
225     // std::ofstream *m_Fp;
226     std::ofstream m_Fp;
227   };
228 }
229 #endif