3 //==========================================================================
5 //==========================================================================
6 #include "bbtkObject.h"
7 #include "bbtkInterpreter.h"
8 #include "bbtkWxBlackBox.h"
9 #include "bbtkWxGUIConsole.h"
11 #include <wx/cmdline.h>
16 static const wxCmdLineEntryDesc cmdLineDesc[] =
18 { wxCMD_LINE_SWITCH, _T("M"), _T("Memory debug"), _T("Display memory debug message on exit ('object -S')") },
19 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("all messages on ('message all 9')") },
20 { wxCMD_LINE_SWITCH, _T("c"), _T("console"), _T("open a console") },
21 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet ('message max 0')") },
22 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help on bbi or on workspace defined if any") },
23 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameter values using graphical dialog") },
24 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameter values in text mode") },
25 { wxCMD_LINE_SWITCH, _T("N"), _T("no-console"), _T("do not show console (even on error)") },
26 { wxCMD_LINE_PARAM, NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
32 class wxBBIApp : public wxApp
37 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
38 // bbtk::Object::PrintObjectListInfo();
40 void OnInitCmdLine(wxCmdLineParser& parser);
41 bool OnCmdLineParsed(wxCmdLineParser& parser);
42 void Run(bbtk::Interpreter*);
46 std::vector<std::string> argv;
51 bool graphical_dialog;
55 std::map<std::string,std::string> param_map;
56 std::vector<std::string> input_file;
60 IMPLEMENT_APP(wxBBIApp);
62 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
64 // std::cout << "OnInitCmdLine"<<std::endl;
65 parser.SetDesc(cmdLineDesc);
68 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
70 if (parser.Found(_T("M")))
72 bbtk::StaticInitTime::PrintObjectListInfo = true;
75 debug = ( parser.Found(_T("d")) );
76 quiet = ( parser.Found(_T("q")) );
77 help = ( parser.Found(_T("h")) );
78 graphical_dialog = ( parser.Found(_T("g")) );
79 text_dialog = ( parser.Found(_T("t")) );
80 no_console = ( parser.Found(_T("N")) );
82 // parse the arguments and consider those which contain a "="
83 // as set input commands, other as files
84 int argc = parser.GetParamCount();
85 for (int i=0; i<argc; ++i)
87 std::string s = bbtk::wx2std(parser.GetParam(i));
88 std::string::size_type pos = s.find_first_of("=");
89 if (std::string::npos != pos)
91 std::string left = s.substr(0,pos);
92 std::string right = s.substr(pos+1,s.size());
93 param_map[left]=right;
94 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
98 // std::cout << "input file = ["<<s<<"]"<<std::endl;
99 input_file.push_back(s);
103 bool usage = (help && (input_file.size()==0));
105 std::cout << "BBI (The Black Box Interpreter) - bbtk "
106 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
111 console = ( parser.Found(_T("c")) ||
112 ((input_file.size() == 0) &&
126 // ----------------------------------------------------------------------------
127 // The `main program' equivalent, creating the windows and returning the
129 bool wxBBIApp::OnInit( )
131 // std::cout << "OnInit"<<std::endl;
134 //See http://www.wxwindows.org/faqgtk.htm#locale
135 setlocale(LC_NUMERIC, "C");
139 if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
140 if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
143 bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
145 if (console) I->Show(true);
148 I->SetInputs(param_map);
150 bool help_on_script = help && (input_file.size() > 0);
151 if (help_on_script) I->SetNoExecMode(true);
153 if (graphical_dialog) I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
154 if (text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
156 std::vector<std::string>::const_iterator i;
159 for (i=input_file.begin(); i!=input_file.end(); ++i)
161 error = ! I->InterpretFile(*i);
164 bool show_on_error = error && ! no_console;
165 if (show_on_error) I->Show();
167 I->SetNoExecMode(false);
172 I->GetInterpreter()->GetExecuter()->GetFactory()->HelpBlackBox("workspace",package,false);
175 if (!(show_on_error || console || bbtk::Wx::IsSomeWindowShown() ))
186 // How to have a Console and wxWidgets
187 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
188 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
189 // (cout's to the console are visible) and has a wxWidgets GUI,
190 // you need to use the linker option "/subsystem:console" and the following code:
191 int main(int argc, char* argv[])
193 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
196 #endif // defined(_WIN32)
200 //==========================================================================
202 //==========================================================================
204 #include "bbtkInterpreter.h"
206 int main(int argc, char* argv[])
209 if (argc>2) return 0;
211 std::cout << "BBI (Black Box Interpreter) - bbtk "
212 << bbtk::GetVersion()<< " - (c) Creatis 2007"
218 I.CommandLineInterpreter();
222 std::string f(argv[1]);
231 #endif //#ifdef _USE_WXWIDGETS_