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/PlotMS/PlotMS.h>
00034 #include <plotms/Plots/PlotMSPlotParameters.h>
00035 #include <plotms/Plots/PlotMSPlot.h>
00036 #include <plotms/Plots/PlotMSPage.h>
00037 #include <plotms/Data/PlotMSIndexer.h>
00038 
00039 namespace casa {
00040 
00041 //# Forward declarations
00042 class PlotMSPages;
00043 class PMS_PP_Cache;
00044 class PMS_PP_Canvas;
00045 class PMS_PP_Axes;
00046 class PMS_PP_Iteration;
00047 class PMS_PP_Display;
00048 
00049 // Class for a single "plot" concept.  Generally speaking this one
00050 // plot handles one data source across potentially many scatter plots and
00051 // canvases, separated by whatever criteria the subclasses decide on.  The 
00052 // class PlotMSPlot handles interfacing with the rest of PlotMS and MS file and
00053 // selection, and provides some useful members and methods for subclasses.
00054 class PlotMSPlot : public PlotMSParametersWatcher {
00055 public:
00056     // Static //    
00057     
00058     // Returns a new instance of PlotMSPlotParameters suitable for use with
00059     // this class, using the given PlotMS parent.
00060     static PlotMSPlotParameters makeParameters(PlotMSApp* plotms);
00061     
00062     // Updates the given PlotMSPlotParameters to be suitable for use with this
00063     // class, using the given PlotMS parent.
00064     static void makeParameters(PlotMSPlotParameters& params, PlotMSApp* plotms);
00065     
00066     void customizeAutoSymbol( const PlotSymbolPtr& baseSymbol, uInt dataSize  );
00067     // Non-Static //
00068     
00069     // Constructor which takes the parent PlotMS object.  Starts out with
00070     // default data parameters.
00071     PlotMSPlot(PlotMSApp* parent);
00072     
00073     // Destructor.
00074     ~PlotMSPlot();
00075 
00076     void resize(PlotMSPages&, uInt rows, uInt cols);
00077 
00078     // Simple class to hold parameter to resume updating after a threaded
00079     // cache loading
00080     class TCLParams {
00081     public:
00082         // Parameters
00083         // <group>
00084         bool releaseWhenDone;
00085         bool updateCanvas;
00086         bool updateDisplay;
00087         bool endCacheLog;
00088         bool updateIteration;
00089 
00090         // </group>
00091 
00092         // Constructor
00093         TCLParams()
00094             :
00095             releaseWhenDone(false),
00096             updateCanvas(false),
00097             updateDisplay(false),
00098             endCacheLog(false)
00099 
00100         {}
00101     };
00102     
00103     // Returns a human-readable name for this plot.  Does not have to be
00104     // unique.
00105     String name() const;
00106 
00107     // Returns specialization Id for this plot
00108     String spectype() const { return "Unknown";};
00109     
00110     // Returns the plots assigned to this plot.
00111     vector<MaskedScatterPlotPtr> plots() const;
00112     
00113     // Returns the canvases that have been assigned to this plot.
00114     vector<PlotCanvasPtr> canvases() const;
00115     
00116     // Attaches/Detaches internal plot objects to their assigned canvases.
00117     // <group>
00118     void attachToCanvases();
00119     void detachFromCanvases();
00120     Int iter() { return iter_; }
00121     // </group>
00122     
00123     //The cache load did not succeed so clear the plot and the cache.
00124     void dataMissing();
00125     
00126     //This method was written because in scripting mode, there was a segfault when
00127     //the grid size was changed (for example 2 x 3 to 1x1).  It was in a draw thread
00128     //that had stale data it was touching after its associated canvas was deleted.
00129     //The purpose of the method is to wait for the draw threads to finish and then
00130     //keep them from redrawing while the deletion is in progress.
00131     void waitForDrawing( bool holdDrawing );
00132 
00133     // Returns a reference to the plot's parameters.
00134     // <group>
00135     const PlotMSPlotParameters& parameters() const;
00136     PlotMSPlotParameters& parameters();
00137     // </group>
00138     
00139     // Returns the visible canvases (accessible via
00140     // PlotMSPlotter::currentCanvases()) associated with this plot.
00141     vector<PlotCanvasPtr> visibleCanvases() const;
00142    
00143     // Returns all selected regions on all canvases associated with this plot.
00144     virtual PlotMSRegions selectedRegions() const;
00145   
00146     // PlotMSPlotter::currentCanvases()) associated with this plot.
00147     PlotMSRegions visibleSelectedRegions() const;
00148 
00149     // Initializes the plot with the given canvases.  Initializes any internal
00150     // plot objects via the protected initializePlot() method, then assigns
00151     // the plot objects to the canvases via the protected assignCanvases()
00152     // method, then calls parametersUpdated() to properly set the plot.
00153     // Drawing is held before these operations, and then released afterwards.
00154     // Returns true if all operations succeeded; false if at least one failed.
00155     bool initializePlot(PlotMSPages& pages);
00156     
00157     // Gets the plot's data source.
00158     // <group>
00159     PlotMSCacheBase& cache() { return *itsCache_; };
00160     const PlotMSCacheBase& cache() const { return *itsCache_; };
00161     // </group>
00162     
00163     // Gets the plot's parent.
00164     PlotMSApp* parent() { return itsParent_; };
00165     
00166     // Steps the iteration
00167     bool firstIter();
00168     bool prevIter();
00169     bool nextIter(); 
00170     bool lastIter();
00171     bool setIter( int index );
00172     bool resetIter();
00173     void recalculateIteration();
00174     Int nIter();
00175 
00176     // Implements PlotMSParametersWatcher::parametersHaveChanged().  Updates
00177     // the data parameters and then calls parametersHaveChanged_().
00178     void parametersHaveChanged(const PlotMSWatchedParameters& params,
00179             int updateFlag);
00180     
00181     // Calls the dataChanged() method on the MaskedScatterPlots.  This WILL
00182     // cause a redraw of the affected canvases.
00183     void plotDataChanged();
00184     
00185     //Returns true if the plot is an iteration plot.
00186     bool isIteration() const;
00187 
00188     // Exports canvases associated with this plot to the given format.  Exports
00189     // to multiple files if the plot has more than one canvas.
00190     bool exportToFormat(const PlotExportFormat& format);
00191     void exportToFormatCancel();
00192     
00193     void cacheLoaded_(bool wasCanceled);
00194 
00195     // This method should be called when the given canvas (which was owned by
00196     // this plot) was disowned.
00197     void canvasWasDisowned(PlotCanvasPtr canvas);
00198     vector<PMS::Axis> getCachedAxes();
00199     vector<PMS::DataColumn> getCachedData();
00200 
00201     Record locateInfo(int plotIterIndex, const Vector<PlotRegion>& regions,
00202                 bool showUnflagged, bool showFlagged, bool selectAll ) const ;
00203 
00204     PlotLogMessage* locateRange( int plotIterIndex, const Vector<PlotRegion> & regions,
00205                 bool showUnflagged, bool showFlagged);
00206 
00207     PlotLogMessage* flagRange( int canvasIndex, casa::PlotMSFlagging& flagging,
00208                 const Vector<PlotRegion>& regions, bool showFlagged);
00209 
00210     // Generates and assigns canvases that this plot will be using, with the
00211     // given PlotMSPages object.  This is called when the plot is first
00212     // created, and can be called by the plot itself if its canvas layout
00213     // has changed (in which case this method should check for the canvases
00214     // that have already been assigned to it in the page).
00215     bool assignCanvases(PlotMSPages& pages);
00216     void updateLocation();
00217 
00218     //Clear the title and axes from all this plots canvases.
00219     void clearCanvases();
00220 
00221     //Whether a thread is currently updating the cache.
00222     bool isCacheUpdating() const;
00223     void setCacheUpdating( bool updating );
00224 
00225     void updatePlots();
00226     bool updateIndexing();
00227 
00228     void logPoints();
00229     void logIter(Int iter, Int nIter);
00230 
00231     //This was added so that in 'mixed mode', cacheloaded will trigger
00232     //a redraw of the plot.
00233     void setRelease( bool b );
00234 
00235     static void cacheLoaded(void *obj, bool wasCanceled){
00236         PlotMSPlot *cobj = static_cast<PlotMSPlot*>(obj);
00237         if(cobj != NULL){
00238                 cobj->setCacheUpdating( false );
00239             if ( ! cobj->itsParent_->guiShown() ){
00240                 cobj->cacheLoaded_(wasCanceled);
00241             }
00242         }
00243     }
00244 
00245 protected:
00246     
00247     
00248     // Initializes any internal plot objects, but does NOT set parameters or
00249     // attach to canvases.  Will only be called ONCE, before assignCanvases and
00250     // parametersUpdated, as long as the public initializePlot method is not
00251     // overridden.  Returns true for success, false for failure.
00252     bool initializePlot();
00253     
00254     // Updates plot members for parameters specific to the child plot type.
00255     // Returns true if the drawing should be released right away; if false is
00256     // returned, the child class is expect to release drawing when finished.
00257     bool parametersHaveChanged_(const PlotMSWatchedParameters& params,
00258                                 int updateFlag, bool releaseWhenDone );
00259     
00260     // Helper method for selectedRegions() and visibleSelectedRegions() that
00261     // returns the selected regions for plots in the given canvases.
00262     PlotMSRegions selectedRegions(
00263             const vector<PlotCanvasPtr>& canvases) const;
00264     
00265     void constructorSetup();
00266     void updatePages();
00267     bool updateCache( );
00268     bool updateCanvas();
00269     bool updateDisplay();
00270     void setColors();
00271     
00272     // Force data update by clearing the cache
00273     bool updateData();
00274     
00275     // Returns true if drawing is currently being held on all plot canvases,
00276     // false otherwise.
00277     bool allDrawingHeld();
00278     
00279     // Holds drawing on all plot canvases.
00280     void holdDrawing();
00281     
00282     // Releases drawing on all plot canvases, which will also cause a redraw.
00283     void releaseDrawing();
00284     
00285     int getPageIterationCount( const PlotMSPage& page );
00286 
00287     void waitOnCanvases();
00288 
00289     // MEMBERS //
00290     
00291     // PlotMS parent.
00292     PlotMSApp* itsParent_;
00293     
00294     // Plot factory for generating plot objects as needed.
00295     PlotFactoryPtr itsFactory_;
00296     
00297     // Parameters.
00298     PlotMSPlotParameters itsParams_;
00299     
00300     // Cache.
00301     PlotMSCacheBase* itsCache_;
00302     
00303     //Used to determine if a thread is running to update the cache.
00304     volatile bool cacheUpdating;
00305 
00306 private:
00307     void waitOnCanvas( const PlotCanvasPtr& canvas );
00308 
00309     // Disable copy constructor and operator for now.
00310     // <group>
00311     PlotMSPlot(const PlotMSPlot& copy);
00312     PlotMSPlot& operator=(const PlotMSPlot& copy);
00313     // </group>
00314 
00315     //Adjust the amount of plot data that this plot is holding.
00316     void resizePlots( int rows, int cols );
00317 
00318     // Clear data when deleting cache to prevent seg fault in other thread
00319     void clearPlotData();
00320 
00321     //Return the dimensions of the plot data that this plot should hold.
00322     void getPlotSize( Int& rows, Int& cols );
00323 
00324     //Returns the iteration for the canvas located at row, r, and column, c.
00325     int getIterationIndex( int r, int c, const PlotMSPage& page );
00326 
00327     //Post a plot message to the logger.
00328     void logMessage( const QString& msg ) const;
00329 
00330     void clearCanvasProperties( int row, int col);
00331     void setCanvasProperties (int row, int col, PMS_PP_Cache*,
00332                 PMS_PP_Axes* axes, bool set, PMS_PP_Canvas *canv,
00333                 uInt rows, uInt cols, PMS_PP_Iteration *iter,
00334                 uInt iteration, PlotMSAveraging averaging );
00335     // To modify axis label if needed:
00336     bool axisIsAveraged(PMS::Axis axis, PlotMSAveraging averaging);
00337     String addFreqFrame(String freqLabel);
00338     PMS::Axis getCalAxis(String calType, PMS::Axis axis);
00339     PMS::Axis getDefaultXAxis(String calType);
00340 
00341     //Note:  First index for a plot is the dataCount,
00342     //second index is the number of iteration.
00343     vector<vector<MaskedScatterPlotPtr> > itsPlots_;
00344 
00345     //Note:  First index for a canvas is the number of rows,
00346     //second index is the column withen a grid.
00347     vector<vector<PlotCanvasPtr> > itsCanvases_;
00348 
00349     vector<vector</*QPScatterPlot**/ColoredPlotPtr> > itsColoredPlots_;
00350     TCLParams itsTCLParams_;
00351     int gridRow;
00352     int gridCol;
00353 
00354     Int iter_;
00355     Int iterStep_;
00356 
00357     static const uInt PIXEL_THRESHOLD;
00358     static const uInt MEDIUM_THRESHOLD;
00359     static const uInt LARGE_THRESHOLD;
00360 };
00361 
00362 }
00363 
00364 #endif /* PLOTMSPLOT_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1