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() { 00107 return itsEllipseExists; 00108 } 00109 00110 00111 protected: 00112 00113 // Functions called by the base class event handling operators--and 00114 // normally only those. This is the input that controls the ellipse's 00115 // appearance and action. When the ellipse is ready and double-click 00116 // is received, the doubleInside/Outside routine will be invoked. 00117 // <group> 00118 virtual void keyPressed(const WCPositionEvent &ev); 00119 virtual void keyReleased(const WCPositionEvent &ev); 00120 virtual void otherKeyPressed(const WCPositionEvent &ev); 00121 virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/); 00122 // </group> 00123 00124 // draw the ellipse (if any) on the object's currently active WC. 00125 // Only to be called by the base class refresh event handler. Derived 00126 // objects should use refresh() if they need to redraw, but even that 00127 // is normally handled automatically. 00128 virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/); 00129 00130 // Output callback functions--to be overridden in derived class. 00131 // Called when there is a double click inside/outside the ellipse 00132 // <group> 00133 virtual void doubleInside() { }; 00134 virtual void doubleOutside() { }; 00135 // </group> 00136 00137 // Called when a ellipse is ready and not being 00138 // edited. (Unused so far on the glish level (12/01)). 00139 virtual void ellipseReady() { }; 00140 //virtual void rectangleReady() { }; 00141 00142 00143 // Retrieve the ellipse coordinates, in screen pixels. 00144 // Anchor (if applicable) is (x1,y1). Valid during the output callbacks; 00145 // to be used by them, as well as internally. 00146 virtual void get(Int &x1, Int &y1, Int &x2, Int &y2) const ; 00147 00148 private: 00149 00150 // set the pixel coordinates of the ellipse 00151 virtual void set(const Int &x1, const Int &y1, 00152 const Int &x2, const Int &y2); 00153 00154 // get only the anchor point 00155 virtual void get(Int &x1, Int &y1) const; 00156 00157 00158 // does the ellipse persist after double clicks (until a new one 00159 // is started)? 00160 Bool itsEllipsePersistent; 00161 //Bool itsRectanglePersistent; 00162 00163 // do we have a ellipse yet? 00164 // (if True, itsCurrentWC, itsEmitted, P1, and P2 are valid) 00165 Bool itsEllipseExists; 00166 //Bool itsRectangleExists; 00167 00168 // was the button pressed in the ellipse (or, if none, in an active WC) 00169 // and not yet released/reset? 00170 Bool itsActive; 00171 00172 // (valid only if itsActive==True): 00173 // True = being moved False = being resized 00174 Bool itsMoving; 00175 00176 // (valid only if itsEllipseExists==True) 00177 // Has doubleInside/Outside been called for this ellipse? If so, a 00178 // key press outside the ellipse will start a new ellipse, as if 00179 // itsEllipseExists were False. 00180 // However, a key press inside the ellipse will reset 00181 // itsEmitted to False, allowing the ellipse to be reused 00182 // (possibly moved or resized, and emitted again). 00183 Bool itsEmitted; 00184 00185 // (Linear) coordinates of the ellipse (invariant over zooms, but not 00186 // coordinate system changes. To do: support the WorldCoordinateChange 00187 // refresh reason, and reset this tool when it occurs). 00188 Vector<Double> itsP1, itsP2; 00189 00190 // storage of the handle (pixel) coordinates 00191 Vector<Int> itsHX, itsHY; 00192 00193 // position that move started from 00194 Int itsBaseMoveX, itsBaseMoveY; 00195 00196 // store the times of the last two presses here: 00197 Double itsLastPressTime, its2ndLastPressTime; 00198 00199 }; 00200 00201 00202 } //# NAMESPACE CASA - END 00203 00204 #endif 00205 00206