casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtRegion.qo.h
Go to the documentation of this file.
00001 //# QtRegion.h: base class for statistical regions
00002 //# Copyright (C) 2011,2012
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_QTREGION_H_
00030 #define REGION_QTREGION_H_
00031 
00032 #include <display/Display/MouseToolState.h>
00033 #include <display/region/QtRegionState.qo.h>
00034 #include <display/region/Region.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <list>
00037 
00038 namespace casa {
00039 
00040     class AnnotationBase;
00041     class RegionTextList;
00042     class DisplayData;
00043 
00044     namespace viewer {
00045 
00046         class QtRegionDock;
00047         class QtRegionState;
00048         class ds9writer;
00049 
00050         class QtRegionSourceKernel;
00051 
00052         // Key points:
00053         //    <ul>
00054         //        <li> regions are produced by a factory to permit the creation of gui specific regions </li>
00055         //    </ul>
00056         class QtRegion : public QObject {
00057             Q_OBJECT
00058 
00059             public:
00060 
00061                 // create a deginerate region just to gain access to the load regions dialog...
00062                 QtRegion( QtRegionSourceKernel *factory );
00063 
00064                 QtRegion( const QString &nme, QtRegionSourceKernel *factory, bool hold_signals_=false,
00065                           QtMouseToolNames::PointRegionSymbols sym=QtMouseToolNames::SYM_UNKNOWN );
00066                 virtual ~QtRegion( );
00067 
00068                 // needed for writing out a list of regions (CASA or DS9 format) because the
00069                 // output is based upon QtRegionState pointers (because that is what is available
00070                 // to the QtRegionDock... this should be rectified to use a list of QtRegion
00071                 // pointers for region output...
00072                 QtRegionState *state( ) { return mystate; }
00073 
00074                 const std::string name( ) const { return name_.toStdString( ); }
00075                 virtual QtMouseToolNames::PointRegionSymbols marker( ) const
00076                                 { return QtMouseToolNames::SYM_UNKNOWN; }
00077                 virtual bool setMarker( QtMouseToolNames::PointRegionSymbols )
00078                                 { return false; }
00079 
00080                 std::string lineColor( ) const { return mystate->lineColor( ); }
00081                 std::string centerColor( ) const { return mystate->centerColor( ); }
00082                 int lineWidth( ) const { return mystate->lineWidth( ); }
00083                 region::LineStyle lineStyle( ) const { return mystate->lineStyle( ); }
00084 
00085                 int markerScale( ) const { return mystate->markerScale( ); }
00086                 void setMarkerScale( int v ) { mystate->setMarkerScale(v); }
00087 
00088                 std::string textColor( ) const { return mystate->textColor( ); }
00089                 std::string textFont( ) const { return mystate->textFont( ); }
00090                 int textFontSize( ) const { return mystate->textFontSize( ); }
00091                 int textFontStyle( ) const { return mystate->textFontStyle( ); }
00092                 std::string textValue( ) const { return mystate->textValue( ); }
00093                 region::TextPosition textPosition( ) const { return mystate->textPosition( ); }
00094                 void textPositionDelta( int &x, int &y ) const { return mystate->textPositionDelta( x, y ); }
00095 
00096                 // set attributes when loading a casa region text file...
00097                 virtual void setLabel( const std::string &l );
00098                 void setLabelPosition( region::TextPosition );
00099                 void setLabelDelta( const std::vector<int> & );
00100                 virtual void setFont( const std::string &font="", int font_size=0, int font_style=0, const std::string &font_color="" );
00101                 virtual void setLine( const std::string &line_color="", region::LineStyle line_style=region::SolidLine, unsigned int line_width=1 );
00102                 virtual void setAnnotation(bool ann);
00103 
00104                 int numFrames( ) const;
00105                 void zRange( int &x, int &y ) const;
00106                 virtual int zIndex( ) const DISPLAY_PURE_VIRTUAL(region::zIndex,0);
00107                 virtual bool regionVisible( ) const DISPLAY_PURE_VIRTUAL(region::regionVisible,true);
00108 
00109                 virtual void linearCenter( double &/*x*/, double &/*y*/ ) const = 0;
00110                   // DISPLAY_PURE_VIRTUAL(region::linearCenter,);
00111                 virtual void pixelCenter( double &/*x*/, double &/*y*/ ) const = 0;
00112                   // DISPLAY_PURE_VIRTUAL(region::pixelCenter,);
00113 
00114                 virtual void refresh( ) DISPLAY_PURE_VIRTUAL(region::refresh,);
00115                 virtual AnnotationBase *annotation( ) const DISPLAY_PURE_VIRTUAL(region::annotation,0);
00116 
00117                 // indicates that the user has selected this rectangle...
00118                 void selectedInCanvas( );
00119                 // is this region weakly or temporarily selected?
00120                 bool weaklySelected( ) const;
00121                 void weaklySelect( );
00122                 void weaklyUnselect( );
00123                 // indicates that region movement requires the update of state information...
00124                 void updateStateInfo( bool region_modified, region::RegionChanges );
00125                 void clearStatistics( );
00126                 void statisticsUpdateNeeded( ) { statistics_update_needed = true; }
00127 
00128                 virtual void getCoordinatesAndUnits( region::Coord &c, region::Units &x_units, region::Units &y_units,
00129                                                      std::string &width_height_units ) const = 0; //DISPLAY_PURE_VIRTUAL(region::getCoordinatesAndUnits,);
00130                 virtual void getPositionString( std::string &x, std::string &y, std::string &angle,
00131                                                 double &bounding_width, double &bounding_height,
00132                                                 region::Coord coord = region::DefaultCoord,
00133                                                 region::Units x_units = region::DefaultUnits,
00134                                                 region::Units y_units = region::DefaultUnits,
00135                                                 const std::string &bounding_units = "rad" ) const = 0; //DISPLAY_PURE_VIRTUAL(region::getPositionString,);
00136 
00137                 virtual bool translateX( const std::string &/*x*/, const std::string &/*x_units*/, const std::string &/*coordsys*/ ) = 0; //DISPLAY_PURE_VIRTUAL(Region::movePosition,false);
00138                 virtual bool translateY( const std::string &/*y*/, const std::string &/*y_units*/, const std::string &/*coordsys*/ ) = 0; //DISPLAY_PURE_VIRTUAL(Region::movePosition,false);
00139                 virtual bool resizeX( const std::string &/*x*/, const std::string &/*x_units*/, const std::string &/*coordsys*/ ) = 0; //DISPLAY_PURE_VIRTUAL(Region::movePosition,false);
00140                 virtual bool resizeY( const std::string &/*y*/, const std::string &/*y_units*/, const std::string &/*coordsys*/ ) = 0; //DISPLAY_PURE_VIRTUAL(Region::movePosition,false);
00141 
00142                 void holdSignals( ) { hold_signals++; }
00143                 void releaseSignals( );
00144 
00145                 // functions added with the introduction of RegionToolManager and the
00146                 // unified selection and manipulation of the various region types...
00147                 void mark( bool set=true );
00148                 bool marked( ) const { return mystate->marked( ); }
00149                 bool mark_toggle( );
00150 
00151                 void status( const std::string &msg, const std::string &type="info" );
00152 
00153                 bool markCenter( ) const { return mystate->markCenter( ); }
00154 
00155                 bool skyComponent( ) const {return mystate->skyComponent();};
00156 
00157                 virtual void output( ds9writer &out ) const = 0;
00158 
00159                 // used to synchronize all of the RegionDock's RegionState tab configuration...
00160                 std::pair<int,int> &tabState( );
00161                 // used to synchronize all of the RegionDock's RegionState coordinate configuration...
00162                 std::map<std::string,int> &coordState( );
00163                 // used to synchronize the default color for all of the RegionDock's RegionState objects...
00164                 int &colorIndex( );
00165                 // forward state update information to the dock wherere a count of selected regions, information
00166                 // is maintained. This is used to determine the corner treatment when drawing regions...
00167                 void selectedCountUpdateNeeded( );
00168 
00169                 // used to synchronize all region directories per QtDisplayPanelGUI...
00170                 QString getSaveDir( );
00171                 void putSaveDir( QString );
00172                 QString getLoadDir( );
00173                 void putLoadDir( QString );
00174 
00175                 // called for existing regions when spectral profile tool is opened...
00176                 void emitUpdate( );
00177                 ImageRegion * getImageRegion( DisplayData* dd ) const {
00178                                         return get_image_region( dd );
00179                                 }
00180                 int getId() const {
00181                         return id_;
00182                 }
00183 
00184             public slots:
00185                 /* void name( const QString &newname ); */
00186                 /* void color( const QString &newcolor ); */
00187             signals:
00188                 void regionChange( viewer::QtRegion *, std::string );
00189                 void regionCreated( int, const QString &shape, const QString &name,
00190                                     const QList<double> &world_x, const QList<double> &world_y,
00191                                     const QList<int> &pixel_x, const QList<int> &pixel_y,
00192                                     const QString &linecolor, const QString &text, const QString &font, int fontsize, int fontstyle );
00193                 void regionUpdate( int, viewer::region::RegionChanges, const QList<double> &world_x, const QList<double> &world_y,
00194                                    const QList<int> &pixel_x, const QList<int> &pixel_y );
00195                 // generated by emitUpdate( )...
00196                 void regionUpdateResponse( int, const QString &shape, const QString &name,
00197                                            const QList<double> &world_x, const QList<double> &world_y,
00198                                            const QList<int> &pixel_x, const QList<int> &pixel_y,
00199                                            const QString &linecolor, const QString &text, const QString &font, int fontsize, int fontstyle );
00200 
00201                 void selectionChanged(viewer::QtRegion*,bool);
00202 
00203                 /* void updated( ); */
00204                 /* void deleted( const QtRegion * ); */
00205 
00206             protected slots:
00207                 void refresh_canvas_event( );
00208                 void reload_statistics_event( );
00209                 void refresh_statistics_event( bool );
00210                 void refresh_position_event( bool );
00211 
00212                 void translate_x( const QString &/*x*/, const QString &/*x_units*/, const QString &/*coordsys*/ );
00213                 void translate_y( const QString &/*y*/, const QString &/*y_units*/, const QString &/*coordsys*/ );
00214                 void resize_x( const QString &/*x*/, const QString &/*x_units*/, const QString &/*coordsys*/ );
00215                 void resize_y( const QString &/*y*/, const QString &/*y_units*/, const QString &/*coordsys*/ );
00216 
00217                 void refresh_zrange_event(int,int);
00218                 // revoke...
00219                 void revoke_region( );
00220                 // revoke if our state matches parameter...
00221                 void revoke_region(QtRegionState*);
00222                 void output(std::list<QtRegionState*>,RegionTextList&);
00223                 void output(std::list<QtRegionState*>,ds9writer&);
00224                 void updateCenterInfo();
00225                 void invalidateCenterInfo( );
00226 
00227 
00228             protected:
00229                 virtual ImageRegion *get_image_region( DisplayData* ) const = 0; /*DISPLAY_PURE_VIRTUAL(Region::get_image_region,0);*/
00230                 virtual std::list<RegionInfo> *generate_dds_statistics( ) DISPLAY_PURE_VIRTUAL(Region::generate_dds_statistics,0);
00231 
00232                 const std::list<Region*> &get_selected_regions( );
00233                 size_t selected_region_count( );
00234                 size_t marked_region_count( );
00235                 // At the base of this inheritance hierarchy is a class that uses
00236                 // multiple inheritance. We are QtRegion is one base class, and we
00237                 // need to be able to retrieve our peer (the non-GUI dependent)
00238                 // Region class pointer...
00239                 virtual Region *fetch_my_region( ) DISPLAY_PURE_VIRTUAL(Region::fetch_my_region,0);
00240                 /* virtual void fetch_region_details( Region::RegionTypes &/\*type*\/, */
00241                 /*                                    std::vector<std::pair<int,int> > &/\*pixel_pts*\/, */
00242                 /*                                 std::vector<std::pair<double,double> > &/\*world_pts*\/ ) const */
00243                 /*                              DISPLAY_PURE_VIRTUAL(QtRegion::fetch_region_details,); */
00244                 virtual void fetch_region_details( region::RegionTypes &/*type*/,
00245                                                    std::vector<std::pair<int,int> > &/*pixel_pts*/,
00246                                                    std::vector<std::pair<double,double> > &/*world_pts*/ ) const { }
00247 
00248                 virtual std::list<RegionInfo> *generate_dds_centers( ) DISPLAY_PURE_VIRTUAL(QtRegion::generate_dds_centers, 0);
00249 
00250 
00251                 void signal_region_change( region::RegionChanges change );
00252 
00253                 bool statistics_visible;
00254                 bool statistics_update_needed;
00255                 bool position_visible;
00256                 bool position_update_needed;
00257 
00258                 QtRegionSourceKernel *source_;
00259                 QtRegionDock *dock_;
00260                 QtRegionState *mystate;
00261                 QString name_;
00262                 QString color_;
00263 
00264             private:
00265                 std::map<region::RegionChanges,bool> held_signals;
00266                 void fetch_details( region::RegionTypes &type, QList<int> &pixelx, QList<int> &pixely, QList<double> &worldx, QList<double> &worldy );
00267                 void clear_signal_cache( );
00268                 int hold_signals;
00269                 bool z_index_within_range;
00270                 int id_;
00271         };
00272     }
00273 }
00274 
00275 #endif