casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SearchMoleculesWidget.qo.h
Go to the documentation of this file.
00001 //# Copyright (C) 2005
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 
00026 #ifndef SEARCHMOLECULESWIDGET_QO_H_1
00027 #define SEARCHMOLECULESWIDGET_QO_H_1
00028 
00029 #include <QtGui/QWidget>
00030 #include <QMap>
00031 #include <QThread>
00032 #include <QProgressDialog>
00033 #include <display/QtPlotter/SearchMoleculesWidget.ui.h>
00034 #include <measures/Measures/MRadialVelocity.h>
00035 #include <measures/Measures/MDoppler.h>
00036 #include <display/QtPlotter/conversion/Converter.h>
00037 #include <spectrallines/Splatalogue/Searcher.h>
00038 #include <spectrallines/Splatalogue/SearcherFactory.h>
00039 #include <display/QtPlotter/SearchMoleculesResultDisplayer.h>
00040 #include <QDebug>
00041 
00042 class QTimer;
00043 
00044 namespace casa {
00045 
00046 class QtCanvas;
00047 
00052 class SearchThread : public QThread {
00053 public:
00054         SearchThread( Searcher* searcher, int offset ){
00055                 this->searcher= searcher;
00056                 this->offset = offset;
00057                 countNeeded = true;
00058         }
00059         String getErrorMessage() const {
00060                 return errorMsg;
00061         }
00062         String getErrorMessageCount() const {
00063                 return errorMsgCount;
00064         }
00065 
00066         void setCountNeeded( bool needed ){
00067                 countNeeded = needed;
00068         }
00069 
00070         long getResultsCount() const {
00071                 return searchResultsCount;
00072         }
00073 
00074         vector<SplatResult> getResults() const {
00075                 return searchResults;
00076         }
00077 
00078         void stopSearch(){
00079                 searcher->stopSearch();
00080         }
00081 
00082         void run(){
00083                 if ( offset == 0 && countNeeded ){
00084                         searchResultsCount = searcher->doSearchCount( errorMsgCount );
00085                 }
00086                 else {
00087                         searchResultsCount = 1;
00088                 }
00089                 if ( searchResultsCount > 0 ){
00090                         searchResults = searcher->doSearch( errorMsg, offset );
00091                 }
00092         }
00093         ~SearchThread(){
00094         }
00095 private:
00096         Searcher* searcher;
00097         int searchResultsCount;
00098         int offset;
00099         bool countNeeded;
00100         vector<SplatResult> searchResults;
00101         string errorMsg;
00102         string errorMsgCount;
00103 };
00104 
00105 
00106 class SearchMoleculesWidget : public QWidget
00107 {
00108     Q_OBJECT
00109 
00110 public:
00111     SearchMoleculesWidget(QWidget *parent = 0);
00112     void setCanvas( QtCanvas* drawCanvas );
00113     QString getUnit() const;
00114     bool isLocal() const;
00115 
00116     void setRange( double min, double max, QString units );
00117     void updateReferenceFrame();
00118     static void setInitialReferenceFrame( QString initialReferenceStr );
00119     void setResultDisplay( SearchMoleculesResultDisplayer* resultDisplay );
00120     double getRedShiftedValue( bool reverseRedshift, double value ) const;
00121 
00122     vector<SplatResult> getSearchResults() const;
00123     MDoppler::Types getDopplerType() const;
00124     MRadialVelocity::Types getReferenceFrame() const;
00125     ~SearchMoleculesWidget();
00126     static const QString SPLATALOGUE_UNITS;
00127 
00128 signals:
00129         void searchCompleted();
00130 
00131 private slots:
00132     void search();
00133     void searchUnitsChanged( const QString& searchUnits );
00134     void dopplerShiftChanged();
00135     void dopplerVelocityUnitsChanged();
00136     void searchFinished();
00137     void prevResults();
00138     void nextResults();
00139     void stopSearch();
00140 
00141 private:
00142 
00143     static QString initialReferenceStr;
00144 
00145     void setAstronomicalFilters( Searcher* searcher );
00146     void convertRangeLineEdit( QLineEdit* lineEdit, Converter* converter );
00147     void initializeSearchRange( QLineEdit* lineEdit, Double& value );
00148     vector<string> initializeChemicalNames();
00149     void startSearchThread();
00150     void setSearchRangeDefault();
00151     void setRangeValue( double value, QString units, QLineEdit* lineEdit );
00152 
00153     MDoppler getRedShiftAdjustment( bool reverseRedshift) const;
00154 
00155     enum AstroFilters { NONE, TOP_20, PLANETARY_ATMOSPHERE,HOT_CORES,
00156                 DARK_CLOUDS,DIFFUSE_CLOUDS,COMETS, AGB_PPN_PN,EXTRAGALACTIC };
00157 
00158     Ui::SearchMoleculesWidget ui;
00159 
00160     QString unitStr;
00161     QString dopplerVelocityUnitStr;
00162     vector<SplatResult> searchResults;
00163     QList<QString> velocityUnitsList;
00164     QMap<QString, MRadialVelocity::Types> radialVelocityTypeMap;
00165     QMap<QString, MDoppler::Types> dopplerTypeMap;
00166     bool dopplerInVelocity;
00167     bool searchInterrupted;
00168     SearchThread* searchThread;
00169     Searcher* searcher;
00170     QtCanvas* canvas;
00171     QProgressDialog progressBar;
00172 
00173 
00174     //Scrolling support
00175     int searchResultCount;
00176     int searchResultOffset;
00177     int searchResultLimit;
00178 
00179     static const double SPLATALOGUE_DEFAULT_MIN;
00180     static const double SPLATALOGUE_DEFAULT_MAX;
00181     SearchMoleculesResultDisplayer* resultDisplay;
00182 };
00183 
00184 }
00185 
00186 #endif // SEARCHMOLECULESWIDGET_H