casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotShape.h
Go to the documentation of this file.
00001 //# PlotShape.h: Different shape classes that can be drawn on a canvas.
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 PLOTSHAPE_H_
00028 #define PLOTSHAPE_H_
00029 
00030 #include <graphics/GenericPlotter/PlotItem.h>
00031 
00032 #include <vector>
00033 
00034 #include <casa/namespace.h>
00035 using namespace std;
00036 
00037 namespace casa {
00038 
00039 // Abstract class for any shape which contains common functionality.
00040 class PlotShape : public virtual PlotItem {
00041 public:
00042     // Constructor.
00043     PlotShape() { }
00044     
00045     // Destructor.
00046     virtual ~PlotShape() { }
00047     
00048     
00049     // Implements PlotItem::drawCount().  Provides default implementation that
00050     // returns 1.
00051     virtual unsigned int drawCount() const { return 1; }
00052     
00053     
00054     // ABSTRACT METHODS //
00055     
00056     // Returns the coordinates for this shape.  The number and order depends
00057     // on the specific shape subclass.
00058     virtual vector<PlotCoordinate> coordinates() const = 0;
00059     
00060     // Sets this shape's coordinates to the given.  Must be in the same size
00061     // and order as that returned by coordinates().  Specific to each shape
00062     // subclass.
00063     virtual void setCoordinates(const vector<PlotCoordinate>& c) = 0;
00064     
00065     // Returns true if a line is shown for this shape, false otherwise.
00066     virtual bool lineShown() const = 0;
00067     
00068     // Sets whether a line is shown for this shape or not.
00069     virtual void setLineShown(bool line = true) = 0;
00070     
00071     // Returns a copy of the line used for this shape.
00072     virtual PlotLinePtr line() const = 0;
00073     
00074     // Sets this shape's line to the given.
00075     virtual void setLine(const PlotLine& line) = 0;
00076     
00077     // Returns true if this shape has an area fill, false otherwise.
00078     virtual bool areaFilled() const = 0;
00079     
00080     // Sets whether or not this shape has an area fill.
00081     virtual void setAreaFilled(bool area = true) = 0;
00082     
00083     // Returns a copy of the area fill for this shape.
00084     virtual PlotAreaFillPtr areaFill() const = 0;
00085     
00086     // Sets this shape's area fill to the given.
00087     virtual void setAreaFill(const PlotAreaFill& fill) = 0;
00088     
00089     
00090     // IMPLEMENTED METHODS //
00091     
00092     // Convenience methods for setting the line for this shape.
00093     // <group>
00094     virtual void setLine(const PlotLinePtr l) {
00095         if(!l.null()) setLine(*l);
00096         else          setLineShown(false);
00097     }
00098     virtual void setLine(const String& color,
00099             PlotLine::Style style = PlotLine::SOLID, double width = 1.0) {
00100         PlotLinePtr l = line();
00101         l->setColor(color);
00102         l->setStyle(style);
00103         l->setWidth(width);
00104         setLine(*l);
00105     }
00106     // </group>
00107     
00108     // Convenience methods for setting the area fill.
00109     // <group>
00110     virtual void setAreaFill(const PlotAreaFillPtr f) {
00111         if(!f.null()) setAreaFill(*f);
00112         else          setAreaFilled(false);
00113     }
00114     virtual void setAreaFill(const String& color,
00115             PlotAreaFill::Pattern pattern = PlotAreaFill::FILL) {
00116         PlotAreaFillPtr f = areaFill();
00117         f->setColor(color);
00118         f->setPattern(pattern);
00119         setAreaFill(*f);
00120     }
00121     // </group>
00122 };
00123 
00124 
00125 // Specialization of PlotShape for a rectangle.  Getting/setting coordinates
00126 // MUST be in the order: [upperLeft, lowerRight].
00127 class PlotShapeRectangle : public virtual PlotShape {
00128 public:
00129     // Constructor.
00130     PlotShapeRectangle() { }
00131     
00132     // Destructor.
00133     virtual ~PlotShapeRectangle() { }
00134     
00135     // Sets the rectangle coordinates to the given.
00136     virtual void setRectCoordinates(const PlotCoordinate& upperLeft,
00137                                     const PlotCoordinate& lowerRight) = 0;
00138 };
00139 
00140 
00141 // Specialization of PlotShape for an ellipse.  Getting/setting coordinates
00142 // MUST be in the order: [center, radii].
00143 class PlotShapeEllipse : public virtual PlotShape {
00144 public:
00145     // Constructor.
00146     PlotShapeEllipse() { }
00147     
00148     // Destructor.
00149     virtual ~PlotShapeEllipse() { }
00150     
00151     
00152     // Sets the ellipse coordinates to the given.
00153     virtual void setEllipseCoordinates(const PlotCoordinate& center,
00154                                        const PlotCoordinate& radii) = 0;
00155     
00156     // Returns the x- and y- radii as a PlotCoordinate.
00157     virtual PlotCoordinate radii() const = 0;
00158     
00159     // Sets the x- and y- radii to the given.
00160     virtual void setRadii(const PlotCoordinate& radii) = 0;
00161     
00162     // Returns the center point.
00163     virtual PlotCoordinate center() const = 0;
00164     
00165     // Sets the center to the given.
00166     virtual void setCenter(const PlotCoordinate& center) = 0;
00167 };
00168 
00169 
00170 // Specialization of PlotShape for a polygon.
00171 class PlotShapePolygon : public virtual PlotShape {
00172 public:
00173     // Constructor.
00174     PlotShapePolygon() { }
00175     
00176     // Destructor.
00177     virtual ~PlotShapePolygon() { }
00178     
00179     // Overrides PlotShape::drawCount().  Provides default implementation that
00180     // returns the number of vertices.
00181     virtual unsigned int drawCount() const { return coordinates().size(); }
00182 };
00183 
00184 
00185 // Specialization of PlotShape for a line.  A line consists of an axis and a
00186 // location.  For example, a line at 5 on the X_BOTTOM axis would draw a
00187 // continuous line at x = 5.  Getting/setting coordinates MUST be in the order:
00188 // [location], where location has the value for x for X_BOTTOM or X_TOP or as y
00189 // for Y_LEFT or Y_RIGHT and is in world coordinates.
00190 class PlotShapeLine : public virtual PlotShape {
00191 public:
00192     // Constructor.
00193     PlotShapeLine() { }
00194     
00195     // Destructor.
00196     virtual ~PlotShapeLine() { }
00197 
00198     // Sets the line location to the given.
00199     virtual void setLineCoordinates(double location, PlotAxis axis) = 0;
00200     
00201     // Returns the line location.
00202     virtual double location() const = 0;
00203     
00204     // Returns the line axis.
00205     virtual PlotAxis axis() const = 0;
00206 };
00207 
00208 
00209 // Specialization of PlotShape for an arrow.  An arrow is a line segment
00210 // connecting two points, with optional arrows at either end.  PlotShape's line
00211 // methods apply both to the line segment and the outline of the arrow; the
00212 // areaFill methods apply to the arrow if applicable.  Getting/setting
00213 // coordinates MUST be in the order: [from, to].
00214 class PlotShapeArrow : public virtual PlotShape {
00215 public:
00216     // Arrow style.
00217     enum Style {
00218         TRIANGLE, // Filled triangle, 45-degree angle
00219         V_ARROW,  // Two lines forming a V, 45-degree angle
00220         NOARROW   // No arrow
00221     };
00222     
00223     
00224     // Constructor.
00225     PlotShapeArrow() { }
00226     
00227     // Destructor.
00228     virtual ~PlotShapeArrow() { }
00229 
00230     // Sets the arrow coordinates to the given.
00231     virtual void setArrowCoordinates(const PlotCoordinate& from,
00232                                      const PlotCoordinate& to) = 0;
00233     
00234     // Gets the arrow style on the from/to points.
00235     // <group>
00236     virtual Style arrowStyleFrom() const = 0;
00237     virtual Style arrowStyleTo() const = 0;
00238     // </group>
00239     
00240     // Sets the arrow style(s) to the given.
00241     // <group>
00242     virtual void setArrowStyleFrom(Style style) = 0;
00243     virtual void setArrowStyleTo(Style style) = 0;
00244     virtual void setArrowStyles(Style from, Style to) {
00245         setArrowStyleFrom(from);
00246         setArrowStyleTo(to);
00247     }
00248     // </group>
00249     
00250     // Returns the arrow size/length.
00251     virtual double arrowSize() const = 0;
00252     
00253     // Sets the arrow size/length to the given.
00254     virtual void setArrowSize(double size) = 0;
00255 };
00256 
00257 
00258 // Specialization of PlotShape for a path.  A path is a series of lines
00259 // connecting the given points.  (Like a polygon, but not connecting the first
00260 // and last points, or filled in.)
00261 class PlotShapePath : public virtual PlotShape {
00262 public:
00263     // Constructor.
00264     PlotShapePath() { }
00265     
00266     // Destructor.
00267     virtual ~PlotShapePath() { }
00268     
00269     // Overrides PlotShape::drawCount().  Provides default implementation that
00270     // returns the number of path points.
00271     virtual unsigned int drawCount() const { return coordinates().size(); }
00272 };
00273 
00274 
00275 // Specialization of PlotShape for an arc.  An arc has a start coordinate,
00276 // width, height, start angle, span angle, and orientation.  Getting/setting
00277 // coordinates MUST be in the order: [start, widthHeight].  The other
00278 // attributes must be set manually.
00279 class PlotShapeArc : public virtual PlotShape {
00280 public:
00281     // Constructor.
00282     PlotShapeArc() { }
00283     
00284     // Destructor.
00285     virtual ~PlotShapeArc() { }
00286 
00287     
00288     // Returns the start coordinate.
00289     virtual PlotCoordinate startCoordinate() const = 0;
00290     
00291     // Sets the start coordinate to the given.
00292     virtual void setStartCoordinate(const PlotCoordinate& coord) = 0;
00293     
00294     // Returns the width and height as a PlotCoordinate.
00295     virtual PlotCoordinate widthHeight() const = 0;
00296     
00297     // Sets the width and height to the given.
00298     virtual void setWidthHeight(double width, double height) {
00299         setWidthHeight(PlotCoordinate(width, height, PlotCoordinate::WORLD)); }
00300     
00301     // Sets the width and height as a PlotCoordinate.
00302     virtual void setWidthHeight(const PlotCoordinate& widthHeight) = 0;
00303     
00304     // Returns the start angle.
00305     virtual int startAngle() const = 0;
00306     
00307     // Sets the start angle.
00308     virtual void setStartAngle(int startAngle) = 0;
00309     
00310     // Returns the span angle.
00311     virtual int spanAngle() const = 0;
00312     
00313     // Sets the span angle.
00314     virtual void setSpanAngle(int spanAngle) = 0;
00315     
00316     // Returns the orientation.
00317     virtual int orientation() const = 0;
00318     
00319     // Sets the orientation.
00320     virtual void setOrientation(int o) = 0;
00321 };
00322 
00323 
00324 // Abstract class for a single point on the canvas (not descended from
00325 // PlotShape).
00326 class PlotPoint : public virtual PlotItem {
00327 public:
00328     // Constructor.
00329     PlotPoint() { }
00330     
00331     // Destructor.
00332     virtual ~PlotPoint() { }
00333     
00334     
00335     // Implements PlotItem::drawCount().  Provides default implementation that
00336     // returns 1.
00337     virtual unsigned int drawCount() const { return 1; }
00338     
00339     
00340     // ABSTRACT METHODS //
00341     
00342     // Returns the location of the point.
00343     virtual PlotCoordinate coordinate() const = 0;
00344     
00345     // Sets the location of the point to the given.
00346     virtual void setCoordinate(const PlotCoordinate& coordinate) = 0;
00347     
00348     // Returns a copy of the symbol used to draw the point.
00349     virtual PlotSymbolPtr symbol() const = 0;
00350  
00351     // Sets the symbol used to draw the point.
00352     virtual void setSymbol(const PlotSymbol& symbol) = 0;
00353     
00354     
00355     // IMPLEMENTED METHODS //
00356     
00357     // Convenience methods for setting the symbol.
00358     // </group>
00359     virtual void setSymbol(const PlotSymbolPtr symbol) {
00360         if(!symbol.null()) setSymbol(*symbol); }
00361     virtual void setSymbol(PlotSymbol::Symbol sym) {
00362         PlotSymbolPtr s = symbol();
00363         s->setSymbol(sym);
00364         setSymbol(*s);
00365     }
00366     // </group>
00367 };
00368 
00369 
00371 // SMART POINTER DEFINITIONS //
00373 
00374 INHERITANCE_POINTER2(PlotShape, PlotShapePtr, PlotItem, PlotItemPtr)
00375 INHERITANCE_POINTER(PlotShapeRectangle, PlotShapeRectanglePtr, PlotShape,
00376                     PlotShapePtr, PlotItem, PlotItemPtr)
00377 INHERITANCE_POINTER(PlotShapeEllipse, PlotShapeEllipsePtr, PlotShape,
00378                     PlotShapePtr, PlotItem, PlotItemPtr)
00379 INHERITANCE_POINTER(PlotShapePolygon, PlotShapePolygonPtr, PlotShape,
00380                     PlotShapePtr, PlotItem, PlotItemPtr)
00381 INHERITANCE_POINTER(PlotShapeLine, PlotShapeLinePtr, PlotShape, PlotShapePtr,
00382                     PlotItem, PlotItemPtr)
00383 INHERITANCE_POINTER(PlotShapeArrow, PlotShapeArrowPtr, PlotShape,
00384                     PlotShapePtr, PlotItem, PlotItemPtr)
00385 INHERITANCE_POINTER(PlotShapePath, PlotShapePathPtr, PlotShape, PlotShapePtr,
00386                     PlotItem, PlotItemPtr)
00387 INHERITANCE_POINTER(PlotShapeArc, PlotShapeArcPtr, PlotShape, PlotShapePtr,
00388                     PlotItem, PlotItemPtr)
00389 INHERITANCE_POINTER2(PlotPoint, PlotPointPtr, PlotItem, PlotItemPtr)
00390 
00391 }
00392 
00393 #endif /*PLOTSHAPE_H_*/