LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotCanvasLayout.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 77 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 27 0.0 %

          Line data    Source code
       1             : //# PlotCanvasLayout.cc: 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             : #include <graphics/GenericPlotter/PlotCanvasLayout.h>
      28             : #include <graphics/GenericPlotter/Plotter.h>
      29             : 
      30             : using namespace casacore;
      31             : namespace casa {
      32             : 
      33             : //////////////////////////////////
      34             : // PLOTLAYOUTSINGLE DEFINITIONS //
      35             : //////////////////////////////////
      36             : 
      37           0 : PlotLayoutSingle::PlotLayoutSingle(PlotCanvasPtr c) : m_canvas(c) { }
      38             : 
      39           0 : PlotLayoutSingle::~PlotLayoutSingle() { }
      40             : 
      41           0 : void PlotLayoutSingle::setCanvasAt(const PlotLayoutCoordinate& coord,
      42             :                                    PlotCanvasPtr c)  
      43             :                                    {
      44             :     (void)coord;
      45           0 :     m_canvas = c;
      46             : 
      47           0 :     if(m_plotter != NULL) m_plotter->canvasLayoutChanged(*this);
      48           0 : }
      49             : 
      50           0 : void PlotLayoutSingle::setCanvas(PlotCanvasPtr canvas) {
      51           0 :     m_canvas = canvas;
      52           0 :     if(m_plotter != NULL) m_plotter->canvasLayoutChanged(*this);
      53           0 : }
      54             : 
      55             : 
      56             : 
      57           0 : PlotCanvasPtr PlotLayoutSingle::canvas() const { 
      58           0 :     return m_canvas; 
      59             : }
      60             : 
      61             : 
      62             : 
      63           0 : PlotCanvasPtr PlotLayoutSingle::canvasAt(const PlotLayoutCoordinate& coord)
      64             :                                          const { 
      65             :     (void)coord;
      66           0 :     return m_canvas; 
      67             : }
      68             : 
      69             : 
      70             : 
      71           0 : std::vector<PlotCanvasPtr> PlotLayoutSingle::allCanvases() const {
      72           0 :     std::vector<PlotCanvasPtr> v(m_canvas.null() ? 0 : 1);
      73           0 :     if(!m_canvas.null()) v[0] = m_canvas;
      74           0 :     return v;
      75           0 : }
      76             : 
      77           0 : bool PlotLayoutSingle::isValid() const { return !m_canvas.null(); }
      78             : 
      79             : 
      80             : 
      81             : 
      82             : 
      83             : 
      84             : ////////////////////////////////
      85             : // PLOTLAYOUTGRID DEFINITIONS //
      86             : ////////////////////////////////
      87             : 
      88           0 : PlotLayoutGrid::PlotLayoutGrid(unsigned int rows, unsigned int cols):
      89           0 :         m_rows(rows), m_cols(cols), m_panels(m_rows), m_spacing(0) {
      90           0 :     if(rows > 0 && cols > 0) {
      91           0 :         for(unsigned int i = 0; i < m_rows; i++)
      92           0 :             m_panels[i].resize(m_cols);
      93             :     }
      94           0 : }
      95             : 
      96             : 
      97           0 : PlotLayoutGrid::~PlotLayoutGrid() { }
      98             : 
      99           0 : unsigned int PlotLayoutGrid::rows() const { return m_rows; }
     100             : 
     101           0 : unsigned int PlotLayoutGrid::cols() const { return m_cols; }
     102             : 
     103             : 
     104           0 : bool PlotLayoutGrid::coordIsValid(const PlotLayoutCoordinate& coord) const {
     105           0 :     const PlotGridCoordinate* c = dynamic_cast<const
     106             :                                   PlotGridCoordinate*>(&coord);
     107           0 :     if(c != NULL) return c->row < m_rows && c->col < m_cols;
     108           0 :     else return false;
     109             : }
     110             : 
     111           0 : int PlotLayoutGrid::coordToIndex(const PlotLayoutCoordinate& coord) const {    
     112           0 :     const PlotGridCoordinate* c = dynamic_cast<const
     113             :                                   PlotGridCoordinate*>(&coord);
     114           0 :     if(c != NULL && coordIsValid(coord)) return (c->row * m_cols) + c->col;
     115           0 :     else return -1;
     116             : }
     117             : 
     118           0 : void PlotLayoutGrid::setCanvasAt(const PlotLayoutCoordinate& coord,
     119             :                                  PlotCanvasPtr canvas) {
     120           0 :     if(!canvas.null() && coordIsValid(coord)) {
     121           0 :         const PlotGridCoordinate* c = dynamic_cast<const
     122             :                                       PlotGridCoordinate*>(&coord);
     123           0 :         m_panels[c->row][c->col] = canvas;
     124             : 
     125           0 :         if(m_plotter != NULL) m_plotter->canvasLayoutChanged(*this);
     126             :     }
     127           0 : }
     128             : 
     129           0 : PlotCanvasPtr PlotLayoutGrid::canvasAt(const PlotLayoutCoordinate& co) const {
     130           0 :     if(coordIsValid(co)) {
     131           0 :         const PlotGridCoordinate* c = dynamic_cast<const
     132             :                                       PlotGridCoordinate*>(&co);
     133           0 :         if(c != NULL) return m_panels[c->row][c->col];
     134             :     }
     135           0 :     return PlotCanvasPtr();
     136             : }
     137             : 
     138           0 : PlotCanvasPtr PlotLayoutGrid::canvas() const {
     139           0 :     if(m_panels.size() > 0 && m_panels[0].size() > 0) return m_panels[0][0];
     140           0 :     else return PlotCanvasPtr();
     141             : }
     142             : 
     143           0 : std::vector<PlotCanvasPtr> PlotLayoutGrid::allCanvases() const {
     144           0 :     unsigned int count = 0;
     145           0 :     for(unsigned int i = 0; i < m_rows; i++)
     146           0 :         for(unsigned int j = 0; j < m_cols; j++)
     147           0 :             if(!m_panels[i][j].null())
     148           0 :                 count++;
     149             : 
     150           0 :     std::vector<PlotCanvasPtr> v(count);
     151             : 
     152           0 :     count = 0;
     153           0 :     for(unsigned int i = 0; i < m_rows; i++)
     154           0 :         for(unsigned int j = 0; j < m_cols; j++)
     155           0 :             if(!m_panels[i][j].null())
     156           0 :                 v[count++] = m_panels[i][j];
     157             : 
     158           0 :     return v;
     159           0 : }
     160             : 
     161           0 : bool PlotLayoutGrid::isValid() const {
     162           0 :     if(m_rows <= 0 || m_cols <= 0) return false;
     163           0 :     for(unsigned int i = 0; i < m_panels.size(); i++)
     164           0 :         for(unsigned int j = 0; j < m_panels[i].size(); j++)
     165           0 :             if(m_panels[i][j].null())
     166           0 :                 return false;
     167           0 :     return true;
     168             : }
     169             : 
     170           0 : unsigned int PlotLayoutGrid::spacing() const { return m_spacing; }
     171             : 
     172           0 : void PlotLayoutGrid::setSpacing(unsigned int spacing) {
     173           0 :     m_spacing = spacing;
     174           0 :     if(m_plotter != NULL) m_plotter->canvasLayoutChanged(*this);
     175           0 : }
     176             : 
     177             : }

Generated by: LCOV version 1.16