PlotCanvasLayout.h

Go to the documentation of this file.
00001 //# PlotCanvasLayout.h: Different layouts for PlotCanvases.
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 PLOTCANVASLAYOUT_H_
00028 #define PLOTCANVASLAYOUT_H_
00029 
00030 #include <graphics/GenericPlotter/PlotCanvas.h>
00031 
00032 namespace casa {
00033 
00034 //# Forward Declarations
00035 class Plotter;
00036 
00037 
00039 // BASE CLASSES //
00041 
00042 // A coordinate for layouts.  Each layout implementation should also provide
00043 // a coordinate implementation.
00044 class PlotLayoutCoordinate {
00045 public:
00046     PlotLayoutCoordinate() { }
00047     
00048     virtual ~PlotLayoutCoordinate() { }
00049 };
00050 
00051 // Base class for any layout.
00052 class PlotCanvasLayout {
00053 public:
00054     // Constructor.
00055     PlotCanvasLayout() : m_plotter(NULL) { }
00056     
00057     // Destructor.
00058     virtual ~PlotCanvasLayout() { }
00059     
00060     
00061     // Returns the plotter this layout is used in, or NULL for none.
00062     virtual Plotter* plotter() const { return m_plotter; }
00063     
00064     // Attaches this layout to the given plotter.  The plotter's
00065     // layoutOptionsChanged method can then be called when the layout changes.
00066     virtual void attach(Plotter* p) { m_plotter = p; }
00067     
00068     
00069     // ABSTRACT METHODS //
00070     
00071     // Returns true if the given coordinate is valid for this layout.
00072     virtual bool coordIsValid(const PlotLayoutCoordinate& coord) const = 0;
00073     
00074     // turn the coordinate into an index.  the index should >= 0 and < the
00075     // total number of canvases in the layout.
00076     virtual int coordToIndex(const PlotLayoutCoordinate& coord) const = 0;
00077     
00078     // Sets the canvas at the given coordinate to the given canvas.
00079     virtual void setCanvasAt(const PlotLayoutCoordinate& coord,
00080             PlotCanvasPtr canvas) = 0;
00081     
00082     // Returns the canvas at the given coordinate.
00083     virtual PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const =0;
00084     
00085     // For single layouts, returns the canvas; otherwise returns the "first".
00086     virtual PlotCanvasPtr canvas() const = 0;
00087     
00088     // Returns all canvases in this layout.
00089     virtual vector<PlotCanvasPtr> allCanvases() const = 0;
00090     
00091     // Indicates whether the layout is valid.
00092     virtual bool isValid() const = 0;
00093     
00094     // Gets/sets the spacing between the canvases in the layout.  May not be
00095     // valid for all layout types.  The implementation for Plotter should use
00096     // this attribute appropriately.
00097     // <group>
00098     virtual unsigned int spacing() const = 0;
00099     virtual void setSpacing(unsigned int spacing) = 0;
00100     // </group>
00101     
00102 protected:
00103     Plotter* m_plotter; // Plotter
00104 };
00105 
00106 
00108 // SINGLE LAYOUT CLASSES //
00110 
00111 // PlotLayoutSingle is basically just a wrapper for a single canvas.
00112 class PlotLayoutSingle : public virtual PlotCanvasLayout {
00113 public:
00114     // Constructor which takes the canvas.
00115     PlotLayoutSingle(PlotCanvasPtr c);
00116     
00117     // Destructor.
00118     ~PlotLayoutSingle();
00119     
00120     
00121     // Implements PlotCanvasLayout::coordIsValid().
00122     bool coordIsValid(const PlotLayoutCoordinate& ) const { return true; }
00123     
00124     // Implements PlotCanvasLayout::coordToIndex().
00125     int coordToIndex(const PlotLayoutCoordinate& ) const { return 0; }
00126     
00127     // Implements PlotCanvasLayout::setCanvasAt().
00128     void setCanvasAt(const PlotLayoutCoordinate& coord, PlotCanvasPtr c);
00129     
00130     // Sets this layout's canvas to the given.
00131     void setCanvas(PlotCanvasPtr canvas);
00132     
00133     // Implements PlotCanvasLayout::canvas().
00134     PlotCanvasPtr canvas() const;
00135     
00136     // Implements PlotCanvasLayout::canvasAt().
00137     PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const;
00138     
00139     // Implements PlotCanvasLayout::allCanvases().
00140     vector<PlotCanvasPtr> allCanvases() const;
00141     
00142     // Implements PlotCanvasLayout::isValid().
00143     bool isValid() const;
00144     
00145     // Implements PlotCanvasLayout::spacing().
00146     unsigned int spacing() const { return 0; }
00147     
00148     // Implements PlotCanvasLayout::setSpacing().
00149     void setSpacing(unsigned int ) { }
00150     
00151 protected:
00152     PlotCanvasPtr m_canvas; // Canvas.
00153 };
00154 
00155 
00157 // GRID LAYOUT CLASSES //
00159 
00160 // Coordinate for a grid layout, which consists of a row and column.
00161 class PlotGridCoordinate : public virtual PlotLayoutCoordinate {
00162 public:
00163     PlotGridCoordinate(unsigned int r, unsigned int c): row(r), col(c) { }
00164     
00165     ~PlotGridCoordinate() { }
00166     
00167     unsigned int row;
00168     unsigned int col;
00169 };
00170 
00171 // An n x m grid of canvases.
00172 class PlotLayoutGrid : public virtual PlotCanvasLayout {
00173 public:
00174     // Constructor which takes the number of rows and columns.
00175     PlotLayoutGrid(unsigned int rows, unsigned int cols);    
00176     
00177     // Destructor.
00178     ~PlotLayoutGrid();
00179     
00180     // Returns the number of rows.
00181     unsigned int rows() const;
00182     
00183     // Returns the number of columns.
00184     unsigned int cols() const;
00185     
00186     // Implements PlotCanvasLayout::coordIsValid().
00187     bool coordIsValid(const PlotLayoutCoordinate& coord) const;
00188     
00189     // Implements PlotCanvasLayout::coordToIndex().
00190     int coordToIndex(const PlotLayoutCoordinate& coord) const;
00191     
00192     // Implements PlotCanvasLayout::setCanvasAt().
00193     void setCanvasAt(const PlotLayoutCoordinate& coord, PlotCanvasPtr canvas);
00194     
00195     // Implements PlotCanvasLayout::canvasAt().
00196     PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord) const;
00197     
00198     // Implements PlotCanvasLayout::canvas().
00199     PlotCanvasPtr canvas() const;
00200     
00201     // Implements PlotCanvasLayout::allCanvases().
00202     vector<PlotCanvasPtr> allCanvases() const;
00203     
00204     // Implements PlotCanvasLayout::isValid().
00205     bool isValid() const;
00206     
00207     // Implements PlotCanvasLayout::spacing().
00208     unsigned int spacing() const;
00209     
00210     // Implements PlotCanvasLayout::setSpacing().
00211     void setSpacing(unsigned int spacing);
00212     
00213 protected:
00214     unsigned int m_rows;                     // rows
00215     unsigned int m_cols;                     // columns
00216     vector<vector<PlotCanvasPtr> > m_panels; // canvases
00217     unsigned int m_spacing;                  // spacing
00218 };
00219 
00220 
00222 // SMART POINTER DEFINITIONS //
00224 
00225 typedef CountedPtr<PlotCanvasLayout> PlotCanvasLayoutPtr;
00226 INHERITANCE_POINTER2(PlotLayoutSingle, PlotLayoutSinglePtr, PlotCanvasLayout,
00227                      PlotCanvasLayoutPtr)
00228 INHERITANCE_POINTER2(PlotLayoutGrid, PlotLayoutGridPtr, PlotCanvasLayout,
00229                      PlotCanvasLayoutPtr)
00230 
00231 }
00232 
00233 #endif /*PLOTCANVASLAYOUT_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1