casa
$Rev:20696$
|
00001 //# WCCrosshairTool.h: Base class for WorldCanvas event-based crosshair 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_WCCROSSHAIRTOOL_H 00029 #define TRIALDISPLAY_WCCROSSHAIRTOOL_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 crosshair 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 // WCCrosshairTool stands for WorldCanvas Crosshair Tool. 00052 // </etymology> 00053 // 00054 // <synopsis> 00055 // This class adds to its base WCTool to provide a tool for placing 00056 // and moving a crosshair on a WorldCanvas. While WCCrosshairTool is 00057 // not abstract, it performs no useful function. The programmer 00058 // should derive from this class, and override the functions 00059 // doubleInside and doubleOutside, which are called when the user 00060 // double-clicks the key or mouse button inside or outside the 00061 // existing crosshair respectively. It is up to the programmer to 00062 // decide what double clicks inside and outside the crosshair 00063 // correspond to, although it is recommended that a double click 00064 // inside correspond to the main action of the tool (eg. emitting the 00065 // current position to an outside controller), and a double click 00066 // outside correspond to a secondary action of the tool, if indeed a 00067 // secondary action exists. 00068 // 00069 // The crosshair is drawn by simply clicking at the location the 00070 // crosshair should be placed. Once constructed, the crosshair can be 00071 // relocated by dragging inside the crosshair. The crosshair is 00072 // removed from the display 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 placing 00080 // a crosshair, and then proceeding to some action with that crosshair. 00081 // A nice example is emitting positions to be caught by some external 00082 // controlling process. 00083 // </motivation> 00084 // 00085 // <todo asof="1999/11/26"> 00086 // </todo> 00087 00088 class WCCrosshairTool : public WCTool, public DTVisible { 00089 00090 public: 00091 00092 // Constructor requires a WorldCanvas to operate on, and optional 00093 // specifications of the key to respond to, and whether the 00094 // crosshair should be persistent. A persistent crosshair will 00095 // "stick around" after a double click action. 00096 WCCrosshairTool(WorldCanvas *wcanvas, 00097 Display::KeySym keysym = Display::K_Pointer_Button1, 00098 const Bool persistent = True); 00099 00100 // Destructor. 00101 virtual ~WCCrosshairTool(); 00102 00103 // Switch the tool off: this calls the base class disable, and then 00104 // erases the crosshair if necessary. 00105 virtual void disable(); 00106 00107 // Functions called by the local event handling operators - these 00108 // handle the drawing of the crosshair. In special conditions, 00109 // namely double clicking the key, they will pass control on to the 00110 // doubleInside and doubleOutside functions. 00111 // <group> 00112 virtual void keyPressed(const WCPositionEvent &/*ev*/); 00113 virtual void keyReleased(const WCPositionEvent &/*ev*/); 00114 virtual void otherKeyPressed(const WCPositionEvent &/*ev*/); 00115 virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/); 00116 virtual void refresh(const WCRefreshEvent &/*ev*/); 00117 // </group> 00118 00119 // Functions special to the crosshair event handling: called when 00120 // there is a double click inside or outside the crosshair. 00121 // <group> 00122 virtual void doubleInside() { }; 00123 virtual void doubleOutside() { }; 00124 // </group> 00125 00126 // Functions called when the crosshair is ready and not being 00127 // editted, and when this status changes. 00128 // <group> 00129 virtual void crosshairReady() { }; 00130 virtual void crosshairNotReady() { }; 00131 // </group> 00132 00133 // Retrieve the crosshair position. 00134 virtual void get(Int &x1, Int &y1) const ; 00135 00136 private: 00137 00138 // does the crosshair persist after double clicks? 00139 Bool itsCrosshairPersistent; 00140 00141 // what radius is the crosshair? in pixels 00142 Int itsCrosshairRadius; 00143 00144 // is the crosshair on screen? 00145 Bool itsOnScreen; 00146 00147 // is some activity taking place with the crosshair? 00148 Bool itsActive; 00149 00150 // has the crosshair been moved? 00151 Bool itsMoved; 00152 00153 // do we have a crosshair drawn yet? 00154 Bool itsCrosshairExists; 00155 00156 // adjustment mode 00157 enum AdjustMode { 00158 Off, 00159 Move 00160 }; 00161 WCCrosshairTool::AdjustMode itsAdjustMode; 00162 00163 // coordinates of the crosshair: pixel and world 00164 // <group> 00165 Int itsX1, itsY1; 00166 Vector<Double> itsStoredWorldPosition; 00167 // </group> 00168 00169 // set the coordinates of the crosshair 00170 // <group> 00171 virtual void set(const Int &x1, const Int &y1); 00172 // </group> 00173 00174 // set/get only the anchor point 00175 // <group> 00176 //virtual void set(const Int &x1, const Int &y1); 00177 //virtual void get(Int &x1, Int &y1) const ; 00178 // </group> 00179 00180 // preserve/restore the world coordinates 00181 // <group> 00182 virtual void preserve(); 00183 virtual void restore(); 00184 // </group> 00185 00186 // draw the crosshair on the WorldCanvas' PixelCanvas. 00187 virtual void draw(const Bool drawHandles = False); 00188 00189 // reset this drawer 00190 virtual void reset(); 00191 00192 // position that move started from 00193 Int itsBaseMoveX, itsBaseMoveY; 00194 00195 // position of last press event 00196 Int itsLastPressX, itsLastPressY; 00197 Int its2ndLastPressX, its2ndLastPressY; 00198 00199 // position of last release event 00200 Int itsLastReleaseX, itsLastReleaseY; 00201 00202 // store the times of the last two presses here: 00203 Double itsLastPressTime, its2ndLastPressTime; 00204 00205 }; 00206 00207 00208 } //# NAMESPACE CASA - END 00209 00210 #endif 00211 00212