DS9FileWriter.qo.h

Go to the documentation of this file.
00001 //# DS9FileWriter.qo.h: DS9 implementation of RSFileWriter classes.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
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 // Implementation of RegionFileWriter for writing to DS9 files.
00044         class DS9FileWriter : public RSFileWriter {
00045         public:
00046                 // Options constants.
00047                 // </group>
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                 // </group>
00064 
00065                 // Converts a coordinate system constant (as used in DS9RFWOptions) into
00066                 // its DS9::CoordinateSystem equivalent.
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                 // Returns true if the given CASA world system is supported by DS9.
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                 // Constructor.
00087                 DS9FileWriter();
00088 
00089                 // Destructor.
00090                 ~DS9FileWriter();
00091 
00092 
00093                 // Implements RegionFileWriter::optionsWidget.
00094                 QWidget* optionsWidget() const;
00095 
00096                 // Implements RegionFileWriter::setOptions.
00097                 void setOptions(const QWidget* widget);
00098 
00099                 // Implements RegionFileWriter::write.
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                 // Custom options.
00108                 // <group>
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                 // </group>
00116 
00117 
00118                 // Rests custom options to defaults.
00119                 void resetOptions() const;
00120 
00121                 // Writes header comments to the file.
00122                 bool writeHeader(QTextStream& file, stringstream& errors) const;
00123 
00124                 // Writes globals (default DS9Region properties) and, if applicable, the
00125                 // overriding coordinate system.
00126                 bool writeGlobals(QTextStream& file, stringstream& errors) const;
00127 
00128                 // Writes a single shape to the file.
00129                 bool writeShape(QTextStream& file, stringstream& errors,
00130                                 const RegionShape* shape, bool isComposite = false) const;
00131 
00132 
00133                 // Returns list of all properties to be used in the globals.
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                 // Finds the DS9 region type for the given shape.  Returns true if no
00156                 // errors were reported, false otherwise.  If errors occurred they are
00157                 // logged on the given stringstream.  Note that RSMarkers are expected
00158                 // to already be converted to a DS9-friendly format.  If this method
00159                 // returns false, the given shape should NOT be written.
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                 // Converts the given RSMarker into one or more DS9-friendly RSMarkers.
00166                 // If marker is NULL or the markers is empty then an empty vector is
00167                 // returned.  Note that the caller is responsible for deleting the new
00168                 // markers.
00169                 static vector<RSMarker*> convertMarker(const RSMarker* marker,
00170                                                        bool& conversionWasNeeded);
00171 
00172                 // Converts the given value to a QString version using the given units.
00173                 // The value is assumed to be in units RegionShape::UNIT.  toUnits should
00174                 // be one of: UNIT_IPIXELS, UNIT_DEGREES, UNIT_RADIANS, PUNIT_HMS,
00175                 // PUNIT_DMS, SUNIT_ARCSEC, SUNIT_ARCMIN, or "".  If toUnits is blank, no
00176                 // converting or adding a unit is done.
00177                 static QString convertValue(double value, const String& toUnits,
00178                                             int precision);
00179 
00180                 // Converts the given position unit, if applicable, from sexagesimal to
00181                 // either HMS or DMS.  Does nothing if the position unit is not
00182                 // sexagesimal.
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 // Widget used for entering options specific to the DS9 format.
00194         class QtDS9RFWOptions : public QWidget, Ui::DS9WriteOptions {
00195                 Q_OBJECT
00196 
00197         public:
00198                 // Constructor.
00199                 QtDS9RFWOptions();
00200 
00201                 // Destructor.
00202                 ~QtDS9RFWOptions();
00203 
00204 
00205                 // Returns true if the user picked a custom coordinate system, false if
00206                 // DS9RegionFileWriter::CSYS_INDIVIDUAL was chosen.
00207                 bool isCustomCoordinateSystem() const;
00208 
00209                 // Returns true if the user picked a custom coordinate system and that
00210                 // system was DS9RegionFileWriter::CSYS_IMAGE, false otherwise.
00211                 bool isPixelCoordinateSystem() const;
00212 
00213                 // Returns the selected coordinate system.  This should only be used if
00214                 // customCoordinateSystem() and pixelCoordinateSystem() were both false.
00215                 // One of: DS9RegionFileWriter::CSYS_*
00216                 String getCoordinateSystem() const;
00217 
00218                 // Returns the selected position units.
00219                 // One of: DS9RegionFileWriter::UNIT_* or DS9RegionFileWriter::PUNIT_*
00220                 String getPositionUnits() const;
00221 
00222                 // Returns the selected size units.
00223                 // One of: DS9RegionFileWriter::UNIT_* or DS9RegionFileWriter::SUNIT_*
00224                 String getSizeUnits() const;
00225 
00226                 // Returns the entered decimal precision.
00227                 int getPrecision() const;
00228 
00229                 // Returned the entered comments.
00230                 String getComments() const;
00231 
00232         private slots:
00233                 // Enable/disable position and size unit chooser accordingly.
00234                 void coordinateSystemChanged(int index);
00235         };
00236 
00237 }
00238 
00239 #endif /* DS9FILEWRITER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1