#include <algorithm>#include <iostream>#include <iomanip>#include <celutil/debug.h>#include <celutil/util.h>#include <celengine/cmdparser.h>#include "favorites.h"Include dependency graph for favorites.cpp:

Go to the source code of this file.
Functions | |
| FavoritesList * | ReadFavoritesList (istream &in) |
| void | WriteFavoritesList (FavoritesList &favorites, ostream &out) |
|
|
Definition at line 21 of file favorites.cpp. References FavoritesEntry::coordSys, DPRINTF, AssociativeArray::getBoolean(), Value::getHash(), AssociativeArray::getNumber(), AssociativeArray::getString(), Tokenizer::getStringValue(), Tokenizer::getTokenType(), Value::getType(), AssociativeArray::getVector(), FavoritesEntry::isFolder, FavoritesEntry::jd, FavoritesEntry::name, Tokenizer::nextToken(), FavoritesEntry::orientation, FavoritesEntry::parentFolder, FavoritesEntry::position, Parser::readValue(), FavoritesEntry::selectionName, Quaternion< T >::setAxisAngle(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by CelestiaCore::readFavoritesFile(). 00022 {
00023 FavoritesList* favorites = new FavoritesList();
00024 Tokenizer tokenizer(&in);
00025 Parser parser(&tokenizer);
00026
00027 while (tokenizer.nextToken() != Tokenizer::TokenEnd)
00028 {
00029 if (tokenizer.getTokenType() != Tokenizer::TokenString)
00030 {
00031 DPRINTF(0, "Error parsing favorites file.\n");
00032 for_each(favorites->begin(), favorites->end(), deleteFunc<FavoritesEntry*>());
00033 delete favorites;
00034 return NULL;
00035 }
00036
00037 FavoritesEntry* fav = new FavoritesEntry();
00038 fav->name = tokenizer.getStringValue();
00039
00040 Value* favParamsValue = parser.readValue();
00041 if (favParamsValue == NULL || favParamsValue->getType() != Value::HashType)
00042 {
00043 DPRINTF(0, "Error parsing favorites entry %s\n", fav->name.c_str());
00044 for_each(favorites->begin(), favorites->end(), deleteFunc<FavoritesEntry*>());
00045 delete favorites;
00046 if (favParamsValue != NULL)
00047 delete favParamsValue;
00048 return NULL;
00049 }
00050
00051 Hash* favParams = favParamsValue->getHash();
00052
00053 //If this is a folder, don't get any other params.
00054 if(!favParams->getBoolean("isFolder", fav->isFolder))
00055 fav->isFolder = false;
00056 if(fav->isFolder)
00057 {
00058 favorites->insert(favorites->end(), fav);
00059 continue;
00060 }
00061
00062 // Get parentFolder
00063 favParams->getString("parentFolder", fav->parentFolder);
00064
00065 // Get position
00066 Vec3d base(0.0, 0.0, 0.0);
00067 Vec3d offset(0.0, 0.0, 0.0);
00068 favParams->getVector("base", base);
00069 favParams->getVector("offset", offset);
00070 base *= 1e6;
00071 fav->position = UniversalCoord(Point3d(base.x, base.y, base.z)) + offset;
00072
00073 // Get orientation
00074 Vec3d axis(1.0, 0.0, 0.0);
00075 double angle = 0.0;
00076 favParams->getVector("axis", axis);
00077 favParams->getNumber("angle", angle);
00078 fav->orientation.setAxisAngle(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
00079 (float) angle);
00080
00081 // Get time
00082 fav->jd = 0.0;
00083 favParams->getNumber("time", fav->jd);
00084
00085 // Get the selected object
00086 favParams->getString("selection", fav->selectionName);
00087
00088 string coordSysName;
00089 favParams->getString("coordsys", coordSysName);
00090 if (coordSysName == "ecliptical")
00091 fav->coordSys = astro::Ecliptical;
00092 else if (coordSysName == "equatorial")
00093 fav->coordSys = astro::Equatorial;
00094 else if (coordSysName == "geographic")
00095 fav->coordSys = astro::Geographic;
00096 else
00097 fav->coordSys = astro::Universal;
00098
00099 favorites->insert(favorites->end(), fav);
00100 }
00101
00102 return favorites;
00103 }
|
|
||||||||||||
|
Definition at line 106 of file favorites.cpp. References FavoritesEntry::coordSys, Quaternion< T >::getAxisAngle(), FavoritesEntry::isFolder, FavoritesEntry::jd, FavoritesEntry::name, FavoritesEntry::orientation, FavoritesEntry::parentFolder, FavoritesEntry::position, FavoritesEntry::selectionName, Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z. Referenced by CelestiaCore::writeFavoritesFile(). 00107 {
00108 for (FavoritesList::const_iterator iter = favorites.begin();
00109 iter != favorites.end(); iter++)
00110 {
00111 FavoritesEntry* fav = *iter;
00112
00113 Vec3f axis;
00114 float angle = 0;
00115 fav->orientation.getAxisAngle(axis, angle);
00116
00117 Point3d base = (Point3d) fav->position;
00118 Vec3d offset = fav->position - base;
00119 base.x *= 1e-6; base.y *= 1e-6; base.z *= 1e-6;
00120
00121 out << '"' << fav->name << "\" {\n";
00122 if(fav->isFolder)
00123 out << "\tisFolder " << "true\n";
00124 else
00125 {
00126 out << "\tisFolder " << "false\n";
00127 out << "\tparentFolder \"" << fav->parentFolder << "\"\n";
00128 out << setprecision(16);
00129 out << "\tbase [ " << base.x << ' ' << base.y << ' ' << base.z << " ]\n";
00130 out << "\toffset [ " << offset.x << ' ' << offset.y << ' ' << offset.z << " ]\n";
00131 out << setprecision(6);
00132 out << "\taxis [ " << axis.x << ' ' << axis.y << ' ' << axis.z << " ]\n";
00133 out << "\tangle " << angle << '\n';
00134 out << setprecision(16);
00135 out << "\ttime " << fav->jd << '\n';
00136 out << "\tselection \"" << fav->selectionName << "\"\n";
00137 out << "\tcoordsys \"";
00138 switch (fav->coordSys)
00139 {
00140 case astro::Universal:
00141 out << "universal"; break;
00142 case astro::Ecliptical:
00143 out << "ecliptical"; break;
00144 case astro::Equatorial:
00145 out << "equatorial"; break;
00146 case astro::Geographic:
00147 out << "geographic"; break;
00148 case astro::ObserverLocal:
00149 out << "local"; break;
00150 case astro::PhaseLock:
00151 out << "phaselock"; break;
00152 case astro::Chase:
00153 out << "chase"; break;
00154 }
00155 out << "\"\n";
00156 }
00157
00158 out << "}\n\n";
00159 }
00160 }
|
1.4.1