]> Creatis software - bbtk.git/blob - kernel/src/bbtkTranscriptor.h
573dfe458b0d5e8e533ed8d641113d719c71b780
[bbtk.git] / kernel / src / bbtkTranscriptor.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkTranscriptor.h,v $
4   Language:  C++
5   Date:      $Date: 2012/11/14 07:12:00 $
6   Version:   $Revision: 1.15 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief class Transcriptor: level 0 of script C++ translation (header)
34  */
35 /**
36  *  \class bbtk::Transcriptor 
37  *  \brief class Transcriptor: level 0 of script C++ translation 
38  */
39  
40 #ifndef __bbtkTranscriptor_h__
41 #define __bbtkTranscriptor_h__
42
43 #include "bbtkVirtualExec.h"
44
45 #include "bbtkSystem.h"
46 #include <iostream>
47
48 namespace bbtk
49 {
50
51   class /*BBTK_EXPORT*/ Transcriptor : public VirtualExec
52   {
53     BBTK_OBJECT_INTERFACE(Transcriptor);
54     typedef VirtualExec Superclass;
55   public:
56     static Pointer New(const std::string& filename);
57
58    
59     /// Sets the inputs of the workspace : 
60     void SetInputs(const std::map<std::string,std::string>& m) { mInputs = m; }
61
62     /// Puts the executer in "no exec" mode, 
63     /// which creates but does not execute pipelines 
64
65     //void SetNoExecMode(bool b) { mNoExecMode = b; }
66     void SetNoExecMode(bool b)
67     {
68        if (b)
69           m_Fp << "  e->SetNoExecMode(true);" << std::endl;
70        else
71           m_Fp << "  e->SetNoExecMode(false);" << std::endl;       
72     }
73
74     void SetNoErrorMode(bool b)
75     {
76        if (b)
77           m_Fp << "  e->SetNoErrorMode(true);" << std::endl;
78        else
79           m_Fp << "  e->SetNoErrorMode(false);" << std::endl;       
80     }
81
82     bool GetNoExecMode() const { return false; }
83     bool GetNoErrorMode() const { return false; }
84
85     /// Sets the mode of dialog of the executer for Root inputs 
86     void SetDialogMode(DialogModeType t) { mDialogMode = t; }
87
88     /// Loads a package
89     void LoadPackage(const std::string &name );
90
91     /// Unloads a package
92     void UnLoadPackage(const std::string &name );
93
94     /// Starts a package block  
95     void BeginPackage (const std::string &name );
96
97     /// Ends a package block
98     void EndPackage ();
99
100     /// Starts the definition of a new ComplexBlackBox in package pack
101     /// scriptfilename is the file from which the def is read
102     void Define (const std::string &name,
103                  const std::string& pack,
104                  const std::string &scriptfilename);
105
106     /// Sets the file name to use for the current definition
107     /// (Used to set it after the Define command)
108     void SetCurrentFileName (const std::string &name );
109
110         void SetTypeOfScript_Application();
111           
112     /// End the definition of a ComplexBlackBox
113     void EndDefine ();
114
115     /// Sets the kind of the currently defined ComplexBlackBox
116     void Kind(const std::string& kind);
117
118     /// Creates a new black box in current complex box
119     void Create ( const std::string& boxType, const std::string& boxName);
120
121     /// Destroys a black box
122     void Destroy (const std::string &boxName);
123
124     /// Clears the currently defined ComplexBlackBox
125     void Clear();
126
127     /// Connects the output boxOutput to the input boxInput
128     void Connect (const std::string &boxfrom,
129                   const std::string &output,
130                   const std::string &boxto,
131                   const std::string &input);
132
133     /// Updates the box 
134     void Execute(const std::string &box);
135
136     /// Defines an input of the current complex box
137     void DefineInput (const std::string &name,
138                       const std::string &box,
139                       const std::string &input,
140                       const std::string &help);
141
142     /// Defines an output of the current complex box
143     void DefineOutput (const std::string &name,
144                        const std::string &box,
145                        const std::string &output,
146                        const std::string &help);     
147   
148     /// sets the input of the box with the value
149     void Set (const std::string &box, 
150               const std::string &input, 
151               const std::string &value);
152
153     /// gets the output of the box
154     std::string Get (const std::string &box, 
155                      const std::string &output);
156
157     /// changes the workspace name
158     void SetWorkspaceName( const std::string& n );
159
160     ///Adds the authorName to the Box author list
161     void Author(const std::string &authorName);
162
163     ///Adds the Categories to the Box category list
164     void Category(const std::string &category);
165
166     /// The description string which explains what does the ComplexBox
167     void Description(const std::string & d);
168
169     /// prints the list off the boxes of the current box
170     void PrintHelpListBoxes();
171
172    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
173     std::string ShowGraph(const std::string &nameblackbox, 
174                           const std::string &detailStr, 
175                           const std::string &levelStr,
176                           const std::string &output_file,
177                           const std::string &custom_header,
178                           const std::string &custom_title,
179                           bool system_display = true);
180
181    /// Generate a HTML with a gif file with the actual pipeline (Graphviz-dot needed). Returns the file path
182     std::string ShowGraphInstances(const std::string &nameblackbox, int detail, int level, bool system_display=true);
183
184     /// Prints help on a black box
185     void PrintHelpBlackBox(const std::string &nameblackbox, const std::string &detailStr, const std::string &levelStr);
186
187       void Reset();
188  
189   /// Sets the level of message for kind
190     void SetMessageLevel(const std::string &kind,
191                          int level);
192
193    /// Prints help on the messages
194     void HelpMessages();
195     
196     /// Prints the string ... MORE : TO EXPLAIN 
197     void Print(const std::string & message);
198
199   //  static const std::string& GetObjectDescription()
200   //  { static std::string s("Executer"); return s; }
201
202   protected:
203
204   private:
205     /// Constructor
206     Transcriptor(const std::string& filename);
207
208     /// The input values of the Root ComplexBlackBox
209     std::map<std::string,std::string> mInputs;
210     
211     /// Dialog mode
212     DialogModeType mDialogMode;
213     
214     /// File Pointer, to hold generated C++ code.
215     // std::ofstream *m_Fp;
216     std::ofstream m_Fp;
217   };
218 }
219 #endif