casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MultiWCTool.h
Go to the documentation of this file.
00001 //# MultiWCTool.h: base class for MultiWorldCanvas event-based tools
00002 //# Copyright (C) 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_MULTIWCTOOL_H
00029 #define TRIALDISPLAY_MULTIWCTOOL_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Containers/List.h>
00033 #include <display/DisplayEvents/WCPositionEH.h>
00034 #include <display/DisplayEvents/WCMotionEH.h>
00035 #include <display/DisplayEvents/WCRefreshEH.h>
00036 #include <display/DisplayEvents/DisplayTool.h>
00037 #include <display/region/Region.qo.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 class MultiWCTool;
00042 class WorldCanvas;
00043 class PixelCanvas;
00044 class PanelDisplay;
00045 
00046 // <summary>
00047 // Base class for MultiWorldCanvas event-based tools.
00048 // </summary>
00049 //
00050 // <use visibility=export>
00051 //
00052 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00053 // </reviewed>
00054 //
00055 // <prerequisites>
00056 //   <li> WCPositionEH
00057 //   <li> WCMotionEH
00058 //   <li> WCRefreshEH
00059 // </prerequisites>
00060 //
00061 // <etymology>
00062 // MultiWCTool stands for MultiWorldCanvas Tool
00063 // </etymology>
00064 //
00065 // <synopsis>
00066 // This class is a base class upon which tools which respond to 
00067 // various events on a WorldCanvas can be built.  It wraps up
00068 // the position, motion and refresh events so that the programmer
00069 // sees them all coming into one class, where they can be dealt
00070 // with in a unified manner.  MultiWCTool is not actually abstract,
00071 // so the programmer need only write handlers for the events in
00072 // which they are interested.
00073 // </synopsis>
00074 //
00075 // <example>
00076 // </example>
00077 //
00078 // <motivation>
00079 // The majority of tools written for the WorldCanvas will fall 
00080 // into the category that this class serves: they respond to a 
00081 // single key or mouse button, and they potentially need to 
00082 // respond to position, motion and refresh events.
00083 // </motivation>
00084 //
00085 // <todo asof="2000/07/12">
00086 //   <li> Nothing known
00087 // </todo>
00088 
00089 class MultiWCTool : public DisplayTool,
00090                     public WCPositionEH,
00091                     public WCMotionEH,
00092                     public WCRefreshEH {
00093   
00094  public:
00095   
00096   // Constructor taking the primary key to which this tool will
00097   // respond.
00098   MultiWCTool(const Display::KeySym &keysym = Display::K_Pointer_Button1, bool enable_events=true );
00099   
00100   // Destructor.
00101   virtual ~MultiWCTool();
00102 
00103   // Add/remove a WorldCanvas from the control of this tool.
00104   // <group>
00105   virtual void addWorldCanvas(WorldCanvas &worldcanvas);
00106   virtual void removeWorldCanvas(WorldCanvas &worldcanvas);
00107   // </group>
00108   
00109   // Add/Remove a list of WorldCanvases from PanelDisplay
00110   // <group>
00111   virtual void addWorldCanvases(PanelDisplay* pdisp);
00112   virtual void removeWorldCanvases(PanelDisplay* pdisp);
00113   // </group>
00114 
00115   // Switch the tool on/off - this simply registers or unregisters
00116   // the event handlers on the WorldCanvases.
00117   // <group>
00118   virtual void enable();
00119   virtual void disable();
00120   // </group>
00121   
00122   // Required operators for event handling - these are called when
00123   // events occur, and distribute the events to the "user-level"
00124   // methods
00125   // <group>
00126   virtual void operator()(const WCPositionEvent& ev);
00127   virtual void operator()(const WCMotionEvent& ev);
00128   virtual void operator()(const WCRefreshEvent& ev);
00129   // </group>
00130 
00131   // Derived classes should implement this to return to the non-showing,
00132   // non-active state.  It should not unregister the tool from WCs or
00133   // disable event handling.  If skipRefresh is false and the tool was showing,
00134   // it also calls refresh() to erase.  (The caller should set skipRefresh=True
00135   // (only) if it will handle refresh itself).
00136   virtual void reset(Bool /*skipRefresh*/=False) {  }
00137 
00138  protected:
00139 
00140   // Functions called by the local event handling operators -
00141   // by default they do nothing, so a derived class needs only
00142   // implement the events it cares about
00143   // <group>
00144   virtual void keyPressed(const WCPositionEvent &/*ev*/);
00145   virtual void keyReleased(const WCPositionEvent &/*ev*/);
00146   virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
00147   virtual void otherKeyReleased(const WCPositionEvent &/*ev*/);
00148   virtual void moved(const WCMotionEvent & /*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00149   virtual void updateRegion() {}
00150   virtual void clicked(Int /*x*/, Int /*y*/) {}
00151   virtual void doubleClicked(Int /*x*/, Int /*y*/) {}
00152   // </group>
00153 
00154   // Draw whatever should be drawn (if anything) on current WC.
00155   // Should only be called by refresh event handler.
00156   virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00157 
00158   // Copy back-to-front buffer (erasing all MWCTool drawings),
00159   // then cause this (and all MWCTools on current WC's PC)
00160   // to draw (or not draw) themselves, according to their
00161   // current state.  Mouse and kbd event handlers within the tools
00162   // now call this in response to drawing state changes, rather than
00163   // calling draw() directly, so that only valid tool drawings are
00164   // displayed, even when more than one is active.  NB: the meaning of
00165   // this routine has changed to be more in line with the rest of the DL
00166   // (i.e., it now causes, rather than responds to, refresh events).
00167   virtual void refresh();
00168 
00169   // An iterator for the WorldCanvases.
00170   mutable ListIter<WorldCanvas *> *itsWCListIter;
00171 
00172   // Cause subsequent drawing commands to be clipped to the current WC
00173   // (or its drawing area).  Be sure to reset when finished drawing; 
00174   // clipping will apply to drawing on entire PC.
00175   // <group>
00176   virtual void setClipToDrawArea();
00177   virtual void setClipToWC();
00178   virtual void resetClip();
00179   // </group>
00180 
00181   // WC being (or to be) drawn on (may be 0 initially).  WC where latest
00182   // relevant input event was received.
00183   WorldCanvas *itsCurrentWC;
00184 
00185  private:
00186 
00187   // copy, default constructors (do not use)
00188   // <group>
00189   MultiWCTool();
00190   MultiWCTool(const MultiWCTool &other);
00191   MultiWCTool &operator=(const MultiWCTool &other);  
00192   // </group>
00193 
00194   // The WorldCanvases to which this tool is connected.
00195   List<WorldCanvas *> itsWCList;
00196 
00197   // whether the event handlers are registered
00198   Bool itsEventHandlersRegistered;
00199 
00200 };
00201 
00202 
00203 } //# NAMESPACE CASA - END
00204 
00205 #endif