casa
$Rev:20696$
|
00001 //# PlotMSConstants.h: Constants and useful classes/methods for plotms. 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 #ifndef PLOTMSCONSTANTS_H_ 00028 #define PLOTMSCONSTANTS_H_ 00029 00030 #include <casa/Containers/Record.h> 00031 #include <graphics/GenericPlotter/PlotFactory.h> 00032 00033 #include <map> 00034 #include <vector> 00035 00036 #include <casa/namespace.h> 00037 using namespace std; 00038 00039 namespace casa { 00040 00041 // Useful macros for defining enums. Although the two macros can be used 00042 // separately, their intended use is for them to be used sequentially. 00043 // Parameters: 00044 // * NAME: name of the enum, 00045 // * ALLMETHOD: name of the method that returns a vector of all defined members 00046 // of the enum (also nALLMETHOD which returns the number of 00047 // defined members in the enum), 00048 // * ALLSTRMETHOD: name of the method that returns a vector of the string 00049 // representation of all defined members of the enum, 00050 // * CONVMETHOD: name of the method that converts between the enum and its 00051 // String representation, 00052 // * ... (__VA_ARGS__): list of enum methods for PMS_ENUM1 and list of 00053 // their string representations for PMS_ENUM2. IMPORTANT: 00054 // if both macros are used then the lists must be the same 00055 // size and in the same order. 00056 // <group> 00057 #define PMS_ENUM1(NAME,ALLMETHOD,ALLSTRMETHOD,CONVMETHOD,...) \ 00058 enum NAME { \ 00059 __VA_ARGS__ \ 00060 }; \ 00061 \ 00062 static const vector< NAME >& ALLMETHOD () { \ 00063 static const NAME arr[] = { \ 00064 __VA_ARGS__ \ 00065 }; \ 00066 static const int count = sizeof(arr) / sizeof(arr[0]); \ 00067 static const vector< NAME > v(arr, &arr[count]); \ 00068 return v; \ 00069 } \ 00070 \ 00071 static unsigned int n##ALLMETHOD () { \ 00072 static unsigned int n = ALLMETHOD ().size(); \ 00073 return n; \ 00074 } 00075 00076 #define PMS_ENUM2(NAME,ALLMETHOD,ALLSTRMETHOD,CONVMETHOD,...) \ 00077 static const vector<String>& ALLSTRMETHOD () { \ 00078 static const String arr[] = { \ 00079 __VA_ARGS__ \ 00080 }; \ 00081 static const int count = sizeof(arr) / sizeof(arr[0]); \ 00082 static const vector<String> v(arr, &arr[count]); \ 00083 return v; \ 00084 } \ 00085 \ 00086 static const String& CONVMETHOD ( NAME v) { \ 00087 return ALLSTRMETHOD ()[v]; } \ 00088 \ 00089 static const NAME & CONVMETHOD (const String& v, bool* ok = NULL) { \ 00090 const vector<String>& strs = ALLSTRMETHOD (); \ 00091 const vector< NAME >& enms = ALLMETHOD (); \ 00092 for(unsigned int i = 0; i < strs.size(); i++) { \ 00093 if(PMS::strEq(v, strs[i], true)) { \ 00094 if(ok != NULL) *ok = true; \ 00095 return enms[i]; \ 00096 } \ 00097 } \ 00098 if(ok != NULL) *ok = false; \ 00099 return enms[0]; \ 00100 } 00101 // </group> 00102 00103 00104 // Container class for useful constants/methods. 00105 class PMS { 00106 public: 00107 // Enum for the axis choices that are available to be plotted. Used both 00108 // by the user to select what to plot and by the cache loading system. 00109 // **If these are changed, also update: xmlcasa/tasks/plotms.xml, 00110 // xmlcasa/scripts/task_plotms.py.** 00111 // <group> 00112 PMS_ENUM1(Axis, axes, axesStrings, axis, 00113 SCAN,FIELD,TIME,TIME_INTERVAL, 00114 SPW,CHANNEL,FREQUENCY,VELOCITY,CORR, 00115 ANTENNA1,ANTENNA2,BASELINE,ROW, 00116 AMP,PHASE,REAL,IMAG,WT,WTxAMP, 00117 FLAG,FLAG_ROW, 00118 UVDIST,UVDIST_L,U,V,W,UWAVE,VWAVE,WWAVE, 00119 AZ0,EL0,HA0,PA0, 00120 ANTENNA,AZIMUTH,ELEVATION,PARANG, 00121 GAMP,GPHASE,GREAL,GIMAG, 00122 DELAY,SWP,TSYS,OPAC, 00123 NONE) 00124 00125 PMS_ENUM2(Axis, axes, axesStrings, axis, 00126 "Scan","Field","Time","Interval", 00127 "Spw","Channel","Frequency","Velocity","Corr", 00128 "Antenna1","Antenna2","Baseline","Row", 00129 "Amp","Phase","Real","Imag","Wt","Wt*Amp", 00130 "Flag","FlagRow", 00131 "UVdist","UVwave","U","V","W","Uwave","Vwave","Wwave", 00132 "Azimuth","Elevation","HourAngle","ParAngle", 00133 "Antenna","Ant-Azimuth","Ant-Elevation","Ant-ParAngle", 00134 "GainAmp","GainPhase","GainReal","GainImag", 00135 "Delay","SwPower","Tsys","Opac", 00136 "None") 00137 00138 // </group> 00139 00140 // Returns the axes scale for the given axis. Currently NORMAL unless the 00141 // axis is TIME, in which case the scale is DATE_MJ_SEC. 00142 static PlotAxisScale axisScale(Axis axis); 00143 00144 00145 // Enum for the different data columns for data axes. 00146 // **If these are changed, also update: xmlcasa/tasks/plotms.xml.** 00147 // <group> 00148 PMS_ENUM1(DataColumn, dataColumns, dataColumnStrings, dataColumn, 00149 DATA, CORRECTED, MODEL, CORRMODEL, DATAMODEL) 00150 PMS_ENUM2(DataColumn, dataColumns, dataColumnStrings, dataColumn, 00151 "data", "corrected", "model", "corrected-model", "data-model") 00152 // </group> 00153 00154 // Returns whether or not the given axis needs the second data parameter to 00155 // indicate which data column to use or not. Currently false except for 00156 // AMP, PHASE, REAL, and IMAG. 00157 static bool axisIsData(Axis axis); 00158 00159 00160 // Enum for different axes types. Currently only used to display this 00161 // information to the user in the GUI's cache tab. 00162 // <group> 00163 PMS_ENUM1(AxisType, axesTypes, axesTypeStrings, axisType, 00164 TBOOL, TINT, TFLOAT, TDOUBLE, TTIME) 00165 PMS_ENUM2(AxisType, axesTypes, axesTypeStrings, axisType, 00166 "boolean", "integer", "float", "double", "time") 00167 //</group> 00168 00169 // Returns the type for the given axis. 00170 static AxisType axisType(Axis axis); 00171 00172 00173 // Enum for different axes units. Currently only used in labels. 00174 // <group> 00175 PMS_ENUM1(AxisUnit, axesUnits, axesUnitStrings, axisUnit, 00176 UNONE, UDATETIME) 00177 PMS_ENUM2(AxisUnit, axesUnits, axesUnitStrings, axisUnit, 00178 "", "date-time") 00179 // </group> 00180 00181 // Returns the unit for the given axis. 00182 static AxisUnit axisUnit(Axis axis); 00183 00184 00185 // Convert to/from dates and doubles, using the given scale (must be either 00186 // DATE_MJ_SEC or DATE_MJ_DAY). 00187 // <group> 00188 static double dateDouble(unsigned int year, unsigned int mon, 00189 unsigned int day, unsigned int hour, unsigned int min, 00190 double sec, PlotAxisScale scale = DATE_MJ_SEC); 00191 static void dateDouble(double value, unsigned int& year, unsigned int& mon, 00192 unsigned int& day, unsigned int& hour, unsigned int& min, 00193 double& sec, PlotAxisScale scale = DATE_MJ_SEC); 00194 // </group> 00195 00196 // Returns true if the given Strings are equals, false otherwise. If 00197 // ignoreCase is false then it is a direct String comparison using ==; 00198 // otherwise the String characters are compared while ignoring case for 00199 // letters. 00200 static bool strEq(const String& str1, const String& str2, 00201 bool ignoreCase = false); 00202 00203 // Returns true if the given Records are equals, false otherwise. 00204 static bool recEq(const Record& rec1, const Record& rec2); 00205 00206 // Converts the given templated vector to/from an int Vector. 00207 // <group> 00208 template <class T> 00209 static Vector<int> toIntVector(const vector<T>& v) { 00210 Vector<int> v2(v.size()); 00211 for(unsigned int i = 0; i < v.size(); i++) v2[i] = (int)v[i]; 00212 return v2; 00213 } 00214 00215 template <class T> 00216 static vector<T> fromIntVector(const Vector<int>& v) { 00217 vector<T> v2(v.size()); 00218 for(unsigned int i = 0; i < v.size(); i++) v2[i] = (T)v[i]; 00219 return v2; 00220 } 00221 // </group> 00222 00223 00224 // Enum for the different MS summary types. 00225 // <group> 00226 PMS_ENUM1(SummaryType, summaryTypes, summaryTypeStrings, summaryType, 00227 S_ALL, S_WHERE, S_WHAT, S_HOW, S_MAIN, S_TABLES, S_ANTENNA, 00228 S_FEED, S_FIELD, S_OBSERVATION, S_HISTORY, S_POLARIZATION, 00229 S_SOURCE, S_SPW, S_SPW_POL, 00230 S_SYSCAL, S_WEATHER) 00231 00232 PMS_ENUM2(SummaryType, summaryTypes, summaryTypeStrings, summaryType, 00233 "All", "Where", "What", "How", "Main", "Tables", "Antenna", 00234 "Feed", "Field", "Observation", "History", "Polarization", 00235 "Source", "Spectral Window", "Spectral Window and Polarization", 00236 "SysCal", "Weather") 00237 // </group> 00238 00239 00240 // Colorizing Values // 00241 00242 // Returns the list of unique colors used to colorize plots. 00243 static const vector<String>& COLORS_LIST(); 00244 00245 00246 // Default Parameter Values // 00247 00248 // Default values for PlotMSParameters. 00249 // <group> 00250 static const String DEFAULT_LOG_FILENAME; 00251 static const int DEFAULT_LOG_EVENTS; 00252 static const LogMessage::Priority DEFAULT_LOG_PRIORITY; 00253 static const bool DEFAULT_CLEAR_SELECTIONS; 00254 static const int DEFAULT_CACHED_IMAGE_WIDTH; 00255 static const int DEFAULT_CACHED_IMAGE_HEIGHT; 00256 // </group> 00257 00258 // Default values for PMS_PP_Cache. 00259 // <group> 00260 static const Axis DEFAULT_XAXIS; 00261 static const Axis DEFAULT_YAXIS; 00262 static const DataColumn DEFAULT_DATACOLUMN; 00263 static const Axis DEFAULT_COLOR_AXIS; 00264 // </group> 00265 00266 // Default values for PMS_PP_Canvas. 00267 // <group> 00268 static const PlotAxis DEFAULT_CANVAS_XAXIS; 00269 static const PlotAxis DEFAULT_CANVAS_YAXIS; 00270 static const String DEFAULT_CANVAS_AXIS_LABEL_FORMAT; 00271 static const bool DEFAULT_SHOWAXIS; 00272 static const bool DEFAULT_SHOWLEGEND; 00273 static const PlotCanvas::LegendPosition DEFAULT_LEGENDPOSITION; 00274 static const bool DEFAULT_SHOW_GRID; 00275 static PlotLinePtr DEFAULT_GRID_LINE(PlotFactoryPtr factory); 00276 static const String DEFAULT_TITLE_FORMAT; 00277 // </group> 00278 00279 // Default values for PMS_PP_Display. 00280 // <group> 00281 static PlotSymbolPtr DEFAULT_UNFLAGGED_SYMBOL(PlotFactoryPtr factory); 00282 static PlotSymbolPtr DEFAULT_FLAGGED_SYMBOL(PlotFactoryPtr factory); 00283 // </group> 00284 00285 // Returns the minimum visible sizes for plot symbol types. 00286 static map<PlotSymbol::Symbol, int> SYMBOL_MINIMUM_SIZES(); 00287 00288 // Default text annotation properties. 00289 // <group> 00290 static PlotFontPtr DEFAULT_ANNOTATION_TEXT_FONT(PlotFactoryPtr factory); 00291 static PlotLinePtr DEFAULT_ANNOTATION_TEXT_OUTLINE(PlotFactoryPtr factory); 00292 static PlotAreaFillPtr DEFAULT_ANNOTATION_TEXT_BACKGROUND( 00293 PlotFactoryPtr factory); 00294 // </group> 00295 00296 // Default rectangle annotation properties. 00297 // <group> 00298 static PlotLinePtr DEFAULT_ANNOTATION_RECT_LINE(PlotFactoryPtr factory); 00299 static PlotAreaFillPtr DEFAULT_ANNOTATION_RECT_FILL(PlotFactoryPtr f); 00300 // </group> 00301 00302 00303 // Logging Constants // 00304 00305 // Log class origin. 00306 static const String LOG_ORIGIN; 00307 00308 // Log event origin names. 00309 // <group> 00310 static const String LOG_ORIGIN_DBUS; 00311 static const String LOG_ORIGIN_FLAG; 00312 static const String LOG_ORIGIN_LOAD_CACHE; 00313 static const String LOG_ORIGIN_LOCATE; 00314 static const String LOG_ORIGIN_PARAMS_CHANGED; 00315 static const String LOG_ORIGIN_PLOT; 00316 static const String LOG_ORIGIN_RELEASE_CACHE; 00317 static const String LOG_ORIGIN_UNFLAG; 00318 static const String LOG_ORIGIN_SUMMARY; 00319 // </group> 00320 00321 // Log event flags. 00322 // <group> 00323 static const int LOG_EVENT_DBUS; 00324 static const int LOG_EVENT_FLAG; 00325 static const int LOG_EVENT_LOAD_CACHE; 00326 static const int LOG_EVENT_LOCATE; 00327 static const int LOG_EVENT_PARAMS_CHANGED; 00328 static const int LOG_EVENT_PLOT; 00329 static const int LOG_EVENT_RELEASE_CACHE; 00330 static const int LOG_EVENT_UNFLAG; 00331 static const int LOG_EVENT_SUMMARY; 00332 // </group> 00333 }; 00334 00335 } 00336 00337 #endif /* PLOTMSCONSTANTS_H_ */