00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "flexilog.h"
00013 #include <wx/display.h>
00014 #include <wx/image.h>
00015 #include "interpreter.h"
00016 #include "kernel.h"
00017 #include "mainwindow.h"
00018 #include "rendermanager.h"
00019 #include "commands.h"
00020 #include "textparser.h"
00021 #include "textwriter.h"
00022 #include "basedefs.h"
00023
00024 using namespace VRUT;
00025
00026
00027 Interpreter::Interpreter()
00028 {
00030 ArgList args;
00032 commandEntries.insert(CommandEntries::value_type(CMD_EXIT, args));
00034 args.clear();
00035 args.push_back(Argument(wxT("moduleName"), ARG_STRING, true));
00036 commandEntries.insert(CommandEntries::value_type(CMD_USEMODULE, args));
00038 args.clear();
00039 args.push_back(Argument(wxT("moduleName"), ARG_STRING, true));
00040 commandEntries.insert(CommandEntries::value_type(CMD_FORBIDMODULE, args));
00042 args.clear();
00043 args.push_back(Argument(wxT("moduleName"), ARG_STRING, true));
00044 commandEntries.insert(CommandEntries::value_type(CMD_RUNMODULE, args));
00046 args.clear();
00047 args.push_back(Argument(wxT("fileName"), ARG_STRING, true));
00048 commandEntries.insert(CommandEntries::value_type(CMD_IMPORTSCENE, args));
00050 args.clear();
00051 args.push_back(Argument(wxT("sceneID"), ARG_UNSIGNED, true));
00052 args.push_back(Argument(wxT("fileName"), ARG_STRING, true));
00053 commandEntries.insert(CommandEntries::value_type(CMD_EXPORTSCENE, args));
00055 args.clear();
00056 commandEntries.insert(CommandEntries::value_type(CMD_LISTSCENES, args));
00058 args.clear();
00059 args.push_back(Argument(wxT("sceneID"), ARG_UNSIGNED, true));
00060 commandEntries.insert(CommandEntries::value_type(CMD_RENDERSCENE, args));
00062 args.clear();
00063 args.push_back(Argument(wxT("sceneID"), ARG_UNSIGNED, true));
00064 commandEntries.insert(CommandEntries::value_type(CMD_SAVEGRAPHVIZ, args));
00066 args.clear();
00067 args.push_back(Argument(wxT("sceneID"), ARG_UNSIGNED, true));
00068 commandEntries.insert(CommandEntries::value_type(CMD_DUMPSCENE, args));
00070 args.clear();
00071 args.push_back(Argument(wxT("module[.param[.instID]]"), ARG_STRING, true));
00072 args.push_back(Argument(wxT("value"), ARG_STRING, true));
00073 args.push_back(Argument(wxT("default"), ARG_BOOL, false));
00074 commandEntries.insert(CommandEntries::value_type(CMD_SETPARAM, args));
00076 args.clear();
00077 args.push_back(Argument(wxT("module[.param[.instID]]"), ARG_STRING, false));
00078 commandEntries.insert(CommandEntries::value_type(CMD_GETPARAM, args));
00080 args.clear();
00081 args.push_back(Argument(wxT("windowID"), ARG_UNSIGNED, true));
00082 commandEntries.insert(CommandEntries::value_type(CMD_FIT, args));
00084 args.clear();
00085 args.push_back(Argument(wxT("windowID"), ARG_UNSIGNED, true));
00086 args.push_back(Argument(wxT("enable"), ARG_BOOL, false));
00087 commandEntries.insert(CommandEntries::value_type(CMD_FULLSCREEN, args));
00089 args.clear();
00090 args.push_back(Argument(wxT("windowID"), ARG_UNSIGNED, true));
00091 commandEntries.insert(CommandEntries::value_type(CMD_RESETVIEW, args));
00093 args.clear();
00094 args.push_back(Argument(wxT("loglevel"), ARG_STRING, true));
00095 commandEntries.insert(CommandEntries::value_type(CMD_SETLOGLEVEL, args));
00097 args.clear();
00098 commandEntries.insert(CommandEntries::value_type(CMD_LISTMODULES, args));
00100 args.clear();
00101 args.push_back(Argument(wxT("module"), ARG_STRING, false));
00102 commandEntries.insert(CommandEntries::value_type(CMD_MODHELP, args));
00104 args.clear();
00105 args.push_back(Argument(wxT("path"), ARG_STRING, false));
00106 commandEntries.insert(CommandEntries::value_type(CMD_LS, args));
00108 args.clear();
00109 args.push_back(Argument(wxT("displayID"), ARG_UNSIGNED, false));
00110 commandEntries.insert(CommandEntries::value_type(CMD_GETVIDEOMODES, args));
00112 args.clear();
00113 args.push_back(Argument(wxT("displayID"), ARG_UNSIGNED, true));
00114 args.push_back(Argument(wxT("width"), ARG_UNSIGNED, true));
00115 args.push_back(Argument(wxT("height"), ARG_UNSIGNED, true));
00116 args.push_back(Argument(wxT("bpp"), ARG_UNSIGNED, true));
00117 args.push_back(Argument(wxT("refresh"), ARG_UNSIGNED, true));
00118 commandEntries.insert(CommandEntries::value_type(CMD_SETVIDEOMODE, args));
00120 args.clear();
00121 args.push_back(Argument(wxT("displayID"), ARG_UNSIGNED, true));
00122 args.push_back(Argument(wxT("width"), ARG_UNSIGNED, true));
00123 args.push_back(Argument(wxT("height"), ARG_UNSIGNED, true));
00124 args.push_back(Argument(wxT("bpp"), ARG_UNSIGNED, true));
00125 args.push_back(Argument(wxT("refresh"), ARG_UNSIGNED, true));
00126 commandEntries.insert(CommandEntries::value_type(CMD_SWITCHVIDEOOUTS, args));
00128 args.clear();
00129 args.push_back(Argument(wxT("texturepath"), ARG_STRING, false));
00130 args.push_back(Argument(wxT("ratiox"), ARG_UNSIGNED, true));
00131 args.push_back(Argument(wxT("ratioy"), ARG_UNSIGNED, true));
00132 commandEntries.insert(CommandEntries::value_type(CMD_CARDISPLAY, args));
00134 args.clear();
00135 args.push_back(Argument(wxT("panename"), ARG_STRING, true));
00136 args.push_back(Argument(wxT("show"), ARG_BOOL, true));
00137 commandEntries.insert(CommandEntries::value_type(CMD_SHOWPANE, args));
00139 args.clear();
00140 args.push_back(Argument(wxT("paramname"), ARG_STRING, true));
00141 args.push_back(Argument(wxT("show"), ARG_BOOL, true));
00142 commandEntries.insert(CommandEntries::value_type(CMD_SHOWPARAM, args));
00144 args.clear();
00145 args.push_back(Argument(wxT("Z"), ARG_FLOAT, true));
00146 args.push_back(Argument(wxT("X"), ARG_FLOAT, true));
00147 args.push_back(Argument(wxT("Z"), ARG_FLOAT, true));
00148 commandEntries.insert(CommandEntries::value_type(CMD_EULER313TOAXISANGLE, args));
00150 args.clear();
00151 args.push_back(Argument(wxT("adamsfile"), ARG_STRING, true));
00152 commandEntries.insert(CommandEntries::value_type(CMD_ADAMSTODELTAGEN, args));
00154 args.clear();
00155 commandEntries.insert(CommandEntries::value_type(CMD_HELP, args));
00156 }
00157
00158
00159 Interpreter::~Interpreter()
00160 {
00161 }
00162
00163
00164 wxString Interpreter::getUsageString(CommandEntries::const_iterator cmdEntry) const
00165 {
00166 wxString usage(cmdEntry->first);
00167 for (ArgList::const_iterator arg = cmdEntry->second.begin(); arg != cmdEntry->second.end(); arg++)
00168 {
00169 wxString argStr = arg->name;
00170 switch (arg->type)
00171 {
00172 case ARG_STRING:
00173 argStr << wxT(":string");
00174 break;
00175 case ARG_INT:
00176 argStr << wxT(":integer");
00177 break;
00178 case ARG_UNSIGNED:
00179 argStr << wxT(":unsigned");
00180 break;
00181 case ARG_FLOAT:
00182 argStr << wxT(":float");
00183 break;
00184 case ARG_BOOL:
00185 argStr << wxT(":bool");
00186 break;
00187 }
00188 if (!arg->mandatory)
00189 argStr.Prepend(wxT("[")).Append(wxT("]"));
00190 usage << wxT(" ") << argStr;
00191 }
00192 return usage;
00193 }
00194
00195
00196 size_t Interpreter::GetCommandsStarting(const wxString & cmdPart, std::vector<wxString> * cmdList) const
00197 {
00198 CommandEntries::const_iterator cmd = commandEntries.begin();
00199 for ( ; cmd != commandEntries.end(); cmd++)
00200 {
00201 if (cmd->first.Lower().StartsWith(cmdPart.Lower().Trim().Trim(false)))
00202 cmdList->push_back(getUsageString(cmd));
00203 }
00204 return cmdList->size();
00205 }
00206
00207
00208 bool Interpreter::CheckSyntax(const wxString & cmd) const
00209 {
00210 if (cmd.IsEmpty())
00211 return false;
00212
00213 TextParser txtParse(cmd);
00214 wxString cmdName = txtParse.GetWxString();
00215
00216 CommandEntries::const_iterator cmdEntry = commandEntries.find(cmdName);
00217 if (cmdEntry == commandEntries.end())
00218 {
00219 LOGERROR(wxString::Format(wxT("<Interpreter>Unrecognized command: '%s'"), cmdName.c_str()));
00220 return false;
00221 }
00222
00223 for (ArgList::const_iterator arg = cmdEntry->second.begin(); arg != cmdEntry->second.end(); arg++)
00224 {
00225 if (txtParse.IsEmpty())
00226 {
00227 if (arg->mandatory)
00228 {
00229 LOGERROR(wxString::Format(wxT("<Interpreter>Not enough arguments. Usage: '%s'"), getUsageString(cmdEntry).c_str()));
00230 return false;
00231 }
00232 else
00233 return true;
00234 }
00235
00236 wxString cmdArg = txtParse.GetWxString();
00237
00238
00239 size_t quoteCount=0;
00240 for (size_t i=0; i<cmdArg.size(); i++)
00241 if (cmdArg[i]==wxT('\"'))
00242 quoteCount++;
00243 if (quoteCount==1)
00244 txtParse.GetWxString("\"");
00245
00246 bool valid = true;
00247 long tmpl;
00248 unsigned long tmpul;
00249 float tmpf;
00250 switch (arg->type)
00251 {
00252 case ARG_INT:
00253 valid = cmdArg.ToLong(&tmpl);
00254 break;
00255 case ARG_UNSIGNED:
00256 valid = cmdArg.ToULong(&tmpul);
00257 break;
00258 case ARG_FLOAT:
00259 valid = TextParser(cmdArg).myatof(tmpf);
00260 break;
00261 case ARG_STRING:
00262 case ARG_BOOL:
00263 break;
00264 }
00265
00266 if (!valid)
00267 {
00268 LOGERROR(wxString::Format(wxT("<Interpreter>Invalid argument '%s' Usage: %s"), cmdArg.c_str(), getUsageString(cmdEntry).c_str()));
00269 return false;
00270 }
00271 }
00272
00273 if (!txtParse.IsEmpty())
00274 {
00275 LOGERROR(wxString::Format(wxT("<Interpreter>Too many arguments. Usage: '%s'"), getUsageString(cmdEntry).c_str()));
00276 return false;
00277 }
00278
00279 return true;
00280 }
00281
00282
00283 bool Interpreter::ProcessCommand(const wxString &cmd)
00284 {
00285 wxString command(cmd);
00286 command.Trim().Trim(false);
00287 if (command.IsEmpty() || command.GetChar(0) == '#')
00288 return false;
00289
00290 LOG(cmd);
00291 if (CheckSyntax(command))
00292 {
00293 TextParser txtParser(command);
00294 wxString commandName = txtParser.GetWxString();
00295 if (commandName.IsSameAs(CMD_EXIT))
00296 {
00297 wxCommandEvent ev = Event::GET_EVT_EXIT();
00298 KERNEL->GetMessageSink()->PostEvent(ev, true);
00299 }
00300 else if (commandName.IsSameAs(CMD_USEMODULE))
00301 {
00302 wxCommandEvent ev = Event::GET_EVT_MODULE_PREFER(txtParser.GetWxString());
00303 KERNEL->GetMessageSink()->PostEvent(ev);
00304 }
00305 else if (commandName.IsSameAs(CMD_FORBIDMODULE))
00306 {
00307 wxCommandEvent ev = Event::GET_EVT_MODULE_FORBID(txtParser.GetWxString());
00308 KERNEL->GetMessageSink()->PostEvent(ev);
00309 }
00310 else if (commandName.IsSameAs(CMD_RUNMODULE))
00311 {
00312 wxCommandEvent ev = Event::GET_EVT_MODULE_RUN(txtParser.GetWxString());
00313 KERNEL->GetMessageSink()->PostEvent(ev);
00314 }
00315 else if (commandName.IsSameAs(CMD_IMPORTSCENE))
00316 {
00317 wxCommandEvent ev = Event::GET_EVT_IO_SCENE_IMPORT(txtParser.GetWxString());
00318 KERNEL->GetMessageSink()->PostEvent(ev);
00319 }
00320 else if (commandName.IsSameAs(CMD_EXPORTSCENE))
00321 {
00322 unsigned long argL = 0;
00323 txtParser.GetWxString().ToULong(&argL);
00324 wxCommandEvent ev = Event::GET_EVT_IO_SCENE_EXPORT(SCENE_ID(argL), txtParser.GetWxString());
00325 KERNEL->GetMessageSink()->PostEvent(ev);
00326 }
00327 else if (commandName.IsSameAs(CMD_RENDERSCENE))
00328 {
00329 unsigned long argL = 0;
00330 txtParser.GetWxString().ToULong(&argL);
00331 wxCommandEvent ev = Event::GET_EVT_RENDER_SCENE(SCENE_ID(argL));
00332 KERNEL->GetMessageSink()->PostEvent(ev);
00333 }
00334 else if (commandName.IsSameAs(CMD_LISTSCENES))
00335 {
00336 std::vector<SCENE_ID> IDlist;
00337 KERNEL->sceneManager->GetSceneIDs(IDlist);
00338 for (size_t i=0; i<IDlist.size(); i++)
00339 LOG(wxString::Format(wxT("SceneID = %i, name = %s"), IDlist[i], KERNEL->sceneManager->GetScene(IDlist[i])->GetName().c_str()));
00340 }
00341 else if (commandName.IsSameAs(CMD_SAVEGRAPHVIZ))
00342 {
00343 unsigned long argL = 0;
00344 txtParser.GetWxString().ToULong(&argL);
00345 wxCommandEvent ev = Event::GET_EVT_SCENE_GRAPHVIZ(SCENE_ID(argL));
00346 KERNEL->GetMessageSink()->PostEvent(ev);
00347 }
00348 else if (commandName.IsSameAs(CMD_DUMPSCENE))
00349 {
00350 unsigned long argL = 0;
00351 txtParser.GetWxString().ToULong(&argL);
00352 wxCommandEvent ev = Event::GET_EVT_SCENE_DUMP(SCENE_ID(argL));
00353 KERNEL->GetMessageSink()->PostEvent(ev);
00354 }
00355 else if (commandName.IsSameAs(CMD_SETPARAM))
00356 {
00357 Parameter::ParameterIdentificator pi;
00358 if (!txtParser.IsEmpty())
00359 pi.poolName = txtParser.GetWxString(". \t");
00360 if (!txtParser.IsEmpty() && (txtParser.NextCharIs('.', NULL, false)))
00361 pi.paramName = txtParser.GetWxString(". \t");
00362 if (!txtParser.IsEmpty() && (txtParser.NextCharIs('.', NULL, false)))
00363 pi.instName = txtParser.GetWxString(". \t\n\r");
00364 wxString value = txtParser.GetWxString();
00365 bool defaultPar = isTrue(txtParser.GetWxString());
00366 wxCommandEvent ev = Event::GET_EVT_PARAM_SET_DO(pi, value, defaultPar);
00367 KERNEL->GetMessageSink()->PostEvent(ev);
00368 }
00369 else if (commandName.IsSameAs(CMD_GETPARAM))
00370 {
00371 Parameter::ParameterIdentificator pi;
00372 if (!txtParser.IsEmpty())
00373 pi.poolName = txtParser.GetWxString(". \t");
00374 if (!txtParser.IsEmpty() && (txtParser.NextCharIs('.', NULL, false)))
00375 pi.paramName = txtParser.GetWxString(". \t");
00376 if (!txtParser.IsEmpty() && (txtParser.NextCharIs('.', NULL, false)))
00377 pi.instName = txtParser.GetWxString(". \t\n\r");
00378 std::vector<Environment::NameValue> vals;
00379 KERNEL->environment.GetParams(pi, &vals);
00380 for (std::vector<Environment::NameValue>::const_iterator it = vals.begin();
00381 it != vals.end(); it++)
00382 LOG(wxString::Format(wxT("%s = %s"), it->first.c_str(), it->second.c_str()));
00383 }
00384 else if (commandName.IsSameAs(CMD_FIT) || commandName.IsSameAs(CMD_RESETVIEW))
00385 {
00386 unsigned long argL = 0;
00387 txtParser.GetWxString().ToULong(&argL);
00388 const GLWindow * glw = KERNEL->renderManager->GetGLWindow(RENDER_WINDOW_ID(argL));
00389 if (glw && glw->GetRenderModule())
00390 {
00391 if (commandName.IsSameAs(CMD_FIT))
00392 {
00393 wxCommandEvent ev = Event::GET_EVT_SCENE_CAM_FIT(glw->GetRenderModule()->GetSceneID(), glw->GetRenderModule()->GetCameraID());
00394 KERNEL->GetMessageSink()->PostEvent(ev);
00395 }
00396 else
00397 {
00398 wxCommandEvent ev = Event::GET_EVT_SCENE_CAM_RESETVIEW(glw->GetRenderModule()->GetSceneID(), glw->GetRenderModule()->GetCameraID());
00399 KERNEL->GetMessageSink()->PostEvent(ev);
00400 }
00401 }
00402 else
00403 LOGERROR(wxString::Format(wxT("<Interpreter>No window with ID %i found or no render module associated with window"), argL));
00404 }
00405 else if (commandName.IsSameAs(CMD_FULLSCREEN))
00406 {
00407 unsigned long argL = 0;
00408 txtParser.GetWxString().ToULong(&argL);
00409 const GLWindow * glw = KERNEL->renderManager->GetGLWindow(RENDER_WINDOW_ID(argL));
00410
00411
00412
00413
00414
00415 if (glw)
00416 {
00417 bool fs = txtParser.IsEmpty() || isTrue(txtParser.GetWxString());
00418 wxCommandEvent ev = Event::GET_EVT_RENDER_FULLSCREEN_SET(glw->GetID(), fs);
00419 KERNEL->GetMessageSink()->PostEvent(ev);
00420 }
00421 }
00422 else if (commandName.IsSameAs(CMD_SETLOGLEVEL))
00423 {
00424 wxString value = txtParser.GetWxString().MakeLower();
00425 wxLogLevel loglevel;
00426 if (value.IsSameAs(wxT("disable")))
00427 loglevel = wxLOG_FatalError;
00428 else if (value.IsSameAs(wxT("errors")))
00429 loglevel = wxLOG_Error;
00430 else if (value.IsSameAs(wxT("warnings")))
00431 loglevel = wxLOG_Warning;
00432 else if (value.IsSameAs(wxT("messages")))
00433 loglevel = wxLOG_Message;
00434 else
00435 loglevel = wxLOG_Info;
00436 wxCommandEvent ev = Event::GET_EVT_LOG_LEVEL_SET(loglevel);
00437 KERNEL->GetMessageSink()->PostEvent(ev, true);
00438 }
00439 else if (commandName.IsSameAs(CMD_LISTMODULES))
00440 {
00441 LOG(wxT("Available modules:"));
00442 std::vector<wxFileName> mods = KERNEL->GetAvailableModules();
00443 for (std::vector<wxFileName>::iterator it = mods.begin();
00444 it != mods.end(); it++)
00445 LOG(it->GetFullPath());
00446
00447 ModuleList insts;
00448 LOG(wxT("Instances:"));
00449 KERNEL->GetModules(&insts, wxT("*"));
00450 for (ModuleList::iterator iit = insts.begin(); iit != insts.end(); iit++)
00451 LOG(wxString::Format(wxT("%s.%i (%s)"), iit->first->GetName().c_str(), iit->second, iit->first->GetID().ToString().c_str()));
00452 }
00453 else if (commandName.IsSameAs(CMD_MODHELP))
00454 {
00455 ModuleList insts;
00456 wxString modMask = wxT("*");
00457 if (!txtParser.IsEmpty())
00458 modMask = txtParser.GetWxString();
00459 KERNEL->GetModules(&insts, modMask);
00460 for (ModuleList::iterator iit = insts.begin(); iit != insts.end(); iit++)
00461 {
00462 LOG(wxString::Format(wxT("%s.%i"), iit->first->GetName().c_str(), iit->second));
00463 LOG(iit->first->GetDesc());
00464 }
00465 }
00466 else if (commandName.IsSameAs(CMD_LS))
00467 {
00468 wxString path = wxT(".");
00469 wxString mask = wxT("*");
00470 if (!txtParser.IsEmpty())
00471 {
00472 wxString arg = txtParser.GetWxString();
00473 path = arg.BeforeLast('/');
00474 if (path.IsEmpty())
00475 path = wxT(".");
00476 mask = arg.AfterLast('/');
00477 if (mask.IsEmpty())
00478 mask = wxT("*");
00479 }
00480 wxDir dir(path);
00481 if (dir.IsOpened())
00482 {
00483 wxString filename;
00484 bool cont = dir.GetFirst(&filename, mask);
00485 while (cont)
00486 {
00487 LOG(filename);
00488 cont = dir.GetNext(&filename);
00489 }
00490 }
00491 }
00492 else if (commandName.IsSameAs(CMD_GETVIDEOMODES))
00493 {
00494 unsigned long displayID = 0;
00495 txtParser.GetWxString().ToULong(&displayID);
00496 wxDisplay display(displayID);
00497 wxArrayVideoModes videomodes = display.GetModes();
00498 for (size_t i=0; i<videomodes.size(); i++)
00499 LOG(wxString::Format(wxT("Mode: %i %i %i %i"), videomodes[i].GetWidth(), videomodes[i].GetHeight(), videomodes[i].GetDepth(), videomodes[i].refresh));
00500 }
00501 else if (commandName.IsSameAs(CMD_SETVIDEOMODE))
00502 {
00503 unsigned long displayID = 0, width = 0, height = 0, bpp = 0, refresh = 0;
00504 txtParser.GetWxString().ToULong(&displayID);
00505 txtParser.GetWxString().ToULong(&width);
00506 txtParser.GetWxString().ToULong(&height);
00507 txtParser.GetWxString().ToULong(&bpp);
00508 txtParser.GetWxString().ToULong(&refresh);
00509 wxVideoMode videomode(width, height, bpp, refresh);
00510 wxDisplay display(displayID);
00511 wxArrayVideoModes videomodes=display.GetModes(videomode);
00512 if (videomodes.size()>0)
00513 {
00514 display.ChangeMode(videomodes[0]);
00515 LOG(wxString::Format(wxT("Mode: %i %i %i %i"), videomodes[0].GetWidth(), videomodes[0].GetHeight(), videomodes[0].GetDepth(), videomodes[0].refresh));
00516 }
00517 else
00518 {
00519 LOGERROR(wxT("Video mode is not valid."));
00520 display.ChangeMode(videomode);
00521 }
00522 }
00523 else if (commandName.IsSameAs(CMD_SWITCHVIDEOOUTS))
00524 {
00525
00526
00527
00528
00529
00530
00531 #ifdef __WINDOWS__
00532 unsigned long displayID = 0, width = 0, height = 0, bpp = 0, refresh = 0;
00533 txtParser.GetWxString().ToULong(&displayID);
00534 txtParser.GetWxString().ToULong(&width);
00535 txtParser.GetWxString().ToULong(&height);
00536 txtParser.GetWxString().ToULong(&bpp);
00537 txtParser.GetWxString().ToULong(&refresh);
00538 wxString origName, otherName;
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 origName=wxString::Format(wxT("\\\\.\\DISPLAY%i"), 2-displayID);
00553 otherName=wxString::Format(wxT("\\\\.\\DISPLAY%i"), displayID+1);
00554 LONG lStatus;
00555
00556 DEVMODE dm1;
00557 EnumDisplaySettings(origName.c_str(), ENUM_REGISTRY_SETTINGS, &dm1);
00558 dm1.dmFields = DM_POSITION;
00559 dm1.dmPosition.x = -(int)dm1.dmPelsWidth;
00560 dm1.dmPosition.y = 0;
00561 lStatus = ChangeDisplaySettingsEx (origName.c_str(), &dm1, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
00562 if (lStatus)
00563 LOGERROR(wxString::Format(wxT("ChangeDisplaySettingsEx 1: %i"), lStatus));
00564 lStatus = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);
00565 if (lStatus)
00566 LOGERROR(wxString::Format(wxT("ChangeDisplaySettingsEx 2: %i"), lStatus));
00567
00568
00569 DEVMODE dmode;
00570 memset(&dmode, 0, sizeof(DEVMODE));
00571 dmode.dmSize = sizeof(DEVMODE);
00572 dmode.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
00573 dmode.dmPelsWidth = width;
00574 dmode.dmPelsHeight = height;
00575 dmode.dmPosition.x = 0;
00576 dmode.dmPosition.y = 0;
00577 dmode.dmBitsPerPel = bpp;
00578 dmode.dmDisplayFrequency = refresh;
00579 lStatus = ChangeDisplaySettingsEx (otherName.c_str(), &dmode, NULL, CDS_SET_PRIMARY | CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
00580 if (lStatus)
00581 LOGERROR(wxString::Format(wxT("ChangeDisplaySettingsEx 3: %i"), lStatus));
00582
00583
00584 dm1.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
00585 dm1.dmPelsWidth = 0;
00586 dm1.dmPelsHeight = 0;
00587 dm1.dmPosition.x = 0;
00588 dm1.dmPosition.y = 0;
00589 lStatus = ChangeDisplaySettingsEx (origName.c_str(), &dm1, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
00590 if (lStatus)
00591 LOGERROR(wxString::Format(wxT("ChangeDisplaySettingsEx 4: %i"), lStatus));
00592 lStatus = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);
00593 if (lStatus)
00594 LOGERROR(wxString::Format(wxT("ChangeDisplaySettingsEx 5: %i"), lStatus));
00595 #else
00596 LOGERROR(wxT("Not supported on Linux, I need it only on Windows, sorry."));
00597 #endif
00598 }
00599 else if (commandName.IsSameAs(CMD_CARDISPLAY))
00600 {
00601 wxString texturepath = txtParser.GetWxString().MakeLower();
00602 unsigned long ratiox = 0, ratioy = 0;
00603 txtParser.GetWxString().ToULong(&ratiox);
00604 txtParser.GetWxString().ToULong(&ratioy);
00605 wxInitAllImageHandlers();
00606 wxImage image(texturepath);
00607 wxImage image_out(image.GetWidth()*(ratiox+1), image.GetHeight()*(ratioy+1));
00608 image_out.SetRGB(wxRect(0, 0, image.GetWidth()*(ratiox+1), image.GetHeight()*(ratioy+1)), 50, 50, 50);
00609 for (long i = 0; i<image.GetWidth(); i++)
00610 {
00611 for (long j = 0; j<image.GetHeight(); j++)
00612 {
00613 image_out.SetRGB(wxRect(i*(ratiox+1), j*(ratioy+1), ratiox, ratioy), image.GetRed(i,j), image.GetGreen(i,j), image.GetBlue(i,j));
00614 }
00615 }
00616 image_out.SaveFile(texturepath+wxT("_new.png"));
00617 wxImage::CleanUpHandlers();
00618 }
00619 else if (commandName.IsSameAs(CMD_SHOWPANE))
00620 {
00621 wxString paneName = txtParser.GetWxString();
00622 int paneID = -1;
00623 if (paneName.IsSameAs(wxT("Status"), false))
00624 paneID = ID_MainWin_View_Status;
00625 else if (paneName.IsSameAs(wxT("Console"), false))
00626 paneID = ID_MainWin_View_Console;
00627 else if (paneName.IsSameAs(wxT("Log"), false))
00628 paneID = ID_MainWin_View_Log;
00629 else if (paneName.IsSameAs(wxT("Render"), false))
00630 paneID = ID_MainWin_View_RenderNotebook;
00631 else if (paneName.IsSameAs(wxT("Parameters"), false))
00632 paneID = ID_MainWin_View_Parameters;
00633 wxCommandEvent evt = Event::GET_EVT_GUI_PANE_SHOW(paneID, isTrue(txtParser.GetWxString()));
00634 KERNEL->GetMessageSink()->PostEvent(evt);
00635 }
00636 else if (commandName.IsSameAs(CMD_SHOWPARAM))
00637 {
00638 wxString paramName = txtParser.GetWxString();
00639 wxCommandEvent evt = Event::GET_EVT_GUI_PARAM_SHOW(paramName, isTrue(txtParser.GetWxString()));
00640 KERNEL->GetMessageSink()->PostEvent(evt);
00641 }
00642 else if (commandName.IsSameAs(CMD_EULER313TOAXISANGLE))
00643 {
00644 float z1 = 0, x = 0, z2;
00645 txtParser.ParseFloat(&z1);
00646 txtParser.ParseFloat(&x);
00647 txtParser.ParseFloat(&z2);
00648 MATRIX mm=MATRIX::RotationZ(z1)*MATRIX::RotationX(x)*MATRIX::RotationZ(z2);
00649 VECTOR3 axis;
00650 float angle;
00651 mm.ToAxisAngle(axis, angle);
00652 LOG(wxString::Format(wxT("%g %g %g %g"), axis.x, axis.y, axis.z, angle));
00653 }
00654 else if (commandName.IsSameAs(CMD_ADAMSTODELTAGEN))
00655 {
00656 wxString adamsFile = txtParser.GetWxString();
00657 wxFileName wxFname(adamsFile);
00658 if (wxFname.FileExists())
00659 {
00660 wxInputStream * sceneStream = new wxFileInputStream(wxFname.GetFullPath());
00661 TextParser textParser(sceneStream, 10000, 1000);
00662 bool newSection=false;
00663 size_t index=0;
00664 std::vector<std::vector<float> > values;
00665 while (!textParser.IsEmpty())
00666 {
00667 TextParser textParser1(textParser.GetWxLine());
00668 float tmp[10];
00669 size_t count=textParser1.ParseVector(tmp, 10, true, " \t");
00670 if (count>0)
00671 {
00672 if (newSection)
00673 {
00674 LOG(wxT("Start new section"));
00675 newSection=false;
00676 index=0;
00677 }
00678 if (values.size()<=index)
00679 {
00680 std::vector<float> row;
00681 values.push_back(row);
00682 }
00683 for (size_t i=0; i<count; i++)
00684 values.at(index).push_back(tmp[i]);
00685 index++;
00686 }
00687 else
00688 newSection=true;
00689 }
00690
00691 wxFileName timename(adamsFile+wxT("_time.txt"));
00692 wxOutputStream * timeOS = new wxFileOutputStream(timename.GetFullPath());
00693 timeOS =new wxBufferedOutputStream(*timeOS);
00694 TextWriter timeTW((wxBufferedOutputStream*)timeOS);
00695 for (size_t i=0; i<values.size(); i++)
00696 timeTW.Write(wxT("\t\t"))->Write((float)i/(values.size()-1))->Write(wxT("\r\n"));
00697 timeOS->Sync();
00698 delete timeOS;
00699
00700 wxFileName tranname(adamsFile+wxT("_tran.txt"));
00701 wxOutputStream * tranOS = new wxFileOutputStream(tranname.GetFullPath());
00702 tranOS =new wxBufferedOutputStream(*tranOS);
00703 TextWriter tranTW((wxBufferedOutputStream*)tranOS);
00704 for (size_t i=0; i<values.size(); i++)
00705 tranTW.Write(wxT("\t\t"))->Write(values.at(i).at(0))->Write(wxT(" "))->Write(values.at(i).at(1))->Write(wxT(" "))->Write(values.at(i).at(2))->Write(wxT(" "))->Write(wxT("\r\n"));
00706 tranOS->Sync();
00707 delete tranOS;
00708
00709 wxFileName rotname(adamsFile+wxT("_rot.txt"));
00710 wxOutputStream * rotOS = new wxFileOutputStream(rotname.GetFullPath());
00711 rotOS =new wxBufferedOutputStream(*rotOS);
00712 TextWriter rotTW((wxBufferedOutputStream*)rotOS);
00713 for (size_t i=0; i<values.size(); i++)
00714 {
00715 MATRIX mm=MATRIX::RotationZ(values.at(i).at(3)/180*3.14159)*MATRIX::RotationX(values.at(i).at(4)/180*3.14159)*MATRIX::RotationZ(values.at(i).at(5)/180*3.14159);
00716 VECTOR3 axis;
00717 float angle;
00718 mm.ToAxisAngle(axis, angle);
00719 rotTW.Write(wxT("\t\t"))->Write(axis.x)->Write(wxT(" "))->Write(axis.y)->Write(wxT(" "))->Write(axis.z)->Write(wxT(" "))->Write(angle)->Write(wxT(" "))->Write(wxT("\r\n"));
00720 }
00721 rotOS->Sync();
00722 delete rotOS;
00723 }
00724 else
00725 LOGERROR(wxT("<AdamsToDeltaGen>File '") + adamsFile + wxT("' not found"));
00726 }
00727 else if (commandName.IsSameAs(CMD_HELP))
00728 {
00729 LOG(wxT("Available commands:"));
00730 CommandEntries::const_iterator cmd = commandEntries.begin();
00731 for ( ; cmd != commandEntries.end(); cmd++)
00732 {
00733 LOG(getUsageString(cmd));
00734 }
00735 }
00736 }
00737
00738 return true;
00739 }
00740
00741
00742 bool Interpreter::ExecuteScriptFile(const wxString & scriptFileName)
00743 {
00744 wxFileInputStream scriptFile(scriptFileName);
00745 if (scriptFile.IsOk())
00746 {
00747 wxTextInputStream scriptText(scriptFile);
00748 while (!scriptFile.Eof())
00749 ProcessCommand(scriptText.ReadLine());
00750
00751 return true;
00752 }
00753 return false;
00754 }