DS9FileWriter.qo.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef DS9FILEWRITER_QO_H_
00028 #define DS9FILEWRITER_QO_H_
00029
00030 #include <QTextStream>
00031
00032 #include <display/RegionShapes/QtDS9WriteOptions.ui.h>
00033 #include <display/RegionShapes/RSFileReaderWriter.h>
00034 #include <display/RegionShapes/DS9FileReader.h>
00035
00036 #include <casa/namespace.h>
00037
00038 namespace casa {
00039
00040 class RSMarker;
00041 class AnnRegion;
00042
00043
00044 class DS9FileWriter : public RSFileWriter {
00045 public:
00046
00047
00048 static const String CSYS_INDIVIDUAL;
00049 static const String CSYS_IMAGE;
00050 static const String CSYS_B1950;
00051 static const String CSYS_J2000;
00052 static const String CSYS_GALACTIC;
00053 static const String CSYS_ECLIPTIC;
00054 static const String UNIT_IPIXELS;
00055 static const String UNIT_DEGREES;
00056 static const String UNIT_RADIANS;
00057 static const String PUNIT_SEXAGESIMAL;
00058 static const String PUNIT_HMS;
00059 static const String PUNIT_DMS;
00060 static const String SUNIT_ARCSEC;
00061 static const String SUNIT_ARCMIN;
00062 static const String DEFAULT_COMMENTS;
00063
00064
00065
00066
00067 static DS9::CoordinateSystem coordinateSystem(const String& system) {
00068 if(system == CSYS_IMAGE) return DS9::Image;
00069 else if(system == CSYS_B1950) return DS9::FK4;
00070 else if(system == CSYS_J2000) return DS9::FK5;
00071 else if(system == CSYS_GALACTIC) return DS9::Galactic;
00072 else if(system == CSYS_ECLIPTIC) return DS9::Ecliptic;
00073
00074 else return DS9::defaultCoordinateSystem();
00075 }
00076
00077
00078 static bool isValidDS9System(MDirection::Types worldSys) {
00079 return worldSys == MDirection::B1950 ||
00080 worldSys == MDirection::J2000 ||
00081 worldSys == MDirection::GALACTIC ||
00082 worldSys == MDirection::ECLIPTIC;
00083 }
00084
00085
00086
00087 DS9FileWriter();
00088
00089
00090 ~DS9FileWriter();
00091
00092
00093
00094 QWidget* optionsWidget() const;
00095
00096
00097 void setOptions(const QWidget* widget);
00098
00099
00100 bool write(const vector<RegionShape*>& shapes) const;
00101
00102 bool writeHeader( QTextStream & ) const;
00103 bool writeFooter( QTextStream & ) const;
00104 bool write( QTextStream &, AnnRegion * ) const;
00105
00106 private:
00107
00108
00109 bool m_custCoordSys;
00110 bool m_pixelCoordSys;
00111 String m_coordSys;
00112 String m_posUnits, m_sizeUnits;
00113 int m_precision;
00114 String m_comments;
00115
00116
00117
00118
00119 void resetOptions() const;
00120
00121
00122 bool writeHeader(QTextStream& file, stringstream& errors) const;
00123
00124
00125
00126 bool writeGlobals(QTextStream& file, stringstream& errors) const;
00127
00128
00129 bool writeShape(QTextStream& file, stringstream& errors,
00130 const RegionShape* shape, bool isComposite = false) const;
00131
00132
00133
00134 static vector<String> globalProperties() {
00135 static vector<String> v(14);
00136
00137 v[0] = DS9Region::PROP_COLOR;
00138 v[1] = DS9Region::PROP_DASH;
00139 v[2] = DS9Region::PROP_DASHLIST;
00140 v[3] = DS9Region::PROP_DELETE;
00141 v[4] = DS9Region::PROP_EDIT;
00142 v[5] = DS9Region::PROP_FIXED;
00143 v[6] = DS9Region::PROP_FONT;
00144 v[7] = DS9Region::PROP_HIGHLITE;
00145 v[8] = DS9Region::PROP_INCLUDE;
00146 v[9] = DS9Region::PROP_MOVE;
00147 v[10] = DS9Region::PROP_ROTATE;
00148 v[11] = DS9Region::PROP_SELECT;
00149 v[12] = DS9Region::PROP_SOURCE;
00150 v[13] = DS9Region::PROP_WIDTH;
00151
00152 return v;
00153 }
00154
00155
00156
00157
00158
00159
00160 static bool regionType(const RegionShape* shape, DS9::RegionType& type,
00161 stringstream& errors);
00162 static bool regionType(const AnnRegion* shape, DS9::RegionType& type,
00163 stringstream& errors);
00164
00165
00166
00167
00168
00169 static vector<RSMarker*> convertMarker(const RSMarker* marker,
00170 bool& conversionWasNeeded);
00171
00172
00173
00174
00175
00176
00177 static QString convertValue(double value, const String& toUnits,
00178 int precision);
00179
00180
00181
00182
00183 static String sgUnit(const String& posUnit, int index,
00184 const String& coordSys) {
00185 if(posUnit == PUNIT_SEXAGESIMAL) {
00186 if(index % 2 == 0 && coordSys != CSYS_GALACTIC) return PUNIT_HMS;
00187 else return PUNIT_DMS;
00188 } else return posUnit;
00189 }
00190 };
00191
00192
00193
00194 class QtDS9RFWOptions : public QWidget, Ui::DS9WriteOptions {
00195 Q_OBJECT
00196
00197 public:
00198
00199 QtDS9RFWOptions();
00200
00201
00202 ~QtDS9RFWOptions();
00203
00204
00205
00206
00207 bool isCustomCoordinateSystem() const;
00208
00209
00210
00211 bool isPixelCoordinateSystem() const;
00212
00213
00214
00215
00216 String getCoordinateSystem() const;
00217
00218
00219
00220 String getPositionUnits() const;
00221
00222
00223
00224 String getSizeUnits() const;
00225
00226
00227 int getPrecision() const;
00228
00229
00230 String getComments() const;
00231
00232 private slots:
00233
00234 void coordinateSystemChanged(int index);
00235 };
00236
00237 }
00238
00239 #endif