casa
$Rev:20696$
|
00001 //# WCPolyTool.h: Base class for WorldCanvas event-based polygon 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_WCPOLYTOOL_H 00029 #define TRIALDISPLAY_WCPOLYTOOL_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 polygon 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><linkto>WCTool</linkto> 00048 // </prerequisites> 00049 // 00050 // <etymology> 00051 // WCPolyTool stands for WorldCanvas Polygon Tool 00052 // </etymology> 00053 // 00054 // <synopsis> 00055 // This class adds to its base WCTool to provide a tool for drawing, 00056 // reshaping and moving polygons on a WorldCanvas. While WCPolyTool 00057 // is not abstract, it performs no useful function. The programmer 00058 // should derive from this class and override the functions doubleInside 00059 // and doubleOutside at the very least. These are called when the user 00060 // double-clicks a particular key or mouse button inside or outside an 00061 // existing polygon respectively. It is up to the programmer to decide 00062 // what these events mean, but it is recommended that an internal double- 00063 // click correspond to the main action of the tool, eg. emitting the 00064 // polygon vertices to the application, and that an external double-click 00065 // correspond to a secondary action of the tool, if indeed there are 00066 // additional actions suitable to the tool. 00067 // 00068 // The polygon is drawn by clicking at each of the vertices, and 00069 // clicking on the last or first vertices to complete the polygon. 00070 // Once drawn, the vertices can be moved by dragging their handles, 00071 // and the entire polygon relocated by dragging inside the polygon. 00072 // The polygon is removed from the display when the Esc key is 00073 // pressed. 00074 // </synopsis> 00075 // 00076 // <example> 00077 // </example> 00078 // 00079 // <motivation> 00080 // Many activities on the WorldCanvas will be based on the user drawing 00081 // a polygon and using the polygon in some operation. 00082 // </motivation> 00083 // 00084 // <todo asof="1999/02/24"> 00085 // <li> Add time constraint to double click detection 00086 // </todo> 00087 00088 class WCPolyTool : public WCTool, public DTVisible { 00089 00090 public: 00091 00092 // Constructor 00093 WCPolyTool(WorldCanvas *wcanvas, 00094 Display::KeySym keysym = Display::K_Pointer_Button1, 00095 const Bool persistent = False); 00096 00097 // Destructor 00098 virtual ~WCPolyTool(); 00099 00100 // Switch the tool off - this calls the base class disable, 00101 // and then erases the polygon if it's around 00102 virtual void disable(); 00103 00104 // Functions called by the local event handling operators - 00105 // these handle the drawing of the polygon. In special 00106 // conditions, namely double clicking the key, they will 00107 // pass control on to the doubleInside and doubleOutside 00108 // functions 00109 // <group> 00110 virtual void keyPressed(const WCPositionEvent &ev); 00111 virtual void keyReleased(const WCPositionEvent &ev); 00112 virtual void otherKeyPressed(const WCPositionEvent &ev); 00113 virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/); 00114 virtual void refresh(const WCRefreshEvent &ev); 00115 // </group> 00116 00117 // Functions special to the polygon event handling - called when 00118 // there is a double click inside/outside the polygon 00119 // <group> 00120 virtual void doubleInside() { }; 00121 virtual void doubleOutside() { }; 00122 // </group> 00123 00124 // Functions called when a polygon is ready and not being 00125 // editted, and when this status changes 00126 // <group> 00127 virtual void polygonReady() { }; 00128 virtual void polygonNotReady() { }; 00129 // </group> 00130 00131 // Retrive the polygon vertices 00132 virtual void get(Vector<Int> &x, Vector<Int> &y); 00133 00134 private: 00135 00136 // do the polygons persist after double clicks? 00137 Bool itsPolygonPersistent; 00138 00139 // is the polygon on screen? 00140 Bool itsOnScreen; 00141 00142 // are we actively drawing? 00143 Bool itsActive; 00144 00145 // have we moved? 00146 Bool itsMoved; 00147 00148 // do we have a polygon yet? 00149 Bool itsPolygonExists; 00150 00151 // adjustment mode 00152 enum AdjustMode { 00153 Off, 00154 Move, 00155 Handle 00156 }; 00157 WCPolyTool::AdjustMode itsAdjustMode; 00158 00159 // Number of points 00160 uInt itsNPoints; 00161 00162 // Polygon points 00163 // ... pixels 00164 Vector<Int> itsX, itsY; 00165 // ... world 00166 Vector<Double> itsStoredWorldX, itsStoredWorldY; 00167 00168 // Point operations 00169 // <group> 00170 void pushPoint(uInt x1, uInt y1); 00171 void popPoint(); 00172 // </group> 00173 00174 // preserve/restore the world coordinates 00175 // <group> 00176 void preserve(); 00177 void restore(); 00178 // </group> 00179 00180 // draw the polygon on a PixelCanvas 00181 void draw(Bool drawHandles = False); 00182 00183 // reset this drawer 00184 void reset(); 00185 00186 // size in pixels of the handles 00187 uInt itsHandleSize; 00188 00189 // are we within the specified handle? 00190 Bool inHandle(const uInt &pt, const uInt &x, const uInt &y) const; 00191 00192 // which handle to modify? 00193 uInt itsSelectedHandle; 00194 00195 // are we inside the polygon? 00196 Bool inPolygon(const uInt &x, const uInt &y) const; 00197 00198 // position that move started from 00199 Int itsBaseMoveX, itsBaseMoveY; 00200 00201 // position of last press event 00202 Int itsLastPressX, itsLastPressY; 00203 Int its2ndLastPressX, its2ndLastPressY; 00204 00205 // position of last release event 00206 Int itsLastReleaseX, itsLastReleaseY; 00207 00208 // store the times of the last two presses here: 00209 Double itsLastPressTime, its2ndLastPressTime; 00210 00211 }; 00212 00213 00214 } //# NAMESPACE CASA - END 00215 00216 #endif 00217 00218