casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WorldCanvasHolder.h
Go to the documentation of this file.
00001 //# WorldCanvasHolder.h: Interface between DisplayDatas and a WorldCanvas
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002
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 TRIALDISPLAY_WORLDCANVASHOLDER_H
00029 #define TRIALDISPLAY_WORLDCANVASHOLDER_H
00030 
00031 #include <casa/aips.h>
00032 #include <list>
00033 #include <display/DisplayEvents/WCRefreshEH.h>
00034 #include <display/DisplayEvents/WCPositionEH.h>
00035 #include <display/DisplayEvents/WCMotionEH.h>
00036 #include <display/DisplayCanvas/WCSizeControlHandler.h>
00037 #include <display/DisplayCanvas/WCCoordinateHandler.h>
00038 #include <display/Display/AttributeBuffer.h>
00039 #include <display/Display/WorldCanvas.h>
00040 
00041 namespace casa { //# NAMESPACE CASA - BEGIN
00042 
00043 class Attribute;
00044 class DisplayData;
00045 class String;
00046 
00047 // <summary>
00048 // A holder to interface between DisplayDatas and a WorldCanvas 
00049 // </summary>
00050 //
00051 // <use visibility=export>
00052 // 
00053 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00054 // </reviewed>
00055 // 
00056 // <prerequisite>
00057 //   <li> Attribute
00058 //   <li> AttributeBuffer
00059 //   <li> WorldCanvas
00060 //   <li> DisplayData
00061 // </prerequisite>
00062 //
00063 // <etymology>
00064 // The WorldCanvasHolder "holds" a WorldCanvas and some number of
00065 // DisplayDatas which are "registered" on the WorldCanvas.  It actually
00066 // registers itself to handle the WC events, and passes the events on to
00067 // the DDs.
00068 // </etymology>
00069 //
00070 // <synopsis> 
00071 // </synopsis>
00072 //
00073 // <example> 
00074 // </example>
00075 //
00076 // <motivation> 
00077 // </motivation>
00078 
00079 class WorldCanvasHolder : public WCRefreshEH,
00080                           public WCMotionEH,
00081                           public WCPositionEH,
00082                           public WCSizeControlHandler,
00083                           public WCCoordinateHandler {
00084 
00085  public:
00086 
00087   // Constructor.  A WorldCanvas must be provided for the constructed
00088   // WorldCanvasHolder to "hold".
00089   WorldCanvasHolder(WorldCanvas *canvas);
00090 
00091   // Destructor.
00092   virtual ~WorldCanvasHolder();
00093 
00094   // Return the WorldCanvas which is held by this WorldCanvasHolder.
00095   virtual WorldCanvas *worldCanvas() const
00096     { return itsWorldCanvas; }
00097 
00098   // Add a DisplayData object to the list of DisplayDatas registered
00099   // on the held WorldCanvas by this WorldCanvasHolder.
00100   virtual void addDisplayData(DisplayData *dData); 
00101 
00102   // Remove a DisplayData from the list of DisplayDatas which are
00103   // registered by this WorldCanvasHolder for display on the held
00104   // WorldCanvas. <src>ignoreRefresh</src> tells the DD not to refresh
00105   // just to clean up DMs
00106   virtual void removeDisplayData(DisplayData& dData, 
00107                                  Bool ignoreRefresh = False); 
00108 
00109   // How many DisplayDatas are registered?
00110   virtual const uInt nDisplayDatas() const;
00111 
00112   // Install a single restriction, or a buffer of restrictions, on the
00113   // WorldCanvasHolder which DisplayData must match in order that they
00114   // be allowed to draw themselves.
00115   // <group>
00116   void setRestriction(const Attribute& restriction) {
00117           itsWorldCanvas->setRestriction(restriction);
00118   }
00119   void setRestrictions(const AttributeBuffer& resBuff) {
00120           itsWorldCanvas->setRestrictions(resBuff);
00121   }
00122   // </group>
00123 
00124   // Check if a named restriction exists.
00125   const Bool existRestriction(const String& name) const {
00126           return itsWorldCanvas->existRestriction(name);
00127   }
00128   
00129   //Set whether or not the viewer is in blink mode
00130   void setBlinkMode( bool mode ){
00131           blinkMode = mode;
00132   }
00133 
00134   // Remove the named restriction, or all restrictions, from the
00135   // WorldCanvasHolder.
00136   // <group>
00137   void removeRestriction(const String& restrictionName) {
00138           itsWorldCanvas->removeRestriction(restrictionName);
00139   }
00140   void removeRestrictions() {
00141           itsWorldCanvas->removeRestrictions( );
00142   }
00143   // </group>
00144   
00145   // Determine whether the restrictions installed on the
00146   // WorldCanvasHolder match the given restriction or buffer of
00147   // restrictions.
00148   // <group>
00149   Bool matchesRestriction(const Attribute& restriction) const { return itsWorldCanvas->matchesRestriction(restriction); }
00150   Bool matchesRestrictions(const AttributeBuffer& buffer) const { return itsWorldCanvas->matchesRestrictions(buffer); }
00151   // </group>
00152  
00153   // Return the buffer of restrictions installed on this
00154   // WorldCanvasHolder.
00155   const AttributeBuffer *restrictionBuffer() const { return itsWorldCanvas->restrictionBuffer( ); }
00156   
00157   // Invoke a refresh on the WorldCanvas, ie. this is a shorthand for
00158   // WorldCanvasHolder->worldCanvas()->refresh(reason);.
00159   virtual void refresh(const Display::RefreshReason &reason = 
00160                        Display::UserCommand,
00161                        const Bool &explicitrequest = True);
00162 
00163   // Handle size control requests originating from the WorldCanvas.
00164   virtual Bool executeSizeControl(WorldCanvas *wCanvas);     
00165 
00166   // Distribute a WCPositionEvent originating from the held
00167   // WorldCanvas over the DisplayDatas.
00168   virtual void operator()(const WCPositionEvent &ev);
00169   
00170   // Distribute a WCRefreshEvent originating from the held WorldCanvas
00171   // over the DisplayDatas.
00172   virtual void operator()(const WCRefreshEvent &ev);
00173 
00174   // Distribute a  WCMotionEvent originating from the held WorldCanvas
00175   // over the DisplayDatas.
00176   virtual void operator()(const WCMotionEvent &ev);
00177 
00178   // Handle other, generic types of events.  As with the handlers above,
00179   // WCH handles these new events by simply passing them on to the
00180   // DisplayDatas registered on it.  WorldCanvasHolder inherits this
00181   // new-style event handling interface from DisplayEH, via WCRefreshEH.
00182   virtual void handleEvent(DisplayEvent& ev);
00183 
00184   // Coordinate conversion routines, handled for the WorldCanvas.  
00185   // In future, they should be handled on the WC itself, via its own CS.
00186   // At present, these requests are forwarded to the CSmaster DD, which
00187   // should be equivalent in most cases.
00188   // <group>
00189   virtual Bool linToWorld(Vector<Double>& world, const Vector<Double>& lin);
00190   virtual Bool worldToLin(Vector<Double>& lin, const Vector<Double>& world);
00191   
00192   //# (these latter two are merely to stop a compiler whine...)
00193   virtual Bool linToWorld(Matrix<Double> & world, Vector<Bool> & failures,
00194                           const Matrix<Double> & lin) {
00195     return WCCoordinateHandler::linToWorld(world, failures, lin);  }
00196   
00197   virtual Bool worldToLin(Matrix<Double> & lin, Vector<Bool> & failures,
00198                           const Matrix<Double> & world) {
00199     return WCCoordinateHandler::worldToLin(lin, failures, world);  }
00200   // </group> 
00201 
00202   // Return the number of world axes, which is hard-wired to 2.
00203   virtual uInt nWorldAxes() const {
00204     return 2;
00205   }
00206 
00207   // Maximum number of animation frames of all registered
00208   // DDs which are valid for the WC's current CS state.
00209   virtual const uInt nelements();
00210   
00211   // Force a cleanup of all the DisplayDatas which are registered with
00212   // this WorldCanvasHolder.
00213   virtual void cleanup();
00214   
00215   // The DD in charge of setting WC coordinate state (0 if none).
00216   const DisplayData* csMaster() const { return itsWorldCanvas->csMaster( ); }
00217 
00218   // Is the specified DisplayData the one in charge of WC state?
00219   // (During DD::sizeControl() execution, it means instead that the
00220   // DD has permission to become CSmaster, if it can).
00221   Bool isCSmaster(const DisplayData *dd) const { return itsWorldCanvas->isCSmaster(dd); }
00222     
00223   // Was the passed DD the last CS master (or, if no DD passed, was
00224   // there any CS master)?  For convenience of the DDs during the next
00225   // sizeControl execution, in determining whether a CS master change is
00226   // occurring, and whether anyone was master before.  This affects
00227   // whether any old zoom window is retained or completely reset.
00228   Bool wasCSmaster(DisplayData* dd=0) const { 
00229     return (dd==0)? itsLastCSmaster!=0 : itsLastCSmaster==dd;  }
00230 
00231   // used by PanelDisplay on new WCHs to keep a consistent CS master on
00232   // all its main display WC[H]s.  Sets [default] CS master dd to that of
00233   // passed wch (if that dd is registered here), and gets it to reset WC
00234   // coordinate state.
00235   virtual Bool syncCSmaster(const WorldCanvasHolder* wch);
00236   bool setCSMaster( DisplayData* dd );
00237 
00238   const std::list<DisplayData*> &displaylist( ) const
00239         { return itsDisplayList; }
00240 
00245   Float getDrawUnit() const;
00246 
00247   const static String BLINK_MODE;
00248 
00249 private: 
00250   //True if the viewer is in blink mode.
00251   bool blinkMode;
00252 
00253   // The WorldCanvas that is held by this WorldCanvasHolder.
00254   WorldCanvas *itsWorldCanvas;
00255 
00256   // A list containing the DisplayDatas that are registered on this
00257   // WorldCanvasHolder.
00258   std::list<DisplayData*> itsDisplayList;
00259   DisplayData* controllingDD;
00260   
00261   // The CS master in effect after executeSizeControl was last run (0 if none).
00262   // For determining (via wasCSmaster(), above) whether a CS master change is
00263   // occurring, and whether anyone was master before.  This affects whether
00264   // the old zoom window is retained or completely reset.
00265   // (Note void*, rather than DD*, type: it is not intended to be dereferenced,
00266   // just compared for equality.  The original DD may not even exist by the
00267   // time it is used).
00268   void* itsLastCSmaster;
00269   Float drawUnit;
00270 
00271 };
00272 
00273 } //# NAMESPACE CASA - END
00274 
00275 #endif