casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiPVTool.h
Go to the documentation of this file.
1 //# MultiPVTool.h: Base class for MultiWorldCanvas event-based rectangle tools
2 //# Copyright (C) 2013
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_MULTIPVTOOL_H_
29 #define DISPLAY_MULTIPVTOOL_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 // MultiPVTool stands for MultiWorldCanvas PVLine 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 MultiPVTool
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 MultiPVTool : 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 ~MultiPVTool();
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 itsPVLineExists;
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 PVLINETOOL;
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::PVLineRegion;
178  }
179  virtual std::shared_ptr<viewer::PVLine> 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::PVLine> > pvlinelist;
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  // do we have a rectangle yet? (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid)
198 
199  // was the button pressed in the rectangle (or, if none, in an active WC)
200  // and not yet released/reset?
202  // itsActive is being replaced by resizing_region
203  std::shared_ptr<viewer::PVLine> resizing_region;
204  std::shared_ptr<viewer::PVLine> creating_region;
206 
207  // (valid only if itsActive==true):
208  // true = being moved false = being resized
210  // itsMoving is being replaced by moving_regions
212  double moving_linx_;
213  double moving_liny_;
214 
215  // (valid only if itsPVLineExists==true)
216  // Has doubleInside/Outside been called for this rectangle? If so, a
217  // key press outside the rectangle will start a new rectangle, as if
218  // itsPVLineExists were false.
219  // However, a key press inside the rectangle will reset
220  // itsEmitted to false, allowing the rectangle to be reused
221  // (possibly moved or resized, and emitted again).
223 
224  // (Linear) coordinates of the rectangle (invariant over zooms, but not
225  // coordinate system changes. To do: support the WorldCoordinateChange
226  // refresh reason, and reset this tool when it occurs).
228 
229  // storage of the handle (pixel) coordinates
231 
232  // position that move started from
234 
235  // store the times of the last two presses here:
237 
240 
241  };
242 
243 } //# NAMESPACE CASA - END
244 
245 #endif
void start_new_rectangle(WorldCanvas *, int x, int y)
virtual bool checkType(viewer::region::RegionTypes t)
Definition: MultiPVTool.h:176
int Int
Definition: aipstype.h:50
MultiPVTool(viewer::RegionSourceFactory *rsf, PanelDisplay *pd, Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
Class which stores WorldCanvas refresh event information.
viewer::RegionSource * rfactory
Definition: MultiPVTool.h:182
Definition: VOID.h:32
casacore::Vector< casacore::Double > itsP1
(Linear) coordinates of the rectangle (invariant over zooms, but not coordinate system changes...
Definition: MultiPVTool.h:227
virtual ~MultiPVTool()
Destructor.
Base class for MultiWorldCanvas event-based rectangle tools.
Definition: MultiPVTool.h:92
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::Int itsBaseMoveY
Definition: MultiPVTool.h:233
casacore::Bool itsPVLineExists
do we have a rectangle yet? (if true, itsCurrentWC, itsEmitted, P1, and P2 are valid) ...
Definition: MultiPVTool.h:197
void update_stats(const WCMotionEvent &ev)
casacore::Double its2ndLastPressTime
Definition: MultiPVTool.h:236
virtual void keyPressed(const WCPositionEvent &ev)
Functions called by the base class event handling operators–and normally only those.
virtual std::shared_ptr< viewer::PVLine > allocate_region(WorldCanvas *wc, double x1, double y1, double x2, double y2, VOID *region_specific_state) const
casacore::Bool itsEmitted
(valid only if itsPVLineExists==true) Has doubleInside/Outside been called for this rectangle...
Definition: MultiPVTool.h:222
casacore::Vector< casacore::Int > itsHY
Definition: MultiPVTool.h:230
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active rectangle.
casacore::Double itsLastPressTime
store the times of the last two presses here:
Definition: MultiPVTool.h:236
pvlinelist moving_regions
itsMoving is being replaced by moving_regions
Definition: MultiPVTool.h:211
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
virtual void rectangleReady()
Called when a rectangle is ready and not being edited.
Definition: MultiPVTool.h:168
virtual void doubleInside()
Output callback functions–to be overridden in derived class.
Definition: MultiPVTool.h:162
std::list< std::shared_ptr< viewer::PVLine > > pvlinelist
Definition: MultiPVTool.h:185
casacore::Vector< casacore::Double > itsP2
Definition: MultiPVTool.h:227
virtual casacore::Bool rectangleDefined()
Is a rectangle currently defined?
Definition: MultiPVTool.h:114
casacore::Vector< casacore::Int > itsHX
storage of the handle (pixel) coordinates
Definition: MultiPVTool.h:230
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::shared_ptr< viewer::PVLine > creating_region
Definition: MultiPVTool.h:204
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
casacore::Bool itsMoving
(valid only if itsActive==true): true = being moved false = being resized
Definition: MultiPVTool.h:209
viewer::RegionSource * getRegionSource()
Definition: MultiPVTool.h:118
RegionToolTypes type() const
Definition: MultiPVTool.h:136
virtual void moved(const WCMotionEvent &ev, const viewer::region::region_list_type &)
void revokeRegion(viewer::Region *)
called when the user (read GUI user) indicates that a region should be deleted... ...
casacore::Int itsBaseMoveX
position that move started from
Definition: MultiPVTool.h:233
virtual void otherKeyPressed(const WCPositionEvent &ev)
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.
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
casacore::Bool itsActive
was the button pressed in the rectangle (or, if none, in an active WC) and not yet released/reset...
Definition: MultiPVTool.h:201
const std::set< viewer::region::RegionTypes > & regionsCreated() const
returns a set which indicates regions this creator creates...
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...
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...
PanelDisplay * pd_
Definition: MultiPVTool.h:239
A class which creates and manages &quot;panelled&quot; displays.
Definition: PanelDisplay.h:79
std::shared_ptr< viewer::PVLine > resizing_region
itsActive is being replaced by resizing_region
Definition: MultiPVTool.h:203
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
virtual void keyReleased(const WCPositionEvent &ev)
virtual void doubleOutside()
Definition: MultiPVTool.h:163
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
pvlinelist rectangles
Definition: MultiPVTool.h:238