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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1