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 PLOTOPTIONS_H_
00028 #define PLOTOPTIONS_H_
00029
00030 #include <utility>
00031 #include <cctype>
00032 #include <vector>
00033
00034 #include <casa/Utilities/CountedPtr.h>
00035 #include <casa/Containers/Record.h>
00036
00037 namespace casa {
00038
00039
00040
00041 typedef std::pair<double, double> prange_t;
00042
00043
00044 typedef std::pair<double, double> psize_t;
00045
00046
00047
00049
00051
00052
00053
00054
00055
00056
00057 enum PlotAxis {
00058 X_BOTTOM = 1, X_TOP = 2, Y_LEFT = 4, Y_RIGHT = 8
00059 };
00060
00061
00062
00063
00064
00065 typedef unsigned int PlotAxisBitset;
00066
00067 const PlotAxisBitset all_four_sides = 0xF;
00068 const PlotAxisBitset none_sides = 0x0;
00069
00070
00071
00072
00073 enum PlotAxisScale {
00074 NORMAL,
00075 LOG10,
00076 DATE_MJ_SEC,
00077 DATE_MJ_DAY
00078 };
00079
00080
00081 enum PlotCursor {
00082 NORMAL_CURSOR,
00083 HAND_OPEN,
00084 HAND_CLOSED,
00085 CROSSHAIR,
00086 WAIT,
00087 TEXT
00088 };
00089
00090
00091
00092
00093
00094
00095
00096 enum PlotCanvasLayer {
00097 MAIN = 1,
00098 ANNOTATION = 2
00099 };
00100
00101
00103
00105
00106
00107
00108
00109
00110
00111
00112 class PlotColor {
00113 public:
00114
00115 PlotColor();
00116
00117
00118 virtual ~PlotColor();
00119
00120
00121
00122
00123
00124 virtual String asHexadecimal() const = 0;
00125
00126
00127
00128 virtual String asName() const = 0;
00129
00130
00131
00132
00133
00134 virtual void setAsHexadecimalOrName(const String& str) = 0;
00135
00136
00137
00138 virtual double alpha() const = 0;
00139
00140
00141
00142 virtual void setAlpha(double a) = 0;
00143
00144
00145
00146
00147
00148 virtual void setAsHexadecimal(const String& hex);
00149
00150
00151 virtual void setAsName(const String& name);
00152
00153
00154
00155
00156
00157
00158 virtual Record toRecord() const;
00159 virtual void fromRecord(const Record& record);
00160
00161
00162
00163
00164
00165
00166 virtual PlotColor& operator=(const PlotColor& rh);
00167
00168
00169 virtual bool operator==(const PlotColor& rh) const;
00170
00171
00172
00173 virtual bool operator!=(const PlotColor& rh) const;
00174
00175 protected:
00176
00177
00178 static const String REC_HEXADECIMAL;
00179 static const String REC_ALPHA;
00180
00181 };
00182 typedef CountedPtr<PlotColor> PlotColorPtr;
00183
00184
00185
00186
00187 class PlotFont {
00188 public:
00189
00190 PlotFont();
00191
00192
00193 virtual ~PlotFont();
00194
00195
00196
00197
00198
00199
00200 virtual double pointSize() const = 0;
00201
00202
00203 virtual void setPointSize(double size) = 0;
00204
00205
00206
00207 virtual int pixelSize() const = 0;
00208
00209
00210 virtual void setPixelSize(int size) = 0;
00211
00212
00213 virtual String fontFamily() const = 0;
00214
00215
00216 virtual void setFontFamily(const String& font) = 0;
00217
00218
00219 virtual PlotColorPtr color() const = 0;
00220
00221
00222 virtual void setColor(const PlotColor& color) = 0;
00223
00224
00225
00226
00227 virtual bool italics() const = 0;
00228 virtual void setItalics(bool i = true) = 0;
00229 virtual bool bold() const = 0;
00230 virtual void setBold(bool b = true) = 0;
00231 virtual bool underline() const = 0;
00232 virtual void setUnderline(bool u = true) = 0;
00233
00234
00235
00236
00237
00238
00239
00240 virtual void setColor(const PlotColorPtr c);
00241 virtual void setColor(const String& col);
00242
00243
00244
00245
00246
00247
00248
00249 virtual Record toRecord() const;
00250 virtual void fromRecord(const Record& record);
00251
00252
00253
00254
00255
00256
00257 virtual PlotFont& operator=(const PlotFont& rh);
00258
00259
00260 virtual bool operator==(const PlotFont& rh) const;
00261
00262
00263
00264 virtual bool operator!=(const PlotFont& rh) const;
00265
00266 protected:
00267
00268
00269 static const String REC_POINTSIZE;
00270 static const String REC_PIXELSIZE;
00271 static const String REC_FAMILY;
00272 static const String REC_COLOR;
00273 static const String REC_ITALICS;
00274 static const String REC_BOLD;
00275 static const String REC_UNDERLINE;
00276
00277 };
00278 typedef CountedPtr<PlotFont> PlotFontPtr;
00279
00280
00281
00282
00283 class PlotAreaFill {
00284 public:
00285
00286
00287 enum Pattern {
00288 FILL, MESH1, MESH2, MESH3, NOFILL
00289 };
00290
00291
00292 PlotAreaFill();
00293
00294
00295 virtual ~PlotAreaFill();
00296
00297
00298
00299
00300
00301 virtual PlotColorPtr color() const = 0;
00302
00303
00304 virtual void setColor(const PlotColor& color) = 0;
00305
00306
00307 virtual Pattern pattern() const = 0;
00308
00309
00310 virtual void setPattern(Pattern pattern) = 0;
00311 virtual void setPattern( const String& descriptor );
00312
00313
00314
00315
00316
00317 virtual void setColor(const PlotColorPtr c);
00318 virtual void setColor(const String& co);
00319
00320
00321
00322
00323
00324
00325
00326 virtual Record toRecord() const;
00327 virtual void fromRecord(const Record& record);
00328
00329
00330
00331
00332
00333
00334 virtual PlotAreaFill& operator=(const PlotAreaFill& rh);
00335
00336
00337
00338 virtual bool operator==(const PlotAreaFill& rh) const;
00339
00340
00341
00342 virtual bool operator!=(const PlotAreaFill& rh) const;
00343
00344 protected:
00345
00346
00347 static const String REC_COLOR;
00348 static const String REC_PATTERN;
00349
00350 };
00351 typedef CountedPtr<PlotAreaFill> PlotAreaFillPtr;
00352
00353
00354
00355 class PlotLine {
00356 public:
00357
00358
00359
00360 enum Style {
00361 SOLID, DASHED, DOTTED, NOLINE
00362 };
00363
00364
00365
00366
00367
00368 PlotLine();
00369
00370
00371 virtual ~PlotLine();
00372
00373
00374
00375
00376
00377 virtual double width() const = 0;
00378
00379
00380 virtual void setWidth(double width) = 0;
00381
00382
00383 virtual Style style() const = 0;
00384
00385
00386 virtual void setStyle(Style style) = 0;
00387
00388
00389 virtual PlotColorPtr color() const = 0;
00390
00391
00392 virtual void setColor(const PlotColor& color) = 0;
00393
00394
00395
00396
00397
00398
00399 virtual void setColor(const PlotColorPtr c);
00400 virtual void setColor(const String& col);
00401
00402
00403
00404
00405
00406
00407
00408 virtual Record toRecord() const;
00409 virtual void fromRecord(const Record& record);
00410
00411
00412
00413
00414
00415
00416 virtual PlotLine& operator=(const PlotLine& rh);
00417
00418
00419 virtual bool operator==(const PlotLine& rh) const;
00420
00421
00422
00423 virtual bool operator!=(const PlotLine& rh) const;
00424
00425 protected:
00426
00427
00428 static const String REC_WIDTH;
00429 static const String REC_STYLE;
00430 static const String REC_COLOR;
00431
00432 };
00433 typedef CountedPtr<PlotLine> PlotLinePtr;
00434
00435
00436
00437
00438 class PlotSymbol {
00439 public:
00440
00441
00442
00443 enum Symbol {
00444 CHARACTER,
00445 CIRCLE, SQUARE, DIAMOND,
00446 PIXEL,
00447 NOSYMBOL,
00448 AUTOSCALING
00449 };
00450
00451
00452
00453
00454
00455 PlotSymbol();
00456
00457
00458
00459
00460 virtual ~PlotSymbol();
00461
00462
00463
00464
00465
00466
00467
00468 virtual psize_t size() const = 0;
00469
00470
00471
00472
00473 virtual void setSize(double width, double height,
00474 bool heightIsPixel = true) = 0;
00475
00476
00477
00478
00479 virtual bool heightIsPixel() const = 0;
00480 virtual void setHeightIsPixel(bool pixel = true) = 0;
00481
00482
00483
00484 virtual Symbol symbol() const = 0;
00485
00486
00487
00488 virtual char symbolChar() const = 0;
00489
00490
00491
00492 virtual unsigned short symbolUChar() const = 0;
00493
00494
00495 virtual void setSymbol(Symbol symbol) = 0;
00496 virtual void setSymbol( const String& descriptor );
00497
00498
00499 virtual void setSymbol(char c) = 0;
00500
00501
00502
00503 virtual void setUSymbol(unsigned short unicode) = 0;
00504
00505
00506
00507 virtual PlotLinePtr line() const = 0;
00508
00509
00510
00511 virtual void setLine(const PlotLine& color) = 0;
00512
00513
00514
00515 virtual PlotAreaFillPtr areaFill() const = 0;
00516
00517
00518
00519 virtual void setAreaFill(const PlotAreaFill& fill) = 0;
00520
00521
00522
00523
00524
00525 virtual void setSize(psize_t size);
00526
00527
00528 virtual bool isCharacter() const;
00529
00530
00531
00532 virtual void setLine(const PlotLinePtr l);
00533 virtual void setLine(const String& color,
00534 PlotLine::Style style = PlotLine::SOLID,
00535 double width = 1.0);
00536
00537
00538
00539
00540 virtual void setAreaFill(const PlotAreaFillPtr a);
00541 virtual void setAreaFill(const String& color,
00542 PlotAreaFill::Pattern pattern = PlotAreaFill::FILL);
00543
00544
00545
00546
00547 virtual void setColor(const PlotColor& color);
00548 virtual void setColor(const PlotColorPtr color);
00549 virtual void setColor(const String& color);
00550 String getColor() const;
00551
00552
00553
00554
00555
00556
00557
00558 virtual Record toRecord() const;
00559 virtual void fromRecord(const Record& record);
00560
00561
00562
00563
00564
00565 virtual PlotSymbol& operator=(const PlotSymbol& rh);
00566
00567
00568 virtual bool operator==(const PlotSymbol& rh) const;
00569
00570
00571
00572 virtual bool operator!=(const PlotSymbol& rh) const;
00573
00574 protected:
00575
00576
00577 static const String REC_WIDTH;
00578 static const String REC_HEIGHT;
00579 static const String REC_HEIGHTISPIXEL;
00580 static const String REC_SYMBOL;
00581 static const String REC_UCHAR;
00582 static const String REC_LINE;
00583 static const String REC_AREAFILL;
00584 static const String REC_COLOR;
00585
00586
00587 private:
00588 const String DEFAULT_COLOR;
00589 String currentColor;
00590 };
00591 typedef CountedPtr<PlotSymbol> PlotSymbolPtr;
00592
00593
00595
00597
00598
00599
00600
00601 class PlotCoordinate {
00602 public:
00603
00604
00605
00606 enum System {
00607 WORLD,
00608 NORMALIZED_WORLD,
00609
00610 PIXEL
00611
00612 };
00613
00614
00615
00616
00617
00618 PlotCoordinate();
00619
00620
00621 PlotCoordinate(double dx, double dy, System s = WORLD);
00622
00623
00624 PlotCoordinate(const PlotCoordinate& c);
00625
00626
00627 ~PlotCoordinate();
00628
00629
00630
00631
00632
00633 System system() const;
00634
00635
00636 double x() const;
00637
00638
00639 double y() const;
00640
00641
00642
00643
00644
00645 PlotCoordinate& operator=(const PlotCoordinate& rh);
00646
00647
00648
00649 bool operator==(const PlotCoordinate& rh) const;
00650
00651
00652
00653 bool operator!=(const PlotCoordinate& rh) const;
00654
00655 private:
00656
00657 System m_system;
00658
00659
00660 double m_x;
00661
00662
00663 double m_y;
00664 };
00665
00666
00667
00668
00669 class PlotRegion {
00670 public:
00671
00672 PlotRegion();
00673
00674
00675 PlotRegion(const PlotCoordinate& upperLeft,
00676 const PlotCoordinate& lowerRight);
00677
00678
00679 PlotRegion(const PlotRegion& copy);
00680
00681
00682 ~PlotRegion();
00683
00684
00685
00686 const PlotCoordinate& upperLeft() const;
00687
00688
00689 const PlotCoordinate& lowerRight() const;
00690
00691
00692 double top() const;
00693
00694
00695 double bottom() const;
00696
00697
00698 double left() const;
00699
00700
00701 double right() const;
00702
00703
00704 bool isValid() const;
00705
00706 private:
00707
00708 PlotCoordinate m_upperLeft;
00709
00710
00711 PlotCoordinate m_lowerRight;
00712 };
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 class PlotAxesStack {
00723 public:
00724
00725
00726 PlotAxesStack(int lengthLimit = -1);
00727
00728
00729 ~PlotAxesStack();
00730
00731
00732
00733
00734 int lengthLimit() const;
00735 void setLengthLimit(int lengthLimit);
00736 void clearLengthLimit() { setLengthLimit(-1); }
00737
00738
00739
00740 bool isValid() const;
00741
00742
00743 unsigned int stackIndex() const;
00744
00745
00746 unsigned int size() const;
00747
00748
00749 std::vector<PlotRegion> stack() const;
00750
00751
00752
00753 std::vector<std::pair<PlotAxis, PlotAxis> > stackAxes() const;
00754
00755
00756 void setBase(const PlotRegion& base, PlotAxis xAxis, PlotAxis yAxis);
00757
00758
00759 void addRegion(const PlotRegion& region, PlotAxis xAxis, PlotAxis yAxis);
00760
00761
00762 void clearStack(bool keepBase = false);
00763
00764
00765 PlotRegion currentRegion() const;
00766
00767
00768 PlotAxis currentXAxis() const;
00769
00770
00771 PlotAxis currentYAxis() const;
00772
00773
00774
00775
00776 void move(int delta);
00777
00778
00779
00780 PlotRegion moveAndReturn(int delta);
00781
00782 private:
00783
00784 int m_lengthLimit;
00785
00786
00787 std::vector<PlotRegion> m_stack;
00788
00789
00790 std::vector<std::pair<PlotAxis, PlotAxis> > m_axes;
00791
00792
00793 unsigned int m_stackIndex;
00794
00795
00796
00797
00798
00799 void shrinkStacks(unsigned int n);
00800 };
00801
00802
00803
00804 class PlotExportFormat {
00805 public:
00806
00807
00808
00809 enum Type {
00810 JPG, PNG, PS, PDF, TEXT,
00811 NUM_FMTS
00812 };
00813
00814
00815 enum Resolution {
00816 SCREEN,
00817 HIGH
00818 };
00819
00820
00821
00822 static String exportFormat(Type t);
00823 static Type exportFormat(String t, bool* ok = NULL);
00824
00825
00826
00827
00828 static String extensionFor(Type t);
00829 static Type typeForExtension(String file, bool* ok = NULL);
00830
00831
00832
00833
00834 static std::vector<Type> supportedFormats();
00835 static std::vector<String> supportedFormatStrings();
00836
00837
00838
00839
00840 static std::vector<Type> supportedImageFormats();
00841 static std::vector<String> supportedImageFormatStrings();
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 PlotExportFormat(Type t, const String& file);
00852
00853
00854 ~PlotExportFormat();
00855
00856
00857
00858 Type type;
00859 String location;
00860 Resolution resolution;
00861 int dpi;
00862 int width;
00863 int height;
00864
00865 };
00866
00867
00869
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880 #define INHERITANCE_POINTER(cname, cptrname, pname, pptrname, gname, gptrname)\
00881 class cptrname : public pptrname { \
00882 public: \
00883 cptrname () : pptrname () { } \
00884 cptrname ( cname * val, bool del = true ) : pptrname() { \
00885 gname * v = dynamic_cast< gname *>(val); \
00886 if(v != NULL) gptrname ::operator=( gptrname (v, del)); \
00887 } \
00888 cptrname ( const gptrname & val ) : pptrname () { \
00889 const cname * v = dynamic_cast<const cname *>( \
00890 val.operator->()); \
00891 if(v != NULL) gptrname ::operator=(val); \
00892 } \
00893 cname & operator*() { \
00894 return dynamic_cast< cname &>(**(( gptrname *)this)); \
00895 } \
00896 cname * operator->() { \
00897 return dynamic_cast< cname *>((( gptrname *)this)->operator->()); \
00898 } \
00899 const cname & operator*() const { \
00900 return dynamic_cast<const cname &>(**(( gptrname * )this)); \
00901 } \
00902 const cname * operator->() const { \
00903 return dynamic_cast<const cname *>( \
00904 (( gptrname *)this)->operator->()); \
00905 } \
00906 cptrname & operator=(const gptrname & val) { \
00907 const cname * v = dynamic_cast<const cname *>(val.operator->()); \
00908 if(v != NULL) (( gptrname *)this)->operator=(val); \
00909 return *this; \
00910 } \
00911 cptrname & operator=( gname * val) { \
00912 cname * v = dynamic_cast< cname *>(val); \
00913 if(v != NULL) (( gptrname *)this)->operator=(val); \
00914 return *this; \
00915 } \
00916 };
00917
00918
00919 #define INHERITANCE_POINTER2(cname, cptrname, pname, pptrname) \
00920 INHERITANCE_POINTER(cname, cptrname, pname, pptrname, pname, pptrname)
00921
00922
00923 #define INHERITANCE_TPOINTER(cname, cptrname, pname, pptrname, gname,gptrname)\
00924 template <class T> class cptrname : public pptrname { \
00925 public: \
00926 cptrname () : pptrname () { } \
00927 cptrname ( cname <T>* val, bool del = true ) : pptrname(){ \
00928 gname * v = dynamic_cast< gname *>(val); \
00929 if(v != NULL) gptrname ::operator=( gptrname (v, del)); \
00930 } \
00931 cptrname ( const gptrname & val ) : pptrname () { \
00932 const cname <T>* v = dynamic_cast<const cname <T>*>( \
00933 val.operator->()); \
00934 if(v != NULL) gptrname ::operator=(val); \
00935 } \
00936 cptrname ( const cptrname <T> & val ) : pptrname() { \
00937 gptrname ::operator=((const gptrname &)val); \
00938 } \
00939 cname <T>& operator*() { \
00940 return dynamic_cast< cname <T>&>(**(( gptrname *)this)); \
00941 } \
00942 cname <T>* operator->() { \
00943 return dynamic_cast< cname <T>*>( \
00944 (( gptrname *)this)->operator->()); \
00945 } \
00946 const cname <T>& operator*() const { \
00947 return dynamic_cast<const cname <T>&>(**(( gptrname * )this)); \
00948 } \
00949 const cname <T>* operator->() const { \
00950 return dynamic_cast<const cname <T>*>( \
00951 (( gptrname *)this)->operator->()); \
00952 } \
00953 cptrname <T>& operator=(const gptrname & val) { \
00954 const cname <T>* v = dynamic_cast<const cname <T>*>( \
00955 val.operator->()); \
00956 if(v != NULL) (( gptrname *)this)->operator=(val); \
00957 return *this; \
00958 } \
00959 cptrname <T>& operator=( gname * val) { \
00960 cname <T>* v = dynamic_cast< cname <T>*>(val); \
00961 if(v != NULL) (( gptrname *)this)->operator=(val); \
00962 return *this; \
00963 } \
00964 };
00965
00966
00967 #define INHERITANCE_TPOINTER2(cname, cptrname, pname, pptrname) \
00968 INHERITANCE_TPOINTER(cname, cptrname, pname, pptrname, pname, pptrname)
00969
00970 }
00971
00972 #endif