casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiPolyTool.h
Go to the documentation of this file.
1 //# MultiPolyTool.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 DISPLAY_MULTIPOLYTOOL_H
29 #define DISPLAY_MULTIPOLYTOOL_H
30 
31 #include <casa/aips.h>
35 
36 namespace casa { //# NAMESPACE CASA - BEGIN
37 
38 // <summary>
39 // Base class for WorldCanvas event-based polygon tools
40 // </summary>
41 //
42 // <use visibility=export>
43 //
44 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45 // </reviewed>
46 //
47 // <prerequisites>
48 // <li><linkto>WCTool</linkto>
49 // </prerequisites>
50 //
51 // <etymology>
52 // MultiPolyTool stands for Multi-WorldCanvas Polygon Tool
53 // </etymology>
54 //
55 // <synopsis>
56 // This class adds to its base MWCTool to provide a tool for drawing,
57 // reshaping and moving polygons on a WorldCanvas. While MultiPolyTool
58 // is not abstract, it performs no useful function. The programmer
59 // should derive from this class and override the functions doubleInside
60 // and doubleOutside at the very least. These are called when the user
61 // double-clicks a particular key or mouse button inside or outside an
62 // existing polygon respectively. It is up to the programmer to decide
63 // what these events mean, but it is recommended that an internal double-
64 // click correspond to the main action of the tool, eg. emitting the
65 // polygon vertices to the application, and that an external double-click
66 // correspond to a secondary action of the tool, if indeed there are
67 // additional actions suitable to the tool.
68 //
69 // The polygon is drawn by clicking at each of the vertices, and
70 // clicking again on the last or first vertex to complete the polygon.
71 // Once drawn, the vertices can be moved by dragging their handles,
72 // and the entire polygon relocated by dragging inside the polygon.
73 // The polygon is removed from the display when the Esc key is
74 // pressed.
75 // </synopsis>
76 //
77 // <example>
78 // </example>
79 //
80 // <motivation>
81 // Many activities on the WorldCanvas will be based on the user drawing
82 // a polygon and using the polygon in some operation.
83 // </motivation>
84 //
85 // <todo asof="1999/02/24">
86 // <li> Add time constraint to double click detection
87 // </todo>
88 
89  class MultiPolyTool : public RegionTool, public DTVisible, public viewer::RegionCreator {
90 
91  public:
92 
93  // Constructor
95  Display::KeySym keysym = Display::K_Pointer_Button1, const casacore::Bool persistent = false );
96 
97  // Destructor
98  virtual ~MultiPolyTool();
99 
100  // Switch the tool off - this calls the base class disable,
101  // and then erases the polygon if it's around
102  virtual void disable();
103 
104  // reset to non-existent, non-active polygon.
105  // Refreshes if necessary to erase (unless skipRefresh==true).
106  // (Does not unregister from WCs or disable future event handling).
107  virtual void reset(casacore::Bool skipRefresh=false);
108 
109  // Is a polygon currently defined?
111  return itsMode>=Ready;
112  }
113 
115  return rfactory;
116  }
117 
118  void checkPoint( WorldCanvas *wc, State &state );
119 
120  // called when the user (read GUI user) indicates that a region should be deleted...
121  void revokeRegion( viewer::Region * );
122 
123  // returns a set which indicates regions this creator creates...
124  const std::set<viewer::region::RegionTypes> &regionsCreated( ) const;
125 
126  bool create( viewer::region::RegionTypes /*region_type*/, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
127  const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
128  const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
129  const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
130  bool /*annotation*/, VOID */*region_specific_state*/ );
131 
133  return POLYTOOL;
134  }
135 
136  protected:
137 
138  // Functions called by the base class event handling operators--and
139  // normally only those. This is the input that controls the polygon's
140  // appearance and action. When the polygon is ready and double-click
141  // is received, the doubleInside/Outside routine is invoked.
142  // <group>
143  virtual void keyPressed(const WCPositionEvent &/*ev*/);
144  virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
145  virtual void keyReleased(const WCPositionEvent &/*ev*/);
146  virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
147  // </group>
148 
149  // draw the polygon (if any) on the object's currently active WC.
150  // Only to be called by the base class refresh event handler. Derived
151  // objects should use refresh() if they need to redraw, but even that
152  // is normally handled automatically by this class.
153  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
154 
155  // Output callback functions--to be overridden in derived class as needed.
156  // Called when there is a double click inside/outside the polygon
157  // <group>
158  virtual void doubleInside() { };
159  virtual void doubleOutside() { };
160  // </group>
161 
162  // casacore::Function called when a polygon is ready and not being
163  // edited. (Unused so far on the glish level (12/01)).
164  virtual void polygonReady() { };
165 
166  // Retrieve polygon vertices, or a single vertex, in screen pixels.
167  // Valid results during the callback functions; to be used by them,
168  // as well as internally.
169  // <group>
171  virtual void get(casacore::Int &x, casacore::Int &y, const casacore::Int pt) const;
172  // </group>
173 
175  return t == viewer::region::PolyRegion;
176  }
177 
178  private:
179  typedef std::list<std::shared_ptr<viewer::Polygon> > polygonlist;
180 
181  void start_new_polygon( WorldCanvas *, int x, int y );
182 
183  // Set the polygon vertices. itsNPoints should already be set, and
184  // x and y must contain (at least) this many points.
186 
187  // replace a single vertex.
188  virtual void set(const casacore::Int x, const casacore::Int y, const casacore::Int pt);
189 
190  std::shared_ptr<viewer::Polygon> resizing_region;
191  std::shared_ptr<viewer::Polygon> creating_region;
192 
193  // push/pop last vertex
194  // <group>
196  void popPoint();
197  // </group>
198 
199  // are we inside the polygon?
200  casacore::Bool inPolygon(const casacore::Int &x, const casacore::Int &y) const;
201 
202  // are we within the specified handle?
203  casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const;
204 
205 
206  // should the polygon remain on screen after double clicks?
208 
209  // state of the polyline tool
210  enum AdjustMode {
211  Off, // Nothing exists yet
212  Def, // defining initial polygon
213  Ready, // polygon finished, no current activity
214  Move, // moving entire polygon
216  }; // moving single vertex whose handle was pressed
218 
219  // set true on double-click, if the polygon is persistent.
220  // set false when the polygon is moved, resized or reset.
221  // If true, a click outside the polygon will erase it and begin
222  // definition of a new one.
224 
225  // Number of points
227 
228  // Polygon points (linear). Not to be used directly.
229  // use get, set, push, pop instead, which take pixel coordinate arguments.
230  // It's done this way so that zooms work on the figures.
232 
233  // size in pixels of the handles
235 
236  // vertex being moved
238 
239  // position that move started from
241 
242  // may not be needed...
244 
246  double moving_linx_;
247  double moving_liny_;
248 
249  std::shared_ptr<viewer::Polygon> building_polygon;
253  };
254 
255 } //# NAMESPACE CASA - END
256 
257 #endif
258 
259 
casacore::Bool itsEmitted
set true on double-click, if the polygon is persistent.
int Int
Definition: aipstype.h:50
Class which stores WorldCanvas refresh event information.
MultiPolyTool::AdjustMode itsMode
polygonlist moving_regions
Definition: VOID.h:32
Base class for WorldCanvas event-based polygon tools.
Definition: MultiPolyTool.h:89
virtual void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
draw the polygon (if any) on the object&#39;s currently active WC.
virtual void set(const casacore::Vector< casacore::Int > &x, const casacore::Vector< casacore::Int > &y)
Set the polygon vertices.
int resizing_region_handle
may not be needed...
const std::set< viewer::region::RegionTypes > & regionsCreated() const
returns a set which indicates regions this creator creates...
virtual bool checkType(viewer::region::RegionTypes t)
casacore::Int itsHandleSize
size in pixels of the handles
virtual void moved(const WCMotionEvent &, const viewer::region::region_list_type &)
viewer::RegionSource * getRegionSource()
virtual void doubleOutside()
RegionToolTypes type() const
casacore::Int itsSelectedHandle
vertex being moved
casacore::Int itsBaseMoveX
position that move started from
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...
AdjustMode
state of the polyline tool
virtual void keyPressed(const WCPositionEvent &)
Functions called by the base class event handling operators–and normally only those.
casacore::Int itsBaseMoveY
virtual void keyReleased(const WCPositionEvent &)
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
PanelDisplay * pd_
casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const
are we within the specified handle?
casacore::Vector< casacore::Double > itsY
MultiPolyTool(viewer::RegionSourceFactory *rsf, PanelDisplay *pd, Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
virtual void disable()
Switch the tool off - this calls the base class disable, and then erases the polygon if it&#39;s around...
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::shared_ptr< viewer::Polygon > creating_region
virtual void otherKeyPressed(const WCPositionEvent &)
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
Class which stores WorldCanvas position event information.
void revokeRegion(viewer::Region *)
called when the user (read GUI user) indicates that a region should be deleted... ...
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
virtual void doubleInside()
Output callback functions–to be overridden in derived class as needed.
virtual void polygonReady()
casacore::Function called when a polygon is ready and not being edited.
void start_new_polygon(WorldCanvas *, int x, int y)
A class which creates and manages &quot;panelled&quot; displays.
Definition: PanelDisplay.h:79
casacore::Vector< casacore::Double > itsX
Polygon points (linear).
void pushPoint(casacore::Int x1, casacore::Int y1)
push/pop last vertex
virtual ~MultiPolyTool()
Destructor.
casacore::Bool inPolygon(const casacore::Int &x, const casacore::Int &y) const
are we inside the polygon?
viewer::RegionSource * rfactory
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
casacore::Int itsNPoints
Number of points.
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active polygon.
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
std::shared_ptr< viewer::Polygon > building_polygon
polygonlist polygons
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 casacore::Bool polygonDefined()
Is a polygon currently defined?
std::list< std::shared_ptr< viewer::Polygon > > polygonlist
std::shared_ptr< viewer::Polygon > resizing_region
casacore::Bool itsPolygonPersistent
should the polygon remain on screen after double clicks?