casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MWCPolyTool.h
Go to the documentation of this file.
1 //# MWCPolyTool.h: Base class for MultiWorldCanvas event-based polygon tools
2 //# Copyright (C) 1999,2000,2001,2002
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_MWCPOLYTOOL_H
29 #define TRIALDISPLAY_MWCPOLYTOOL_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 // MWCPolyTool stands for Multi-WorldCanvas Polygon Tool
52 // </etymology>
53 //
54 // <synopsis>
55 // This class adds to its base MWCTool to provide a tool for drawing,
56 // reshaping and moving polygons on a WorldCanvas. While MWCPolyTool
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 again on the last or first vertex 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 MWCPolyTool : public MultiWCTool, public DTVisible {
89 
90  public:
91 
92  // Constructor
94  const casacore::Bool persistent = false);
95 
96  // Destructor
97  virtual ~MWCPolyTool();
98 
99  // Switch the tool off - this calls the base class disable,
100  // and then erases the polygon if it's around
101  virtual void disable();
102 
103  // reset to non-existent, non-active polygon.
104  // Refreshes if necessary to erase (unless skipRefresh==true).
105  // (Does not unregister from WCs or disable future event handling).
106  virtual void reset(casacore::Bool skipRefresh=false);
107 
108  // Is a polygon currently defined?
110  return itsMode>=Ready;
111  }
112 
113  protected:
114 
115  // Functions called by the base class event handling operators--and
116  // normally only those. This is the input that controls the polygon's
117  // appearance and action. When the polygon is ready and double-click
118  // is received, the doubleInside/Outside routine is invoked.
119  // <group>
120  virtual void keyPressed(const WCPositionEvent &/*ev*/);
121  virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
122  virtual void keyReleased(const WCPositionEvent &/*ev*/);
123  virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
124  // </group>
125 
126  // draw the polygon (if any) on the object's currently active WC.
127  // Only to be called by the base class refresh event handler. Derived
128  // objects should use refresh() if they need to redraw, but even that
129  // is normally handled automatically by this class.
130  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
131 
132  // Output callback functions--to be overridden in derived class as needed.
133  // Called when there is a double click inside/outside the polygon
134  // <group>
135  virtual void doubleInside() { };
136  virtual void doubleOutside() { };
137  // </group>
138 
139  // casacore::Function called when a polygon is ready and not being
140  // edited. (Unused so far on the glish level (12/01)).
141  virtual void polygonReady() { };
142 
143  // Retrieve polygon vertices, or a single vertex, in screen pixels.
144  // Valid results during the callback functions; to be used by them,
145  // as well as internally.
146  // <group>
148  virtual void get(casacore::Int &x, casacore::Int &y, const casacore::Int pt) const;
149  // </group>
150 
151  private:
152 
153  // Set the polygon vertices. itsNPoints should already be set, and
154  // x and y must contain (at least) this many points.
156 
157  // replace a single vertex.
158  virtual void set(const casacore::Int x, const casacore::Int y, const casacore::Int pt);
159  // push/pop last vertex
160  // <group>
162  void popPoint();
163  // </group>
164 
165  // are we inside the polygon?
166  casacore::Bool inPolygon(const casacore::Int &x, const casacore::Int &y) const;
167 
168  // are we within the specified handle?
169  casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const;
170 
171 
172  // should the polygon remain on screen after double clicks?
174 
175  // state of the polygon tool
176  enum AdjustMode {
177  Off, // Nothing exists yet
178  Def, // defining initial polygon
179  Ready, // polygon finished, no current activity
180  Move, // moving entire polygon
182  }; // moving single vertex whose handle was pressed
184 
185  // set true on double-click, if the polygon is persistent.
186  // set false when the polygon is moved, resized or reset.
187  // If true, a click outside the polygon will erase it and begin
188  // definition of a new one.
190 
191  // Number of points
193 
194  // Polygon points (linear). Not to be used directly.
195  // use get, set, push, pop instead, which take pixel coordinate arguments.
196  // It's done this way so that zooms work on the figures.
198 
199  // size in pixels of the handles
201 
202  // vertex being moved
204 
205  // position that move started from
207 
208  // times of the last two presses
210 
211  };
212 
213 
214 } //# NAMESPACE CASA - END
215 
216 #endif
217 
218 
casacore::Double its2ndLastPressTime
Definition: MWCPolyTool.h:209
int Int
Definition: aipstype.h:50
Class which stores WorldCanvas refresh event information.
MWCPolyTool(Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
virtual void keyReleased(const WCPositionEvent &)
casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const
are we within the specified handle?
casacore::Bool inPolygon(const casacore::Int &x, const casacore::Int &y) const
are we inside the polygon?
casacore::Int itsSelectedHandle
vertex being moved
Definition: MWCPolyTool.h:203
casacore::Int itsBaseMoveY
Definition: MWCPolyTool.h:206
virtual void polygonReady()
casacore::Function called when a polygon is ready and not being edited.
Definition: MWCPolyTool.h:141
virtual casacore::Bool polygonDefined()
Is a polygon currently defined?
Definition: MWCPolyTool.h:109
void pushPoint(casacore::Int x1, casacore::Int y1)
push/pop last vertex
casacore::Bool itsEmitted
set true on double-click, if the polygon is persistent.
Definition: MWCPolyTool.h:189
casacore::Int itsNPoints
Number of points.
Definition: MWCPolyTool.h:192
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
virtual void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
draw the polygon (if any) on the object&#39;s currently active WC.
casacore::Bool itsPolygonPersistent
should the polygon remain on screen after double clicks?
Definition: MWCPolyTool.h:173
virtual void moved(const WCMotionEvent &, const viewer::region::region_list_type &)
double Double
Definition: aipstype.h:55
virtual ~MWCPolyTool()
Destructor.
casacore::Double itsLastPressTime
times of the last two presses
Definition: MWCPolyTool.h:209
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void doubleOutside()
Definition: MWCPolyTool.h:136
MWCPolyTool::AdjustMode itsMode
Definition: MWCPolyTool.h:183
casacore::Int itsHandleSize
size in pixels of the handles
Definition: MWCPolyTool.h:200
casacore::Vector< casacore::Double > itsY
Definition: MWCPolyTool.h:197
casacore::Int itsBaseMoveX
position that move started from
Definition: MWCPolyTool.h:206
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
Class which stores WorldCanvas position event information.
virtual void doubleInside()
Output callback functions–to be overridden in derived class as needed.
Definition: MWCPolyTool.h:135
virtual void disable()
Switch the tool off - this calls the base class disable, and then erases the polygon if it&#39;s around...
Base class for MultiWorldCanvas event-based tools.
Definition: MultiWCTool.h:89
Base class for WorldCanvas event-based polygon tools.
Definition: MWCPolyTool.h:88
virtual void set(const casacore::Vector< casacore::Int > &x, const casacore::Vector< casacore::Int > &y)
Set the polygon vertices.
casacore::Vector< casacore::Double > itsX
Polygon points (linear).
Definition: MWCPolyTool.h:197
AdjustMode
state of the polygon tool
Definition: MWCPolyTool.h:176
virtual void otherKeyPressed(const WCPositionEvent &)
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active polygon.
virtual void keyPressed(const WCPositionEvent &)
Functions called by the base class event handling operators–and normally only those.