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