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