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 <display/QtViewer/VOParam.ui.h>
00051 #include <casaqt/QtDBus/dVO.h>
00052 #include <graphics/X11/X_exit.h>
00053 #include <display/Utilities/Lowlevel.h>
00054 #include <set>
00055 #include <list>
00056 #if defined(__APPLE__)
00057 #include <tuple>
00058 #define TUPLE std::tuple
00059 #else
00060 #include <tr1/tuple>
00061 #define TUPLE std::tr1::tuple
00062 #endif
00063 
00064 namespace casa { //# NAMESPACE CASA - BEGIN
00065 
00066         class QtDisplayPanelGui;
00067         class QtDisplayPanel;
00068         class QtDisplayData;
00069         template <class T> class ImageInterface;
00070 
00071         namespace viewer {
00072                 class Region;
00073 
00074         namespace dvo {
00075             // entry of flexible VO parameters...
00076             class param : public QGroupBox, public Ui::VOParam {
00077                 Q_OBJECT
00078                 public:
00079                     param( QListWidget *l, QListWidgetItem *i, QWidget *parent=0 ) : QGroupBox(parent), list(l), item(i) { setupUi(this); }
00080                 protected:
00081                     void mousePressEvent ( QMouseEvent * event );
00082                 private:
00083                     QListWidget *list;
00084                     QListWidgetItem *item;
00085             };
00086         }
00087         }
00088 
00089         class QtDataManager : public QWidget, private Ui::QtDataManager {
00090 
00091                 Q_OBJECT
00092 
00093         public:
00094 
00095                 typedef std::list<std::pair<QGroupBox*,QLineEdit*> > infofield_list_t;
00096 
00097                 QtDataManager( QtDisplayPanelGui* panel=0, const char* name=0, QWidget* parent=0 );
00098                 ~QtDataManager();
00099 
00100                 /*   String path() const { return dir_.path().toStdString();  } */
00101 
00102                 void updateDirectory(const std::string &);
00103 
00104                 void showTab( std::string );
00105                 void clearRegionMap();
00106 
00107         signals:
00108 
00109                 void tableReadErrorSignal(String msg);
00110 
00111 
00112         protected:
00113 
00114         void showEvent( QShowEvent *event );
00115         void enterEvent( QEvent  *event );
00116                 void showDisplayButtons(int,const QString &name=QString((const char *)0));
00117                 void hideDisplayButtons();
00118                 QColor getDirColor(int);
00119                 QStringList analyseFITSImage(QString path);
00120                 Bool isQualImg(const QString &extexpr);
00121 
00122 
00123                 std::string guimethod_to_iamethod( const QString & );
00124 
00125                 enum DATATYPE { UNKNOWN, IMAGE, MEASUREMENT_SET, SKY_CATALOG, RESTORE,
00126                                 DIRECTORY, QUALIMG, CASAREGION, DS9REGION
00127                               };
00128                 enum DISPLAYTYPE { RASTER, CONTOUR, VECTOR, MARKER, SKY_CAT,
00129                                    NEWPANEL, OLDPANEL
00130                                  };
00131 
00132                 QHash<int, QString> dataType_;
00133                 QHash<QString, int> uiDataType_;
00134                 QHash<QString, int> displayType_;
00135                 QHash<QString, int> uiDisplayType_;
00136                 QVector<int>        exportTypes_;
00137 
00138                 viewer::ImageProperties image_properties;
00139                 infofield_list_t load_ifields;
00140                 /*   infofield_list_t img_ifields; */
00141 
00142         public slots:
00143 
00144                 void updateDisplayDatas(QtDisplayData* qdd=0, Bool autoRegister=True);
00145 
00146         protected slots:
00147 
00148                 void handle_region_update(viewer::Region*,std::string);
00149 
00150                 void createButtonClicked();
00151                 void clickItem(QTreeWidgetItem* item);
00152                 void expandItem(QTreeWidgetItem* item);
00153                 void changeItemSelection();
00154                 void returnPressed();
00155                 void buildDirTree( std::string newdir="" );
00156                 void lelGotFocus_();
00157                 void load_regions_clicked( );
00158 
00159                 // Restore viewer state to existing panel.
00160                 // Use the first empty panel, or if none, the first panel.
00161                 void restoreToOld_();
00162 
00163                 // Create new display panel, restore viewer state to it.
00164                 void restoreToNew_();
00165 
00166                 // Restore viewer state to given panel.
00167                 void restoreTo_(QtDisplayPanel* dp);
00168 
00169 
00170                 void showDDCreateError_(String);
00171 
00172                 void leaveopenButtonClicked( bool checked );
00173                 void showlelButtonClicked( bool checked );
00174                 void showSliceButtonClicked( bool checked );
00175 
00176                 void changeTabContext(int);
00177 
00178                 void img_output_target_changed(const QString &s="");
00179                 void img_output_target_changed(bool) {
00180                         img_output_target_changed( );
00181                 }
00182 
00183                 void region_ds9_csys_disable(bool);
00184                 void region_output_target_changed(const QString &s="");
00185                 void region_output_target_changed(bool) {
00186                         region_output_target_changed( );
00187                 }
00188 
00189                 void img_do_output( );
00190                 void region_do_output( );
00191 
00192                 void region_item_state_change(QTreeWidgetItem*,int);
00193                 void region_selection_change( viewer::Region *rgn, bool selected );
00194 
00195         //---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---
00196         //  VO controls...
00197         //---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---
00198         void addVOParam( );
00199         void removeVOParam( );
00200         //---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---
00201 
00202     private slots:
00203          void enable_disable_slice( const QString & );
00204          void enable_disable_regrid( bool );
00205         private:
00206 
00207                 typedef std::map<QString,QtDisplayData*> display_data_map_t;
00208                 display_data_map_t display_datas;
00209 
00210                 typedef std::map<QTreeWidgetItem*,viewer::Region*> treeitem_map_t;
00211                 treeitem_map_t treeitem_to_region;
00212                 typedef std::map<viewer::Region*,QTreeWidgetItem*> region_map_t;
00213                 region_map_t region_to_treeitem;
00214 
00215                 struct validation_msg {
00216                         enum output_format_t { FITS, CASA, CRTF, DS9 };
00217                         enum valid_t { VALID, INVALID, WARN };
00218                         validation_msg( const QString &s, output_format_t f, valid_t v, const QString &m ) : path(s), output_format(f), valid(v), msg(m) { }
00219                         validation_msg( const validation_msg &o ) : path(o.path), output_format(o.output_format), valid(o.valid), msg(o.msg) { }
00220                         validation_msg( ) : path(/* QString::Null */), output_format(CASA), valid(INVALID), msg(/* QString::Null */) {
00221                                 fprintf( stderr, "HERE<3>:::: " );
00222                         }
00223                         validation_msg operator=(const validation_msg &o ) {
00224                                 path = o.path;
00225                                 output_format = o.output_format;
00226                                 valid = o.valid;
00227                                 msg = o.msg;
00228                                 return *this;
00229                         }
00230                         QString canonical_path( const QString & );
00231                         QString path;
00232                         output_format_t output_format;
00233                         valid_t valid;
00234                         QString msg;
00235                 };
00236 
00237                 validation_msg output_validation( const QString &, const QString &, validation_msg::output_format_t ) const;
00238 
00239                 class tab_state {
00240                 public:
00241                         typedef void (QtDataManager::*notify_func_t)( const std::string &, tab_state & );
00242                         tab_state( ) : dir_entry_(0), tree_(0), dir_(new QDir), notify_func_(0),
00243                                 info_frame_(0), info_fields_(0), dtree_(0),
00244                                 output_name_line_(0), error_func_(0) {
00245                                 dir_->setFilter( QDir::AllDirs | QDir::Files);
00246                                 dir_->setSorting(QDir::Name);
00247                         }
00248                         tab_state( const tab_state &o ) : filtered_types_(o.filtered_types_), dir_entry_(o.dir_entry_),
00249                                 tree_(o.tree_), dir_(o.dir_), notify_func_(o.notify_func_),
00250                                 info_frame_(o.info_frame_), info_fields_(o.info_fields_),
00251                                 dtree_(o.dtree_), output_name_line_(o.output_name_line_),
00252                                 error_func_(o.error_func_) { }
00253                         tab_state( QLineEdit *le, QTreeWidget *t, std::set<int> s, QFrame *info_frame=0,
00254                                    infofield_list_t *info_fields=0, notify_func_t f=0,
00255                                    QTreeWidget *d=0, QLineEdit *on=0, notify_func_t oerr=0 ) :
00256                                 filtered_types_(s), dir_entry_(le), tree_(t), dir_(new QDir),
00257                                 notify_func_(f), info_frame_(info_frame), info_fields_(info_fields),
00258                                 dtree_(d), output_name_line_(on), error_func_(oerr) {
00259                                 dir_->setFilter( QDir::AllDirs | QDir::Files);
00260                                 dir_->setSorting(QDir::Name);
00261                         }
00262                         const std::set<int> &filter( ) const {
00263                                 return filtered_types_;
00264                         }
00265                         void updateDir( ) {
00266                                 if ( dir_entry_ ) {
00267                                         dir_entry_->setText(dir_->currentPath( ));
00268                                 }
00269                         }
00270 
00271                         void notify( QtDataManager *mgr, const std::string &s ) {
00272                                 if ( notify_func_ ) (mgr->*notify_func_)(s,*this);
00273                         }
00274                         void notifyErr( QtDataManager *mgr, const std::string &s ) {
00275                                 if ( error_func_ ) (mgr->*error_func_)(s,*this);
00276                         }
00277 
00278                         QTreeWidget *tree( ) {
00279                                 return tree_;
00280                         }
00281                         QFrame *infoFrame( ) {
00282                                 return info_frame_;
00283                         }
00284                         infofield_list_t *infoFields( ) {
00285                                 return info_fields_;
00286                         }
00287 
00288                         QTreeWidget *dtree( ) {
00289                                 return dtree_;
00290                         }
00291                         QLineEdit *outFileLine( ) {
00292                                 return output_name_line_;
00293                         }
00294 
00295                         SHARED_PTR<QDir> dir( ) {
00296                                 return dir_;
00297                         }
00298                         QLineEdit *dirline( ) {
00299                                 return dir_entry_;
00300                         }
00301                         std::string dirStr( ) const {
00302                                 return dir_entry_->text( ).toStdString( );
00303                         }
00304                 private:
00305                         std::set<int> filtered_types_;
00306                         QLineEdit *dir_entry_;
00307                         QTreeWidget *tree_;
00308                         SHARED_PTR<QDir> dir_;
00309                         notify_func_t notify_func_;
00310                         QFrame *info_frame_;
00311                         infofield_list_t *info_fields_;
00312 
00313                         QTreeWidget *dtree_;
00314                         QLineEdit *output_name_line_;
00315                         notify_func_t error_func_;
00316 
00317                 };
00318 
00319                 void update_regrid_options( );
00320                 void update_slice_options( int ddtp,const QString &name );
00321                 void fill_image_info( const std::string &/*path*/ );
00322 
00323                 QWidget *parent_;
00324                 QtDisplayPanelGui* panel_;
00325                 Ui::QtDataMgrMsSelect *ms_selection;
00326 
00327                 // avoid setting the export type more than once
00328                 QString last_image_extension_tweak_string;
00329                 QString last_region_extension_tweak_string;
00330 
00331                 // connection to rc file
00332                 Casarc &rc;
00333 
00334                 typedef std::map<int,tab_state> tab_info_map_t;
00335                 tab_info_map_t tab_info;
00336                 void init_tab_info( );
00337 
00338                 void load_tab_notify( const std::string &value, tab_state & );
00339 
00340                 void update_dd_list( tab_state &ts );
00341                 void image_tab_notify( const std::string &value, tab_state & );
00342                 void image_tab_error( const std::string &value, tab_state & );
00343 
00344                 void update_region_list( tab_state &ts );
00345                 void region_tab_notify( const std::string &value, tab_state & );
00346                 void region_tab_error( const std::string &value, tab_state & );
00347 
00348                 bool export_to_fits(ImageInterface<Float> *img, std::string outFile);
00349                 bool export_to_casa(ImageInterface<Float> *img, String outFile);
00350                 void getSpectralCoordFlags(const ImageInterface<Float>* img, Bool &preferVelocity, Bool &opticalVelocity, Bool &preferWavelength, Bool &preferAirWavelength);
00351 
00352                 viewer::SlicerGen *slice_gen;
00353 
00354         bool slice_available;
00355         bool regrid_available;
00356 
00357         void setupVO( );
00358         // returns true if everything is OK...
00359         bool updateVOstatus( );
00360         QPushButton *new_vo_dismiss_button( QTableWidgetItem*, QString, QString );
00361         bool collect_vo_parameters( double &ra, double &dec, double &ra_size, double &dec_size, QVariantMap &params );
00362         void vo_flag_missing_param( QLineEdit *widget );
00363         // (enabled, gui label, vo parameter name,vo parameter default,entry box)
00364         typedef TUPLE<bool,QString,QString,QString,viewer::dvo::param*> vo_param_t;
00365         std::vector<vo_param_t> voparameters;
00366         edu::nrao::casa::dVO dvo;
00367         std::set<QWidget*> dvo_missing_parameters;
00368 
00369         std::map<QString,int> vo_label2col;
00370         std::vector<QString> vo_urls;
00371         std::vector<QString> vo_labels;
00372         std::vector<QString> vo_labels_tip;
00373 
00374         QColor vo_default_bg;
00375                 struct dvo_working_item {
00376                         int id;
00377                         unsigned int count;
00378                         bool operator<( const dvo_working_item &other ) const { return id < other.id; }
00379                         operator int( ) const { return id; }
00380                         dvo_working_item( int i ) : id(i), count(0) { }
00381                         dvo_working_item( QDBusPendingReply<int> i ) : id(i), count(0) { }
00382                         // set find etc. yeilds constant iterators (even though changes to
00383                         // the set item may have no effect on set ordering...)
00384                         void increment( ) const { ((dvo_working_item*)this)->count += 1; }
00385                 };
00386                 std::set<dvo_working_item> dvo_working_set;
00387                 QPushButton *vo_current_action;
00388 
00389                 void vo_clear_status_delayed( int seconds );
00390                 void vo_action_with_timeout( int id, int seconds, QString msg );
00391                 bool vo_action_with_timeout_active( ) const { return vo_action_timeout->isActive( ); }
00392                 void vo_action_with_timeout_reset( ) {
00393                         if ( vo_action_with_timeout_active( ) ) vo_action_timeout->start( );
00394                 }
00395                 void vo_action_with_timeout_complete( );
00396 
00397     private slots:
00398 
00399                 void vo_service_select( const QString &service ) { vo_selected_service = service; }
00400                 void vo_selection_changed( );
00401 
00402                 void vo_clear_table( ) {
00403                         vo_table->clear( );
00404                         vo_table->setRowCount( 0 );
00405                         vo_init_columns( );
00406                         vo_label2col.clear( );
00407                         vo_urls.clear( );
00408                         vo_labels.clear( );
00409                         vo_labels_tip.clear( );
00410                 }
00411         void vo_launch_query( );
00412                 void vo_fetch_data( );
00413         void vo_clear_param( );
00414         void vo_query_begin( int, const QString&, const QtStringMap& );
00415         void vo_query_complete( int, const QString&, const QtStringMap& );
00416         void vo_query_description( int, const QString&, const QtStringMap& );
00417         void vo_query_row( int, const QString&, const QtStringMap& );
00418                 void vo_error( int, const QString&, const QString& );
00419                 void vo_dismiss_row( );
00420                 void vo_fetch_complete( int, QString );
00421                 void vo_fetch_progress(int,QString,double,double,double,double);
00422 
00423                 void vo_clear_status( );
00424                 void vo_disable_actions( );
00425                 void vo_enable_actions( );
00426                 void vo_action_timed_out( );
00427 
00428         private:
00429                 void error( const QString &msg ) {
00430                         vo_status->setStyleSheet("color: red");
00431                         vo_status->setText( msg );
00432                 }
00433                 void status( const QString &msg ) {
00434                         vo_status->setStyleSheet("color: black");
00435                         vo_status->setText( msg );
00436                 }
00437                 void warning( const QString &msg ) {
00438                         vo_status->setStyleSheet("color: orange");
00439                         vo_status->setText( msg );
00440                 }
00441 
00442                 void vo_init_columns( ) {
00443                         vo_table->setColumnCount( 2 );
00444                         vo_table->setColumnWidth(0,30);
00445                         QTableWidgetItem *first = new QTableWidgetItem( "" );
00446                         vo_table->setHorizontalHeaderItem(0,first);
00447                         QTableWidgetItem *second = new QTableWidgetItem( "1" );
00448                         vo_table->setHorizontalHeaderItem(1,second);
00449                 }
00450 
00451         QDoubleValidator *ra_val;
00452         QDoubleValidator *dec_val;
00453         QDoubleValidator *ra_size_val;
00454         QDoubleValidator *dec_size_val;
00455 
00456                 QTimer *vo_action_timeout;
00457                 int vo_action_timeout_id;
00458                 QString vo_action_timeout_msg;
00459                 bool vo_actions_are_enabled;
00460 
00461                 std::map<QString,QString> vo_service_name_to_url;
00462                 QString vo_selected_service;
00463                 std::vector<int> vo_selected_rows;
00464 
00465                 friend void lambda_dsoc_test_pre_( QtDataManager& );
00466         };
00467 
00468 } //# NAMESPACE CASA - END
00469 
00470 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1