SlewDialog.cpp   SlewDialog.cpp 
skipping to change at line 24 skipping to change at line 24
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "Dialog.hpp" #include "Dialog.hpp"
#include "AngleSpinBox.hpp" #include "AngleSpinBox.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp"
#include "StelModuleMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelUtils.hpp"
#include "VecMath.hpp" #include "VecMath.hpp"
#include "TelescopeControl.hpp" #include "TelescopeControl.hpp"
#include "SlewDialog.hpp" #include "SlewDialog.hpp"
#include "ui_slewDialog.h" #include "ui_slewDialog.h"
#include <QDebug> #include <QDebug>
using namespace TelescopeControlGlobals; using namespace TelescopeControlGlobals;
SlewDialog::SlewDialog() SlewDialog::SlewDialog()
{ {
ui = new Ui_slewDialog; ui = new Ui_slewDialog;
//TODO: Fix this - it's in the same plugin //TODO: Fix this - it's in the same plugin
telescopeManager = GETSTELMODULE(TelescopeControl); telescopeManager = GETSTELMODULE(TelescopeControl);
storedPointsDialog = NULL;
} }
SlewDialog::~SlewDialog() SlewDialog::~SlewDialog()
{ {
delete ui; delete ui;
storedPointsDialog = NULL;
} }
void SlewDialog::retranslate() void SlewDialog::retranslate()
{ {
if (dialog) if (dialog)
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
} }
void SlewDialog::createDialogContent() void SlewDialog::createDialogContent()
{ {
skipping to change at line 74 skipping to change at line 74
connect(ui->radioButtonHMS, SIGNAL(toggled(bool)), this, SLOT(setFor matHMS(bool))); connect(ui->radioButtonHMS, SIGNAL(toggled(bool)), this, SLOT(setFor matHMS(bool)));
connect(ui->radioButtonDMS, SIGNAL(toggled(bool)), this, SLOT(setFor matDMS(bool))); connect(ui->radioButtonDMS, SIGNAL(toggled(bool)), this, SLOT(setFor matDMS(bool)));
connect(ui->radioButtonDecimal, SIGNAL(toggled(bool)), this, SLOT(se tFormatDecimal(bool))); connect(ui->radioButtonDecimal, SIGNAL(toggled(bool)), this, SLOT(se tFormatDecimal(bool)));
connect(ui->pushButtonSlew, SIGNAL(clicked()), this, SLOT(slew())); connect(ui->pushButtonSlew, SIGNAL(clicked()), this, SLOT(slew()));
connect(ui->pushButtonConfigure, SIGNAL(clicked()), this, SLOT(showC onfiguration())); connect(ui->pushButtonConfigure, SIGNAL(clicked()), this, SLOT(showC onfiguration()));
connect(telescopeManager, SIGNAL(clientConnected(int, QString)), thi s, SLOT(addTelescope(int, QString))); connect(telescopeManager, SIGNAL(clientConnected(int, QString)), thi s, SLOT(addTelescope(int, QString)));
connect(telescopeManager, SIGNAL(clientDisconnected(int)), this, SLO T(removeTelescope(int))); connect(telescopeManager, SIGNAL(clientDisconnected(int)), this, SLO T(removeTelescope(int)));
//
connect(ui->comboBoxStoredPoints, SIGNAL(currentIndexChanged(int)),
this, SLOT(getStoredPointInfo()));
connect(ui->toolButtonStoredPoints, SIGNAL(clicked()), this, SLOT(ed
itStoredPoints()));
connect(ui->pushButtonCurrent, SIGNAL(clicked()), this, SLOT(getCurr entObjectInfo())); connect(ui->pushButtonCurrent, SIGNAL(clicked()), this, SLOT(getCurr entObjectInfo()));
connect(ui->pushButtonCenter, SIGNAL(clicked()), this, SLOT(getCente rInfo())); connect(ui->pushButtonCenter, SIGNAL(clicked()), this, SLOT(getCente rInfo()));
//Coordinates are in HMS by default: //Coordinates are in HMS by default:
ui->radioButtonHMS->setChecked(true); ui->radioButtonHMS->setChecked(true);
storedPointsDialog = new StoredPointsDialog;
// add point and remove
connect(storedPointsDialog, SIGNAL(addStoredPoint(int, QString, doub
le, double)),
this, SLOT(addStoredPointToComboBox(int, QString, double, do
uble)));
// remove point
connect(storedPointsDialog, SIGNAL(removeStoredPoint(int)),
this, SLOT(removeStoredPointFromComboBox(int)));
updateTelescopeList(); updateTelescopeList();
updateStoredPointsList();
} }
void SlewDialog::showConfiguration() void SlewDialog::showConfiguration()
{ {
//Hack to work around having no direct way to do display the window //Hack to work around having no direct way to do display the window
telescopeManager->configureGui(true); telescopeManager->configureGui(true);
} }
void SlewDialog::setFormatHMS(bool set) void SlewDialog::setFormatHMS(bool set)
{ {
if (!set) return; if (!set)
return;
ui->spinBoxRA->setDecimals(2);
ui->spinBoxDec->setDecimals(2);
ui->spinBoxRA->setDisplayFormat(AngleSpinBox::HMSLetters); ui->spinBoxRA->setDisplayFormat(AngleSpinBox::HMSLetters);
ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DMSLetters); ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DMSSymbols);
} }
void SlewDialog::setFormatDMS(bool set) void SlewDialog::setFormatDMS(bool set)
{ {
if (!set) return; if (!set)
ui->spinBoxRA->setDisplayFormat(AngleSpinBox::DMSLetters); return;
ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DMSLetters);
ui->spinBoxRA->setDecimals(2);
ui->spinBoxDec->setDecimals(2);
ui->spinBoxRA->setDisplayFormat(AngleSpinBox::DMSSymbols);
ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DMSSymbols);
} }
void SlewDialog::setFormatDecimal(bool set) void SlewDialog::setFormatDecimal(bool set)
{ {
if (!set) return; if (!set)
return;
ui->spinBoxRA->setDecimals(6);
ui->spinBoxDec->setDecimals(6);
ui->spinBoxRA->setDisplayFormat(AngleSpinBox::DecimalDeg); ui->spinBoxRA->setDisplayFormat(AngleSpinBox::DecimalDeg);
ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DecimalDeg); ui->spinBoxDec->setDisplayFormat(AngleSpinBox::DecimalDeg);
} }
void SlewDialog::updateTelescopeList() void SlewDialog::updateTelescopeList()
{ {
connectedSlotsByName.clear(); connectedSlotsByName.clear();
ui->comboBoxTelescope->clear(); ui->comboBoxTelescope->clear();
QHash<int, QString> connectedSlotsByNumber = telescopeManager->getCo nnectedClientsNames(); QHash<int, QString> connectedSlotsByNumber = telescopeManager->getCo nnectedClientsNames();
skipping to change at line 154 skipping to change at line 179
} }
void SlewDialog::removeTelescope(int slot) void SlewDialog::removeTelescope(int slot)
{ {
if (slot <= 0) if (slot <= 0)
return; return;
QString name = connectedSlotsByName.key(slot, QString()); QString name = connectedSlotsByName.key(slot, QString());
if (name.isEmpty()) if (name.isEmpty())
return; return;
connectedSlotsByName.remove(name); connectedSlotsByName.remove(name);
int index = ui->comboBoxTelescope->findText(name); int index = ui->comboBoxTelescope->findText(name);
if (index != -1) if (index != -1)
{ {
ui->comboBoxTelescope->removeItem(index); ui->comboBoxTelescope->removeItem(index);
} }
else else
{ {
//Something very wrong just happened, so: //Something very wrong just happened, so:
updateTelescopeList(); updateTelescopeList();
return; return;
} }
updateTelescopeControls(); updateTelescopeControls();
} }
void SlewDialog::slew() void SlewDialog::slew()
{ {
double radiansRA = ui->spinBoxRA->valueRadians(); double radiansRA = ui->spinBoxRA->valueRadians();
double radiansDec = ui->spinBoxDec->valueRadians(); double radiansDec = ui->spinBoxDec->valueRadians();
int slot = connectedSlotsByName.value(ui->comboBoxTelescope->current Text()); int slot = connectedSlotsByName.value(ui->comboBoxTelescope->current Text());
Vec3d targetPosition; Vec3d targetPosition;
StelUtils::spheToRect(radiansRA, radiansDec, targetPosition); StelUtils::spheToRect(radiansRA, radiansDec, targetPosition);
telescopeManager->telescopeGoto(slot, targetPosition); telescopeManager->telescopeGoto(slot, targetPosition);
} }
void SlewDialog::getCurrentObjectInfo() void SlewDialog::getCurrentObjectInfo()
skipping to change at line 208 skipping to change at line 234
const StelProjectorP projector = core->getProjection(StelCore::Frame EquinoxEqu); const StelProjectorP projector = core->getProjection(StelCore::Frame EquinoxEqu);
Vec3d centerPosition; Vec3d centerPosition;
Vec2f center = projector->getViewportCenter(); Vec2f center = projector->getViewportCenter();
projector->unProject(center[0], center[1], centerPosition); projector->unProject(center[0], center[1], centerPosition);
double dec_j2000 = 0; double dec_j2000 = 0;
double ra_j2000 = 0; double ra_j2000 = 0;
StelUtils::rectToSphe(&ra_j2000,&dec_j2000,core->equinoxEquToJ2000(c enterPosition)); StelUtils::rectToSphe(&ra_j2000,&dec_j2000,core->equinoxEquToJ2000(c enterPosition));
ui->spinBoxRA->setRadians(ra_j2000); ui->spinBoxRA->setRadians(ra_j2000);
ui->spinBoxDec->setRadians(dec_j2000); ui->spinBoxDec->setRadians(dec_j2000);
} }
void SlewDialog::editStoredPoints()
{
storedPointsDialog->setVisible(true);
QVariantList qvl;
for (int i = 1;i< ui->comboBoxStoredPoints->count(); i++)
{
QVariant var = ui->comboBoxStoredPoints->itemData(i);
qvl.append(var);
}
storedPointsDialog->populatePointsList(qvl);
}
void SlewDialog::updateStoredPointsList()
{
//user point from file
loadPointsFromFile();
}
void SlewDialog::addStoredPointToComboBox(int number, QString name, double
radiansRA, double radiansDec)
{
if (!ui->comboBoxStoredPoints->count())
{
ui->comboBoxStoredPoints->addItem(q_("Select one"));
}
storedPoint sp;
sp.number = number;
sp.name = name;
sp.radiansRA = radiansRA;
sp.radiansDec= radiansDec;
QVariant var;
var.setValue(sp);
ui->comboBoxStoredPoints->addItem(name,var);
savePointsToFile();
}
void SlewDialog::removeStoredPointFromComboBox(int number)
{
ui->comboBoxStoredPoints->removeItem(number+1);
if (1 == ui->comboBoxStoredPoints->count())
{
ui->comboBoxStoredPoints->removeItem(0);
}
this->savePointsToFile();
}
void SlewDialog::getStoredPointInfo()
{
QVariant var = ui->comboBoxStoredPoints->currentData();
storedPoint sp = var.value<storedPoint>();
ui->spinBoxRA->setRadians(sp.radiansRA);
ui->spinBoxDec->setRadians(sp.radiansDec);
}
void SlewDialog::savePointsToFile()
{
//Open/create the JSON file
QString pointsJsonPath = StelFileMgr::findFile("modules/TelescopeCon
trol", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable))
+ "/points.json";
if (pointsJsonPath.isEmpty())
{
qWarning() << "SlewDialog: Error saving points";
return;
}
QFile pointsJsonFile(pointsJsonPath);
if(!pointsJsonFile.open(QFile::WriteOnly|QFile::Text))
{
qWarning() << "SlewDialog: Points can not be saved. A file c
an not be open for writing:"
<< QDir::toNativeSeparators(pointsJsonPath);
return;
}
storedPointsDescriptions.clear();
// All user stored points from comboBox
for (int i = 1;i< ui->comboBoxStoredPoints->count(); i++)
{
QVariant var = ui->comboBoxStoredPoints->itemData(i);
storedPoint sp = var.value<storedPoint>();
QVariantMap point;
point.insert("number", sp.number);
point.insert("name", sp.name);
point.insert("radiansRA", sp.radiansRA);
point.insert("radiansDec", sp.radiansDec);
storedPointsDescriptions.insert(QString::number(sp.number),p
oint);
}
//Add the version:
storedPointsDescriptions.insert("version", QString(TELESCOPE_CONTROL
_VERSION));
//Convert the tree to JSON
StelJsonParser::write(storedPointsDescriptions, &pointsJsonFile);
pointsJsonFile.flush();//Is this necessary?
pointsJsonFile.close();
}
void SlewDialog::loadPointsFromFile()
{
QVariantMap result;
QString pointsJsonPath = StelFileMgr::findFile("modules/TelescopeCon
trol", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable))
+ "/points.json";
if (pointsJsonPath.isEmpty())
{
qWarning() << "SlewDialog: Error loading points";
return;
}
if(!QFileInfo(pointsJsonPath).exists())
{
qWarning() << "SlewDialog::loadPointsFromFile(): No pointss
loaded. File is missing:"
<< QDir::toNativeSeparators(pointsJsonPath);
storedPointsDescriptions = result;
return;
}
QFile pointsJsonFile(pointsJsonPath);
QVariantMap map;
if(!pointsJsonFile.open(QFile::ReadOnly))
{
qWarning() << "SlewDialog: No points loaded. Can't open for
reading"
<< QDir::toNativeSeparators(pointsJsonPath);
storedPointsDescriptions = result;
return;
}
else
{
map = StelJsonParser::parse(&pointsJsonFile).toMap();
pointsJsonFile.close();
}
//File contains any points?
if(map.isEmpty())
{
storedPointsDescriptions = result;
return;
}
QString version = map.value("version", "0.0.0").toString();
if(version < QString(TELESCOPE_CONTROL_VERSION))
{
QString newName = pointsJsonPath + ".backup." + QDateTime::c
urrentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(pointsJsonFile.rename(newName))
{
qWarning() << "SlewDialog: The existing version of p
oints.json is obsolete. Backing it up as "
<< QDir::toNativeSeparators(newName);
qWarning() << "SlewDialog: A blank points.json file
will have to be created.";
storedPointsDescriptions = result;
return;
}
else
{
qWarning() << "SlewDialog: The existing version of p
oints.json is obsolete. Unable to rename.";
storedPointsDescriptions = result;
return;
}
}
map.remove("version");//Otherwise it will try to read it as a point
//Read pointss, if any
QMapIterator<QString, QVariant> node(map);
if(node.hasNext())
{
ui->comboBoxStoredPoints->addItem(q_("Select one"));
do
{
node.next();
QVariantMap point = node.value().toMap();
storedPoint sp;
sp.name = point.value("name").toString();
sp.number = point.value("number").toInt();
sp.radiansRA = point.value("radiansRA").toDouble();
sp.radiansDec = point.value("radiansDec").toDouble()
;
QVariant var;
var.setValue(sp);
ui->comboBoxStoredPoints->addItem(sp.name,var);
} while (node.hasNext());
}
}
 End of changes. 15 change blocks. 
11 lines changed or deleted 41 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/