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