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( ) {
00055                                 return all_regions;
00056                         }
00057                         viewer::region::region_list_type &regions( RegionTool *tool );
00058                         SHARED_PTR<viewer::region::region_list_type> regions( viewer::region::PointLocation loc,
00059                                 viewer::region::RegionSelect select );
00060                         viewer::region::PointInfo state( viewer::Region *region );
00061 
00062                         double x( ) const {
00063                                 return x_;
00064                         }
00065                         double y( ) const {
00066                                 return y_;
00067                         }
00068                         WorldCanvas *wc( ) {
00069                                 return wc_;
00070                         }
00071 
00072                         void refresh( ) {
00073                                 ++refresh_count;
00074                         }
00075 
00076                         ~State( );
00077 
00078                 private:
00079 
00080                         SHARED_PTR<viewer::region::region_list_type> filter( SHARED_PTR<viewer::region::region_list_type>,
00081                                 viewer::region::RegionSelect );
00082 
00083                         void *operator new( size_t ); // { /* refresh( ) with automatic creation/deletion in mind */ }
00084                         State( const State & ) { }
00085                         State( ) { }
00086 
00087                         typedef std::map< RegionTool*, viewer::region::region_list_type > tool_regions_type;
00088                         typedef std::map< viewer::region::PointLocation, SHARED_PTR<viewer::region::region_list_type> > state_count_type;
00089 
00090                         WorldCanvas *wc_;
00091                         double x_, y_;
00092                         unsigned int refresh_count;
00093 
00094                         region_map_type state_map;
00095                         tool_regions_type tool_map;
00096                         state_count_type count_map;
00097                         viewer::region::region_list_type all_regions;
00098                         viewer::region::region_list_type default_region_list;
00099                 };
00100                 // Constructor taking the primary key to which this tool will respond.
00101                 RegionTool( Display::KeySym keysym = Display::K_Pointer_Button1) : MultiWCTool( keysym, false ) { }
00102                 ~RegionTool( ) { }
00103 
00104                 void keyPressed(const WCPositionEvent &ev);
00105                 void keyReleased(const WCPositionEvent &);
00106                 void otherKeyPressed(const WCPositionEvent &);
00107                 void otherKeyReleased(const WCPositionEvent &);
00108                 void moved(const WCMotionEvent &ev, const viewer::region::region_list_type & /*selected_regions*/);
00109                 void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00110 
00111                 // this is a non-const function because a non-const RegionTool ptr is
00112                 // returned in 'state' which can then be used for setting the state of
00113                 // the regions managed by the various tools....
00114                 virtual void checkPoint( WorldCanvas *wc, State &state ) = 0;
00115 
00116                 // create regions of various types (e.g. point, rect, poly, etc.). For use when
00117                 // loading casa region files...
00118                 virtual bool create( viewer::region::RegionTypes, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
00119                                      const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
00120                                      const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
00121                                      const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
00122                                      bool /*annotation*/, VOID */*region_specific_state*/ ) = 0;
00123 //                      DISPLAY_PURE_VIRTUAL(RegionTool::create,true);
00124 
00125                 // defeat the registering/unregistering done by MultiWCTool (because polygon regions stop working
00126                 // because they see a double-click from both the RegionToolManager and MultiWCTool)...
00127                 void enable() { }
00128                 void disable() { }
00129 
00130                 virtual RegionToolTypes type( ) const = 0;
00131 
00132                 // called when the user (read GUI user) indicates that a region should be deleted...
00133                 virtual void revokeRegion( viewer::Region * ) = 0;
00134 
00135         };
00136 }
00137 
00138 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1