casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
WCRectTool.h
Go to the documentation of this file.
00001 //# WCRectTool.h: Base class for WorldCanvas event-based rectangle 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_WCRECTTOOL_H
00029 #define TRIALDISPLAY_WCRECTTOOL_H
00030 
00031 #include <casa/aips.h>
00032 #include <display/DisplayEvents/WCTool.h>
00033 #include <display/DisplayEvents/DTVisible.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // Base class for WorldCanvas event-based rectangle tools
00039 // </summary>
00040 //
00041 // <use visibility=export>
00042 //
00043 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00044 // </reviewed>
00045 //
00046 // <prerequisites>
00047 //   <li> WCTool
00048 // </prerequisites>
00049 //
00050 // <etymology>
00051 // WCRectTool stands for WorldCanvas Rectangle Tool
00052 // </etymology>
00053 //
00054 // <synopsis>
00055 // This class adds to its base WCTool to provide a tool for drawing,
00056 // resizing and moving rectangles on a WorldCanvas.  While WCRectTool
00057 // is not abstract, it performs no useful function.  The programmer
00058 // should derive from this class, and implement the functions
00059 // doubleInside and doubleOutside, which are called when the user
00060 // double-clicks the key or mouse button inside or outside an existing
00061 // rectangle respectively.  It is up to the programmer to decide what
00062 // double clicks inside and outside the rectangle correspond to,
00063 // although it is recommended that a double click inside correspond to
00064 // the main action of the tool, and a double click outside correspond
00065 // to a secondary action of the tool, if indeed a secondary action
00066 // exists.
00067 //
00068 // The rectangle is drawn by dragging the mouse from one corner to 
00069 // the diagonally opposite corner.  Once constructed, the rectangle
00070 // can be resized by dragging its corners, or relocated by dragging
00071 // inside the rectangle.  The rectangle is removed from the display 
00072 // when the Esc key is pressed.
00073 // </synopsis>
00074 //
00075 // <example>
00076 // </example>
00077 //
00078 // <motivation>
00079 // Many activities on the WorldCanvas will be based on the user drawing 
00080 // a rectangle, and then proceeding to some action with that rectangle.
00081 // A nice example is zooming.
00082 // </motivation>
00083 //
00084 // <todo asof="1999/07/23">
00085 //   <li> Add time constraint to double click detection
00086 // </todo>
00087 
00088 class WCRectTool : public WCTool, public DTVisible {
00089   
00090  public:
00091   
00092   // Constructor
00093   WCRectTool(WorldCanvas *wcanvas,
00094              Display::KeySym keysym = Display::K_Pointer_Button1,
00095              const Bool persistent = False);
00096   
00097   // Destructor
00098   virtual ~WCRectTool();
00099   
00100   // Switch the tool off - this calls the base class disable, and
00101   // then erases the rectangle if it's around
00102   virtual void disable();
00103 
00104   // Functions called by the local event handling operators -
00105   // these handle the drawing of the rectangle.  In special 
00106   // conditions, namely double clicking the key, they will
00107   // pass control on to the doubleInside and doubleOutside
00108   // functions
00109   // <group>
00110   virtual void keyPressed(const WCPositionEvent &ev);
00111   virtual void keyReleased(const WCPositionEvent &ev);
00112   virtual void otherKeyPressed(const WCPositionEvent &ev);
00113   virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
00114   virtual void refresh(const WCRefreshEvent &ev);
00115   // </group>
00116 
00117   // Functions special to the rectangle event handling - called when
00118   // there is a double click inside/outside the rectangle
00119   // <group>
00120   virtual void doubleInside() { };
00121   virtual void doubleOutside() { };
00122   // </group>
00123 
00124   // Functions called when a rectangle is ready and not being 
00125   // editted, and when this status changes
00126   // <group>
00127   virtual void rectangleReady() { };
00128   virtual void rectangleNotReady() { };
00129   // </group>
00130 
00131   // Retrieve the rectangle corners
00132   virtual void get(Int &x1, Int &y1, Int &x2, Int &y2) const ;
00133 
00134  private:
00135 
00136   // do the rectangles persist after double clicks?
00137   Bool itsRectanglePersistent;
00138 
00139   // is the rectangle on screen?
00140   Bool itsOnScreen;
00141   
00142   // are we actively zooming?
00143   Bool itsActive;
00144 
00145   // have we moved?
00146   Bool itsMoved;
00147 
00148   // do we have a rectangle drawn yet?
00149   Bool itsRectangleExists;
00150 
00151   // adjustment mode
00152   enum AdjustMode {
00153     Off, 
00154     Move
00155   };
00156   WCRectTool::AdjustMode itsAdjustMode;
00157 
00158   // coordinates of the rectangle: pixel and world
00159   // <group>
00160   Int itsX1, itsY1, itsX2, itsY2;
00161   Vector<Double> itsStoredWorldBlc, itsStoredWorldTrc;
00162   // </group>
00163 
00164   // set the coordinates of the rectangle
00165   // <group>
00166   virtual void set(const Int &x1, const Int &y1, const Int &x2, const Int &y2);
00167   // </group>
00168 
00169   // set/get only the anchor point
00170   // <group>
00171   virtual void set(const Int &x1, const Int &y1);
00172   virtual void get(Int &x1, Int &y1) const ;
00173   // </group>
00174 
00175   // preserve/restore the world coordinates
00176   // <group>
00177   virtual void preserve();
00178   virtual void restore();
00179   // </group>
00180 
00181   // draw the rubberband box on a PixelCanvas
00182   virtual void draw(const Bool drawHandles = False);
00183   
00184   // reset this drawer
00185   virtual void reset();
00186 
00187   // storage of the handle coordinates
00188   Vector<Int> itsHX, itsHY;
00189 
00190   // position that move started from
00191   Int itsBaseMoveX, itsBaseMoveY;
00192 
00193   // position of last press event
00194   Int itsLastPressX, itsLastPressY;
00195   Int its2ndLastPressX, its2ndLastPressY;
00196 
00197   // position of last release event
00198   Int itsLastReleaseX, itsLastReleaseY;
00199 
00200   // store the times of the last two presses here:
00201   Double itsLastPressTime, its2ndLastPressTime;
00202 
00203 };
00204 
00205 
00206 } //# NAMESPACE CASA - END
00207 
00208 #endif
00209 
00210