casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotMSDBusApp.h
Go to the documentation of this file.
00001 //# PlotMSDBusApp.h: Controller for plotms using DBus.
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 PLOTMSDBUSAPP_H_
00028 #define PLOTMSDBUSAPP_H_
00029 
00030 #include <casaqt/QtUtilities/QtDBusXmlApp.qo.h>
00031 #include <plotms/PlotMS/PlotMSParameters.h>
00032 #include <plotms/Plots/PlotMSPlotManager.h>
00033 
00034 #include <casa/namespace.h>
00035 
00036 namespace casa {
00037 
00038 //# Forward declarations.
00039 class PlotMSApp;
00040 
00041 
00042 // Subclass of QtDBusXmlApp to control plotms using DBus communication.
00043 class PlotMSDBusApp: public QtDBusXmlApp, public PlotMSParametersWatcher,
00044                      public PlotMSPlotManagerWatcher {
00045     
00046     //# Friend class declarations.
00047     friend class PlotMSDBusAppWatcher;
00048     
00049 public:
00050 
00051     static const QString &name( );
00052     QString dbusName( ) const { return QString(name( )); }
00053 
00054     // Static //
00055     
00056     // Constants for the casaplotms standalone executable.
00057     // <group>
00058     static const String APP_NAME;
00059     static const String APP_CASAPY_SWITCH;
00060     static const String APP_LOGFILENAME_SWITCH;
00061     static const String APP_LOGFILTER_SWITCH;
00062     // </group>
00063     
00064     
00065     // PARAMETERS //
00066     
00067     // Parameter names.
00068     // <group>
00069     static const String PARAM_AVERAGING; // Record (see PlotMSAveraging)
00070     static const String PARAM_AXIS_X; // String
00071     static const String PARAM_AXIS_Y; // String
00072     static const String PARAM_CLEARSELECTIONS; // bool
00073     static const String PARAM_DATACOLUMN_X; // String
00074     static const String PARAM_DATACOLUMN_Y; // String
00075     static const String PARAM_FILENAME; // String
00076     static const String PARAM_FLAGGING; // Record
00077     static const String PARAM_HEIGHT; // int or uInt
00078     static const String PARAM_ITERATE; // Record (see PlotMSIterParam)
00079     static const String PARAM_PLOTINDEX; // int or uInt
00080     static const String PARAM_PRIORITY; // String
00081     static const String PARAM_SELECTION; // Record (see PlotMSSelection)
00082     static const String PARAM_TRANSFORMATIONS; // Record (see PlotMSTransformations)
00083     static const String PARAM_UPDATEIMMEDIATELY; // bool
00084     static const String PARAM_WIDTH; // int or uInt
00085     static const String PARAM_EXPORT_FILENAME; // String
00086     static const String PARAM_EXPORT_FORMAT; //String
00087     static const String PARAM_EXPORT_HIGHRES; // bool
00088     static const String PARAM_EXPORT_INTERACTIVE; // bool
00089     static const String PARAM_EXPORT_ASYNC;  // bool
00090     static const String PARAM_COLORIZE;      // bool
00091     static const String PARAM_COLORAXIS;     // string
00092     static const String PARAM_CANVASTITLE;    // string
00093     static const String PARAM_XAXISLABEL;    // string
00094     static const String PARAM_YAXISLABEL;    // string
00095     static const String PARAM_SHOWMAJORGRID;  // bool
00096     static const String PARAM_SHOWMINORGRID;  // bool
00097     static const String PARAM_MAJORCOLOR;    // string
00098     static const String PARAM_MINORCOLOR;    // string
00099     static const String PARAM_MAJORSTYLE;    // string 
00100     static const String PARAM_MINORSTYLE;    // string
00101     static const String PARAM_MAJORWIDTH;    // int 
00102     static const String PARAM_MINORWIDTH;    // int 
00103     static const String PARAM_XAUTORANGE;    // bool
00104     static const String PARAM_XMIN;          // double
00105     static const String PARAM_XMAX;          // double
00106     static const String PARAM_YAUTORANGE;    // bool
00107     static const String PARAM_YMIN;          // double
00108     static const String PARAM_YMAX;          // double
00109     static const String PARAM_SYMBOL;        // bool
00110     static const String PARAM_SYMBOLSHAPE;   // string
00111     static const String PARAM_SYMBOLSIZE;    // int
00112     static const String PARAM_SYMBOLCOLOR;   // string
00113     static const String PARAM_SYMBOLFILL;    // string
00114     static const String PARAM_SYMBOLOUTLINE; // bool
00115     static const String PARAM_FLAGGEDSYMBOL;        // bool
00116     static const String PARAM_FLAGGEDSYMBOLSHAPE;   // string
00117     static const String PARAM_FLAGGEDSYMBOLSIZE;    // int
00118     static const String PARAM_FLAGGEDSYMBOLCOLOR;   // string
00119     static const String PARAM_FLAGGEDSYMBOLFILL;    // string
00120     static const String PARAM_FLAGGEDSYMBOLOUTLINE; // bool
00121     
00122     
00123     // </group>
00124 
00125     // DBus method name for getting the log parameters, including: the sink
00126     // filename (PARAM_FILENAME) and the filter priority (PARAM_PRIORITY).
00127     // PARAMETERS: none.
00128     // RETURNS: value (Record), unless invalid or run asynchronously.
00129     static const String METHOD_GETLOGPARAMS;
00130     
00131     // DBus method name for setting the log parameters, using a Record with
00132     // zero or more of the parameters set (see METHOD_GETLOGPARAMS).
00133     // PARAMETERS: value (Record).
00134     // RETURNS: none.
00135     static const String METHOD_SETLOGPARAMS;
00136     
00137     // DBus method name for getting the plotms parameters, including: the
00138     // "clear selections on axes change" flag (PARAM_CLEARSELECTIONS), and the
00139     // cached image width (PARAM_WIDTH) and height (PARAM_HEIGHT).
00140     // PARAMETERS: none.
00141     // RETURNS: value (Record), unless invalid or run asynchronously.
00142     static const String METHOD_GETPLOTMSPARAMS;
00143     
00144     // DBus method name for setting the plotms parameters, using a Record with
00145     // zero or more of the parameters set (see METHOD_GETPLOTMSPARAMS).
00146     // PARAMETERS: value (Record).
00147     // RETURNS: none.
00148     static const String METHOD_SETPLOTMSPARAMS;
00149     
00150     // DBus method name for setting the cached image size to the current screen
00151     // resolution.
00152     // PARAMETERS: none.
00153     // RETURNS: none.
00154     static const String METHOD_SETCACHEDIMAGESIZETOSCREENRES;
00155     
00156     // DBus method name for getting the plot parameters at the given index
00157     // (PARAM_PLOTINDEX), including: the MS filename (PARAM_FILENAME), the x
00158     // axis (PARAM_AXIS_X) and data column (PARAM_DATACOLUMN_X), the y axis
00159     // (PARAM_AXIS_Y) and data column (PARAM_DATACOLUMN_Y), averaging
00160     // (PARAM_AVERAGING), selection (PARAM_SELECTION), and trasformations
00161     // (PARAM_TRANSFORMATIONS)
00162     // PARAMETERS: plot index.
00163     // RETURNS: value (Record), unless invalid or run asynchronously.
00164     static const String METHOD_GETPLOTPARAMS;
00165     
00166     // DBus method name for setting the plot parameters at the given index
00167     // (PARAM_PLOTINDEX), using a Record with zero or more of the parameters
00168     // set (see METHOD_GETPLOTPARAMS).
00169     // PARAMETERS: value (Record).
00170     // RETURNS: none.
00171     static const String METHOD_SETPLOTPARAMS;
00172     
00173     // DBus method name for getting the flag extension parameters
00174     // (PARAM_FLAGGING).
00175     // PARAMETERS: none.
00176     // RETURNS: value (Record), unless invalid or run asynchronously.
00177     static const String METHOD_GETFLAGGING;
00178     
00179     // DBus method name for setting the flag extension parameters.
00180     // PARAMETERS: flagging value.
00181     // RETURNS: none.
00182     static const String METHOD_SETFLAGGING;
00183     
00184     // DBus method names for showing/hiding the window.  Does NOT quit the
00185     // entire application.
00186     // PARAMETERS: none.
00187     // RETURNS: none.
00188     // <group>
00189     static const String METHOD_SHOW;
00190     static const String METHOD_HIDE;
00191     // </group>
00192     
00193     // DBus method name for updating the running PlotMS with any attributes
00194     // that were set with updateImmediately = false.
00195     // PARAMETERS: none.
00196     // RETURNS: none.
00197     static const String METHOD_UPDATE;
00198     
00199     // DBus method name for quitting the entire application.
00200     // PARAMETERS: none.
00201     // RETURNS: none.
00202     static const String METHOD_QUIT;
00203     
00204     //DBus method name for exporting plot file.
00205 
00206     static const String METHOD_SAVE;
00207 
00208     //DBus method name for determining if a plot is being drawn
00209     static const String METHOD_ISDRAWING;
00210     
00211     //is the top widget still shown
00212     static const String METHOD_ISCLOSED;
00213 
00214     // DBus method name for locating points in a specified region
00215     // PARAMETERS: upper left and lower right bounding box coordinates
00216     // RETURNS: meta data of located points (Record)
00217     static const String METHOD_LOCATEINFO;
00218 
00219     // Returns the name that the plotms in the process with the given ID is (or
00220     // would be) registered with in the CASA DBus server.
00221     static String dbusName(pid_t pid);
00222     
00223     // Non-Static //
00224     
00225     // Constructor which takes PlotMS parent object.
00226     PlotMSDBusApp(PlotMSApp& plotms);
00227     
00228     // Destructor.
00229     ~PlotMSDBusApp();
00230     
00231     // Connects to the DBus server using the dbusName() method with the current
00232     // process ID.  Returns whether the connection succeeded or not.
00233     bool connectToDBus( const QString &dbus_name="" );
00234     
00235     // Implements PlotMSParametersWatcher::parametersHaveChanged().
00236     void parametersHaveChanged(
00237         const PlotMSWatchedParameters& params, int updateFlag
00238     );
00239     
00240     // Implements PlotMSPlotManagerWatcher::plotsChanged().
00241     void plotsChanged(const PlotMSPlotManager& manager);
00242     
00243 protected:
00244     // Implements QtDBusXmlApp::dbusRunXmlMethod().
00245     void dbusRunXmlMethod(
00246         const String& methodName, const Record& parameters,
00247         Record& retValue, const String& callerName, bool isAsync
00248     );
00249     
00250     // Overrides QtDBusXmlApp::dbusXmlReceived() to print the message to the log
00251     // as needed.
00252     void dbusXmlReceived(const QtDBusXML& xml);
00253     
00254 private:
00255     // Parent PlotMS.
00256     PlotMSApp& itsPlotms_;
00257     
00258     // Set PlotMS parameters that haven't yet been transferred to the current
00259     // PlotMS.
00260     PlotMSParameters itsParams_;
00261     
00262     // Set PlotMSSinglePlot parameters that haven't yet been transfered to the
00263     // current PlotMS.
00264     vector<PlotMSPlotParameters> itsPlotParams_;
00265     
00266     // Flag for whether to call update() during show() or not.  This will be
00267     // true if the user updates something while the GUI is hidden.
00268     bool itsUpdateFlag_;
00269 
00270     // Helper method for posting log messages.
00271     void log(const String& message);
00272     
00273     // Adjusts the given plot index to be an acceptable, and returns whether
00274     // the parameters were resized or not.
00275     bool plotParameters(int& plotIndex) const;
00276     
00277     // Helper for updating.
00278     void update();
00279 
00280     // helper for saving
00281     bool _savePlot(const Record& parameters);
00282 
00283     // helper for locate
00284     Record _locateInfo(const Record& parameters);
00285 
00286 };
00287 
00288 }
00289 
00290 #endif /* PLOTMSDBUSAPP_H_ */