casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtDataManager.qo.h
Go to the documentation of this file.
00001 //# QtDataManager.qo.h: Qt implementation of viewer data manager widget.
00002 //# Copyright (C) 2005
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 QTDATAMANAGER_H_
00029 #define QTDATAMANAGER_H_
00030         // (Trailing underscore is not a typo -- do not remove it;
00031         // QtDataManager.ui.h uses the QTDATAMANAGER_H symbol).
00032 
00033 
00034 #include <casa/aips.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <display/QtViewer/QtLELEdit.qo.h>
00037 #include <display/Utilities/ImageProperties.h>
00038 #include <display/QtViewer/SlicerGen.qo.h>
00039 
00040 #include <graphics/X11/X_enter.h>
00041 #include <QDir>
00042 #include <QColor>
00043 #include <QHash>
00044 #include <QWidget>
00045    //#dk Be careful to put *.ui.h within X_enter/exit bracket too,
00046    //#   because they'll have Qt includes.
00047    //#   E.g. <QApplication> needs the X11 definition of 'Display'
00048 #include <display/QtViewer/QtDataManager.ui.h>
00049 #include <display/QtViewer/QtDataMgrMsSelect.ui.h>
00050 #include <graphics/X11/X_exit.h>
00051 #include <display/Utilities/Lowlevel.h>
00052 #include <set>
00053 #include <list>
00054 #include <tr1/memory>
00055 
00056  
00057 namespace casa { //# NAMESPACE CASA - BEGIN
00058 
00059 class QtDisplayPanelGui;
00060 class QtDisplayPanel;
00061 class QtDisplayData;
00062 template <class T> class ImageInterface;
00063 
00064 namespace viewer {
00065   class Region;
00066 }
00067 
00068 class QtDataManager : public QWidget, private Ui::QtDataManager {
00069    
00070    Q_OBJECT
00071 
00072  public:
00073   
00074   typedef std::list<std::pair<QGroupBox*,QLineEdit*> > infofield_list_t;
00075 
00076   QtDataManager( QtDisplayPanelGui* panel=0, const char* name=0, QWidget* parent=0 );
00077   ~QtDataManager();
00078   
00079 /*   String path() const { return dir_.path().toStdString();  } */
00080   
00081   void updateDirectory(const std::string &);
00082 
00083   void showTab( std::string );
00084  
00085  signals:
00086  
00087   void tableReadErrorSignal(String msg);
00088   
00089 
00090  protected:
00091 
00092   void showDisplayButtons(int,const QString &name=QString((const char *)0));
00093   void hideDisplayButtons();
00094   QColor getDirColor(int);
00095   QStringList analyseFITSImage(QString path);
00096   Bool isQualImg(const QString &extexpr);
00097 
00098 
00099   std::string guimethod_to_iamethod( const QString & );
00100 
00101   enum DATATYPE { UNKNOWN, IMAGE, MEASUREMENT_SET, SKY_CATALOG, RESTORE,
00102                   DIRECTORY, QUALIMG, CASAREGION, DS9REGION };
00103   enum DISPLAYTYPE { RASTER, CONTOUR, VECTOR, MARKER, SKY_CAT,
00104                      NEWPANEL, OLDPANEL };
00105 
00106   QHash<int, QString> dataType_;
00107   QHash<QString, int> uiDataType_;
00108   QHash<QString, int> displayType_;
00109   QHash<QString, int> uiDisplayType_;
00110   QVector<int>        exportTypes_;
00111  
00112   viewer::ImageProperties image_properties;
00113   infofield_list_t load_ifields;
00114 /*   infofield_list_t img_ifields; */
00115 
00116  public slots:
00117 
00118   void updateDisplayDatas(QtDisplayData* qdd=0, Bool autoRegister=True);
00119  
00120  protected slots:
00121   
00122   void handle_region_update(viewer::Region*,std::string);
00123 
00124   void createButtonClicked();
00125   void clickItem(QTreeWidgetItem* item);
00126   void expandItem(QTreeWidgetItem* item);
00127   void changeItemSelection();
00128   void returnPressed();
00129   void buildDirTree( std::string newdir="" );
00130   void lelGotFocus_();
00131   void load_regions_clicked( );
00132 
00133   // Restore viewer state to existing panel.
00134   // Use the first empty panel, or if none, the first panel.
00135   void restoreToOld_();
00136   
00137   // Create new display panel, restore viewer state to it.
00138   void restoreToNew_();
00139 
00140   // Restore viewer state to given panel.
00141   void restoreTo_(QtDisplayPanel* dp);
00142   
00143   
00144   void showDDCreateError_(String);
00145 
00146   void leaveopenButtonClicked( bool checked );
00147   void showlelButtonClicked( bool checked );
00148   void showSliceButtonClicked( bool checked );
00149  
00150   void changeTabContext(int);
00151 
00152   void img_output_target_changed(const QString &s="");
00153   void img_output_target_changed(bool) { img_output_target_changed( ); }
00154 
00155   void region_ds9_csys_disable(bool);
00156   void region_output_target_changed(const QString &s="");
00157   void region_output_target_changed(bool) { region_output_target_changed( ); }
00158 
00159   void img_do_output( );
00160   void region_do_output( );
00161 
00162   void region_item_state_change(QTreeWidgetItem*,int);
00163   void region_selection_change( viewer::Region *rgn, bool selected );
00164 
00165  private:
00166 
00167     typedef std::map<QString,QtDisplayData*> display_data_map_t;
00168     display_data_map_t display_datas;
00169     
00170     typedef std::map<QTreeWidgetItem*,viewer::Region*> treeitem_map_t;
00171     treeitem_map_t treeitem_to_region;
00172     typedef std::map<viewer::Region*,QTreeWidgetItem*> region_map_t;
00173     region_map_t region_to_treeitem;
00174 
00175     struct validation_msg {
00176         enum output_format_t { FITS, CASA, CRTF, DS9 };
00177         enum valid_t { VALID, INVALID, WARN };
00178         validation_msg( const QString &s, output_format_t f, valid_t v, const QString &m ) : path(s), output_format(f), valid(v), msg(m) { }
00179         validation_msg( const validation_msg &o ) : path(o.path), output_format(o.output_format), valid(o.valid), msg(o.msg) { }
00180         validation_msg( ) : path(/* QString::Null */), output_format(CASA), valid(INVALID), msg(/* QString::Null */) { fprintf( stderr, "HERE<3>:::: " ); }
00181         validation_msg operator=(const validation_msg &o ) { path = o.path; output_format = o.output_format; valid = o.valid; msg = o.msg; return *this; }
00182         QString canonical_path( const QString & );
00183         QString path;
00184         output_format_t output_format;
00185         valid_t valid;
00186         QString msg;
00187     };
00188 
00189     validation_msg output_validation( const QString &, const QString &, validation_msg::output_format_t ) const;
00190 
00191     class tab_state {
00192         public:
00193             typedef void (QtDataManager::*notify_func_t)( const std::string &, tab_state & );
00194             tab_state( ) : dir_entry_(0), tree_(0), dir_(new QDir), notify_func_(0),
00195                                                 info_frame_(0), info_fields_(0), dtree_(0),
00196                                                 output_name_line_(0), error_func_(0) {
00197                 dir_->setFilter( QDir::AllDirs | QDir::Files);
00198                 dir_->setSorting(QDir::Name);
00199             }
00200             tab_state( const tab_state &o ) : filtered_types_(o.filtered_types_), dir_entry_(o.dir_entry_),
00201                                                 tree_(o.tree_), dir_(o.dir_), notify_func_(o.notify_func_),
00202                                                 info_frame_(o.info_frame_), info_fields_(o.info_fields_),
00203                                                 dtree_(o.dtree_), output_name_line_(o.output_name_line_),
00204                                                 error_func_(o.error_func_) { }
00205             tab_state( QLineEdit *le, QTreeWidget *t, std::set<int> s, QFrame *info_frame=0,
00206                        infofield_list_t *info_fields=0, notify_func_t f=0,
00207                        QTreeWidget *d=0, QLineEdit *on=0, notify_func_t oerr=0 ) :
00208                                                 filtered_types_(s), dir_entry_(le), tree_(t), dir_(new QDir),
00209                                                 notify_func_(f), info_frame_(info_frame), info_fields_(info_fields),
00210                                                 dtree_(d), output_name_line_(on), error_func_(oerr) {
00211                 dir_->setFilter( QDir::AllDirs | QDir::Files);
00212                 dir_->setSorting(QDir::Name);
00213             }
00214             const std::set<int> &filter( ) const { return filtered_types_; }
00215             void updateDir( ) { if ( dir_entry_ ) { dir_entry_->setText(dir_->currentPath( )); } }
00216 
00217             void notify( QtDataManager *mgr, const std::string &s ) {
00218                 if ( notify_func_ ) (mgr->*notify_func_)(s,*this);
00219             }
00220             void notifyErr( QtDataManager *mgr, const std::string &s ) {
00221                 if ( error_func_ ) (mgr->*error_func_)(s,*this);
00222             }
00223 
00224             QTreeWidget *tree( ) { return tree_; }
00225             QFrame *infoFrame( ) { return info_frame_; }
00226             infofield_list_t *infoFields( ) { return info_fields_; }
00227             
00228             QTreeWidget *dtree( ) { return dtree_; }
00229             QLineEdit *outFileLine( ) { return output_name_line_; }
00230 
00231             std::tr1::shared_ptr<QDir> dir( ) { return dir_; }
00232             QLineEdit *dirline( ) { return dir_entry_; }
00233             std::string dirStr( ) const { return dir_entry_->text( ).toStdString( ); }
00234         private:
00235             std::set<int> filtered_types_;
00236             QLineEdit *dir_entry_;
00237             QTreeWidget *tree_;
00238             std::tr1::shared_ptr<QDir> dir_;
00239             notify_func_t notify_func_;
00240             QFrame *info_frame_;
00241             infofield_list_t *info_fields_;
00242 
00243             QTreeWidget *dtree_;
00244             QLineEdit *output_name_line_;
00245             notify_func_t error_func_;
00246 
00247   };
00248   
00249   void update_regrid_options( );
00250   void update_slice_options( int ddtp,const QString &name );
00251   void fill_image_info( const std::string &/*path*/ );
00252 
00253   QWidget *parent_;
00254   QtDisplayPanelGui* panel_;
00255   Ui::QtDataMgrMsSelect *ms_selection;
00256 
00257   // avoid setting the export type more than once
00258   QString last_image_extension_tweak_string;
00259   QString last_region_extension_tweak_string;
00260 
00261   // connection to rc file
00262   Casarc &rc;
00263 
00264   typedef std::map<int,tab_state> tab_info_map_t;
00265   tab_info_map_t tab_info;
00266   void init_tab_info( );
00267 
00268   void load_tab_notify( const std::string &value, tab_state & );
00269 
00270   void update_dd_list( tab_state &ts );
00271   void image_tab_notify( const std::string &value, tab_state & );
00272   void image_tab_error( const std::string &value, tab_state & );
00273 
00274   void update_region_list( tab_state &ts );
00275   void region_tab_notify( const std::string &value, tab_state & );
00276   void region_tab_error( const std::string &value, tab_state & );
00277 
00278   bool export_to_fits(ImageInterface<Float> *img, std::string outFile);
00279   bool export_to_casa(ImageInterface<Float> *img, String outFile);
00280   void getSpectralCoordFlags(const ImageInterface<Float>* img, Bool &preferVelocity, Bool &opticalVelocity, Bool &preferWavelength, Bool &preferAirWavelength);
00281 
00282   viewer::SlicerGen *slice_gen;
00283 
00284 };
00285 
00286 
00287 
00288 } //# NAMESPACE CASA - END
00289 
00290 #endif