casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiRectTool.h
Go to the documentation of this file.
1 //# MultiRectTool.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 DISPLAY_MULTIRECTTOOL_H
29 #define DISPLAY_MULTIRECTTOOL_H
30 
31 #include <list>
32 #include <casa/aips.h>
37 
38 
39 namespace casa { //# NAMESPACE CASA - BEGIN
40 
41  namespace viewer {
42  class QtRegionDock;
43  }
44 
45 // <summary>
46 // Base class for MultiWorldCanvas event-based rectangle tools
47 // </summary>
48 //
49 // <use visibility=export>
50 //
51 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
52 // </reviewed>
53 //
54 // <prerequisites>
55 // <li> WCTool
56 // </prerequisites>
57 //
58 // <etymology>
59 // MultiRectTool stands for MultiWorldCanvas Rectangle Tool
60 // </etymology>
61 //
62 // <synopsis>
63 // This class adds to its base WCTool to provide a tool for drawing,
64 // resizing and moving rectangles on a WorldCanvas. While MultiRectTool
65 // is not abstract, it performs no useful function. The programmer
66 // should derive from this class, and implement the functions
67 // doubleInside and doubleOutside, which are called when the user
68 // double-clicks the key or mouse button inside or outside an existing
69 // rectangle respectively. It is up to the programmer to decide what
70 // double clicks inside and outside the rectangle correspond to,
71 // although it is recommended that a double click inside correspond to
72 // the main action of the tool, and a double click outside correspond
73 // to a secondary action of the tool, if indeed a secondary action
74 // exists.
75 //
76 // The rectangle is drawn by dragging the mouse from one corner to
77 // the diagonally opposite corner. Once constructed, the rectangle
78 // can be resized by dragging its corners, or relocated by dragging
79 // inside the rectangle. The rectangle is removed from the display
80 // when the Esc key is pressed.
81 // </synopsis>
82 //
83 // <example>
84 // </example>
85 //
86 // <motivation>
87 // Many activities on the WorldCanvas will be based on the user drawing
88 // a rectangle, and then proceeding to some action with that rectangle.
89 // A nice example is zooming.
90 // </motivation>
91 
92  class MultiRectTool : public RegionTool, public DTVisible, public viewer::RegionCreator {
93 
94  public:
95 
96  // Constructor
98  Display::KeySym keysym = Display::K_Pointer_Button1, const casacore::Bool persistent = false );
99 
100  // Destructor
101  virtual ~MultiRectTool();
102 
103  // Switch the tool off - this erases the rectangle, if any,
104  // and calls the base class disable.
105  virtual void disable();
106 
107  // reset to non-existent, non-active rectangle.
108  // Refreshes if necessary to erase (unless skipRefresh==true In
109  // that case, the caller should do the refresh itself).
110  // (Does not unregister from WCs or disable future event handling).
111  virtual void reset(casacore::Bool skipRefresh=false);
112 
113  // Is a rectangle currently defined?
115  return itsrectangleexists;
116  }
117 
119  return rfactory;
120  }
121 
122  void checkPoint( WorldCanvas *wc, State &state );
123 
124  // called when the user (read GUI user) indicates that a region should be deleted...
125  void revokeRegion( viewer::Region * );
126 
127  // returns a set which indicates regions this creator creates...
128  const std::set<viewer::region::RegionTypes> &regionsCreated( ) const;
129 
130  bool create( viewer::region::RegionTypes /*region_type*/, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
131  const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
132  const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
133  const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
134  bool /*annotation*/, VOID */*region_specific_state*/ );
135 
137  return RECTTOOL;
138  }
139 
140  protected:
141 
142  // Functions called by the base class event handling operators--and
143  // normally only those. This is the input that controls the rectangle's
144  // appearance and action. When the rectangle is ready and double-click
145  // is received, the doubleInside/Outside routine will be invoked.
146  // <group>
147  virtual void keyPressed(const WCPositionEvent &ev);
148  virtual void keyReleased(const WCPositionEvent &ev);
149  virtual void otherKeyPressed(const WCPositionEvent &ev);
150  virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
151  // </group>
152 
153  // draw the rectangle (if any) on the object's currently active WC.
154  // Only to be called by the base class refresh event handler. Derived
155  // objects should use refresh() if they need to redraw, but even that
156  // is normally handled automatically.
157  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
158 
159  // Output callback functions--to be overridden in derived class.
160  // Called when there is a double click inside/outside the rectangle
161  // <group>
162  virtual void doubleInside() { };
163  virtual void doubleOutside() { };
164  // </group>
165 
166  // Called when a rectangle is ready and not being
167  // edited. (Unused so far on the glish level (12/01)).
168  virtual void rectangleReady() { };
169 
170 
171  // Retrieve the rectangle coordinates, in screen pixels.
172  // Anchor (if applicable) is (x1,y1). Valid during the output callbacks;
173  // to be used by them, as well as internally.
174  virtual void get(casacore::Int &x1, casacore::Int &y1, casacore::Int &x2, casacore::Int &y2) const ;
175 
177  return t == viewer::region::RectRegion;
178  }
179  virtual std::shared_ptr<viewer::Rectangle> allocate_region( WorldCanvas *wc, double x1, double y1, double x2, double y2, VOID *region_specific_state ) const;
180 
181 
183 
184  private:
185  typedef std::list<std::shared_ptr<viewer::Rectangle> > rectanglelist;
186 
187  void update_stats(const WCMotionEvent &ev);
188  void start_new_rectangle( WorldCanvas *, int x, int y );
189 
190  // set the pixel coordinates of the rectangle
191  virtual void set(const casacore::Int &x1, const casacore::Int &y1, const casacore::Int &x2, const casacore::Int &y2);
192 
193  // get only the anchor point
194  virtual void get(casacore::Int &x1, casacore::Int &y1) const;
195 
196 
197  // does the rectangle persist after double clicks (until a new one is started)?
199 
200  // do we have a rectangle yet? (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid)
202 
203  // was the button pressed in the rectangle (or, if none, in an active WC)
204  // and not yet released/reset?
206  // itsActive is being replaced by resizing_region
207  std::shared_ptr<viewer::Rectangle> resizing_region;
208  std::shared_ptr<viewer::Rectangle> creating_region;
210 
211  // (valid only if itsActive==true):
212  // true = being moved false = being resized
214  // itsMoving is being replaced by moving_regions
216  double moving_linx_;
217  double moving_liny_;
218 
219  // (valid only if itsrectangleexists==true)
220  // Has doubleInside/Outside been called for this rectangle? If so, a
221  // key press outside the rectangle will start a new rectangle, as if
222  // itsrectangleexists were false.
223  // However, a key press inside the rectangle will reset
224  // itsEmitted to false, allowing the rectangle to be reused
225  // (possibly moved or resized, and emitted again).
227 
228  // (Linear) coordinates of the rectangle (invariant over zooms, but not
229  // coordinate system changes. To do: support the WorldCoordinateChange
230  // refresh reason, and reset this tool when it occurs).
232 
233  // storage of the handle (pixel) coordinates
235 
236  // position that move started from
238 
239  // store the times of the last two presses here:
241 
244 
245  };
246 
247 } //# NAMESPACE CASA - END
248 
249 #endif
virtual bool checkType(viewer::region::RegionTypes t)
MultiRectTool(viewer::RegionSourceFactory *rsf, PanelDisplay *pd, Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
virtual void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
draw the rectangle (if any) on the object&#39;s currently active WC.
std::list< std::shared_ptr< viewer::Rectangle > > rectanglelist
casacore::Bool itsMoving
(valid only if itsActive==true): true = being moved false = being resized
std::shared_ptr< viewer::Rectangle > resizing_region
itsActive is being replaced by resizing_region
int Int
Definition: aipstype.h:50
casacore::Bool itsActive
was the button pressed in the rectangle (or, if none, in an active WC) and not yet released/reset...
bool create(viewer::region::RegionTypes, WorldCanvas *, const std::vector< std::pair< double, double > > &, const std::string &, viewer::region::TextPosition, const std::vector< int > &, const std::string &, int, int, const std::string &, const std::string &, viewer::region::LineStyle, unsigned int, bool, VOID *)
create regions of various types (e.g.
virtual ~MultiRectTool()
Destructor.
Class which stores WorldCanvas refresh event information.
PanelDisplay * pd_
Definition: VOID.h:32
casacore::Vector< casacore::Int > itsHY
virtual void otherKeyPressed(const WCPositionEvent &ev)
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active rectangle.
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 keyReleased(const WCPositionEvent &ev)
casacore::Double itsLastPressTime
store the times of the last two presses here:
casacore::Double its2ndLastPressTime
rectanglelist rectangles
void revokeRegion(viewer::Region *)
called when the user (read GUI user) indicates that a region should be deleted... ...
casacore::Vector< casacore::Double > itsP2
casacore::Bool itsRectanglePersistent
does the rectangle persist after double clicks (until a new one is started)?
virtual casacore::Bool rectangleDefined()
Is a rectangle currently defined?
const std::set< viewer::region::RegionTypes > & regionsCreated() const
returns a set which indicates regions this creator creates...
virtual void keyPressed(const WCPositionEvent &ev)
Functions called by the base class event handling operators–and normally only those.
casacore::Bool itsrectangleexists
do we have a rectangle yet? (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid) ...
casacore::Vector< casacore::Int > itsHX
storage of the handle (pixel) coordinates
All regions are specified in &quot;linear coordinates&quot;, not &quot;pixel coordinates&quot;.
Definition: Region.qo.h:147
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
double Double
Definition: aipstype.h:55
void start_new_rectangle(WorldCanvas *, int x, int y)
void update_stats(const WCMotionEvent &ev)
casacore::Vector< casacore::Double > itsP1
(Linear) coordinates of the rectangle (invariant over zooms, but not coordinate system changes...
RegionToolTypes type() const
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Int itsBaseMoveY
viewer::RegionSource * getRegionSource()
void checkPoint(WorldCanvas *wc, State &state)
this is a non-const function because a non-const RegionTool ptr is returned in &#39;state&#39; which can then...
std::shared_ptr< viewer::Rectangle > creating_region
Base class for MultiWorldCanvas event-based rectangle tools.
Definition: MultiRectTool.h:92
virtual std::shared_ptr< viewer::Rectangle > allocate_region(WorldCanvas *wc, double x1, double y1, double x2, double y2, VOID *region_specific_state) const
LineStyle
LSDoubleDashed is only used to preserve state (it is a Display::LineStyle option) ...
Definition: RegionEnums.h:27
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
virtual void doubleInside()
Output callback functions–to be overridden in derived class.
viewer::RegionSource * rfactory
virtual void rectangleReady()
Called when a rectangle is ready and not being edited.
Class which stores WorldCanvas position event information.
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
virtual void disable()
Switch the tool off - this erases the rectangle, if any, and calls the base class disable...
A class which creates and manages &quot;panelled&quot; displays.
Definition: PanelDisplay.h:79
casacore::Int itsBaseMoveX
position that move started from
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
rectanglelist moving_regions
itsMoving is being replaced by moving_regions
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
virtual void doubleOutside()
casacore::Bool itsEmitted
(valid only if itsrectangleexists==true) Has doubleInside/Outside been called for this rectangle...
virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type &)