casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiPolylineTool.h
Go to the documentation of this file.
1 //# Copyright (C) 1999,2000,2001,2002
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 //# $Id$
26 
27 #ifndef DISPLAY_MULTIPOLYLINETOOL_H
28 #define DISPLAY_MULTIPOLYLINETOOL_H
29 
30 #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 // MultiPolylineTool 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 MultiPolylineTool
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 or first vertex 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 
80 
81 
83 
84  public:
85 
86  // Constructor
88  Display::KeySym keysym = Display::K_Pointer_Button1, const casacore::Bool persistent = false );
89 
90  // Destructor
91  virtual ~MultiPolylineTool();
92 
93  // Switch the tool off - this calls the base class disable,
94  // and then erases the polyline if it's around
95  virtual void disable();
96 
97  // reset to non-existent, non-active polyline.
98  // Refreshes if necessary to erase (unless skipRefresh==true).
99  // (Does not unregister from WCs or disable future event handling).
100  virtual void reset(casacore::Bool skipRefresh=false);
101 
102  // Is a polyline currently defined?
104  return itsMode>=Ready;
105  }
106 
108  return rfactory;
109  }
110 
111  void checkPoint( WorldCanvas *wc, State &state );
112 
113  // called when the user (read GUI user) indicates that a region should be deleted...
114  void revokeRegion( viewer::Region * );
115 
116  // returns a set which indicates regions this creator creates...
117  const std::set<viewer::region::RegionTypes> &regionsCreated( ) const;
118 
119  bool create( viewer::region::RegionTypes /*region_type*/, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
120  const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
121  const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
122  const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
123  bool /*annotation*/, VOID */*region_specific_state*/ );
124 
126  return POLYLINETOOL;
127  }
128 
129  protected:
130 
131  // Functions called by the base class event handling operators--and
132  // normally only those. This is the input that controls the polyline's
133  // appearance and action. When the polyline is ready and double-click
134  // is received, the doubleInside/Outside routine is invoked.
135  // <group>
136  virtual void keyPressed(const WCPositionEvent &/*ev*/);
137  virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
138  virtual void keyReleased(const WCPositionEvent &/*ev*/);
139  virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
140  // </group>
141 
142  // draw the polyline (if any) on the object's currently active WC.
143  // Only to be called by the base class refresh event handler. Derived
144  // objects should use refresh() if they need to redraw, but even that
145  // is normally handled automatically by this class.
146  virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
147 
148  // Output callback functions--to be overridden in derived class as needed.
149  // Called when there is a double click inside/outside the polyline
150  // <group>
151  virtual void doubleInside() { };
152  virtual void doubleOutside() { };
153  // </group>
154 
155  // casacore::Function called when a polyline is ready and not being
156  // edited. (Unused so far on the glish level (12/01)).
157  virtual void polylineReady() { };
158 
159  // Retrieve polyline vertices, or a single vertex, in screen pixels.
160  // Valid results during the callback functions; to be used by them,
161  // as well as internally.
162  // <group>
164  virtual void get(casacore::Int &x, casacore::Int &y, const casacore::Int pt) const;
165  // </group>
166 
168  return t == viewer::region::PolylineRegion;
169  }
170 
171  private:
172  typedef std::list<std::shared_ptr<viewer::Polyline> > polylinelist;
173  void start_new_polyline( WorldCanvas *, int x, int y );
174 
175  // Set the polyline vertices. itsNPoints should already be set, and
176  // x and y must contain (at least) this many points.
178 
179  // replace a single vertex.
180  virtual void set(const casacore::Int x, const casacore::Int y, const casacore::Int pt);
181 
182  std::shared_ptr<viewer::Polyline> resizing_region;
183  std::shared_ptr<viewer::Polyline> creating_region;
184 
185  // push/pop last vertex
186  // <group>
188  void popPoint();
189  // </group>
190 
191  // are we inside the polyline?
192  casacore::Bool inPolyline(const casacore::Int &x, const casacore::Int &y) const;
193 
194  // are we within the specified handle?
195  casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const;
196 
197 
198  // should the polyline remain on screen after double clicks?
200 
201  // state of the polyline tool
202  enum AdjustMode {
203  Off, // Nothing exists yet
204  Def, // defining initial polyline
205  Ready, // polyline finished, no current activity
206  Move, // moving entire polyline
208  }; // moving single vertex whose handle was pressed
210 
211  // set true on double-click, if the polyline is persistent.
212  // set false when the polyline is moved, resized or reset.
213  // If true, a click outside the polyline will erase it and begin
214  // definition of a new one.
216 
217  // Number of points
219 
220  // Polyline points (linear). Not to be used directly.
221  // use get, set, push, pop instead, which take pixel coordinate arguments.
222  // It's done this way so that zooms work on the figures.
224  // pixel coordinates of the pan vector. 1 = anchor, 2 = new position.
226 
227 
228  // size in pixels of the handles
230 
231  // vertex being moved
233 
234  // position that move started from
236 
237  // may not be needed...
239 
241  double moving_linx_;
242  double moving_liny_;
243 
244  std::shared_ptr<viewer::Polyline> building_polyline;
248  };
249 
250 } //# NAMESPACE CASA - END
251 
252 #endif
253 
254 
casacore::Bool inPolyline(const casacore::Int &x, const casacore::Int &y) const
are we inside the polyline?
std::shared_ptr< viewer::Polyline > creating_region
int Int
Definition: aipstype.h:50
Class which stores WorldCanvas refresh event information.
Definition: VOID.h:32
std::list< std::shared_ptr< viewer::Polyline > > polylinelist
std::shared_ptr< viewer::Polyline > resizing_region
casacore::Int itsX1
pixel coordinates of the pan vector.
virtual void reset(casacore::Bool skipRefresh=false)
reset to non-existent, non-active polyline.
virtual void polylineReady()
casacore::Function called when a polyline is ready and not being edited.
casacore::Vector< casacore::Double > itsX
Polyline points (linear).
virtual casacore::Bool polylineDefined()
Is a polyline currently defined?
virtual ~MultiPolylineTool()
Destructor.
AdjustMode
state of the polyline tool
std::shared_ptr< viewer::Polyline > building_polyline
void start_new_polyline(WorldCanvas *, int x, int y)
All regions are specified in &quot;linear coordinates&quot;, not &quot;pixel coordinates&quot;.
Definition: Region.qo.h:147
casacore::Bool itsPolylinePersistent
should the polyline remain on screen after double clicks?
casacore::Bool inHandle(const casacore::Int &pt, const casacore::Int &x, const casacore::Int &y) const
are we within the specified handle?
Class which stores WorldCanvas motion event information.
Definition: WCMotionEvent.h:79
virtual void otherKeyPressed(const WCPositionEvent &)
Base class for WorldCanvas event-based polyline tools.
void pushPoint(casacore::Int x1, casacore::Int y1)
push/pop last vertex
casacore::Int itsHandleSize
size in pixels of the handles
virtual bool checkType(viewer::region::RegionTypes t)
casacore::Vector< casacore::Double > itsY
casacore::Bool itsEmitted
set true on double-click, if the polyline is persistent.
casacore::Int itsSelectedHandle
vertex being moved
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
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.
casacore::Int itsBaseMoveX
position that move started from
virtual void set(const casacore::Vector< casacore::Int > &x, const casacore::Vector< casacore::Int > &y)
Set the polyline vertices.
void revokeRegion(viewer::Region *)
called when the user (read GUI user) indicates that a region should be deleted... ...
LineStyle
LSDoubleDashed is only used to preserve state (it is a Display::LineStyle option) ...
Definition: RegionEnums.h:27
virtual void keyPressed(const WCPositionEvent &)
Functions called by the base class event handling operators–and normally only those.
Class providing draw style settings for visible DisplayTools.
Definition: DTVisible.h:95
MultiPolylineTool::AdjustMode itsMode
viewer::RegionSource * rfactory
Class which stores WorldCanvas position event information.
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
const std::set< viewer::region::RegionTypes > & regionsCreated() const
returns a set which indicates regions this creator creates...
virtual void keyReleased(const WCPositionEvent &)
viewer::RegionSource * getRegionSource()
RegionToolTypes type() const
A class which creates and manages &quot;panelled&quot; displays.
Definition: PanelDisplay.h:79
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 void doubleInside()
Output callback functions–to be overridden in derived class as needed.
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::set< Region * > region_list_type
Definition: RegionEnums.h:14
MultiPolylineTool(viewer::RegionSourceFactory *rsf, PanelDisplay *pd, Display::KeySym keysym=Display::K_Pointer_Button1, const casacore::Bool persistent=false)
Constructor.
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
int resizing_region_handle
may not be needed...
virtual void moved(const WCMotionEvent &, const viewer::region::region_list_type &)
casacore::Int itsNPoints
Number of points.