casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBPlotter.qo.h
Go to the documentation of this file.
00001 //# TBPlotter.qo.h: Widget to collect plot parameters and plot on the canvas.
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 #ifndef TBPLOTTER_H_
00028 #define TBPLOTTER_H_
00029 
00030 #include <casaqt/QtBrowser/TBPlotter.ui.h>
00031 #include <casaqt/QtBrowser/TBPlotCanvas.qo.h>
00032 #include <casaqt/QtBrowser/TBConstants.h>
00033 #include <graphics/GenericPlotter/PlotFactory.h>
00034 
00035 #include <QtGui>
00036 #include <QtGui/QStandardItemModel>
00037 
00038 #include <map>
00039 #include <vector>
00040 
00041 #include <casa/BasicSL/String.h>
00042 
00043 #include <casa/namespace.h>
00044 using namespace std;
00045 
00046 namespace casa {
00047 
00048 //# Forward Declarations
00049 class TBBrowser;
00050 class TBPlotCanvas;
00051 class QProgressPanel;
00052 class TBTableTabs;
00053 
00054 // <summary>
00055 // Parameters for a single field for collecting plotting data.
00056 // </summary>
00057 //
00058 // <synopsis>
00059 // A PlotParams accompanies each axis when plot data is being collected.
00060 // A PlotParams indicates which field is being plotted and other important
00061 // parameters.
00062 // </synopsis>
00063 
00064 class PlotParams {
00065 public:
00066     // Default Constructor
00067     PlotParams(): rowNumbers(false), complex(false), complexAmp(false),
00068                   colIndex(0) { }
00069 
00070     
00071     // Indicates whether this plot axis is only the row numbers (true) or an
00072     // actual field (false).
00073     bool rowNumbers;
00074 
00075     // Indicates whether this field is complex or not.
00076     bool complex;
00077 
00078     // If the field is complex, indicates whether the amplitude (true) or the
00079     // phase (false) is used.
00080     bool complexAmp;
00081 
00082     // Indicates which field index is to be used.
00083     unsigned int colIndex;
00084 
00085     // If the field is an array, indicates the array slice to be used.
00086     vector<int> slice;
00087 };
00088 
00089 // <summary>
00090 // Data for plotting.
00091 // </summary>
00092 //
00093 // <synopsis>
00094 // A TBPlotData holds two double arrays and the number of points.
00095 // </synopsis>
00096 
00097 class TBPlotData {
00098 public:
00099     // Default Constructor.
00100     TBPlotData() { }
00101     
00102     // Constructor which takes the number of points and the two arrays.
00103     TBPlotData(PlotPointDataPtr d) : data(d) { }
00104     
00105     ~TBPlotData() { }
00106     
00107     // Actual data.
00108     PlotPointDataPtr data;
00109     
00110     // Table this data is from.
00111     TBTableTabs* table;
00112     
00113     // Row numbers that correspond to the given data.  In the future may want
00114     // to replace with a less memory-heavy implementation.
00115     vector<int> rows;
00116     
00117     // Title for the plot; usually xAxisName vs. yAxisName
00118     String title;
00119 };
00120 
00121 // <summary>
00122 // Small widget to provide a variable number of spinners to create a slice.
00123 // </summary>
00124 //
00125 // <synopsis>
00126 // A PlotSlicer provides a variable number of QSpinBoxes to allow the user
00127 // to enter an array slice.  The number of spinners depends on the
00128 // dimensionality (i.e., a two-dimensional array will have two spinners).  The
00129 // range of the spinners depends on the array's shape (i.e., a 4x2 array will
00130 // have a [0, 3] range on the first spinner and a [0, 1] range on the second
00131 // spinner).  A PlotSlicer can also display a QComboBox to allow the user to
00132 // choose between phase and amplitude for complex numbers.
00133 // </synopsis>
00134 
00135 class PlotSlicer : public QHBoxLayout {
00136     Q_OBJECT
00137     
00138 public:
00139     // Default Constructor.
00140     PlotSlicer();
00141 
00142     ~PlotSlicer();
00143 
00144     
00145     // Sets the dimensions of the slicer to the given vector.  If complex is
00146     // true, a combobox to choose between phase and amplitude is also shown.
00147     // If index is true, a spinbox to select plot axis is also shown.
00148     bool setDimension(vector<int>* d, bool complex = false);
00149     bool setDimension(vector<int>* d, bool complex, bool index);
00150 
00151     // Retrieves the array slice into the given vector.  complex is set to true
00152     // if the slice is for complex numbers; if complex is true, amp indicates
00153     // whether the slice is for the amplitude (true) or the phase (false).
00154     void getDimension(vector<int>& d, bool& complex, bool& amp);
00155     void getDimension(vector<int>& d, bool& complex, bool& amp, int& axis);
00156 
00157 private:
00158     // All current spinners.
00159     vector<QSpinBox*> spinners;
00160 
00161     // Complex chooser.
00162     QComboBox* complexChooser;
00163 
00164     // Whether the current slice is for a complex or not.
00165     bool complex;
00166 
00167     // Spinbox and Label to choose axis
00168     QSpinBox* plotAxisChooser;
00169     QLabel* axisLabel;
00170 
00171 private slots:
00172     void axisChosen(int axis);
00173 };
00174 
00175 // <summary>
00176 // Widget to collect plot parameters and plot on the canvas.
00177 // </summary>
00178 //
00179 // <synopsis>
00180 // A TBPlotter consists of a TBPlotCanvas and other widgets to control plot
00181 // parameters and other options.  The TBPlotter has four sections in a vertical
00182 // layout.  The first section is the TBPlotCanvas.  The second is the data
00183 // parameters: which table and rows to use, which fields to plot, etc.  The
00184 // third is the graph format: scatter vs. line, point formatting, etc.  The
00185 // fourth are plotting tools such as saving as an image.
00186 // </synopsis>
00187 
00188 class TBPlotter : public QMainWindow, public Ui::Plotter {
00189     Q_OBJECT
00190     
00191 public:
00192     // Constructor that takes the parent browser.
00193     TBPlotter(TBBrowser* browser, PlotFactoryPtr factory);
00194 
00195     ~TBPlotter();
00196 
00197     
00198     // Adds a QProgressPanel to the plotter with the given parameters and
00199     // returns it.
00200     QProgressPanel* addProgressPanel(String label, bool hideable,
00201                                      bool cancelable);
00202 
00203     // Removes the given QProgressPanel from the plotter.
00204     void removeProgressPanel(QProgressPanel* panel);
00205     
00206 protected:
00207     // Capture when the window closes.  If the parameters dock widget is
00208     // floating, close it manually.
00209     void closeEvent(QCloseEvent* event);
00210 
00211 private:
00212     // Parent browser.
00213     TBBrowser* browser;
00214     
00215     // Plotter factory
00216     PlotFactoryPtr factory;
00217 
00218     // For each table the plotter knows about, the dimensions of the fields are
00219     // kept for fast access.  So, for example, the dimensions of a field can be
00220     // found with dimensions[tableName][columnIndex].
00221     map<String, vector<vector<int>*> > dimensions;
00222 
00223     // Since only certain field types are plottable, adjustedIndices allows for
00224     // translation between the index of the combobox (which contains only
00225     // plottable fields) and the index in the table (which contains all
00226     // fields).  So, for example, adjustedIndices[plottableIndex] = tableIndex.
00227     vector<int> adjustedIndices;
00228 
00229     // PlotSlicer for the x-axis.
00230     PlotSlicer xSlice;
00231 
00232     // PlotSlicer for the y-axis.
00233     PlotSlicer ySlice;
00234 
00235     // Types for the displayed plottable fields.
00236     vector<String> types;
00237 
00238     // Is true if the current selection for the x-axis is valid, false
00239     // otherwise.  If the axis is invalid, it cannot be used for plotting.
00240     bool xValid;
00241 
00242     // Is true if the current selection for the x-axis is valid, false
00243     // otherwise.  If the axis is invalid, it cannot be used for plotting.
00244     bool yValid;
00245 
00246     // Flag to indicate whether GUI-generated events are "genuine."
00247     bool update;
00248 
00249     // Plot canvas.
00250     TBPlotCanvas* plotCanvas;
00251 
00252     
00253     // Collects the parameters and plots as indicated.
00254     void doPlot(bool overplot = true);
00255 
00256     // Model for xChooser and yChooser to disable [index] selection
00257     QStandardItemModel* xChooserModel;
00258     QStandardItemModel* yChooserModel;
00259 
00260     // Flag to indicate whether index based plot is selected or not
00261     bool isIndexPlot;
00262 
00263     // Show/Hide row iteration GUI when [index] is deselected/selected.
00264     void enableRowIteration(bool visible);
00265     
00266 private slots:
00267     // Slot for when the user chooses a different table from the combobox.
00268     // Updates the displayed options for the table.
00269     void tableChosen(QString name);
00270 
00271     // Slot for when the user chooses a field for the x-axis.
00272     void xChosen(int x);
00273 
00274     // Slot for when the user chooses a field for the y-axis.
00275     void yChosen(int y);
00276     
00277     // Slot for code common to xChosen and yChosen.
00278     void chosen(bool x, int i);
00279 
00280     // Slot for when [index] is chosen
00281     void indexChosen(bool x);
00282 
00283     // Slot for when [index] is deselected
00284     void indexReleased(bool x, int i);
00285 
00286     // Slot for the "Clear and Plot" button.  See doPlot(false);
00287     void plot();
00288 
00289     // Slot for the "Overplot" button.  See doPlot(true);
00290     void overplot();
00291 
00292     // Opens a new TBPlotter window.
00293     void openNewPlotter();
00294 
00295     // Slot for when a table is opened in the browser.  Adds the table name
00296     // to the list of opened tables.
00297     void tableOpened(String table, String fullpath);
00298 
00299     // Slot for when a table is closed in the browser.  Removes the table
00300     // name from the list of opened tables.
00301     void tableClosed(String table);
00302 
00303     // Slot for the "Clear" button.  See TBPlotCanvas::clearAndHideAxes().
00304     void clear();
00305 
00306     // Slot for the "All Rows" button.  Sets the row selection to be all the
00307     // rows in the currently selected table.
00308     void allRows();
00309 
00310     // Slot to open a QColorDialog for the given line edit.
00311     void setColor(QLineEdit* lineEdit);
00312 
00313     // Convenience slot
00314     void setLineColor() { setColor(lineColorEdit); }
00315     
00316     // Convenience slot
00317     void setSymbolColor() { setColor(symbolColorEdit); }
00318     
00319     // Slot to export the current plot canvas to the image format specified
00320     // by the QComboBox.
00321     void exportImage();
00322     
00323     // Slot for when the user enters a filter rule for the table at the given
00324     // index.
00325     void filterRuleEntered(int i);
00326     
00327     // Slot for when the user enters a filter rule for the table at the given
00328     // index.
00329     void filterRuleCleared(int i);
00330     
00331     // Slot for when the user changes the grid options.
00332     void gridChanged();
00333     
00334     void regionSelected(bool selected);
00335     
00336     // Slot for when the user clicks "locate".
00337     void selectLocate();
00338     
00339     // Slot for when the user clears the currently selected region.
00340     void clearSelection();
00341 };
00342 
00343 }
00344 
00345 #endif /* TBPLOTTER_H_ */