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() { 00107 return itsRectangleExists; 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 rectangle's 00115 // appearance and action. When the rectangle 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 rectangle (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 rectangle 00132 // <group> 00133 virtual void doubleInside() { }; 00134 virtual void doubleOutside() { }; 00135 // </group> 00136 00137 // Called when a rectangle is ready and not being 00138 // edited. (Unused so far on the glish level (12/01)). 00139 virtual void rectangleReady() { }; 00140 00141 00142 // Retrieve the rectangle coordinates, in screen pixels. 00143 // Anchor (if applicable) is (x1,y1). Valid during the output callbacks; 00144 // to be used by them, as well as internally. 00145 virtual void get(Int &x1, Int &y1, Int &x2, Int &y2) const ; 00146 00147 private: 00148 00149 // set the pixel coordinates of the rectangle 00150 virtual void set(const Int &x1, const Int &y1, 00151 const Int &x2, const Int &y2); 00152 00153 // get only the anchor point 00154 virtual void get(Int &x1, Int &y1) const; 00155 00156 00157 // does the rectangle persist after double clicks (until a new one 00158 // is started)? 00159 Bool itsRectanglePersistent; 00160 00161 // do we have a rectangle yet? 00162 // (if True, itsCurrentWC, itsEmitted, P1, and P2 are valid) 00163 Bool itsRectangleExists; 00164 00165 // was the button pressed in the rectangle (or, if none, in an active WC) 00166 // and not yet released/reset? 00167 Bool itsActive; 00168 00169 // (valid only if itsActive==True): 00170 // True = being moved False = being resized 00171 Bool itsMoving; 00172 00173 // (valid only if itsRectangleExists==True) 00174 // Has doubleInside/Outside been called for this rectangle? If so, a 00175 // key press outside the rectangle will start a new rectangle, as if 00176 // itsRectangleExists were False. 00177 // However, a key press inside the rectangle will reset 00178 // itsEmitted to False, allowing the rectangle to be reused 00179 // (possibly moved or resized, and emitted again). 00180 Bool itsEmitted; 00181 00182 // (Linear) coordinates of the rectangle (invariant over zooms, but not 00183 // coordinate system changes. To do: support the WorldCoordinateChange 00184 // refresh reason, and reset this tool when it occurs). 00185 Vector<Double> itsP1, itsP2; 00186 00187 // storage of the handle (pixel) coordinates 00188 Vector<Int> itsHX, itsHY; 00189 00190 // position that move started from 00191 Int itsBaseMoveX, itsBaseMoveY; 00192 00193 // store the times of the last two presses here: 00194 Double itsLastPressTime, its2ndLastPressTime; 00195 00196 }; 00197 00198 00199 } //# NAMESPACE CASA - END 00200 00201 #endif 00202 00203