LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotCanvasLayout.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 8 0.0 %
Date: 2024-10-12 00:35:29 Functions: 0 9 0.0 %

          Line data    Source code
       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: casa-feedback@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             : 
      30             : #include <graphics/GenericPlotter/PlotCanvas.h>
      31             : 
      32             : namespace casa {
      33             : 
      34             : //# Forward Declarations
      35             : class Plotter;
      36             : 
      37             : 
      38             : //////////////////
      39             : // BASE CLASSES //
      40             : //////////////////
      41             : 
      42             : // A coordinate for layouts.  Each layout implementation should also provide
      43             : // a coordinate implementation.
      44             : class PlotLayoutCoordinate {
      45             : public:
      46             :     PlotLayoutCoordinate() { }
      47             :     
      48             :     virtual ~PlotLayoutCoordinate() { }
      49             : };
      50             : 
      51             : // Base class for any layout.
      52             : class PlotCanvasLayout {
      53             : public:
      54             :     // Constructor.
      55           0 :     PlotCanvasLayout() : m_plotter(NULL) { }
      56             :     
      57             :     // Destructor.
      58           0 :     virtual ~PlotCanvasLayout() { }
      59             :     
      60             :     
      61             :     // Returns the plotter this layout is used in, or NULL for none.
      62           0 :     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           0 :     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             : 
     107             : ///////////////////////////
     108             : // SINGLE LAYOUT CLASSES //
     109             : ///////////////////////////
     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.
     115             :     PlotLayoutSingle(PlotCanvasPtr c);
     116             :     
     117             :     // Destructor.
     118             :     ~PlotLayoutSingle();
     119             :     
     120             :     
     121             :     // Implements PlotCanvasLayout::coordIsValid().
     122           0 :     bool coordIsValid(const PlotLayoutCoordinate& ) const { return true; }
     123             :     
     124             :     // Implements PlotCanvasLayout::coordToIndex().
     125           0 :     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.
     131             :     void setCanvas(PlotCanvasPtr canvas);
     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           0 :     unsigned int spacing() const { return 0; }
     147             :     
     148             :     // Implements PlotCanvasLayout::setSpacing().
     149           0 :     void setSpacing(unsigned int ) { }
     150             :     
     151             : protected:
     152             :     PlotCanvasPtr m_canvas; // Canvas.
     153             : };
     154             : 
     155             : 
     156             : /////////////////////////
     157             : // GRID LAYOUT CLASSES //
     158             : /////////////////////////
     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             :     
     165             :     ~PlotGridCoordinate() { }
     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().
     193             :     void setCanvasAt(const PlotLayoutCoordinate& coord, PlotCanvasPtr canvas);
     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             : 
     221             : ///////////////////////////////
     222             : // SMART POINTER DEFINITIONS //
     223             : ///////////////////////////////
     224             : 
     225             : typedef casacore::CountedPtr<PlotCanvasLayout> PlotCanvasLayoutPtr;
     226             : INHERITANCE_POINTER2(PlotLayoutSingle, PlotLayoutSinglePtr, PlotCanvasLayout,
     227             :                      PlotCanvasLayoutPtr)
     228             : INHERITANCE_POINTER2(PlotLayoutGrid, PlotLayoutGridPtr, PlotCanvasLayout,
     229             :                      PlotCanvasLayoutPtr)
     230             : 
     231             : }
     232             : 
     233             : #endif /*PLOTCANVASLAYOUT_H_*/

Generated by: LCOV version 1.16