3 //==========================================================================
5 //==========================================================================
6 #include "bbtkInterpreter.h"
7 #include "bbtkWxBlackBox.h"
8 #include "bbtkWxGUIConsole.h"
10 #include <wx/cmdline.h>
14 #include "EXEC_FUNCTION.h"
16 static const wxCmdLineEntryDesc cmdLineDesc[] =
18 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("debug messages on (message all 9)") },
19 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet (message mac 0)") },
20 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
21 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
22 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
23 { wxCMD_LINE_PARAM, NULL, NULL, _T("Input=Value"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
29 class wxBBIApp : public wxApp
33 int OnExit() { return true; }
34 void OnInitCmdLine(wxCmdLineParser& parser);
35 bool OnCmdLineParsed(wxCmdLineParser& parser);
36 void Run(bbtk::Interpreter*);
38 bbtk::Executer::Pointer mExecuter;
40 // std::vector<std::string> argv;
45 bool graphical_dialog;
48 std::map<std::string,std::string> param_map;
52 IMPLEMENT_APP(wxBBIApp);
54 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
56 parser.SetDesc(cmdLineDesc);
59 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
61 debug = ( parser.Found(_T("d")) );
62 quiet = ( parser.Found(_T("q")) );
63 help = ( parser.Found(_T("h")) );
64 graphical_dialog = ( parser.Found(_T("g")) );
65 text_dialog = ( parser.Found(_T("t")) );
67 // parse the arguments and consider those which contain a "="
68 // as set input commands
69 int argc = parser.GetParamCount();
70 for (int i=0; i<argc; ++i)
72 std::string s = bbtk::wx2std(parser.GetParam(i));
73 std::string::size_type pos = s.find_first_of("=");
74 if (std::string::npos != pos)
76 std::string left = s.substr(0,pos);
77 std::string right = s.substr(pos+1,s.size());
78 param_map[left]=right;
82 std::cout << "'" << s << "' option unrecognized : ignored"<<std::endl;
87 std::cout << bbtk::wx2std(parser.GetParam(0)) << std::endl;
96 // ----------------------------------------------------------------------------
97 // The `main program' equivalent, creating the windows and returning the
99 bool wxBBIApp::OnInit( )
101 // std::cout << "OnInit"<<std::endl;
104 //See http://www.wxwindows.org/faqgtk.htm#locale
105 setlocale(LC_NUMERIC, "C");
108 if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
109 if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
111 // Creates the parent window of all bbtk windows
112 bbtk::Wx::CreateTopWindow();
115 mExecuter = bbtk::Executer::New();
116 mExecuter->SetInputs(param_map);
118 if (help) mExecuter->SetNoExecMode(true);
120 if (graphical_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
121 if (text_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::TextDialog);
123 EXEC_FUNCTION(mExecuter);
125 mExecuter->SetNoExecMode(false);
130 mExecuter->GetFactory()->HelpBlackBox("workspace",package,false);
133 catch (bbtk::Exception e)
136 mess += bbtk::std2wx ( e.GetMessage() );
137 wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
138 bbtk::Wx::GetTopWindow()->Close();
141 if (help || !bbtk::Wx::IsSomeWindowAlive())
151 // How to have a Console and wxWidgets
152 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
153 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
154 // (cout's to the console are visible) and has a wxWidgets GUI,
155 // you need to use the linker option "/subsystem:console" and the following code:
156 int main(int argc, char* argv[])
158 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
162 #endif // defined(_WIN32)
166 //==========================================================================
168 //==========================================================================
170 #include "bbtkInterpreter.h"
172 int main(int argc, char* argv[])
175 if (argc>2) return 0;
177 std::cout << "BBI (Black Box Interpreter) - bbtk "
178 << bbtk::GetVersion()<< " - (c) Creatis 2007"
184 I.CommandLineInterpreter();
188 std::string f(argv[1]);
197 #endif //#ifdef _USE_WXWIDGETS_