diff --git a/imageinfo.cpp b/imageinfo.cpp index bf699ee..c8cc1dd 100644 --- a/imageinfo.cpp +++ b/imageinfo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "pcl/FITSHeaderKeyword.h" static const QVector noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"}; @@ -12,6 +13,44 @@ bool FITSRecord::editable() const return noEditableKey.count(key); } +FITSRecord::FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment) : + key(key), value(value), comment(comment) +{ +} + +FITSRecord::FITSRecord(const pcl::FITSHeaderKeyword &record) +{ + key = record.name.c_str(); + comment = record.comment.c_str(); + + QString string = record.value.c_str(); + if(string.startsWith('\'') && string.endsWith('\'')) + { + string.chop(1); + string.remove(0, 1); + } + bool isint; + bool isdouble; + double vald = string.toDouble(&isdouble); + long long vall = string.toLongLong(&isint); + if(isint) + value = vall; + else if(isdouble) + value = vald; + else if(string == "T" || string == "F") + value = string == "T"; + else + value = string; +} + +QByteArray FITSRecord::valueToByteArray() const +{ + if(value.type() == QVariant::Bool) + return value.toBool() ? "T" : "F"; + else + return value.toString().toLatin1(); +} + ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent) { setColumnCount(3); @@ -86,16 +125,10 @@ WCSData::WCSData(int width, int height, const QVector &header) : { if(record.key.startsWith("PV"))continue; - QByteArray value = record.value.toString().toLatin1(); - if(value.startsWith('\'') && value.endsWith('\'')) - { - value.chop(1); - value = value.remove(0, 1); - } QByteArray rec; rec.append(record.key.leftJustified(8, ' ')); rec.append("= "); - rec.append(value); + rec.append(record.value.toString().toLatin1()); rec.append(" / "); rec.append(record.comment); str.append(rec.leftJustified(80, ' ', true)); diff --git a/imageinfo.h b/imageinfo.h index 9b9c0fc..a9210c2 100644 --- a/imageinfo.h +++ b/imageinfo.h @@ -5,12 +5,17 @@ #include #include +namespace pcl { class FITSHeaderKeyword; } + struct FITSRecord { QByteArray key; QVariant value; QByteArray comment; bool editable() const; + FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment); + FITSRecord(const pcl::FITSHeaderKeyword &record); + QByteArray valueToByteArray() const; }; class SkyPoint diff --git a/loadrunable.cpp b/loadrunable.cpp index b5e3298..a315804 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -161,10 +161,12 @@ int loadFITSHeader(fitsfile *file, ImageInfoData &info) var = vald; else if(status == VALUE_UNDEFINED) var = QVariant(); + else if(string == "T" || string == "F") + var = string == "T"; else - var = strval; + var = string; status = 0; - info.fitsHeader.append({key, var, comm}); + info.fitsHeader.append(FITSRecord(key, var, comm)); } else { @@ -324,7 +326,7 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image) auto fitskeywords = xisf.ReadFITSKeywords(); for(auto fits : fitskeywords) { - info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()}); + info.fitsHeader.append(fits); } info.wcs = std::make_shared(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader); if(!info.wcs->valid())info.wcs.reset(); @@ -500,7 +502,7 @@ bool readXISFHeader(const QString &path, ImageInfoData &info) auto fitskeywords = xisf.ReadFITSKeywords(); for(auto fits : fitskeywords) { - info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()}); + info.fitsHeader.append(fits); } info.wcs = std::make_shared(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader); if(!info.wcs->valid())info.wcs.reset(); @@ -626,7 +628,7 @@ void ConvertRunable::run() pcl::FITSKeywordArray fitskeywords; for(auto &record : imageinfo.fitsHeader) { - pcl::FITSHeaderKeyword key(pcl::IsoString(record.key.data()), pcl::IsoString(record.value.toString().toLatin1().data()), pcl::IsoString(record.comment.data())); + pcl::FITSHeaderKeyword key(pcl::IsoString(record.key.data()), pcl::IsoString(record.valueToByteArray().data()), pcl::IsoString(record.comment.data())); fitskeywords.Append(key); } pcl::XISFWriter xisf;