LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotShape.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 0 6 0.0 %
Date: 2023-10-25 08:47:59 Functions: 0 9 0.0 %

          Line data    Source code
       1             : //# PlotShape.h: Different shape classes that can be drawn on a canvas.
       2             : //# Copyright (C) 2008
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: aips2-request@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id: $
      27             : #ifndef PLOTSHAPE_H_
      28             : #define PLOTSHAPE_H_
      29             : 
      30             : #include <graphics/GenericPlotter/PlotItem.h>
      31             : 
      32             : #include <vector>
      33             : 
      34             : namespace casa {
      35             : 
      36             : // Abstract class for any shape which contains common functionality.
      37             : class PlotShape : public virtual PlotItem {
      38             : public:
      39             :     // Constructor.
      40             :     PlotShape() { }
      41             :     
      42             :     // Destructor.
      43             :     virtual ~PlotShape() { }
      44             :     
      45             :     
      46             :     // Implements PlotItem::drawCount().  Provides default implementation that
      47             :     // returns 1.
      48             :     virtual unsigned int drawCount() const { return 1; }
      49             :     
      50             :     
      51             :     // ABSTRACT METHODS //
      52             :     
      53             :     // Returns the coordinates for this shape.  The number and order depends
      54             :     // on the specific shape subclass.
      55             :     virtual std::vector<PlotCoordinate> coordinates() const = 0;
      56             :     
      57             :     // Sets this shape's coordinates to the given.  Must be in the same size
      58             :     // and order as that returned by coordinates().  Specific to each shape
      59             :     // subclass.
      60             :     virtual void setCoordinates(const std::vector<PlotCoordinate>& c) = 0;
      61             :     
      62             :     // Returns true if a line is shown for this shape, false otherwise.
      63             :     virtual bool lineShown() const = 0;
      64             :     
      65             :     // Sets whether a line is shown for this shape or not.
      66             :     virtual void setLineShown(bool line = true) = 0;
      67             :     
      68             :     // Returns a copy of the line used for this shape.
      69             :     virtual PlotLinePtr line() const = 0;
      70             :     
      71             :     // Sets this shape's line to the given.
      72             :     virtual void setLine(const PlotLine& line) = 0;
      73             :     
      74             :     // Returns true if this shape has an area fill, false otherwise.
      75             :     virtual bool areaFilled() const = 0;
      76             :     
      77             :     // Sets whether or not this shape has an area fill.
      78             :     virtual void setAreaFilled(bool area = true) = 0;
      79             :     
      80             :     // Returns a copy of the area fill for this shape.
      81             :     virtual PlotAreaFillPtr areaFill() const = 0;
      82             :     
      83             :     // Sets this shape's area fill to the given.
      84             :     virtual void setAreaFill(const PlotAreaFill& fill) = 0;
      85             :     
      86             :     
      87             :     // IMPLEMENTED METHODS //
      88             :     
      89             :     // Convenience methods for setting the line for this shape.
      90             :     // <group>
      91             :     virtual void setLine(const PlotLinePtr l) {
      92             :         if(!l.null()) setLine(*l);
      93             :         else          setLineShown(false);
      94             :     }
      95             :     virtual void setLine(const casacore::String& color,
      96             :             PlotLine::Style style = PlotLine::SOLID, double width = 1.0) {
      97             :         PlotLinePtr l = line();
      98             :         l->setColor(color);
      99             :         l->setStyle(style);
     100             :         l->setWidth(width);
     101             :         setLine(*l);
     102             :     }
     103             :     // </group>
     104             :     
     105             :     // Convenience methods for setting the area fill.
     106             :     // <group>
     107             :     virtual void setAreaFill(const PlotAreaFillPtr f) {
     108             :         if(!f.null()) setAreaFill(*f);
     109             :         else          setAreaFilled(false);
     110             :     }
     111             :     virtual void setAreaFill(const casacore::String& color,
     112             :             PlotAreaFill::Pattern pattern = PlotAreaFill::FILL) {
     113             :         PlotAreaFillPtr f = areaFill();
     114             :         f->setColor(color);
     115             :         f->setPattern(pattern);
     116             :         setAreaFill(*f);
     117             :     }
     118             :     // </group>
     119             : };
     120             : 
     121             : 
     122             : // Specialization of PlotShape for a rectangle.  Getting/setting coordinates
     123             : // MUST be in the order: [upperLeft, lowerRight].
     124             : class PlotShapeRectangle : public virtual PlotShape {
     125             : public:
     126             :     // Constructor.
     127             :     PlotShapeRectangle() { }
     128             :     
     129             :     // Destructor.
     130             :     virtual ~PlotShapeRectangle() { }
     131             :     
     132             :     // Sets the rectangle coordinates to the given.
     133             :     virtual void setRectCoordinates(const PlotCoordinate& upperLeft,
     134             :                                     const PlotCoordinate& lowerRight) = 0;
     135             : };
     136             : 
     137             : 
     138             : // Specialization of PlotShape for an ellipse.  Getting/setting coordinates
     139             : // MUST be in the order: [center, radii].
     140             : class PlotShapeEllipse : public virtual PlotShape {
     141             : public:
     142             :     // Constructor.
     143             :     PlotShapeEllipse() { }
     144             :     
     145             :     // Destructor.
     146             :     virtual ~PlotShapeEllipse() { }
     147             :     
     148             :     
     149             :     // Sets the ellipse coordinates to the given.
     150             :     virtual void setEllipseCoordinates(const PlotCoordinate& center,
     151             :                                        const PlotCoordinate& radii) = 0;
     152             :     
     153             :     // Returns the x- and y- radii as a PlotCoordinate.
     154             :     virtual PlotCoordinate radii() const = 0;
     155             :     
     156             :     // Sets the x- and y- radii to the given.
     157             :     virtual void setRadii(const PlotCoordinate& radii) = 0;
     158             :     
     159             :     // Returns the center point.
     160             :     virtual PlotCoordinate center() const = 0;
     161             :     
     162             :     // Sets the center to the given.
     163             :     virtual void setCenter(const PlotCoordinate& center) = 0;
     164             : };
     165             : 
     166             : 
     167             : // Specialization of PlotShape for a polygon.
     168             : class PlotShapePolygon : public virtual PlotShape {
     169             : public:
     170             :     // Constructor.
     171             :     PlotShapePolygon() { }
     172             :     
     173             :     // Destructor.
     174             :     virtual ~PlotShapePolygon() { }
     175             :     
     176             :     // Overrides PlotShape::drawCount().  Provides default implementation that
     177             :     // returns the number of vertices.
     178             :     virtual unsigned int drawCount() const { return coordinates().size(); }
     179             : };
     180             : 
     181             : 
     182             : // Specialization of PlotShape for a line.  A line consists of an axis and a
     183             : // location.  For example, a line at 5 on the X_BOTTOM axis would draw a
     184             : // continuous line at x = 5.  Getting/setting coordinates MUST be in the order:
     185             : // [location], where location has the value for x for X_BOTTOM or X_TOP or as y
     186             : // for Y_LEFT or Y_RIGHT and is in world coordinates.
     187             : class PlotShapeLine : public virtual PlotShape {
     188             : public:
     189             :     // Constructor.
     190             :     PlotShapeLine() { }
     191             :     
     192             :     // Destructor.
     193             :     virtual ~PlotShapeLine() { }
     194             : 
     195             :     // Sets the line location to the given.
     196             :     virtual void setLineCoordinates(double location, PlotAxis axis) = 0;
     197             :     
     198             :     // Returns the line location.
     199             :     virtual double location() const = 0;
     200             :     
     201             :     // Returns the line axis.
     202             :     virtual PlotAxis axis() const = 0;
     203             : };
     204             : 
     205             : 
     206             : // Specialization of PlotShape for an arrow.  An arrow is a line segment
     207             : // connecting two points, with optional arrows at either end.  PlotShape's line
     208             : // methods apply both to the line segment and the outline of the arrow; the
     209             : // areaFill methods apply to the arrow if applicable.  Getting/setting
     210             : // coordinates MUST be in the order: [from, to].
     211             : class PlotShapeArrow : public virtual PlotShape {
     212             : public:
     213             :     // Arrow style.
     214             :     enum Style {
     215             :         TRIANGLE, // Filled triangle, 45-degree angle
     216             :         V_ARROW,  // Two lines forming a V, 45-degree angle
     217             :         NOARROW   // No arrow
     218             :     };
     219             :     
     220             :     
     221             :     // Constructor.
     222             :     PlotShapeArrow() { }
     223             :     
     224             :     // Destructor.
     225             :     virtual ~PlotShapeArrow() { }
     226             : 
     227             :     // Sets the arrow coordinates to the given.
     228             :     virtual void setArrowCoordinates(const PlotCoordinate& from,
     229             :                                      const PlotCoordinate& to) = 0;
     230             :     
     231             :     // Gets the arrow style on the from/to points.
     232             :     // <group>
     233             :     virtual Style arrowStyleFrom() const = 0;
     234             :     virtual Style arrowStyleTo() const = 0;
     235             :     // </group>
     236             :     
     237             :     // Sets the arrow style(s) to the given.
     238             :     // <group>
     239             :     virtual void setArrowStyleFrom(Style style) = 0;
     240             :     virtual void setArrowStyleTo(Style style) = 0;
     241             :     virtual void setArrowStyles(Style from, Style to) {
     242             :         setArrowStyleFrom(from);
     243             :         setArrowStyleTo(to);
     244             :     }
     245             :     // </group>
     246             :     
     247             :     // Returns the arrow size/length.
     248             :     virtual double arrowSize() const = 0;
     249             :     
     250             :     // Sets the arrow size/length to the given.
     251             :     virtual void setArrowSize(double size) = 0;
     252             : };
     253             : 
     254             : 
     255             : // Specialization of PlotShape for a path.  A path is a series of lines
     256             : // connecting the given points.  (Like a polygon, but not connecting the first
     257             : // and last points, or filled in.)
     258             : class PlotShapePath : public virtual PlotShape {
     259             : public:
     260             :     // Constructor.
     261             :     PlotShapePath() { }
     262             :     
     263             :     // Destructor.
     264             :     virtual ~PlotShapePath() { }
     265             :     
     266             :     // Overrides PlotShape::drawCount().  Provides default implementation that
     267             :     // returns the number of path points.
     268             :     virtual unsigned int drawCount() const { return coordinates().size(); }
     269             : };
     270             : 
     271             : 
     272             : // Specialization of PlotShape for an arc.  An arc has a start coordinate,
     273             : // width, height, start angle, span angle, and orientation.  Getting/setting
     274             : // coordinates MUST be in the order: [start, widthHeight].  The other
     275             : // attributes must be set manually.
     276             : class PlotShapeArc : public virtual PlotShape {
     277             : public:
     278             :     // Constructor.
     279             :     PlotShapeArc() { }
     280             :     
     281             :     // Destructor.
     282             :     virtual ~PlotShapeArc() { }
     283             : 
     284             :     
     285             :     // Returns the start coordinate.
     286             :     virtual PlotCoordinate startCoordinate() const = 0;
     287             :     
     288             :     // Sets the start coordinate to the given.
     289             :     virtual void setStartCoordinate(const PlotCoordinate& coord) = 0;
     290             :     
     291             :     // Returns the width and height as a PlotCoordinate.
     292             :     virtual PlotCoordinate widthHeight() const = 0;
     293             :     
     294             :     // Sets the width and height to the given.
     295             :     virtual void setWidthHeight(double width, double height) {
     296             :         setWidthHeight(PlotCoordinate(width, height, PlotCoordinate::WORLD)); }
     297             :     
     298             :     // Sets the width and height as a PlotCoordinate.
     299             :     virtual void setWidthHeight(const PlotCoordinate& widthHeight) = 0;
     300             :     
     301             :     // Returns the start angle.
     302             :     virtual int startAngle() const = 0;
     303             :     
     304             :     // Sets the start angle.
     305             :     virtual void setStartAngle(int startAngle) = 0;
     306             :     
     307             :     // Returns the span angle.
     308             :     virtual int spanAngle() const = 0;
     309             :     
     310             :     // Sets the span angle.
     311             :     virtual void setSpanAngle(int spanAngle) = 0;
     312             :     
     313             :     // Returns the orientation.
     314             :     virtual int orientation() const = 0;
     315             :     
     316             :     // Sets the orientation.
     317             :     virtual void setOrientation(int o) = 0;
     318             : };
     319             : 
     320             : 
     321             : // Abstract class for a single point on the canvas (not descended from
     322             : // PlotShape).
     323             : class PlotPoint : public virtual PlotItem {
     324             : public:
     325             :     // Constructor.
     326             :     PlotPoint() { }
     327             :     
     328             :     // Destructor.
     329             :     virtual ~PlotPoint() { }
     330             :     
     331             :     
     332             :     // Implements PlotItem::drawCount().  Provides default implementation that
     333             :     // returns 1.
     334             :     virtual unsigned int drawCount() const { return 1; }
     335             :     
     336             :     
     337             :     // ABSTRACT METHODS //
     338             :     
     339             :     // Returns the location of the point.
     340             :     virtual PlotCoordinate coordinate() const = 0;
     341             :     
     342             :     // Sets the location of the point to the given.
     343             :     virtual void setCoordinate(const PlotCoordinate& coordinate) = 0;
     344             :     
     345             :     // Returns a copy of the symbol used to draw the point.
     346             :     virtual PlotSymbolPtr symbol() const = 0;
     347             :  
     348             :     // Sets the symbol used to draw the point.
     349             :     virtual void setSymbol(const PlotSymbol& symbol) = 0;
     350             :     
     351             :     
     352             :     // IMPLEMENTED METHODS //
     353             :     
     354             :     // Convenience methods for setting the symbol.
     355             :     // </group>
     356             :     virtual void setSymbol(const PlotSymbolPtr symbol) {
     357             :         if(!symbol.null()) setSymbol(*symbol); }
     358             :     virtual void setSymbol(PlotSymbol::Symbol sym) {
     359             :         PlotSymbolPtr s = symbol();
     360             :         s->setSymbol(sym);
     361             :         setSymbol(*s);
     362             :     }
     363             :     // </group>
     364             : };
     365             : 
     366             : 
     367             : ///////////////////////////////
     368             : // SMART POINTER DEFINITIONS //
     369             : ///////////////////////////////
     370             : 
     371           0 : INHERITANCE_POINTER2(PlotShape, PlotShapePtr, PlotItem, PlotItemPtr)
     372           0 : INHERITANCE_POINTER(PlotShapeRectangle, PlotShapeRectanglePtr, PlotShape,
     373             :                     PlotShapePtr, PlotItem, PlotItemPtr)
     374           0 : INHERITANCE_POINTER(PlotShapeEllipse, PlotShapeEllipsePtr, PlotShape,
     375             :                     PlotShapePtr, PlotItem, PlotItemPtr)
     376             : INHERITANCE_POINTER(PlotShapePolygon, PlotShapePolygonPtr, PlotShape,
     377             :                     PlotShapePtr, PlotItem, PlotItemPtr)
     378           0 : INHERITANCE_POINTER(PlotShapeLine, PlotShapeLinePtr, PlotShape, PlotShapePtr,
     379             :                     PlotItem, PlotItemPtr)
     380           0 : INHERITANCE_POINTER(PlotShapeArrow, PlotShapeArrowPtr, PlotShape,
     381             :                     PlotShapePtr, PlotItem, PlotItemPtr)
     382             : INHERITANCE_POINTER(PlotShapePath, PlotShapePathPtr, PlotShape, PlotShapePtr,
     383             :                     PlotItem, PlotItemPtr)
     384             : INHERITANCE_POINTER(PlotShapeArc, PlotShapeArcPtr, PlotShape, PlotShapePtr,
     385             :                     PlotItem, PlotItemPtr)
     386           0 : INHERITANCE_POINTER2(PlotPoint, PlotPointPtr, PlotItem, PlotItemPtr)
     387             : 
     388             : }
     389             : 
     390             : #endif /*PLOTSHAPE_H_*/

Generated by: LCOV version 1.16