casa
$Rev:20696$
|
00001 //# PlotMSLabelFormat.h: Class for generating labels based on a format. 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 PLOTMSLABELFORMAT_H_ 00028 #define PLOTMSLABELFORMAT_H_ 00029 00030 #include <plotms/PlotMS/PlotMSConstants.h> 00031 00032 #include <casa/namespace.h> 00033 00034 namespace casa { 00035 00036 //# Forward declarations. 00037 class PlotMSPlotParameters; 00038 00039 00040 // Class for generating labels based upon axes, units, etc. A format is a 00041 // String that consists of tags and non-tags. Tags are special substrings 00042 // differentiated by being surrounded by a separator; tags are replaced with 00043 // given values when the label is built. For example: the %%axis%% tag is 00044 // replaced with the name of the Axis that is passed in when generating the 00045 // String. Non-tags are copied exactly into the label. An example of a format 00046 // is: "%%xaxis%% vs. %%yaxis%%", when passed in the axes TIME and AMP, would 00047 // return the label "time vs. amp". Currently, labels can either be single 00048 // axis (like for an axis label) or double axes (like for a plot title). 00049 class PlotMSLabelFormat { 00050 public: 00051 // Static // 00052 00053 // Separator that goes before and after tags. 00054 static const String& TAGSEPARATOR(); 00055 00056 // Tag for axes, both the single case and the double case. This tag is 00057 // replaced with the axis name (see PMS::axis()) during generation. 00058 // <group> 00059 static const String& TAG_AXIS(); 00060 static const String& TAG_XAXIS(); 00061 static const String& TAG_YAXIS(); 00062 // </group> 00063 00064 // Tag for axes units, both the single case and the double case. This tag 00065 // is replaced with the axis unit name (see PMS::axisUnit()) during 00066 // generation. 00067 // <group> 00068 static const String& TAG_UNIT(); 00069 static const String& TAG_XUNIT(); 00070 static const String& TAG_YUNIT(); 00071 // </group> 00072 00073 // Tags for if/endif for axes units. Parts of the format that are 00074 // surrounded with an IF at the beginning and ENDIF at the end are only 00075 // copied to the label if the given unit is NOT PMS::UNONE. For example, 00076 // "TAG_IF_UNIT(sample text)TAG_ENDIF_UNIT" would copy over "(sample text)" 00077 // only if the given unit was NOT PMS::UNONE. 00078 // <group> 00079 static const String& TAG_IF_UNIT(); 00080 static const String& TAG_IF_XUNIT(); 00081 static const String& TAG_IF_YUNIT(); 00082 static const String& TAG_ENDIF_UNIT(); 00083 static const String& TAG_ENDIF_XUNIT(); 00084 static const String& TAG_ENDIF_YUNIT(); 00085 // </group> 00086 00087 // Tags for axis reference values, both the single case and the double 00088 // case. This tag is replaced with the reference value for the given axis, 00089 // if there is one, during generation. Note: if the associated axis is a 00090 // date, the value will be in date format. 00091 // <group> 00092 static const String& TAG_REFVALUE(); 00093 static const String& TAG_XREFVALUE(); 00094 static const String& TAG_YREFVALUE(); 00095 // </group> 00096 00097 // Tags for if/endif for axis reference values. Parts of the format that 00098 // are surrounded with an IF at the beginning and ENDIF at the end are only 00099 // copied to the label if the given axis has a reference value set. For 00100 // example, "TAG_IF_REFVALUE(sample text)TAG_ENDIF_REFVALUE" would copy 00101 // over "(sample text)" only if the given axis had a set reference value. 00102 // <group> 00103 static const String& TAG_IF_REFVALUE(); 00104 static const String& TAG_IF_XREFVALUE(); 00105 static const String& TAG_IF_YREFVALUE(); 00106 static const String& TAG_ENDIF_REFVALUE(); 00107 static const String& TAG_ENDIF_XREFVALUE(); 00108 static const String& TAG_ENDIF_YREFVALUE(); 00109 // </group> 00110 00111 // Convenience method to surround the given tag with the separator. 00112 static String TAG(const String& tag); 00113 00114 00115 // Non-Static // 00116 00117 // Constructor which takes an optional starting format. 00118 PlotMSLabelFormat(const String& format = ""); 00119 00120 // Copy constructor. See operator=(). 00121 PlotMSLabelFormat(const PlotMSLabelFormat& copy); 00122 00123 // Destructor. 00124 ~PlotMSLabelFormat(); 00125 00126 00127 // Format. 00128 String format; 00129 00130 00131 // Generates a label, using the given single axis and reference value. If 00132 // any double axes tags are in the format, the given axis will be used for 00133 // them. 00134 String getLabel(PMS::Axis axis, bool refValueSet = false, 00135 double refValue = 0) const; 00136 00137 // Generates a label, using the given double axes and reference values. If 00138 // any single axes tags are in the format, the x axis will be used for it. 00139 String getLabel(PMS::Axis xAxis, PMS::Axis yAxis, 00140 bool xRefValueSet = false, double xRefValue = 0, 00141 bool yRefValueSet = false, double yRefValue = 0) const; 00142 00143 // Equality operators. 00144 // <group> 00145 bool operator==(const PlotMSLabelFormat& other) const; 00146 bool operator!=(const PlotMSLabelFormat& other) const { 00147 return !(operator==(other)); } 00148 // </group> 00149 00150 // Copy operator. 00151 PlotMSLabelFormat& operator=(const PlotMSLabelFormat& copy); 00152 00153 private: 00154 // Generates a label using the given format, single axis, and double axes. 00155 static String getLabel(const String& format, PMS::Axis axis, 00156 PMS::Axis xAxis, PMS::Axis yAxis, bool refValueSet, 00157 double refValue, bool xRefValueSet, double xRefValue, 00158 bool yRefValueSet, double yRefValue); 00159 00160 // Helper method for getLabel() which gets the next token in the format. 00161 // Returns true if a token was returned; false if the end of the format was 00162 // reached. The given format will be automatically shortened as tokens are 00163 // taken out. The next token is put in the token parameter, and the 00164 // tokenWasTag parameter is set to true if the token was a tag, false 00165 // otherwise. 00166 static bool nextToken(String& format, String& token, bool& tokenWasTag); 00167 00168 // Format for when reference values are dates. 00169 static const String REFERENCE_DATE_FORMAT; 00170 }; 00171 00172 } 00173 00174 #endif /* PLOTMSLABELFORMAT_H_ */