casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MWCPolylineTool.h
Go to the documentation of this file.
1 //# MWCPolyTool.h: Base class for MultiWorldCanvas event-based polyline tools
2 //# Copyright (C) 2003
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_MWCPOLYLINETOOL_H
29 #define TRIALDISPLAY_MWCPOLYLINETOOL_H
30 
31 #include <casa/aips.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Base class for WorldCanvas event-based polyline 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 // MWCPolylineTool stands for Multi-WorldCanvas Polyline Tool
52 // </etymology>
53 //
54 // <synopsis>
55 // This class adds to its base MWCTool to provide a tool for drawing,
56 // reshaping and moving polylines on a WorldCanvas. While MWCPolylineTool
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 polyline 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 // polyline 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 polyline is drawn by clicking at each of the vertices, and
69 // clicking again on the last to complete the polyline.
70 // Once drawn, the vertices can be moved by dragging their handles,
71 // and the entire polyline relocated by dragging inside the polyline.
72 // The polyline 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 polyline and using the polyline in some operation.
82 // </motivation>
83 //
84 // <todo asof="2003/12/15">
85 // <li> Add time constraint to double click detection
86 // </todo>
87 
88  class MWCPolylineTool : public MultiWCTool, public DTVisible {
89 
90  public:
91 
92  // Constructor
94  const casacore::Bool persistent = false);
95 
96  // Destructor
97  virtual ~MWCPolylineTool();
98 
99  // Switch the tool off - this calls the base class disable,
100  // and then erases the polyline if it's around
101  virtual void disable();
102 
103  // reset to non-existent, non-active polyline.
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  protected:
109 
110  // Functions called by the base class event handling operators--and
111  // normally only those. This is the input that controls the polyline's
112  // appearance and action. When the polyline is ready and double-click
113  // is received, the doubleInside/Outside routine is invoked.
114  // <group>
115  virtual void keyPressed(const WCPositionEvent &ev);
116  virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
117  virtual void keyReleased(const WCPositionEvent &ev);
118  virtual void otherKeyPressed(const WCPositionEvent &ev);
119  // </group>
120 
121  // draw the polyline (if any) on the object's currently active WC.
122  // Only to be called by the base class refresh event handler. Derived
123  // objects should use refresh() if they need to redraw, but even that
124  // is normally handled automatically by this class.
125  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
126 
127  // Output callback functions--to be overridden in derived class as needed.
128  // Called when there is a double click inside/outside the polyline
129  // <group>
130  virtual void doubleInside() { };
131  virtual void doubleOutside() { };
132  // </group>
133 
134  // casacore::Function called when the polyline is ready and not being
135  // edited. (Useful for e.g. slicing).
136  virtual void polylineReady() { };
137 
138  // Retrieve polyline vertices, or a single vertex, in screen pixels.
139  // Valid results during the callback functions; to be used by them,
140  // as well as internally.
141  // <group>
143  virtual void get(casacore::Int &x, casacore::Int &y, const casacore::Int pt) const;
145  // </group>
146 
147  private:
148 
149  // Set the polyline vertices. itsNPoints should already be set, and
150  // x and y must contain (at least) this many points.
152 
153  // replace a single vertex.
154  virtual void set(const casacore::Int x, const casacore::Int y, const casacore::Int pt);
155  // push/pop last vertex
156  // <group>
158  void popPoint();
159  // </group>
160 
161  // are we inside the polyline?
162  casacore::Bool inPolyline(const casacore::Int &x, const casacore::Int &y) const;
163 
164  // are we within the specified handle?
165  casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const;
166 
167 
168  // should the polyline remain on screen after double clicks?
170 
171  // state of the polyline tool
172  enum AdjustMode {
173  Off, // Nothing exists yet
174  Def, // defining initial polyline
175  Ready, // polyline finished, no current activity
176  Move, // moving entire polyline
178  }; // moving single vertex whose handle was pressed
180 
181  // set true on double-click, if the polyline is persistent.
182  // set false when the polyline is moved, resized or reset.
183  // If true, a click outside the polyline will erase it and begin
184  // definition of a new one.
186 
187  // Number of points
189 
190  // Polyline points (linear). Not to be used directly.
191  // use get, set, push, pop instead, which take pixel coordinate arguments.
192  // It's done this way so that zooms work on the figures.
194 
195  // size in pixels of the handles
197 
198  // vertex being moved
200 
201  // position that move started from
203 
204  // times of the last two presses
206 
207  };
208 
209 
210 } //# NAMESPACE CASA - END
211 
212 #endif
213 
214 
virtual void keyReleased(const WCPositionEvent &ev)
virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type &)
int Int
Definition: aipstype.h:50
void pushPoint(casacore::Int x1, casacore::Int y1)
push/pop last vertex
casacore::Bool inPolyline(const casacore::Int &x, const casacore::Int &y) const
are we inside the polyline?
Class which stores WorldCanvas refresh event information.
virtual void polylineReady()
casacore::Function called when the polyline is ready and not being edited.
casacore::Int itsHandleSize
size in pixels of the handles
void getLinear(casacore::Vector< casacore::Float > &x, casacore::Vector< casacore::Float > &y) const
MWCPolylineTool::AdjustMode itsMode
casacore::Vector< casacore::Double > itsY
virtual void doubleInside()
Output callback functions–to be overridden in derived class as needed.
casacore::Bool itsPolylinePersistent
should the polyline remain on screen after double clicks?
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active polyline.
virtual void otherKeyPressed(const WCPositionEvent &ev)
Base class for WorldCanvas event-based polyline tools.
virtual void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
draw the polyline (if any) on the object&#39;s currently active WC.
virtual void disable()
Switch the tool off - this calls the base class disable, and then erases the polyline if it&#39;s around...
virtual ~MWCPolylineTool()
Destructor.
MWCPolylineTool(Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
casacore::Double itsLastPressTime
times of the last two presses
virtual void doubleOutside()
double Double
Definition: aipstype.h:55
virtual void set(const casacore::Vector< casacore::Int > &x, const casacore::Vector< casacore::Int > &y)
Set the polyline vertices.
AdjustMode
state of the polyline tool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool itsEmitted
set true on double-click, if the polyline is persistent.
casacore::Int itsBaseMoveY
casacore::Int itsNPoints
Number of points.
casacore::Vector< casacore::Double > itsX
Polyline points (linear).
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
casacore::Int itsBaseMoveX
position that move started from
casacore::Double its2ndLastPressTime
Class which stores WorldCanvas position event information.
virtual void keyPressed(const WCPositionEvent &ev)
Functions called by the base class event handling operators–and normally only those.
Base class for MultiWorldCanvas event-based tools.
Definition: MultiWCTool.h:89
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const
are we within the specified handle?
casacore::Int itsSelectedHandle
vertex being moved