PlotMSPlotParameters.h

Go to the documentation of this file.
00001 //# PlotMSPlotParameters.h: Parameter classes for PlotMSPlot classes.
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 PLOTMSPLOTPARAMETERS_H_
00028 #define PLOTMSPLOTPARAMETERS_H_
00029 
00030 #include <casa/Containers/Record.h>
00031 #include <graphics/GenericPlotter/PlotFactory.h>
00032 #include <plotms/PlotMS/PlotMSWatchedParameters.h>
00033 
00034 namespace casa {
00035 
00036 //# Forward Declarations.
00037 class PlotMSApp;
00038 
00039 
00040 // Parameters for a PlotMSPlot.  Parameters for different plot types are
00041 // defined by subparameter groups, which are in the PlotMSPlotParameterGroups
00042 // files.
00043 class PlotMSPlotParameters : public PlotMSWatchedParameters {
00044     
00045 public:
00046     // Static //
00047     
00048     // Abstract superclass representing a "group" of subparameters of a
00049     // PlotMSPlotParameters object.
00050     class Group {
00051         
00052         //# Friend class declarations.
00053         friend class PlotMSPlotParameters;
00054         
00055     public:
00056         // Constructor which takes a plot factory.
00057         Group(PlotFactoryPtr factory);
00058         
00059         // Copy constructor.  Does NOT copy parameter values using operator=().
00060         Group(const Group& copy);
00061         
00062         // Destructor.
00063         virtual ~Group();
00064         
00065         
00066         // Abstract Methods //
00067         
00068         // Returns a clone (deep copy) of this group of subparameters.
00069         virtual Group* clone() const = 0;
00070         
00071         // Returns the name of this group of subparameters.  Will be used as an
00072         // update flag.
00073         virtual const String& name() const = 0;
00074         
00075         // Returns a Record representing this group of subparameters.
00076         virtual Record toRecord() const = 0;
00077         
00078         // Sets the values for this group of subparameters using the given
00079         // Record.
00080         virtual void fromRecord(const Record& record) = 0;
00081         
00082         // Returns true if the plot needs to be redrawn when subpamarameters in
00083         // this group have changed, false otherwise.
00084         virtual bool requiresRedrawOnChange() const = 0;
00085         
00086         
00087         // Implemented Methods //
00088         
00089         // Copy operator.  Should probably be overridden by children to be more
00090         // efficient.  Only copies if the two groups have the same name.
00091         virtual Group& operator=(const Group& other);
00092         
00093         // Equality operators.  Should probably be overridden by children to be
00094         // more efficient.
00095         virtual bool operator==(const Group& other) const;
00096         virtual bool operator!=(const Group& other) const {
00097             return !(operator==(other)); }
00098         
00099     protected:
00100         // Should be called by the child class whenever any of the
00101         // subparameter values have been updated.
00102         // <group>
00103         void updated() { updated(requiresRedrawOnChange()); }
00104         void updated(bool requiresRedraw);
00105         // </group>
00106         
00107         // Returns the parent parameters, or NULL for none.
00108         // <group>
00109         PlotMSPlotParameters* parent() { return itsParent_; }
00110         const PlotMSPlotParameters* parent() const { return itsParent_; }
00111         // </group>
00112         
00113         // Returns the factory.
00114         // <group>
00115         PlotFactoryPtr factory() { return itsFactory_; }
00116         const PlotFactoryPtr factory() const { return itsFactory_; }
00117         // </group>
00118         
00119     private:
00120         // Parent of this group of subparameters.
00121         PlotMSPlotParameters* itsParent_;
00122         
00123         // Factory.
00124         PlotFactoryPtr itsFactory_;
00125         
00126         
00127         // Post-thread method for notifying watchers that this group has
00128         // changed.
00129     public:
00130                 static void
00131                 notifyWatchers (void *obj, bool wasCanceled)
00132                 {
00133                         Group *cobj = static_cast < Group * >(obj);
00134                         if (cobj != NULL)
00135                                 cobj->notifyWatchers_ (wasCanceled);
00136                 }
00137         private:
00138                 void notifyWatchers_ (bool wasCanceled);
00139                 
00140         
00141             };
00142             
00143     //# Friend class declarations.
00144     friend class PlotMSPlotParameters::Group;
00145     
00146     
00147     // Non-Static //
00148     
00149     // Constructor, which starts out with no subparameter groups.
00150     PlotMSPlotParameters(PlotFactoryPtr factory);
00151     
00152     // Copy constructor.  See operator=().
00153     PlotMSPlotParameters(const PlotMSPlotParameters& copy);
00154     
00155     // Destructor.
00156     ~PlotMSPlotParameters();
00157     
00158     
00159     // Implements PlotMSWatchedParameters::equals().  Will return false if the
00160     // other parameters are not of type PlotMSPlotParameters.
00161     bool equals(const PlotMSWatchedParameters& other, int updateFlags) const;
00162 
00163     
00164     // Returns the subparameters group with the given name, or NULL for none.
00165     // <group>
00166     const Group* group(const String& name) const;
00167     Group* group(const String& name);
00168     // </group>
00169     
00170     // Returns the templated type of subparameters group, or NULL for none.
00171     // <group>
00172     template <class T>
00173     const T* typedGroup() const {
00174         const T* g = NULL;
00175         for(unsigned int i = 0; i < itsGroups_.size(); i++)
00176             if((g = dynamic_cast<const T*>(itsGroups_[i])) != NULL) return g;
00177         return NULL;
00178     }
00179     template <class T>
00180     T* typedGroup() {
00181         T* g = NULL;
00182         for(unsigned int i = 0; i < itsGroups_.size(); i++){
00183             if((g = dynamic_cast<T*>(itsGroups_[i])) != NULL) return g;
00184         }
00185         return NULL;
00186     }
00187     // </group>
00188     
00189     // Sets (or adds) the given group of subparameters in this object, cloning
00190     // it.
00191     void setGroup(const Group& group);
00192     
00193     // Sets (or adds) the default constructor of the templated type of
00194     // subparameters group.
00195     template <class T>
00196     void setGroup() { setGroup(T(itsFactory_)); }
00197     
00198     
00199     // Copy operator.  Copies subparameters groups.
00200     PlotMSPlotParameters& operator=(const PlotMSPlotParameters& copy);
00201 
00202 
00203 protected:
00204     // Factory.
00205     PlotFactoryPtr itsFactory_;
00206     
00207     // Notifies any watchers that the parameters have been updated with the
00208     // given flags.  If an updater is given, it is NOT notified.
00209     // <group>
00210     void notifyWatchers(int updateFlags,
00211             PlotMSParametersWatcher* updater = NULL);
00212     void notifyWatchers(const String& updateName,
00213             PlotMSParametersWatcher* updater = NULL) {
00214         notifyWatchers(UPDATE_FLAG(updateName), updater); }
00215     // </group>
00216     
00217 private:
00218     // Subparameter groups.
00219     vector<Group*> itsGroups_;
00220     
00221     
00222     // To be called when one of the groups is updated.
00223     void groupUpdated(Group* group, bool requiresRedraw);
00224 };
00225 
00226 // Helper macros to simplify calling a method on a subparameters group.
00227 // <group>
00228 #define PMS_PP_CALL(PARAMS, GROUP, METHOD, ...)                               \
00229     if( PARAMS .typedGroup< GROUP >() != NULL)                                \
00230         PARAMS .typedGroup< GROUP >()-> METHOD ( __VA_ARGS__ );
00231 
00232 #define PMS_PP_RETCALL(PARAMS, GROUP, METHOD, DEFAULT, ...)                   \
00233     (PARAMS .typedGroup< GROUP >() == NULL ? DEFAULT :                        \
00234         PARAMS .typedGroup< GROUP >()-> METHOD ( __VA_ARGS__ ))
00235 // </group>
00236 
00237 }
00238 
00239 #endif /* PLOTMSPLOTPARAMETERS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1