Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

cmdparser.cpp

Go to the documentation of this file.
00001 // cmdparser.cpp
00002 //
00003 // Parse Celestia command files and turn them into CommandSequences.
00004 //
00005 // Copyright (C) 2001 Chris Laurel <claurel@shatters.net>
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 
00012 #include <algorithm>
00013 #include <cstdio>
00014 
00015 #include "celestia.h"
00016 // Ugh . . . the C++ standard says that stringstream should be in
00017 // sstream, but the GNU C++ compiler uses strstream instead.
00018 #ifdef HAVE_SSTREAM
00019 #include <sstream>
00020 #else
00021 #include <strstream>
00022 #endif // HAVE_SSTREAM
00023 
00024 #include <celutil/util.h>
00025 #include <celutil/debug.h>
00026 #include <celmath/mathlib.h>
00027 #include <celengine/astro.h>
00028 #include "astro.h"
00029 #include "cmdparser.h"
00030 #include "glcontext.h"
00031 
00032 using namespace std;
00033 
00034 
00035 static int parseRenderFlags(string);
00036 static int parseLabelFlags(string);
00037 static int parseOrbitFlags(string);
00038 
00039 CommandParser::CommandParser(istream& in)
00040 {
00041     tokenizer = new Tokenizer(&in);
00042     parser = new Parser(tokenizer);
00043 }
00044 
00045 CommandParser::CommandParser(Tokenizer& tok)
00046 {
00047     tokenizer = &tok;
00048     parser = new Parser(tokenizer);
00049 }
00050 
00051 CommandParser::~CommandParser()
00052 {
00053     delete parser;
00054     delete tokenizer;
00055 }
00056 
00057 
00058 CommandSequence* CommandParser::parse()
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 }
00103 
00104 
00105 const vector<string>* CommandParser::getErrors() const
00106 {
00107     return &errorList;
00108 }
00109 
00110 
00111 void CommandParser::error(const string errMsg)
00112 {
00113     errorList.insert(errorList.end(), errMsg);
00114 }
00115 
00116 
00117 static astro::CoordinateSystem parseCoordinateSystem(const string& name)
00118 {
00119     if (compareIgnoringCase(name, "observer") == 0)
00120         return astro::ObserverLocal;
00121     else if (compareIgnoringCase(name, "geographic") == 0)
00122         return astro::Geographic;
00123     else if (compareIgnoringCase(name, "equatorial") == 0)
00124         return astro::Equatorial;
00125     else if (compareIgnoringCase(name, "ecliptical") == 0)
00126         return astro::Ecliptical;
00127     else if (compareIgnoringCase(name, "universal") == 0)
00128         return astro::Universal;
00129     else if (compareIgnoringCase(name, "lock") == 0)
00130         return astro::PhaseLock;
00131     else if (compareIgnoringCase(name, "chase") == 0)
00132         return astro::Chase;
00133     else
00134         return astro::ObserverLocal;
00135 }
00136 
00137 
00138 Command* CommandParser::parseCommand()
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 }
00645 
00646 
00647 int parseRenderFlags(string s)
00648 {
00649 #ifdef HAVE_SSTREAM    
00650     istringstream in(s);
00651 #else
00652     istrstream in(s.c_str());
00653 #endif
00654     Tokenizer tokenizer(&in);
00655     int flags = 0;
00656 
00657     Tokenizer::TokenType ttype = tokenizer.nextToken();
00658     while (ttype != Tokenizer::TokenEnd)
00659     {
00660         if (ttype == Tokenizer::TokenName)
00661         {
00662             string name = tokenizer.getNameValue();
00663             if (compareIgnoringCase(name, "orbits") == 0)
00664                 flags |= Renderer::ShowOrbits;
00665             else if (compareIgnoringCase(name, "cloudmaps") == 0)
00666                 flags |= Renderer::ShowCloudMaps;
00667             else if (compareIgnoringCase(name, "constellations") == 0)
00668                 flags |= Renderer::ShowDiagrams;
00669             else if (compareIgnoringCase(name, "galaxies") == 0)
00670                 flags |= Renderer::ShowGalaxies;
00671             else if (compareIgnoringCase(name, "nebulae") == 0)
00672                 flags |= Renderer::ShowNebulae;
00673             else if (compareIgnoringCase(name, "planets") == 0)
00674                 flags |= Renderer::ShowPlanets;
00675             else if (compareIgnoringCase(name, "stars") == 0)
00676                 flags |= Renderer::ShowStars;
00677             else if (compareIgnoringCase(name, "nightmaps") == 0)
00678                 flags |= Renderer::ShowNightMaps;
00679             else if (compareIgnoringCase(name, "eclipseshadows") == 0)
00680                 flags |= Renderer::ShowEclipseShadows;
00681             else if (compareIgnoringCase(name, "ringshadows") == 0)
00682                 flags |= Renderer::ShowRingShadows;
00683             else if (compareIgnoringCase(name, "comettails") == 0)
00684                 flags |= Renderer::ShowCometTails;
00685             else if (compareIgnoringCase(name, "boundaries") == 0)
00686                 flags |= Renderer::ShowBoundaries;
00687             else if (compareIgnoringCase(name, "markers") == 0)
00688                 flags |= Renderer::ShowMarkers;
00689             else if (compareIgnoringCase(name, "automag") == 0)
00690                 flags |= Renderer::ShowAutoMag;
00691             else if (compareIgnoringCase(name, "atmospheres") == 0)
00692                 flags |= Renderer::ShowAtmospheres;
00693             else if (compareIgnoringCase(name, "grid") == 0)
00694                 flags |= Renderer::ShowCelestialSphere;
00695             else if (compareIgnoringCase(name, "partialtrajectories") == 0)
00696                 flags |= Renderer::ShowPartialTrajectories;
00697 
00698             ttype = tokenizer.nextToken();
00699             if (ttype == Tokenizer::TokenBar)
00700                 ttype = tokenizer.nextToken();
00701         }
00702         else
00703         {
00704             DPRINTF(0, "Command Parser: error parsing render flags\n");
00705             return 0;
00706         }
00707     }
00708 
00709     return flags;
00710 }
00711 
00712 
00713 int parseLabelFlags(string s)
00714 {
00715 #ifdef HAVE_SSTREAM
00716     istringstream in(s);
00717 #else
00718     istrstream in(s.c_str());
00719 #endif
00720     Tokenizer tokenizer(&in);
00721     int flags = 0;
00722 
00723     Tokenizer::TokenType ttype = tokenizer.nextToken();
00724     while (ttype != Tokenizer::TokenEnd)
00725     {
00726         if (ttype == Tokenizer::TokenName)
00727         {
00728             string name = tokenizer.getNameValue();
00729             if (compareIgnoringCase(name, "planets") == 0)
00730                 flags |= Renderer::PlanetLabels;
00731             else if (compareIgnoringCase(name, "moons") == 0)
00732                 flags |= Renderer::MoonLabels;
00733             else if (compareIgnoringCase(name, "spacecraft") == 0)
00734                 flags |= Renderer::SpacecraftLabels;
00735             else if (compareIgnoringCase(name, "asteroids") == 0)
00736                 flags |= Renderer::AsteroidLabels;
00737             else if (compareIgnoringCase(name, "comets") == 0)
00738                 flags |= Renderer::CometLabels;
00739             else if (compareIgnoringCase(name, "constellations") == 0)
00740                 flags |= Renderer::ConstellationLabels;
00741             else if (compareIgnoringCase(name, "stars") == 0)
00742                 flags |= Renderer::StarLabels;
00743             else if (compareIgnoringCase(name, "galaxies") == 0)
00744                 flags |= Renderer::GalaxyLabels;
00745 
00746             ttype = tokenizer.nextToken();
00747             if (ttype == Tokenizer::TokenBar)
00748                 ttype = tokenizer.nextToken();
00749         }
00750         else
00751         {
00752             DPRINTF(0, "Command Parser: error parsing label flags\n");
00753             return 0;
00754         }
00755     }
00756 
00757     return flags;
00758 }
00759 
00760 
00761 int parseOrbitFlags(string s)
00762 {
00763 #ifdef HAVE_SSTREAM    
00764     istringstream in(s);
00765 #else
00766     istrstream in(s.c_str());
00767 #endif
00768     Tokenizer tokenizer(&in);
00769     int flags = 0;
00770 
00771     Tokenizer::TokenType ttype = tokenizer.nextToken();
00772     while (ttype != Tokenizer::TokenEnd)
00773     {
00774         if (ttype == Tokenizer::TokenName)
00775         {
00776             string name = tokenizer.getNameValue();
00777             if (compareIgnoringCase(name, "planet") == 0)
00778                 flags |= Body::Planet;
00779             else if (compareIgnoringCase(name, "moon") == 0)
00780                 flags |= Body::Moon;
00781             else if (compareIgnoringCase(name, "asteroid") == 0)
00782                 flags |= Body::Asteroid;
00783             else if (compareIgnoringCase(name, "comet") == 0)
00784                 flags |= Body::Comet;
00785             else if (compareIgnoringCase(name, "spacecraft") == 0)
00786                 flags |= Body::Spacecraft;
00787 
00788             ttype = tokenizer.nextToken();
00789             if (ttype == Tokenizer::TokenBar)
00790                 ttype = tokenizer.nextToken();
00791         }
00792         else
00793         {
00794             DPRINTF(0, "Command Parser: error parsing orbit flags\n");
00795             return 0;
00796         }
00797     }
00798 
00799     return flags;
00800 }

Generated on Sat Jan 14 22:30:26 2006 for Celestia by  doxygen 1.4.1