+#ifdef _USE_WXWIDGETS_
+
+//==========================================================================
+// WITH WX
+//==========================================================================
+#include "bbtkInterpreter.h"
+#include "bbtkWxBlackBox.h"
+#include "bbtkWxGUIConsole.h"
+
+#include <wx/cmdline.h>
+#include <vector>
+#include <map>
+
+#include "EXEC_FUNCTION.h"
+
+static const wxCmdLineEntryDesc cmdLineDesc[] =
+{
+ { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("Debug messages on (message All 9)") },
+ { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
+ { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
+ { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
+ { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
+ { wxCMD_LINE_PARAM, NULL, NULL, _T("Input=Value"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
+ { wxCMD_LINE_NONE }
+};
+
+
+
+class wxBBIApp : public wxApp
+{
+public:
+ bool OnInit( );
+ int OnExit() { delete mExecuter; return true; }
+ void OnInitCmdLine(wxCmdLineParser& parser);
+ bool OnCmdLineParsed(wxCmdLineParser& parser);
+ void Run(bbtk::Interpreter*);
+
+ bbtk::Executer* mExecuter;
+ // int argc;
+ // std::vector<std::string> argv;
+ bool command;
+ bool debug;
+ bool quiet;
+ bool help;
+ bool graphical_dialog;
+ bool text_dialog;
+
+ std::map<std::string,std::string> param_map;
+
+};
+
+IMPLEMENT_APP(wxBBIApp);
+
+void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
+{
+ parser.SetDesc(cmdLineDesc);
+}
+
+bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
+{
+ debug = ( parser.Found(_T("d")) );
+ quiet = ( parser.Found(_T("q")) );
+ help = ( parser.Found(_T("h")) );
+ graphical_dialog = ( parser.Found(_T("g")) );
+ text_dialog = ( parser.Found(_T("t")) );
+
+ // parse the arguments and consider those which contain a "="
+ // as set input commands
+ int argc = parser.GetParamCount();
+ for (int i=0; i<argc; ++i)
+ {
+ std::string s = bbtk::wx2std(parser.GetParam(i));
+ std::string::size_type pos = s.find_first_of("=");
+ if (std::string::npos != pos)
+ {
+ std::string left = s.substr(0,pos);
+ std::string right = s.substr(pos+1,s.size());
+ param_map[left]=right;
+ }
+ else
+ {
+ std::cout << "'" << s << "' option unrecognized : ignored"<<std::endl;
+ }
+ }
+
+ if (help) {
+ std::cout << bbtk::wx2std(parser.GetParam(0)) << std::endl;
+ parser.Usage();
+ }
+
+ return true;
+}
+
+
+
+// ----------------------------------------------------------------------------
+// The `main program' equivalent, creating the windows and returning the
+// main frame
+bool wxBBIApp::OnInit( )
+{
+ // std::cout << "OnInit"<<std::endl;
+ wxApp::OnInit();
+#ifdef __WXGTK__
+ //See http://www.wxwindows.org/faqgtk.htm#locale
+ setlocale(LC_NUMERIC, "C");
+#endif
+
+ if (quiet) bbtk::MessageManager::SetMessageLevel("All",0);
+ if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
+
+ bbtk::Wx::CreateInvisibleTopWindow();
+
+ try {
+ mExecuter = new bbtk::Executer();
+ mExecuter->SetInputs(param_map);
+
+ if (help) mExecuter->SetNoExecMode(true);
+
+ if (graphical_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
+ if (text_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::TextDialog);
+
+ EXEC_FUNCTION(mExecuter);
+
+ mExecuter->SetNoExecMode(false);
+
+ if (help)
+ {
+ std::string package;
+ mExecuter->GetFactory()->HelpBlackBox("workspace",package,false);
+ }
+ }
+ catch (bbtk::Exception e)
+ {
+ wxString mess;
+ mess += bbtk::std2wx ( e.GetMessage() );
+ wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
+ bbtk::Wx::GetTopWindow()->Close();
+ delete mExecuter;
+ return false;
+ }
+ if (help || !bbtk::Wx::IsSomeWindowAlive())
+ {
+ return false;
+ }
+ return true;
+}
+
+
+#if defined(_WIN32)
+
+// How to have a Console and wxWidgets
+// http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
+// In Visual C++ 6 (7 should be similar), to create an application that is both a console application
+// (cout's to the console are visible) and has a wxWidgets GUI,
+// you need to use the linker option "/subsystem:console" and the following code:
+int main(int argc, char* argv[])
+{
+ return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
+ SW_SHOWNORMAL);
+}
+
+#endif // defined(_WIN32)
+
+
+#else
+//==========================================================================
+// WITHOUT WX
+//==========================================================================
+
+#include "bbtkInterpreter.h"
+
+int main(int argc, char* argv[])
+{
+
+ if (argc>2) return 0;
+
+ std::cout << "BBI (Black Box Interpreter) - bbtk "
+ << bbtk::GetVersion()<< " - (c) Creatis 2007"
+ <<std::endl;
+
+ bbtk::Interpreter I;
+ if (argc==1)
+ {
+ I.CommandLineInterpreter();
+ }
+ else
+ {
+ std::string f(argv[1]);
+ I.InterpretFile(f);
+ }
+
+ return 0;
+
+}
+
+// EOF
+#endif //#ifdef _USE_WXWIDGETS_
+
+
+