casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtRegionDock.qo.h
Go to the documentation of this file.
00001 //# QtRegionDock.qo.h: dockable Qt implementation of viewer region management
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 #ifndef REGION_QTREGIONDOCK_H_
00029 #define REGION_QTREGIONDOCK_H_
00030 #include <map>
00031 #include <list>
00032 #include <iostream>
00033 #include <display/region/QtRegionDock.ui.h>
00034 #include <imageanalysis/Annotations/AnnRegion.h>
00035 #include <imageanalysis/Annotations/RegionTextList.h>
00036 #include <display/region/Region.qo.h>
00037 
00038 namespace casa {
00039 
00040     class QtDisplayData;
00041     class QtDisplayPanelGui;
00042 
00043     namespace viewer {
00044 
00045         class Region;
00046         class QtRegionState;
00047         class ds9writer;
00048         class Region;
00049 
00050         class QtRegionDock : public QDockWidget, protected Ui::QtRegionDock {
00051             Q_OBJECT
00052             public:
00053 
00054                 QtRegionDock( QtDisplayPanelGui *, QWidget* parent=0 );
00055                 ~QtRegionDock();
00056 
00057                 void addRegion(Region *,QtRegionState*,int index = -1);
00058                 int indexOf(QtRegionState*) const;
00059                 void removeRegion(QtRegionState*);
00060                 void selectRegion(QtRegionState*,bool scroll=true);
00061 
00062                 void status( const std::string &msg, const std::string &type="info" );
00063 
00064                 QtDisplayPanelGui *panel( ) { return dpg; }
00065 
00066                 /* QStackedWidget *regionStack( ) { return regions; } */
00067 
00068                 /* void showStats( const QString &stats ); */
00069 
00070                 std::pair<int,int> &tabState( ) { return current_tab_state; }
00071                 std::map<std::string,int> &coordState( ) { return current_coord_state; }
00072                 QString &saveDir( ) { return current_save_dir; }
00073                 QString &loadDir( ) { return current_load_dir; }
00074                 int &colorIndex( ) { return current_color_index; }
00075 
00076                 // called to signal that selected region state needs to be updated...
00077                 void selectedCountUpdateNeeded( );
00078                 // retrieve the selected region state...
00079                 size_t selectedRegionCount( ) { return selected_region_set_.size( ); }
00080                 const region::region_list_type &selectedRegionSet( ) { return selected_region_set_; }
00081                 size_t markedRegionCount( ) { return marked_region_set_.size( ); }
00082                 const region::region_list_type &markedRegionSet( ) { return marked_region_set_; }
00083                 const region::region_list_type &weaklySelectedRegionSet( ) { return weakly_selected_region_set_; }
00084                 void clearWeaklySelectedRegionSet( );
00085                 bool isWeaklySelectedRegion( const Region * ) const;
00086                 void addWeaklySelectedRegion( Region * );
00087                 void removeWeaklySelectedRegion( Region * );
00088 
00089                 void dismiss( );
00090 
00091                 std::list<Region*> regions( ) const { return region_list; }
00092                 // zero length string indicates OK!
00093                 std::string outputRegions( std::list<viewer::QtRegionState*> regions, std::string file,
00094                                            std::string format, std::string ds9_csys="pixel" );
00095 
00096                 void updateRegionStats( );
00097                 void emitCreate( Region * );
00098 
00099                 int numFrames( ) const;
00100                 void deleteRegions( const region::region_list_type & );
00101                 void revokeRegion( Region *r );
00102 
00103                 signals:
00104                         // triggers deletion elsewhere of Region containing this QtRegionState
00105                         // which then causes the removal of this QtRegionState...
00106                         void deleteRegion(QtRegionState*);
00107                         // notice sent after QtRegionState is removed from QStackWidget,
00108                         // *and* after Region has already been deleted...
00109                         // also sent when a region is created (see std::string arg)...
00110                         void regionChange( viewer::Region *, std::string );
00111                         void deleteAllRegions( );
00112                         void regionSelected( int id );
00113                         void saveRegions( std::list<QtRegionState*>, RegionTextList & );
00114                         void saveRegions( std::list<QtRegionState*>, ds9writer & );
00115                         void loadRegions( const QString &path, const QString &type );
00116 
00117                         void region_stack_change(QWidget*);
00118 
00119                 public slots:
00120                         void updateRegionState(QtDisplayData*);
00121 
00122                 private slots:
00123                         void stack_changed(int);
00124                         void change_stack(int);
00125                         void delete_current_region(bool);
00126                         void delete_all_regions(bool);
00127                         void output_region_event(const QString &what, const QString &where, const QString &type, const QString &csys );
00128                         void handle_visibility(bool);
00129                         void emit_region_stack_change( int );
00130 
00131             protected:
00132                 void enterEvent( QEvent* );
00133                 void leaveEvent( QEvent* );
00134                 void closeEvent ( QCloseEvent * event );
00135 
00136             private:
00137                 QtDisplayPanelGui *dpg;
00138                 QtDisplayData *current_dd;
00139                 std::pair<int,int> current_tab_state;
00140                 std::map<std::string,int> current_coord_state;
00141                 int current_color_index;
00142                 QString current_save_dir;
00143                 QString current_load_dir;
00144                 bool dismissed;
00145                 bool mouse_in_dock;
00146 
00147                 typedef std::list<Region*> region_list_t;
00148                 region_list_t region_list;
00149                 typedef std::map<QtRegionState*,Region*> region_map_t;
00150                 region_map_t region_map;
00151 
00152                 // maintain a count of selected regions, information which is used
00153                 // to determine the corner treatment when drawing regions...
00154                 region::region_list_type selected_region_set_;
00155                 region::region_list_type weakly_selected_region_set_;
00156                 region::region_list_type marked_region_set_;
00157                 void update_region_statistics( );
00158 
00159         };
00160     }
00161 }
00162 
00163 #endif