MainService.cpp   MainService.cpp 
skipping to change at line 41 skipping to change at line 41
#include "StelPropertyMgr.hpp" #include "StelPropertyMgr.hpp"
#include "StelScriptMgr.hpp" #include "StelScriptMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
MainService::MainService(const QByteArray &serviceName, QObject *parent) MainService::MainService(QObject *parent)
: AbstractAPIService(serviceName,parent), : AbstractAPIService(parent),
moveX(0),moveY(0),lastMoveUpdateTime(0), moveX(0),moveY(0),lastMoveUpdateTime(0),
//100 should be more than enough //100 should be more than enough
//this only has to emcompass events that occur between 2 status up dates //this only has to emcompass events that occur between 2 status up dates
actionCache(100), propCache(100) actionCache(100), propCache(100)
{ {
//this is run in the main thread //this is run in the main thread
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
actionMgr = StelApp::getInstance().getStelActionManager(); actionMgr = StelApp::getInstance().getStelActionManager();
lsMgr = GETSTELMODULE(LandscapeMgr); lsMgr = GETSTELMODULE(LandscapeMgr);
localeMgr = &StelApp::getInstance().getLocaleMgr(); localeMgr = &StelApp::getInstance().getLocaleMgr();
objMgr = &StelApp::getInstance().getStelObjectMgr(); objMgr = &StelApp::getInstance().getStelObjectMgr();
mvmgr = GETSTELMODULE(StelMovementMgr); mvmgr = GETSTELMODULE(StelMovementMgr);
propMgr = StelApp::getInstance().getStelPropertyManager(); propMgr = StelApp::getInstance().getStelPropertyManager();
scriptMgr = &StelApp::getInstance().getScriptMgr(); scriptMgr = &StelApp::getInstance().getScriptMgr();
skyCulMgr = &StelApp::getInstance().getSkyCultureMgr(); skyCulMgr = &StelApp::getInstance().getSkyCultureMgr();
connect(actionMgr,SIGNAL(actionToggled(QString,bool)),this,SLOT(acti onToggled(QString,bool))); connect(actionMgr,SIGNAL(actionToggled(QString,bool)),this,SLOT(acti onToggled(QString,bool)));
connect(propMgr,SIGNAL(stelPropChanged(QString,QVariant)),this,SLOT( propertyChanged(QString,QVariant))); connect(propMgr,SIGNAL(stelPropertyChanged(StelProperty*,QVariant)), this,SLOT(propertyChanged(StelProperty*,QVariant)));
Q_ASSERT(this->thread()==objMgr->thread()); Q_ASSERT(this->thread()==objMgr->thread());
} }
void MainService::update(double deltaTime) void MainService::update(double deltaTime)
{ {
bool xZero = qFuzzyIsNull(moveX); bool xZero = qFuzzyIsNull(moveX);
bool yZero = qFuzzyIsNull(moveY); bool yZero = qFuzzyIsNull(moveY);
//prevent sudden disconnects from moving endlessly //prevent sudden disconnects from moving endlessly
skipping to change at line 82 skipping to change at line 82
{ {
if(!xZero || !yZero) if(!xZero || !yZero)
qDebug()<<"[MainService] move timeout"; qDebug()<<"[MainService] move timeout";
moveX = moveY = .0f; moveX = moveY = .0f;
} }
//Similar to StelMovementMgr::updateMotion //Similar to StelMovementMgr::updateMotion
if(!xZero || !yZero) if(!xZero || !yZero)
{ {
//qDebug()<<moveX<<moveY;
double currentFov = mvmgr->getCurrentFov(); double currentFov = mvmgr->getCurrentFov();
// the more it is zoomed, the lower the moving speed is (in angle) // the more it is zoomed, the lower the moving speed is (in angle)
double depl=0.00025*deltaTime*1000*currentFov; //0.0004 is the default key move speed
double depl=0.0004 / 30 *deltaTime*1000*currentFov;
float deltaAz = moveX;
float deltaAlt = moveY;
if (deltaAz<0) double deltaAz = moveX*depl;
{ double deltaAlt = moveY*depl;
deltaAz = -depl/30;
if (deltaAz<-0.2)
deltaAz = -0.2;
}
else
{
if (deltaAz>0)
{
deltaAz = (depl/30);
if (deltaAz>0.2)
deltaAz = 0.2;
}
}
if (deltaAlt<0)
{
deltaAlt = -depl/30;
if (deltaAlt<-0.2)
deltaAlt = -0.2;
}
else
{
if (deltaAlt>0)
{
deltaAlt = depl/30;
if (deltaAlt>0.2)
deltaAlt = 0.2;
}
}
mvmgr->panView(deltaAz,deltaAlt); mvmgr->panView(deltaAz,deltaAlt);
//this is required to enable maximal fps for smoothness //this is required to enable maximal fps for smoothness
StelMainView::getInstance().thereWasAnEvent(); StelMainView::getInstance().thereWasAnEvent();
} }
} }
void MainService::getImpl(const QByteArray& operation, const APIParameters &parameters, APIServiceResponse &response) void MainService::get(const QByteArray& operation, const APIParameters &par ameters, APIServiceResponse &response)
{ {
if(operation=="status") if(operation=="status")
{ {
//a listing of the most common stuff that can change often //a listing of the most common stuff that can change often
QString sActionId = QString::fromUtf8(parameters.value("acti onId")); QString sActionId = QString::fromUtf8(parameters.value("acti onId"));
bool actionOk; bool actionOk;
int actionId = sActionId.toInt(&actionOk); int actionId = sActionId.toInt(&actionOk);
QString sPropId = QString::fromUtf8(parameters.value("propId ")); QString sPropId = QString::fromUtf8(parameters.value("propId "));
skipping to change at line 252 skipping to change at line 223
response.writeJSON(QJsonDocument(mainObj)); response.writeJSON(QJsonDocument(mainObj));
} }
else else
{ {
//TODO some sort of service description? //TODO some sort of service description?
response.writeRequestError("unsupported operation. GET: stat us, plugins"); response.writeRequestError("unsupported operation. GET: stat us, plugins");
} }
} }
void MainService::postImpl(const QByteArray& operation, const APIParameters &parameters, const QByteArray &data, APIServiceResponse &response) void MainService::post(const QByteArray& operation, const APIParameters &pa rameters, const QByteArray &data, APIServiceResponse &response)
{ {
Q_UNUSED(data); Q_UNUSED(data);
if(operation == "time") if(operation == "time")
{ {
bool doneSomething = false; bool doneSomething = false;
bool ok; bool ok;
//set the time + timerate //set the time + timerate
{ {
skipping to change at line 310 skipping to change at line 281
} }
if(doneSomething) if(doneSomething)
response.setData("ok"); response.setData("ok");
else else
response.setData("error: invalid parameters, use tim e/timerate as double values"); response.setData("error: invalid parameters, use tim e/timerate as double values");
} }
else if(operation == "focus") else if(operation == "focus")
{ {
QString target = QString::fromUtf8(parameters.value("target" )); QString target = QString::fromUtf8(parameters.value("target" ));
SelectionMode selMode = Center;
if(parameters.value("mode") == "zoom")
selMode = Zoom;
else if(parameters.value("mode") == "mark")
selMode = Mark;
//check target string first //check target string first
if(target.isEmpty()) if(target.isEmpty())
{ {
if(parameters.value("position").isEmpty()) if(parameters.value("position").isEmpty())
{ {
//no parameters = clear focus //no parameters = clear focus
target = ""; target = "";
} }
else else
skipping to change at line 346 skipping to change at line 323
} }
response.writeRequestError("invalid position format"); response.writeRequestError("invalid position format");
return; return;
} }
} }
bool result; bool result;
QMetaObject::invokeMethod(this,"focusObject",SERVICE_DEFAULT _INVOKETYPE, QMetaObject::invokeMethod(this,"focusObject",SERVICE_DEFAULT _INVOKETYPE,
Q_RETURN_ARG(bool,result), Q_RETURN_ARG(bool,result),
Q_ARG(QString,target)); Q_ARG(QString,target),
Q_ARG(SelectionMode,selMode));
response.setData(result ? "true" : "false"); response.setData(result ? "true" : "false");
} }
else if(operation == "move") else if(operation == "move")
{ {
QString xs = QString::fromUtf8(parameters.value("x"));
QString ys = QString::fromUtf8(parameters.value("y"));
bool xOk,yOk; bool xOk,yOk;
float x = xs.toInt(&xOk);
float y = ys.toInt(&yOk); double x = parameters.value("x").toDouble(&xOk);
double y = parameters.value("y").toDouble(&yOk);
if(xOk || yOk) if(xOk || yOk)
{ {
QMetaObject::invokeMethod(this,"updateMovement", SER VICE_DEFAULT_INVOKETYPE, QMetaObject::invokeMethod(this,"updateMovement", SER VICE_DEFAULT_INVOKETYPE,
Q_ARG(float,x), Q_ARG(double,x),
Q_ARG(float,y), Q_ARG(double,y),
Q_ARG(bool,xOk), Q_ARG(bool,xOk),
Q_ARG(bool,yOk)); Q_ARG(bool,yOk));
response.setData("ok"); response.setData("ok");
} }
else else
response.writeRequestError("requires x or y paramete r"); response.writeRequestError("requires x or y paramete r");
} }
else if(operation == "view") else if(operation == "view")
{ {
QByteArray j2000 = parameters.value("j2000");
if(!j2000.isEmpty())
{
QJsonDocument doc = QJsonDocument::fromJson(j2000);
QJsonArray arr = doc.array();
if(arr.size() == 3)
{
Vec3d pos;
pos[0] = arr.at(0).toDouble();
pos[1] = arr.at(1).toDouble();
pos[2] = arr.at(2).toDouble();
mvmgr->setViewDirectionJ2000(pos);
response.setData("ok");
}
else
{
response.writeRequestError("invalid j2000 fo
rmat, use JSON array of 3 doubles");
}
return;
}
QByteArray rect = parameters.value("altAz");
if(!rect.isEmpty())
{
QJsonDocument doc = QJsonDocument::fromJson(rect);
QJsonArray arr = doc.array();
if(arr.size() == 3)
{
Vec3d pos;
pos[0] = arr.at(0).toDouble();
pos[1] = arr.at(1).toDouble();
pos[2] = arr.at(2).toDouble();
mvmgr->setViewDirectionJ2000(core->altAzToJ2
000(pos,StelCore::RefractionOff));
response.setData("ok");
}
else
{
response.writeRequestError("invalid altAz fo
rmat, use JSON array of 3 doubles");
}
return;
}
QString azs = QString::fromUtf8(parameters.value("az")); QString azs = QString::fromUtf8(parameters.value("az"));
QString alts = QString::fromUtf8(parameters.value("alt")); QString alts = QString::fromUtf8(parameters.value("alt"));
bool azOk,altOk; bool azOk,altOk;
double az = azs.toDouble(&azOk); double az = azs.toDouble(&azOk);
double alt = alts.toDouble(&altOk); double alt = alts.toDouble(&altOk);
if(azOk || altOk) if(azOk || altOk)
{ {
QMetaObject::invokeMethod(this,"updateView", SERVICE _DEFAULT_INVOKETYPE, QMetaObject::invokeMethod(this,"updateView", SERVICE _DEFAULT_INVOKETYPE,
Q_ARG(double,az), Q_ARG(double,az),
Q_ARG(double,alt), Q_ARG(double,alt),
Q_ARG(bool,azOk), Q_ARG(bool,azOk),
Q_ARG(bool,altOk)); Q_ARG(bool,altOk));
response.setData("ok"); response.setData("ok");
} }
else else
response.writeRequestError("requires x or y paramete r"); response.writeRequestError("requires at least one of az,alt,j2000 parameters");
} }
else if (operation == "fov") else if (operation == "fov")
{ {
QString fov = QString::fromUtf8(parameters.value("fov")); QString fov = QString::fromUtf8(parameters.value("fov"));
bool ok; bool ok;
double dFov = fov.toDouble(&ok); double dFov = fov.toDouble(&ok);
if(fov.isEmpty() || !ok) if(fov.isEmpty() || !ok)
{ {
skipping to change at line 415 skipping to change at line 435
} }
QMetaObject::invokeMethod(this,"setFov",SERVICE_DEFAULT_INVO KETYPE, QMetaObject::invokeMethod(this,"setFov",SERVICE_DEFAULT_INVO KETYPE,
Q_ARG(double,dFov)); Q_ARG(double,dFov));
response.setData("ok"); response.setData("ok");
} }
else else
{ {
//TODO some sort of service description? //TODO some sort of service description?
response.writeRequestError("unsupported operation. POST: tim e,focus,move,fov"); response.writeRequestError("unsupported operation. POST: tim e,focus,move,view,fov");
} }
} }
StelObjectP MainService::getSelectedObject() StelObjectP MainService::getSelectedObject()
{ {
const QList<StelObjectP>& list = objMgr->getSelectedObject(); const QList<StelObjectP>& list = objMgr->getSelectedObject();
if(list.isEmpty()) if(list.isEmpty())
return StelObjectP(); return StelObjectP();
return list.first(); return list.first();
} }
QString MainService::getInfoString() QString MainService::getInfoString()
{ {
StelObjectP selectedObject = getSelectedObject(); StelObjectP selectedObject = getSelectedObject();
if(selectedObject.isNull()) if(selectedObject.isNull())
return QString(); return QString();
return selectedObject->getInfoString(core,StelObject::AllInfo | Stel Object::NoFont); return selectedObject->getInfoString(core,StelObject::AllInfo | Stel Object::NoFont);
} }
bool MainService::focusObject(const QString &name) bool MainService::focusObject(const QString &name, SelectionMode mode)
{ {
//StelDialog::gotoObject //StelDialog::gotoObject
//if name is empty, unselect //if name is empty, unselect
if(name.isEmpty()) if(name.isEmpty())
{ {
objMgr->unSelect(); objMgr->unSelect();
if(mode == Zoom)
mvmgr->autoZoomOut();
return true; return true;
} }
bool result = false; bool result = false;
if (objMgr->findAndSelectI18n(name) || objMgr->findAndSelect(name)) if (objMgr->findAndSelectI18n(name) || objMgr->findAndSelect(name))
{ {
const QList<StelObjectP> newSelected = objMgr->getSelectedOb ject(); const QList<StelObjectP> newSelected = objMgr->getSelectedOb ject();
if (!newSelected.empty()) if (!newSelected.empty())
{ {
// Can't point to home planet // Can't point to home planet
if (newSelected[0]->getEnglishName()!=core->getCurre ntLocation().planetName) if (newSelected[0]->getEnglishName()!=core->getCurre ntLocation().planetName)
{ {
mvmgr->moveToObject(newSelected[0], mvmgr->g if(mode != Mark)
etAutoMoveDuration()); {
mvmgr->setFlagTracking(true); mvmgr->moveToObject(newSelected[0],
mvmgr->getAutoMoveDuration());
mvmgr->setFlagTracking(true);
if(mode == Zoom)
{
mvmgr->autoZoomIn();
}
}
result = true; result = true;
} }
else else
{ {
objMgr->unSelect(); objMgr->unSelect();
} }
} }
} }
return result; return result;
} }
void MainService::focusPosition(const Vec3d &pos) void MainService::focusPosition(const Vec3d &pos)
{ {
objMgr->unSelect(); objMgr->unSelect();
mvmgr->moveToJ2000(pos, mvmgr->mountFrameToJ2000(Vec3d(0., 0., 1.)), mvmgr->getAutoMoveDuration()); mvmgr->moveToJ2000(pos, mvmgr->mountFrameToJ2000(Vec3d(0., 0., 1.)), mvmgr->getAutoMoveDuration());
} }
void MainService::updateMovement(float x, float y, bool xUpdated, bool yUpd ated) void MainService::updateMovement(double x, double y, bool xUpdated, bool yU pdated)
{ {
if(xUpdated) if(xUpdated)
{ {
this->moveX = x; this->moveX = x;
} }
if(yUpdated) if(yUpdated)
{ {
this->moveY = y; this->moveY = y;
} }
qint64 curTime = QDateTime::currentMSecsSinceEpoch(); qint64 curTime = QDateTime::currentMSecsSinceEpoch();
skipping to change at line 526 skipping to change at line 555
actionCache.append(ActionCacheEntry(id,val)); actionCache.append(ActionCacheEntry(id,val));
if(!actionCache.areIndexesValid()) if(!actionCache.areIndexesValid())
{ {
//in theory, this can happen, but practically not so much //in theory, this can happen, but practically not so much
qWarning()<<"Action cache indices invalid"; qWarning()<<"Action cache indices invalid";
actionCache.clear(); actionCache.clear();
} }
actionMutex.unlock(); actionMutex.unlock();
} }
void MainService::propertyChanged(const QString &id, const QVariant &val) void MainService::propertyChanged(StelProperty* prop, const QVariant& val)
{ {
propMutex.lock(); propMutex.lock();
propCache.append(PropertyCacheEntry(id,val)); propCache.append(PropertyCacheEntry(prop->getId(),val));
if(!propCache.areIndexesValid()) if(!propCache.areIndexesValid())
{ {
//in theory, this can happen, but practically not so much //in theory, this can happen, but practically not so much
qWarning()<<"Property cache indices invalid"; qWarning()<<"Property cache indices invalid";
propCache.clear(); propCache.clear();
} }
propMutex.unlock(); propMutex.unlock();
} }
QJsonObject MainService::getActionChangesSinceID(int changeId) QJsonObject MainService::getActionChangesSinceID(int changeId)
 End of changes. 21 change blocks. 
57 lines changed or deleted 89 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/