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