casa
$Rev:20696$
|
00001 //# PlotOptions.h: Customization classes for plotter objects. 00002 //# Copyright (C) 2008 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 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 #include <casa/namespace.h> 00038 using namespace std; 00039 00040 namespace casa { 00041 00042 00043 // Typedef for range, which is two doubles (min and max). 00044 typedef pair<double, double> prange_t; 00045 00046 // Typedef for size, which is two doubles (width and height). 00047 typedef pair<double, double> psize_t; 00048 00049 00050 00052 // ENUMS // 00054 00055 00056 // Enum for the four plot axes. If this enum is changed, PlotCanvas::allAxes() 00057 // needs to be updated. 00058 // Use this in contexts where one and only one side is specified. 00059 // For combinations of sides, or none, use PlotAxiBitset 00060 enum PlotAxis { 00061 X_BOTTOM = 1, X_TOP = 2, Y_LEFT = 4, Y_RIGHT = 8 00062 }; 00063 00064 00065 // Set of bit flags to indicate combinations of sides, 00066 // used (as of this writing) for indicating which axes have visible scales. 00067 // The value of a PlotSideBitset is the bitwise OR of values of PlotSide. 00068 typedef unsigned int PlotAxisBitset; 00069 00070 const PlotAxisBitset all_four_sides = 0xF; 00071 const PlotAxisBitset none_sides = 0x0; 00072 00073 00074 00075 // Enum for possible axis scales. 00076 enum PlotAxisScale { 00077 NORMAL, 00078 LOG10, // logarithmic scale 00079 DATE_MJ_SEC, // display scale values as dates (modified julian seconds) 00080 DATE_MJ_DAY // display scale values as dates (modified julian days) 00081 }; 00082 00083 // Enum for cursors. 00084 enum PlotCursor { 00085 NORMAL_CURSOR, 00086 HAND_OPEN, 00087 HAND_CLOSED, 00088 CROSSHAIR, 00089 WAIT, 00090 TEXT 00091 }; 00092 00093 // The canvas is composed of multiple layers, where changing/adding items from 00094 // one layer will not affect the others. This is mainly used to separate items 00095 // that are costly to draw (i.e. scatter plots with many points) from 00096 // interaction-type items (i.e. annotations and selections). The layers share 00097 // axes and are otherwise transparent to the user. If this enum is changed, 00098 // PlotCanvas::allLayers() needs to be updated. 00099 enum PlotCanvasLayer { 00100 MAIN = 1, // "Main" or bottom layer. 00101 ANNOTATION = 2 // Annotations or top layer. 00102 }; 00103 00104 00106 // ABSTRACT CLASSES // 00108 00109 // Abstract class for colors. Any implementation of color should be able to 00110 // provide a hexadecimal form of the color (i.e., "000000" for black) and, if 00111 // applicable, a human-readable name (i.e. "black"). In many places throughout 00112 // the plotter, color and Strings are interchangeable; however implementation 00113 // classes should use PlotColors where possible for additional features such as 00114 // alpha blending. 00115 class PlotColor { 00116 public: 00117 // Constructor. 00118 PlotColor(); 00119 00120 // Destructor. 00121 virtual ~PlotColor(); 00122 00123 00124 // ABSTRACT METHODS // 00125 00126 // Returns this color's value in a hexadecimal form, i.e. "000000". 00127 virtual String asHexadecimal() const = 0; 00128 00129 // Returns this color's value as a human-readable name if applicable, or an 00130 // empty String if inapplicable. 00131 virtual String asName() const = 0; 00132 00133 // If the given String is a hexadecimal value, sets the color to it. 00134 // Otherwise tries to set the color as a name. If the given name is 00135 // invalid, the behavior is undefined but should probably default to a 00136 // sensible value. 00137 virtual void setAsHexadecimalOrName(const String& str) = 0; 00138 00139 // Returns this color's alpha as a value between 0 (transparent) and 1 00140 // (opaque). 00141 virtual double alpha() const = 0; 00142 00143 // Sets this color's alpha as a value between 0 (transparent) and 1 00144 // (opaque). 00145 virtual void setAlpha(double a) = 0; 00146 00147 00148 // CONVENIENCE METHODS // 00149 00150 // Sets this color's value as a hexadecimal value. 00151 virtual void setAsHexadecimal(const String& hex); 00152 00153 // Set's this color's value to the given named color. 00154 virtual void setAsName(const String& name); 00155 00156 00157 // RECORD METHODS // 00158 00159 // Gets/Sets the color as a Record. 00160 // <group> 00161 virtual Record toRecord() const; 00162 virtual void fromRecord(const Record& record); 00163 // </group> 00164 00165 00166 // OPERATORS // 00167 00168 // Assigns the value of the given PlotColor to this one. 00169 virtual PlotColor& operator=(const PlotColor& rh); 00170 00171 // Returns true if this PlotColor is equal to the given; false otherwise. 00172 virtual bool operator==(const PlotColor& rh) const; 00173 00174 // Returns true if this PlotColor is NOT equal to the given; false 00175 // otherwise. 00176 virtual bool operator!=(const PlotColor& rh) const; 00177 00178 protected: 00179 // Record key names. 00180 // <group> 00181 static const String REC_HEXADECIMAL; // String 00182 static const String REC_ALPHA; // double 00183 // </group> 00184 }; 00185 typedef CountedPtr<PlotColor> PlotColorPtr; 00186 00187 00188 // Abstract class for fonts. A font has a family, size, color, bold, italics, 00189 // and underline properties. 00190 class PlotFont { 00191 public: 00192 // Constructor. 00193 PlotFont(); 00194 00195 // Destructor. 00196 virtual ~PlotFont(); 00197 00198 00199 // ABSTRACT METHODS // 00200 00201 // Returns the point size of this font, or -1 if the size was set in 00202 // pixels. 00203 virtual double pointSize() const = 0; 00204 00205 // Sets the point size of this font to the given. 00206 virtual void setPointSize(double size) = 0; 00207 00208 // Returns the pixel size of this font, or -1 if the size was set in 00209 // points. 00210 virtual int pixelSize() const = 0; 00211 00212 // Sets the pixel size of this font to the given. 00213 virtual void setPixelSize(int size) = 0; 00214 00215 // Returns the font family. 00216 virtual String fontFamily() const = 0; 00217 00218 // Sets the font family to the given. 00219 virtual void setFontFamily(const String& font) = 0; 00220 00221 // Returns a copy of the color for this font. 00222 virtual PlotColorPtr color() const = 0; 00223 00224 // Sets the color of this font to the given. 00225 virtual void setColor(const PlotColor& color) = 0; 00226 00227 // Gets/sets whether this font is italicized, bolded, and/or underlined, 00228 // respectively. 00229 // <group> 00230 virtual bool italics() const = 0; 00231 virtual void setItalics(bool i = true) = 0; 00232 virtual bool bold() const = 0; 00233 virtual void setBold(bool b = true) = 0; 00234 virtual bool underline() const = 0; 00235 virtual void setUnderline(bool u = true) = 0; 00236 // </group> 00237 00238 00239 // CONVENIENCE METHODS // 00240 00241 // Convenience methods for setting color. 00242 // <group> 00243 virtual void setColor(const PlotColorPtr c); 00244 virtual void setColor(const String& col); 00245 // </group> 00246 00247 00248 // RECORD METHODS // 00249 00250 // Gets/Sets the color as a Record. 00251 // <group> 00252 virtual Record toRecord() const; 00253 virtual void fromRecord(const Record& record); 00254 // </group> 00255 00256 00257 // OPERATORS // 00258 00259 // Assigns the value of the given PlotFont to this one. 00260 virtual PlotFont& operator=(const PlotFont& rh); 00261 00262 // Returns true if this PlotFont is equal to the given; false otherwise. 00263 virtual bool operator==(const PlotFont& rh) const; 00264 00265 // Returns true if this PlotFont is NOT equal to the given; false 00266 // otherwise. 00267 virtual bool operator!=(const PlotFont& rh) const; 00268 00269 protected: 00270 // Record key names. 00271 // <group> 00272 static const String REC_POINTSIZE; // double 00273 static const String REC_PIXELSIZE; // int 00274 static const String REC_FAMILY; // String 00275 static const String REC_COLOR; // Record 00276 static const String REC_ITALICS; // bool 00277 static const String REC_BOLD; // bool 00278 static const String REC_UNDERLINE; // bool 00279 // </group> 00280 }; 00281 typedef CountedPtr<PlotFont> PlotFontPtr; 00282 00283 00284 // Abstract class for area fill. An area fill consists of a color and a 00285 // pattern. 00286 class PlotAreaFill { 00287 public: 00288 // Pattern enum, similar in spirit to 00289 // http://doc.trolltech.com/4.3/qt.html#BrushStyle-enum . 00290 enum Pattern { 00291 FILL, MESH1, MESH2, MESH3, NOFILL 00292 }; 00293 00294 // Constructor 00295 PlotAreaFill(); 00296 00297 // Destructor 00298 virtual ~PlotAreaFill(); 00299 00300 00301 // ABSTRACT METHODS // 00302 00303 // Returns a copy of the color in this area fill. 00304 virtual PlotColorPtr color() const = 0; 00305 00306 // Sets the area fill color to the given. 00307 virtual void setColor(const PlotColor& color) = 0; 00308 00309 // Returns the pattern for this area fill. 00310 virtual Pattern pattern() const = 0; 00311 00312 // Sets the pattern for this area fill to the given. 00313 virtual void setPattern(Pattern pattern) = 0; 00314 00315 00316 // CONVENIENCE METHODS // 00317 00318 // Convenience methods for setting color. 00319 // <group> 00320 virtual void setColor(const PlotColorPtr c); 00321 virtual void setColor(const String& co); 00322 // </group> 00323 00324 00325 // RECORD METHODS // 00326 00327 // Gets/Sets the color as a Record. 00328 // <group> 00329 virtual Record toRecord() const; 00330 virtual void fromRecord(const Record& record); 00331 // </group> 00332 00333 00334 // OPERATORS // 00335 00336 // Assigns the value of the given PlotAreaFill to this one. 00337 virtual PlotAreaFill& operator=(const PlotAreaFill& rh); 00338 00339 // Returns true if this PlotAreaFill is equal to the given; false 00340 // otherwise. 00341 virtual bool operator==(const PlotAreaFill& rh) const; 00342 00343 // Returns true if this PlotAreaFill is NOT equal to the given; false 00344 // otherwise. 00345 virtual bool operator!=(const PlotAreaFill& rh) const; 00346 00347 protected: 00348 // Record key names. 00349 // <group> 00350 static const String REC_COLOR; // Record 00351 static const String REC_PATTERN; // int 00352 // </group> 00353 }; 00354 typedef CountedPtr<PlotAreaFill> PlotAreaFillPtr; 00355 00356 00357 // Abstract class for a line. A line has a color, style, and width. 00358 class PlotLine { 00359 public: 00360 // Static // 00361 00362 // Line styles. 00363 enum Style { 00364 SOLID, DASHED, DOTTED, NOLINE 00365 }; 00366 00367 00368 // Non-Static // 00369 00370 // Constructor. 00371 PlotLine(); 00372 00373 // Destructor. 00374 virtual ~PlotLine(); 00375 00376 00377 // ABSTRACT METHODS // 00378 00379 // Returns this line's width. 00380 virtual double width() const = 0; 00381 00382 // Sets the width to the given. 00383 virtual void setWidth(double width) = 0; 00384 00385 // Returns this line's style. 00386 virtual Style style() const = 0; 00387 00388 // Sets the style to the given. 00389 virtual void setStyle(Style style) = 0; 00390 00391 // Returns a copy of the color used for this line. 00392 virtual PlotColorPtr color() const = 0; 00393 00394 // Sets this line's color to the given. 00395 virtual void setColor(const PlotColor& color) = 0; 00396 00397 00398 // CONVENIENCE METHODS // 00399 00400 // Convenience methods for setting color. 00401 // <group> 00402 virtual void setColor(const PlotColorPtr c); 00403 virtual void setColor(const String& col); 00404 // </group> 00405 00406 00407 // RECORD METHODS // 00408 00409 // Gets/Sets the color as a Record. 00410 // <group> 00411 virtual Record toRecord() const; 00412 virtual void fromRecord(const Record& record); 00413 // </group> 00414 00415 00416 // OPERATORS // 00417 00418 // Assigns the value of the given PlotLine to this one. 00419 virtual PlotLine& operator=(const PlotLine& rh); 00420 00421 // Returns true if this PlotLine is equal to the given; false otherwise. 00422 virtual bool operator==(const PlotLine& rh) const; 00423 00424 // Returns true if this PlotLine is NOT equal to the given; false 00425 // otherwise. 00426 virtual bool operator!=(const PlotLine& rh) const; 00427 00428 protected: 00429 // Record key names. 00430 // <group> 00431 static const String REC_WIDTH; // double 00432 static const String REC_STYLE; // int 00433 static const String REC_COLOR; // Record 00434 // </group> 00435 }; 00436 typedef CountedPtr<PlotLine> PlotLinePtr; 00437 00438 00439 // Abstract class for a symbol. A symbol has a style, size, line, and area 00440 // fill. 00441 class PlotSymbol { 00442 public: 00443 // Static // 00444 00445 // Symbol style. 00446 enum Symbol { 00447 CHARACTER, // for char symbols 00448 CIRCLE, SQUARE, DIAMOND, // standard shapes 00449 PIXEL, // draw a single pixel 00450 NOSYMBOL, // don't show symbols 00451 AUTOSCALING // autoscaling symbol 00452 }; 00453 00454 00455 // Non-Static // 00456 00457 // Constructor. 00458 PlotSymbol(); 00459 00460 // Destructor. 00461 virtual ~PlotSymbol(); 00462 00463 00464 // ABSTRACT METHODS // 00465 00466 // Returns the size, in pixels, of this symbol. If this symbol is a 00467 // character, the height corresponds to the font size (in either pixels or 00468 // points, see heightIsPixel()). 00469 virtual psize_t size() const = 0; 00470 00471 // Sets the size of the symbol in pixels. The heightIsPixel parameter is 00472 // used for character symbols and indicates whether the given height is in 00473 // points or pixels. 00474 virtual void setSize(double width, double height, 00475 bool heightIsPixel = true) = 0; 00476 00477 // Gets/Sets whether the set height is in pixels or points, ONLY for 00478 // character symbols. 00479 // <group> 00480 virtual bool heightIsPixel() const = 0; 00481 virtual void setHeightIsPixel(bool pixel = true) = 0; 00482 // </group> 00483 00484 // Returns the symbol style. 00485 virtual Symbol symbol() const = 0; 00486 00487 // Returns the character for this symbol. Invalid if the style is not 00488 // CHARACTER. 00489 virtual char symbolChar() const = 0; 00490 00491 // Returns the character unicode for this symbol. Invalid if the style is 00492 // not CHARACTER. 00493 virtual unsigned short symbolUChar() const = 0; 00494 00495 // Sets the symbol style to the given. 00496 virtual void setSymbol(Symbol symbol) = 0; 00497 00498 // Sets the symbol character to the given. Implies setSymbol(CHARACTER). 00499 virtual void setSymbol(char c) = 0; 00500 00501 // Sets the symbol character unicode to the given. Implies 00502 // setSymbol(CHARACTER). 00503 virtual void setUSymbol(unsigned short unicode) = 0; 00504 00505 // Returns a copy of the line for the outline of this symbol. Does not 00506 // apply to character or pixel symbols. 00507 virtual PlotLinePtr line() const = 0; 00508 00509 // Sets the outline of this symbol to the given. Does not apply to 00510 // character or pixel symbols. 00511 virtual void setLine(const PlotLine& color) = 0; 00512 00513 // Returns a copy of the area fill for this symbol. Does not apply to 00514 // character or pixel symbols. 00515 virtual PlotAreaFillPtr areaFill() const = 0; 00516 00517 // Sets the area fill of this symbol to the given. Does not apply to 00518 // character or pixel symbols. 00519 virtual void setAreaFill(const PlotAreaFill& fill) = 0; 00520 00521 00522 // CONVENIENCE METHODS // 00523 00524 // Convenience method for setting size. 00525 virtual void setSize(psize_t size); 00526 00527 // Returns true if this symbol is set to a character or not. 00528 virtual bool isCharacter() const; 00529 00530 // Convenience methods for setting the line. 00531 // <group> 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 // </group> 00537 00538 // Convenience methods for setting area fill. 00539 // <group> 00540 virtual void setAreaFill(const PlotAreaFillPtr a); 00541 virtual void setAreaFill(const String& color, 00542 PlotAreaFill::Pattern pattern = PlotAreaFill::FILL); 00543 // </group> 00544 00545 // Convenience method for setting color of both line and area fill. 00546 // <group> 00547 virtual void setColor(const PlotColor& color); 00548 virtual void setColor(const PlotColorPtr color); 00549 virtual void setColor(const String& color); 00550 // </group> 00551 00552 00553 // RECORD METHODS // 00554 00555 // Gets/Sets the color as a Record. 00556 // <group> 00557 virtual Record toRecord() const; 00558 virtual void fromRecord(const Record& record); 00559 // </group> 00560 00561 00562 // OPERATORS // 00563 00564 // Assigns the value of the given PlotSymbol to this one. 00565 virtual PlotSymbol& operator=(const PlotSymbol& rh); 00566 00567 // Returns true if this PlotSymbol is equal to the given; false otherwise. 00568 virtual bool operator==(const PlotSymbol& rh) const; 00569 00570 // Returns true if this PlotSymbol is NOT equal to the given; false 00571 // otherwise. 00572 virtual bool operator!=(const PlotSymbol& rh) const; 00573 00574 protected: 00575 // Record key names. 00576 // <group> 00577 static const String REC_WIDTH; // double 00578 static const String REC_HEIGHT; // double 00579 static const String REC_HEIGHTISPIXEL; // bool 00580 static const String REC_SYMBOL; // int 00581 static const String REC_UCHAR; // int (no ushort in Records) 00582 static const String REC_LINE; // Record 00583 static const String REC_AREAFILL; // Record 00584 // </group> 00585 }; 00586 typedef CountedPtr<PlotSymbol> PlotSymbolPtr; 00587 00588 00590 // CONCRETE UTILITY CLASSES // 00592 00593 // Coordinate on the canvas surface (i.e., the part where the actual plots 00594 // are, which doesn't include things like axes, titles, etc.). A coordinate 00595 // has two values and a system. 00596 class PlotCoordinate { 00597 public: 00598 // Static // 00599 00600 // Coordinate system. 00601 enum System { 00602 WORLD, // in the units of the axes 00603 NORMALIZED_WORLD, // [0 ... 1] value that maps to a "percentage" of 00604 // world units 00605 PIXEL // pixels right and below the upper left corner of 00606 // the canvas 00607 }; 00608 00609 00610 // Non-Static // 00611 00612 // Default constructor. 00613 PlotCoordinate(); 00614 00615 // Parameterized constructor. 00616 PlotCoordinate(double dx, double dy, System s = WORLD); 00617 00618 // Copy constructor. 00619 PlotCoordinate(const PlotCoordinate& c); 00620 00621 // Destructor. 00622 ~PlotCoordinate(); 00623 00624 00625 // Accessors // 00626 00627 // Returns the coordinate system. 00628 System system() const; 00629 00630 // Returns the x value. 00631 double x() const; 00632 00633 // Returns the y value. 00634 double y() const; 00635 00636 00637 // Operators // 00638 00639 // Assigns the value of the given PlotCoordinate to this one. 00640 PlotCoordinate& operator=(const PlotCoordinate& rh); 00641 00642 // Returns true if this PlotCoordinate is equal to the given; false 00643 // otherwise. 00644 bool operator==(const PlotCoordinate& rh) const; 00645 00646 // Returns true if this PlotCoordinate is NOT equal to the given; false 00647 // otherwise. 00648 bool operator!=(const PlotCoordinate& rh) const; 00649 00650 private: 00651 // Coordinate system. 00652 System m_system; 00653 00654 // X value. 00655 double m_x; 00656 00657 // Y value. 00658 double m_y; 00659 }; 00660 00661 00662 // A PlotRegion is basically just a wrapper for two PlotCoordinates: an upper 00663 // left coordinate and a lower right coordinate. 00664 class PlotRegion { 00665 public: 00666 // Default constructor. 00667 PlotRegion(); 00668 00669 // Parameterized constructor. 00670 PlotRegion(const PlotCoordinate& upperLeft, 00671 const PlotCoordinate& lowerRight); 00672 00673 // Copy constructor. 00674 PlotRegion(const PlotRegion& copy); 00675 00676 // Destructor. 00677 ~PlotRegion(); 00678 00679 00680 // Returns the upper left coordinate. 00681 const PlotCoordinate& upperLeft() const; 00682 00683 // Returns the lower right coordinate. 00684 const PlotCoordinate& lowerRight() const; 00685 00686 // Returns the top y value. 00687 double top() const; 00688 00689 // Returns the bottom y value. 00690 double bottom() const; 00691 00692 // Returns the left x value. 00693 double left() const; 00694 00695 // Returns the right x value. 00696 double right() const; 00697 00698 // Returns true if the region is valid, false otherwise. 00699 bool isValid() const; 00700 00701 private: 00702 // Upper-left coordinate. 00703 PlotCoordinate m_upperLeft; 00704 00705 // Lower-right coordinate. 00706 PlotCoordinate m_lowerRight; 00707 }; 00708 00709 00710 // A PlotAxesStack is basically a list of PlotRegions as well as axis 00711 // information that provides stack functionality such as a current index, and 00712 // moving up and down the stack. A valid stack has a "base" followed by zero 00713 // or more PlotRegions. A stack can optionally have a limit on its length; 00714 // adding to the stack after it reaches its length will remove the oldest 00715 // members after the base. The smallest value this limit can be is 2, (base + 00716 // 1 value). 00717 class PlotAxesStack { 00718 public: 00719 // Constructor for empty stack. Length limits with values <= 1 mean no 00720 // limit. 00721 PlotAxesStack(int lengthLimit = -1); 00722 00723 // Destructor. 00724 ~PlotAxesStack(); 00725 00726 00727 // Gets/Sets the length limit on this stack. Values <= 1 mean no limit. 00728 // <group> 00729 int lengthLimit() const; 00730 void setLengthLimit(int lengthLimit); 00731 void clearLengthLimit() { setLengthLimit(-1); } 00732 // </group> 00733 00734 // Returns whether the stack is valid (has size > 0) or not. 00735 bool isValid() const; 00736 00737 // Returns the current stack index. 00738 unsigned int stackIndex() const; 00739 00740 // Returns the stack size. 00741 unsigned int size() const; 00742 00743 // Returns a copy of the stack. 00744 vector<PlotRegion> stack() const; 00745 00746 // Returns a copy of the stack axes. The first item is for x, the second 00747 // for y. 00748 vector<pair<PlotAxis, PlotAxis> > stackAxes() const; 00749 00750 // Resets the stack and sets the stack base to the given. 00751 void setBase(const PlotRegion& base, PlotAxis xAxis, PlotAxis yAxis); 00752 00753 // Adds the given region to the stack. 00754 void addRegion(const PlotRegion& region, PlotAxis xAxis, PlotAxis yAxis); 00755 00756 // Clears the stack, including the base if keepBase is false. 00757 void clearStack(bool keepBase = false); 00758 00759 // Returns the current region in the stack. 00760 PlotRegion currentRegion() const; 00761 00762 // Returns the x-axis for the current region in the stack. 00763 PlotAxis currentXAxis() const; 00764 00765 // Returns the y-axis for the current region in the stack. 00766 PlotAxis currentYAxis() const; 00767 00768 // Moves the stack index the given delta. If delta is negative, the index 00769 // goes backwards; if delta is positive, the index goes forward. If delta 00770 // is zero, the index goes to the base. 00771 void move(int delta); 00772 00773 // Moves the stack index the given delta (see move()) and returns the 00774 // current region. 00775 PlotRegion moveAndReturn(int delta); 00776 00777 private: 00778 // Length limit. 00779 int m_lengthLimit; 00780 00781 // Region stack. 00782 vector<PlotRegion> m_stack; 00783 00784 // Axes stack. 00785 vector<pair<PlotAxis, PlotAxis> > m_axes; 00786 00787 // Stack index. 00788 unsigned int m_stackIndex; 00789 00790 00791 // Shrinks the region and axes stack to the given size, discarding the 00792 // oldest UNLESS the stack index is in the elements to be discarded. In 00793 // this case, the element referenced by the index is also kept. 00794 void shrinkStacks(unsigned int n); 00795 }; 00796 00797 00798 // PlotExportFormat contains parameters for exporting a canvas to a file. 00799 class PlotExportFormat { 00800 public: 00801 // Static // 00802 00803 // The type of file/export. 00804 enum Type { 00805 JPG, PNG, PS, PDF, TEXT, 00806 NUM_FMTS 00807 }; 00808 00809 // Whether to have high resolution or not. 00810 enum Resolution { 00811 SCREEN, // basically a screen shot 00812 HIGH // "high" resolution 00813 }; 00814 00815 // Converts to/from a Type and its String representation. 00816 // <group> 00817 static String exportFormat(Type t); 00818 static Type exportFormat(String t, bool* ok = NULL); 00819 // </group> 00820 00821 // Gives/converts the standard extension for export types. 00822 // <group> 00823 static String extensionFor(Type t); 00824 static Type typeForExtension(String file, bool* ok = NULL); 00825 // </group> 00826 00827 // Returns all supported export formats. 00828 // <group> 00829 static vector<Type> supportedFormats(); 00830 static vector<String> supportedFormatStrings(); 00831 // </group> 00832 00833 // Returns all supported image formats. 00834 // <group> 00835 static vector<Type> supportedImageFormats(); 00836 static vector<String> supportedImageFormatStrings(); 00837 // </group> 00838 00839 00840 // Non-Static // 00841 00842 // Sets up a format with the given type and location. Default resolution 00843 // is SCREEN; default dpi is -1 (unspecified); default width and height 00844 // are -1 (unspecified). Unspecified values are left up to the plotting 00845 // implementation. 00846 PlotExportFormat(Type t, const String& file); 00847 00848 // Destructor. 00849 ~PlotExportFormat(); 00850 00851 // Public Members 00852 // <group> 00853 Type type; // export type 00854 String location; // export location 00855 Resolution resolution; // export resolution 00856 int dpi; // export dpi (if applicable) 00857 int width; // export width (if applicable) 00858 int height; // export height (if applicable) 00859 // </group> 00860 }; 00861 00862 00864 // SMART POINTER MACROS // 00866 00867 // This is painful but necessary to have transparent smart pointers that 00868 // support hierarchies and inheritance. See examples in other files. 00869 // cname = class name (to declare smart pointer for), 00870 // cptrname = name for pointer (usually cname + Ptr), 00871 // pname = immediate parent class name 00872 // pptrname = name for pointer of parent class (usually pname + Ptr), 00873 // gname = "grandparent" class name (or highest smart pointer in hierarchy), 00874 // gptrname = grandparent pointer name (usually gname + Ptr) 00875 #define INHERITANCE_POINTER(cname, cptrname, pname, pptrname, gname, gptrname)\ 00876 class cptrname : public pptrname { \ 00877 public: \ 00878 cptrname () : pptrname () { } \ 00879 cptrname ( cname * val, bool del = true ) : pptrname() { \ 00880 gname * v = dynamic_cast< gname *>(val); \ 00881 if(v != NULL) gptrname ::operator=( gptrname (v, del)); \ 00882 } \ 00883 cptrname ( const gptrname & val ) : pptrname () { \ 00884 const cname * v = dynamic_cast<const cname *>( \ 00885 val.operator->()); \ 00886 if(v != NULL) gptrname ::operator=(val); \ 00887 } \ 00888 cname & operator*() { \ 00889 return dynamic_cast< cname &>(**(( gptrname *)this)); \ 00890 } \ 00891 cname * operator->() { \ 00892 return dynamic_cast< cname *>((( gptrname *)this)->operator->()); \ 00893 } \ 00894 const cname & operator*() const { \ 00895 return dynamic_cast<const cname &>(**(( gptrname * )this)); \ 00896 } \ 00897 const cname * operator->() const { \ 00898 return dynamic_cast<const cname *>( \ 00899 (( gptrname *)this)->operator->()); \ 00900 } \ 00901 cptrname & operator=(const gptrname & val) { \ 00902 const cname * v = dynamic_cast<const cname *>(val.operator->()); \ 00903 if(v != NULL) (( gptrname *)this)->operator=(val); \ 00904 return *this; \ 00905 } \ 00906 cptrname & operator=( gname * val) { \ 00907 cname * v = dynamic_cast< cname *>(val); \ 00908 if(v != NULL) (( gptrname *)this)->operator=(val); \ 00909 return *this; \ 00910 } \ 00911 }; 00912 00913 // Convenience macro. 00914 #define INHERITANCE_POINTER2(cname, cptrname, pname, pptrname) \ 00915 INHERITANCE_POINTER(cname, cptrname, pname, pptrname, pname, pptrname) 00916 00917 // Macro for when the child class is a template. 00918 #define INHERITANCE_TPOINTER(cname, cptrname, pname, pptrname, gname,gptrname)\ 00919 template <class T> class cptrname : public pptrname { \ 00920 public: \ 00921 cptrname () : pptrname () { } \ 00922 cptrname ( cname <T>* val, bool del = true ) : pptrname(){ \ 00923 gname * v = dynamic_cast< gname *>(val); \ 00924 if(v != NULL) gptrname ::operator=( gptrname (v, del)); \ 00925 } \ 00926 cptrname ( const gptrname & val ) : pptrname () { \ 00927 const cname <T>* v = dynamic_cast<const cname <T>*>( \ 00928 val.operator->()); \ 00929 if(v != NULL) gptrname ::operator=(val); \ 00930 } \ 00931 cptrname ( const cptrname <T> & val ) : pptrname() { \ 00932 gptrname ::operator=((const gptrname &)val); \ 00933 } \ 00934 cname <T>& operator*() { \ 00935 return dynamic_cast< cname <T>&>(**(( gptrname *)this)); \ 00936 } \ 00937 cname <T>* operator->() { \ 00938 return dynamic_cast< cname <T>*>( \ 00939 (( gptrname *)this)->operator->()); \ 00940 } \ 00941 const cname <T>& operator*() const { \ 00942 return dynamic_cast<const cname <T>&>(**(( gptrname * )this)); \ 00943 } \ 00944 const cname <T>* operator->() const { \ 00945 return dynamic_cast<const cname <T>*>( \ 00946 (( gptrname *)this)->operator->()); \ 00947 } \ 00948 cptrname <T>& operator=(const gptrname & val) { \ 00949 const cname <T>* v = dynamic_cast<const cname <T>*>( \ 00950 val.operator->()); \ 00951 if(v != NULL) (( gptrname *)this)->operator=(val); \ 00952 return *this; \ 00953 } \ 00954 cptrname <T>& operator=( gname * val) { \ 00955 cname <T>* v = dynamic_cast< cname <T>*>(val); \ 00956 if(v != NULL) (( gptrname *)this)->operator=(val); \ 00957 return *this; \ 00958 } \ 00959 }; 00960 00961 // Convenience macro. 00962 #define INHERITANCE_TPOINTER2(cname, cptrname, pname, pptrname) \ 00963 INHERITANCE_TPOINTER(cname, cptrname, pname, pptrname, pname, pptrname) 00964 00965 } 00966 00967 #endif /*PLOTOPTIONS_H_*/