#include <cmdparser.h>
Collaboration diagram for CommandParser:

Public Member Functions | |
| CommandParser (Tokenizer &) | |
| CommandParser (std::istream &) | |
| const std::vector< std::string > * | getErrors () const |
| CommandSequence * | parse () |
| ~CommandParser () | |
Private Member Functions | |
| void | error (const string) |
| Command * | parseCommand () |
Private Attributes | |
| std::vector< std::string > | errorList |
| Parser * | parser |
| Tokenizer * | tokenizer |
|
|
Definition at line 39 of file cmdparser.cpp. References parser, and tokenizer.
|
|
|
Definition at line 45 of file cmdparser.cpp. References parser, and tokenizer.
|
|
|
Definition at line 51 of file cmdparser.cpp. References parser, and tokenizer.
|
|
|
Definition at line 111 of file cmdparser.cpp. References errorList. Referenced by parse(), and parseCommand().
|
|
|
Definition at line 105 of file cmdparser.cpp. References errorList. Referenced by HandleOpenScript(), MainWindowProc(), openScript(), CelestiaCore::runScript(), and KdeApp::slotOpenFileURL(). 00106 {
00107 return &errorList;
00108 }
|
|
|
Definition at line 58 of file cmdparser.cpp. References error(), Tokenizer::nextToken(), parseCommand(), Tokenizer::pushBack(), and tokenizer. Referenced by HandleOpenScript(), MainWindowProc(), openScript(), CelestiaCore::runScript(), and KdeApp::slotOpenFileURL(). 00059 {
00060 CommandSequence* seq = new CommandSequence();
00061
00062 if (tokenizer->nextToken() != Tokenizer::TokenBeginGroup)
00063 {
00064 error("'{' expected at start of script.");
00065 delete seq;
00066 return NULL;
00067 }
00068
00069 Tokenizer::TokenType ttype = tokenizer->nextToken();
00070 while (ttype != Tokenizer::TokenEnd && ttype != Tokenizer::TokenEndGroup)
00071 {
00072 tokenizer->pushBack();
00073 Command* cmd = parseCommand();
00074 if (cmd == NULL)
00075 {
00076 for (CommandSequence::const_iterator iter = seq->begin();
00077 iter != seq->end();
00078 iter++)
00079 {
00080 delete *iter;
00081 }
00082 delete seq;
00083 return NULL;
00084 }
00085 else
00086 {
00087 seq->insert(seq->end(), cmd);
00088 }
00089
00090 ttype = tokenizer->nextToken();
00091 }
00092
00093 if (ttype != Tokenizer::TokenEndGroup)
00094 {
00095 error("Missing '}' at end of script.");
00096 for_each(seq->begin(), seq->end(), deleteFunc<Command*>());;
00097 delete seq;
00098 return NULL;
00099 }
00100
00101 return seq;
00102 }
|
|
|
Definition at line 138 of file cmdparser.cpp. References compareIgnoringCase(), astro::Date::day, degToRad(), distance(), error(), Quaternion< T >::getAxisAngle(), Value::getHash(), AssociativeArray::getNumber(), AssociativeArray::getString(), Tokenizer::getStringValue(), Value::getType(), AssociativeArray::getVector(), astro::Date::hour, astro::kilometersToMicroLightYears(), astro::Date::minute, astro::Date::month, Tokenizer::nextToken(), parseCoordinateSystem(), parseLabelFlags(), parseOrbitFlags(), parser, parseRenderFlags(), Parser::readValue(), astro::Date::seconds, tokenizer, Vector3< T >::x, Quaternion< float >::xrotation(), Vector3< T >::y, astro::Date::year, Quaternion< float >::yrotation(), Vector3< T >::z, and Quaternion< float >::zrotation(). Referenced by parse(). 00139 {
00140 if (tokenizer->nextToken() != Tokenizer::TokenName)
00141 {
00142 error("Invalid command name");
00143 return NULL;
00144 }
00145
00146 string commandName = tokenizer->getStringValue();
00147
00148 Value* paramListValue = parser->readValue();
00149 if (paramListValue == NULL || paramListValue->getType() != Value::HashType)
00150 {
00151 error("Bad parameter list");
00152 return NULL;
00153 }
00154
00155 Hash* paramList = paramListValue->getHash();
00156 Command* cmd = NULL;
00157
00158 if (commandName == "wait")
00159 {
00160 double duration = 1.0;
00161 paramList->getNumber("duration", duration);
00162 cmd = new CommandWait(duration);
00163 }
00164 else if (commandName == "set")
00165 {
00166 double value = 0.0;
00167 string name;
00168 paramList->getString("name", name);
00169 if (!paramList->getNumber("value", value))
00170 {
00171 // Some values may be specified via strings
00172 string valstr;
00173 if (paramList->getString("value", valstr))
00174 {
00175 if (compareIgnoringCase(valstr, "fuzzypoints") == 0)
00176 value = (double) Renderer::FuzzyPointStars;
00177 else if (compareIgnoringCase(valstr, "points") == 0)
00178 value = (double) Renderer::PointStars;
00179 else if (compareIgnoringCase(valstr, "scaleddiscs") == 0)
00180 value = (double) Renderer::ScaledDiscStars;
00181 }
00182 }
00183
00184 cmd = new CommandSet(name, value);
00185 }
00186 else if (commandName == "select")
00187 {
00188 string object;
00189 paramList->getString("object", object);
00190 cmd = new CommandSelect(object);
00191 }
00192 else if (commandName == "setframe")
00193 {
00194 string refName;
00195 paramList->getString("ref", refName);
00196 string targetName;
00197 paramList->getString("target", targetName);
00198 string coordSysName;
00199 astro::CoordinateSystem coordSys = astro::Universal;
00200 if (paramList->getString("coordsys", coordSysName))
00201 coordSys = parseCoordinateSystem(coordSysName);
00202
00203 cmd = new CommandSetFrame(coordSys, refName, targetName);
00204 }
00205 else if (commandName == "setsurface")
00206 {
00207 string name;
00208 paramList->getString("name", name);
00209 cmd = new CommandSetSurface(name);
00210 }
00211 else if (commandName == "goto")
00212 {
00213 double t = 1.0;
00214 paramList->getNumber("time", t);
00215 double distance = 5.0;
00216 paramList->getNumber("distance", distance);
00217
00218 astro::CoordinateSystem upFrame = astro::ObserverLocal;
00219 string frameString;
00220 if (paramList->getString("upframe", frameString))
00221 upFrame = parseCoordinateSystem(frameString);
00222
00223 Vec3d up(0, 1, 0);
00224 paramList->getVector("up", up);
00225
00226 cmd = new CommandGoto(t,
00227 distance,
00228 Vec3f((float) up.x, (float) up.y, (float) up.z),
00229 upFrame);
00230 }
00231 else if (commandName == "gotolonglat")
00232 {
00233 double t = 1.0;
00234 paramList->getNumber("time", t);
00235 double distance = 5.0;
00236 paramList->getNumber("distance", distance);
00237 Vec3d up(0, 1, 0);
00238 paramList->getVector("up", up);
00239 double longitude;
00240 paramList->getNumber("longitude", longitude);
00241 double latitude;
00242 paramList->getNumber("latitude", latitude);
00243
00244 cmd = new CommandGotoLongLat(t,
00245 distance,
00246 (float) degToRad(longitude),
00247 (float) degToRad(latitude),
00248 Vec3f((float) up.x, (float) up.y, (float) up.z));
00249 }
00250 else if (commandName == "gotoloc")
00251 {
00252 double t = 1.0;
00253 paramList->getNumber("time", t);
00254 Vec3d pos(0, 1, 0);
00255 if (paramList->getVector("position", pos))
00256 {
00257 pos = pos * astro::kilometersToMicroLightYears(1.0);
00258 double xrot = 0.0;
00259 paramList->getNumber("xrot", xrot);
00260 double yrot = 0.0;
00261 paramList->getNumber("yrot", yrot);
00262 double zrot = 0.0;
00263 paramList->getNumber("zrot", zrot);
00264 zrot = degToRad(zrot);
00265 Quatf rotation = Quatf::xrotation((float) degToRad(xrot)) *
00266 Quatf::yrotation((float) degToRad(yrot)) *
00267 Quatf::zrotation((float) degToRad(zrot));
00268 cmd = new CommandGotoLocation(t, Point3d(0.0, 0.0, 0.0) + pos,
00269 rotation);
00270 }
00271 else
00272 {
00273 std::string x, y, z;
00274 paramList->getString("x", x);
00275 paramList->getString("y", y);
00276 paramList->getString("z", z);
00277 double ow, ox, oy, oz;
00278 paramList->getNumber("ow", ow);
00279 paramList->getNumber("ox", ox);
00280 paramList->getNumber("oy", oy);
00281 paramList->getNumber("oz", oz);
00282 Quatf orientation((float)ow, (float)ox, (float)oy, (float)oz);
00283 cmd = new CommandGotoLocation(t, Point3d((double)BigFix(x), (double)BigFix(y), (double)BigFix(z)),
00284 orientation);
00285 }
00286 }
00287 else if (commandName == "seturl")
00288 {
00289 std::string url;
00290 paramList->getString("url", url);
00291 cmd = new CommandSetUrl(url);
00292 }
00293 else if (commandName == "center")
00294 {
00295 double t = 1.0;
00296 paramList->getNumber("time", t);
00297 cmd = new CommandCenter(t);
00298 }
00299 else if (commandName == "follow")
00300 {
00301 cmd = new CommandFollow();
00302 }
00303 else if (commandName == "synchronous")
00304 {
00305 cmd = new CommandSynchronous();
00306 }
00307 else if (commandName == "lock")
00308 {
00309 cmd = new CommandLock();
00310 }
00311 else if (commandName == "chase")
00312 {
00313 cmd = new CommandChase();
00314 }
00315 else if (commandName == "track")
00316 {
00317 cmd = new CommandTrack();
00318 }
00319 else if (commandName == "cancel")
00320 {
00321 cmd = new CommandCancel();
00322 }
00323 else if (commandName == "exit")
00324 {
00325 cmd = new CommandExit();
00326 }
00327 else if (commandName == "print")
00328 {
00329 string text;
00330 string origin;
00331 int horig = -1;
00332 int vorig = -1;
00333 double hoff = 0;
00334 double voff = 0;
00335 double duration = 1.0e9;
00336 paramList->getString("text", text);
00337 paramList->getString("origin", origin);
00338 paramList->getNumber("duration", duration);
00339 paramList->getNumber("row", voff);
00340 paramList->getNumber("column", hoff);
00341 if (compareIgnoringCase(origin, "left") == 0)
00342 {
00343 horig = -1;
00344 vorig = 0;
00345 }
00346 else if (compareIgnoringCase(origin, "right") == 0)
00347 {
00348 horig = 1;
00349 vorig = 0;
00350 }
00351 else if (compareIgnoringCase(origin, "center") == 0)
00352 {
00353 horig = 0;
00354 vorig = 0;
00355 }
00356 else if (compareIgnoringCase(origin, "left") == 0)
00357 {
00358 horig = -1;
00359 vorig = 0;
00360 }
00361 else if (compareIgnoringCase(origin, "top") == 0)
00362 {
00363 horig = 0;
00364 vorig = 1;
00365 }
00366 else if (compareIgnoringCase(origin, "bottom") == 0)
00367 {
00368 horig = 0;
00369 vorig = -1;
00370 }
00371 else if (compareIgnoringCase(origin, "topright") == 0)
00372 {
00373 horig = 1;
00374 vorig = 1;
00375 }
00376 else if (compareIgnoringCase(origin, "topleft") == 0)
00377 {
00378 horig = -1;
00379 vorig = 1;
00380 }
00381 else if (compareIgnoringCase(origin, "bottomleft") == 0)
00382 {
00383 horig = -1;
00384 vorig = -1;
00385 }
00386 else if (compareIgnoringCase(origin, "bottomright") == 0)
00387 {
00388 horig = 1;
00389 vorig = -1;
00390 }
00391
00392 cmd = new CommandPrint(text,
00393 horig, vorig, (int) hoff, (int) -voff,
00394 duration);
00395 }
00396 else if (commandName == "cls")
00397 {
00398 cmd = new CommandClearScreen();
00399 }
00400 else if (commandName == "time")
00401 {
00402 double jd = 2451545;
00403 if (!paramList->getNumber("jd", jd))
00404 {
00405 std::string utc;
00406 paramList->getString("utc", utc);
00407 astro::Date date = astro::Date(0.0);
00408 sscanf(utc.c_str(), "%d-%d-%dT%d:%d:%lf",
00409 &date.year, &date.month, &date.day,
00410 &date.hour, &date.minute, &date.seconds);
00411 jd = (double)date;
00412 }
00413 cmd = new CommandSetTime(jd);
00414 }
00415 else if (commandName == "timerate")
00416 {
00417 double rate = 1.0;
00418 paramList->getNumber("rate", rate);
00419 cmd = new CommandSetTimeRate(rate);
00420 }
00421 else if (commandName == "changedistance")
00422 {
00423 double rate = 0.0;
00424 double duration = 1.0;
00425 paramList->getNumber("rate", rate);
00426 paramList->getNumber("duration", duration);
00427 cmd = new CommandChangeDistance(duration, rate);
00428 }
00429 else if (commandName == "orbit")
00430 {
00431 double rate = 0.0;
00432 double duration = 1.0;
00433 Vec3d axis;
00434 paramList->getNumber("duration", duration);
00435 paramList->getNumber("rate", rate);
00436 paramList->getVector("axis", axis);
00437 cmd = new CommandOrbit(duration,
00438 Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
00439 (float) degToRad(rate));
00440 }
00441 else if (commandName == "rotate")
00442 {
00443 double rate = 0.0;
00444 double duration = 1.0;
00445 Vec3d axis;
00446 paramList->getNumber("duration", duration);
00447 paramList->getNumber("rate", rate);
00448 paramList->getVector("axis", axis);
00449 cmd = new CommandRotate(duration,
00450 Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
00451 (float) degToRad(rate));
00452 }
00453 else if (commandName == "move")
00454 {
00455 Vec3d velocity;
00456 double duration;
00457 paramList->getNumber("duration", duration);
00458 paramList->getVector("velocity", velocity);
00459 cmd = new CommandMove(duration, velocity * astro::kilometersToMicroLightYears(1.0));
00460 }
00461 else if (commandName == "setposition")
00462 {
00463 Vec3d base, offset;
00464 if (paramList->getVector("base", base))
00465 {
00466 paramList->getVector("offset", offset);
00467 cmd = new CommandSetPosition(astro::universalPosition(Point3d(offset.x, offset.y, offset.z),
00468 Point3f((float) base.x, (float) base.y, (float) base.z)));
00469 }
00470 else
00471 {
00472 std::string x, y, z;
00473 paramList->getString("x", x);
00474 paramList->getString("y", y);
00475 paramList->getString("z", z);
00476 cmd = new CommandSetPosition(UniversalCoord(BigFix(x), BigFix(y), BigFix(z)));
00477 }
00478 }
00479 else if (commandName == "setorientation")
00480 {
00481 Vec3d axis;
00482 double angle;
00483 if (paramList->getNumber("angle", angle))
00484 {
00485 paramList->getVector("axis", axis);
00486 cmd = new CommandSetOrientation(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
00487 (float) degToRad(angle));
00488 }
00489 else
00490 {
00491 double ow, ox, oy, oz;
00492 paramList->getNumber("ow", ow);
00493 paramList->getNumber("ox", ox);
00494 paramList->getNumber("oy", oy);
00495 paramList->getNumber("oz", oz);
00496 Quatf orientation((float)ow, (float)ox, (float)oy, (float)oz);
00497 Vec3f axis;
00498 float angle;
00499 orientation.getAxisAngle(axis, angle);
00500 cmd = new CommandSetOrientation(axis, angle);
00501 }
00502 }
00503 else if (commandName == "lookback")
00504 {
00505 cmd = new CommandLookBack();
00506 }
00507 else if (commandName == "renderflags")
00508 {
00509 int setFlags = 0;
00510 int clearFlags = 0;
00511 string s;
00512
00513 if (paramList->getString("set", s))
00514 setFlags = parseRenderFlags(s);
00515 if (paramList->getString("clear", s))
00516 clearFlags = parseRenderFlags(s);
00517
00518 cmd = new CommandRenderFlags(setFlags, clearFlags);
00519 }
00520 else if (commandName == "labels")
00521 {
00522 int setFlags = 0;
00523 int clearFlags = 0;
00524 string s;
00525
00526 if (paramList->getString("set", s))
00527 setFlags = parseLabelFlags(s);
00528 if (paramList->getString("clear", s))
00529 clearFlags = parseLabelFlags(s);
00530
00531 cmd = new CommandLabels(setFlags, clearFlags);
00532 }
00533 else if (commandName == "orbitflags")
00534 {
00535 int setFlags = 0;
00536 int clearFlags = 0;
00537 string s;
00538
00539 if (paramList->getString("set", s))
00540 setFlags = parseOrbitFlags(s);
00541 if (paramList->getString("clear", s))
00542 clearFlags = parseOrbitFlags(s);
00543
00544 cmd = new CommandOrbitFlags(setFlags, clearFlags);
00545 }
00546 else if (commandName == "setvisibilitylimit")
00547 {
00548 double mag = 6.0;
00549 paramList->getNumber("magnitude", mag);
00550 cmd = new CommandSetVisibilityLimit(mag);
00551 }
00552 else if (commandName == "setfaintestautomag45deg")
00553 {
00554 double mag = 8.5;
00555 paramList->getNumber("magnitude", mag);
00556 cmd = new CommandSetFaintestAutoMag45deg(mag);
00557 }
00558 else if (commandName == "setambientlight")
00559 {
00560 double brightness = 0.0;
00561 paramList->getNumber("brightness", brightness);
00562 cmd = new CommandSetAmbientLight((float) brightness);
00563 }
00564 else if (commandName == "preloadtex")
00565 {
00566 string object;
00567 paramList->getString("object", object);
00568 cmd = new CommandPreloadTextures(object);
00569 }
00570 else if (commandName == "mark")
00571 {
00572 string object;
00573 paramList->getString("object", object);
00574 double size = 10.0f;
00575 paramList->getNumber("size", size);
00576 Vec3d colorv(1.0f, 0.0f, 0.0f);
00577 paramList->getVector("color", colorv);
00578 Color color((float) colorv.x, (float) colorv.y, (float) colorv.z, 0.9f);
00579
00580 Marker::Symbol symbol = Marker::Diamond;
00581 string symbolString;
00582 if (paramList->getString("symbol", symbolString))
00583 {
00584 if (compareIgnoringCase(symbolString, "diamond") == 0)
00585 symbol = Marker::Diamond;
00586 else if (compareIgnoringCase(symbolString, "square") == 0)
00587 symbol = Marker::Square;
00588 else if (compareIgnoringCase(symbolString, "triangle") == 0)
00589 symbol = Marker::Triangle;
00590 else if (compareIgnoringCase(symbolString, "plus") == 0)
00591 symbol = Marker::Plus;
00592 else if (compareIgnoringCase(symbolString, "x") == 0)
00593 symbol = Marker::X;
00594 }
00595
00596 cmd = new CommandMark(object, color, (float) size, symbol);
00597 }
00598 else if (commandName == "unmark")
00599 {
00600 string object;
00601 paramList->getString("object", object);
00602 cmd = new CommandUnmark(object);
00603 }
00604 else if (commandName == "unmarkall")
00605 {
00606 cmd = new CommandUnmarkAll();
00607 }
00608 else if (commandName == "capture")
00609 {
00610 string type, filename;
00611 paramList->getString("type", type);
00612 paramList->getString("filename", filename);
00613
00614 cmd = new CommandCapture(type, filename);
00615 }
00616 else if (commandName == "renderpath")
00617 {
00618 GLContext::GLRenderPath glcpath = GLContext::GLPath_Basic;
00619 string path;
00620 paramList->getString("path", path);
00621
00622 if (compareIgnoringCase(path, "basic") == 0)
00623 glcpath = GLContext::GLPath_Basic;
00624 else if (compareIgnoringCase(path, "multitexture") == 0)
00625 glcpath = GLContext::GLPath_Multitexture;
00626 else if (compareIgnoringCase(path, "vp") == 0)
00627 glcpath = GLContext::GLPath_DOT3_ARBVP;
00628 else if (compareIgnoringCase(path, "vp-nv") == 0)
00629 glcpath = GLContext::GLPath_NvCombiner_ARBVP;
00630 else if (compareIgnoringCase(path, "glsl") == 0)
00631 glcpath = GLContext::GLPath_GLSL;
00632
00633 cmd = new CommandRenderPath(glcpath);
00634 }
00635 else
00636 {
00637 error("Unknown command name '" + commandName + "'");
00638 cmd = NULL;
00639 }
00640
00641 delete paramListValue;
00642
00643 return cmd;
00644 }
|
|
|
Definition at line 36 of file cmdparser.h. Referenced by error(), and getErrors(). |
|
|
Definition at line 34 of file cmdparser.h. Referenced by CommandParser(), parseCommand(), and ~CommandParser(). |
|
|
Definition at line 35 of file cmdparser.h. Referenced by CommandParser(), parse(), parseCommand(), and ~CommandParser(). |
1.4.1