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
00027 #ifndef RSUTILS_QO_H_
00028 #define RSUTILS_QO_H_
00029
00030 #include <QtGui>
00031
00032 #include <casa/BasicSL/String.h>
00033 #include <display/Display/WorldCanvasHolder.h>
00034 #include <display/Display/WorldCanvas.h>
00035 #include <measures/Measures/MCDirection.h>
00036 #include <measures/Measures/MDirection.h>
00037
00038 #include <casa/namespace.h>
00039
00040 namespace casa {
00041
00042 class QtColorWidget;
00043
00044
00045 class RSUtils {
00046 public:
00047
00048
00049
00050 static QHBoxLayout* hlayout(QWidget* parent = NULL);
00051 static QVBoxLayout* vlayout(QWidget* parent = NULL);
00052
00053
00054
00055
00056
00057 static void setupLayout(QLayout* layout);
00058
00059
00060
00061 static QWidget* hline();
00062 static QWidget* vline();
00063
00064
00065
00066
00067
00068 static QtColorWidget* colorWidget(bool showButton = false,
00069 String setColor = "",
00070 QWidget* parent = NULL);
00071
00072
00073
00074
00075 static const String PIXEL;
00076
00077
00078
00079
00080
00081 static bool hasDirectionCoordinate(const DisplayCoordinateSystem& cs);
00082 static bool hasDirectionCoordinate(const WorldCanvas* wc) {
00083 return wc != NULL && hasDirectionCoordinate(wc->coordinateSystem());
00084 }
00085 static bool hasDirectionCoordinate(const WorldCanvasHolder& wch) {
00086 return hasDirectionCoordinate(wch.worldCanvas()->coordinateSystem());
00087 }
00088
00089
00090
00091 static MDirection::Types worldSystem(const DisplayCoordinateSystem& cs);
00092
00093
00094 static MDirection::Types worldSystem(const WorldCanvas* wc) {
00095 return worldSystem(wc->coordinateSystem());
00096 }
00097
00098
00099 static MDirection::Types worldSystem(const WorldCanvasHolder& wch) {
00100 return worldSystem(wch.worldCanvas()->coordinateSystem());
00101 }
00102
00103
00104
00105 static bool convertWCS(const Quantum<Vector<Double> >& from,
00106 MDirection::Types fromSys,
00107 Quantum<Vector<Double> >& to,
00108 MDirection::Types toSys);
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 static bool worldToPixel(const Quantum<Vector<double> >& worldX,
00120 const Quantum<Vector<double> >& worldY,
00121 Vector<double>& pixelX, Vector<double>& pixelY,
00122 WorldCanvasHolder& wch, MDirection::Types fromSys,
00123 bool wrap = true, String* error = NULL);
00124
00125 static bool pixelToWorld(const Vector<double>& pixelX,
00126 const Vector<double>& pixelY,
00127 Quantum<Vector<double> >& worldX,
00128 Quantum<Vector<double> >& worldY,
00129 WorldCanvasHolder& wch, MDirection::Types toSys,
00130 bool wrap = true, String* error = NULL);
00131
00132 static bool worldToLinear(const Quantum<Vector<double> >& worldX,
00133 const Quantum<Vector<double> >& worldY,
00134 Vector<double>& linearX, Vector<double>& linearY,
00135 WorldCanvasHolder& wch, MDirection::Types fromSys,
00136 bool wrap = true, String* error = NULL);
00137
00138 static bool pixelToLinear(const Vector<double>& pixelX,
00139 const Vector<double>& pixelY,
00140 Vector<double>& linearX, Vector<double>& linearY,
00141 WorldCanvasHolder& wch, String* error = NULL);
00142
00143 static bool linearToScreen(const Vector<double>& linearX,
00144 const Vector<double>& linearY,
00145 Vector<double>& screenX, Vector<double>& screenY,
00146 WorldCanvasHolder& wch, String* error = NULL);
00147
00148 static bool worldToScreen(const Quantum<Vector<double> >& worldX,
00149 const Quantum<Vector<double> >& worldY,
00150 Vector<double>& screenX, Vector<double>& screenY,
00151 WorldCanvasHolder& wch, MDirection::Types fromSys,
00152 bool wrap = true, String* error = NULL) {
00153 Vector<double> linX(worldX.getValue().size()),
00154 linY(worldY.getValue().size());
00155 return worldToLinear(worldX, worldY, linX, linY, wch, fromSys, wrap,
00156 error) && linearToScreen(linX,linY,screenX,screenY,wch,error);
00157 }
00158
00159 static bool pixelToScreen(const Vector<double>& pixelX,
00160 const Vector<double>& pixelY,
00161 Vector<double>& screenX, Vector<double>& screenY,
00162 WorldCanvasHolder& wch, String* error = NULL) {
00163 Vector<double> linX(pixelX.size()), linY(pixelY.size());
00164 return pixelToLinear(pixelX, pixelY, linX, linY, wch, error) &&
00165 linearToScreen(linX, linY, screenX, screenY, wch, error);
00166 }
00167
00168 static bool screenToLinear(const Vector<double>& screenX,
00169 const Vector<double>& screenY,
00170 Vector<double>& linearX, Vector<double>& linearY,
00171 WorldCanvasHolder& wch, String* error = NULL);
00172
00173 static bool linearToWorld(const Vector<double>& linearX,
00174 const Vector<double>& linearY,
00175 Quantum<Vector<double> >& worldX,
00176 Quantum<Vector<double> >& worldY,
00177 WorldCanvasHolder& wch, MDirection::Types toSys,
00178 const vector<int>& xSign,const vector<int>& ySign,
00179 bool wrap = true, String* error = NULL);
00180
00181 static bool linearToWorld(const Vector<double>& linearX,
00182 const Vector<double>& linearY,
00183 Quantum<Vector<double> >& worldX,
00184 Quantum<Vector<double> >& worldY,
00185 WorldCanvasHolder& wch, MDirection::Types toSys,
00186 String* error = NULL) {
00187 return linearToWorld(linearX, linearY, worldX, worldY, wch, toSys,
00188 vector<int>(), vector<int>(), false, error);
00189 }
00190
00191 static bool linearToPixel(const Vector<double>& linearX,
00192 const Vector<double>& linearY,
00193 Vector<double>& pixelX, Vector<double>& pixelY,
00194 WorldCanvasHolder& wch, String* error = NULL);
00195
00196 static bool screenToWorld(const Vector<double>& screenX,
00197 const Vector<double>& screenY,
00198 Quantum<Vector<double> >& worldX,
00199 Quantum<Vector<double> >& worldY,
00200 WorldCanvasHolder& wch, MDirection::Types toSys,
00201 String* error = NULL) {
00202 Vector<double> linX(screenX.size()), linY(screenY.size());
00203 return screenToLinear(screenX, screenY, linX, linY, wch) &&
00204 linearToWorld(linX, linY, worldX, worldY, wch, toSys,
00205 vector<int>(), vector<int>(), false, error);
00206 }
00207
00208 static bool screenToWorld(const Vector<double>& screenX,
00209 const Vector<double>& screenY,
00210 Quantum<Vector<double> >& worldX,
00211 Quantum<Vector<double> >& worldY,
00212 WorldCanvasHolder& wch, MDirection::Types toSys,
00213 const vector<int>& xSign, const vector<int>& ySign,
00214 String* error = NULL) {
00215 Vector<double> linX(screenX.size()), linY(screenY.size());
00216 return screenToLinear(screenX, screenY, linX, linY, wch) &&
00217 linearToWorld(linX, linY, worldX, worldY, wch, toSys,
00218 xSign, ySign, true, error);
00219 }
00220
00221 static bool screenToPixel(const Vector<double>& screenX,
00222 const Vector<double>& screenY,
00223 Vector<double>& pixelX, Vector<double>& pixelY,
00224 WorldCanvasHolder& wch, String* error = NULL) {
00225 Vector<double> linX(screenX.size()), linY(screenY.size());
00226 return screenToLinear(screenX, screenY, linX, linY, wch, error) &&
00227 linearToPixel(linX, linY, pixelX, pixelY, wch, error);
00228 }
00229
00230
00231
00232
00233
00234
00235 static void appendUniqueMessage(stringstream& ss, const String& message);
00236 static void appendUniqueMessage(stringstream* ss, const String& message) {
00237 if(ss != NULL) appendUniqueMessage(*ss, message);
00238 }
00239 static void appendUniqueMessage(String& ss, const String& message);
00240 static void appendUniqueMessage(String* ss, const String& message) {
00241 if(ss != NULL) appendUniqueMessage(*ss, message);
00242 }
00243
00244 };
00245
00246
00247
00248
00249 class QtColorWidget : public QHBoxLayout {
00250 Q_OBJECT
00251
00252 public:
00253
00254
00255
00256 QtColorWidget(bool showButton = false, String setText = "",
00257 QWidget* parent = NULL);
00258
00259
00260
00261
00262 QtColorWidget(const vector<String>& colors, bool showButton = false,
00263 String setText = "", QWidget* parent = NULL);
00264
00265
00266 ~QtColorWidget();
00267
00268
00269
00270 String getColor() const;
00271
00272
00273
00274
00275 void setColor(const String& color);
00276
00277
00278
00279 static vector<String> defaultColors() {
00280 static vector<String> v(9);
00281 v[0] = "white";
00282 v[1] = "black";
00283 v[2] = "red";
00284 v[3] = "green";
00285 v[4] = "blue";
00286 v[5] = "cyan";
00287 v[6] = "magenta";
00288 v[7] = "yellow";
00289 v[8] = "gray";
00290 return v;
00291 }
00292
00293 private:
00294
00295 QComboBox* m_chooser;
00296
00297
00298 QLineEdit* m_edit;
00299
00300
00301 QPushButton* m_button;
00302
00303
00304 void init(const vector<String>& colors, const String& setText,
00305 bool showButton);
00306
00307 private slots:
00308
00309 void colorChanged(int index);
00310
00311
00312 void colorPick();
00313 };
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 class RSValue {
00325 public:
00326 RSValue(double d = 0) : isQuantum(true), isHMS(false), isMinusZero(false),
00327 val(d, DEG), hOrD(0), min(0), sec(0) { }
00328
00329 RSValue(double d, Unit u) : isQuantum(true), isHMS(false),
00330 isMinusZero(false), val(d, u), hOrD(0), min(0), sec(0) { }
00331
00332 RSValue(bool hms, long hd, long m, double s, bool minus = false) :
00333 isQuantum(false), isHMS(hms), isMinusZero(minus), val(0, "_"),
00334 hOrD(hd), min(m), sec(s) { }
00335
00336 ~RSValue() { }
00337
00338 bool isQuantum;
00339 bool isHMS;
00340 bool isMinusZero;
00341
00342 Quantum<double> val;
00343 long hOrD;
00344 long min;
00345 double sec;
00346
00347
00348
00349
00350
00351
00352 static const String DEG;
00353 static const String RAD;
00354 static const String ARCSEC;
00355 static const String ARCMIN;
00356 static const String HMS;
00357 static const String DMS;
00358
00359
00360
00361
00362
00363
00364 static bool convertBetween(const QString& from, const String& fromUnits,
00365 RSValue& to);
00366
00367
00368
00369 static bool convertBetween(const RSValue& from, QString& to,
00370 int precision = -1);
00371
00372
00373
00374
00375
00376 static bool convertBetween(const RSValue& from, RSValue& to,
00377 const String& toUnits);
00378 };
00379
00380
00381
00382 class RSOption {
00383 public:
00384
00385 RSOption(const String& str);
00386
00387
00388 RSOption(bool b = false);
00389
00390
00391 RSOption(double d);
00392
00393
00394 RSOption(const vector<String>& v);
00395
00396
00397 ~RSOption();
00398
00399
00400
00401 bool isString() const;
00402 bool isBool() const;
00403 bool isDouble() const;
00404 bool isStringArray() const;
00405
00406
00407
00408
00409 const String& asString() const;
00410 bool asBool() const;
00411 double asDouble() const;
00412 const vector<String>& asStringArray() const;
00413
00414
00415
00416
00417 bool operator==(const RSOption& other);
00418 bool operator!=(const RSOption& other);
00419 RSOption& operator=(const String& str);
00420 RSOption& operator=(bool b);
00421 RSOption& operator=(double d);
00422 RSOption& operator=(const vector<String>& v);
00423
00424
00425 private:
00426 bool m_isString;
00427 String m_string;
00428 bool m_isBool;
00429 bool m_bool;
00430 bool m_isDouble;
00431 double m_double;
00432 bool m_isStringArray;
00433 vector<String> m_stringArray;
00434 };
00435
00436
00437
00438
00439
00440
00441 class RSHandle {
00442 public:
00443
00444
00445 static const int DEFAULT_MARKER_HEIGHT;
00446 static const String DEFAULT_MARKER_COLOR;
00447 static const Display::Marker DEFAULT_MARKER_TYPE;
00448
00449
00450
00451 RSHandle();
00452
00453
00454
00455 RSHandle(const vector<double>& x, const vector<double>& y,
00456 int markerHeight = DEFAULT_MARKER_HEIGHT,
00457 const String& markerColor = DEFAULT_MARKER_COLOR,
00458 Display::Marker markerType = DEFAULT_MARKER_TYPE);
00459
00460
00461
00462 RSHandle(const Vector<double>& x, const Vector<double>& y,
00463 int markerHeight = DEFAULT_MARKER_HEIGHT,
00464 const String& markerColor = DEFAULT_MARKER_COLOR,
00465 Display::Marker markerType = DEFAULT_MARKER_TYPE);
00466
00467
00468 ~RSHandle();
00469
00470
00471
00472 int getMarkerHeight() const {
00473 return m_markerHeight;
00474 }
00475 void setMarkerHeight(int height);
00476 String getMarkerColor() const {
00477 return m_markerColor;
00478 }
00479 void setMarkerColor(const String& color);
00480 Display::Marker getMarkerType() const {
00481 return m_markerType;
00482 }
00483 void setMarkerType(Display::Marker type);
00484
00485
00486
00487 bool isValid() const {
00488 return m_isValid;
00489 }
00490
00491
00492 bool containsPoint(double x, double y) const;
00493
00494
00495
00496
00497 bool getVertices(vector<double>& x, vector<double>& y) const;
00498
00499
00500
00501
00502 bool draw(PixelCanvas* canvas) const;
00503
00504 private:
00505 bool m_isValid;
00506 vector<double> m_x, m_y;
00507 int m_markerHeight;
00508 String m_markerColor;
00509 Display::Marker m_markerType;
00510 };
00511
00512 }
00513
00514 #endif