PlotOptions.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1