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