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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1