casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RegionTool.h
Go to the documentation of this file.
1 //# RegionTool.h: base class for event-based tools which create and manage regions
2 //# Copyright (C) 2011
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_REGIONTOOL_H__
29 #define DISPLAY_REGIONTOOL_H__
30 
31 #include <map>
32 #include <set>
33 #include <list>
36 #include <display/Utilities/VOID.h>
37 
38 namespace casa {
39  class RegionTool : public MultiWCTool {
40  public:
41  typedef std::map<viewer::Region*,viewer::region::PointInfo> region_map_type;
42 
44 
45  class State {
46  public:
47  State( WorldCanvas *wc, double X, double Y ) : wc_(wc), x_(X), y_(Y), refresh_count(0) { }
48  void insert( RegionTool *tool, viewer::Region *region, const viewer::region::PointInfo &state );
49  // get the number of regions in a particular state
51  bool exists( viewer::Region * ) const;
52  // get the number of regions by a specific tool
53  /* region_map_type &regions( ) { return state_map; } */
55  return all_regions;
56  }
58  std::shared_ptr<viewer::region::region_list_type> regions( viewer::region::PointLocation loc,
61 
62  double x( ) const {
63  return x_;
64  }
65  double y( ) const {
66  return y_;
67  }
69  return wc_;
70  }
71 
72  void refresh( ) {
73  ++refresh_count;
74  }
75 
76  ~State( );
77 
78  private:
79 
80  std::shared_ptr<viewer::region::region_list_type> filter( std::shared_ptr<viewer::region::region_list_type>,
82 
83  void *operator new( size_t ); // { /* refresh( ) with automatic creation/deletion in mind */ }
84  State( const State & ) { }
85  State( ) { }
86 
87  typedef std::map< RegionTool*, viewer::region::region_list_type > tool_regions_type;
88  typedef std::map< viewer::region::PointLocation, std::shared_ptr<viewer::region::region_list_type> > state_count_type;
89 
91  double x_, y_;
92  unsigned int refresh_count;
93 
99  };
100  // Constructor taking the primary key to which this tool will respond.
102  ~RegionTool( ) { }
103 
104  void keyPressed(const WCPositionEvent &ev);
105  void keyReleased(const WCPositionEvent &);
106  void otherKeyPressed(const WCPositionEvent &);
107  void otherKeyReleased(const WCPositionEvent &);
108  void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
109  void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
110 
111  // this is a non-const function because a non-const RegionTool ptr is
112  // returned in 'state' which can then be used for setting the state of
113  // the regions managed by the various tools....
114  virtual void checkPoint( WorldCanvas *wc, State &state ) = 0;
115 
116  // create regions of various types (e.g. point, rect, poly, etc.). For use when
117  // loading casa region files...
118  virtual bool create( viewer::region::RegionTypes, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
119  const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
120  const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
121  const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
122  bool /*annotation*/, VOID */*region_specific_state*/ ) = 0;
123 // DISPLAY_PURE_VIRTUAL(RegionTool::create,true);
124 
125  // defeat the registering/unregistering done by MultiWCTool (because polygon regions stop working
126  // because they see a double-click from both the RegionToolManager and MultiWCTool)...
127  void enable() { }
128  void disable() { }
129 
130  virtual RegionToolTypes type( ) const = 0;
131 
132  // called when the user (read GUI user) indicates that a region should be deleted...
133  virtual void revokeRegion( viewer::Region * ) = 0;
134 
135  };
136 }
137 
138 #endif
unsigned int refresh_count
Definition: RegionTool.h:92
virtual RegionToolTypes type() const =0
viewer::region::region_list_type default_region_list
Definition: RegionTool.h:98
double x() const
Definition: RegionTool.h:62
Class which stores WorldCanvas refresh event information.
region_map_type state_map
Definition: RegionTool.h:94
Definition: VOID.h:32
tool_regions_type tool_map
Definition: RegionTool.h:95
State(WorldCanvas *wc, double X, double Y)
Definition: RegionTool.h:47
viewer::region::PointInfo state(viewer::Region *region)
WorldCanvas * wc()
Definition: RegionTool.h:68
unsigned int count(viewer::region::PointLocation state)
get the number of regions in a particular state
virtual void revokeRegion(viewer::Region *)=0
called when the user (read GUI user) indicates that a region should be deleted... ...
virtual 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 *)=0
create regions of various types (e.g.
std::shared_ptr< viewer::region::region_list_type > filter(std::shared_ptr< viewer::region::region_list_type >, viewer::region::RegionSelect)
void insert(RegionTool *tool, viewer::Region *region, const viewer::region::PointInfo &state)
void otherKeyReleased(const WCPositionEvent &)
std::map< viewer::Region *, viewer::region::PointInfo > region_map_type
Definition: RegionTool.h:41
WorldCanvas * wc_
Definition: RegionTool.h:90
viewer::region::region_list_type & regions()
get the number of regions by a specific tool
Definition: RegionTool.h:54
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
void enable()
DISPLAY_PURE_VIRTUAL(RegionTool::create,true);.
Definition: RegionTool.h:127
void moved(const WCMotionEvent &ev, const viewer::region::region_list_type &)
RegionTool(Display::KeySym keysym=Display::K_Pointer_Button1)
Constructor taking the primary key to which this tool will respond.
Definition: RegionTool.h:101
void keyPressed(const WCPositionEvent &ev)
Functions called by the local event handling operators - by default they do nothing, so a derived class needs only implement the events it cares about.
std::map< RegionTool *, viewer::region::region_list_type > tool_regions_type
Definition: RegionTool.h:87
viewer::region::region_list_type all_regions
Definition: RegionTool.h:97
LineStyle
LSDoubleDashed is only used to preserve state (it is a Display::LineStyle option) ...
Definition: RegionEnums.h:27
bool exists(viewer::Region *) const
Class which stores WorldCanvas position event information.
Implementation of drawing in world coordinates on top of a PixelCanvas.
Definition: WorldCanvas.h:204
virtual void checkPoint(WorldCanvas *wc, State &state)=0
this is a non-const function because a non-const RegionTool ptr is returned in &#39;state&#39; which can then...
state_count_type count_map
Definition: RegionTool.h:96
Base class for MultiWorldCanvas event-based tools.
Definition: MultiWCTool.h:89
void otherKeyPressed(const WCPositionEvent &)
double y() const
Definition: RegionTool.h:65
void draw(const WCRefreshEvent &, const viewer::region::region_list_type &)
Draw whatever should be drawn (if anything) on current WC.
void keyReleased(const WCPositionEvent &)
std::set< Region * > region_list_type
Definition: RegionEnums.h:14
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
State(const State &)
Definition: RegionTool.h:84
std::map< viewer::region::PointLocation, std::shared_ptr< viewer::region::region_list_type > > state_count_type
Definition: RegionTool.h:88