casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotMSCacheThread.qo.h
Go to the documentation of this file.
00001 //# PlotMSCacheThread.qo.h: Subclass of PlotMSThread for cache loading.
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 PLOTMSCACHETHREAD_QO_H_
00028 #define PLOTMSCACHETHREAD_QO_H_
00029 
00030 #include <plotms/Actions/PlotMSThread.qo.h>
00031 #include <plotms/PlotMS/PlotMSSelection.h>
00032 #include <plotms/PlotMS/PlotMSAveraging.h>
00033 #include <plotms/PlotMS/PlotMSTransformations.h>
00034 #include <plotms/PlotMS/PlotMSConstants.h>
00035 
00036 #include <QThread>
00037 
00038 #include <vector>
00039 
00040 #include <casa/namespace.h>
00041 
00042 namespace casa {
00043 
00044 //# Forward Declarations
00045 class PlotMSCacheBase;
00046 class PlotMSPlot;
00047 
00048 // Subclass of PlotMSThread for loading axes in a PlotMSCache.
00049 class PlotMSCacheThread : public PlotMSThread {
00050     Q_OBJECT
00051     
00052     //# Friend class declarations.
00053     friend class PlotMSCacheBase;
00054     friend class MSCache;
00055     friend class CalCache;
00056     friend class PlotMSCacheThreadHelper;
00057     
00058 public:
00059     // LOADING constructor which takes the PlotMSPlot, the PlotMSData, the axes
00060     // and data columns, the averaging, a flag for whether to call setupPlot
00061     // after the loading, and optional post-thread method parameters.
00062     PlotMSCacheThread(PlotMSPlot* plot, PlotMSCacheBase* cache,
00063                       const vector<PMS::Axis>& axes, 
00064                       const vector<PMS::DataColumn>& data2,
00065                       const String& msname, 
00066                       const PlotMSSelection& selection, 
00067                       const PlotMSAveraging& averaging, 
00068                       const PlotMSTransformations& transformations, 
00069                       bool setupPlot = false,
00070                       PMSPTMethod postThreadMethod = NULL,
00071                       PMSPTObject postThreadObject = NULL);
00072     
00073     // RELEASING constructor which takes the PlotMSPlot, the axes, and optional
00074     // post-thread method parameters.
00075     PlotMSCacheThread(PlotMSPlot* plot, const vector<PMS::Axis>& axes,
00076             PMSPTMethod postThreadMethod = NULL,
00077             PMSPTObject postThreadObject = NULL);
00078     
00079     // Destructor.
00080     ~PlotMSCacheThread();
00081     
00082     
00083     // Implements PlotMSThread::startOperation().
00084     void startOperation();
00085     
00086 protected:
00087     // Implements PlotMSThread::wasCanceled().
00088     bool wasCanceled() const;
00089     
00090     // Allows the cache to set the progress.
00091     void setProgress(unsigned int progress) {
00092         setProgressAndStatus(progress, itsLastStatus_); }
00093     
00094     // Allows the cache to set the status.
00095     void setStatus(const String& status) {
00096         setProgressAndStatus(itsLastProgress_, status); }
00097     
00098     // Allows the cache to set the progress and the status.
00099     void setProgressAndStatus(unsigned int progress, const String& status);
00100     
00101 protected slots:
00102     // Implements PlotMSThread::background().  Currently is unimplemented.
00103     void background();
00104     
00105     // Implements PlotMSThread::pause().  Currently is unimplemented.
00106     void pause();
00107     
00108     // Implements PlotMSThread::resume().  Currently is unimplemented.
00109     void resume();
00110     
00111     // Implements PlotMSThread::cancel().
00112     void cancel();
00113     
00114 private:
00115     // Plot.
00116     PlotMSPlot* itsPlot_;
00117     
00118     // Data.
00119     PlotMSCacheBase* itsCache_;
00120     
00121     // Load (true) or release (false) axes.
00122     bool itsLoad_;
00123     
00124     // Axes.
00125     vector<PMS::Axis> itsAxes_;
00126     
00127     // Axes data columns.
00128     vector<PMS::DataColumn> itsAxesData_;
00129     
00130     // MS selection/averaging info
00131     String itsMSName_;
00132     PlotMSSelection itsSelection_;
00133     PlotMSAveraging itsAveraging_;
00134     PlotMSTransformations itsTransformations_;
00135     
00136     // Whether to set up the cache afterwards.
00137     bool itsSetupPlot_;
00138     
00139     // Last set progress.
00140     unsigned int itsLastProgress_;
00141     
00142     // Last set status.
00143     String itsLastStatus_;
00144     
00145     // Flag for whether thread was canceled or not.
00146     bool wasCanceled_;
00147     
00148     // Error message, if there was one (otherwise empty).
00149     String itsCacheError_;
00150     
00151 private slots:
00152     // Slot for when the QThread finishes.
00153     void threadFinished();
00154 };
00155 
00156 
00157 // Helper class for PlotMSCacheThread that actually does the work in a new
00158 // QThread.
00159 class PlotMSCacheThreadHelper : public QThread {
00160 public:
00161     // Constructor that takes parent.
00162     PlotMSCacheThreadHelper(PlotMSCacheThread& parent);
00163     
00164     // Destructor.
00165     ~PlotMSCacheThreadHelper();
00166 
00167 protected:
00168     // Implements QThread::run().
00169     void run();
00170     
00171 private:
00172     // Parent.
00173     PlotMSCacheThread& itsParent_;
00174 };
00175 
00176 }
00177 
00178 #endif /* PLOTMSCACHETHREAD_QO_H_ */