00001 //# RegionFileReaderWriter.h: Interfaces for classes that read/write image regions. 00002 //# Copyright (C) 2009 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 00028 #ifndef IMAGES_RFREADERWRITER_H 00029 #define IMAGES_RFREADERWRITER_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/Logging/LogIO.h> 00034 #include <casacore/casa/Containers/Record.h> 00035 #include <casacore/coordinates/Coordinates/CoordinateSystem.h> 00036 00037 namespace casacore {//# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward declarations 00040 class RFReader; 00041 class RFWriter; 00042 00043 // <summary> 00044 // Convenience class for a String/bool pair. 00045 // </summary> 00046 // 00047 // <use visibility=export> 00048 // 00049 // <reviewed reviewer="" date="" tests=""> 00050 // </reviewed> 00051 // 00052 // <prerequisite> 00053 // </prerequisite> 00054 // 00055 // <synopsis> 00056 // </synopsis> 00057 // 00058 // <example> 00059 // <srcblock> 00060 // </srcblock> 00061 // </example> 00062 // 00063 //# <todo asof="2009/03/10"> 00064 //# <li> 00065 //# </todo> 00066 00067 class RFError 00068 { 00069 public: 00070 // Constructor, blank error. 00071 RFError(); 00072 00073 // Constructor, error with the given text and isFatal flag. 00074 RFError(const String& error, bool isFatal = false); 00075 00076 // Destructor. 00077 ~RFError(); 00078 00079 // Returns whether this error was fatal or not. 00080 bool isFatal() const; 00081 00082 // Returns this error's text. 00083 const String& error() const; 00084 00085 // Sets the error. 00086 void set(const String& error, bool isFatal = false); 00087 00088 private: 00089 String error_p; 00090 bool fatal_p; 00091 }; 00092 00093 00094 // <summary> 00095 // Superclass for readers and writers containing common definitions and 00096 // operations. 00097 // </summary> 00098 // 00099 // <use visibility=export> 00100 // 00101 // <reviewed reviewer="" date="" tests=""> 00102 // </reviewed> 00103 // 00104 // <prerequisite> 00105 // </prerequisite> 00106 // 00107 // <synopsis> 00108 // </synopsis> 00109 // 00110 // <example> 00111 // <srcblock> 00112 // </srcblock> 00113 // </example> 00114 // 00115 //# <todo asof="2009/03/10"> 00116 //# <li> 00117 //# </todo> 00118 00119 class RFReaderWriter 00120 { 00121 public: 00122 // An enum of all known subclasses/formats supported. 00123 enum SupportedType { 00124 AIPS_BOX, DS9, CASA_XML, AIPS_IO 00125 }; 00126 00127 // Converts between enum and String for SupportedType. 00128 // <group> 00129 static SupportedType supportedTypes(String type); 00130 static String supportedTypes(SupportedType type); 00131 // </group> 00132 00133 // Returns the file extension for the given SupportedType. 00134 static String extensionForType(SupportedType type); 00135 00136 // Returns all known SupportedTypes. 00137 // <group> 00138 static Vector<SupportedType> supportedTypes(); 00139 static Vector<String> supportedTypeStrings(); 00140 // </group> 00141 00142 // Returns an appropriate child RFReader class for the given 00143 // SupportedType, or NULL for an error (shouldn't happen). 00144 static RFReader* readerForType(SupportedType type); 00145 00146 // Returns an new appropriate child RfWriter class for the given 00147 // SupportedType, or NULL for an error (shouldn't happen). 00148 static RFWriter* writerForType(SupportedType type); 00149 00150 // Returns an new appropriate options widget for the given SupportedType, 00151 // or NULL for an error (shouldn't happen). 00152 static Record* optionsWidgetForType(SupportedType type); 00153 00154 00155 // Constructor. 00156 RFReaderWriter() { } 00157 00158 // Destructor. 00159 virtual ~RFReaderWriter() { } 00160 00161 // Sets the file to be read/written to the given. 00162 virtual void setFile(const String& filename); 00163 00164 // Sets the region name associated withe the file to be read or written. 00165 virtual void setName(const String& regionName); 00166 00167 // Returns the last error set during read/write. 00168 virtual const RFError& lastError() const; 00169 00170 protected: 00171 // Filename to be read/written. 00172 String *pFilename_p; 00173 00174 // Name to be assigned to the region 00175 String *pRegionName_p; 00176 00177 // Last error seen during read/write. 00178 RFError lastError_p; 00179 00180 // Record containg plotting options for the regions 00181 Record options_p; 00182 00183 // Convenience method for setting last error during read/write. 00184 virtual void setError(const String& error, bool fatal = false) const; 00185 }; 00186 00187 00188 // <summary> 00189 // Abstract superclass for any class that reads a format that produces 00190 // Regions from a file. 00191 // </summary> 00192 // 00193 // <use visibility=export> 00194 // 00195 // <reviewed reviewer="" date="" tests=""> 00196 // </reviewed> 00197 // 00198 // <prerequisite> 00199 // </prerequisite> 00200 // 00201 // <synopsis> 00202 // Provide a well defined set of operations for reading 00203 // region files, regardless of the data format. 00204 // 00205 // Note that some file formats allow for plotting options 00206 // to be defined as well as the regions. These options are 00207 // read and stored in a record of ... , the contents 00208 // of this record is ill-defined (ie. there is no standard). 00209 // 00210 // There may come a time where a standard is necessary. 00211 // </synopsis> 00212 // 00213 // <example> 00214 // <srcblock> 00215 // </srcblock> 00216 // </example> 00217 // 00218 //# <todo asof="2009/03/10"> 00219 //# <li> 00220 //# </todo> 00221 00222 class RFReader : public virtual RFReaderWriter 00223 { 00224 public: 00225 // Constructor. 00226 RFReader() { } 00227 00228 // Destructor. 00229 virtual ~RFReader() { } 00230 00231 // Provides access to the plotting options that 00232 // were found in the region file. 00233 virtual Record* options() { 00234 return &options_p; 00235 }; 00236 00237 // reported, false otherwise. If false is returned, the details can be 00238 // found using lastError(). Any valid Regions that were read from the 00239 // file are placed in the given vector (which is cleared first). 00240 virtual bool read(Record& region) = 0; 00241 00242 00243 // Calls setFile() then read(). 00244 virtual bool readFile(const String& file, Record& region) { 00245 setFile(file); 00246 return read(region); 00247 } 00248 }; 00249 00250 00251 // <summary> 00252 // Abstract superclass for any class that writes Regions to a region 00253 // file format. 00254 // </summary> 00255 // 00256 // <use visibility=export> 00257 // 00258 // <reviewed reviewer="" date="" tests=""> 00259 // </reviewed> 00260 // 00261 // <prerequisite> 00262 // </prerequisite> 00263 // 00264 // <synopsis> 00265 // Provide a well defined set of operations that all 00266 // region file writers must contain regardless of the 00267 // file format of the file being saved. . 00268 // 00269 // Note that some file formats allow for plotting options 00270 // to be stored with the region information. The setOptions 00271 // method allows the user to supply this information. 00272 // </synopsis> 00273 // 00274 // <example> 00275 // <srcblock> 00276 // </srcblock> 00277 // </example> 00278 // 00279 //# <todo asof="2009/03/10"> 00280 //# <li> 00281 //# </todo> 00282 00283 class RFWriter : public virtual RFReaderWriter 00284 { 00285 public: 00286 // Constructor. 00287 RFWriter() { } 00288 00289 // Destructor. 00290 virtual ~RFWriter() { } 00291 00292 // Sets the optional to the values. These values are related to 00293 // the drawing of regions and not defining the regions themselves. 00294 // For example, the colour to draw the region as. 00295 virtual void setOptions(const Record* options) { 00296 options_p.defineRecord( "regionoptions", *options ); 00297 }; 00298 00299 00300 // Write the given regions to the filename set with setFile and returns 00301 // true if no errors were reported, false otherwise. If false is returned, 00302 // the details can be found using lastError(). 00303 virtual bool write(const Record& region) const = 0; 00304 00305 // Calls setFile then write. 00306 virtual bool writeFile(const String& filename, 00307 const Record& regions) { 00308 setFile(filename); 00309 return write(regions); 00310 } 00311 }; 00312 00313 } //# end namespace 00314 00315 #endif