casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtDBusViewerAdaptor.qo.h
Go to the documentation of this file.
00001 //# QtDBusViewerAdaptor.qo.h: provides viewer services via 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 
00028 #ifndef QTDBUSVIEWERADAPTOR_QO_H_
00029 #define QTDBUSVIEWERADAPTOR_QO_H_
00030 
00031 #include <map>
00032 #include <limits>
00033 #include <casaqt/QtUtilities/QtDBusXmlApp.qo.h>
00034 #include <casa/namespace.h>
00035 #include <QVariantMap>
00036 #include <display/QtViewer/QtViewer.qo.h>
00037 
00038 namespace casa {
00039 
00040     class QtDisplayData;
00041     class QtDisplayPanel;
00042     class QtDisplayPanelGui;
00043 
00044     class QtDBusViewerAdaptor : public QDBusAbstractAdaptor, public QtDBusApp {
00045         Q_OBJECT
00046         Q_CLASSINFO("D-Bus Interface", "edu.nrao.casa.viewer")
00047 
00048     public:    
00049 
00050         QString dbusName( ) const { return QString(QtViewer::name( )); }
00051         bool connectToDBus( const QString &dbus_name="" )
00052                         { return QtDBusApp::connectToDBus( parent(), dbus_name ); }
00053 
00054         // Constructor which takes the application.
00055         QtDBusViewerAdaptor( QtViewer * );
00056     
00057         // Destructor.
00058         ~QtDBusViewerAdaptor();
00059 
00060     public slots:
00061 
00062         QDBusVariant start_interact( const QDBusVariant &input, int panel );
00063         QDBusVariant datarange( const QList<double> &range, int data=0 );
00064         QDBusVariant contourlevels( const QList<double> &levels,
00065                                     double baselevel=2147483648.0,
00066                                     double unitlevel=2147483648.0, int panel_or_data=0 );
00067         QDBusVariant axes( const QString &x = "", const QString &y = "", const QString &z = "", int panel=0 );
00068         QDBusVariant colormap( const QString &map, int panel_or_data=0 );
00069         QDBusVariant colorwedge( bool show=true, int panel_or_data=0 );
00070 
00071         QDBusVariant load( const QString &path, const QString &displaytype = "raster", int panel=0, double scaling=0 );
00072         QDBusVariant reload( int panel_or_data );
00073         QDBusVariant unload( int data );
00074 
00075         QDBusVariant restore( const QString &path, int panel=0 );
00076 
00077         QDBusVariant panel( const QString &type="viewer", bool hidden=false  );
00078         QDBusVariant hide( int panel=0 );
00079         QDBusVariant show( int panel=0 );
00080         QDBusVariant close( int panel=0 );
00081         QDBusVariant popup( const QString &what, int panel=0 );
00082 
00083         QDBusVariant cwd( const QString &new_path = "" );
00084 
00085         QDBusVariant freeze( int panel=0 );
00086         QDBusVariant unfreeze( int panel=0 );
00087 
00088         QDBusVariant channel( int num=-1, int panel=0 );
00089         QDBusVariant zoom( int level, int panel=0 );
00090         QDBusVariant zoom( const QList<double> &blc, const QList<double> &trc, const QString &coordinates="pixel", int panel=0 );
00091 
00092         // like "close()", but leaves the closing up to the user if the window is not hidden
00093         QDBusVariant release( int panel );
00094         //To change certain things so the panel 
00095         QDBusVariant setoptions( const QDBusVariant &input, int panel);
00096         // device:      file name or printer name
00097         // devicetype:  "file", "printer", or "ghostscript"
00098         // format:      "jpg", "pdf", "eps", "ps", "png", "xbm", "xpm", "ppm"
00099         //              [only used with devicetype == "file"] [extension on device, e.g. "outfile.pdf" overrides "format"]
00100         // scale:       size scale factor for raster output (e.g. jpg etc.)
00101         // dpi:         resolution of PS or EPS images
00102         // orientation: "portrait", "landscape"
00103         // media:       "letter" or "a4"
00104         bool output( const QString &device, const QString &devicetype = "file", int panel = 0,
00105                      double scale = 1.0, int dpi = 300, const QString &format = "jpg",
00106                      const QString &orientation = "portrait", const QString &media = "letter" );
00107 
00108 
00109         QDBusVariant fileinfo( const QString &path );
00110         QStringList keyinfo( int );
00111 
00112         bool done( );
00113     
00114     signals:
00115         void interact( QDBusVariant );
00116         void exiting( QDBusVariant );
00117 
00118     protected slots:
00119 
00120         void handle_interact( QVariant );
00121         void handle_destroyed_panel(QObject*);
00122 
00123     private:
00124 
00125         inline QDBusVariant error( const QString &message ) {
00126             QMap<QString,QVariant> err;
00127             err["*error*"] = message;
00128             return QDBusVariant(QVariant(err));
00129         }
00130 
00131         class data_desc {
00132         public:
00133             data_desc( int idx, const QString &pathx, const QString &typex,
00134                        QtDisplayData *ddx, QtDisplayPanelGui *dpx ) :
00135                                 id_(idx), path_(pathx), type_(typex), dd_(ddx), dp_(dpx) { }
00136 
00137             data_desc( int idx ) : id_(idx), dd_(0) { }
00138             data_desc( ) : id_(0), dd_(0) { }
00139 
00140             int &id( ) { return id_; }
00141             int id( ) const { return id_; }
00142             QString &path( ) { return path_; }
00143             const QString &path( ) const { return path_; }
00144             QString &type( ) { return type_; }
00145             const QString &type( ) const { return type_; }
00146             QtDisplayData *&data( ) { return dd_; }
00147             const QtDisplayData *data( ) const { return dd_; }
00148             QtDisplayPanelGui *&panel( ) { return dp_; }
00149             const QtDisplayPanelGui *panel( ) const { return dp_; }
00150 
00151         private:
00152             int id_;
00153             QString path_;
00154             QString type_;
00155             QtDisplayData *dd_;
00156             QtDisplayPanelGui *dp_;
00157 
00158             // QtDisplayData does not have a copy constructor...
00159             // wonder if we'll need to copy our descriptor...
00160             data_desc( const data_desc &other);
00161             data_desc &operator=( const data_desc &);
00162         };
00163 
00164 
00165         class panel_desc {
00166         public:
00167 
00168             panel_desc(QtDisplayPanelGui*p) : panel_(p) { }
00169 
00170             std::list<int> &data( ) { return data_; }
00171             const std::list<int> &data( ) const { return data_; }
00172             QtDisplayPanelGui *&panel( ) { return panel_; }
00173             const QtDisplayPanelGui *panel( ) const { return panel_; }
00174 
00175         private:
00176             std::list<int> data_;
00177             QtDisplayPanelGui *panel_;
00178         };
00179 
00180 
00181         QtViewer *viewer_;
00182 
00183         bool printps( QtDisplayPanel *panel, const QString &type, const QString &file, int dpi,
00184                       const QString &orientation, const QString &media );
00185         bool printraster( QtDisplayPanel *panel, const QString &type, const QString &file, double scale );
00186         void  adjusteps( const char *from, const char *to, const QSize &wcmax, const QRect &viewport );
00187 
00188         typedef std::map<int,panel_desc*> panelmap;
00189         typedef std::map<int,data_desc*> datamap;
00190         datamap managed_datas;
00191         panelmap managed_panels;
00192 
00193         int get_id( QtDisplayPanelGui *, QtDisplayData *, const QString &path, const QString &type );
00194         int get_id( QtDisplayPanelGui * );
00195         QtDisplayPanelGui *findpanel( int key, bool create=true );
00196         QtDisplayData *finddata( int key );
00197 
00198     protected:
00199         QtDisplayPanelGui *create_panel( );
00200         void load_data( QtDisplayPanelGui *panel, int index );
00201         void unload_data( QtDisplayPanelGui *panel, int index, bool erase=true );
00202         QtDisplayPanelGui *erase_panel( int panel );
00203         void erase_data( int );
00204 
00205     };
00206 
00207 }
00208 
00209 #endif