]> Creatis software - bbtk.git/blob - kernel/src/bbtkInterpreter.h
#3202 BBTK Feature New Normal - fast algorithm for ImageBoundaries box
[bbtk.git] / kernel / src / bbtkInterpreter.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: bbtkInterpreter.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.46 $
34 =========================================================================*/
35
36
37
38 /**
39  *  \file 
40  *  \brief class Interpreter : The bbtk language interpreter
41  */
42 /**
43  *  \class bbtk::Interpreter 
44  *  \brief The bbtk language interpreter
45  */
46
47 #ifndef __bbtkInterpreter_h__
48 #define __bbtkInterpreter_h__
49
50 #include "bbtkVirtualExec.h"
51 #include "bbtkExecuter.h"
52 #include "bbtkInterpreterVirtual.h"
53
54 #include <fstream>
55 #include <deque>
56
57
58 namespace bbtk
59 {
60
61 #ifdef USE_WXWIDGETS
62   class WxConsole;
63 #endif
64   
65         
66
67         
68         
69
70   //=======================================================================
71   class BBTK_EXPORT Interpreter : public InterpreterVirtual
72   {
73     BBTK_OBJECT_INTERFACE_NO_CONDES(Interpreter);
74     typedef Object InterpreterVirtual;
75   public:
76     static Pointer New(const std::string& cpp_file = "");
77     static Pointer New(VirtualExec::Pointer);
78
79
80     /// Sets the inputs of the workspace :
81     /// the map is passed as is to the Executer
82     void SetInputs(const std::map<std::string,std::string>& m)
83     { mVirtualExecuter->SetInputs(m); }
84
85     /// Puts the executer in "no exec" mode,
86     /// which creates but does not execute pipelines.
87     void SetNoExecMode(bool m) { mVirtualExecuter->SetNoExecMode(m); }
88
89     /// Puts the executer in "no error" mode, 
90     /// Errors do not stop execution (but warnings are produced)
91     void SetNoErrorMode(bool m) { mVirtualExecuter->SetNoErrorMode(m);}
92     ///
93     //typedef Executer::DialogModeType DialogModeType;
94     typedef VirtualExec::DialogModeType DialogModeType;
95
96     void SetDialogMode(DialogModeType t) { mVirtualExecuter->SetDialogMode(t);}
97
98
99     /// Gets the Executer 
100     VirtualExec::Pointer GetExecuter() const { return mVirtualExecuter; }
101
102     /*
103     // For 'break' commands observation
104     typedef boost::signals::trackable BreakObserverType;
105     typedef boost::signal<void ()>  BreakSignalType;
106     typedef BreakSignalType::slot_function_type BreakCallbackType;
107   
108     // Adds a callback when 'break' command issued
109     void AddBreakObserver( BreakCallbackType );
110     */
111
112   protected:
113
114           
115     /// Resets all
116     virtual void commandReset();
117
118           
119     /// Displays help (entry point of any help)
120     virtual void commandHelp(const std::vector<std::string>& words);
121
122     /// Displays help on all the commands
123     void HelpCommands();
124
125           
126     /// Displays help on a particular command 
127     virtual void commandHelp( const std::string& command );
128
129     ///
130     virtual void commandGraph(const std::vector<std::string>& words);
131
132     ///
133     virtual void commandConfig() const; 
134     /// 
135     //    void Print(const std::string&);
136
137     virtual void commandIndex(const std::string& filename, 
138                const std::string& type = "Initials");
139
140           
141     /// Creates and connects the piece of pipeline which defines a GUI 
142     /// for the box box. 
143     /// Define it as a complex box type with name instanceName+"Type"
144     /// The instance is called instanceName
145     /// and connected to the existing pipeline
146      virtual void commandNewGUI(const std::string& box,const std::string& instanceName);
147      virtual void commandDebug(const std::string& arg);
148           virtual void commandNew(const std::string &boxType,const std::string &boxName);
149           virtual void commandDelete(const std::string &boxName);
150           virtual void commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel);
151           virtual void commandPackage(const std::string &packageName);
152           virtual void commandEndPackage();
153           virtual void commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename);
154           virtual void commandEndDefine();
155           virtual void commandKind(const std::string &kind);
156           virtual void commandPrint(const std::string &value);
157           virtual void commandExec(const std::string &word);
158           virtual void commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string  &help);
159           virtual void commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string  &help);
160           virtual void commandSet(const std::string &box,const std::string &input,const std::string &value);
161           virtual void commandAuthor(const std::string &author);
162           virtual void commandCategory(const std::string &categorytype);
163           virtual void commandDescription(const std::string &description);
164           virtual void commandClear();
165           virtual void commandInclude(const std::string &word, bool ok);
166           virtual void commandLoad(const std::string &packageName);
167           virtual void commandUnload(const std::string &packageName);
168           virtual void commandBreak();
169           virtual void commandQuit();
170           virtual void commandMessage();
171           virtual void commandMessage(const std::string &kind,const  std::string &levelstr);
172           virtual void SetCurrentFileName(const std::string &fullPathScriptName); 
173           virtual void SetTypeOfScript_Application();
174
175           
176           
177           /// Constructor
178           Interpreter(const std::string& cpp_file = "");
179           Interpreter(VirtualExec::Pointer);
180           
181   private:
182
183                   
184     void Init(VirtualExec::Pointer, const std::string& cpp_file);
185
186
187     //==================================================================
188     // ATTRIBUTES
189
190     /// The command executer used
191     bbtk::VirtualExec::Pointer mVirtualExecuter;
192     bbtk::Executer::WeakPointer mRealExecuter;
193
194
195   protected:
196           ~Interpreter();
197
198           /// 
199           virtual void CatchInterpreterException( const InterpreterException& e );
200           virtual void CatchBbtkException( const bbtk::Exception& e );
201           virtual void CatchStdException( const std::exception& e );
202           virtual void CatchUnknownException();
203           
204           
205   };
206   // EO class Interpreter
207
208
209
210 }
211 #endif