casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MWCEllipseTool.h
Go to the documentation of this file.
00001 //# MWCEllipseTool.h: Base class for MultiWorldCanvas event-based ellipse 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_MWCELLIPSETOOL_H
00029 #define TRIALDISPLAY_MWCELLIPSETOOL_H
00030 
00031 #include <casa/aips.h>
00032 #include <display/DisplayEvents/MultiWCTool.h>
00033 #include <display/DisplayEvents/DTVisible.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // Base class for MultiWorldCanvas event-based ellipse 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 // MWCEllipseTool stands for MultiWorldCanvas Ellipse Tool
00052 // </etymology>
00053 //
00054 // <synopsis>
00055 // This class adds to its base WCTool to provide a tool for drawing,
00056 // resizing and moving ellipses on a WorldCanvas.  While MWCEllipseTool
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 // ellipse respectively.  It is up to the programmer to decide what
00062 // double clicks inside and outside the ellipse 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 ellipse is drawn by dragging the mouse from one corner to
00069 // the diagonally opposite corner.  Once constructed, the ellipse
00070 // can be resized by dragging its corners, or relocated by dragging
00071 // inside the ellipse.  The ellipse 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 ellipse, and then proceeding to some action with that ellipse.
00081 // </motivation>
00082 
00083 class MWCEllipseTool : public MultiWCTool, public DTVisible {
00084   
00085  public:
00086   
00087   // Constructor
00088   MWCEllipseTool(Display::KeySym keysym = Display::K_Pointer_Button1,
00089               const Bool persistent = False);
00090   
00091   // Destructor
00092   virtual ~MWCEllipseTool();
00093   
00094   // Switch the tool off - this erases the ellipse, if any,
00095   // and calls the base class disable.
00096   virtual void disable();
00097 
00098   // reset to non-existent, non-active ellipse.
00099   // Refreshes if necessary to erase (unless skipRefresh==True  In
00100   // that case, the caller should do the refresh itself).
00101   // (Does not unregister from WCs or disable future event handling).
00102   virtual void reset(Bool skipRefresh=False);
00103   
00104   // Is a ellipse currently defined?
00105   //virtual Bool rectangleDefined() { return itsRectangleExists;  }
00106   virtual Bool ellipseDefined() { return itsEllipseExists;  }
00107   
00108  
00109  protected:
00110 
00111   // Functions called by the base class event handling operators--and
00112   // normally only those.  This is the input that controls the ellipse's
00113   // appearance and action.  When the ellipse is ready and double-click
00114   // is received, the doubleInside/Outside routine will be invoked.
00115   // <group>
00116   virtual void keyPressed(const WCPositionEvent &ev);
00117   virtual void keyReleased(const WCPositionEvent &ev);
00118   virtual void otherKeyPressed(const WCPositionEvent &ev);
00119   virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00120   // </group>
00121 
00122   // draw the ellipse (if any) on the object's currently active WC.
00123   // Only to be called by the base class refresh event handler.  Derived
00124   // objects should use refresh() if they need to redraw, but even that
00125   // is normally handled automatically.
00126   virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00127 
00128   // Output callback functions--to be overridden in derived class.
00129   // Called when there is a double click inside/outside the ellipse
00130   // <group>
00131   virtual void doubleInside() { };
00132   virtual void doubleOutside() { };
00133   // </group>
00134 
00135   // Called when a ellipse is ready and not being
00136   // edited.  (Unused so far on the glish level (12/01)).
00137   virtual void ellipseReady() { };
00138   //virtual void rectangleReady() { };
00139 
00140 
00141   // Retrieve the ellipse coordinates, in screen pixels.
00142   // Anchor (if applicable) is (x1,y1).  Valid during the output callbacks;
00143   // to be used by them, as well as internally.
00144   virtual void get(Int &x1, Int &y1, Int &x2, Int &y2) const ;
00145 
00146  private:
00147 
00148   // set the pixel coordinates of the ellipse
00149   virtual void set(const Int &x1, const Int &y1,
00150                    const Int &x2, const Int &y2);
00151 
00152   // get only the anchor point
00153   virtual void get(Int &x1, Int &y1) const;
00154 
00155 
00156   // does the ellipse persist after double clicks (until a new one
00157   // is started)?
00158   Bool itsEllipsePersistent;
00159   //Bool itsRectanglePersistent;
00160 
00161   // do we have a ellipse yet?
00162   // (if True, itsCurrentWC, itsEmitted, P1, and P2 are valid)
00163   Bool itsEllipseExists;
00164   //Bool itsRectangleExists;
00165 
00166   // was the button pressed in the ellipse (or, if none, in an active WC)
00167   // and not yet released/reset?
00168   Bool itsActive;
00169 
00170   // (valid only if itsActive==True):
00171   // True = being moved     False = being resized
00172   Bool itsMoving;
00173 
00174   // (valid only if itsEllipseExists==True)
00175   // Has doubleInside/Outside been called for this ellipse?  If so, a
00176   // key press outside the ellipse will start a new ellipse, as if
00177   // itsEllipseExists were False.
00178   // However, a key press inside the ellipse will reset
00179   // itsEmitted to False, allowing the ellipse to be reused
00180   // (possibly moved or resized, and emitted again).
00181   Bool itsEmitted;
00182 
00183   // (Linear) coordinates of the ellipse (invariant over zooms, but not
00184   // coordinate system changes.  To do: support the WorldCoordinateChange
00185   // refresh reason, and reset this tool when it occurs).
00186   Vector<Double> itsP1, itsP2;
00187 
00188   // storage of the handle (pixel) coordinates
00189   Vector<Int> itsHX, itsHY;
00190 
00191   // position that move started from
00192   Int itsBaseMoveX, itsBaseMoveY;
00193 
00194   // store the times of the last two presses here:
00195   Double itsLastPressTime, its2ndLastPressTime;
00196 
00197 };
00198 
00199 
00200 } //# NAMESPACE CASA - END
00201 
00202 #endif
00203 
00204