Commit 7f91c1d2 authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Mosaic job tool ready for testing

parent 1a319e7f
......@@ -166,6 +166,7 @@ void MosaicTile::updateTiles()
tile->center_rot = rotatePoint(tile->center, centerPoint);
}
}
}
QPointF MosaicTile::rotatePoint(QPointF pointToRotate, QPointF centerPoint)
......@@ -219,6 +220,8 @@ Mosaic::Mosaic(Scheduler *scheduler)
scene.addItem(mosaicTile);
mosaicView->setScene(&scene);
selectJobsDirB->setIcon(QIcon::fromTheme("document-open-folder"));
//mosaicView->setResizeAnchor(QGraphicsView::AnchorViewCenter);
......@@ -276,8 +279,7 @@ void Mosaic::calculateFOV()
Options::setCameraPixelWidth(pixelWSizeSpin->value());
Options::setCameraPixelHeight(pixelHSizeSpin->value());
Options::setCameraWidth(cameraWSpin->value());
Options::setCameraHeight(cameraHSpin->value());
Options::setCameraRotation(rotationSpin->value());
Options::setCameraHeight(cameraHSpin->value());
// Calculate FOV in arcmins
double fov_x = 206264.8062470963552 * cameraWSpin->value() * pixelWSizeSpin->value() / 60000.0 / focalLenSpin->value();
......@@ -460,8 +462,11 @@ void Mosaic::constructMosaic()
if (mosaicWSpin->value() > 1 || mosaicHSpin->value() > 1)
createJobsB->setEnabled(true);
if (mosaicTile->getWidth() != mosaicWSpin->value() || mosaicTile->getHeight() != mosaicHSpin->value() || mosaicTile->getOverlap() != overlapSpin->value() || mosaicTile->getPA() != rotationSpin->value())
if (mosaicTile->getWidth() != mosaicWSpin->value() || mosaicTile->getHeight() != mosaicHSpin->value() || mosaicTile->getOverlap() != overlapSpin->value() || mosaicTile->getPA() != rotationSpin->value())
{
if (mosaicTile->getPA() != rotationSpin->value())
Options::setCameraRotation(rotationSpin->value());
// Update target FOV value
targetWFOVSpin->setValue(cameraWFOVSpin->value() * mosaicWSpin->value());
targetHFOVSpin->setValue(cameraHFOVSpin->value() * mosaicHSpin->value());
......@@ -479,6 +484,8 @@ void Mosaic::constructMosaic()
//render();
mosaicTile->setTransformOriginPoint(mosaicTile->boundingRect().center());
mosaicTile->setRotation(mosaicTile->getPA());
jobCountSpin->setValue(mosaicTile->getWidth()*mosaicTile->getHeight());
}
}
......@@ -495,7 +502,6 @@ void Mosaic::createJobs()
qDebug() << "Center RA" << center.ra().toHMSString() << " DEC " << center.dec().toDMSString();
KStars::Instance()->setApproxFOV( targetWFOVSpin->value()*2 / 60.0 );
// map->setFocus( sp ); // FIXME: Why does setFocus() need a non-const SkyPoint pointer?
center.EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
......@@ -512,7 +518,6 @@ void Mosaic::createJobs()
qDebug() << "North PA " << northPA;
qDebug() << "Target Screen X " << screenPoint.x() << " Y " << screenPoint.y();
for (int i=0; i < mosaicTile->getHeight(); i++)
{
......@@ -526,10 +531,7 @@ void Mosaic::createJobs()
QPointF tileScreenPoint(screenPoint.x()-targetItem->boundingRect().width()/2.0 + tile->center_rot.x(), screenPoint.y()-targetItem->boundingRect().height()/2.0 + tile->center_rot.y());
tile->skyCenter = map->projector()->fromScreen(tileScreenPoint, KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
tile->skyCenter.apparentCoord(KStars::Instance()->data()->ut().djd(), (long double) J2000);
tile->skyCenter.setRA0(tile->skyCenter.ra());
tile->skyCenter.setDec0(tile->skyCenter.dec());
tile->skyCenter.deprecess(KStarsData::Instance()->updateNum());
// TODO Check if J2000 are VALID. If they are use them to generate the jobs
// Add directory to save job file along with sequence files
......
......@@ -11,6 +11,9 @@
#include "Options.h"
#include <stdio.h>
#include <stdlib.h>
#include <QtDBus>
#include <QFileDialog>
......@@ -123,7 +126,7 @@ Scheduler::Scheduler()
loadSequenceB->setIcon(QIcon::fromTheme("document-open"));
selectStartupScriptB->setIcon(QIcon::fromTheme("document-open"));
selectShutdownScriptB->setIcon(QIcon::fromTheme("document-open"));
selectFITSB->setIcon(QIcon::fromTheme("document-open"));
selectFITSB->setIcon(QIcon::fromTheme("document-open"));
connect(selectObjectB,SIGNAL(clicked()),this,SLOT(selectObject()));
connect(selectFITSB,SIGNAL(clicked()),this,SLOT(selectFITS()));
......@@ -3756,6 +3759,15 @@ void Scheduler::startMosaicTool()
QString outputDir = mosaicTool.getJobsDir();
QString targetName = nameEdit->text().simplified().remove(" ");
XMLEle *root = getSequenceJobRoot();
if (root == NULL)
{
KMessageBox::error(this, i18n("Sequence file %1 is corrupted. Unable to create mosaic.", sequenceURL.fileName()));
return;
}
int currentJobsCount = jobs.count();
foreach (OneTile *oneJob, mosaicTool.getJobs())
{
QString prefix = QString("%1-Part%2").arg(targetName).arg(batchCount++);
......@@ -3763,7 +3775,7 @@ void Scheduler::startMosaicTool()
nameEdit->setText(prefix);
if (createJobSequence(prefix, outputDir) == false)
if (createJobSequence(root, prefix, outputDir) == false)
return;
QString filename = QString("%1/%2.esq").arg(outputDir).arg(prefix);
......@@ -3776,21 +3788,35 @@ void Scheduler::startMosaicTool()
addJob();
}
delXMLEle(root);
// Delete any prior jobs before saving
for (int i=0; i < currentJobsCount; i++)
{
delete (jobs.takeFirst());
queueTable->removeRow(0);
}
QUrl mosaicURL;
mosaicURL.setPath(QString("%1/%2_mosaic.esl").arg(outputDir).arg(targetName));
mosaicURL.setPath(QString("%1/%2_mosaic.esl").arg(outputDir).arg(targetName));
if (saveScheduler(mosaicURL))
appendLogText(i18n("Mosaic file %1 saved successfully.", mosaicURL.path()));
{
appendLogText(i18n("Mosaic file %1 saved successfully.", mosaicURL.path()));
}
else
appendLogText(i18n("Error saving mosaic file %1", mosaicURL.path()));
{
appendLogText(i18n("Error saving mosaic file %1. Please reload job.", mosaicURL.path()));
}
}
}
bool Scheduler::createJobSequence(const QString &prefix, const QString &outputDir)
XMLEle * Scheduler::getSequenceJobRoot()
{
QFile sFile;
sFile.setFileName(sequenceURL.path());
if ( !sFile.open( QIODevice::ReadWrite))
if ( !sFile.open( QIODevice::ReadOnly))
{
KMessageBox::sorry(KStars::Instance(), i18n( "Unable to open file %1", sFile.fileName()), i18n( "Could Not Open File" ) );
return false;
......@@ -3799,7 +3825,6 @@ bool Scheduler::createJobSequence(const QString &prefix, const QString &outputDi
LilXML *xmlParser = newLilXML();
char errmsg[MAXRBUF];
XMLEle *root = NULL;
XMLEle *ep=NULL, *subEP=NULL;
char c;
while ( sFile.getChar(&c))
......@@ -3807,43 +3832,53 @@ bool Scheduler::createJobSequence(const QString &prefix, const QString &outputDi
root = readXMLEle(xmlParser, c, errmsg);
if (root)
{
for (ep = nextXMLEle(root, 1) ; ep != NULL ; ep = nextXMLEle(root, 0))
{
if (!strcmp(tagXMLEle(ep), "Job"))
{
break;
}
for (subEP = nextXMLEle(ep, 1) ; subEP != NULL ; subEP = nextXMLEle(ep, 0))
{
delLilXML(xmlParser);
sFile.close();
return root;
}
if (!strcmp(tagXMLEle(subEP), "Prefix"))
{
XMLEle *rawPrefix = findXMLEle(subEP, "RawPrefix");
if (rawPrefix)
{
editXMLEle(rawPrefix, prefix.toLatin1().constData());
}
}
else if (!strcmp(tagXMLEle(subEP), "FITSDirectory"))
{
editXMLEle(subEP, QString("%1/%2").arg(outputDir).arg(prefix).toLatin1().constData());
}
}
bool Scheduler::createJobSequence(XMLEle *root, const QString &prefix, const QString &outputDir)
{
QFile sFile;
sFile.setFileName(sequenceURL.path());
}
}
delXMLEle(root);
}
else if (errmsg[0])
if ( !sFile.open( QIODevice::ReadOnly))
{
KMessageBox::sorry(KStars::Instance(), i18n( "Unable to open file %1", sFile.fileName()), i18n( "Could Not Open File" ) );
return false;
}
XMLEle *ep=NULL, *subEP=NULL;
for (ep = nextXMLEle(root, 1) ; ep != NULL ; ep = nextXMLEle(root, 0))
{
if (!strcmp(tagXMLEle(ep), "Job"))
{
appendLogText(QString(errmsg));
delLilXML(xmlParser);
sFile.close();
return false;
for (subEP = nextXMLEle(ep, 1) ; subEP != NULL ; subEP = nextXMLEle(ep, 0))
{
if (!strcmp(tagXMLEle(subEP), "Prefix"))
{
XMLEle *rawPrefix = findXMLEle(subEP, "RawPrefix");
if (rawPrefix)
{
editXMLEle(rawPrefix, prefix.toLatin1().constData());
}
}
else if (!strcmp(tagXMLEle(subEP), "FITSDirectory"))
{
editXMLEle(subEP, QString("%1/%2").arg(outputDir).arg(prefix).toLatin1().constData());
}
}
}
}
sFile.close();
QDir().mkpath(outputDir);
......@@ -3858,6 +3893,7 @@ bool Scheduler::createJobSequence(const QString &prefix, const QString &outputDi
return false;
}
fprintf(outputFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
prXMLEle(outputFile, root, 0);
fclose(outputFile);
......
......@@ -430,7 +430,9 @@ private:
* @param outputDir Output dir to set for the job sequence
* @return True if new file is saved, false otherwise
*/
bool createJobSequence(const QString &prefix, const QString &outputDir);
bool createJobSequence(XMLEle *root, const QString &prefix, const QString &outputDir);
XMLEle * getSequenceJobRoot();
bool isWeatherOK(SchedulerJob *job);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment