casa
$Rev:20696$
|
00001 //# MWCPolyTool.h: Base class for MultiWorldCanvas event-based polyline tools 00002 //# Copyright (C) 2003 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_MWCPOLYLINETOOL_H 00029 #define TRIALDISPLAY_MWCPOLYLINETOOL_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 WorldCanvas event-based polyline 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 // MWCPolylineTool stands for Multi-WorldCanvas Polyline Tool 00052 // </etymology> 00053 // 00054 // <synopsis> 00055 // This class adds to its base MWCTool to provide a tool for drawing, 00056 // reshaping and moving polylines on a WorldCanvas. While MWCPolylineTool 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 polyline 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 // polyline 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 polyline is drawn by clicking at each of the vertices, and 00069 // clicking again on the last to complete the polyline. 00070 // Once drawn, the vertices can be moved by dragging their handles, 00071 // and the entire polyline relocated by dragging inside the polyline. 00072 // The polyline 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 polyline and using the polyline in some operation. 00082 // </motivation> 00083 // 00084 // <todo asof="2003/12/15"> 00085 // <li> Add time constraint to double click detection 00086 // </todo> 00087 00088 class MWCPolylineTool : public MultiWCTool, public DTVisible { 00089 00090 public: 00091 00092 // Constructor 00093 MWCPolylineTool(Display::KeySym keysym = Display::K_Pointer_Button1, 00094 const Bool persistent = False); 00095 00096 // Destructor 00097 virtual ~MWCPolylineTool(); 00098 00099 // Switch the tool off - this calls the base class disable, 00100 // and then erases the polyline if it's around 00101 virtual void disable(); 00102 00103 // reset to non-existent, non-active polyline. 00104 // Refreshes if necessary to erase (unless skipRefresh==True). 00105 // (Does not unregister from WCs or disable future event handling). 00106 virtual void reset(Bool skipRefresh=False); 00107 00108 protected: 00109 00110 // Functions called by the base class event handling operators--and 00111 // normally only those. This is the input that controls the polyline's 00112 // appearance and action. When the polyline is ready and double-click 00113 // is received, the doubleInside/Outside routine is invoked. 00114 // <group> 00115 virtual void keyPressed(const WCPositionEvent &ev); 00116 virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/); 00117 virtual void keyReleased(const WCPositionEvent &ev); 00118 virtual void otherKeyPressed(const WCPositionEvent &ev); 00119 // </group> 00120 00121 // draw the polyline (if any) on the object's currently active WC. 00122 // Only to be called by the base class refresh event handler. Derived 00123 // objects should use refresh() if they need to redraw, but even that 00124 // is normally handled automatically by this class. 00125 virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/); 00126 00127 // Output callback functions--to be overridden in derived class as needed. 00128 // Called when there is a double click inside/outside the polyline 00129 // <group> 00130 virtual void doubleInside() { }; 00131 virtual void doubleOutside() { }; 00132 // </group> 00133 00134 // Function called when the polyline is ready and not being 00135 // edited. (Useful for e.g. slicing). 00136 virtual void polylineReady() { }; 00137 00138 // Retrieve polyline vertices, or a single vertex, in screen pixels. 00139 // Valid results during the callback functions; to be used by them, 00140 // as well as internally. 00141 // <group> 00142 virtual void get(Vector<Int> &x, Vector<Int> &y) const; 00143 virtual void get(Int &x, Int &y, const Int pt) const; 00144 void getLinear(Vector<Float> &x, Vector<Float> &y) const; 00145 // </group> 00146 00147 private: 00148 00149 // Set the polyline vertices. itsNPoints should already be set, and 00150 // x and y must contain (at least) this many points. 00151 virtual void set(const Vector<Int> &x, const Vector<Int> &y); 00152 00153 // replace a single vertex. 00154 virtual void set(const Int x, const Int y, const Int pt); 00155 // push/pop last vertex 00156 // <group> 00157 void pushPoint(Int x1, Int y1); 00158 void popPoint(); 00159 // </group> 00160 00161 // are we inside the polyline? 00162 Bool inPolyline(const Int &x, const Int &y) const; 00163 00164 // are we within the specified handle? 00165 Bool inHandle(const Int &pt, const Int &x, const Int &y) const; 00166 00167 00168 // should the polyline remain on screen after double clicks? 00169 Bool itsPolylinePersistent; 00170 00171 // state of the polyline tool 00172 enum AdjustMode { 00173 Off, // Nothing exists yet 00174 Def, // defining initial polyline 00175 Ready, // polyline finished, no current activity 00176 Move, // moving entire polyline 00177 Resize }; // moving single vertex whose handle was pressed 00178 MWCPolylineTool::AdjustMode itsMode; 00179 00180 // set True on double-click, if the polyline is persistent. 00181 // set False when the polyline is moved, resized or reset. 00182 // If True, a click outside the polyline will erase it and begin 00183 // definition of a new one. 00184 Bool itsEmitted; 00185 00186 // Number of points 00187 Int itsNPoints; 00188 00189 // Polyline points (linear). Not to be used directly. 00190 // use get, set, push, pop instead, which take pixel coordinate arguments. 00191 // It's done this way so that zooms work on the figures. 00192 Vector<Double> itsX, itsY; 00193 00194 // size in pixels of the handles 00195 Int itsHandleSize; 00196 00197 // vertex being moved 00198 Int itsSelectedHandle; 00199 00200 // position that move started from 00201 Int itsBaseMoveX, itsBaseMoveY; 00202 00203 // times of the last two presses 00204 Double itsLastPressTime, its2ndLastPressTime; 00205 00206 }; 00207 00208 00209 } //# NAMESPACE CASA - END 00210 00211 #endif 00212 00213