casa
$Rev:20696$
|
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 00027 #ifndef TQDRAWCANVAS_H 00028 #define TQDRAWCANVAS_H 00029 00030 #include <casa/aips.h> 00031 #include <casa/BasicSL/String.h> 00032 #include <casa/Containers/Record.h> 00033 #include <casa/Arrays/Array.h> 00034 #include <casa/Arrays/ArrayMath.h> 00035 #include <casa/Arrays/Vector.h> 00036 #include <casa/Arrays/Matrix.h> 00037 #include <casa/Inputs/Input.h> 00038 #include <casa/Arrays/IPosition.h> 00039 00040 #include <display/QtPlotter/QtDrawSettings.h> 00041 00042 #include <graphics/X11/X_enter.h> 00043 #include <QDir> 00044 #include <QColor> 00045 #include <QHash> 00046 #include <QWidget> 00047 #include <QMouseEvent> 00048 #include <QToolButton> 00049 #include <QDialog> 00050 #include <QPixmap> 00051 #include <QVBoxLayout> 00052 #include <QLabel> 00053 #include <map> 00054 #include <vector> 00055 #include <graphics/X11/X_exit.h> 00056 00057 namespace casa { 00058 00059 typedef std::vector<double> CurveData; 00060 00061 class GraphLabel 00062 { 00063 public: 00064 QString text; 00065 QString fontName; 00066 int fontSize; 00067 QColor color; 00068 GraphLabel() : text(""), fontName("Helvetica [Cronyx]"), 00069 fontSize(12), color(Qt::blue) {} 00070 }; 00071 00072 class QtDrawCanvas : public QWidget 00073 { 00074 Q_OBJECT 00075 public: 00076 enum {LINE = 0, POINT, FPOINT, CIRCLE, FCIRCLE, 00077 RECT, FRECT, DIM, FDIM, 00078 PLUS, FPLUS, CROSS, FCROSS, 00079 TRIGU, FTRIGU, TRIGD, FTRIGD, 00080 TRIGL, FTRIGL, TRIGR, FTRIGR, 00081 SAND, FSAND, WING, FWING, 00082 BEAM, FBEAM, BED, FBED, 00083 HIST, FHIST}; 00084 QtDrawCanvas(QWidget *parent = 0); 00085 00086 void setPlotSettings(const QtDrawSettings &settings); 00087 void setCurveData(int id, const CurveData data, 00088 int tp = 0, int cl = 0); 00089 void clearCurve(int id); 00090 void setDataRange(); 00091 void setImageMode(bool); 00092 void setPixmap(const QImage&); 00093 QPixmap* graph(); 00094 void drawBackBuffer(QPainter *); 00095 void plotPolyLines(QString); 00096 00097 //ln = 0, new chart 00098 //ln < 0, remove trace 00099 //ln > 0, append trace if ln exists, otherwise add trace 00100 //tp = 0, continous line 00101 //tp > 0, discrete symbols 00102 //tp < 0, line and symbols 00103 //cl, color value range from 0 up 00104 void plotPolyLine(const Vector<Int>&, 00105 const Vector<Int>&, 00106 int ln = 0, int tp = 0, int cl = 0); 00107 void plotPolyLine(const Vector<Float> &x, 00108 const Vector<Float> &y, 00109 int ln = 0, int tp = 0, int cl = 0); 00110 void plotPolyLine(const Vector<Double>&, 00111 const Vector<Double>&, 00112 int ln = 0, int tp = 0, int cl = 0); 00113 00114 //Each row is a trace 00115 //ln = 0, new chart 00116 //ln < 0, remove traces 00117 //ln > 0, append traces from (ln)th, add if not exists 00118 //tp < 0, same shape for all traces 00119 //tp = 0, continuous lines 00120 //tp > 0, different discrete shape for each trace 00121 //cl > 0, different color for each trace 00122 //cl <= 0, same color for all traces 00123 void plotPolyLine(const Matrix<Int> &verts, 00124 int ln = 0, int tp = 0, int cl = 0); 00125 void plotPolyLine(const Matrix<Float> &verts, 00126 int ln = 0, int tp = 0, int cl = 0); 00127 void plotPolyLine(const Matrix<Double> &verts, 00128 int ln = 0, int tp = 0, int cl = 0); 00129 00130 // template<class T> 00131 void drawImage(const Matrix<uInt> &data, Matrix<uInt> *mask); 00132 void drawImage(const Matrix<uInt> &data); 00133 //void setMarkMode(bool); 00134 00135 QColor getLinearColor(double); 00136 QSize minimumSizeHint() const; 00137 QSize sizeHint() const; 00138 ~QtDrawCanvas(); 00139 void increaseCurZoom(); 00140 int getCurZoom(); 00141 int getZoomStackSize(); 00142 int getCurLine(); 00143 int getTotalLines(); 00144 00145 void setTitle(const QString &text, 00146 int fontSize = 12, int color = 0, 00147 const QString &font = "Helvetica [Cronyx]"); 00148 void setXLabel(const QString &text, 00149 int fontSize = 10, int color = 1, 00150 const QString &font = "Helvetica [Cronyx]"); 00151 void setYLabel(const QString &text, 00152 int fontSize = 10, int color = 2, 00153 const QString &font = "Helvetica [Cronyx]"); 00154 void setWelcome(const QString &text, int fontSize = 14, 00155 int color = 1, 00156 const QString &font = "Helvetica [Cronyx]"); 00157 00158 public slots: 00159 void zoomIn(); 00160 void zoomOut(); 00161 void markPrev(); 00162 void markNext(); 00163 00164 signals: 00165 void zoomChanged(); 00166 void gotFocus(); 00167 00168 protected: 00169 void paintEvent(QPaintEvent *event); 00170 void resizeEvent(QResizeEvent *event); 00171 void mousePressEvent(QMouseEvent *event); 00172 void mouseMoveEvent(QMouseEvent *event); 00173 void mouseReleaseEvent(QMouseEvent *event); 00174 void keyPressEvent(QKeyEvent *event); 00175 void wheelEvent(QWheelEvent *event); 00176 void focusInEvent(QFocusEvent *event); 00177 00178 private: 00179 void updateRubberBandRegion(); 00180 void refreshPixmap(); 00181 void drawGrid(QPainter *painter); 00182 void drawTicks(QPainter *painter); 00183 void drawLabels(QPainter *painter); 00184 void drawWelcome(QPainter *painter); 00185 void drawCurves(QPainter *painter); 00186 void drawRects(QPainter *painter); 00187 00188 enum { Margin = 60 }; 00189 00190 GraphLabel title; 00191 GraphLabel xLabel; 00192 GraphLabel yLabel; 00193 GraphLabel welcome; 00194 00195 std::map<int, CurveData> curveMap; 00196 std::map<int, int> typeMap; 00197 std::map<int, int> colorMap; 00198 int curLine; 00199 00200 std::vector<QtDrawSettings> zoomStack; 00201 int curZoom; 00202 00203 std::map<int, CurveData> markerStack; 00204 int curMarker; 00205 00206 QRect rubberBandRect; 00207 bool rubberBandIsShown; 00208 00209 bool imageMode; 00210 bool markMode; 00211 00212 QPixmap pixmap; 00213 QPixmap backBuffer; 00214 Matrix<uInt> *pMask; 00215 00216 }; 00217 00218 } 00219 #endif 00220