casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DParameterChoice.h
Go to the documentation of this file.
00001 //# DParameterChoice.h: class to store and retrieve Choice parameters 
00002 //# Copyright (C) 2000,2001
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 TRIALDISPLAY_DPARAMETERCHOICE_H
00029 #define TRIALDISPLAY_DPARAMETERCHOICE_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Vector.h>
00033 #include <display/Display/DisplayParameter.h>
00034 #include <display/Display/ColormapDefinition.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary>
00039 // Implementation of DisplayParameter to store choice parameters.
00040 // </summary>
00041 
00042 // <use visibility=export>
00043 
00044 // <reviewed reviewer="" date="" test="" demos="">
00045 // </reviewed>
00046 
00047 // <prerequisite>
00048 // <li> <linkto class=DisplayParameter>DisplayParameter</linkto>
00049 // </prerequisite>
00050 
00051 // <etymology>
00052 // DParameterChoice is an implementation of a DisplayParameter
00053 // providing a choice parameter type.
00054 // </etymology>
00055 
00056 // <synopsis>
00057 // This class is derived from <linkto
00058 // class=DisplayParameter>DisplayParameter</linkto> and provides a
00059 // choice-type parameter.  Choice parameters simply have a vector
00060 // of possible String selections, and a default selection.  They
00061 // cannot be unset.
00062 // </synopsis>
00063 
00064 // <example>
00065 
00066 // A DParameterChoice can easily be used to store and update any
00067 // parameter which can be expressed as a selection from two or more
00068 // options.  In the following example, a DParameterChoice is
00069 // constructed to provide the name of the font to use in axis
00070 // labelling:
00071 // <srcblock>
00072 // Vector<String> fonts(4);
00073 // fonts(0) = "roman";
00074 // // ...
00075 // DParameterChoice pchoice("font", "Label font", 
00076 //                          "Select the font to use for axis labelling",
00077 //                          fonts, fonts(0), fonts(0));
00078 //
00079 // // ...
00080 // 
00081 // // update the parameter from some Record
00082 // pchoice.fromRecord(rec);
00083 //
00084 // // examine the value of the parameter
00085 // if (pchoice.value() == "italic") {
00086 // // ...
00087 // }
00088 // </srcblock>
00089 // </example>
00090 
00091 // <motivation>
00092 // Many parameters are naturally choices, or can be expressed as
00093 // choices, hence this class.
00094 // </motivation>
00095 
00096 // <thrown>
00097 // <li> None.
00098 // </thrown>
00099 
00100 // <todo asof="2000/01/31">
00101 // <li> Nothing known.
00102 // </todo>
00103 
00104 class DParameterChoice : public DisplayParameter {
00105 
00106  public:
00107 
00108   // Constructor taking the name of the parameter, a short
00109   // description, some help text, a list of allowed options, a default
00110   // value, an initial value, the context of the parameter, and a flag
00111   // indicating whether the parameter is editable.  Obviously the
00112   // <src>defaultvalue</src> and <src>value</src> parameters must
00113   // exist in the list of allowed options, otherwise an exception
00114   // is thrown.
00115   DParameterChoice(const String name, const String description,
00116                    const String help, const Vector<String> &options,
00117                    const String defaultvalue, const String value, 
00118                    const String context = "", const Bool editable = False);
00119   DParameterChoice(const String name, const String description,
00120                    const String help, const ColormapDefinition::colormapnamemap &options,
00121                    const String defaultvalue, const String value, 
00122                    const String context = "", const Bool editable = False);
00123 
00124   // (Required) copy constructor.
00125   DParameterChoice(const DParameterChoice &other);
00126 
00127   // Destructor.
00128   virtual ~DParameterChoice();
00129 
00130   // (Required) copy assignment.
00131   DParameterChoice &operator=(const DParameterChoice &other);
00132 
00133   // Parse <src>record</src>, and update this parameter if a field
00134   // exists whose name matches that of this parameter.  Return
00135   // <src>True</src> if the parameter is changed, otherwise return
00136   // <src>False</src>.
00137   virtual Bool fromRecord(const RecordInterface &record);
00138 
00139   // Place a record describing this parameter in a sub-field of
00140   // <src>record</src> with name matching that of this parameter.  If
00141   // <src>overwrite</src> is <src>True</src>, then any existing field
00142   // with matching name will be overwritten.  If <src>fullrecord</src>
00143   // is <src>True</src>, then a complete description of the parameter
00144   // is given, otherwise just its current value is stored in
00145   // <src>record</src>.  Presently <src>fullrecord</src> is ignored.
00146   virtual void toRecord(RecordInterface &record, const Bool fullrecord = True,
00147                         const Bool overwrite = False);
00148 
00149   // Return the list of allowed options for this parameter.
00150   Vector<String> options() const
00151     { return itsOptions; }
00152 
00153   // Return the default for this parameter.
00154   String defaultValue() 
00155     { return itsDefaultValue; }
00156 
00157   // Return the current value of this parameter.
00158   String value() 
00159     { return itsValue; }
00160 
00161   // Set or change if this parameter is editable (determines wether
00162   // choice or userchoice is returned in the record
00163   void setEditable(const Bool editable)
00164   { itsEditable = editable; } 
00165 
00166   // Set or change the list of allowed options for this parameter.
00167   void setOptions(const Vector<String> &options)
00168     { itsOptions = options; }
00169 
00170   // Set or change the default value for this parameter.
00171   void setDefaultValue(const String defaultvalue)
00172     { itsDefaultValue = defaultvalue; }
00173 
00174   // Set or change the current value.
00175   void setValue(const String value)
00176     { itsValue = value; }
00177 
00178   // Convenient syntax to set (only) the value.
00179   const String& operator=(const String &value) {
00180     itsValue = value; return value;  }
00181   
00182   // Determine whether this value exists in the list of options.
00183   Bool existsOption(const String value);
00184 
00185  protected:
00186   
00187   // (Required) default constructor.
00188   DParameterChoice();
00189 
00190  private:
00191 
00192   Bool itsEditable;
00193   // Store for the allowed options for this parameter.
00194   Vector<String> itsOptions;
00195 
00196   // Store for the default of this parameter.
00197   String itsDefaultValue;
00198 
00199   // Store for the value of this parameter.
00200   String itsValue;
00201 
00202 };
00203 
00204 
00205 } //# NAMESPACE CASA - END
00206 
00207 #endif