PlotMSLabelFormat.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1