casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotMSPlotParameters.h
Go to the documentation of this file.
1 //# PlotMSPlotParameters.h: Parameter classes for PlotMSPlot classes.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef PLOTMSPLOTPARAMETERS_H_
28 #define PLOTMSPLOTPARAMETERS_H_
29 
30 #include <casa/Containers/Record.h>
33 
34 namespace casa {
35 
36 //# Forward Declarations.
37 class PlotMSApp;
38 
39 
40 // Parameters for a PlotMSPlot. Parameters for different plot types are
41 // defined by subparameter groups, which are in the PlotMSPlotParameterGroups
42 // files.
44 
45 public:
46  // Static //
47 
48  // Abstract superclass representing a "group" of subparameters of a
49  // PlotMSPlotParameters object.
50  class Group {
51 
52  //# Friend class declarations.
53  friend class PlotMSPlotParameters;
54 
55  public:
56  // Constructor which takes a plot factory.
58 
59  // Copy constructor. Does NOT copy parameter values using operator=().
60  Group(const Group& copy);
61 
62  // Destructor.
63  virtual ~Group();
64 
65 
66  // Abstract Methods //
67 
68  // Returns a clone (deep copy) of this group of subparameters.
69  virtual Group* clone() const = 0;
70 
71  // Returns the name of this group of subparameters. Will be used as an
72  // update flag.
73  virtual const casacore::String& name() const = 0;
74 
75  // Returns a casacore::Record representing this group of subparameters.
76  virtual casacore::Record toRecord() const = 0;
77 
78  // Sets the values for this group of subparameters using the given
79  // Record.
80  virtual void fromRecord(const casacore::Record& record) = 0;
81 
82  // Returns true if the plot needs to be redrawn when subpamarameters in
83  // this group have changed, false otherwise.
84  virtual bool requiresRedrawOnChange() const = 0;
85 
86 
87  // Implemented Methods //
88 
89  // Copy operator. Should probably be overridden by children to be more
90  // efficient. Only copies if the two groups have the same name.
91  virtual Group& operator=(const Group& other);
92 
93  // Equality operators. Should probably be overridden by children to be
94  // more efficient.
95  virtual bool operator==(const Group& other) const;
96  virtual bool operator!=(const Group& other) const {
97  return !(operator==(other)); }
98 
99  protected:
100  // Should be called by the child class whenever any of the
101  // subparameter values have been updated.
102  // <group>
104  void updated(bool requiresRedraw);
105  // </group>
106 
107  // Returns the parent parameters, or NULL for none.
108  // <group>
110  const PlotMSPlotParameters* parent() const { return itsParent_; }
111  // </group>
112 
113  // Returns the factory.
114  // <group>
116  const PlotFactoryPtr factory() const { return itsFactory_; }
117  // </group>
118 
119  private:
120  // Parent of this group of subparameters.
122 
123  // Factory.
125 
126 
127  // Post-thread method for notifying watchers that this group has
128  // changed.
129  public:
130  static void
131  notifyWatchers (void *obj, bool wasCanceled)
132  {
133  Group *cobj = static_cast < Group * >(obj);
134  if (cobj != NULL)
135  cobj->notifyWatchers_ (wasCanceled);
136  }
137  private:
138  void notifyWatchers_ (bool wasCanceled);
139 
140 
141  };
142 
143  //# Friend class declarations.
145 
146 
147  // Non-Static //
148 
149  // Constructor, which starts out with no subparameter groups.
151 
152  // Copy constructor. See operator=().
154 
155  // Destructor.
157 
158 
159  // Implements PlotMSWatchedParameters::equals(). Will return false if the
160  // other parameters are not of type PlotMSPlotParameters.
161  bool equals(const PlotMSWatchedParameters& other, int updateFlags) const;
162 
163 
164  // Returns the subparameters group with the given name, or NULL for none.
165  // <group>
166  const Group* group(const casacore::String& name) const;
167  Group* group(const casacore::String& name);
168  // </group>
169 
170  // Returns the templated type of subparameters group, or NULL for none.
171  // <group>
172  template <class T>
173  const T* typedGroup() const {
174  const T* g = NULL;
175  for(unsigned int i = 0; i < itsGroups_.size(); i++)
176  if((g = dynamic_cast<const T*>(itsGroups_[i])) != NULL) return g;
177  return NULL;
178  }
179  template <class T>
180  T* typedGroup() {
181  T* g = NULL;
182  for(unsigned int i = 0; i < itsGroups_.size(); i++){
183  if((g = dynamic_cast<T*>(itsGroups_[i])) != NULL) return g;
184  }
185  return NULL;
186  }
187  // </group>
188 
189  // Sets (or adds) the given group of subparameters in this object, cloning
190  // it.
191  void setGroup(const Group& group);
192 
193  // Sets (or adds) the default constructor of the templated type of
194  // subparameters group.
195  template <class T>
196  void setGroup() { setGroup(T(itsFactory_)); }
197 
198 
199  // Copy operator. Copies subparameters groups.
201 
202 
203 protected:
204  // Factory.
206 
207  // Notifies any watchers that the parameters have been updated with the
208  // given flags. If an updater is given, it is NOT notified.
209  // <group>
210  void notifyWatchers(int updateFlags,
211  PlotMSParametersWatcher* updater = NULL);
212  void notifyWatchers(const casacore::String& updateName,
213  PlotMSParametersWatcher* updater = NULL) {
214  notifyWatchers(UPDATE_FLAG(updateName), updater); }
215  // </group>
216 
217 private:
218  // Subparameter groups.
219  std::vector<Group*> itsGroups_;
220 
221 
222  // To be called when one of the groups is updated.
223  void groupUpdated(Group* group, bool requiresRedraw);
224 };
225 
226 // Helper macros to simplify calling a method on a subparameters group.
227 // <group>
228 #define PMS_PP_CALL(PARAMS, GROUP, METHOD, ...) \
229  if( PARAMS .typedGroup< GROUP >() != NULL) \
230  PARAMS .typedGroup< GROUP >()-> METHOD ( __VA_ARGS__ );
231 
232 #define PMS_PP_RETCALL(PARAMS, GROUP, METHOD, DEFAULT, ...) \
233  (PARAMS .typedGroup< GROUP >() == NULL ? DEFAULT : \
234  PARAMS .typedGroup< GROUP >()-> METHOD ( __VA_ARGS__ ))
235 // </group>
236 
237 }
238 
239 #endif /* PLOTMSPLOTPARAMETERS_H_ */
const Group * group(const casacore::String &name) const
Returns the subparameters group with the given name, or NULL for none.
std::vector< Group * > itsGroups_
Subparameter groups.
static void notifyWatchers(void *obj, bool wasCanceled)
Post-thread method for notifying watchers that this group has changed.
void groupUpdated(Group *group, bool requiresRedraw)
To be called when one of the groups is updated.
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
PlotFactoryPtr factory()
Returns the factory.
PlotFactoryPtr itsFactory_
Factory.
virtual ~Group()
Destructor.
virtual Group & operator=(const Group &other)
Implemented Methods //.
Parameters for a PlotMSPlot.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
void notifyWatchers_(bool wasCanceled)
Abstract class for parameters that may be watched by one or more interested classes.
virtual bool operator!=(const Group &other) const
void updateFlags(int updateFlags)
Provides access to children to indicate which update flags are on.
void notifyWatchers(const casacore::String &updateName, PlotMSParametersWatcher *updater=NULL)
bool equals(const PlotMSWatchedParameters &other, int updateFlags) const
Implements PlotMSWatchedParameters::equals().
const PlotMSPlotParameters * parent() const
virtual casacore::Record toRecord() const =0
Returns a casacore::Record representing this group of subparameters.
virtual bool operator==(const Group &other) const
Equality operators.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
~PlotMSPlotParameters()
Destructor.
virtual Group * clone() const =0
Abstract Methods //.
void setGroup()
Sets (or adds) the default constructor of the templated type of subparameters group.
static int UPDATE_FLAG(const casacore::String &name)
Converts between an update flag&#39;s name and value, if valid.
virtual void fromRecord(const casacore::Record &record)=0
Sets the values for this group of subparameters using the given Record.
const PlotFactoryPtr factory() const
Interface for classes that wish to be notified when PlotMSWatchedParameters have changed.
PlotMSPlotParameters * itsParent_
Parent of this group of subparameters.
Group(PlotFactoryPtr factory)
Constructor which takes a plot factory.
PlotMSPlotParameters & operator=(const PlotMSPlotParameters &copy)
Copy operator.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
PlotMSPlotParameters(PlotFactoryPtr factory)
Non-Static //.
PlotMSPlotParameters * parent()
Returns the parent parameters, or NULL for none.
void notifyWatchers(int updateFlags, PlotMSParametersWatcher *updater=NULL)
Notifies any watchers that the parameters have been updated with the given flags. ...
void updated()
Should be called by the child class whenever any of the subparameter values have been updated...
virtual const casacore::String & name() const =0
Returns the name of this group of subparameters.
const T * typedGroup() const
Returns the templated type of subparameters group, or NULL for none.
virtual bool requiresRedrawOnChange() const =0
Returns true if the plot needs to be redrawn when subpamarameters in this group have changed...