casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionSource.h
Go to the documentation of this file.
00001 //# regionsource.h: regionsource producing persistent regions used within the casa viewer
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 
00029 #ifndef REGION_REGIONSOURCE_H_
00030 #define REGION_REGIONSOURCE_H_
00031 #include <list>
00032 #include <tr1/memory>
00033 #include <display/region/RegionCreator.h>
00034 #include <display/Utilities/dtor.h>
00035 #include <display/Display/MouseToolState.h>
00036 
00037 namespace casa {
00038 
00039     class WorldCanvas;
00040 
00041     namespace viewer {
00042 
00043         class Rectangle;
00044         class Polygon;
00045         class Polyline;
00046         class Ellipse;
00047         class PVLine;
00048 
00049         class QtRegionDock;
00050         class RegionSource;
00051         class RegionCreator;
00052 
00053         class RegionSourceKernel : public dtorNotifiee {
00054             public:
00055                 typedef std::tr1::shared_ptr<RegionSourceKernel> shared_kernel_ptr_type;
00056 
00057                 RegionSourceKernel( ) { }
00058                 virtual ~RegionSourceKernel( );
00059 
00060                 // inherited pure-virtual from dtorNotifiee, removes deleted regions...
00061                 void dtorCalled( const dtorNotifier * );
00062 
00063                 // re-generate regionUpdateResponse( ) signals for existing regions...
00064                 // with *same* arguments as regionCreated( ), for the benefit of a newly created (e.g. QtProfile) tool...
00065                 virtual void generateExistingRegionUpdates( );
00066 
00067                 virtual QtRegionDock *dock( ) { return 0; }
00068                 virtual int numFrames( ) const { return -1; }
00069 
00070                 virtual void revokeRegion( Region *r ) = 0;
00071 
00072             protected:
00073                 friend class RegionSource;
00074                 virtual std::tr1::shared_ptr<Rectangle> rectangle( RegionCreator *rc, WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y ) = 0;
00075                 virtual std::tr1::shared_ptr<Polygon> polygon( RegionCreator *rc, WorldCanvas *wc, double x1, double y1 ) = 0;
00076                 virtual std::tr1::shared_ptr<Polygon> polygon( RegionCreator *rc, WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts ) = 0;
00077                 virtual std::tr1::shared_ptr<Polyline> polyline( RegionCreator *rc, WorldCanvas *wc, double x1, double y1 ) = 0;
00078                 virtual std::tr1::shared_ptr<Polyline> polyline( RegionCreator *rc, WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts ) = 0;
00079                 virtual std::tr1::shared_ptr<Rectangle> ellipse( RegionCreator *rc, WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y ) = 0;
00080                 virtual std::tr1::shared_ptr<Rectangle> point( RegionCreator *rc, WorldCanvas *wc, double x, double y, QtMouseToolNames::PointRegionSymbols sym, int size ) = 0;
00081                 virtual std::tr1::shared_ptr<PVLine> pvline( RegionCreator *rc, WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y ) = 0;
00082 
00083                 virtual QtMouseToolNames::PointRegionSymbols currentPointSymbolType( ) const = 0;
00084 
00085                 // register region for dtor callback, and add to list of created regions...
00086                 void register_new_region( Region * );
00087 
00088                 std::list<Region*> created_regions;
00089         };
00090 
00091         class RegionSource {
00092             public:
00093                 typedef RegionSourceKernel::shared_kernel_ptr_type shared_kernel_ptr_type;
00094 
00095                 std::tr1::shared_ptr<Rectangle> rectangle( WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y )
00096                                                                 { return kernel_->rectangle(region_creator,wc,blc_x,blc_y,trc_x,trc_y); }
00097                 virtual std::tr1::shared_ptr<Polygon> polygon( WorldCanvas *wc, double x1, double y1 )
00098                                                                 { return kernel_->polygon(region_creator,wc,x1,y1); }
00099                 virtual std::tr1::shared_ptr<Polygon> polygon( WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts )
00100                                                                 { return kernel_->polygon(region_creator,wc,pts); }
00101                 virtual std::tr1::shared_ptr<Polyline> polyline( WorldCanvas *wc, double x1, double y1 )
00102                                                                 { return kernel_->polyline(region_creator,wc,x1,y1); }
00103                 virtual std::tr1::shared_ptr<Polyline> polyline( WorldCanvas *wc, const std::vector<std::pair<double,double> > &pts )
00104                                                                                 { return kernel_->polyline(region_creator,wc,pts); }
00105                 virtual std::tr1::shared_ptr<Rectangle> ellipse( WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y )
00106                                                                 { return kernel_->ellipse(region_creator,wc,blc_x,blc_y,trc_x,trc_y); }
00107                 virtual std::tr1::shared_ptr<Rectangle> point( WorldCanvas *wc, double x, double y, QtMouseToolNames::PointRegionSymbols sym, int size )
00108                                                                 { return kernel_->point(region_creator,wc,x,y,sym,size); }
00109                 std::tr1::shared_ptr<PVLine> pvline( WorldCanvas *wc, double blc_x, double blc_y, double trc_x, double trc_y )
00110                                                                 { return kernel_->pvline(region_creator,wc,blc_x,blc_y,trc_x,trc_y); }
00111           
00112                 RegionSource( RegionCreator *rc, const shared_kernel_ptr_type &k ) :  kernel_(k), region_creator(rc) { }
00113                 RegionSource( const RegionSource &other ) : kernel_(other.kernel_), region_creator(other.region_creator) { }
00114 
00115                 void revokeRegion( Region *r ) { kernel_->revokeRegion(r); }
00116 
00117                 shared_kernel_ptr_type kernel( ) { return kernel_; }
00118 
00119                 QtRegionDock *dock( ) { return kernel_->dock( ); }
00120                 int numFrames( ) const { return kernel_->numFrames( ); }
00121 
00122                 QtMouseToolNames::PointRegionSymbols currentPointSymbolType( ) const { return kernel_->currentPointSymbolType( ); }
00123                 virtual ~RegionSource( ) { }
00124 
00125             private:
00126                 shared_kernel_ptr_type kernel_;
00127                 RegionCreator *region_creator;
00128         };
00129     }
00130 }
00131 
00132 #endif