casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MWCRectTool.h
Go to the documentation of this file.
1 //# MWCRectTool.h: Base class for MultiWorldCanvas event-based rectangle tools
2 //# Copyright (C) 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_MWCRECTTOOL_H
29 #define TRIALDISPLAY_MWCRECTTOOL_H
30 
31 #include <casa/aips.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Base class for MultiWorldCanvas event-based rectangle 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> WCTool
48 // </prerequisites>
49 //
50 // <etymology>
51 // MWCRectTool stands for MultiWorldCanvas Rectangle Tool
52 // </etymology>
53 //
54 // <synopsis>
55 // This class adds to its base WCTool to provide a tool for drawing,
56 // resizing and moving rectangles on a WorldCanvas. While MWCRectTool
57 // is not abstract, it performs no useful function. The programmer
58 // should derive from this class, and implement the functions
59 // doubleInside and doubleOutside, which are called when the user
60 // double-clicks the key or mouse button inside or outside an existing
61 // rectangle respectively. It is up to the programmer to decide what
62 // double clicks inside and outside the rectangle correspond to,
63 // although it is recommended that a double click inside correspond to
64 // the main action of the tool, and a double click outside correspond
65 // to a secondary action of the tool, if indeed a secondary action
66 // exists.
67 //
68 // The rectangle is drawn by dragging the mouse from one corner to
69 // the diagonally opposite corner. Once constructed, the rectangle
70 // can be resized by dragging its corners, or relocated by dragging
71 // inside the rectangle. The rectangle is removed from the display
72 // when the Esc key is pressed.
73 // </synopsis>
74 //
75 // <example>
76 // </example>
77 //
78 // <motivation>
79 // Many activities on the WorldCanvas will be based on the user drawing
80 // a rectangle, and then proceeding to some action with that rectangle.
81 // A nice example is zooming.
82 // </motivation>
83 
84  class MWCRectTool : public MultiWCTool, public DTVisible {
85 
86  public:
87 
88  // Constructor
90  const casacore::Bool persistent = false);
91 
92  // Destructor
93  virtual ~MWCRectTool();
94 
95  // Switch the tool off - this erases the rectangle, if any,
96  // and calls the base class disable.
97  virtual void disable();
98 
99  // reset to non-existent, non-active rectangle.
100  // Refreshes if necessary to erase (unless skipRefresh==true In
101  // that case, the caller should do the refresh itself).
102  // (Does not unregister from WCs or disable future event handling).
103  virtual void reset(casacore::Bool skipRefresh=false);
104 
105  // Is a rectangle currently defined?
107  return itsRectangleExists;
108  }
109 
110 
111  protected:
112 
113  // Functions called by the base class event handling operators--and
114  // normally only those. This is the input that controls the rectangle's
115  // appearance and action. When the rectangle is ready and double-click
116  // is received, the doubleInside/Outside routine will be invoked.
117  // <group>
118  virtual void keyPressed(const WCPositionEvent &/*ev*/);
119  virtual void keyReleased(const WCPositionEvent &/*ev*/);
120  virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
121  virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
122  // </group>
123 
124  // draw the rectangle (if any) on the object's currently active WC.
125  // Only to be called by the base class refresh event handler. Derived
126  // objects should use refresh() if they need to redraw, but even that
127  // is normally handled automatically.
128  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
129 
130  // Output callback functions--to be overridden in derived class.
131  // Called when there is a double click inside/outside the rectangle
132  // <group>
133  virtual void doubleInside() { };
134  virtual void doubleOutside() { };
135  // </group>
136 
137  // Called when a rectangle is ready and not being
138  // edited. (Unused so far on the glish level (12/01)).
139  virtual void rectangleReady() { };
140 
141 
142  // Retrieve the rectangle coordinates, in screen pixels.
143  // Anchor (if applicable) is (x1,y1). Valid during the output callbacks;
144  // to be used by them, as well as internally.
145  virtual void get(casacore::Int &x1, casacore::Int &y1, casacore::Int &x2, casacore::Int &y2) const ;
146 
147  private:
148 
149  // set the pixel coordinates of the rectangle
150  virtual void set(const casacore::Int &x1, const casacore::Int &y1,
151  const casacore::Int &x2, const casacore::Int &y2);
152 
153  // get only the anchor point
154  virtual void get(casacore::Int &x1, casacore::Int &y1) const;
155 
156 
157  // does the rectangle persist after double clicks (until a new one
158  // is started)?
160 
161  // do we have a rectangle yet?
162  // (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid)
164 
165  // was the button pressed in the rectangle (or, if none, in an active WC)
166  // and not yet released/reset?
168 
169  // (valid only if itsActive==true):
170  // true = being moved false = being resized
172 
173  // (valid only if itsRectangleExists==true)
174  // Has doubleInside/Outside been called for this rectangle? If so, a
175  // key press outside the rectangle will start a new rectangle, as if
176  // itsRectangleExists were false.
177  // However, a key press inside the rectangle will reset
178  // itsEmitted to false, allowing the rectangle to be reused
179  // (possibly moved or resized, and emitted again).
181 
182  // (Linear) coordinates of the rectangle (invariant over zooms, but not
183  // coordinate system changes. To do: support the WorldCoordinateChange
184  // refresh reason, and reset this tool when it occurs).
186 
187  // storage of the handle (pixel) coordinates
189 
190  // position that move started from
192 
193  // store the times of the last two presses here:
195 
196  };
197 
198 
199 } //# NAMESPACE CASA - END
200 
201 #endif
202 
203 
casacore::Vector< casacore::Int > itsHY
Definition: MWCRectTool.h:188
int Int
Definition: aipstype.h:50
casacore::Bool itsMoving
(valid only if itsActive==true): true = being moved false = being resized
Definition: MWCRectTool.h:171
virtual ~MWCRectTool()
Destructor.
Class which stores WorldCanvas refresh event information.
MWCRectTool(Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
virtual void doubleOutside()
Definition: MWCRectTool.h:134
Base class for MultiWorldCanvas event-based rectangle tools.
Definition: MWCRectTool.h:84
casacore::Int itsBaseMoveX
position that move started from
Definition: MWCRectTool.h:191
casacore::Bool itsRectanglePersistent
does the rectangle persist after double clicks (until a new one is started)?
Definition: MWCRectTool.h:159
casacore::Bool itsEmitted
(valid only if itsRectangleExists==true) Has doubleInside/Outside been called for this rectangle...
Definition: MWCRectTool.h:180
casacore::Double itsLastPressTime
store the times of the last two presses here:
Definition: MWCRectTool.h:194
casacore::Vector< casacore::Double > itsP2
Definition: MWCRectTool.h:185
virtual void keyPressed(const WCPositionEvent &)
Functions called by the base class event handling operators–and normally only those.
virtual void keyReleased(const WCPositionEvent &)
casacore::Bool itsActive
was the button pressed in the rectangle (or, if none, in an active WC) and not yet released/reset...
Definition: MWCRectTool.h:167
virtual void set(const casacore::Int &x1, const casacore::Int &y1, const casacore::Int &x2, const casacore::Int &y2)
set the pixel coordinates of the rectangle
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active rectangle.
virtual void rectangleReady()
Called when a rectangle is ready and not being edited.
Definition: MWCRectTool.h:139
virtual void moved(const WCMotionEvent &, const viewer::region::region_list_type &)
virtual casacore::Bool rectangleDefined()
Is a rectangle currently defined?
Definition: MWCRectTool.h:106
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
casacore::Bool itsRectangleExists
do we have a rectangle yet? (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid) ...
Definition: MWCRectTool.h:163
virtual void doubleInside()
Output callback functions–to be overridden in derived class.
Definition: MWCRectTool.h:133
double Double
Definition: aipstype.h:55
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Double its2ndLastPressTime
Definition: MWCRectTool.h:194
virtual void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
draw the rectangle (if any) on the object&#39;s currently active WC.
casacore::Vector< casacore::Int > itsHX
storage of the handle (pixel) coordinates
Definition: MWCRectTool.h:188
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
Class which stores WorldCanvas position event information.
Base class for MultiWorldCanvas event-based tools.
Definition: MultiWCTool.h:89
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 disable()
Switch the tool off - this erases the rectangle, if any, and calls the base class disable...
casacore::Int itsBaseMoveY
Definition: MWCRectTool.h:191
casacore::Vector< casacore::Double > itsP1
(Linear) coordinates of the rectangle (invariant over zooms, but not coordinate system changes...
Definition: MWCRectTool.h:185