casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtViewerBase.qo.h
Go to the documentation of this file.
00001 //# QtViewerBase.qo.h: Qt implementation of main viewer supervisory object.
00002 //#                 -- Functional level.
00003 //# Copyright (C) 2005
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 
00029 #ifndef QTVIEWERBASE_H
00030 #define QTVIEWERBASE_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Containers/List.h>
00034 #include <display/QtViewer/QtMouseToolState.qo.h>
00035 #include <casa/Arrays/Vector.h>
00036 
00037 #include <graphics/X11/X_enter.h>
00038 #  include <QObject>
00039 #  include <QtXml/QDomDocument>
00040 #include <graphics/X11/X_exit.h>
00041 
00042 
00043 // <summary>
00044 // Qt implementation of main viewer supervisory object -- Functional level.
00045 // </summary>
00046 
00047 // <synopsis>
00048 // The viewer is structured with a functional layer and a gui layer.
00049 // In principle the former can operate without the latter.  This class
00050 // manages functional objects associated with the viewer, in particular
00051 // the list of user-created DDs.
00052 // </synopsis>
00053 
00054 namespace casa { //# NAMESPACE CASA - BEGIN
00055 
00056 class String;
00057 class QtDisplayData;
00058 class QtDisplayPanel;
00059 class QtDisplayPanelGui;
00060 
00061 class QtViewerBase : public QObject {
00062 
00063   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00064                 //# implement/.../*.h files; also, makefile must include
00065                 //# name of this file in 'mocs' section.
00066 
00067  public:
00068   
00069   QtViewerBase( bool is_server=false );
00070   ~QtViewerBase();
00071   
00072   bool server( ) const { return server_; }
00073   
00074     // Return the common QtMouseToolState that all mouse tool users
00075   // should share.
00076   virtual QtMouseToolState* mouseBtns() { return &msbtns_;  }
00077   virtual const QtMouseToolState* mouseBtns() const { return &msbtns_;  }
00078   
00079   // The list of QtDisplayPanels that are not closed.
00080   virtual List<QtDisplayPanelGui*> openDPs();
00081   
00082   // The number of open QtDisplayPanels.  (More efficient than the
00083   // equivalent openDPs().len(), if the number is all that's needed).
00084   virtual Int nOpenDPs();
00085   
00086   // Only to be used by QtDisplayPanels, to inform this class of
00087   // their creation.  (C++ should allow individual methods to be
00088   // 'friend'ed to outside classes...).
00089   virtual void dpCreated( QtDisplayPanelGui *newDP, QtDisplayPanel *panel );
00090  
00091   // function to aid typing files of interest to the viewer.
00092   // Moved from QtDataManager to be available for non-gui use.
00093   // Returns user interface Strings like "Measurement Set".
00094   static String fileType(const String pathname);
00095 
00096   // similar to above; returns internal DD datatype names like "ms"
00097   // (or else 'nonexistent', 'unknown').
00098   static String filetype(const String pathname);
00099 
00100   // Does the given file pathname hold a readable file with valid ID and
00101   // form as a viewer restore xml document?  (If so, contents are set
00102   // onto restoredoc).
00103   static Bool isRestoreFile(String filename, QDomDocument& restoredoc);
00104   
00105   // Does the given String have valid ID and form as viewer restore xml?
00106   // (If so, contents are set onto restoredoc).
00107   static Bool isRestoreString(String xmlState, QDomDocument& restoredoc);
00108   
00109   static const String cvRestoreID;              //# internal identifier,
00110   static const String cvRestoreFileExt;         //# default file extension,
00111                                                 //# for save-restore
00112   
00113   // Utility routines to convert between Vector<Float> and String.
00114   //<group>
00115   static String toString(Vector<Float> values);
00116   static Vector<Float> toVectorF(String values, Bool* ok=0);
00117   static String toString(Vector<Double> values);
00118   static Vector<Double> toVectorD(String values, Bool* ok=0);
00119   //</group>
00120  
00121  
00122   // Returns True iff datatype is a vaild viewer datatype and
00123   // displaytype is valid for the datatype.  If the former is true
00124   // but the latter isn't, displaytype is [re]set to the default
00125   // displaytype for the datatype.
00126   Bool dataDisplaysAs(String datatype, String& displaytype);
00127   
00128   // public (const) data.
00129   
00130   // viewer datatypess.
00131   static const Int IMAGE=1, MEASUREMENT_SET=2, SKY_CATALOG=3,
00132                    RESTORE=4, LEL=5,                           N_DT=5;
00133 
00134   // viewer displaytypes.
00135   static const Int RASTER=1, CONTOUR=2, VECTOR=3, MARKER=4,
00136                    SKY_CAT=5, OLDPANEL=6, NEWPANEL=7,          N_DS=7;
00137      
00138   // (for invalid datatype or displaytype).
00139   static const Int INVALID=0;
00140   
00141   
00142   bool exiting( ) { return qtviewer_app_exit; }
00143  
00144  public slots:
00145  
00146   // Hold/release of (canvas-draw) refresh of all QDPs.  (NB: does not
00147   // concern enabling of Qt Widgets).  Call to hold() must be matched to
00148   // later call of release(); they can be nested.  It is sometimes
00149   // efficient to wait until several changes are complete and then
00150   // redraw everything just once.
00151   //<group>
00152   virtual void hold();
00153   virtual void release();
00154   //</group>
00155   
00156   // Closes all open panels, which will exit the Qt loop.  Note that the
00157   // loop can be restarted (and is, in interactive clean, e.g.), with
00158   // existing widgets intact.  This does not in itself delete objects
00159   // or exit the process, although the driver program might do that.
00160   // Also, some of the panels may have WA_DeleteOnClose set, which
00161   // would cause their deletion (see, e.g., QtViewer::createDPG()).
00162   virtual void quit();
00163 
00164  protected slots:
00165  
00166   // Connected by this class, (only) to QDPs' destroyed() signals
00167   // (for maintenance of the list of existing QDPs).
00168   virtual void dpDestroyed_(QObject*);
00169  
00170   // Connected by this class, (only) to QDPs' dpHidden() signals
00171   // (for checking on open QDPs -- will quit if none are left open).  
00172   virtual void dpHidden_(QtDisplayPanel*);
00173  
00174 
00175     
00176  protected:
00177  
00178   bool server_;
00179  
00180   // Existing QtDisplayPanels (whether 'closed' or not, as long as
00181   // not deleted).  Unlike QDDs, QtViewerBase does not create or delete
00182   // QDPs, it just tries to keep track of them.  Note that by default,
00183   // 'closed' DPs are simply not 'visible' (see QWidget::isVisible()), though
00184   // they are not deleted unless their owner does it.  An owner can also
00185   // revive (show) a 'closed' QDP.  The publicly-available list openDPs()
00186   // shows only those which are not closed.  Minimized or covered
00187   // DPs are still considered 'open'.
00188   List<QtDisplayPanelGui*> qdps_;
00189   
00190   
00191   // This should be the only place this object is ever created....
00192   // Holds mouse button assignment for the mouse tools, which is to
00193   // be the same on all mouse toolbars / display panels.
00194   QtMouseToolState msbtns_;
00195 
00196   // Translates IMAGE, RASTER, etc. into the names used internally
00197   // (e.g. "image", "raster").
00198   Vector<String> datatypeNames_, displaytypeNames_;
00199   
00200   // e.g. dataDisplaysAs_[IMAGE] will be {RASTER, CONTOUR, VECTOR, MARKER}
00201   // dataDisplaysAs_[datatype][0] will be the default displaytype for
00202   // that datatype.
00203   Vector<Vector<Int> > dataDisplaysAs_;
00204 
00205  private:
00206   static bool qtviewer_app_exit;
00207  
00208 };
00209 
00210 
00211 
00212 } //# NAMESPACE CASA - END
00213 
00214 #endif