casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotMSPlot.h
Go to the documentation of this file.
00001 //# PlotMSPlot.h: High level plot concept across potentially multiple objects.
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 PLOTMSPLOT_H_
00028 #define PLOTMSPLOT_H_
00029 
00030 #include <graphics/GenericPlotter/PlotFactory.h>
00031 #include <plotms/Data/PlotMSCacheBase.h>
00032 #include <plotms/PlotMS/PlotMSRegions.h>
00033 #include <plotms/Plots/PlotMSPlotParameters.h>
00034 
00035 #include <casa/namespace.h>
00036 
00037 namespace casa {
00038 
00039 //# Forward declarations
00040 class PlotMSApp;
00041 class PlotMSPages;
00042 class PlotMSPlotTab;
00043 
00044 // Abstract class for a single "plot" concept.  Generally speaking this one
00045 // plot handles one data source across potentially many scatter plots and
00046 // canvases, separated by whatever criteria the subclasses decide on.  The base
00047 // class PlotMSPlot handles interfacing with the rest of PlotMS and MS file and
00048 // selection, and provides some useful members and methods for subclasses.
00049 class PlotMSPlot : public PlotMSParametersWatcher {
00050 public:
00051     // Static //    
00052     
00053     // Returns a new instance of PlotMSPlotParameters suitable for use with
00054     // this class, using the given PlotMS parent.
00055     static PlotMSPlotParameters makeParameters(PlotMSApp* plotms);
00056     
00057     // Updates the given PlotMSPlotParameters to be suitable for use with this
00058     // class, using the given PlotMS parent.
00059     static void makeParameters(PlotMSPlotParameters& params, PlotMSApp* plotms);
00060     
00061     
00062     // Non-Static //
00063     
00064     // Constructor which takes the parent PlotMS object.  Starts out with
00065     // default data parameters.
00066     PlotMSPlot(PlotMSApp* parent);
00067     
00068     // Destructor.
00069     virtual ~PlotMSPlot();
00070     
00071     
00072     // ABSTRACT METHODS //
00073     
00074     // Returns a human-readable name for this plot.  Does not have to be
00075     // unique.
00076     virtual String name() const = 0;
00077 
00078     // Returns specialization Id for this plot
00079     virtual String spectype() const { return "Unknown";};
00080     
00081     // Returns the plots assigned to this plot.
00082     virtual vector<MaskedScatterPlotPtr> plots() const = 0;
00083     
00084     // Returns the canvases that have been assigned to this plot.
00085     virtual vector<PlotCanvasPtr> canvases() const = 0;
00086     
00087     // Sets up subtabs for the given plot tab, using the add/insert subtab
00088     // methods.
00089     virtual void setupPlotSubtabs(PlotMSPlotTab& tab) const = 0;
00090     
00091     // Attaches/Detaches internal plot objects to their assigned canvases.
00092     // <group>
00093     virtual void attachToCanvases() = 0;
00094     virtual void detachFromCanvases() = 0;
00095     // </group>
00096     
00097     // Called when the GUI settings in the plot tab have changed.
00098     virtual void plotTabHasChanged(PlotMSPlotTab& tab) = 0;
00099     
00100     
00101     // IMPLEMENTED METHODS //
00102     
00103     // Returns a reference to the plot's parameters.
00104     // <group>
00105     virtual const PlotMSPlotParameters& parameters() const;
00106     virtual PlotMSPlotParameters& parameters();
00107     // </group>
00108     
00109     // Returns the visible canvases (accessible via
00110     // PlotMSPlotter::currentCanvases()) associated with this plot.
00111     virtual vector<PlotCanvasPtr> visibleCanvases() const;
00112     
00113     // Returns all selected regions on all canvases associated with this plot.
00114     virtual PlotMSRegions selectedRegions() const;
00115     
00116     // Returns selected regions on all visible canvases (accessible via
00117     // PlotMSPlotter::currentCanvases()) associated with this plot.
00118     virtual PlotMSRegions visibleSelectedRegions() const;
00119     
00120     // Initializes the plot with the given canvases.  Initializes any internal
00121     // plot objects via the protected initializePlot() method, then assigns
00122     // the plot objects to the canvases via the protected assignCanvases()
00123     // method, then calls parametersUpdated() to properly set the plot.
00124     // Drawing is held before these operations, and then released afterwards.
00125     // Returns true if all operations succeeded; false if at least one failed.
00126     virtual bool initializePlot(PlotMSPages& pages);
00127     
00128     // Gets the plot's data source.
00129     // <group>
00130     virtual PlotMSCacheBase& cache() { return *itsCache_; };
00131     virtual const PlotMSCacheBase& cache() const { return *itsCache_; };
00132     virtual Int iter() { return 0; };
00133     // </group>
00134     
00135     // Gets the plot's parent.
00136     virtual PlotMSApp* parent() { return itsParent_; };
00137     
00138     // Steps the iteration
00139     virtual bool firstIter() { return False;};
00140     virtual bool prevIter() { return False;};
00141     virtual bool nextIter() { return False;};
00142     virtual bool lastIter() { return False;};
00143 
00144 
00145     // Implements PlotMSParametersWatcher::parametersHaveChanged().  Updates
00146     // the data parameters and then calls parametersHaveChanged_().
00147     virtual void parametersHaveChanged(const PlotMSWatchedParameters& params,
00148             int updateFlag);
00149     
00150     // Calls the dataChanged() method on the MaskedScatterPlots.  This WILL
00151     // cause a redraw of the affected canvases.
00152     virtual void plotDataChanged();
00153     
00154     // Exports canvases associated with this plot to the given format.  Exports
00155     // to multiple files if the plot has more than one canvas.
00156     virtual bool exportToFormat(const PlotExportFormat& format);
00157     
00158     // This method should be called when the given canvas (which was owned by
00159     // this plot) was disowned.
00160     virtual void canvasWasDisowned(PlotCanvasPtr canvas);
00161     
00162 protected:
00163     // ABSTRACT METHODS //
00164     
00165     // Generates and assigns canvases that this plot will be using, with the
00166     // given PlotMSPages object.  This is called when the plot is first
00167     // created, and can be called by the plot itself if its canvas layout
00168     // has changed (in which case this method should check for the canvases
00169     // that have already been assigned to it in the page).
00170     virtual bool assignCanvases(PlotMSPages& pages) = 0;
00171     
00172     // Initializes any internal plot objects, but does NOT set parameters or
00173     // attach to canvases.  Will only be called ONCE, before assignCanvases and
00174     // parametersUpdated, as long as the public initializePlot method is not
00175     // overridden.  Returns true for success, false for failure.
00176     virtual bool initializePlot() = 0;
00177     
00178     // Updates plot members for parameters specific to the child plot type.
00179     // Returns true if the drawing should be released right away; if false is
00180     // returned, the child class is expect to release drawing when finished.
00181     virtual bool parametersHaveChanged_(const PlotMSWatchedParameters& params,
00182             int updateFlag, bool releaseWhenDone) = 0;
00183     
00184     // Helper method for selectedRegions() and visibleSelectedRegions() that
00185     // returns the selected regions for plots in the given canvases.
00186     virtual PlotMSRegions selectedRegions(
00187             const vector<PlotCanvasPtr>& canvases) const = 0;
00188     
00189     
00190     // IMPLEMENTED METHODS //
00191     
00192     // Note: this method MUST be called in the constructor of any children
00193     // classes.
00194     virtual void constructorSetup();
00195     
00196     // Force data update by clearing the cache
00197     virtual bool updateData() { itsCache_->clear(); return True; };   
00198     
00199     // Returns true if drawing is currently being held on all plot canvases,
00200     // false otherwise.
00201     virtual bool allDrawingHeld();
00202     
00203     // Holds drawing on all plot canvases.
00204     virtual void holdDrawing();
00205     
00206     // Releases drawing on all plot canvases, which will also cause a redraw.
00207     virtual void releaseDrawing();
00208     
00209 
00210     // MEMBERS //
00211     
00212     // PlotMS parent.
00213     PlotMSApp* itsParent_;
00214     
00215     // Plot factory for generating plot objects as needed.
00216     PlotFactoryPtr itsFactory_;
00217     
00218     // Parameters.
00219     PlotMSPlotParameters itsParams_;
00220     
00221     // Cache.
00222     PlotMSCacheBase* itsCache_;
00223     
00224 private:
00225     // Disable copy constructor and operator for now.
00226     // <group>
00227     PlotMSPlot(const PlotMSPlot& copy);
00228     PlotMSPlot& operator=(const PlotMSPlot& copy);
00229     // </group>
00230 };
00231 
00232 }
00233 
00234 #endif /* PLOTMSPLOT_H_ */