casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionToolManager.qo.h
Go to the documentation of this file.
00001 //# RegionToolManager.qo.h: class designed to unify the behavior of all of the mouse tools
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_TOOLMANAGER_H__
00029 #define DISPLAY_TOOLMANAGER_H__
00030 
00031 #include <QObject>
00032 #include <display/Display/PanelDisplay.h>
00033 #include <display/region/QtRegionSourceFactory.h>
00034 
00035 #include <display/DisplayEvents/WCPositionEH.h>
00036 #include <display/DisplayEvents/WCMotionEH.h>
00037 #include <display/DisplayEvents/WCRefreshEH.h>
00038 #include <display/QtViewer/QtDisplayPanelGui.qo.h>
00039 #include <display/QtPlotter/QtMWCTools.qo.h>
00040 
00041 namespace casa {
00042 
00043     /* class QtMWCTool; */
00044     class QtMouseTool;
00045     class QtRectTool;
00046 
00047     namespace viewer {
00048 
00049                 // the RegionCreator class now has static members which allow for the
00050                 // retrieval of lists of RegionCreator objects for creating each type
00051                 // of region (currently rectangle, polygon, ellipse, and point).
00052                 class RegionToolManager : public QObject, public WCPositionEH, public WCMotionEH, public WCRefreshEH {
00053                         Q_OBJECT
00054                 public:
00055 
00056                                 enum ToolTypes { RectTool, PointTool, EllipseTool, PolyTool, PolylineTool, PVTool };
00057 
00058 
00059                                 RegionToolManager( QtRegionSourceFactory *rsf, QtDisplayPanelGui *dpg, PanelDisplay *pd );
00060                                 ~RegionToolManager( );
00061 
00062                                 // Required operators for event handling - these are called when
00063                                 // events occur, and distribute the events to the "user-level"
00064                                 // methods
00065                                 // <group>
00066                                 void operator()(const WCPositionEvent& ev);
00067                                 void operator()(const WCMotionEvent& ev);
00068                                 void operator()(const WCRefreshEvent& ev);
00069                                 // </group>
00070 
00071                                 void loadRegions( const std::string &path, const std::string &type );
00072 
00073                                 // fetch tool for a particular region type...
00074                                 std::tr1::shared_ptr<RegionTool> tool( region::RegionTypes );
00075 
00076                 private:
00077 
00078                                 region::RegionSelect tool_to_select(RegionTool::RegionToolTypes type ) const
00079                                                 { return type == RegionTool::POLYTOOL ? region::SelectPoly :
00080                                                                         type == RegionTool::RECTTOOL ? region::SelectRect :
00081                                                                         type == RegionTool::POINTTOOL ? region::SelectPoint :
00082                                                                         type == RegionTool::ELLIPSETOOL ? region::SelectEllipse :
00083                                                                         type == RegionTool::POLYLINETOOL ? region::SelectPolyline : region::SelectAny; }
00084 
00085                                 typedef std::pair<double,double> linear_point_type;
00086                                 PanelDisplay *pd;
00087                                 typedef std::map<ToolTypes,std::tr1::shared_ptr<RegionTool> > tool_map;
00088                                 tool_map tools;
00089 
00090                                 // members for keeping track of marked (sticky-selected) regions...
00091                                 /* region_list_type marked_regions; */
00092 
00093                                 // members for state when moving selected region...
00094                                 bool inDrawArea( WorldCanvas *wc, const linear_point_type &new_blc, const linear_point_type &new_trc ) const;
00095                                 region::region_list_type moving_regions;
00096                                 linear_point_type moving_ref_point;
00097                                 linear_point_type moving_blc;
00098                                 linear_point_type moving_trc;
00099 
00100                                 // members for state when moving a region handle...
00101                                 bool moving_handle;
00102                                 viewer::region::PointInfo moving_handle_info;
00103                                 viewer::Region *moving_handle_region;
00104 
00105                                 // returns new region marked state...
00106                                 bool add_mark_select( RegionTool::State &state, region::RegionSelect );
00107                                 void clear_mark_select( RegionTool::State &state, region::RegionSelect );
00108                                 bool setup_moving_regions( RegionTool::State &state, region::RegionSelect );
00109                                 void setup_moving_regions_state( double linx, double liny, const region::region_list_type & );
00110                                 void translate_moving_regions( WorldCanvas *wc, double dx, double dy );
00111                                 bool process_double_click( RegionTool::State &state, region::RegionSelect );
00112 
00113                                 // region source factory is needed to retrieve the region dock
00114                                 // which can provide a list of selected regions...
00115                                 QtRegionSourceFactory *factory;
00116 
00117                 };
00118     }
00119 }
00120 
00121 
00122 #endif