00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef QTCANVAS_H
00027 #define QTCANVAS_H
00028
00029 #include <casa/aips.h>
00030 #include <casa/BasicSL/String.h>
00031 #include <casa/Containers/Record.h>
00032 #include <casa/Arrays/Array.h>
00033 #include <casa/Arrays/ArrayMath.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/Arrays/Matrix.h>
00036 #include <casa/Inputs/Input.h>
00037 #include <casa/Arrays/IPosition.h>
00038 #include <coordinates/Coordinates/SpectralCoordinate.h>
00039
00040 #include <display/QtPlotter/QtPlotSettings.h>
00041 #include <display/QtPlotter/CanvasCurve.h>
00042 #include <display/QtPlotter/WorldCanvasTranslator.h>
00043 #include <display/QtPlotter/ProfileFitMarker.h>
00044 #include <display/QtPlotter/MolecularLine.h>
00045 #include <display/QtPlotter/canvasMode/CanvasMode.h>
00046
00047 #include <graphics/X11/X_enter.h>
00048 #include <QDir>
00049 #include <QColor>
00050 #include <QHash>
00051 #include <QWidget>
00052 #include <QMouseEvent>
00053 #include <QToolButton>
00054 #include <QDialog>
00055 #include <QPixmap>
00056 #include <QVBoxLayout>
00057 #include <QPainterPath>
00058 #include <QLabel>
00059 #include <QMenu>
00060 #include <map>
00061 #include <vector>
00062 #include <graphics/X11/X_exit.h>
00063
00064 namespace casa {
00065
00066 class Annotation;
00067 class CanvasModeFactory;
00068
00069 #define QT_DIAMOND_SIZE 5
00070
00071 class GraphLabel {
00072 public:
00073 QString text;
00074 QString fontName;
00075 int fontSize;
00076 QColor color;
00077 GraphLabel() : text(""), fontName(""), fontSize(12), color(Qt::blue) {}
00078 };
00079
00080 class QtCanvas : public QWidget, public WorldCanvasTranslator {
00081 Q_OBJECT
00082
00083 friend class CanvasModeAnnotation;
00084 friend class CanvasModeRangeSelection;
00085 friend class CanvasModeChannel;
00086 friend class CanvasModeContextMenu;
00087 friend class CanvasModeZoom;
00088
00089 public:
00090 QtCanvas(QWidget *parent = 0);
00091
00092 void setPlotSettings(const QtPlotSettings &settings);
00093 void setTopAxisRange(const Vector<Float> &xValues, bool topAxisDescending );
00094 void setFrameMarker( float framePositionX );
00095 void setZoomRectColor( QColor color );
00096
00097
00098 void getCanvasDomain( double* minValue, double* maxValue, QString& units);
00099
00100 CurveData getCurveData(int);
00101 ErrorData getCurveError(int id);
00102 QString getCurveName(int id);
00103 void setCurveName(int id, const QString& name );
00104 void curveColorsChanged();
00105 QColor getCurveColor( int id );
00106 CanvasCurve getCurve( const QString& curveName );
00107 int getLineCount();
00108 void curveLabelsChanged();
00109 void clearCurve( bool inDtor=false );
00110 void clearFitCurves();
00111 void clearEverything();
00112 void clearMolecularLines( bool refresh = true );
00113 void setDataRange();
00114 void setImageMode(bool);
00115 QPixmap* graph();
00116 void drawBackBuffer(QPainter *);
00117
00118 void drawFrameMarker( QPainter* );
00119 QString getType( QtPlotSettings::AxisIndex axisIndex = QtPlotSettings::xBottom );
00120 QString getUnits( QtPlotSettings::AxisIndex axisIndex = QtPlotSettings::xBottom );
00121 QList<MolecularLine*> getMolecularLines() const;
00122 void setGaussianEstimateCount( int count );
00123
00124
00125 void plotPolyLines(QString);
00126 template<class T> void plotPolyLine(const Vector<T>&, const Vector<T>&,
00127 double beamAngle, double beamArea, SpectralCoordinate coord);
00128 void plotPolyLine(const Vector<Float> &x, const Vector<Float> &y, const Vector<Float> &e,
00129 double beamAngle, double beamArea, SpectralCoordinate coord, const QString& lb="");
00130 enum ColorCategory { TITLE_COLOR, CURVE_COLOR, CURVE_COLOR_PRIMARY,
00131 CURVE_COLOR_SECONDARY, WARNING_COLOR, CURVE_TRADITIONAL};
00132 void addPolyLine(const Vector<Float> &x, const Vector<Float> &y,
00133 double beamAngle, double beamArea, SpectralCoordinate coord,
00134 const QString& lb="", ColorCategory colorCategory=CURVE_COLOR );
00135 void addMolecularLine(MolecularLine* molecularLine );
00136 QList<QString> getMolecularLineNames() const;
00137
00138 template<class T> void plotPolyLine(const Matrix<T> &verts, double beamAngle,
00139 double beamArea, SpectralCoordinate coord, double restValue );
00140
00141 QSize minimumSizeHint() const;
00142 QSize sizeHint() const;
00143 ~QtCanvas();
00144
00145
00146 void setTitle(const QString &text, int fontSize = 13,const QString &font = FONT_NAME);
00147 QString getTitle() {
00148 return title.text;
00149 };
00150
00151 bool isShowChannelLine();
00152 void setShowChannelLine( bool showLine );
00153 void setChannelLineColor( QColor color );
00154
00155 void setXLabel(const QString &text, int fontSize = 10,
00156 const QString &font = FONT_NAME, QtPlotSettings::AxisIndex axisIndex=QtPlotSettings::xBottom);
00157 void setWelcome(const QString &text, int fontSize = 14,
00158 const QString &font = FONT_NAME);
00159 void setAutoScaleX(bool autoScale);
00160 void setAutoScaleY(bool autoScale);
00161 void setShowGrid(int a) {
00162 showGrid = a;
00163 refreshPixmap();
00164 }
00165 bool getAutoScaleX( ) {
00166 return autoScaleX;
00167 }
00168 bool getAutoScaleY( ) {
00169 return autoScaleY;
00170 }
00171 int getShowGrid( ) {
00172 return showGrid;
00173 }
00174 void setPlotError(int a) {
00175 plotError = a;
00176 setDataRange();
00177 }
00178
00179
00180 void setShowTopAxis( bool showAxis );
00181
00182
00183
00184
00185
00186
00187
00188 void setTopAxisCompatible( bool compatible );
00189
00190
00191
00192 void setShowToolTips( bool toolTipsVisible ) {
00193 showToolTips = toolTipsVisible;
00194 }
00195 bool getShowToolTips() const {
00196 return showToolTips;
00197 }
00198
00199
00200
00201 void setToolTipXUnit( const QString& xUnit ) {
00202 toolTipXUnit = xUnit;
00203 }
00204
00205
00206
00207 void setProfileFitMarkerCenterPeak( int index, double center, double peak);
00208
00209
00210
00211 void setProfileFitMarkerFWHM( int index, double fwhm, double fwhmHeight);
00212
00213
00214
00215 bool isDisplayStepFunction() const;
00216 void setDisplayStepFunction( bool displayAsStepFunction );
00217
00218
00219 void setTraditionalCurveColors( const QList<QString>& colors );
00220 void setMainCurveColors( const QList<QString>& colors );
00221 void setFitCurveColors( const QList<QString>& colors );
00222 void setSummaryCurveColors( const QList<QString>& colors );
00223
00224
00225 void setTraditionalColors( bool traditionalColors );
00226 static const QString FONT_NAME;
00227
00228
00229 void setShowLegend( bool visible );
00230 bool isShowLegend() const;
00231 void setLegendPosition( int position );
00232 int getLegendPosition() const;
00233
00234
00235 void setImageYUnits( const QString& imageUnits );
00236
00237
00238 enum TaskMode { SPECTRAL_LINE_MODE, LINE_OVERLAY_MODE, MODE_COUNT };
00239
00240
00241
00242
00243 QString getDisplayYUnits();
00244 void setDisplayYUnits( const QString& displayUnits );
00245
00246 int getCurZoom();
00247 int getZoomStackSize();
00248
00253 bool isTopAxisRange() const;
00254
00255
00256 void refreshPixmap();
00257
00258
00259 void setSpectralCoordinate( const SpectralCoordinate& coord );
00260
00261
00262 public slots:
00263 void zoomIn();
00264 void zoomOut();
00265 void zoomNeutral();
00266 void changeTaskMode( int mode );
00267 void createAnnotationText();
00268 void rangeSelectionMode();
00269 void channelPositioningMode();
00270
00271 signals:
00272 void xRangeChanged(double xmin, double xmax);
00273 void channelSelect(float xvalue);
00274 void specFitEstimateSpecified( double xValue, double yValue, bool centerPeak );
00275 void findRedshiftAt( double center, double peak );
00276 void channelRangeSelect( float startVal, float endVal );
00277 void curvesChanged();
00278 void clearPaletteModes();
00279 void togglePalette( int modeIndex );
00280
00281 protected:
00282 void paintEvent(QPaintEvent *event);
00283 void resizeEvent(QResizeEvent *event);
00284 void mousePressEvent(QMouseEvent *event);
00285 void mouseMoveEvent(QMouseEvent *event);
00286 void mouseReleaseEvent(QMouseEvent *event);
00287 void keyPressEvent(QKeyEvent *event);
00288 void keyReleaseEvent(QKeyEvent *event);
00289 void wheelEvent(QWheelEvent *event);
00290
00291 void updateRubberBandRegion();
00292 void updatexRangeBandRegion();
00293 void drawGrid(QPainter *painter);
00294 void drawTicks(QPainter *painter);
00295 void drawLabels(QPainter *painter);
00296 void drawWelcome(QPainter *painter);
00297 void drawCurves(QPainter *painter);
00298
00299 private slots:
00300 void deleteSelectedAnnotation();
00301 void editSelectedAnnotation();
00302 void gaussianCenterPeakSelected();
00303 void gaussianFWHMSelected();
00304 void findRedshift();
00305
00306 private:
00307
00308
00309 void zoomYBasedOnX( QtPlotSettings& settings, double zoomFactor, bool zoomIn );
00310 pair<double,double> getRangeFor( double zoomFactor, bool zoomIn, double minX, double maxX );
00311 void increaseCurZoom();
00312 void defaultZoomIn();
00313 void defaultZoomOut();
00314
00324 void setCurveData(int id, const CurveData &data, double beamAngle, double beamArea,
00325 SpectralCoordinate coord, const ErrorData &error=ErrorData(),
00326 const QString& lb="", ColorCategory colorCategory = CURVE_COLOR);
00327
00328
00333 void displayToolTip( QMouseEvent* event ) const;
00334
00339 void adjustExtremes( double* const min, double* const max ) const;
00340
00346 double getDataY( int pixelPosition ) const;
00347
00353 double getDataX( int pixelPosition ) const;
00354
00355
00361 int getPixelX( double dataX ) const;
00362
00368 int getPixelY ( double dataY ) const;
00369
00380 QString findCoords( double x, double y ) const;
00381
00385 int getRectHeight() const;
00386
00390 int getRectWidth() const;
00391
00395 int getRectBottom() const;
00396
00400 int getRectLeft() const;
00401
00410 QString getXTickLabel( int index, int tickCount, QtPlotSettings::AxisIndex axisIndex ) const;
00411
00417 void initContextMenu();
00418 void addDiamond( int x, int y, int diamondSize, QPainterPath& points ) const;
00419 bool storeClickPosition( QMouseEvent* event );
00420 int getIndependentCurveCount();
00421 int getLastAxis();
00422 void stripCurveTitleNumbers( QString& curveName ) const;
00423 int duplicateCurve( QString& targetLabel );
00424
00425 void setYLabel(const QString &text, int fontSize = 10, const QString &font = FONT_NAME);
00426
00427
00428 void selectAnnotation( QMouseEvent* event, bool select = true );
00429 bool isAnnotation( QMouseEvent* event ) const;
00430 Annotation* getSelectedAnnotation() const;
00431
00432
00433 void storeActiveAnnotation( QMouseEvent* event );
00434 void selectChannel( QMouseEvent* event );
00435 void updateChannel( QMouseEvent* event );
00436 void startRangeX( QMouseEvent* event );
00437 void updateRangeX( QMouseEvent* event );
00438 void endRangeX( QMouseEvent* event );
00439 void startZoomRect( QMouseEvent* event );
00440 void updateZoomRect( QMouseEvent* event );
00441 void endZoomRect( QMouseEvent* event );
00442 void resetSelectedAnnotation( QMouseEvent* event );
00443 void drawMolecularLines( QPainter& painter );
00444 void drawAnnotations( QPainter& painter );
00445
00446
00447 const int MARGIN_LEFT;
00448 const int MARGIN_BOTTOM;
00449 const int MARGIN_TOP;
00450 const int MARGIN_RIGHT;
00451 const int FRACZOOM;
00452
00453
00454 GraphLabel title;
00455 GraphLabel xLabel[2];
00456 GraphLabel yLabel;
00457 GraphLabel welcome;
00458
00459 std::map<int, CanvasCurve> curveMap;
00460 std::vector<QtPlotSettings> zoomStack;
00461 QList<MolecularLine*> molecularLineStack;
00462 std::pair<double,double> topAxisRange;
00463
00464 int curZoom;
00465 int curMarker;
00466 bool rubberBandIsShown;
00467 bool xRangeIsShown;
00468 bool imageMode;
00469 bool xRangeMode;
00470 double xRangeStart;
00471 double xRangeEnd;
00472 QRect rubberBandRect;
00473 QRect xRangeRect;
00474 QPixmap pixmap;
00475 QPixmap backBuffer;
00476 Matrix<uInt> *pMask;
00477
00478 QPoint currentCursorPosition;
00479 QColor xcursor;
00480
00481 bool autoScaleX;
00482 bool autoScaleY;
00483 int plotError;
00484 int showGrid;
00485
00486 int xRectStart;
00487 int xRectEnd;
00488
00489
00490 bool showTopAxis;
00491
00492
00493 bool topAxisCompatible;
00494 bool showToolTips;
00495 bool showFrameMarker;
00496 bool displayStepFunction;
00497 QString toolTipXUnit;
00498 QString yUnitImage;
00499 QString yUnitDisplay;
00500
00501
00502 QMenu contextMenu;
00503 QAction* centerPeakAction;
00504 QAction* fwhmAction;
00505 QAction* findRedshiftAction;
00506 QAction* createAnnotationAction;
00507 QAction* editAnnotationAction;
00508 QAction* deleteAnnotationAction;
00509 void showContextMenu( QMouseEvent* event );
00510
00511
00512 double gaussianEstimateX;
00513 double gaussianEstimateY;
00514 QList<ProfileFitMarker> profileFitMarkers;
00515
00516 ProfileFitMarker getMarker( int index ) const;
00517 void setMarker( int index, ProfileFitMarker& marker );
00518
00519
00527 QColor getDiscreteColor(ColorCategory colorCategory, int id=0);
00528 QColor frameMarkerColor;
00529 QColor zoomColor;
00530 QList<QString> mainCurveColorList;
00531 QList<QString> fitCurveColorList;
00532 QList<QString> fitSummaryCurveColorList;
00533 QList<QString> traditionalCurveColorList;
00534
00535 int curveCount;
00536 int curveCountPrimary;
00537 int curveCountSecondary;
00538
00539
00540
00541
00542 bool traditionalColors;
00543
00544
00545 bool showLegend;
00546
00547
00548
00549 int legendPosition;
00550
00551
00552
00553 float framePositionX;
00554
00555
00556 TaskMode taskMode;
00557
00558 float channelSelectValue;
00559
00560
00561
00562 int gaussEstimateCount;
00563
00564 Annotation* selectedAnnotation;
00565 vector<Annotation*> annotations;
00566
00567
00568
00569 bool isAnnotationActive() const;
00570
00571 Annotation* getActiveAnnotation() const;
00572 CanvasMode* currentMode;
00573 CanvasModeFactory* modeFactory;
00574 SpectralCoordinate m_spectralCoordinate;
00575 };
00576
00577 }
00578 #endif
00579