casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtDisplayPanel.qo.h
Go to the documentation of this file.
00001 //# QtDisplayPanel.qo.h: Qt implementation of viewer display Widget.
00002 //# Copyright (C) 2005
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 QTDISPLAYPANEL_H
00029 #define QTDISPLAYPANEL_H
00030 
00031 #include <casa/aips.h>
00032 #include <display/Display/Colormap.h>
00033 #include <casa/Containers/List.h>
00034 #include <display/QtViewer/QtPixelCanvas.qo.h>
00035 #include <display/QtViewer/QtMouseTools.qo.h>
00036 #include <display/QtViewer/QtOldMouseTools.qo.h>
00037 #include <display/QtViewer/DisplayDataHolder.h>
00038 #include <display/QtViewer/ImageManager/ImageTracker.h>
00039 #include <display/Display/PanelDisplay.h>
00040 #include <images/Regions/ImageRegion.h>
00041 #include <display/DisplayEvents/MWCRTZoomer.h>
00042 #include <display/DisplayEvents/PCPositionEH.h>
00043 #include <display/QtPlotter/QtMWCTools.qo.h>
00044 #include <display/QtPlotter/QtOldMWCTools.qo.h>
00045 #include <display/region/QtRegionSourceFactory.h>
00046 #include <display/Display/Position.h>
00047 
00048 #include <graphics/X11/X_enter.h>
00049 #  include <QtCore>
00050 #  include <QtGui>
00051 #  include <QTimer>
00052 #  include <QDebug>
00053 #  include <QtXml>
00054 #include <graphics/X11/X_exit.h>
00055 
00056 
00057 namespace casa { //# NAMESPACE CASA - BEGIN
00058 
00059 
00060 class QtDisplayPanelGui;
00061 class QtDisplayData;
00062 class DisplayData;
00063 class PCITFiddler;
00064 //class MWCCrosshairTool;
00065 class MWCPannerTool;
00066 class MWCPolylineTool;
00067 class MWCRulerlineTool;
00068 class MWCPositionVelocityTool;
00069 //class MWCPTRegion;
00070 class DParameterChoice;
00071 class RegionShape;
00072 class QtRegionShapeManager;
00073 
00074 namespace viewer {
00075         class RegionToolManager;
00076         class Region;
00077 }
00078 
00079 class QtDisplayPanel : public QWidget,
00080                        public WCMotionEH,  public PCPositionEH, public ImageDisplayer {
00081 
00082   Q_OBJECT      //# Allows slot/signal definition.  Must only occur in
00083                 //# implement/.../*.h files; also, makefile must include
00084                 //# name of this file in 'mocs' section.
00085 
00086 public:
00087 
00088         // included in cursor boundary signals...
00089         enum CursorBoundaryCondition { ENTER, LEAVE };
00090 
00091     class panel_state {
00092     public:
00093 
00094         class colormap_state {
00095         public:
00096             colormap_state( const std::string &n, const Vector<Float> &s, const Vector<Float> &b ) : name_(n), shift_(s), brightness_(b) { }
00097             colormap_state( const colormap_state &other ) : name_(other.name_), shift_(other.shift_), brightness_(other.brightness_) { }
00098             const std::string &name( ) const { return name_; }
00099             const Vector<Float> &shift( ) const { return shift_; }
00100             const Vector<Float> &brightness( ) const { return brightness_; }
00101             const std::string &colormap( ) const { return name_; }
00102         private:
00103             std::string name_;
00104             Vector<Float> shift_;
00105             Vector<Float> brightness_;
00106         };
00107 
00108         typedef std::pair<Vector<Double>,Vector<Double> > zoom_state;
00109         typedef std::map<std::string,colormap_state> colormap_map;
00110 
00111         panel_state( const panel_state &other ) : zoom_(other.zoom_) { }
00112         const Vector<Double> &blc( ) const { return zoom_.first; }
00113         const Vector<Double> &trc( ) const { return zoom_.second; }
00114         const colormap_state *colormap( const std::string &s ) const;
00115 
00116  private:
00117         panel_state( const zoom_state &z_, const colormap_map &cm ) : zoom_(z_), colormaps_(cm) { }
00118 
00119         zoom_state zoom_;
00120         colormap_map colormaps_;
00121 
00122         friend class QtDisplayPanel;
00123     };
00124    
00125 
00126   QtDisplayPanel( QtDisplayPanelGui* panel, QWidget* parent=0,
00127                   const std::list<std::string> &args = std::list<std::string>( ) );
00128   ~QtDisplayPanel();
00129   
00130   Bool isEmptyRegistered() const;
00131 
00132   //Manipulation of the QtDisplayData's.
00133   DisplayDataHolder::DisplayDataIterator beginRegistered() const;
00134   DisplayDataHolder::DisplayDataIterator endRegistered() const;
00135   QtDisplayData* getDD( const std::string& name ) const;
00136   DisplayDataHolder* getDataHolder() const;
00137   void setControllingDD( QtDisplayData* controllingDD );
00138   // True if DD is on our list.  (It may _not_ be on viewer's list
00139   // any longer, in particular when reacting to ddRemoved signal).
00140   // Either qdd pointer or its name can be given.
00141   //<group>
00142   virtual Bool isRegistered(QtDisplayData*);
00143   //</group>
00144   
00145 
00146   
00147   
00148   // Return Options record (of margins and no.-of-panels settings, e.g.)
00149   // The form of the record is suitable for automatically creating
00150   // controlling user interface.  These options are set with the
00151   // corresponding setOptions() slot (below).
00152   virtual Record getOptions();    
00153   
00154   
00155 /*   QtViewerBase* viewer() { return v_;  } */
00156  
00157   // Return a QPixmap* with a copy of currently-displayed widget contents.
00158   // Caller is responsible for deleting.
00159   virtual QPixmap* contents() { return pc_->contents();  }
00160   virtual QPixmap* getBackBuffer() { return pc_->getBackBuffer();  }
00161   
00162   // Return underlying library PanelDisplay (used by Annotations, e.g.)
00163   // (You better know what you're doing if you reach underneath the Qt layer.
00164   // You are responsible for consistency between the layers, etc...).
00165   virtual PanelDisplay *panelDisplay() { return pd_;  }
00166 
00167   // Hold and release of refresh.  In order to draw, every call to hold()
00168   // must be accompanied by a subsequent call to release() (so don't
00169   // neglect: beware of exceptions, e.g.).  Calls can nest (they are 
00170   // counted).  Panel may be deleted in a held state.  Also, excess calls
00171   // to release() will have no effect.  The calls are propagated to the main
00172   // PanelDisplay as well as to those used for color bars (and thence to
00173   // their WorldCanvases).
00174   //<group>
00175   virtual void hold();
00176   virtual void release();
00177   //</group>
00178    
00179   // Return names of resident mouse tools (order is a suggestion
00180   // for order in gui).
00181   virtual Vector<String> mouseToolNames() { return mouseToolNames_;  }
00182   
00183   
00184   // This callback method is automatically registered with the
00185   // appropriate objects, and is not intended for general use (it
00186   // has a similar role to a protected, self-connected slot).
00187   // Overrides (null) base WCMotionEH operator to forward cursor
00188   // position tracking events from any of the panel's WorldCanvases
00189   // as Qt signals.  
00190   virtual void operator()(const WCMotionEvent &ev);
00191   
00192   // This callback method is automatically registered with the
00193   // appropriate PC object, and is not intended for general use (it
00194   // has a similar role to a protected, self-connected slot).
00195   void operator()(const PCPositionEvent &pev) {
00196     //# (Its only current role is to toggle a
00197     //# freeze of cursor tracking via the space bar).
00198     if(pev.key()==Display::K_space) tracking_ = !tracking_;  }
00199 
00200   
00201   // Return total number of (main) subpanels (e.g. 12 for 3x4-panel display).
00202   Int nPanels() { return pd_->nWCHs();  }
00203    
00204   
00205   //# animation
00206  
00207   //# ( Updates to user interface will likely need only these:
00208   //#   modeZ() (or mode()),
00209   //#   nFrames(), frame(),
00210   //#   startFrame(), lastFrame(), step(),
00211   //#   animRate(), minRate(), maxRate(), animating()  ).
00212   
00213   virtual Bool modeZ()  { return modeZ_;  }
00214   virtual String mode() { return modeZ()?  "Normal" : "Blink";  }
00215   
00216   virtual Int nFrames()  { return modeZ()?  nZFrames() : nBFrames();  }
00217   virtual Int nZFrames() { return zLen_;  }
00218   virtual Int nBFrames() { return bLen_;  }
00219   
00220   virtual Int frame()  { return index();  }
00221   virtual Int index()  { return modeZ()?  zIndex() : bIndex();  }
00222   virtual Int zIndex() { return zIndex_;  }
00223   virtual Int bIndex() { return bIndex_;  }
00224   
00225   virtual Int startFrame()  { return modeZ()?  zStart() : bStart();  }
00226   virtual Int zStart() { return zStart_;  }
00227   virtual Int bStart() { return bStart_;  }
00228   
00229   virtual Int lastFrame() { return endFrame()-1;  }
00230   virtual Int endFrame()  { return modeZ()?  zEnd() : bEnd();  }
00231   virtual Int zEnd() { return zEnd_;  }
00232   virtual Int bEnd() { return bEnd_;  }
00233         //# NB: frame() <  endFrame()  (<--used internally)
00234         //# but frame() <= lastFrame() (<--shown in ui)
00235 
00236   virtual Int step()  { return modeZ()?  zStep() : bStep();  }
00237   virtual Int zStep() { return zStep_;  }
00238   virtual Int bStep() { return bStep_;  }
00239   
00240   virtual Int animRate()  { return animRate_;  }
00241   virtual Int minRate()   { return minRate_;  }
00242   virtual Int maxRate()   { return maxRate_;  }
00243   virtual Int animating() { return animating_;  }
00244 
00245  
00246    
00247   
00248   //# region management
00249 
00250     
00251   // Transform origPath to a plausible pathname for a new image region file.
00252   // Assures the filename ends in '.rgn' and that no such file already exists.
00253   static String regionPathname(String origPath);
00254   
00255   // Save the last region created (via an image DD) with the mouse.
00256   // Return value indicates success.
00257   // (The ImageRegion is transformed to a TableRecord then saved via AipsIO).
00258   Bool saveLastRegion(String path);
00259   
00260   // same as above except it is saved in the last registered image as a keyword
00261 
00262   String saveRegionInImage(String regname, const ImageRegion& imreg);
00263   
00264   // Delete the region regname from last registered image
00265   // does not care if its RegionHandler::Masks or  RegionHandler::Regions
00266   void removeRegionInImage(String regname);
00267   
00268   // give the regions already stored in last dd image
00269   // a coma separated list
00270   String listRegions();
00271   // a vector list
00272   Vector<String> listRegionsInImage();
00273   // get an ImageRegion from active Image
00274   ImageRegion getRegion(const String& name);
00275   
00276   // Set current extension policy to use to for (subsequent) image region
00277   // creation (and for printed region statistics):
00278   // 0: Region should apply to viewed plane only.
00279   // 1: Extend to all channels (iff spectral axis not on display).
00280   // 2: Extend along all non-displayed axes.
00281   // (The mouse polygon/rectangle always determines the region on the
00282   // displayed axes).
00283   //
00284   // The default policy is 0.
00285   void setRegionExtent(Int ext) { rgnExtent_ = max(0, min(2,  ext  ));  }
00286   
00287   // Return the last region created (via an image DD) with the mouse.
00288   ImageRegion lastRegion() { return lastRgn_;  }
00289   
00290   Bool hasRegion() { return hasRgn_;  } 
00291   
00292   
00293   
00294   
00295   //# 'region' Shapes (unrelated to mouse regions / ImageRegions;
00296   //# more like annotations.)
00297   
00298   
00299   // Sets the region shape manager from QtDisplayPanelGui.
00300   void setShapeManager(QtRegionShapeManager* manager);
00301   
00302   // Register the given RegionShape on this display panel.
00303   void registerRegionShape(RegionShape* rs);
00304 
00305   // Unregister the given RegionShape on this display panel.
00306   void unregisterRegionShape(RegionShape* rs);
00307 
00308   // Returns true if the given RegionShape is registered on this display panel,
00309   // false otherwise.
00310   Bool isRegistered(RegionShape* rs);
00311   
00312   
00313 
00314      
00315   //# save-restore
00316 
00317 
00318   // Suggest name for restore file (based on first-registered DD).
00319   String suggestedRestoreFilename();
00320   
00321   // Returns an xml String of displayPanel state.  This includes registered
00322   // DDs and their options, panel options, animation and zoom state, etc.
00323   // (QtDisplayPanelGui adds some gui/window state to this, and has
00324   // file-saving interface).
00325   // If a restorefilename where you intend to store the state is given, it
00326   // will be set as attribute 'restorefile' of the root node.  This allows
00327   // data files to be moved and still restored later, relative to the restore
00328   // file location.
00329   String dpState(String restorefilename="");
00330    
00331   // Save panel state to a file (as xml).  State is also stored to an
00332   // internal lastSavedState_ String (only there, if filename=="").
00333   // By default, the file will be overwritten if necessary.
00334   virtual Bool savePanelState(String filename="", Bool overwrite=True);
00335   
00336   // Restore panel state from a file or from lastSavedState_ if filename=="".
00337   virtual Bool restorePanelState(String filename="");
00338   
00339   // set panel state from xml String (lastSavedState_, by default).
00340   virtual Bool setPanelState(String xmlState="");
00341 
00342   // [re]set panel state from a QDomDocument.
00343   virtual Bool setPanelState(QDomDocument& restoredoc,
00344                              QString restorefiledir="");
00345 
00346   panel_state getPanelState( ) const;
00347   void setPanelState( const panel_state & );
00348 
00349   // *new* Region code  --  load casa (or DS9?) region files...
00350   void loadRegions( const std::string &path, const std::string &type );
00351   // *new* Region code  --  revoke region from region source...
00352   void revokeRegion( viewer::Region *r );
00353 
00354   // called to indicate application activation state... true -> activated, false -> deactivated
00355   void activate( bool );
00356   
00357 
00358  public slots:
00359 
00360   //respond to region manager to set ImageRegion extension 
00361   void extendRegion(String, String);
00362   
00363   // Register / unregister [all] DDs created by user through QtViewer.
00364   //<group>
00365   virtual void registerDD(QtDisplayData*, int postion = -1);
00366   virtual void unregisterDD(QtDisplayData*);
00367   virtual void unregisterAll();
00368   virtual void registerAll(List<QtDisplayData*> registerDatas);
00369   //</group>
00370 
00371   // Set display panel options such as margins or number of panels.  The
00372   // form of the record (along with current settings) is returned by
00373   // getOptions().  (These Records are an older form of 'parameter sets'
00374   // which are used in various places within the display library).
00375   // Set emitAll = True if the call was not initiated by the options gui
00376   // itself (e.g. via scripting or save-restore); that will assure that
00377   // the options gui does receive all option updates (via the optionsChanged
00378   // signal) and updates its user interface accordingly.
00379   virtual void setOptions(Record opts, Bool emitAll=False);
00380  
00381   
00382   
00383   //# animation
00384    
00385   virtual void setMode(bool modez, bool channelCubes = false);
00386   virtual void setMode(String mode) { setMode(downcase(mode)=="normal");  }
00387 
00388   virtual void toStart() { goTo(startFrame());  }
00389   virtual void toEnd()   { goTo(lastFrame());  }
00390   virtual void revStep() { stop_(); prev_();  }
00391   virtual void fwdStep() { stop_(); next_();  }
00392   virtual void revPlay();
00393   virtual void stop();          // slots corresp. to tapedeck buttons.
00394   virtual void fwdPlay();
00395   virtual void setRate(int rate);
00396   void lowerBoundAnimatorImageChanged( int );
00397   void upperBoundAnimatorImageChanged(int);
00398   void stepSizeAnimatorImageChanged(int);
00399   void lowerBoundAnimatorChannelChanged( int );
00400   void upperBoundAnimatorChannelChanged(int);
00401   void stepSizeAnimatorChannelChanged(int);
00402 
00403     
00404   virtual void goTo(int frm, bool channelFrame=false) { if(modeZ() || channelFrame ) goToZ(frm); else goToB(frm);  }
00405         //# Note: connected to std Qt signal which takes 'int'.
00406         //# As of Qt4.1.3, declaring goTo(Int frm) will no longer
00407         //# do (which is a bit of a pain...).  (Actually, though,
00408         //# it is very unclear to me that having casa Ints, Floats,
00409         //# et. al. buys us anything at all...).
00410   virtual void goToZ(int frm);
00411   virtual void goToB(int frm);
00412 
00413   virtual void emitAnimState() { emit animatorChange();  }
00414   
00415   //# mouse tools
00416   
00417   // (Will remove mouse-tools' own visual feedback from screen;
00418   // usually called after selection has been processed).
00419   
00420   //<group>
00421   virtual void resetRTRegion();
00422   virtual void resetPTRegion();
00423   virtual void resetETRegion();
00424   virtual void resetZoomer();   //# (NB: != unzoom(); no zoom effect).
00425   virtual void resetCrosshair();
00426   virtual void resetPolyline();
00427   virtual void resetPanner();
00428   
00429   virtual void resetRegionTools();
00430   virtual void resetSelectionTools();
00431   
00432   virtual void resetTool(String toolname);
00433   virtual void resetTools();
00434   //</group>
00435   
00436   
00437   // Expose Zoomer functions: zoom in/out, zoom out to whole image.
00438   //<group>
00439   virtual void zoomIn (Double fctr=2.) { if(zoom_!=0) zoom_->zoomIn (fctr);  }
00440   virtual void zoomOut(Double fctr=2.) { if(zoom_!=0) zoom_->zoomOut(fctr);  }
00441   virtual void zoom (const Vector<Double> &blc, const Vector<Double> &trc )
00442                                 {if ( zoom_ != 0 ) zoom_->zoom( blc, trc ); }
00443   virtual void unzoom() { if(zoom_!=0) zoom_->unzoom();  }
00444   //</group>
00445 
00446 
00447   Bool worldToLin(Vector<Double> &lin, const Vector<Double> &world);
00448   
00449   // Returns the pixel canvas's current size.
00450   QSize canvasSize() { return pc_->size(); }
00451   
00452   
00453 
00454   // Refresh everything: main panel and colorbar panels (if any).
00455   virtual void refresh() {
00456     pd_->refresh();
00457     refreshCBPanels_();  }
00458   virtual void setBlen_(Int len);
00459  
00460 
00461  signals:
00462 
00463   
00464 
00465   void animatorChange();
00466         //# (Updating entire animator gui when any animator
00467         //# change occurs is plenty fast, it turns out...).
00468 
00469   
00470   // signals from registration methods.
00471   //
00472   // If you connect to any of these registrationChange signals
00473   // and/or to ddCreated or ddRemoved signals (from QtViewerBase),
00474   // the following are true when the slot is invoked:
00475   // * Any removed QDD still exists until after the signal's 
00476   //   _directly_ connected slots have returned.
00477   // * Any new QDD has been created before the corresp. signal is emitted.
00478   // * The list of existing QDDs (QtViewerBase::dds()) and [un]registered
00479   //   QDDS (registeredDDs(), unregisteredDDs()) reflect the new state.
00480   //
00481   // However, if you connect to a registrationChange signal _and_ to
00482   // ddCreated or ddRemoved, it is not certain which slot will be
00483   // invoked first.
00484   //<group>
00485   
00486   //#dk (These signals are the ones most suitable for the regMenu and
00487   //#dk  other parts of the gui to react to....  They are emitted
00488   //#dk _after_ respective action has taken place, but QDD still exists).
00489   void oldDDRegistered(QtDisplayData*);         //# reg. status change
00490   void oldDDUnregistered(QtDisplayData*);       //# on pre-existing DDs.
00491   void newRegisteredDD(QtDisplayData*);         //# new DD creation, with
00492   void newUnregisteredDD(QtDisplayData*);       //# new reg. status.
00493   void RegisteredDDRemoved(QtDisplayData*);     //# DD removal from viewer,
00494   void UnregisteredDDRemoved(QtDisplayData*);   //# with former reg. status.
00495   void allDDsRegistered();      //# (may be emitted _instead_ of
00496   void allDDsUnregistered();    //#  oldDD[Un]registered, above).
00497   
00498   void registrationChange();    //# Any of above occurred; usually
00499                                 //# simplest just to connect to this one.
00500   //</group>
00501   
00502   
00503   //# signals arising from 'region' mouse tools.
00504   
00505   // This raw mouse region signal is probably less useful to connect
00506   // to than the ones processed through the DDs (below), which contain
00507   // true 'image regions'.
00508   void mouseRegionReady(Record mouseRegion, WorldCanvasHolder*);
00509   
00510   
00511   // Higher-level (ImageRegion) signal.  ddName is the name() of a
00512   // registered [Lattice] QDD which conforms to the panel's current
00513   // state (see DD:conformsTo()) and can compute true-region information
00514   // from the latest 'mouse tool region event'.  The ImageRegion
00515   // parameter has the dimensions [and CS] of the DD's Image
00516   // (currently, only Image PADDs are supported).  It will correspond
00517   // to the 2-D mouse region on its display axes. On 'animator' and
00518   // 'hidden' axes (if any), the region will be 1 element wide, positioned
00519   // at the current 'slice' for each of these axes.
00520   void imageRegionReady(ImageRegion imgRegion, String ddName);
00521   
00522   
00523   
00524   
00525   // signal from cursor position tracking.  The field names are the
00526   // names of registered QDDs with tracking info; corresponding values
00527   // are Strings with the formatted tracking information.
00528   void trackingInfo(Record trackingRec);
00529   
00530 
00531 
00532   // signal from option setting (probably unused at present).
00533   void optionsChanged(Record chgOpt); 
00534  
00535   // Emitted when this QDP is hidden (closed).
00536   void dpHidden(QtDisplayPanel* dp);
00537   
00538   
00539   // Emitted when a new ImageRegion has been stored internally (in lastRgn_).
00540   // It can be saved to disk with saveLastRegion().
00541   void newRegion(String imagePath);
00542   
00543   
00544   // Emitted when the panel has been resized.
00545   void resized(QSize panelSize, QSize canvasSize);
00546 
00547   
00548   // Emitted when creating a restore xml doc.  QtDisplayPanelGui (in
00549   // particular) can process by adding intormation to restoredoc.
00550   void creatingRstrDoc(QDomDocument* restoredoc);
00551   
00552   // Emitted when restoring panel state from an xml doc.  QtDisplayPanelGui
00553   // (in particular) can respond by setting its own state from certain
00554   // elements of restoredoc.
00555   void restoring(QDomDocument* restoredoc);
00556 
00557   void activate(Record);
00558 
00559   // signal cursor boundary transitions
00560   void cursorBoundary( QtDisplayPanel::CursorBoundaryCondition );
00561   void cursorPosition( viewer::Position );
00562 
00563  protected slots:
00564   
00565   //# I.e., only this class creates the connections to these,
00566   //# (though the signals _may_ come from outside...).
00567  
00568   //# Protected counterparts to public slots/routines generally are 
00569   //# 'workhorse' parts of the public routines.  They do the indicated
00570   //# task, but without assuring consistency with other state/interface,
00571   //# or sending signals for that purpose.  Those jobs are left to the
00572   //# public parts, mostly.
00573   
00574   
00575   //# registration
00576    
00577   // reacts to similar-named signals from QtViewer
00578   // <group>
00579   virtual void ddCreated_(QtDisplayData*, Bool autoRegister);
00580   virtual void ddRemoved_(QtDisplayData*);
00581   // </group>
00582   
00583   
00584   //# animation
00585    
00586   virtual void setAnimatorOptions_(Record opts);
00587   virtual void setAnimator_(Record sarec);
00588   
00589   virtual void setLen_(Int len) {       //# (probably unneeded).
00590     if(modeZ()) setZlen_(len);
00591     else        setBlen_(len);  }
00592   virtual void setZlen_(Int len);
00593   
00594 
00595   virtual void stop_();
00596   virtual void goTo_(Int frm) { if(modeZ()) goToZ_(frm); else goToB_(frm);  }
00597   virtual void goToZ_(Int frm);
00598   virtual void goToB_(Int frm);
00599   
00600   virtual void playStep_() {
00601     if(animating_<0) prev_(); else if(animating_>0) next_();  } 
00602   virtual void prev_(); //# (Like fwdStep, revStep, but these don't stop
00603   virtual void next_(); //#  the animation; they are _used_ by animation)
00604   
00605   
00606   
00607   //# mouse tools
00608    
00609   // Connected to QtMouseToolState::mouseBtnChg() signal: changes
00610   // button assignment for a mouse tool.
00611   virtual void chgMouseBtn_(std::string tool, Int button);
00612 
00613   // Connected to corresp. signals from 'region' mouse tools.  Emits that
00614   // signal verbatum, but also processes it through the registered DDs,
00615   // and emits higher-level 'Image Regions' from those DDs which can
00616   // create one from the 'mouse region' record.
00617   virtual void mouseRegionReady_(Record mouseRegion, WorldCanvasHolder*);
00618   
00619   
00620   
00621   //# color bar maintenance.
00622   
00623   virtual void reorientColorBars_() { arrangeColorBars_(True);   }
00624   virtual void checkColorBars_()    { arrangeColorBars_(False);  }
00625   virtual void pcResizing_()        { arrangeColorBars_(False, True);  }
00626  
00627   
00628   
00629   //# position tracking
00630   
00631   // triggered by internal dd change (not mouse movement;
00632   // see operator()(WCMotionEvent) for that.) 
00633   virtual void refreshTracking_(QtDisplayData* qdd=0);
00634  
00635   void clicked(Record);
00636   
00637  protected:
00638   
00639   // Called during construction.
00640   virtual void setupMouseTools_( bool new_region_tools );
00641   
00642   // The workhorse part of [un]registering; these do not send the
00643   // highest-level signals.
00644   // Called internally when the DD is new or being removed, or from
00645   // corresponding public methods.
00646   // <group>
00647   virtual void registerDD_(QtDisplayData* qdd, int position = -1);
00648   virtual void unregisterDD_(QtDisplayData* qdd);
00649   // </group>
00650 
00651   // Maintain monitors of events on underlying canvases.  Called during
00652   // construction/destruction, or when the set of canvases might change.
00653   // <group>
00654   virtual void installEventHandlers_();
00655   virtual void removeEventHandlers_();
00656   // </group>
00657   
00658   // Utility function: is the given wc one belonging to the main pd_?
00659   virtual Bool myWC_(const WorldCanvas* wc);
00660   
00661   
00662   //# color bar maintenance.
00663   
00664   // This routine corresponds to the old viewerdisplaypanel.g routine called
00665   // 'arrangewedgerequirements'.  It responds to events which may require
00666   // change to the relative placement or number of colorbars and their panels.
00667   // 'reorient' is True if color bars are changing from horizontal to vertical
00668   // (or vise versa); it helps determine how much action (if any) this routine
00669   // needs to take.
00670   // Only the pcResizing_() slot should set resizing=True; in this case,
00671   // arrangeColorBars_ lets the PC take care of refresh.
00672   virtual void arrangeColorBars_(Bool reorient=False, Bool resizing=False);
00673  
00674  
00675   // Update Lists of registered DDs which have color bar display
00676   // activated (allColorBarDDs_ and colorBarDDsToDisplay_).
00677   // Used by arrangeColorBars_().
00678   virtual void updateColorBarDDLists_();
00679  
00680   
00681   // Used by arrangeColorBars_().
00682   // Return the margin to give to dd's colorbar panel on the side where
00683   // colorbar labelling is done (right margin for vertical bars, e.g.).
00684   // shrink will usually be 1.; in rare cases where many colorbars are
00685   // crowding the main panel and each other, it may be less (and then
00686   // the returned margin allowance may also be less than ideal...). 
00687   virtual Int marginb_(QtDisplayData* dd, Float shrink=1.);
00688  
00689   
00690   // Used by arrangeColorBars_().
00691   // Return the nominal proportion of the PixelCanvas to use for dd's
00692   // colorbar panel.  (This is allocated along the direction of the
00693   // colorbar's thickness; in the direction its length the panel uses
00694   // the entire PC size).
00695   virtual Float cbPanelSpace_(QtDisplayData* dd);
00696   
00697   
00698   // Refresh (only) the colorbar panels (if any).  (An attempt to reduce
00699   // flashing during blink animation).
00700   virtual void refreshCBPanels_();  
00701   
00702  
00703   //# save-restore
00704   
00705   // Tries to find existing DD (or create one from a file) that matches
00706   // the given path.  Used for restoring DDs from a restore file.
00707   // Several directories are checked, not just the one in path, to
00708   // provide flexibility.  If dd is non-zero, it is tested for suitability
00709   // to path, datatype and displaytype.  If dd is zero, the filesystem
00710   // is searched and an attempt is made to create dd from a matching file
00711   // (if any); if creation succeeds, dd will contain the new DD.
00712   // Note: the DD will _not_ be registered automatically.
00713   // origrestorefile and (current) restoredir aid in locating data files
00714   // relative to the current restore file location.
00715   virtual Bool ddFileMatch_( const std::string &path, const std::string &dataType, const std::string &displayType,
00716                              QtDisplayData*& dd, QString origrestorefile, QString restoredir);
00717  
00718   
00719   
00720   //# Qt Widget event handlers
00721   
00722   void hideEvent(QHideEvent* ev) {
00723     QWidget::hideEvent(ev);
00724     emit dpHidden(this);  }
00725     
00726   // (emits Qt signal with QDP and PC sizes.  (You probably really want
00727   // to take action on QPC resizeEvents (based on QPC size) instead...))
00728   void resizeEvent(QResizeEvent* ev);
00729     
00730  
00731   // central (unique) viewer object: for viewer-global state / methods.
00732   QtDisplayPanelGui *panel_;
00733   
00734   // 'Main' panel of pc_, where qdds_ draw themselves.
00735   PanelDisplay* pd_;
00736   
00737   // The entire display canvas for this object
00738   //(the area with black (default) background).
00739   QtPixelCanvas* pc_;   //# QtDisplayPanel is basically just enhanced
00740                         //# state and functional interface on top of
00741                         //# this PixelCanvas.  Its own QWidget
00742                         //# is just a container for the PC's.
00743   
00744   // QDDs registered on this QDP, in registration order.
00745   // (List of _all_ (user-loaded) QDDs is v_->dds()).
00746   //List<QtDisplayData*> qdds_;
00747   DisplayDataHolder* displayDataHolder;
00748   
00749   //# mouse tools.
00750   viewer::RegionToolManager *toolmgr;
00751   
00752   //<group>
00753   MWCRTZoomer* zoom_;
00754   MWCPannerTool* panner_;
00755   
00756   QtOldCrossTool* ocrosshair_;
00757   QtOldRectTool* ortregion_;
00758   QtOldEllipseTool *oelregion_;
00759   QtOldPolyTool* optregion_;
00760 
00761   viewer::QtRegionSourceFactory *region_source_factory;
00762 
00763   MWCPolylineTool* polyline_;
00764 
00765   MWCRulerlineTool* rulerline_;
00766   MWCPositionVelocityTool *pvtool_;
00767 
00768   PCITFiddler* snsFidd_;
00769   PCITFiddler* bncFidd_;
00770   //</group>
00771   
00772   Vector<String> mouseToolNames_;
00773   
00774   
00775   
00776   QTimer tmr_;
00777   
00778   Bool tracking_;       //# Won't send out tracking signals when False.
00779 
00780     
00781   //# animation state
00782   
00783   Bool modeZ_;                  //# True (default) == normal mode; else blink.
00784   Int zLen_, bLen_;             //# total number of frames for each mode.
00785   Int zIndex_, bIndex_;         //# current frame (0-based).
00786   
00787   Int animRate_;                //# frames / sec. for play.
00788   Int minRate_, maxRate_;       //# limits to above:
00789                                 //# 1 <= minRate_ <= animRate_ <= maxRate_.
00790   Int animating_;               //# -1: reverse play  0: stopped  1: fwd. play
00791 
00792   
00793   
00794   //# color bar state
00795   
00796   // Registered QDDs which have color bar display activated (in registration
00797   // order).  See arrangeColorBars_() and updateColorBarDDLists_().
00798   List<QtDisplayData*> allColorBarDDs_;
00799 
00800   // Subset of the list above: those which should actually display now
00801   // (which would exclude, e.g., a DD which is 'off blink').  These DDs
00802   // are ordered so that in multipanel blink displays the order of images
00803   // in panels is the same as the display order of their corresponding
00804   // colorbars.
00805   List<QtDisplayData*> colorBarDDsToDisplay_;
00806   
00807   // Corresponding List of PanelDisplays in which color bars are placed
00808   // -- one for each QDD in colorBarDDsToDisplay_.  Assignment of QDDs
00809   // to panels is maintained in the order of list above.
00810   List<PanelDisplay*> colorBarPanels_;
00811   
00812   // A panel that takes unused PC space in the colorbar area, if any.
00813   // just to see that it's cleared when appropriate.
00814   PanelDisplay* blankCBPanel_;
00815   
00816   // Proportion of the pc_ that each color bar panel will use along the
00817   // direction of colorbar thickness (e.g., along the horizontal axis for
00818   // a vertical bar).  arrangeColorBars_() gets nominal sizes for colorbar
00819   // panels from cbPanelSpace_(), and that is usually what they get.
00820   Vector<Float> colorBarPanelSizes_;
00821 
00822   // The portion of the PixelCanvas allocated to the main (image display)
00823   // PanelDisplay (pd_);
00824   Float mainPanelSize_;
00825   
00826   // The following are used (only) by arrangeColorBars_() and its
00827   // auxiliary routines, and are set for current conditions every time
00828   // arrangeColorBars_() is called. The margins (in 'pgp chars') are
00829   // set onto the colorbar panels. PixelCanvas current sizes are in
00830   // screen pixels.  marginUnit_ is 1/65 of the PC's minimum dimansion.
00831   // 'ln' and 'th' refer to the directions along the colorbar's length
00832   // and thickness, respectively; 'ln' corresponds to vertical / horizontal
00833   // according to the current orientation of color bars.  mrgna_, mrgnb_
00834   // are margins in the colorbar thickness direction; mrgnb_ is where
00835   // labelling occurs.
00836   Int pcthsz_,  pclnsz_;
00837   Float marginUnit_;
00838   Int mrgna_, mrgnb_,  lnmrgna_, lnmrgnb_;
00839 
00840   
00841     
00842   //# region management state
00843   
00844   // The last region created with a mouse tool.  
00845   ImageRegion lastRgn_;
00846   
00847   // path (if any) to image of DD that produced the region (needed?)
00848   String rgnImgPath_;
00849   
00850   // Has any such region (ever) been saved?
00851   Bool hasRgn_;
00852   
00853   // Extension policy to use to for saved region (and for statistics:
00854   // 0: Region applies to viewed plane only.
00855   // 1: Extend to all channels (iff spectral axis not on display).
00856   // 2: Extend along all non-displayed axes.
00857   // (The mouse polygon/rectangle always determines the region on the
00858   // displayed axes).
00859   Int rgnExtent_;
00860 
00861     
00862   
00863   //# 'Region Shape' state (unrelated to mouse region / ImageRegion state
00864   //# above; more like annotations.)
00865   
00866   // RegionShapes registered on this display panel, in registration order.
00867   List<RegionShape*> rshapes_;
00868   
00869   // Pointer to shape manager.
00870   // (within this class, please do not assume qsm_ has been set.)
00871   QtRegionShapeManager* qsm_;
00872   
00873   
00874   
00875   //# save-restore state
00876   
00877   // last saved state for this panel (this session -- "" if none).
00878   // Used for fast 'clipboard' save-restore.
00879   // (Note: No user interface for this yet...).
00880   String lastSavedState_;  
00881   
00882 
00883   
00884   //# position tracking state
00885   
00886   // last valid mouse motion event; for use by refreshTracking_() in
00887   // case something besides mouse motion dictates that tracking
00888   // data should be refreshed.
00889   WCMotionEvent* lastMotionEvent_;
00890   
00891   
00892   
00893   //# misc.
00894     
00895   // User interface parsing object for background/foreground color.
00896   // (Used in get/setOptions(), shows up in QDPG's 'Panel Display Options'
00897   // window).
00898   DParameterChoice* bkgdClrOpt_;
00899 
00900 
00901  
00902   //image region extension flags
00903   String extChan_;
00904   String extPol_;
00905 
00906   // keep track or where the (USER) cursor currently is...
00907   enum CursorBoundaryState { INSIDE_PLOT, OUTSIDE_PLOT };
00908   CursorBoundaryState cursorBoundaryState;
00909 
00910  public:
00911  
00912   //# This (public) bool is probably temporary.  True by default.
00913   //# Set it False to disable stats printing.
00914   Bool printStats;
00915 
00916   Bool useRegion;
00917   
00918   //# Printing utilities
00919   
00920   void setAllowBackToFront(Bool allowed=True) { 
00921      if (pc_) pc_->setAllowBackToFront(allowed);  }
00922   
00923   void setUpdateAllowed(Bool allowed=True) { 
00924      if (pc_) pc_->setUpdateAllowed(allowed);  }
00925   
00926   void setLineWidthPS(Float &w); 
00927   void setBackgroundPS(String &w, String &c); 
00928 
00929   void beginLabelAndAxisCaching( ) { pc_->beginLabelAndAxisCaching( );  }
00930   void endLabelAndAxisCaching( QPainter &qp ) {
00931     pc_->endLabelAndAxisCaching( qp );  }
00932 
00933 
00934  private:
00935 
00940   void processTracking( const Record& trackingRec, const WCMotionEvent& ev );
00941 
00951   void setColorBarMargins( bool vertical, float plotPercentage, PanelDisplay* cbp, bool resizing );
00952 
00959   void setPanelGeometry( PanelDisplay* pd, float orgn, float siz );
00960 
00968   void setPanelMargins( PanelDisplay* pd, int marginA =LEFT_MARGIN_SPACE_DEFAULT,
00969                   int marginB = RIGHT_MARGIN_SPACE_DEFAULT,
00970                   int lengthMarginA = BOTTOM_MARGIN_SPACE_DEFAULT,
00971                   int lengthMarginB = TOP_MARGIN_SPACE_DEFAULT);
00972   /*
00973    * Attempts to set an appropriate font size for plot axis
00974    * labels based on the number of plots that are displayed.
00975    */
00976   void setLabelFontSize(  );
00977 
00982   void setMarginSize(  );
00983 
00984   //# DATA
00985   //An estimate for the number of pixels that correspond to one
00986   //PGP plot unit.
00987   const int PGP_MARGIN_UNIT;
00988   enum ColorBarIndex {ORIGIN, SIZE, LENGTH_SIDE_ORIGIN, LENGTH_SIDE_SIZE, MARGIN_A,
00989           MARGIN_B, LENGTH_SIDE_MARGIN_A, LENGTH_SIDE_MARGIN_B};
00990 
00991    std::map<ColorBarIndex,String> settingsMap;
00992 
00997    void initializeSettingsMap( bool vertical );
00998 
01003    void plotCountChangeAdjustment();
01004 
01005    //Used for coming up with estimates for the new font and margin
01006    //sizes.
01007    float oldPlotPercentage;
01008    int oldPixelCanvasHeight;
01009    int oldPixelCanvasWidth;
01010    int oldRowCount;
01011    int oldColumnCount;
01012 
01013    //Default sizes for the margins
01014    static const int LEFT_MARGIN_SPACE_DEFAULT;
01015    static const int BOTTOM_MARGIN_SPACE_DEFAULT;
01016    static const int TOP_MARGIN_SPACE_DEFAULT;
01017    static const int RIGHT_MARGIN_SPACE_DEFAULT;
01018 
01019    //# Start_, End_ are current user-defined animator limits;
01020    //# The user can now set her/her own desired limits.
01021    //# 0 <= Start_ <=Index_ < End_ <=Len_   and  1 <= Step_ <= Len_.
01022    Int zStart_, zEnd_, zStep_;
01023    Int bStart_, bEnd_, bStep_;
01024 
01025 };
01026 
01027 
01028 
01029 } //# NAMESPACE CASA - END
01030 
01031 #endif