casa
$Rev:20696$
|
00001 //# MWCRectTool.h: Base class for MultiWorldCanvas event-based rectangle 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_MWCRECTTOOL_H 00029 #define TRIALDISPLAY_MWCRECTTOOL_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 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 // MWCRectTool stands for MultiWorldCanvas 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 MWCRectTool 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 class MWCRectTool : public MultiWCTool, public DTVisible { 00085 00086 public: 00087 00088 // Constructor 00089 MWCRectTool(Display::KeySym keysym = Display::K_Pointer_Button1, 00090 const Bool persistent = False); 00091 00092 // Destructor 00093 virtual ~MWCRectTool(); 00094 00095 // Switch the tool off - this erases the rectangle, if any, 00096 // and calls the base class disable. 00097 virtual void disable(); 00098 00099 // reset to non-existent, non-active rectangle. 00100 // Refreshes if necessary to erase (unless skipRefresh==True In 00101 // that case, the caller should do the refresh itself). 00102 // (Does not unregister from WCs or disable future event handling). 00103 virtual void reset(Bool skipRefresh=False); 00104 00105 // Is a rectangle currently defined? 00106 virtual Bool rectangleDefined() { return itsRectangleExists; } 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 rectangle's 00113 // appearance and action. When the rectangle 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 rectangle (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 rectangle 00130 // <group> 00131 virtual void doubleInside() { }; 00132 virtual void doubleOutside() { }; 00133 // </group> 00134 00135 // Called when a rectangle is ready and not being 00136 // edited. (Unused so far on the glish level (12/01)). 00137 virtual void rectangleReady() { }; 00138 00139 00140 // Retrieve the rectangle coordinates, in screen pixels. 00141 // Anchor (if applicable) is (x1,y1). Valid during the output callbacks; 00142 // to be used by them, as well as internally. 00143 virtual void get(Int &x1, Int &y1, Int &x2, Int &y2) const ; 00144 00145 private: 00146 00147 // set the pixel coordinates of the rectangle 00148 virtual void set(const Int &x1, const Int &y1, 00149 const Int &x2, const Int &y2); 00150 00151 // get only the anchor point 00152 virtual void get(Int &x1, Int &y1) const; 00153 00154 00155 // does the rectangle persist after double clicks (until a new one 00156 // is started)? 00157 Bool itsRectanglePersistent; 00158 00159 // do we have a rectangle yet? 00160 // (if True, itsCurrentWC, itsEmitted, P1, and P2 are valid) 00161 Bool itsRectangleExists; 00162 00163 // was the button pressed in the rectangle (or, if none, in an active WC) 00164 // and not yet released/reset? 00165 Bool itsActive; 00166 00167 // (valid only if itsActive==True): 00168 // True = being moved False = being resized 00169 Bool itsMoving; 00170 00171 // (valid only if itsRectangleExists==True) 00172 // Has doubleInside/Outside been called for this rectangle? If so, a 00173 // key press outside the rectangle will start a new rectangle, as if 00174 // itsRectangleExists were False. 00175 // However, a key press inside the rectangle will reset 00176 // itsEmitted to False, allowing the rectangle to be reused 00177 // (possibly moved or resized, and emitted again). 00178 Bool itsEmitted; 00179 00180 // (Linear) coordinates of the rectangle (invariant over zooms, but not 00181 // coordinate system changes. To do: support the WorldCoordinateChange 00182 // refresh reason, and reset this tool when it occurs). 00183 Vector<Double> itsP1, itsP2; 00184 00185 // storage of the handle (pixel) coordinates 00186 Vector<Int> itsHX, itsHY; 00187 00188 // position that move started from 00189 Int itsBaseMoveX, itsBaseMoveY; 00190 00191 // store the times of the last two presses here: 00192 Double itsLastPressTime, its2ndLastPressTime; 00193 00194 }; 00195 00196 00197 } //# NAMESPACE CASA - END 00198 00199 #endif 00200 00201