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") },
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("All",0);
109 if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
111 bbtk::Wx::CreateInvisibleTopWindow();
114 mExecuter = bbtk::Executer::New();
115 mExecuter->SetInputs(param_map);
117 if (help) mExecuter->SetNoExecMode(true);
119 if (graphical_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
120 if (text_dialog) mExecuter->SetDialogMode(bbtk::VirtualExec::TextDialog);
122 EXEC_FUNCTION(mExecuter);
124 mExecuter->SetNoExecMode(false);
129 mExecuter->GetFactory()->HelpBlackBox("workspace",package,false);
132 catch (bbtk::Exception e)
135 mess += bbtk::std2wx ( e.GetMessage() );
136 wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
137 bbtk::Wx::GetTopWindow()->Close();
140 if (help || !bbtk::Wx::IsSomeWindowAlive())
150 // How to have a Console and wxWidgets
151 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
152 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
153 // (cout's to the console are visible) and has a wxWidgets GUI,
154 // you need to use the linker option "/subsystem:console" and the following code:
155 int main(int argc, char* argv[])
157 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
161 #endif // defined(_WIN32)
165 //==========================================================================
167 //==========================================================================
169 #include "bbtkInterpreter.h"
171 int main(int argc, char* argv[])
174 if (argc>2) return 0;
176 std::cout << "BBI (Black Box Interpreter) - bbtk "
177 << bbtk::GetVersion()<< " - (c) Creatis 2007"
183 I.CommandLineInterpreter();
187 std::string f(argv[1]);
196 #endif //#ifdef _USE_WXWIDGETS_