]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.h
5ab590a956df924e2fbb9414be54f324ca0c3b6b
[bbtk.git] / kernel / src / bbtkTranscriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkTranscriptor.h,v $ $
5   Language:  C++
6   Date:      $Date: 2008/01/22 17:00:17 $
7   Version:   $Revision: 1.1 $
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 <iostream>
33
34 namespace bbtk
35 {
36
37   class /*BBTK_EXPORT*/ Transcriptor : public VirtualExec
38   {
39
40   public:  
41
42     /// Constructor
43     Transcriptor(std::string filename);
44       
45     /// Destructor
46     ~Transcriptor( );
47     
48     /// Sets the inputs of the workspace : 
49     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
50
51     /// Puts the executer in "no exec" mode, 
52     /// which creates but does not execute pipelines 
53
54     //void SetNoExecMode(bool b) { mNoExecMode = b; }
55     void SetNoExecMode(bool b)
56     {
57        m_Fp << "e->SetNoExecMode(true);" << std::endl;      
58     }    
59
60     bool GetNoExecMode() const { return mNoExecMode; }
61     /*
62     bool GetNoExecMode() const 
63     {
64       // cannot compile, since ethos is 'const' !
65       //m_Fp << "e->GetNoExecMode(true);" << std::endl;      
66     }
67     */
68     /// Sets the mode of dialog of the executer for Root inputs 
69     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
70
71     /// Starts the definition of a new ComplexBlackBox in package pack
72     /// scriptfilename is the file from which the def is read
73     void Define (const std::string &name,
74                  const std::string& pack,
75                  const std::string &scriptfilename);
76
77     /// End the definition of a ComplexBlackBox
78     void EndDefine ();
79
80     /// Creates a new black box in current complex box
81     void Create ( const std::string& boxType, const std::string& boxName);
82
83     /// Destroys a black box
84     void Destroy (const std::string &boxName);
85
86     /// Connects the output boxOutput to the input boxInput
87     void Connect (const std::string &boxfrom,
88                   const std::string &output,
89                   const std::string &boxto,
90                   const std::string &input);
91
92     /// Updates the box 
93     /// would 'Execute' be more meaningfull ?
94     void Update (const std::string &box);
95
96     /// Defines an input of the current complex box
97     void DefineInput (const std::string &name,
98                       const std::string &box,
99                       const std::string &input,
100                       const std::string &help);
101
102     /// Defines an output of the current complex box
103     void DefineOutput (const std::string &name,
104                        const std::string &box,
105                        const std::string &output,
106                        const std::string &help);     
107   
108     /// sets the input of the box with the value
109     void Set (const std::string &box, 
110               const std::string &input, 
111               const std::string &value);
112
113     /// gets the output of the box
114     std::string Get (const std::string &box, 
115                      const std::string &output);
116
117     /// changes the workspace name
118     void SetWorkspaceName( const std::string& n );
119
120     ///Adds the authorName to the Box's author list
121     void Author(const std::string &authorName);
122
123     /// The description string which explains what does the ComplexBox
124     void Description(const std::string & d);
125
126     /// prints the list off the boxes of the current box
127     void PrintBoxes();
128
129    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
130     std::string ShowGraph(const std::string &nameblackbox, 
131                           const std::string &detailStr, 
132                           const std::string &levelStr,
133                           const std::string &output_file,
134                           const std::string &custom_header,
135                           const std::string &custom_title,
136                           bool system_display = true);
137
138    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
139     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
140
141    /// Description of the actual pipeline
142       void ShowRelations(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
143
144       void Reset();
145
146   //  static const std::string& GetObjectDescription() 
147   //  { static std::string s("Executer"); return s; }
148
149   protected:
150
151   private:
152
153     /// Gets the current working black box 
154     ComplexBlackBoxDescriptor* Current() { return mCurrent.back().box; }
155     
156     /// Returns true when we are inside a define/endefine block
157     //    bool InDefinitionBlock() { return (mCurrent.size()>1); }
158
159     //==================================================================
160     // ATTRIBUTES
161      
162     /// The factory used
163     //   Factory* mFactory;
164
165     /// The Root Package
166     Package* mPackage;
167     
168     /// The root ComplexBlackBox, in which operations are done when outside a define/endefine block
169     /// Its name in bbi is 'workspace'  
170     ComplexBlackBoxDescriptor* mRoot;
171     
172     /// Struct that stores info on user defined complex black boxes
173     struct CBBDefinition
174     {
175       ComplexBlackBoxDescriptor* box;
176       std::string package;
177       CBBDefinition(ComplexBlackBoxDescriptor* d, const std::string& p )
178         : box(d), package(p) {}
179     };
180
181     /// The stack of current working ComplexBlackBox
182     /// (is a stack for nested definitions)
183     /// only contains the root when outside a define/endefine block
184     std::deque<CBBDefinition> mCurrent;
185
186     /// flag which is true when we are inside a Define/EndDefine block
187     //    bool mDefineFlag;
188     
189     /// The input values of the Root ComplexBlackBox
190     std::map<std::string,std::string> mInputs;
191     
192     /// no exec mode flag
193     bool mNoExecMode;
194
195     /// Dialog mode
196     DialogModeType mDialogMode;
197     
198     /// File Pointer, to hold generated C++ code.
199    // std::ofstream *m_Fp;
200    std::ofstream m_Fp;
201   };
202 }
203 #endif