00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "app.h"
00013 #include "kernel.h"
00014 #include "flexilog.h"
00015 #include "mainwindow.h"
00016 #include "parameter.h"
00017 #ifdef USE_TEST
00018 #include "toolkitTest.h"
00019 #endif
00020
00021 using namespace VRUT;
00022
00023 IMPLEMENT_APP(VRUT::BaseApp);
00024 IMPLEMENT_DYNAMIC_CLASS(BaseApp, wxApp);
00025
00026
00027 BaseApp::BaseApp() : wxApp()
00028 {
00029 }
00030
00031
00032 BaseApp::~BaseApp()
00033 {
00034 }
00035
00036
00037 bool BaseApp::OnInit()
00038 {
00039 wxInitAllImageHandlers();
00040 MainWindow * mainWin = new MainWindow( wxT("VRUT"), wxDefaultPosition, wxSize(800, 800));
00041
00042 Kernel::Instantiate(mainWin);
00043 KERNEL->Initialize();
00044 KERNEL->GetMessageSink()->RegisterListener(mainWin, Event::EVT_LOG_LEVEL_SET);
00045 KERNEL->GetMessageSink()->RegisterListener(mainWin, Event::EVT_RENDER_FRAMERATE);
00046 KERNEL->GetMessageSink()->RegisterListener(mainWin, Event::EVT_GUI_PANE_SHOW);
00047
00048 SetTopWindow(mainWin);
00049 mainWin->SetFocus();
00050 mainWin->Show();
00051
00052 LOGDEBUG(wxT("<BaseApp>DEBUG MODE"));
00053
00055 bool ret = wxApp::OnInit();
00056
00058 wxKeyEvent evk;
00059 KERNEL->GetMessageSink()->ProcessEvent(evk);
00060
00061 return ret;
00062 }
00063
00064
00065 int BaseApp::OnExit()
00066 {
00067 return wxApp::OnExit();
00068 }
00069
00070
00071 void BaseApp::OnInitCmdLine(wxCmdLineParser & parser)
00072 {
00073 parser.AddSwitch(wxT("h"), wxT("help"), wxEmptyString, wxCMD_LINE_OPTION_HELP);
00074 parser.AddSwitch(wxT("t"), wxT("test"));
00075 parser.AddParam(wxT("script_filenames"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL);
00076 parser.AddOption(wxT("D"));
00078 parser.SetSwitchChars(wxT("-"));
00079 }
00080
00081
00082 bool BaseApp::OnCmdLineHelp(wxCmdLineParser & WXUNUSED(parser))
00083 {
00084 wxMessageOutput * msgOut = wxMessageOutput::Get();
00085 if (msgOut)
00086 {
00087 wxString usage;
00088 usage << wxT("Usage: vrut [-h] [-t] [-D<param>=<value>] [<script_filenames>...]\n");
00089 usage << wxT(" -h, --help \tdisplay help on the command line parameters\n");
00090 usage << wxT(" -t, --test \tdo automatic tests and exit\n");
00091 usage << wxT(" -D<owner.param>=<value>\tdefine parameter value,\n");
00092 usage << wxT(" \tif parameter belongs to module use $moduleName.$paramName=$value (eg. '-DRenderGL.drawBVH=1' )\n");
00093 usage << wxT(" \tif parameter belongs to kernel use kernel.$paramName=$value (eg. '-Dkernel.evtsPerIteration=256' )\n");
00094 msgOut->Printf(usage);
00095 }
00096 return false;
00097 }
00098
00099
00100 bool BaseApp::OnCmdLineError(wxCmdLineParser & parser)
00101 {
00102 return OnCmdLineHelp(parser);
00103 }
00104
00105
00106 bool BaseApp::OnCmdLineParsed(wxCmdLineParser & parser)
00107 {
00108 #ifdef USE_TEST
00109 if (parser.Found(wxT("t")))
00110 {
00111 runToolkitTest();
00112 delete mainWin;
00113 }
00114 #endif
00115
00116 for (int i = 1; i < argc; i++)
00117 {
00118 wxString parval;
00119 if (wxString(argv[i]).StartsWith(wxT("-D"), &parval))
00120 {
00121 Parameter::ParameterIdentificator pi = Parameter::ParameterIdentificator::FromParamName(parval.BeforeFirst('='));
00122 if (pi.IsValid())
00123 KERNEL->environment.SetParam(pi, parval.AfterFirst('='), true);
00124 else
00125 LOGERROR(wxString::Format(wxT("<BaseApp>Set parameter command line argument error. Invalid parameter name: '%s'"), parval.BeforeFirst('=').c_str()));
00126 }
00127 }
00128
00130 if (!KERNEL->interpreter.ExecuteScriptFile(wxT("autoexec.cfg")))
00131 LOGWARNING(wxT("Could not execute 'autoexec.cfg' script file"));
00132
00133 for (size_t i = 0; i < parser.GetParamCount(); i++)
00134 if (!KERNEL->interpreter.ExecuteScriptFile(parser.GetParam(i)))
00135 LOGWARNING((wxString::Format(wxT("Could not execute '%s' script file")), parser.GetParam(i).c_str()));
00136
00137 return true;
00138 }