casa
$Rev:20696$
|
00001 //# PlotMSPage.h: Layout of PlotCanvases on a single "page". 00002 //# Copyright (C) 2009 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 PLOTMSPAGE_H_ 00028 #define PLOTMSPAGE_H_ 00029 00030 #include <graphics/GenericPlotter/PlotCanvas.h> 00031 00032 #include <casa/namespace.h> 00033 00034 namespace casa { 00035 00036 //# Forward Declarations. 00037 class PlotMSPages; 00038 class PlotMSPlot; 00039 class PlotMSPlotManager; 00040 00041 00042 // Represents a single page of PlotCanvases, arranged in a grid. 00043 class PlotMSPage { 00044 00045 //# Friend class declarations. 00046 friend class PlotMSOverPlot; 00047 friend class PlotMSMultiPlot; 00048 friend class PlotMSPages; 00049 friend class PlotMSSinglePlot; 00050 friend class PlotMSIterPlot; 00051 00052 public: 00053 // Copy constructor. 00054 PlotMSPage(const PlotMSPage& copy); 00055 00056 // Destructor. 00057 ~PlotMSPage(); 00058 00059 00060 // Returns this page's page number. 00061 unsigned int pageNumber() const; 00062 00063 // Returns the number of rows/columns of the canvas grid on this page. 00064 // <group> 00065 unsigned int canvasRows() const; 00066 unsigned int canvasCols() const; 00067 // </group> 00068 00069 00070 // Copy operator. 00071 PlotMSPage& operator=(const PlotMSPage& copy); 00072 00073 private: 00074 // Parent. 00075 PlotMSPages* itsParent_; 00076 00077 // Page number. 00078 unsigned int itsPageNum_; 00079 00080 // Canvases grid. 00081 vector<vector<PlotCanvasPtr> > itsCanvases_; 00082 00083 // Owner grid. 00084 vector<vector<PlotMSPlot*> > itsCanvasOwners_; 00085 00086 00087 // Constructor. 00088 PlotMSPage(PlotMSPages& parent, unsigned int pageNumber); 00089 00090 00091 // Resizes the grid to the given number of rows and columns. 00092 void resize(unsigned int nrows, unsigned int ncols); 00093 00094 // Returns the canvas at the given row and column, or NULL if invalid. 00095 PlotCanvasPtr canvas(unsigned int row, unsigned int col); 00096 00097 // Returns the owner plot at the given row and column, or NULL if invalid 00098 // or there is no owner for that canvas. 00099 PlotMSPlot* owner(unsigned int row, unsigned int col); 00100 00101 // Sets the owner for the canvas at the given row and column to the given 00102 // plot; returns true for success, false otherwise. If the given canvas is 00103 // already owned, it must first be disowned by its old owner. 00104 bool setOwner(unsigned int row, unsigned int col, PlotMSPlot* plot); 00105 00106 // Returns true if the canvas at the given row and column exists and is 00107 // owned, false otherwise. 00108 bool isOwned(unsigned int row, unsigned int col) { 00109 return owner(row, col) != NULL; } 00110 00111 // Sets the canvas at the given row and column to be owned by no one. All 00112 // items are removed from the canvas. Returns true for success, false for 00113 // failure. 00114 bool disown(unsigned int row, unsigned int col); 00115 00116 // Sets up this page on the plotter. 00117 void setupPage(); 00118 }; 00119 00120 00121 // Represents (potentially) multiple pages for PlotMS, with one being current 00122 // (visible) at a time. 00123 class PlotMSPages { 00124 00125 //# Friend class declarations. 00126 friend class PlotMSMultiPlot; 00127 friend class PlotMSPage; 00128 friend class PlotMSPlot; 00129 friend class PlotMSPlotManager; 00130 friend class PlotMSSinglePlot; 00131 friend class PlotMSIterPlot; 00132 00133 public: 00134 // Constructor, which the plot manager. 00135 PlotMSPages(PlotMSPlotManager& manager); 00136 00137 // Copy constructor. 00138 PlotMSPages(const PlotMSPages& copy); 00139 00140 // Destructor. 00141 ~PlotMSPages(); 00142 00143 // Returns the current page number. 00144 unsigned int currentPageNumber() const; 00145 00146 // Returns a COPY of the current page. 00147 PlotMSPage currentPage() const; 00148 00149 void setCurrentPageNum(uInt num) { 00150 if(num < totalPages()) itsCurrentPageNum_ = num; 00151 } 00152 00153 // Accessor 00154 PlotMSPage& operator[](uInt index) { return itsPages_[index]; } 00155 00156 // Iterators 00157 typedef vector<PlotMSPage>::iterator iterator; 00158 iterator begin() { return itsPages_.begin(); } 00159 iterator end() { return itsPages_.end(); } 00160 00161 typedef vector<PlotMSPage>::const_iterator const_iterator; 00162 const_iterator begin() const { return itsPages_.begin(); } 00163 const_iterator end() const { return itsPages_.end(); } 00164 00165 // Returns the total pages. 00166 unsigned int totalPages() const; 00167 00168 // Clear all pages 00169 void clear() { itsPages_.clear(); } 00170 00171 void resize(size_t pages) { 00172 size_t currentSize = itsPages_.size(); 00173 // Shrink if needed 00174 if(pages < currentSize) { 00175 itsPages_.resize(pages, PlotMSPage(*this, 0)); 00176 } 00177 // If we are adding new pages, initialize them 00178 for(size_t i = currentSize; i < pages; ++i) { 00179 insertPage(i); 00180 itsPages_[i].resize(itsPages_[0].canvasRows(), 00181 itsPages_[0].canvasCols()); 00182 itsPages_[i].setupPage(); 00183 } 00184 } 00185 00186 // Copy operator. 00187 PlotMSPages& operator=(const PlotMSPages& copy); 00188 00189 // Iterators 00190 void firstPage(); 00191 void nextPage(); 00192 void previousPage(); 00193 void lastPage(); 00194 00195 // Inserts a new page at the given index, and returns it. If the given 00196 // index is invalid, the page is inserted at the end. 00197 PlotMSPage insertPage(int index = -1); 00198 00199 // Clears all pages. 00200 void clearPages(); 00201 00202 // Sets up the current page (see PlotMSPage::setupPage()). 00203 void setupCurrentPage(); 00204 00205 private: 00206 // Plot manager. 00207 PlotMSPlotManager* itsManager_; 00208 00209 // Pages. 00210 vector<PlotMSPage> itsPages_; 00211 00212 // Current page number. 00213 unsigned int itsCurrentPageNum_; 00214 }; 00215 00216 } 00217 00218 #endif /* PLOTMSPAGE_H_ */