casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionTool.h
Go to the documentation of this file.
00001 //# RegionTool.h: base class for event-based tools which create and manage regions
00002 //# Copyright (C) 2011
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef DISPLAY_REGIONTOOL_H__
00029 #define DISPLAY_REGIONTOOL_H__
00030 
00031 #include <map>
00032 #include <set>
00033 #include <list>
00034 #include <display/region/RegionEnums.h>
00035 #include <display/DisplayEvents/MultiWCTool.h>
00036 #include <display/Utilities/VOID.h>
00037 
00038 namespace casa {
00039     class RegionTool : public MultiWCTool {
00040         public:
00041             typedef std::map<viewer::Region*,viewer::region::PointInfo> region_map_type;
00042 
00043             enum RegionToolTypes { POLYTOOL, RECTTOOL, POINTTOOL, ELLIPSETOOL, POLYLINETOOL, PVLINETOOL };
00044 
00045             class State {
00046                 public:
00047                     State( WorldCanvas *wc, double X, double Y ) : wc_(wc), x_(X), y_(Y), refresh_count(0) {  }
00048                     void insert( RegionTool *tool, viewer::Region *region, const viewer::region::PointInfo &state );
00049                     // get the number of regions in a particular state
00050                     unsigned int count( viewer::region::PointLocation state );
00051                     bool exists( viewer::Region * ) const;
00052                     // get the number of regions by a specific tool
00053                     /* region_map_type &regions( ) { return state_map; } */
00054                     viewer::region::region_list_type &regions( ) { return all_regions; }
00055                     viewer::region::region_list_type &regions( RegionTool *tool );
00056                     std::tr1::shared_ptr<viewer::region::region_list_type> regions( viewer::region::PointLocation loc,
00057                                                                                                                                                         viewer::region::RegionSelect select );
00058                     viewer::region::PointInfo state( viewer::Region *region );
00059 
00060                     double x( ) const { return x_; }
00061                     double y( ) const { return y_; }
00062                     WorldCanvas *wc( ) { return wc_; }
00063 
00064                     void refresh( ) { ++refresh_count; }
00065 
00066                     ~State( );
00067 
00068                 private:
00069 
00070                         std::tr1::shared_ptr<viewer::region::region_list_type> filter( std::tr1::shared_ptr<viewer::region::region_list_type>,
00071                                                                                                                                                    viewer::region::RegionSelect );
00072 
00073                     void *operator new( size_t ); // { /* refresh( ) with automatic creation/deletion in mind */ }
00074                     State( const State & ) { }
00075                     State( ) { }
00076 
00077                     typedef std::map< RegionTool*, viewer::region::region_list_type > tool_regions_type;
00078                     typedef std::map< viewer::region::PointLocation, std::tr1::shared_ptr<viewer::region::region_list_type> > state_count_type;
00079 
00080                     WorldCanvas *wc_;
00081                     double x_, y_;
00082                     unsigned int refresh_count;
00083 
00084                     region_map_type state_map;
00085                     tool_regions_type tool_map;
00086                     state_count_type count_map;
00087                     viewer::region::region_list_type all_regions;
00088                     viewer::region::region_list_type default_region_list;
00089             };
00090             // Constructor taking the primary key to which this tool will respond.
00091             RegionTool( Display::KeySym keysym = Display::K_Pointer_Button1) : MultiWCTool( keysym, false ) { }
00092             ~RegionTool( ) { }
00093 
00094             void keyPressed(const WCPositionEvent &ev);
00095             void keyReleased(const WCPositionEvent &);
00096             void otherKeyPressed(const WCPositionEvent &);
00097             void otherKeyReleased(const WCPositionEvent &);
00098             void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
00099             void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00100 
00101             // this is a non-const function because a non-const RegionTool ptr is
00102             // returned in 'state' which can then be used for setting the state of
00103             // the regions managed by the various tools....
00104             virtual void checkPoint( WorldCanvas *wc, State &state ) = 0;
00105 
00106             // create regions of various types (e.g. point, rect, poly, etc.). For use when
00107             // loading casa region files...
00108             virtual bool create( viewer::region::RegionTypes, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
00109                                  const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
00110                                  const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
00111                                  const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
00112                                  bool /*annotation*/, VOID */*region_specific_state*/ ) = 0;
00113 //                      DISPLAY_PURE_VIRTUAL(RegionTool::create,true);
00114 
00115             // defeat the registering/unregistering done by MultiWCTool (because polygon regions stop working
00116             // because they see a double-click from both the RegionToolManager and MultiWCTool)...
00117             void enable() { }
00118             void disable() { }
00119 
00120             virtual RegionToolTypes type( ) const = 0;
00121 
00122             // called when the user (read GUI user) indicates that a region should be deleted...
00123             virtual void revokeRegion( viewer::Region * ) = 0;
00124 
00125     };
00126 }
00127 
00128 #endif