casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MWCCrosshairTool.h
Go to the documentation of this file.
00001 //# MWCCrosshairTool.h: Base class for WorldCanvas event-based crosshair tools
00002 //# Copyright (C) 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 
00027 #ifndef TRIALDISPLAY_MWCCROSSHAIRTOOL_H
00028 #define TRIALDISPLAY_MWCCROSSHAIRTOOL_H
00029 
00030 #include <casa/aips.h>
00031 #include <display/DisplayEvents/MultiWCTool.h>
00032 #include <display/DisplayEvents/DTVisible.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 class WorldCanvas;
00037 
00038 // <summary>
00039 // Base class for MultiWorldCanvas event-based crosshair tools.
00040 // </summary>
00041 //
00042 // <use visibility=export>
00043 //
00044 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00045 // </reviewed>
00046 //
00047 // <prerequisites>
00048 //   <li> WCTool
00049 // </prerequisites>
00050 //
00051 // <etymology>
00052 // MWCCrosshairTool stands for MultiWorldCanvas Crosshair Tool.
00053 // </etymology>
00054 //
00055 // <synopsis> 
00056 // This class adds to its base MWCTool to provide a tool for placing
00057 // and moving a crosshair on a WorldCanvas.  While MWCCrosshairTool is
00058 // not abstract, it performs no useful function.  The programmer
00059 // should derive from this class, and override the crosshairReady function,
00060 // which is called when the mouse button is pressed, moved, or released
00061 // within a WC draw area where events are handled.  The get() function then
00062 // retrieves the crosshair position in screen pixels.
00063 //
00064 // The crosshair will track the mouse as long as it is within the WC draw
00065 // area and the button is pressed.
00066 // The persistent parameter determines whether the crosshair remains visible
00067 // once the button is released.
00068 // The crosshair is removed when it is dragged off the draw area or the
00069 // Esc key is pressed within the WC.
00070 // </synopsis>
00071 //
00072 // <example>
00073 // </example>
00074 //
00075 // <motivation>
00076 // Many activities on the WorldCanvas will be based on the user causing
00077 // some action by placing or moving a crosshair.
00078 // Emitted positions are to be caught by some external process or method.
00079 // </motivation>
00080 //
00081 // <todo asof="1999/11/26">
00082 // </todo>
00083 
00084 class MWCCrosshairTool : public MultiWCTool, public DTVisible {
00085   
00086  public:
00087   
00088   // Constructor specifies the button to respond to, and whether the 
00089   // crosshair should remain on screen after the button is released.
00090   // Base class methods must also be called to register event handling
00091   // for the desired WorldCanvas[es].
00092   MWCCrosshairTool(Display::KeySym keysym = Display::K_Pointer_Button1,
00093                    const Bool persistent = True);
00094   
00095   // Destructor.
00096   virtual ~MWCCrosshairTool();
00097   
00098   // Retrieve the crosshair position in pixels.  A derived crosshairReady()
00099   // routine would use this.
00100   virtual void get(Int &x, Int &y) const ;
00101 
00102   //Rectrive the crosshair position in Lin
00103   virtual void getLin(Double &x, Double &y) const;
00104 
00105   //Rectrive the crosshair position in World
00106   virtual void getWorld(Double &x, Double &y) const;
00107 
00108   // Switch the tool off: this calls the base class disable to turn off
00109   // event handling, and then erases the crosshair if necessary.
00110   virtual void disable();
00111 
00112   // set crosshair cursor type
00113   virtual void setCross(Bool cross=False);
00114 
00115   // Reset to non-showing, non-active crosshair.
00116   // Refreshes if necessary to erase (unless skipRefresh==True).
00117   // (Does not unregister from WCs or disable future event handling).
00118   virtual void reset(Bool skipRefresh=False);
00119 
00120   // handle events, via new-style interface.  Currently just for reset event.
00121   virtual void handleEvent(DisplayEvent& ev);
00122 
00123 
00124  protected:
00125 
00126   // Functions called by the base class mouse/kbd event handling operators--
00127   // and normally only those.  This is the input that controls the crosshair's
00128   // action.  When the crosshair is ready (positioned on the draw area)
00129   // the crosshairReady() routine is called.
00130   // <group>
00131   virtual void keyPressed(const WCPositionEvent &/*ev*/);
00132   virtual void keyReleased(const WCPositionEvent &/*ev*/);
00133   virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
00134   virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00135   // </group>
00136 
00137   // draw the crosshair on the object's currently active WC.
00138   // Only to be called by the base class refresh event handler.  Derived
00139   // objects should use refresh() if they need to redraw, but even that
00140   // is normally handled automatically.
00141   virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00142 
00143   // Called when the crosshair position has been chosen.  Override to
00144   // handle the crosshair-position-ready 'event'.
00145   // evtype is "down" "move" or "up" depending on the state of the
00146   // mouse leading to this event.
00147   virtual void crosshairReady(const String& ) { };
00148 
00149  private:
00150 
00151   // Set the current position from pixel coordinates.
00152   // To do: reset the tool when the WC CS (linToWorld) transformation
00153   // changes.  (There is a WorldCoordinateChange RefreshReason, but it is
00154   // not currently used when WC CS/Coordinatehandlers are set/changed).
00155   virtual void set(Int x, Int y);
00156 
00157   // the last crosshair position.
00158   // (zooms will change pixel but not linear coordinates; therefore this
00159   // position is stored in the latter).
00160   Vector<Double> itsPos;
00161   Vector<Double> itsWorld;
00162 
00163   // should the crosshair remain visible after its button is released?
00164   Bool itsPersist;
00165 
00166   // what is the crosshair radius? (screen pixels)
00167   Int itsRadius;
00168 
00169   // was the crosshair drawing visible after last refresh cycle?
00170   Bool itsShowing;
00171   
00172   // should the crosshair be drawn when X,Y are in the zoom window?
00173   Bool itsShow;
00174 
00175   // draw crosshair 
00176   Bool itsCross; 
00177 
00178   // is the crosshair's button down?  (True when the
00179   // tool's button was pressed in a WC where it is handling events,
00180   // and has not yet been released, or the tool reset).
00181   Bool itsBtnDn;
00182 
00183 };
00184 
00185 
00186 } //# NAMESPACE CASA - END
00187 
00188 #endif
00189 
00190