casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DS9FileWriter.qo.h
Go to the documentation of this file.
1 //# DS9FileWriter.qo.h: DS9 implementation of RSFileWriter classes.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 #ifndef DS9FILEWRITER_QO_H_
28 #define DS9FILEWRITER_QO_H_
29 
30 #include <QTextStream>
31 
32 #include <display/RegionShapes/QtDS9WriteOptions.ui.h>
35 
36 #include <casa/namespace.h>
37 
38 namespace casa {
39 
40  class RSMarker;
41  class AnnRegion;
42 
43 // Implementation of RegionFileWriter for writing to DS9 files.
44  class DS9FileWriter : public RSFileWriter {
45  public:
46  // Options constants.
47  // </group>
63  // </group>
64 
65  // Converts a coordinate system constant (as used in DS9RFWOptions) into
66  // its DS9::CoordinateSystem equivalent.
68  if(system == CSYS_IMAGE) return DS9::Image;
69  else if(system == CSYS_B1950) return DS9::FK4;
70  else if(system == CSYS_J2000) return DS9::FK5;
71  else if(system == CSYS_GALACTIC) return DS9::Galactic;
72  else if(system == CSYS_ECLIPTIC) return DS9::Ecliptic;
73 
74  else return DS9::defaultCoordinateSystem();
75  }
76 
77  // Returns true if the given CASA world system is supported by DS9.
79  return worldSys == casacore::MDirection::B1950 ||
80  worldSys == casacore::MDirection::J2000 ||
81  worldSys == casacore::MDirection::GALACTIC ||
83  }
84 
85 
86  // Constructor.
87  DS9FileWriter();
88 
89  // Destructor.
91 
92 
93  // Implements RegionFileWriter::optionsWidget.
94  QWidget* optionsWidget() const;
95 
96  // Implements RegionFileWriter::setOptions.
97  void setOptions(const QWidget* widget);
98 
99  // Implements RegionFileWriter::write.
100  bool write(const std::vector<RegionShape*>& shapes) const;
101 
102  bool writeHeader( QTextStream & ) const;
103  bool writeFooter( QTextStream & ) const;
104  bool write( QTextStream &, AnnRegion * ) const;
105 
106  private:
107  // Custom options.
108  // <group>
115  // </group>
116 
117 
118  // Rests custom options to defaults.
119  void resetOptions() const;
120 
121  // Writes header comments to the file.
122  bool writeHeader(QTextStream& file, stringstream& errors) const;
123 
124  // Writes globals (default DS9Region properties) and, if applicable, the
125  // overriding coordinate system.
126  bool writeGlobals(QTextStream& file, stringstream& errors) const;
127 
128  // Writes a single shape to the file.
129  bool writeShape(QTextStream& file, stringstream& errors,
130  const RegionShape* shape, bool isComposite = false) const;
131 
132 
133  // Returns list of all properties to be used in the globals.
134  static std::vector<casacore::String> globalProperties() {
135  static std::vector<casacore::String> v(14);
136 
137  v[0] = DS9Region::PROP_COLOR;
138  v[1] = DS9Region::PROP_DASH;
140  v[3] = DS9Region::PROP_DELETE;
141  v[4] = DS9Region::PROP_EDIT;
142  v[5] = DS9Region::PROP_FIXED;
143  v[6] = DS9Region::PROP_FONT;
146  v[9] = DS9Region::PROP_MOVE;
147  v[10] = DS9Region::PROP_ROTATE;
148  v[11] = DS9Region::PROP_SELECT;
149  v[12] = DS9Region::PROP_SOURCE;
150  v[13] = DS9Region::PROP_WIDTH;
151 
152  return v;
153  }
154 
155  // Finds the DS9 region type for the given shape. Returns true if no
156  // errors were reported, false otherwise. If errors occurred they are
157  // logged on the given stringstream. Note that RSMarkers are expected
158  // to already be converted to a DS9-friendly format. If this method
159  // returns false, the given shape should NOT be written.
160  static bool regionType(const RegionShape* shape, DS9::RegionType& type,
161  stringstream& errors);
162  static bool regionType(const AnnRegion* shape, DS9::RegionType& type,
163  stringstream& errors);
164 
165  // Converts the given RSMarker into one or more DS9-friendly RSMarkers.
166  // If marker is NULL or the markers is empty then an empty vector is
167  // returned. Note that the caller is responsible for deleting the new
168  // markers.
169  static std::vector<RSMarker*> convertMarker(const RSMarker* marker,
170  bool& conversionWasNeeded);
171 
172  // Converts the given value to a QString version using the given units.
173  // The value is assumed to be in units RegionShape::UNIT. toUnits should
174  // be one of: UNIT_IPIXELS, UNIT_DEGREES, UNIT_RADIANS, PUNIT_HMS,
175  // PUNIT_DMS, SUNIT_ARCSEC, SUNIT_ARCMIN, or "". If toUnits is blank, no
176  // converting or adding a unit is done.
177  static QString convertValue(double value, const casacore::String& toUnits,
178  int precision);
179 
180  // Converts the given position unit, if applicable, from sexagesimal to
181  // either HMS or DMS. Does nothing if the position unit is not
182  // sexagesimal.
183  static casacore::String sgUnit(const casacore::String& posUnit, int index,
184  const casacore::String& coordSys) {
185  if(posUnit == PUNIT_SEXAGESIMAL) {
186  if(index % 2 == 0 && coordSys != CSYS_GALACTIC) return PUNIT_HMS;
187  else return PUNIT_DMS;
188  } else return posUnit;
189  }
190  };
191 
192 
193 // Widget used for entering options specific to the DS9 format.
194  class QtDS9RFWOptions : public QWidget, Ui::DS9WriteOptions {
195  Q_OBJECT
196 
197  public:
198  // Constructor.
199  QtDS9RFWOptions();
200 
201  // Destructor.
202  ~QtDS9RFWOptions();
203 
204 
205  // Returns true if the user picked a custom coordinate system, false if
206  // DS9RegionFileWriter::CSYS_INDIVIDUAL was chosen.
207  bool isCustomCoordinateSystem() const;
208 
209  // Returns true if the user picked a custom coordinate system and that
210  // system was DS9RegionFileWriter::CSYS_IMAGE, false otherwise.
211  bool isPixelCoordinateSystem() const;
212 
213  // Returns the selected coordinate system. This should only be used if
214  // customCoordinateSystem() and pixelCoordinateSystem() were both false.
215  // One of: DS9RegionFileWriter::CSYS_*
217 
218  // Returns the selected position units.
219  // One of: DS9RegionFileWriter::UNIT_* or DS9RegionFileWriter::PUNIT_*
220  casacore::String getPositionUnits() const;
221 
222  // Returns the selected size units.
223  // One of: DS9RegionFileWriter::UNIT_* or DS9RegionFileWriter::SUNIT_*
224  casacore::String getSizeUnits() const;
225 
226  // Returns the entered decimal precision.
227  int getPrecision() const;
228 
229  // Returned the entered comments.
230  casacore::String getComments() const;
231 
232  private slots:
233  // Enable/disable position and size unit chooser accordingly.
234  void coordinateSystemChanged(int index);
235  };
236 
237 }
238 
239 #endif /* DS9FILEWRITER_H_ */
static const casacore::String PROP_FONT
static const casacore::String CSYS_B1950
bool m_custCoordSys
Custom options.
static const casacore::String CSYS_INDIVIDUAL
static const casacore::String PROP_SELECT
static const casacore::String PUNIT_SEXAGESIMAL
~DS9FileWriter()
Destructor.
static std::vector< casacore::String > globalProperties()
Returns list of all properties to be used in the globals.
casacore::String m_sizeUnits
bool m_pixelCoordSys
Widget used for entering options specific to the DS9 format.
casacore::String m_coordSys
virtual Type type()
Return the type enum.
static bool isValidDS9System(casacore::MDirection::Types worldSys)
Returns true if the given CASA world system is supported by DS9.
static DS9::CoordinateSystem coordinateSystem(const casacore::String &system)
Converts a coordinate system constant (as used in DS9RFWOptions) into its DS9::CoordinateSystem equiv...
virtual bool write(const std::vector< RegionShape * > &shapes) const =0
Write the given regions to the filename set with setFile and returns true if no errors were reported...
static const casacore::String PROP_DASH
bool writeGlobals(QTextStream &file, stringstream &errors) const
Writes globals (default DS9Region properties) and, if applicable, the overriding coordinate system...
static CoordinateSystem defaultCoordinateSystem()
Definition: DS9FileReader.h:89
static const casacore::String PROP_SOURCE
virtual void setOptions(const QWidget *widget)=0
Sets the options to the values given in the widget.
static const casacore::String CSYS_ECLIPTIC
static const casacore::String SUNIT_ARCSEC
static const casacore::String CSYS_GALACTIC
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
static const casacore::String SUNIT_ARCMIN
bool writeFooter(QTextStream &) const
Abstract superclass for any class that writes RegionShapes to a region file format.
casacore::String m_comments
static QString convertValue(double value, const casacore::String &toUnits, int precision)
Converts the given value to a QString version using the given units.
static const casacore::String PUNIT_HMS
bool writeShape(QTextStream &file, stringstream &errors, const RegionShape *shape, bool isComposite=false) const
Writes a single shape to the file.
static std::vector< RSMarker * > convertMarker(const RSMarker *marker, bool &conversionWasNeeded)
Converts the given RSMarker into one or more DS9-friendly RSMarkers.
static const casacore::String PROP_INCLUDE
static const casacore::String PROP_COLOR
DS9FileWriter()
Constructor.
Subclass of RegionShape used for drawing markers.
Definition: RegionShapes.h:722
static const casacore::String PROP_DELETE
Implementation of RegionFileWriter for writing to DS9 files.
int m_precision
static casacore::String sgUnit(const casacore::String &posUnit, int index, const casacore::String &coordSys)
Converts the given position unit, if applicable, from sexagesimal to either HMS or DMS...
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
static const casacore::String PROP_MOVE
casacore::String m_posUnits
static const casacore::String PROP_EDIT
static const casacore::String PROP_WIDTH
static const casacore::String PROP_DASHLIST
static const casacore::String UNIT_IPIXELS
static const casacore::String DEFAULT_COMMENTS
static const casacore::String PUNIT_DMS
static const casacore::String UNIT_DEGREES
bool writeHeader(QTextStream &) const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static const casacore::String PROP_HIGHLITE
static const casacore::String CSYS_IMAGE
static const casacore::String PROP_ROTATE
void resetOptions() const
Rests custom options to defaults.
CoordinateSystem
casacore::Coordinate systems.
Definition: DS9FileReader.h:84
static const casacore::String CSYS_J2000
PlotCoordinate::System getCoordinateSystem() const
Overrides PlotTool::getCoordinateSystem().
static bool regionType(const RegionShape *shape, DS9::RegionType &type, stringstream &errors)
Finds the DS9 region type for the given shape.
RegionType
Regions.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
virtual QWidget * optionsWidget() const =0
Provides a custom widget that can be used to get/set options specific to each format type...
static const casacore::String PROP_FIXED
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100
static const casacore::String UNIT_RADIANS