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