2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 #ifdef _USE_WXWIDGETS_
29 //==========================================================================
31 //==========================================================================
32 #include "bbtkInterpreter.h"
33 #include "bbtkWxBlackBox.h"
34 #include "bbtkWxGUIConsole.h"
36 #include <wx/cmdline.h>
40 #include "EXEC_FUNCTION.h"
42 static const wxCmdLineEntryDesc cmdLineDesc[] =
44 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("debug messages on (message all 9)") },
45 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet (message mac 0)") },
46 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
47 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
48 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
49 { wxCMD_LINE_PARAM, NULL, NULL, _T("Input=Value"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
55 class wxBBIApp : public wxApp
59 int OnExit() { return true; }
60 void OnInitCmdLine(wxCmdLineParser& parser);
61 bool OnCmdLineParsed(wxCmdLineParser& parser);
62 void Run(bbtk::Interpreter*);
64 bbtk::Executer::Pointer mExecuter;
66 // std::vector<std::string> argv;
71 bool graphical_dialog;
74 std::map<std::string,std::string> param_map;
78 IMPLEMENT_APP(wxBBIApp);
80 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
82 parser.SetDesc(cmdLineDesc);
85 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
87 debug = ( parser.Found(_T("d")) );
88 quiet = ( parser.Found(_T("q")) );
89 help = ( parser.Found(_T("h")) );
90 graphical_dialog = ( parser.Found(_T("g")) );
91 text_dialog = ( parser.Found(_T("t")) );
93 // parse the arguments and consider those which contain a "="
94 // as set input commands
95 int argc = parser.GetParamCount();
96 for (int i=0; i<argc; ++i)
98 std::string s = bbtk::wx2std(parser.GetParam(i));
99 std::string::size_type pos = s.find_first_of("=");
100 if (std::string::npos != pos)
102 std::string left = s.substr(0,pos);
103 std::string right = s.substr(pos+1,s.size());
104 param_map[left]=right;
108 std::cout << "'" << s << "' option unrecognized : ignored"<<std::endl;
113 std::cout << bbtk::wx2std(parser.GetParam(0)) << std::endl;
122 // ----------------------------------------------------------------------------
123 // The `main program' equivalent, creating the windows and returning the
125 bool wxBBIApp::OnInit( )
127 // std::cout << "OnInit"<<std::endl;
130 //See http://www.wxwindows.org/faqgtk.htm#locale
131 setlocale(LC_NUMERIC, "C");
134 if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
135 if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
137 // Creates the parent window of all bbtk windows
138 bbtk::Wx::CreateTopWindow();
141 mExecuter = bbtk::Executer::New();
142 mExecuter->SetInputs(param_map);
144 if (help) mExecuter->SetNoExecMode(true);
146 if (graphical_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
147 if (text_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::TextDialog);
149 EXEC_FUNCTION(mExecuter);
151 mExecuter->SetNoExecMode(false);
156 mExecuter->GetFactory()->HelpBlackBox("workspace",package,false);
159 catch (bbtk::Exception e)
162 mess += bbtk::std2wx ( e.GetMessage() );
163 wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
164 bbtk::Wx::GetTopWindow()->Close();
167 if (help || !bbtk::Wx::IsSomeWindowAlive())
177 // How to have a Console and wxWidgets
178 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
179 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
180 // (cout's to the console are visible) and has a wxWidgets GUI,
181 // you need to use the linker option "/subsystem:console" and the following code:
182 int main(int argc, char* argv[])
184 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
188 #endif // defined(_WIN32)
192 //==========================================================================
194 //==========================================================================
196 #include "bbtkInterpreter.h"
198 int main(int argc, char* argv[])
201 if (argc>2) return 0;
203 std::cout << "BBI (Black Box Interpreter) - bbtk "
204 << bbtk::GetVersion()<< " - (c) Creatis 2007"
210 I.CommandLineInterpreter();
214 std::string f(argv[1]);
223 #endif //#ifdef _USE_WXWIDGETS_