casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WCPolyTool.h
Go to the documentation of this file.
1 //# WCPolyTool.h: Base class for WorldCanvas event-based polygon tools
2 //# Copyright (C) 1999,2000
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_WCPOLYTOOL_H
29 #define TRIALDISPLAY_WCPOLYTOOL_H
30 
31 #include <casa/aips.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Base class for WorldCanvas event-based polygon tools
39 // </summary>
40 //
41 // <use visibility=export>
42 //
43 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
44 // </reviewed>
45 //
46 // <prerequisites>
47 // <li><linkto>WCTool</linkto>
48 // </prerequisites>
49 //
50 // <etymology>
51 // WCPolyTool stands for WorldCanvas Polygon Tool
52 // </etymology>
53 //
54 // <synopsis>
55 // This class adds to its base WCTool to provide a tool for drawing,
56 // reshaping and moving polygons on a WorldCanvas. While WCPolyTool
57 // is not abstract, it performs no useful function. The programmer
58 // should derive from this class and override the functions doubleInside
59 // and doubleOutside at the very least. These are called when the user
60 // double-clicks a particular key or mouse button inside or outside an
61 // existing polygon respectively. It is up to the programmer to decide
62 // what these events mean, but it is recommended that an internal double-
63 // click correspond to the main action of the tool, eg. emitting the
64 // polygon vertices to the application, and that an external double-click
65 // correspond to a secondary action of the tool, if indeed there are
66 // additional actions suitable to the tool.
67 //
68 // The polygon is drawn by clicking at each of the vertices, and
69 // clicking on the last or first vertices to complete the polygon.
70 // Once drawn, the vertices can be moved by dragging their handles,
71 // and the entire polygon relocated by dragging inside the polygon.
72 // The polygon is removed from the display when the Esc key is
73 // pressed.
74 // </synopsis>
75 //
76 // <example>
77 // </example>
78 //
79 // <motivation>
80 // Many activities on the WorldCanvas will be based on the user drawing
81 // a polygon and using the polygon in some operation.
82 // </motivation>
83 //
84 // <todo asof="1999/02/24">
85 // <li> Add time constraint to double click detection
86 // </todo>
87 
88  class WCPolyTool : public WCTool, public DTVisible {
89 
90  public:
91 
92  // Constructor
93  WCPolyTool(WorldCanvas *wcanvas,
95  const casacore::Bool persistent = false);
96 
97  // Destructor
98  virtual ~WCPolyTool();
99 
100  // Switch the tool off - this calls the base class disable,
101  // and then erases the polygon if it's around
102  virtual void disable();
103 
104  // Functions called by the local event handling operators -
105  // these handle the drawing of the polygon. In special
106  // conditions, namely double clicking the key, they will
107  // pass control on to the doubleInside and doubleOutside
108  // functions
109  // <group>
110  virtual void keyPressed(const WCPositionEvent &ev);
111  virtual void keyReleased(const WCPositionEvent &ev);
112  virtual void otherKeyPressed(const WCPositionEvent &ev);
113  virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
114  virtual void refresh(const WCRefreshEvent &ev);
115  // </group>
116 
117  // Functions special to the polygon event handling - called when
118  // there is a double click inside/outside the polygon
119  // <group>
120  virtual void doubleInside() { };
121  virtual void doubleOutside() { };
122  // </group>
123 
124  // Functions called when a polygon is ready and not being
125  // editted, and when this status changes
126  // <group>
127  virtual void polygonReady() { };
128  virtual void polygonNotReady() { };
129  // </group>
130 
131  // Retrive the polygon vertices
133 
134  private:
135 
136  // do the polygons persist after double clicks?
138 
139  // is the polygon on screen?
141 
142  // are we actively drawing?
144 
145  // have we moved?
147 
148  // do we have a polygon yet?
150 
151  // adjustment mode
152  enum AdjustMode {
156  };
158 
159  // Number of points
161 
162  // Polygon points
163  // ... pixels
165  // ... world
167 
168  // Point operations
169  // <group>
171  void popPoint();
172  // </group>
173 
174  // preserve/restore the world coordinates
175  // <group>
176  void preserve();
177  void restore();
178  // </group>
179 
180  // draw the polygon on a PixelCanvas
181  void draw(casacore::Bool drawHandles = false);
182 
183  // reset this drawer
184  void reset();
185 
186  // size in pixels of the handles
188 
189  // are we within the specified handle?
190  casacore::Bool inHandle(const casacore::uInt &pt, const casacore::uInt &x, const casacore::uInt &y) const;
191 
192  // which handle to modify?
194 
195  // are we inside the polygon?
196  casacore::Bool inPolygon(const casacore::uInt &x, const casacore::uInt &y) const;
197 
198  // position that move started from
200 
201  // position of last press event
204 
205  // position of last release event
207 
208  // store the times of the last two presses here:
210 
211  };
212 
213 
214 } //# NAMESPACE CASA - END
215 
216 #endif
217 
218 
virtual void disable()
Switch the tool off - this calls the base class disable, and then erases the polygon if it&#39;s around...
casacore::Int its2ndLastPressY
Definition: WCPolyTool.h:203
int Int
Definition: aipstype.h:50
Base class for WorldCanvas event-based tools.
Definition: WCTool.h:141
Class which stores WorldCanvas refresh event information.
virtual ~WCPolyTool()
Destructor.
casacore::uInt itsNPoints
Number of points.
Definition: WCPolyTool.h:160
AdjustMode
adjustment mode
Definition: WCPolyTool.h:152
WCPolyTool(WorldCanvas *wcanvas, Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
casacore::Vector< casacore::Int > itsX
Polygon points ...
Definition: WCPolyTool.h:164
casacore::Int its2ndLastPressX
Definition: WCPolyTool.h:203
void draw(casacore::Bool drawHandles=false)
draw the polygon on a PixelCanvas
void reset()
reset this drawer
casacore::Vector< casacore::Double > itsStoredWorldY
Definition: WCPolyTool.h:166
virtual void keyReleased(const WCPositionEvent &ev)
casacore::Double its2ndLastPressTime
Definition: WCPolyTool.h:209
virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type &)
void preserve()
preserve/restore the world coordinates
virtual void doubleOutside()
Definition: WCPolyTool.h:121
casacore::Double itsLastPressTime
store the times of the last two presses here:
Definition: WCPolyTool.h:209
casacore::Bool itsOnScreen
is the polygon on screen?
Definition: WCPolyTool.h:140
virtual void doubleInside()
Functions special to the polygon event handling - called when there is a double click inside/outside ...
Definition: WCPolyTool.h:120
casacore::Int itsLastPressY
Definition: WCPolyTool.h:202
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
casacore::Int itsBaseMoveY
Definition: WCPolyTool.h:199
casacore::Bool itsPolygonPersistent
do the polygons persist after double clicks?
Definition: WCPolyTool.h:137
double Double
Definition: aipstype.h:55
casacore::Vector< casacore::Int > itsY
Definition: WCPolyTool.h:164
WCPolyTool::AdjustMode itsAdjustMode
Definition: WCPolyTool.h:157
virtual void refresh(const WCRefreshEvent &ev)
casacore::Int itsLastReleaseX
position of last release event
Definition: WCPolyTool.h:206
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool itsPolygonExists
do we have a polygon yet?
Definition: WCPolyTool.h:149
casacore::uInt itsSelectedHandle
which handle to modify?
Definition: WCPolyTool.h:193
void pushPoint(casacore::uInt x1, casacore::uInt y1)
Point operations.
casacore::Int itsLastPressX
position of last press event
Definition: WCPolyTool.h:202
casacore::Int itsBaseMoveX
position that move started from
Definition: WCPolyTool.h:199
virtual void polygonReady()
Functions called when a polygon is ready and not being editted, and when this status changes...
Definition: WCPolyTool.h:127
casacore::Bool itsActive
are we actively drawing?
Definition: WCPolyTool.h:143
Base class for WorldCanvas event-based polygon tools.
Definition: WCPolyTool.h:88
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
Class which stores WorldCanvas position event information.
casacore::Int itsLastReleaseY
Definition: WCPolyTool.h:206
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
casacore::Bool inPolygon(const casacore::uInt &x, const casacore::uInt &y) const
are we inside the polygon?
casacore::Bool inHandle(const casacore::uInt &pt, const casacore::uInt &x, const casacore::uInt &y) const
are we within the specified handle?
virtual void otherKeyPressed(const WCPositionEvent &ev)
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
casacore::Bool itsMoved
have we moved?
Definition: WCPolyTool.h:146
casacore::Vector< casacore::Double > itsStoredWorldX
...
Definition: WCPolyTool.h:166
casacore::uInt itsHandleSize
size in pixels of the handles
Definition: WCPolyTool.h:187
virtual void keyPressed(const WCPositionEvent &ev)
Functions called by the local event handling operators - these handle the drawing of the polygon...
unsigned int uInt
Definition: aipstype.h:51
virtual void polygonNotReady()
Definition: WCPolyTool.h:128