2002-11-03 13:33:30 -07:00
|
|
|
/***************************************************************************
|
|
|
|
url.cpp - description
|
|
|
|
-------------------
|
|
|
|
begin : Wed Aug 7 2002
|
|
|
|
copyright : (C) 2002 by chris
|
|
|
|
email : chris@tux.teyssier.org
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <string>
|
2008-02-20 19:25:48 -07:00
|
|
|
#include <cassert>
|
2008-05-05 13:09:31 -06:00
|
|
|
#include <sstream>
|
2009-03-17 15:57:23 -06:00
|
|
|
#include <iomanip>
|
2018-09-22 07:13:49 -06:00
|
|
|
#include <utility>
|
2019-08-28 20:29:36 -06:00
|
|
|
#include <celutil/debug.h>
|
2002-11-03 13:33:30 -07:00
|
|
|
#include "celestiacore.h"
|
2008-11-16 03:19:38 -07:00
|
|
|
#include "celutil/util.h"
|
2002-11-03 13:33:30 -07:00
|
|
|
#include "celengine/astro.h"
|
|
|
|
#include "url.h"
|
|
|
|
|
2009-07-21 22:53:15 -06:00
|
|
|
using namespace Eigen;
|
2008-05-05 13:09:31 -06:00
|
|
|
using namespace std;
|
2019-05-16 15:51:11 -06:00
|
|
|
using namespace celmath;
|
2008-05-05 13:09:31 -06:00
|
|
|
|
2018-11-16 10:34:51 -07:00
|
|
|
const unsigned int Url::CurrentVersion = 4;
|
|
|
|
constexpr const uint64_t NewRenderFlags = Renderer::ShowDwarfPlanets |
|
|
|
|
Renderer::ShowMoons |
|
|
|
|
Renderer::ShowMinorMoons |
|
|
|
|
Renderer::ShowAsteroids |
|
|
|
|
Renderer::ShowComets |
|
|
|
|
Renderer::ShowSpacecrafts;
|
2008-05-05 13:09:31 -06:00
|
|
|
|
|
|
|
|
2009-03-17 15:57:23 -06:00
|
|
|
const string getEncodedObjectName(const Selection& sel, const CelestiaCore* appCore);
|
2008-05-05 13:09:31 -06:00
|
|
|
|
|
|
|
void
|
|
|
|
CelestiaState::captureState(CelestiaCore* appCore)
|
|
|
|
{
|
|
|
|
Simulation *sim = appCore->getSimulation();
|
|
|
|
Renderer *renderer = appCore->getRenderer();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-08-05 11:31:02 -06:00
|
|
|
auto frame = sim->getFrame();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
coordSys = frame->getCoordinateSystem();
|
|
|
|
if (coordSys != ObserverFrame::Universal)
|
|
|
|
{
|
2009-03-17 15:57:23 -06:00
|
|
|
refBodyName = getEncodedObjectName(frame->getRefObject(), appCore);
|
2018-03-11 07:12:58 -06:00
|
|
|
if (coordSys == ObserverFrame::PhaseLock)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
2009-03-17 15:57:23 -06:00
|
|
|
targetBodyName = getEncodedObjectName(frame->getTargetObject(), appCore);
|
2008-05-05 13:09:31 -06:00
|
|
|
}
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
tdb = sim->getTime();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// Store the position and orientation of the observer in the current
|
|
|
|
// frame.
|
|
|
|
observerPosition = sim->getObserver().getPosition();
|
|
|
|
observerPosition = frame->convertFromUniversal(observerPosition, tdb);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2009-07-21 22:53:15 -06:00
|
|
|
Quaterniond q = sim->getObserver().getOrientation();
|
2008-05-05 13:09:31 -06:00
|
|
|
q = frame->convertFromUniversal(q, tdb);
|
2009-07-25 16:18:51 -06:00
|
|
|
observerOrientation = q.cast<float>();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
Selection tracked = sim->getTrackedObject();
|
2009-03-17 15:57:23 -06:00
|
|
|
trackedBodyName = getEncodedObjectName(tracked, appCore);
|
2008-05-05 13:09:31 -06:00
|
|
|
Selection selected = sim->getSelection();
|
2009-03-17 15:57:23 -06:00
|
|
|
selectedBodyName = getEncodedObjectName(selected, appCore);
|
2008-05-05 13:09:31 -06:00
|
|
|
fieldOfView = radToDeg(sim->getActiveObserver()->getFOV());
|
|
|
|
timeScale = (float) sim->getTimeScale();
|
|
|
|
pauseState = sim->getPauseState();
|
|
|
|
lightTimeDelay = appCore->getLightDelayActive();
|
|
|
|
renderFlags = renderer->getRenderFlags();
|
|
|
|
labelMode = renderer->getLabelMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
bool CelestiaState::loadState(std::map<std::string, std::string> params)
|
|
|
|
{
|
|
|
|
sscanf(timeString.c_str(), "%d-%d-%dT%d:%d:%lf",
|
|
|
|
&date.year, &date.month, &date.day,
|
|
|
|
&date.hour, &date.minute, &date.seconds);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
observerPosition = UniversalCoord(BigFix(params["x"]),
|
|
|
|
BigFix(params["y"]),
|
|
|
|
BigFix(params["z"]));
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
float ow = 0.0f;
|
|
|
|
float ox = 0.0f;
|
|
|
|
float oy = 0.0f;
|
|
|
|
float oz = 0.0f;
|
|
|
|
if (sscanf(params["ow"].c_str(), "%f", &ow) != 1 ||
|
|
|
|
sscanf(params["ox"].c_str(), "%f", &ox) != 1 ||
|
|
|
|
sscanf(params["oy"].c_str(), "%f", &oy) != 1 ||
|
|
|
|
sscanf(params["oz"].c_str(), "%f", &oz) != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
orientation = Quatf(ow, ox, oy, oz);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("select") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
selectedBodyName = params["select"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("track") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
trackedBodyName = params["track"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("ltd") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
lightTimeDelay = (strcmp(params["ltd"].c_str(), "1") == 0);
|
|
|
|
else
|
|
|
|
lightTimeDelay = false;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("fov") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (sscanf(params["fov"].c_str(), "%f", &fieldOfView) != 1.0f)
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("ts") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (sscanf(params["ts"].c_str(), "%f", &timeScale) != 1.0f)
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
int paused = 0;
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("p") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (sscanf(params["p"].c_str(), "%d", &paused) != 1)
|
|
|
|
return false;
|
|
|
|
if (paused != 0 && paused != 1)
|
|
|
|
return false;
|
|
|
|
pauseState = paused == 1;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// Render settings
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("rf") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (sscanf(params["rf"].c_str(), "%d", &renderFlags) != 1)
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("lm") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (sscanf(params["lm"].c_str(), "%d", &labelMode) != 1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
Url::Url(std::string str, CelestiaCore *core):
|
|
|
|
urlStr(std::move(str)),
|
2018-10-30 12:57:10 -06:00
|
|
|
appCore(core)
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string::size_type pos, endPrevious;
|
|
|
|
std::vector<Selection> bodies;
|
|
|
|
Simulation *sim = appCore->getSimulation();
|
|
|
|
std::map<std::string, std::string> params = parseUrlParams(urlStr);
|
|
|
|
|
2002-11-07 22:28:42 -07:00
|
|
|
if (urlStr.substr(0, 6) != "cel://")
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr = "";
|
|
|
|
return;
|
|
|
|
}
|
2008-05-05 13:09:31 -06:00
|
|
|
|
|
|
|
// Version labelling of cel URLs was only added in Celestia 1.5, cel URL
|
|
|
|
// version 2. Assume any URL without a version is version 1.
|
2019-05-02 10:40:32 -06:00
|
|
|
version = params.count("ver") == 0 ? 1 : (unsigned) stoi(params["ver"]);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
pos = urlStr.find('/', 6);
|
2008-05-05 13:09:31 -06:00
|
|
|
if (pos == std::string::npos)
|
2018-09-22 07:13:49 -06:00
|
|
|
pos = urlStr.find('?', 6);
|
2002-11-03 13:33:30 -07:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
if (pos == std::string::npos)
|
|
|
|
modeStr = urlStr.substr(6);
|
|
|
|
else
|
2009-03-17 15:57:23 -06:00
|
|
|
modeStr = decodeString(urlStr.substr(6, pos - 6));
|
2002-11-03 13:33:30 -07:00
|
|
|
|
2004-02-11 15:25:42 -07:00
|
|
|
if (!compareIgnoringCase(modeStr, std::string("Freeflight")))
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
mode = ObserverFrame::Universal;
|
2002-11-03 13:33:30 -07:00
|
|
|
nbBodies = 0;
|
|
|
|
}
|
2004-02-11 15:25:42 -07:00
|
|
|
else if (!compareIgnoringCase(modeStr, std::string("Follow")))
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
mode = ObserverFrame::Ecliptical;
|
2002-11-03 13:33:30 -07:00
|
|
|
nbBodies = 1;
|
|
|
|
}
|
2004-02-11 15:25:42 -07:00
|
|
|
else if (!compareIgnoringCase(modeStr, std::string("SyncOrbit")))
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
mode = ObserverFrame::BodyFixed;
|
2002-11-03 13:33:30 -07:00
|
|
|
nbBodies = 1;
|
|
|
|
}
|
2004-02-11 15:25:42 -07:00
|
|
|
else if (!compareIgnoringCase(modeStr, std::string("Chase")))
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
mode = ObserverFrame::Chase;
|
2002-11-03 13:33:30 -07:00
|
|
|
nbBodies = 1;
|
|
|
|
}
|
2004-02-11 15:25:42 -07:00
|
|
|
else if (!compareIgnoringCase(modeStr, std::string("PhaseLock")))
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
mode = ObserverFrame::PhaseLock;
|
2002-11-03 13:33:30 -07:00
|
|
|
nbBodies = 2;
|
|
|
|
}
|
2004-02-11 15:25:42 -07:00
|
|
|
else if (!compareIgnoringCase(modeStr, std::string("Settings")))
|
2003-05-31 11:40:19 -06:00
|
|
|
{
|
|
|
|
type = Settings;
|
|
|
|
nbBodies = 0;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-07 22:28:42 -07:00
|
|
|
if (nbBodies == -1)
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr = "";
|
|
|
|
return; // Mode not recognized
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
endPrevious = pos;
|
|
|
|
int nb = nbBodies, i=1;
|
2002-12-09 14:24:12 -07:00
|
|
|
while (nb != 0 && endPrevious != std::string::npos) {
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string bodyName="";
|
2018-09-22 07:13:49 -06:00
|
|
|
pos = urlStr.find('/', endPrevious + 1);
|
|
|
|
if (pos == std::string::npos) pos = urlStr.find('?', endPrevious + 1);
|
2002-11-03 13:33:30 -07:00
|
|
|
if (pos == std::string::npos) bodyName = urlStr.substr(endPrevious + 1);
|
|
|
|
else bodyName = urlStr.substr(endPrevious + 1, pos - endPrevious - 1);
|
|
|
|
endPrevious = pos;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2009-03-17 15:57:23 -06:00
|
|
|
bodyName = decodeString(bodyName);
|
2002-11-03 13:33:30 -07:00
|
|
|
pos = 0;
|
|
|
|
if (i==1) body1 = bodyName;
|
|
|
|
if (i==2) body2 = bodyName;
|
|
|
|
while(pos != std::string::npos) {
|
|
|
|
pos = bodyName.find(":", pos + 1);
|
|
|
|
if (pos != std::string::npos) bodyName[pos]='/';
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
bodies.push_back(sim->findObjectFromPath(bodyName));
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
nb--;
|
|
|
|
i++;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-12-09 14:24:12 -07:00
|
|
|
if (nb != 0) {
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr = "";
|
|
|
|
return; // Number of bodies in Url doesn't match Mode
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-02-08 14:46:02 -07:00
|
|
|
if (nbBodies == 0) ref = ObserverFrame();
|
|
|
|
if (nbBodies == 1) ref = ObserverFrame(mode, bodies[0]);
|
|
|
|
if (nbBodies == 2) ref = ObserverFrame(mode, bodies[0], bodies[1]);
|
2002-11-03 13:33:30 -07:00
|
|
|
fromString = true;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string time="";
|
2018-09-22 07:13:49 -06:00
|
|
|
pos = urlStr.find('?', endPrevious + 1);
|
2008-05-05 13:09:31 -06:00
|
|
|
if (pos == std::string::npos)
|
|
|
|
time = urlStr.substr(endPrevious + 1);
|
2002-11-03 13:33:30 -07:00
|
|
|
else time = urlStr.substr(endPrevious + 1, pos - endPrevious -1);
|
2009-03-17 15:57:23 -06:00
|
|
|
time = decodeString(time);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
switch (version)
|
2003-05-31 11:40:19 -06:00
|
|
|
{
|
2008-05-05 13:09:31 -06:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
initVersion2(params, time);
|
2003-05-31 11:40:19 -06:00
|
|
|
break;
|
2008-05-05 13:09:31 -06:00
|
|
|
case 3:
|
2018-11-16 10:34:51 -07:00
|
|
|
case 4:
|
|
|
|
// Version 4 has only render flags defined as uint64_t
|
2008-05-05 13:09:31 -06:00
|
|
|
initVersion3(params, time);
|
2003-01-23 15:46:46 -07:00
|
|
|
break;
|
2008-05-05 13:09:31 -06:00
|
|
|
default:
|
|
|
|
urlStr = "";
|
|
|
|
return;
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
|
2003-01-23 15:46:46 -07:00
|
|
|
evalName();
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2005-11-18 02:00:39 -07:00
|
|
|
Url::Url(CelestiaCore* core, UrlType type)
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
appCore = core;
|
2008-05-05 13:09:31 -06:00
|
|
|
timeSource = UseUrlTime;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
Simulation *sim = appCore->getSimulation();
|
|
|
|
Renderer *renderer = appCore->getRenderer();
|
2003-05-06 16:13:33 -06:00
|
|
|
|
2003-01-23 15:46:46 -07:00
|
|
|
this->type = type;
|
2002-11-03 13:33:30 -07:00
|
|
|
|
2008-02-08 14:46:02 -07:00
|
|
|
modeStr = getCoordSysName(sim->getFrame()->getCoordinateSystem());
|
2003-05-31 11:40:19 -06:00
|
|
|
if (type == Settings) modeStr = "Settings";
|
2008-02-08 14:46:02 -07:00
|
|
|
ref = *sim->getFrame();
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr += "cel://" + modeStr;
|
2008-02-08 14:46:02 -07:00
|
|
|
if (type != Settings && sim->getFrame()->getCoordinateSystem() != ObserverFrame::Universal) {
|
2009-03-17 15:57:23 -06:00
|
|
|
body1 = getEncodedObjectName(sim->getFrame()->getRefObject());
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr += "/" + body1;
|
2008-02-08 14:46:02 -07:00
|
|
|
if (sim->getFrame()->getCoordinateSystem() == ObserverFrame::PhaseLock) {
|
2009-03-17 15:57:23 -06:00
|
|
|
body2 = getEncodedObjectName(sim->getFrame()->getTargetObject());
|
2002-11-03 13:33:30 -07:00
|
|
|
urlStr += "/" + body2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
double simTime = sim->getTime();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2018-10-14 06:56:04 -06:00
|
|
|
string date_str;
|
2008-05-05 13:09:31 -06:00
|
|
|
date = astro::Date(simTime);
|
2003-05-06 16:13:33 -06:00
|
|
|
|
2003-01-23 15:46:46 -07:00
|
|
|
switch (type) {
|
2003-05-06 16:13:33 -06:00
|
|
|
case Absolute:
|
2018-10-14 06:56:04 -06:00
|
|
|
date_str = fmt::sprintf("%04d-%02d-%02dT%02d:%02d:%08.5f",
|
2003-01-23 15:46:46 -07:00
|
|
|
date.year, date.month, date.day, date.hour, date.minute, date.seconds);
|
|
|
|
|
|
|
|
coord = sim->getObserver().getPosition();
|
|
|
|
urlStr += std::string("/") + date_str + "?x=" + coord.x.toString();
|
|
|
|
urlStr += "&y=" + coord.y.toString();
|
|
|
|
urlStr += "&z=" + coord.z.toString();
|
2003-05-06 16:13:33 -06:00
|
|
|
|
2009-07-25 16:18:51 -06:00
|
|
|
orientation = sim->getObserver().getOrientationf();
|
2018-10-14 06:56:04 -06:00
|
|
|
urlStr += fmt::sprintf("&ow=%f&ox=%f&oy=%f&oz=%f", orientation.w(), orientation.x(), orientation.y(), orientation.z());
|
2003-01-23 15:46:46 -07:00
|
|
|
break;
|
2003-05-06 16:13:33 -06:00
|
|
|
case Relative:
|
2003-01-23 15:46:46 -07:00
|
|
|
sim->getSelectionLongLat(distance, longitude, latitude);
|
2018-10-14 06:56:04 -06:00
|
|
|
urlStr += fmt::sprintf("/?dist=%f&long=%f&lat=%f", distance, longitude, latitude);
|
2003-01-23 15:46:46 -07:00
|
|
|
break;
|
2003-05-31 11:40:19 -06:00
|
|
|
case Settings:
|
|
|
|
urlStr += std::string("/?");
|
|
|
|
break;
|
2003-01-23 15:46:46 -07:00
|
|
|
}
|
2003-05-06 16:13:33 -06:00
|
|
|
|
2003-05-31 11:40:19 -06:00
|
|
|
switch (type) {
|
|
|
|
case Absolute: // Intentional Fall-Through
|
|
|
|
case Relative:
|
|
|
|
tracked = sim->getTrackedObject();
|
2009-03-17 15:57:23 -06:00
|
|
|
trackedStr = getEncodedObjectName(tracked);
|
2003-05-31 11:40:19 -06:00
|
|
|
if (trackedStr != "") urlStr += "&track=" + trackedStr;
|
|
|
|
|
|
|
|
selected = sim->getSelection();
|
2009-03-17 15:57:23 -06:00
|
|
|
selectedStr = getEncodedObjectName(selected);
|
2003-05-31 11:40:19 -06:00
|
|
|
if (selectedStr != "") urlStr += "&select=" + selectedStr;
|
|
|
|
|
|
|
|
fieldOfView = radToDeg(sim->getActiveObserver()->getFOV());
|
2007-01-11 12:30:04 -07:00
|
|
|
timeScale = (float) sim->getTimeScale();
|
2007-11-03 03:49:29 -06:00
|
|
|
pauseState = sim->getPauseState();
|
2003-05-31 11:40:19 -06:00
|
|
|
lightTimeDelay = appCore->getLightDelayActive();
|
2018-10-14 06:56:04 -06:00
|
|
|
urlStr += fmt::sprintf("&fov=%f&ts=%f<d=%c&p=%c&", fieldOfView,
|
|
|
|
timeScale, lightTimeDelay ? '1' : '0',
|
|
|
|
pauseState ? '1' : '0');
|
2003-05-31 11:52:31 -06:00
|
|
|
case Settings: // Intentional Fall-Through
|
2003-05-31 11:40:19 -06:00
|
|
|
renderFlags = renderer->getRenderFlags();
|
|
|
|
labelMode = renderer->getLabelMode();
|
2018-11-16 10:34:51 -07:00
|
|
|
if (version >= 4)
|
|
|
|
urlStr += fmt::sprintf("rf=%lu&lm=%d", renderFlags, labelMode);
|
|
|
|
else
|
|
|
|
urlStr += fmt::sprintf("rf=%d&lm=%d", (int) (renderFlags & 0xffffffff), labelMode);
|
2003-05-31 11:40:19 -06:00
|
|
|
break;
|
|
|
|
}
|
2002-11-03 13:33:30 -07:00
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
// Append the Celestia URL version
|
2018-10-14 06:56:04 -06:00
|
|
|
urlStr += fmt::sprintf("&ver=%u", version);
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2003-01-23 15:46:46 -07:00
|
|
|
evalName();
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
/*! Construct a new cel URL from a saved CelestiaState object. This method may
|
|
|
|
* may only be called to create a version 3 or later url.
|
|
|
|
*/
|
|
|
|
Url::Url(const CelestiaState& appState, unsigned int _version, TimeSource _timeSource)
|
|
|
|
{
|
|
|
|
ostringstream u;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
appCore = nullptr;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
assert(_version >= 3);
|
|
|
|
version = _version;
|
|
|
|
timeSource = _timeSource;
|
|
|
|
type = Absolute;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
modeStr = getCoordSysName(appState.coordSys);
|
|
|
|
body1 = appState.refBodyName;
|
|
|
|
body2 = appState.targetBodyName;
|
|
|
|
selectedStr = appState.selectedBodyName;
|
|
|
|
trackedStr = appState.trackedBodyName;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
coord = appState.observerPosition;
|
|
|
|
orientation = appState.observerOrientation;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
//ref =
|
|
|
|
//selected =
|
|
|
|
//tracked =
|
|
|
|
nbBodies = 1;
|
|
|
|
if (appState.coordSys == ObserverFrame::Universal)
|
|
|
|
nbBodies = 0;
|
|
|
|
else if (appState.coordSys == ObserverFrame::PhaseLock)
|
|
|
|
nbBodies = 2;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
fieldOfView = appState.fieldOfView;
|
|
|
|
renderFlags = appState.renderFlags;
|
|
|
|
labelMode = appState.labelMode;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
date = astro::Date(appState.tdb);
|
|
|
|
timeScale = appState.timeScale;
|
|
|
|
pauseState = appState.pauseState;
|
2018-03-11 07:12:58 -06:00
|
|
|
lightTimeDelay = appState.lightTimeDelay;
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
u << "cel://" << modeStr;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
if (appState.coordSys != ObserverFrame::Universal)
|
|
|
|
{
|
|
|
|
u << "/" << appState.refBodyName;
|
|
|
|
if (appState.coordSys == ObserverFrame::PhaseLock)
|
|
|
|
{
|
|
|
|
u << "/" << appState.targetBodyName;
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2018-10-14 06:56:04 -06:00
|
|
|
string date_str;
|
|
|
|
date_str = fmt::sprintf("%04d-%02d-%02dT%02d:%02d:%08.5f",
|
|
|
|
date.year, date.month, date.day, date.hour, date.minute, date.seconds);
|
2008-05-05 13:09:31 -06:00
|
|
|
u << "/" << date_str;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// observer position
|
|
|
|
u << "?x=" << coord.x.toString() << "&y=" << coord.y.toString() << "&z=" << coord.z.toString();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// observer orientation
|
2009-07-25 16:18:51 -06:00
|
|
|
u << "&ow=" << orientation.w()
|
|
|
|
<< "&ox=" << orientation.x()
|
|
|
|
<< "&oy=" << orientation.y()
|
|
|
|
<< "&oz=" << orientation.z();
|
2018-03-11 07:12:58 -06:00
|
|
|
|
|
|
|
if (trackedStr != "")
|
2008-05-05 13:09:31 -06:00
|
|
|
u << "&track=" << trackedStr;
|
|
|
|
if (selectedStr != "")
|
|
|
|
u << "&select=" << selectedStr;
|
|
|
|
|
|
|
|
u << "&fov=" << fieldOfView;
|
|
|
|
u << "&ts=" << timeScale;
|
|
|
|
u << "<d=" << (lightTimeDelay ? 1 : 0);
|
|
|
|
u << "&p=" << (pauseState ? 1 : 0);
|
|
|
|
|
2018-11-16 10:34:51 -07:00
|
|
|
if (_version >= 4)
|
|
|
|
u << "&rf=" << renderFlags;
|
|
|
|
else
|
|
|
|
u << "&rf=" << (int) (renderFlags & 0xffffffff);
|
2008-05-05 13:09:31 -06:00
|
|
|
u << "&lm=" << labelMode;
|
|
|
|
|
|
|
|
// Append the url settings: time source and version
|
|
|
|
u << "&tsrc=" << (int) timeSource;
|
|
|
|
u << "&ver=" << version;
|
|
|
|
|
|
|
|
urlStr = u.str();
|
|
|
|
|
|
|
|
evalName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Url::initVersion2(std::map<std::string, std::string>& params,
|
2018-03-11 07:12:58 -06:00
|
|
|
const std::string& timeString)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
if (type != Settings)
|
|
|
|
{
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("dist") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
type = Relative;
|
|
|
|
else
|
|
|
|
type = Absolute;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
switch (type) {
|
|
|
|
case Absolute:
|
|
|
|
date = astro::Date(0.0);
|
|
|
|
sscanf(timeString.c_str(), "%d-%d-%dT%d:%d:%lf",
|
|
|
|
&date.year, &date.month, &date.day,
|
|
|
|
&date.hour, &date.minute, &date.seconds);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
coord = UniversalCoord(BigFix(params["x"]),
|
|
|
|
BigFix(params["y"]),
|
|
|
|
BigFix(params["z"]));
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
float ow, ox, oy, oz;
|
2019-05-02 10:40:32 -06:00
|
|
|
ow = stof(params["ow"]);
|
|
|
|
ox = stof(params["ox"]);
|
|
|
|
oy = stof(params["oy"]);
|
|
|
|
oz = stof(params["oz"]);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2009-07-25 16:18:51 -06:00
|
|
|
orientation = Quaternionf(ow, ox, oy, oz);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// Intentional Fall-Through
|
|
|
|
case Relative:
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("dist") != 0)
|
|
|
|
distance = stof(params["dist"]);
|
|
|
|
if (params.count("long") != 0)
|
|
|
|
longitude = stof(params["long"]);
|
|
|
|
if (params.count("lat") != 0)
|
|
|
|
latitude = stof(params["lat"]);
|
|
|
|
if (params.count("select") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
selectedStr = params["select"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("track") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
trackedStr = params["track"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("fov") != 0)
|
|
|
|
fieldOfView = stof(params["fov"]);
|
|
|
|
if (params.count("ts") != 0)
|
|
|
|
timeScale = stof(params["ts"]);
|
|
|
|
|
|
|
|
lightTimeDelay = params.count("ltd") != 0 && params["ltd"] == "1";
|
|
|
|
pauseState = params.count("p") != 0 && stoi(params["p"]) == 1;
|
2008-05-05 13:09:31 -06:00
|
|
|
break;
|
|
|
|
case Settings:
|
|
|
|
break;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("rf") != 0)
|
|
|
|
{
|
|
|
|
renderFlags = static_cast<uint64_t>(stoi(params["rf"]));
|
2018-11-16 10:34:51 -07:00
|
|
|
// older celestia versions didn't know about new renderer flags
|
|
|
|
if ((renderFlags & Renderer::ShowPlanets) != 0)
|
|
|
|
renderFlags |= NewRenderFlags;
|
2008-05-05 13:09:31 -06:00
|
|
|
}
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("lm") != 0)
|
|
|
|
labelMode = stoi(params["lm"]);
|
2008-05-05 13:09:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Url::initVersion3(std::map<std::string, std::string>& params,
|
|
|
|
const std::string& timeString)
|
|
|
|
{
|
|
|
|
// Type field not used for version 3 urls; position is always relative
|
|
|
|
// to the frame center. Time setting is controlled by the time source.
|
|
|
|
type = Absolute;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
date = astro::Date(0.0);
|
|
|
|
sscanf(timeString.c_str(), "%d-%d-%dT%d:%d:%lf",
|
|
|
|
&date.year, &date.month, &date.day,
|
|
|
|
&date.hour, &date.minute, &date.seconds);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
coord = UniversalCoord(BigFix(params["x"]),
|
|
|
|
BigFix(params["y"]),
|
|
|
|
BigFix(params["z"]));
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
float ow, ox, oy, oz;
|
2019-05-02 10:40:32 -06:00
|
|
|
ow = stof(params["ow"]);
|
|
|
|
ox = stof(params["ox"]);
|
|
|
|
oy = stof(params["oy"]);
|
|
|
|
oz = stof(params["oz"]);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2009-07-25 16:18:51 -06:00
|
|
|
orientation = Quaternionf(ow, ox, oy, oz);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("select") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
selectedStr = params["select"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("track") != 0)
|
2008-05-05 13:09:31 -06:00
|
|
|
trackedStr = params["track"];
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("ltd") != 0)
|
|
|
|
lightTimeDelay = params["ltd"] == "1";
|
2008-05-05 13:09:31 -06:00
|
|
|
else
|
|
|
|
lightTimeDelay = false;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("fov") != 0)
|
|
|
|
fieldOfView = stof(params["fov"]);
|
|
|
|
if (params.count("ts") != 0)
|
|
|
|
timeScale = stof(params["ts"]);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2019-05-02 10:40:32 -06:00
|
|
|
pauseState = params.count("p") != 0 && stoi(params["p"]) == 1;
|
2008-05-05 13:09:31 -06:00
|
|
|
|
|
|
|
// Render settings
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("rf") != 0)
|
2018-11-16 10:34:51 -07:00
|
|
|
{
|
|
|
|
if (version == 4)
|
|
|
|
{
|
2019-05-02 10:40:32 -06:00
|
|
|
renderFlags = static_cast<uint64_t>(stoull(params["rf"]));
|
2018-11-16 10:34:51 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-02 10:40:32 -06:00
|
|
|
// old renderer flags are int
|
|
|
|
renderFlags = static_cast<uint64_t>(stoi(params["rf"]));
|
2018-11-16 10:34:51 -07:00
|
|
|
// older celestia versions didn't know about new renderer flags
|
|
|
|
if ((renderFlags & Renderer::ShowPlanets) != 0)
|
|
|
|
renderFlags |= NewRenderFlags;
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("lm") != 0)
|
|
|
|
labelMode = stoi(params["lm"]);
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
int timeSourceInt = 0;
|
2019-05-02 10:40:32 -06:00
|
|
|
if (params.count("tsrc") != 0)
|
|
|
|
timeSourceInt = stoi(params["tsrc"]);
|
2008-05-05 13:09:31 -06:00
|
|
|
if (timeSourceInt >= 0 && timeSourceInt < TimeSourceCount)
|
|
|
|
timeSource = (TimeSource) timeSourceInt;
|
|
|
|
else
|
|
|
|
timeSource = UseUrlTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
std::string Url::getAsString() const
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
return urlStr;
|
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
|
|
|
std::string Url::getName() const
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
|
|
|
void Url::evalName()
|
|
|
|
{
|
2003-05-31 11:40:19 -06:00
|
|
|
double lo = longitude, la = latitude;
|
|
|
|
char los = 'E';
|
|
|
|
char las = 'N';
|
2003-01-23 15:46:46 -07:00
|
|
|
switch(type) {
|
|
|
|
case Absolute:
|
2005-07-19 15:31:04 -06:00
|
|
|
name = _(modeStr.c_str());
|
|
|
|
if (body1 != "") name += " " + std::string(_(getBodyShortName(body1).c_str()));
|
|
|
|
if (body2 != "") name += " " + std::string(_(getBodyShortName(body2).c_str()));
|
|
|
|
if (trackedStr != "") name += " -> " + std::string(_(getBodyShortName(trackedStr).c_str()));
|
|
|
|
if (selectedStr != "") name += " [" + std::string(_(getBodyShortName(selectedStr).c_str())) + "]";
|
2003-01-23 15:46:46 -07:00
|
|
|
break;
|
|
|
|
case Relative:
|
2005-07-19 15:31:04 -06:00
|
|
|
if (selectedStr != "") name = std::string(_(getBodyShortName(selectedStr).c_str())) + " ";
|
2003-01-23 15:46:46 -07:00
|
|
|
if (lo < 0) { lo = -lo; los = 'W'; }
|
|
|
|
if (la < 0) { la = -la; las = 'S'; }
|
2018-10-14 06:56:04 -06:00
|
|
|
name += fmt::sprintf("(%.1lf%c, %.1lf%c)", lo, los, la, las);
|
2003-01-23 15:46:46 -07:00
|
|
|
break;
|
2003-05-31 11:40:19 -06:00
|
|
|
case Settings:
|
2005-07-19 15:31:04 -06:00
|
|
|
name = _("Settings");
|
2003-05-31 11:40:19 -06:00
|
|
|
break;
|
2003-01-23 15:46:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
|
|
|
std::string Url::getBodyShortName(const std::string& body) const
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string::size_type pos;
|
|
|
|
if (body != "") {
|
|
|
|
pos = body.rfind(":");
|
|
|
|
if (pos != std::string::npos) return body.substr(pos+1);
|
|
|
|
else return body;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
|
|
|
std::map<std::string, std::string> Url::parseUrlParams(const std::string& url) const
|
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string::size_type pos, startName, startValue;
|
|
|
|
std::map<std::string, std::string> params;
|
|
|
|
|
|
|
|
pos = url.find("?");
|
|
|
|
while (pos != std::string::npos) {
|
|
|
|
startName = pos + 1;
|
2018-09-22 07:13:49 -06:00
|
|
|
startValue = url.find('=', startName);
|
|
|
|
pos = url.find('&', pos + 1);
|
2002-11-03 13:33:30 -07:00
|
|
|
if (startValue != std::string::npos) {
|
|
|
|
startValue++;
|
|
|
|
if (pos != std::string::npos)
|
2009-03-17 15:57:23 -06:00
|
|
|
params[url.substr(startName, startValue - startName -1)] = decodeString(url.substr(startValue, pos - startValue));
|
2002-11-03 13:33:30 -07:00
|
|
|
else
|
2009-03-17 15:57:23 -06:00
|
|
|
params[url.substr(startName, startValue - startName -1)] = decodeString(url.substr(startValue));
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2008-02-08 14:46:02 -07:00
|
|
|
std::string Url::getCoordSysName(ObserverFrame::CoordinateSystem mode) const
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::Universal:
|
2002-11-03 13:33:30 -07:00
|
|
|
return "Freeflight";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::Ecliptical:
|
2002-11-07 22:28:42 -07:00
|
|
|
return "Follow";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::BodyFixed:
|
2002-11-03 13:33:30 -07:00
|
|
|
return "SyncOrbit";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::Chase:
|
2002-11-03 13:33:30 -07:00
|
|
|
return "Chase";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::PhaseLock:
|
2002-11-03 13:33:30 -07:00
|
|
|
return "PhaseLock";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::Equatorial:
|
2002-12-13 12:39:18 -07:00
|
|
|
return "Unknown";
|
2008-02-08 14:46:02 -07:00
|
|
|
case ObserverFrame::ObserverLocal:
|
2002-12-13 12:39:18 -07:00
|
|
|
return "Unknown";
|
2008-05-05 13:09:31 -06:00
|
|
|
default:
|
|
|
|
return "Unknown";
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-22 21:52:03 -06:00
|
|
|
static std::string getBodyName(Universe* universe, Body* body)
|
|
|
|
{
|
|
|
|
std::string name = body->getName();
|
|
|
|
PlanetarySystem* parentSystem = body->getSystem();
|
2018-09-22 07:13:49 -06:00
|
|
|
const Body* parentBody = nullptr;
|
2007-10-22 21:52:03 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (parentSystem != nullptr)
|
2007-10-22 21:52:03 -06:00
|
|
|
parentBody = parentSystem->getPrimaryBody();
|
2007-11-03 08:54:42 -06:00
|
|
|
else
|
2008-02-20 19:25:48 -07:00
|
|
|
assert(0);
|
|
|
|
// TODO: Figure out why the line below was added.
|
2018-03-11 07:12:58 -06:00
|
|
|
//parentBody = body->getOrbitBarycenter();
|
2007-10-22 21:52:03 -06:00
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
while (parentBody != nullptr)
|
2007-10-22 21:52:03 -06:00
|
|
|
{
|
|
|
|
name = parentBody->getName() + ":" + name;
|
|
|
|
parentSystem = parentBody->getSystem();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (parentSystem == nullptr)
|
|
|
|
parentBody = nullptr;
|
2007-10-22 21:52:03 -06:00
|
|
|
else
|
|
|
|
parentBody = parentSystem->getPrimaryBody();
|
|
|
|
}
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
if (body->getSystem()->getStar() != nullptr)
|
2007-10-22 21:52:03 -06:00
|
|
|
{
|
|
|
|
name = universe->getStarCatalog()->getStarName(*(body->getSystem()->getStar())) + ":" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-07 22:28:42 -07:00
|
|
|
void Url::goTo()
|
2007-01-11 12:30:04 -07:00
|
|
|
{
|
2003-05-31 11:40:19 -06:00
|
|
|
Selection sel;
|
|
|
|
|
2002-11-07 22:28:42 -07:00
|
|
|
if (urlStr == "")
|
|
|
|
return;
|
2002-11-03 13:33:30 -07:00
|
|
|
Simulation *sim = appCore->getSimulation();
|
|
|
|
Renderer *renderer = appCore->getRenderer();
|
|
|
|
std::string::size_type pos;
|
|
|
|
|
|
|
|
sim->update(0.0);
|
2003-05-31 11:40:19 -06:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case Absolute:// Intentional Fall-Through
|
|
|
|
case Relative:
|
2008-02-08 14:46:02 -07:00
|
|
|
sim->setFrame(ref.getCoordinateSystem(), ref.getRefObject(), ref.getTargetObject());
|
2003-05-31 11:40:19 -06:00
|
|
|
sim->getActiveObserver()->setFOV(degToRad(fieldOfView));
|
2003-06-03 15:49:54 -06:00
|
|
|
appCore->setZoomFromFOV();
|
2003-05-31 11:40:19 -06:00
|
|
|
sim->setTimeScale(timeScale);
|
2007-11-03 03:49:29 -06:00
|
|
|
sim->setPauseState(pauseState);
|
2003-05-31 11:40:19 -06:00
|
|
|
appCore->setLightDelayActive(lightTimeDelay);
|
|
|
|
|
2007-11-03 03:49:29 -06:00
|
|
|
if (selectedStr != "")
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
while(pos != std::string::npos)
|
|
|
|
{
|
|
|
|
pos = selectedStr.find(":", pos + 1);
|
|
|
|
if (pos != std::string::npos) selectedStr[pos]='/';
|
|
|
|
}
|
|
|
|
sel = sim->findObjectFromPath(selectedStr);
|
|
|
|
sim->setSelection(sel);
|
|
|
|
}
|
|
|
|
else
|
2003-05-31 11:40:19 -06:00
|
|
|
{
|
2007-11-03 03:49:29 -06:00
|
|
|
sim->setSelection(Selection());
|
2003-05-31 11:40:19 -06:00
|
|
|
}
|
2002-11-03 13:33:30 -07:00
|
|
|
|
2007-11-03 03:49:29 -06:00
|
|
|
if (trackedStr != "")
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
while(pos != std::string::npos)
|
|
|
|
{
|
|
|
|
pos = trackedStr.find(":", pos + 1);
|
|
|
|
if (pos != std::string::npos) trackedStr[pos]='/';
|
|
|
|
}
|
|
|
|
sel = sim->findObjectFromPath(trackedStr);
|
|
|
|
sim->setTrackedObject(sel);
|
|
|
|
}
|
|
|
|
else
|
2003-05-31 11:40:19 -06:00
|
|
|
{
|
2007-11-03 03:49:29 -06:00
|
|
|
if (!sim->getTrackedObject().empty())
|
|
|
|
sim->setTrackedObject(Selection());
|
2003-05-31 11:40:19 -06:00
|
|
|
}
|
|
|
|
// Intentional Fall-Through
|
|
|
|
case Settings:
|
|
|
|
renderer->setRenderFlags(renderFlags);
|
|
|
|
renderer->setLabelMode(labelMode);
|
|
|
|
break;
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
if (version >= 3)
|
|
|
|
{
|
|
|
|
switch (timeSource)
|
|
|
|
{
|
|
|
|
case UseUrlTime:
|
|
|
|
sim->setTime((double) date);
|
|
|
|
break;
|
|
|
|
case UseSimulationTime:
|
|
|
|
// Leave the current simulation time unmodified
|
|
|
|
break;
|
|
|
|
case UseSystemTime:
|
|
|
|
sim->setTime(astro::UTCtoTDB(astro::Date::systemDate()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// Position and orientation stored in frame coordinates; convert them
|
|
|
|
// to universal and set the observer position.
|
|
|
|
double tdb = sim->getTime();
|
|
|
|
coord = sim->getObserver().getFrame()->convertToUniversal(coord, tdb);
|
2009-07-25 16:18:51 -06:00
|
|
|
Quaterniond q = sim->getObserver().getFrame()->convertToUniversal(orientation.cast<double>(), tdb);
|
2003-01-23 15:46:46 -07:00
|
|
|
sim->setObserverPosition(coord);
|
2009-07-21 22:53:15 -06:00
|
|
|
sim->setObserverOrientation(q.cast<float>());
|
2008-05-05 13:09:31 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case Absolute:
|
|
|
|
sim->setTime((double) date);
|
|
|
|
sim->setObserverPosition(coord);
|
2009-07-25 16:18:51 -06:00
|
|
|
sim->setObserverOrientation(orientation);
|
2008-05-05 13:09:31 -06:00
|
|
|
break;
|
|
|
|
case Relative:
|
2009-07-21 22:53:15 -06:00
|
|
|
sim->gotoSelectionLongLat(0, distance, (float) (longitude * PI / 180), (float) (latitude * PI / 180), Vector3f::UnitY());
|
2008-05-05 13:09:31 -06:00
|
|
|
break;
|
|
|
|
case Settings:
|
|
|
|
break;
|
|
|
|
}
|
2003-01-23 15:46:46 -07:00
|
|
|
}
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:30:04 -07:00
|
|
|
|
2009-03-17 15:57:23 -06:00
|
|
|
std::string Url::decodeString(const std::string& str)
|
2002-11-07 22:28:42 -07:00
|
|
|
{
|
2002-11-03 13:33:30 -07:00
|
|
|
std::string::size_type a=0, b;
|
|
|
|
std::string out = "";
|
2003-05-06 16:13:33 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
b = str.find("%");
|
2002-11-07 22:28:42 -07:00
|
|
|
while (b != std::string::npos)
|
|
|
|
{
|
2002-12-13 12:39:18 -07:00
|
|
|
unsigned int c;
|
|
|
|
out += str.substr(a, b-a);
|
2003-05-06 16:13:33 -06:00
|
|
|
std::string c_code = str.substr(b+1, 2);
|
2002-11-03 13:33:30 -07:00
|
|
|
sscanf(c_code.c_str(), "%02x", &c);
|
2009-03-17 15:57:23 -06:00
|
|
|
out += (char) c;
|
2002-11-03 13:33:30 -07:00
|
|
|
a = b + 3;
|
2018-09-22 07:13:49 -06:00
|
|
|
b = str.find('%', a);
|
2002-11-03 13:33:30 -07:00
|
|
|
}
|
|
|
|
out += str.substr(a);
|
2006-10-11 14:44:17 -06:00
|
|
|
|
2002-11-03 13:33:30 -07:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-17 15:57:23 -06:00
|
|
|
string Url::encodeString(const string& str)
|
|
|
|
{
|
|
|
|
ostringstream enc;
|
|
|
|
|
2018-09-22 07:13:49 -06:00
|
|
|
for (const auto _ch : str)
|
2009-03-17 15:57:23 -06:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
int ch = (unsigned char) _ch;
|
2009-03-17 15:57:23 -06:00
|
|
|
bool encode = false;
|
|
|
|
if (ch <= 32 || ch >= 128)
|
|
|
|
{
|
|
|
|
encode = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
case '?':
|
|
|
|
case '"':
|
|
|
|
case '#':
|
|
|
|
case '+':
|
|
|
|
case ',':
|
|
|
|
case '=':
|
|
|
|
case '@':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
|
|
|
encode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encode)
|
|
|
|
{
|
2011-03-12 17:58:23 -07:00
|
|
|
enc << '%' << setw(2) << hex << ch;
|
2009-03-17 15:57:23 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
enc << _ch;
|
2009-03-17 15:57:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return enc.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
// Utility function that returns the complete path for a selection.
|
|
|
|
string
|
2009-03-17 15:57:23 -06:00
|
|
|
Url::getEncodedObjectName(const Selection& selection)
|
|
|
|
{
|
|
|
|
return ::getEncodedObjectName(selection, appCore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const string
|
|
|
|
getEncodedObjectName(const Selection& selection, const CelestiaCore* appCore)
|
2008-05-05 13:09:31 -06:00
|
|
|
{
|
|
|
|
Universe *universe = appCore->getSimulation()->getUniverse();
|
2009-03-17 15:57:23 -06:00
|
|
|
string name;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
switch (selection.getType())
|
|
|
|
{
|
|
|
|
case Selection::Type_Body:
|
2009-03-17 15:57:23 -06:00
|
|
|
name = getBodyName(universe, selection.body());
|
|
|
|
break;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
case Selection::Type_Star:
|
2009-03-17 15:57:23 -06:00
|
|
|
name = universe->getStarCatalog()->getStarName(*selection.star());
|
|
|
|
break;
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
case Selection::Type_DeepSky:
|
2009-03-17 15:57:23 -06:00
|
|
|
name = universe->getDSOCatalog()->getDSOName(selection.deepsky());
|
|
|
|
break;
|
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
case Selection::Type_Location:
|
2009-03-17 15:57:23 -06:00
|
|
|
name = selection.location()->getName();
|
|
|
|
{
|
|
|
|
Body* parentBody = selection.location()->getParentBody();
|
2018-09-22 07:13:49 -06:00
|
|
|
if (parentBody != nullptr)
|
2009-03-17 15:57:23 -06:00
|
|
|
name = getBodyName(universe, parentBody) + ":" + name;
|
|
|
|
}
|
|
|
|
break;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2008-05-05 13:09:31 -06:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2009-03-17 15:57:23 -06:00
|
|
|
|
|
|
|
return Url::encodeString(name);
|
2008-05-05 13:09:31 -06:00
|
|
|
}
|