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 
00099                 // Add a DisplayData object to the list of DisplayDatas registered
00100                 // on the held WorldCanvas by this WorldCanvasHolder.
00101                 virtual void addDisplayData(DisplayData *dData, int position);
00102 
00103                 // Remove a DisplayData from the list of DisplayDatas which are
00104                 // registered by this WorldCanvasHolder for display on the held
00105                 // WorldCanvas. <src>ignoreRefresh</src> tells the DD not to refresh
00106                 // just to clean up DMs
00107                 virtual void removeDisplayData(DisplayData& dData,
00108                                                Bool ignoreRefresh = False);
00109 
00110                 // How many DisplayDatas are registered?
00111                 virtual uInt nDisplayDatas() const;
00112 
00113                 // Install a single restriction, or a buffer of restrictions, on the
00114                 // WorldCanvasHolder which DisplayData must match in order that they
00115                 // be allowed to draw themselves.
00116                 // <group>
00117                 void setRestriction(const Attribute& restriction) {
00118                         cout<<"World canvas holder restriction="<<restriction.getName().c_str()<<" value="<<restriction.getType()<<endl;
00119 
00120                         itsWorldCanvas->setRestriction(restriction);
00121                 }
00122                 void setRestrictions(const AttributeBuffer& resBuff) {
00123                         itsWorldCanvas->setRestrictions(resBuff);
00124                 }
00125                 // </group>
00126 
00127                 // Check if a named restriction exists.
00128                 Bool existRestriction(const String& name) const {
00129                         return itsWorldCanvas->existRestriction(name);
00130                 }
00131 
00132                 //Set whether or not the viewer is in blink mode
00133                 void setBlinkMode( bool mode ) {
00134                         blinkMode = mode;
00135                 }
00136 
00137                 // Remove the named restriction, or all restrictions, from the
00138                 // WorldCanvasHolder.
00139                 // <group>
00140                 void removeRestriction(const String& restrictionName) {
00141                         itsWorldCanvas->removeRestriction(restrictionName);
00142                 }
00143                 void removeRestrictions() {
00144                         itsWorldCanvas->removeRestrictions( );
00145                 }
00146                 // </group>
00147 
00148                 // Determine whether the restrictions installed on the
00149                 // WorldCanvasHolder match the given restriction or buffer of
00150                 // restrictions.
00151                 // <group>
00152                 Bool matchesRestriction(const Attribute& restriction) const {
00153                         return itsWorldCanvas->matchesRestriction(restriction);
00154                 }
00155                 Bool matchesRestrictions(const AttributeBuffer& buffer) const {
00156                         return itsWorldCanvas->matchesRestrictions(buffer);
00157                 }
00158                 // </group>
00159 
00160                 // Return the buffer of restrictions installed on this
00161                 // WorldCanvasHolder.
00162                 const AttributeBuffer *restrictionBuffer() const {
00163                         return itsWorldCanvas->restrictionBuffer( );
00164                 }
00165 
00166                 // Invoke a refresh on the WorldCanvas, ie. this is a shorthand for
00167                 // WorldCanvasHolder->worldCanvas()->refresh(reason);.
00168                 virtual void refresh(const Display::RefreshReason &reason =
00169                                          Display::UserCommand,
00170                                      const Bool &explicitrequest = True);
00171 
00172                 // Handle size control requests originating from the WorldCanvas.
00173                 virtual Bool executeSizeControl(WorldCanvas *wCanvas);
00174 
00175                 // Distribute a WCPositionEvent originating from the held
00176                 // WorldCanvas over the DisplayDatas.
00177                 virtual void operator()(const WCPositionEvent &ev);
00178 
00179                 // Distribute a WCRefreshEvent originating from the held WorldCanvas
00180                 // over the DisplayDatas.
00181                 virtual void operator()(const WCRefreshEvent &ev);
00182 
00183                 // Distribute a  WCMotionEvent originating from the held WorldCanvas
00184                 // over the DisplayDatas.
00185                 virtual void operator()(const WCMotionEvent &ev);
00186 
00187                 // Handle other, generic types of events.  As with the handlers above,
00188                 // WCH handles these new events by simply passing them on to the
00189                 // DisplayDatas registered on it.  WorldCanvasHolder inherits this
00190                 // new-style event handling interface from DisplayEH, via WCRefreshEH.
00191                 virtual void handleEvent(DisplayEvent& ev);
00192 
00193                 // Coordinate conversion routines, handled for the WorldCanvas.
00194                 // In future, they should be handled on the WC itself, via its own CS.
00195                 // At present, these requests are forwarded to the CSmaster DD, which
00196                 // should be equivalent in most cases.
00197                 // <group>
00198                 virtual Bool linToWorld(Vector<Double>& world, const Vector<Double>& lin);
00199                 virtual Bool worldToLin(Vector<Double>& lin, const Vector<Double>& world);
00200 
00201                 //# (these latter two are merely to stop a compiler whine...)
00202                 virtual Bool linToWorld(Matrix<Double> & world, Vector<Bool> & failures,
00203                                         const Matrix<Double> & lin) {
00204                         return WCCoordinateHandler::linToWorld(world, failures, lin);
00205                 }
00206 
00207                 virtual Bool worldToLin(Matrix<Double> & lin, Vector<Bool> & failures,
00208                                         const Matrix<Double> & world) {
00209                         return WCCoordinateHandler::worldToLin(lin, failures, world);
00210                 }
00211                 // </group>
00212 
00213                 // Return the number of world axes, which is hard-wired to 2.
00214                 virtual uInt nWorldAxes() const {
00215                         return 2;
00216                 }
00217 
00218                 // Maximum number of animation frames of all registered
00219                 // DDs which are valid for the WC's current CS state.
00220                 virtual uInt nelements();
00221 
00222                 // Force a cleanup of all the DisplayDatas which are registered with
00223                 // this WorldCanvasHolder.
00224                 virtual void cleanup();
00225 
00226                 // The DD in charge of setting WC coordinate state (0 if none).
00227                 const DisplayData* csMaster() const {
00228                         return itsWorldCanvas->csMaster( );
00229                 }
00230 
00231                 // Is the specified DisplayData the one in charge of WC state?
00232                 // (During DD::sizeControl() execution, it means instead that the
00233                 // DD has permission to become CSmaster, if it can).
00234                 Bool isCSmaster(const DisplayData *dd) const {
00235                         return itsWorldCanvas->isCSmaster(dd);
00236                 }
00237                 void clearCSMasterSettings( WorldCanvas* wCanvas, bool clearZoom = true );
00238 
00239                 // Was the passed DD the last CS master (or, if no DD passed, was
00240                 // there any CS master)?  For convenience of the DDs during the next
00241                 // sizeControl execution, in determining whether a CS master change is
00242                 // occurring, and whether anyone was master before.  This affects
00243                 // whether any old zoom window is retained or completely reset.
00244                 Bool wasCSmaster(DisplayData* dd=0) const {
00245                         return (dd==0)? itsLastCSmaster!=0 : itsLastCSmaster==dd;
00246                 }
00247 
00248                 // used by PanelDisplay on new WCHs to keep a consistent CS master on
00249                 // all its main display WC[H]s.  Sets [default] CS master dd to that of
00250                 // passed wch (if that dd is registered here), and gets it to reset WC
00251                 // coordinate state.
00252                 virtual Bool syncCSmaster(const WorldCanvasHolder* wch);
00253                 bool setCSMaster( DisplayData* dd );
00254 
00255                 const std::list<DisplayData*> &displaylist( ) const {
00256                         return itsDisplayList;
00257                 }
00258 
00263                 Float getDrawUnit() const;
00264 
00265                 const static String BLINK_MODE;
00266 
00267                 std::string errorMessage( ) const { return error_string; }
00268 
00269         private:
00270                 //True if the viewer is in blink mode.
00271                 bool blinkMode;
00272 
00273                 // The WorldCanvas that is held by this WorldCanvasHolder.
00274                 WorldCanvas *itsWorldCanvas;
00275 
00276                 // A list containing the DisplayDatas that are registered on this
00277                 // WorldCanvasHolder.
00278                 std::list<DisplayData*> itsDisplayList;
00279                 DisplayData* controllingDD;
00280 
00281                 // The CS master in effect after executeSizeControl was last run (0 if none).
00282                 // For determining (via wasCSmaster(), above) whether a CS master change is
00283                 // occurring, and whether anyone was master before.  This affects whether
00284                 // the old zoom window is retained or completely reset.
00285                 // (Note void*, rather than DD*, type: it is not intended to be dereferenced,
00286                 // just compared for equality.  The original DD may not even exist by the
00287                 // time it is used).
00288                 void* itsLastCSmaster;
00289                 Float drawUnit;
00290 
00291                 String getTitleDDName(const Vector<Bool>& conforms) const;
00292                 DisplayData* getTitleDDBlink( const Vector<Bool> & conforms ) const;
00293                 DisplayData* getTitleDDNormal( const Vector<Bool> & conforms ) const;
00294                 String getTitle( DisplayData* dd ) const;
00295                 void labelAxes( const Vector<Bool>& conforms, const WCRefreshEvent &ev);
00296                 void labelAxesBlink( const Vector<Bool>& conforms, const WCRefreshEvent & ev );
00297                 void labelAxesNormal( const Vector<Bool>& conforms, const WCRefreshEvent & ev );
00298                 void setControllingTitle( const Vector<Bool>& conforms );
00299                 void clearSubstituteTitles( );
00300                 Vector<Bool> getConformance() const;
00301                 std::string error_string;
00302         };
00303 
00304 } //# NAMESPACE CASA - END
00305 
00306 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1