casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WCTool.h
Go to the documentation of this file.
00001 //# WCTool.h: base class for WorldCanvas event-based tools
00002 //# Copyright (C) 1999,2000
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_WCTOOL_H
00029 #define TRIALDISPLAY_WCTOOL_H
00030 
00031 #include <casa/aips.h>
00032 #include <display/DisplayEvents/WCPositionEH.h>
00033 #include <display/DisplayEvents/WCMotionEH.h>
00034 #include <display/DisplayEvents/WCRefreshEH.h>
00035 #include <display/DisplayEvents/DisplayTool.h>
00036 #include <display/region/Region.qo.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 class WCTool;
00041 class WorldCanvas;
00042 class PixelCanvas;
00043 
00044 // <summary>
00045 // WorldCanvas position event handler for WCTool.
00046 // </summary>
00047 //
00048 // <synopsis>
00049 // This class is a simple implementation of a WCPositionEH which 
00050 // passes WorldCanvas position events on to a single WCTool.
00051 // </synopsis>
00052 
00053 class WCToolPosEH : public WCPositionEH {
00054  public:
00055   WCToolPosEH(WCTool *tool);
00056   virtual ~WCToolPosEH(){};
00057   virtual void operator()(const WCPositionEvent& ev);
00058  private:
00059   WCTool *itsTool;
00060 };
00061 
00062 // <summary>
00063 // WorldCanvas motion event handler for WCTool.
00064 // </summary>
00065 //
00066 // <synopsis>
00067 // This class is a simple implementation of a WCMotionEH which 
00068 // passes WorldCanvas motion events on to a single WCTool.
00069 // </synopsis>
00070 
00071 class WCToolMotEH : public WCMotionEH {
00072  public:
00073   WCToolMotEH(WCTool *tool);
00074   virtual ~WCToolMotEH(){};
00075   virtual void operator()(const WCMotionEvent& ev);
00076  private:
00077   WCTool *itsTool;
00078 };
00079 
00080 // <summary>
00081 // WorldCanvas refresh event handler for WCTool.
00082 // </summary>
00083 //
00084 // <synopsis>
00085 // This class is a simple implementation of a WCRefreshEH which 
00086 // passes WorldCanvas refresh events on to a single WCTool.
00087 // </synopsis>
00088 
00089 class WCToolRefEH : public WCRefreshEH {
00090  public:
00091   WCToolRefEH(WCTool *tool);
00092   virtual ~WCToolRefEH(){};
00093   virtual void operator()(const WCRefreshEvent& ev);
00094  private:
00095   WCTool *itsTool;
00096 };
00097 
00098 // <summary>
00099 // Base class for WorldCanvas event-based tools.
00100 // </summary>
00101 
00102 // <use visibility=export>
00103 
00104 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00105 // </reviewed>
00106 
00107 // <prerequisites>
00108 //   <li> WCPositionEH
00109 //   <li> WCMotionEH
00110 //   <li> WCRefreshEH
00111 // </prerequisites>
00112 
00113 // <etymology>
00114 // WCTool stands for WorldCanvas Tool
00115 // </etymology>
00116 
00117 // <synopsis>
00118 // This class is a base class upon which tools which respond to 
00119 // various events on a WorldCanvas can be built.  It wraps up
00120 // the position, motion and refresh events so that the programmer
00121 // sees them all coming into one class, where they can be dealt
00122 // with in a unified manner.  WCTool is not actually abstract,
00123 // so the programmer need only write handlers for the events in
00124 // which they are interested.
00125 // </synopsis>
00126 
00127 // <example>
00128 // </example>
00129 
00130 // <motivation>
00131 // The majority of tools written for the WorldCanvas will fall 
00132 // into the category that this class serves: they respond to a 
00133 // single key or mouse button, and they potentially need to 
00134 // respond to position, motion and refresh events.
00135 // </motivation>
00136 
00137 // <todo asof="1999/10/18">
00138 //   <li> Nothing known
00139 // </todo>
00140 
00141 class WCTool : public DisplayTool {
00142   
00143  public:
00144   
00145   // Constructor taking a pointer to a WorldCanvas to which this tool
00146   // will attach, and a primary key to respond to.
00147   WCTool(WorldCanvas *wcanvas,
00148          const Display::KeySym &keysym = Display::K_Pointer_Button1);
00149   
00150   // Destructor.
00151   virtual ~WCTool();
00152   
00153   // Switch the tool on/off - this simply registers or unregisters
00154   // the event handlers
00155   // <group>
00156   virtual void enable();
00157   virtual void disable();
00158   // </group>
00159   
00160   // Required operators for event handling - these are called when
00161   // an events occur, and distribute the events to the "user-level"
00162   // methods
00163   // <group>
00164   virtual void operator()(const WCPositionEvent& ev);
00165   virtual void operator()(const WCMotionEvent& ev);
00166   virtual void operator()(const WCRefreshEvent& ev);
00167   // </group>
00168 
00169   // Functions called by the local event handling operators -
00170   // by default they do nothing, so a derived class needs only
00171   // implement the events it cares about
00172   // <group>
00173   virtual void keyPressed(const WCPositionEvent &/*ev*/);
00174   virtual void keyReleased(const WCPositionEvent &/*ev*/);
00175   virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
00176   virtual void otherKeyReleased(const WCPositionEvent &/*ev*/);
00177   virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00178   virtual void refresh(const WCRefreshEvent &/*ev*/);
00179   // </group>
00180 
00181   // Get the WorldCanvas that this Tool is attached to
00182   virtual WorldCanvas *worldCanvas() const 
00183     { return itsWorldCanvas; }
00184 
00185   // Get the PixelCanvas that this Tool is attached to via its WorldCanvas
00186   virtual PixelCanvas *pixelCanvas() const
00187     { return itsPixelCanvas; }
00188 
00189  protected:
00190 
00191   // (Required) default constructor.
00192   WCTool();
00193 
00194   // (Required) copy constructor.
00195   WCTool(const WCTool &other);
00196 
00197   // (Required) copy assignment.
00198   WCTool &operator=(const WCTool &other);  
00199 
00200  private:
00201 
00202   // The WorldCanvas to which this is connected
00203   WorldCanvas *itsWorldCanvas;
00204 
00205   // The PixelCanvas to which this is connected via the WorldCanvas
00206   PixelCanvas *itsPixelCanvas;
00207 
00208   // whether the event handlers are registered
00209   Bool itsEventHandlersRegistered;
00210 
00211   // event handlers:
00212   WCToolPosEH *itsPositionEH;
00213   WCToolMotEH *itsMotionEH;
00214   WCToolRefEH *itsRefreshEH;
00215 
00216 };
00217 
00218 
00219 } //# NAMESPACE CASA - END
00220 
00221 #endif
00222 
00223