casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotShape.h
Go to the documentation of this file.
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 
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,
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.
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.
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.
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.
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.
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.
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.
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 
368 // SMART POINTER DEFINITIONS //
370 
372 INHERITANCE_POINTER(PlotShapeRectangle, PlotShapeRectanglePtr, PlotShape,
374 INHERITANCE_POINTER(PlotShapeEllipse, PlotShapeEllipsePtr, PlotShape,
375  PlotShapePtr, PlotItem, PlotItemPtr)
376 INHERITANCE_POINTER(PlotShapePolygon, PlotShapePolygonPtr, PlotShape,
377  PlotShapePtr, PlotItem, PlotItemPtr)
378 INHERITANCE_POINTER(PlotShapeLine, PlotShapeLinePtr, PlotShape, PlotShapePtr,
379  PlotItem, PlotItemPtr)
380 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 INHERITANCE_POINTER2(PlotPoint, PlotPointPtr, PlotItem, PlotItemPtr)
387 
388 }
389 
390 #endif /*PLOTSHAPE_H_*/
virtual void setAreaFill(const PlotAreaFill &fill)=0
Sets this shape&#39;s area fill to the given.
virtual PlotCoordinate startCoordinate() const =0
Returns the start coordinate.
Bool null() const
Check to see if this CountedPtr is un-initialized, null.
Definition: CountedPtr.h:237
virtual int startAngle() const =0
Returns the start angle.
virtual bool lineShown() const =0
Returns true if a line is shown for this shape, false otherwise.
virtual ~PlotShapeArrow()
Destructor.
Definition: PlotShape.h:225
PlotShapePolygon()
Constructor.
Definition: PlotShape.h:171
virtual std::vector< PlotCoordinate > coordinates() const =0
ABSTRACT METHODS //.
virtual PlotAxis axis() const =0
Returns the line axis.
PlotShapeArrow()
Constructor.
Definition: PlotShape.h:222
virtual void setAreaFill(const casacore::String &color, PlotAreaFill::Pattern pattern=PlotAreaFill::FILL)
Definition: PlotShape.h:111
PlotShapeLine()
Constructor.
Definition: PlotShape.h:190
virtual void setAreaFill(const PlotAreaFillPtr f)
Convenience methods for setting the area fill.
Definition: PlotShape.h:107
virtual void setArrowSize(double size)=0
Sets the arrow size/length to the given.
virtual void setLine(const casacore::String &color, PlotLine::Style style=PlotLine::SOLID, double width=1.0)
Definition: PlotShape.h:95
virtual void setCoordinate(const PlotCoordinate &coordinate)=0
Sets the location of the point to the given.
virtual void setRectCoordinates(const PlotCoordinate &upperLeft, const PlotCoordinate &lowerRight)=0
Sets the rectangle coordinates to the given.
SMART POINTER DEFINITIONS PlotItemPtr PlotShapeLinePtr
Definition: PlotShape.h:378
virtual PlotCoordinate radii() const =0
Returns the x- and y- radii as a PlotCoordinate.
PlotPoint()
Constructor.
Definition: PlotShape.h:326
virtual double location() const =0
Returns the line location.
Abstract class for any shape which contains common functionality.
Definition: PlotShape.h:37
virtual ~PlotShapePath()
Destructor.
Definition: PlotShape.h:264
PlotShapeArc()
Constructor.
Definition: PlotShape.h:279
Abstract class for area fill.
Definition: PlotOptions.h:296
virtual PlotLinePtr line() const =0
Returns a copy of the line used for this shape.
virtual void setWidthHeight(double width, double height)
Sets the width and height to the given.
Definition: PlotShape.h:295
virtual void setEllipseCoordinates(const PlotCoordinate &center, const PlotCoordinate &radii)=0
Sets the ellipse coordinates to the given.
Style
Arrow style.
Definition: PlotShape.h:214
virtual void setArrowStyles(Style from, Style to)
Definition: PlotShape.h:241
Pattern
Pattern enum, similar in spirit to http://doc.trolltech.com/4.3/qt.html#BrushStyle-enum.
Definition: PlotOptions.h:300
SMART POINTER DEFINITIONS PlotShapeEllipsePtr
Definition: PlotShape.h:374
size_t size() const
Specialization of PlotShape for a line.
Definition: PlotShape.h:187
TableExprNode pattern(const TableExprNode &node)
Definition: ExprNode.h:1444
virtual ~PlotShapePolygon()
Destructor.
Definition: PlotShape.h:174
virtual ~PlotPoint()
Destructor.
Definition: PlotShape.h:329
virtual double arrowSize() const =0
Returns the arrow size/length.
PlotShapeRectangle()
Constructor.
Definition: PlotShape.h:127
PlotShape()
Constructor.
Definition: PlotShape.h:40
virtual void setLine(const PlotLine &line)=0
Sets this shape&#39;s line to the given.
virtual void setLine(const PlotLinePtr l)
IMPLEMENTED METHODS //.
Definition: PlotShape.h:91
virtual ~PlotShapeLine()
Destructor.
Definition: PlotShape.h:193
virtual void setCenter(const PlotCoordinate &center)=0
Sets the center to the given.
virtual PlotCoordinate widthHeight() const =0
Returns the width and height as a PlotCoordinate.
virtual PlotSymbolPtr symbol() const =0
Returns a copy of the symbol used to draw the point.
virtual void setRadii(const PlotCoordinate &radii)=0
Sets the x- and y- radii to the given.
Specialization of PlotShape for an arrow.
Definition: PlotShape.h:211
PlotShapeEllipse()
Constructor.
Definition: PlotShape.h:143
virtual void setSpanAngle(int spanAngle)=0
Sets the span angle.
virtual bool areaFilled() const =0
Returns true if this shape has an area fill, false otherwise.
Abstract class for a line.
Definition: PlotOptions.h:368
virtual ~PlotShapeRectangle()
Destructor.
Definition: PlotShape.h:130
SMART POINTER DEFINITIONS PlotShapePtr
Definition: PlotShape.h:374
PlotItem
Definition: Plot.h:598
SMART POINTER DEFINITIONS PlotShape
Definition: PlotShape.h:374
Style
Static //.
Definition: PlotOptions.h:373
virtual void setOrientation(int o)=0
Sets the orientation.
PlotAxis
Enum for the four plot axes.
Definition: PlotOptions.h:62
virtual unsigned int drawCount() const
Implements PlotItem::drawCount().
Definition: PlotShape.h:334
SMART POINTER DEFINITIONS PlotItemPtr PlotItemPtr PlotShapePathPtr
Definition: PlotShape.h:382
virtual void setCoordinates(const std::vector< PlotCoordinate > &c)=0
Sets this shape&#39;s coordinates to the given.
Specialization of PlotShape for a rectangle.
Definition: PlotShape.h:124
Abstract class for a symbol.
Definition: PlotOptions.h:451
Abstract class for a single point on the canvas (not descended from PlotShape).
Definition: PlotShape.h:323
virtual ~PlotShapeArc()
Destructor.
Definition: PlotShape.h:282
virtual unsigned int drawCount() const
Overrides PlotShape::drawCount().
Definition: PlotShape.h:178
PlotItem is the superclass of any object that is meant to be placed on the canvas (plots...
Definition: PlotItem.h:40
virtual void setSymbol(const PlotSymbol &symbol)=0
Sets the symbol used to draw the point.
PlotShapePath()
Constructor.
Definition: PlotShape.h:261
virtual void setStartCoordinate(const PlotCoordinate &coord)=0
Sets the start coordinate to the given.
virtual PlotCoordinate center() const =0
Returns the center point.
INHERITANCE_POINTER2(PlotLayoutSingle, PlotLayoutSinglePtr, PlotCanvasLayout, PlotCanvasLayoutPtr) INHERITANCE_POINTER2(PlotLayoutGrid
virtual void setArrowCoordinates(const PlotCoordinate &from, const PlotCoordinate &to)=0
Sets the arrow coordinates to the given.
Symbol
Static //.
Definition: PlotOptions.h:456
virtual Style arrowStyleFrom() const =0
Gets the arrow style on the from/to points.
casacore::CountedPtr< PlotItem > PlotItemPtr
Definition: PlotItem.h:98
Specialization of PlotShape for a polygon.
Definition: PlotShape.h:168
virtual ~PlotShape()
Destructor.
Definition: PlotShape.h:43
virtual int orientation() const =0
Returns the orientation.
virtual void setStartAngle(int startAngle)=0
Sets the start angle.
virtual unsigned int drawCount() const
Overrides PlotShape::drawCount().
Definition: PlotShape.h:268
Specialization of PlotShape for an arc.
Definition: PlotShape.h:276
virtual void setLineShown(bool line=true)=0
Sets whether a line is shown for this shape or not.
const Double c
Fundamental physical constants (SI units):
virtual ~PlotShapeEllipse()
Destructor.
Definition: PlotShape.h:146
Specialization of PlotShape for a path.
Definition: PlotShape.h:258
virtual unsigned int drawCount() const
Implements PlotItem::drawCount().
Definition: PlotShape.h:48
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void setAreaFilled(bool area=true)=0
Sets whether or not this shape has an area fill.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and
INHERITANCE_POINTER(PlotFlagAllTool, PlotFlagAllToolPtr, PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr) TOOL NOTIFICATION CLASSESInterface for objects that want to be notified when the selection tool changes.*/class PlotSelectToolNotifier
Definition: PlotTool.h:675
virtual Style arrowStyleTo() const =0
virtual PlotCoordinate coordinate() const =0
ABSTRACT METHODS //.
virtual int spanAngle() const =0
Returns the span angle.
virtual PlotAreaFillPtr areaFill() const =0
Returns a copy of the area fill for this shape.
virtual void setArrowStyleFrom(Style style)=0
Sets the arrow style(s) to the given.
Specialization of PlotShape for an ellipse.
Definition: PlotShape.h:140
virtual void setArrowStyleTo(Style style)=0
virtual void setLineCoordinates(double location, PlotAxis axis)=0
Sets the line location to the given.