casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotCanvasLayout.h
Go to the documentation of this file.
1 //# PlotCanvasLayout.h: Different layouts for PlotCanvases.
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 PLOTCANVASLAYOUT_H_
28 #define PLOTCANVASLAYOUT_H_
29 
31 
32 namespace casa {
33 
34 //# Forward Declarations
35 class Plotter;
36 
37 
39 // BASE CLASSES //
41 
42 // A coordinate for layouts. Each layout implementation should also provide
43 // a coordinate implementation.
45 public:
47 
48  virtual ~PlotLayoutCoordinate() { }
49 };
50 
51 // Base class for any layout.
53 public:
54  // Constructor.
56 
57  // Destructor.
58  virtual ~PlotCanvasLayout() { }
59 
60 
61  // Returns the plotter this layout is used in, or NULL for none.
62  virtual Plotter* plotter() const { return m_plotter; }
63 
64  // Attaches this layout to the given plotter. The plotter's
65  // layoutOptionsChanged method can then be called when the layout changes.
66  virtual void attach(Plotter* p) { m_plotter = p; }
67 
68 
69  // ABSTRACT METHODS //
70 
71  // Returns true if the given coordinate is valid for this layout.
72  virtual bool coordIsValid(const PlotLayoutCoordinate& coord) const = 0;
73 
74  // turn the coordinate into an index. the index should >= 0 and < the
75  // total number of canvases in the layout.
76  virtual int coordToIndex(const PlotLayoutCoordinate& coord) const = 0;
77 
78  // Sets the canvas at the given coordinate to the given canvas.
79  virtual void setCanvasAt(const PlotLayoutCoordinate& coord,
80  PlotCanvasPtr canvas) = 0;
81 
82  // Returns the canvas at the given coordinate.
83  virtual PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const =0;
84 
85  // For single layouts, returns the canvas; otherwise returns the "first".
86  virtual PlotCanvasPtr canvas() const = 0;
87 
88  // Returns all canvases in this layout.
89  virtual std::vector<PlotCanvasPtr> allCanvases() const = 0;
90 
91  // Indicates whether the layout is valid.
92  virtual bool isValid() const = 0;
93 
94  // Gets/sets the spacing between the canvases in the layout. May not be
95  // valid for all layout types. The implementation for Plotter should use
96  // this attribute appropriately.
97  // <group>
98  virtual unsigned int spacing() const = 0;
99  virtual void setSpacing(unsigned int spacing) = 0;
100  // </group>
101 
102 protected:
103  Plotter* m_plotter; // Plotter
104 };
105 
106 
108 // SINGLE LAYOUT CLASSES //
110 
111 // PlotLayoutSingle is basically just a wrapper for a single canvas.
112 class PlotLayoutSingle : public virtual PlotCanvasLayout {
113 public:
114  // Constructor which takes the canvas.
116 
117  // Destructor.
119 
120 
121  // Implements PlotCanvasLayout::coordIsValid().
122  bool coordIsValid(const PlotLayoutCoordinate& ) const { return true; }
123 
124  // Implements PlotCanvasLayout::coordToIndex().
125  int coordToIndex(const PlotLayoutCoordinate& ) const { return 0; }
126 
127  // Implements PlotCanvasLayout::setCanvasAt().
128  void setCanvasAt(const PlotLayoutCoordinate& coord, PlotCanvasPtr c);
129 
130  // Sets this layout's canvas to the given.
132 
133  // Implements PlotCanvasLayout::canvas().
134  PlotCanvasPtr canvas() const;
135 
136  // Implements PlotCanvasLayout::canvasAt().
137  PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const;
138 
139  // Implements PlotCanvasLayout::allCanvases().
140  std::vector<PlotCanvasPtr> allCanvases() const;
141 
142  // Implements PlotCanvasLayout::isValid().
143  bool isValid() const;
144 
145  // Implements PlotCanvasLayout::spacing().
146  unsigned int spacing() const { return 0; }
147 
148  // Implements PlotCanvasLayout::setSpacing().
149  void setSpacing(unsigned int ) { }
150 
151 protected:
153 };
154 
155 
157 // GRID LAYOUT CLASSES //
159 
160 // casacore::Coordinate for a grid layout, which consists of a row and column.
161 class PlotGridCoordinate : public virtual PlotLayoutCoordinate {
162 public:
163  PlotGridCoordinate(unsigned int r, unsigned int c): row(r), col(c) { }
164 
166 
167  unsigned int row;
168  unsigned int col;
169 };
170 
171 // An n x m grid of canvases.
172 class PlotLayoutGrid : public virtual PlotCanvasLayout {
173 public:
174  // Constructor which takes the number of rows and columns.
175  PlotLayoutGrid(unsigned int rows, unsigned int cols);
176 
177  // Destructor.
178  ~PlotLayoutGrid();
179 
180  // Returns the number of rows.
181  unsigned int rows() const;
182 
183  // Returns the number of columns.
184  unsigned int cols() const;
185 
186  // Implements PlotCanvasLayout::coordIsValid().
187  bool coordIsValid(const PlotLayoutCoordinate& coord) const;
188 
189  // Implements PlotCanvasLayout::coordToIndex().
190  int coordToIndex(const PlotLayoutCoordinate& coord) const;
191 
192  // Implements PlotCanvasLayout::setCanvasAt().
194 
195  // Implements PlotCanvasLayout::canvasAt().
196  PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const;
197 
198  // Implements PlotCanvasLayout::canvas().
199  PlotCanvasPtr canvas() const;
200 
201  // Implements PlotCanvasLayout::allCanvases().
202  std::vector<PlotCanvasPtr> allCanvases() const;
203 
204  // Implements PlotCanvasLayout::isValid().
205  bool isValid() const;
206 
207  // Implements PlotCanvasLayout::spacing().
208  unsigned int spacing() const;
209 
210  // Implements PlotCanvasLayout::setSpacing().
211  void setSpacing(unsigned int spacing);
212 
213 protected:
214  unsigned int m_rows; // rows
215  unsigned int m_cols; // columns
216  std::vector<std::vector<PlotCanvasPtr> > m_panels; // canvases
217  unsigned int m_spacing; // spacing
218 };
219 
220 
222 // SMART POINTER DEFINITIONS //
224 
230 
231 }
232 
233 #endif /*PLOTCANVASLAYOUT_H_*/
An n x m grid of canvases.
void setCanvasAt(const PlotLayoutCoordinate &coord, PlotCanvasPtr c)
Implements PlotCanvasLayout::setCanvasAt().
PlotLayoutGrid(unsigned int rows, unsigned int cols)
Constructor which takes the number of rows and columns.
PlotCanvasPtr canvas() const
Implements PlotCanvasLayout::canvas().
PlotLayoutSingle(PlotCanvasPtr c)
Constructor which takes the canvas.
void setSpacing(unsigned int)
Implements PlotCanvasLayout::setSpacing().
virtual void attach(Plotter *p)
Attaches this layout to the given plotter.
int coordToIndex(const PlotLayoutCoordinate &) const
Implements PlotCanvasLayout::coordToIndex().
PlotCanvasLayout()
Constructor.
unsigned int spacing() const
Implements PlotCanvasLayout::spacing().
PlotCanvasPtr canvas() const
Implements PlotCanvasLayout::canvas().
bool coordIsValid(const PlotLayoutCoordinate &coord) const
Implements PlotCanvasLayout::coordIsValid().
SMART POINTER DEFINITIONS *typedef casacore::CountedPtr< PlotCanvasLayout > PlotCanvasLayoutPtr
virtual unsigned int spacing() const =0
Gets/sets the spacing between the canvases in the layout.
void setCanvasAt(const PlotLayoutCoordinate &coord, PlotCanvasPtr canvas)
Implements PlotCanvasLayout::setCanvasAt().
A Plotter can be thought of as a frame that holds one or more PlotCanvases in a configuration determi...
Definition: Plotter.h:43
~PlotLayoutGrid()
Destructor.
Base class for any layout.
virtual ~PlotCanvasLayout()
Destructor.
virtual int coordToIndex(const PlotLayoutCoordinate &coord) const =0
turn the coordinate into an index.
virtual bool coordIsValid(const PlotLayoutCoordinate &coord) const =0
ABSTRACT METHODS //.
std::vector< std::vector< PlotCanvasPtr > > m_panels
PlotCanvasPtr canvasAt(const PlotLayoutCoordinate &coord) const
Implements PlotCanvasLayout::canvasAt().
unsigned int cols() const
Returns the number of columns.
void setSpacing(unsigned int spacing)
Implements PlotCanvasLayout::setSpacing().
virtual PlotCanvasPtr canvas() const =0
For single layouts, returns the canvas; otherwise returns the &quot;first&quot;.
bool coordIsValid(const PlotLayoutCoordinate &) const
Implements PlotCanvasLayout::coordIsValid().
virtual void setSpacing(unsigned int spacing)=0
virtual Plotter * plotter() const
Returns the plotter this layout is used in, or NULL for none.
~PlotLayoutSingle()
Destructor.
void setCanvas(PlotCanvasPtr canvas)
Sets this layout&#39;s canvas to the given.
PlotCanvasPtr canvasAt(const PlotLayoutCoordinate &coord) const
Implements PlotCanvasLayout::canvasAt().
virtual bool isValid() const =0
Indicates whether the layout is valid.
INHERITANCE_POINTER2(PlotLayoutSingle, PlotLayoutSinglePtr, PlotCanvasLayout, PlotCanvasLayoutPtr) INHERITANCE_POINTER2(PlotLayoutGrid
virtual void setCanvasAt(const PlotLayoutCoordinate &coord, PlotCanvasPtr canvas)=0
Sets the canvas at the given coordinate to the given canvas.
std::vector< PlotCanvasPtr > allCanvases() const
Implements PlotCanvasLayout::allCanvases().
unsigned int spacing() const
Implements PlotCanvasLayout::spacing().
const Double c
Fundamental physical constants (SI units):
virtual std::vector< PlotCanvasPtr > allCanvases() const =0
Returns all canvases in this layout.
bool isValid() const
Implements PlotCanvasLayout::isValid().
int coordToIndex(const PlotLayoutCoordinate &coord) const
Implements PlotCanvasLayout::coordToIndex().
PlotGridCoordinate(unsigned int r, unsigned int c)
std::vector< PlotCanvasPtr > allCanvases() const
Implements PlotCanvasLayout::allCanvases().
virtual PlotCanvasPtr canvasAt(const PlotLayoutCoordinate &coord) const =0
Returns the canvas at the given coordinate.
unsigned int rows() const
Returns the number of rows.
bool isValid() const
Implements PlotCanvasLayout::isValid().