casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plotter.h
Go to the documentation of this file.
1 //# Plotter.h: Highest level plotting object that holds one or more canvases.
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: aips2-request@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 PLOTTER_H_
28 #define PLOTTER_H_
29 
34 
35 namespace casa {
36 
37 //# Forward Declarations
38 class PlotFactory;
39 
40 // A Plotter can be thought of as a frame that holds one or more PlotCanvases
41 // in a configuration determined by a given PlotCanvasLayout. It also has
42 // some top-level and main-window functionality.
43 class Plotter {
44 public:
45  // Static //
46 
47  // This enum should contain all known implementations.
49  QWT,
50 
51  // Default plotter implementation is set here.
53  };
54 
55  // Default implementation-specific GUI panels that can be turned on or off.
56  enum DefaultPanel {
57  HAND_TOOLS, // buttons/tools to: select regions, zoom, and pan;
58  // (optionally) turn on/off tracker;
59  // (optionally) show/hide and position legend
60  EXPORT_TOOLS // buttons/tools to export the canvases to a file
61  };
62 
63  // The default date format to use for the plotter. See dateFormat().
65 
66  // The default relative date format to use for the plotter. See
67  // relativeDateFormat().
69 
70  // Returns a casacore::String for the given date value using the given format (see
71  // dateFormat()) and scale. If isRelative is true, the value is treated as
72  // a relative value (i.e., +X seconds past a reference date); otherwise it
73  // is treated as an absolute value. For relative values years, months, and
74  // days are ignored.
75  // Default precision for seconds is 4; use secPrecision to change this
77  double value, PlotAxisScale scale, bool isRelative = false,
78  int secPrecision=-1);
79 
80 
81  // Non-Static //
82 
83  // Constructor.
84  Plotter();
85 
86  // Destructor.
87  virtual ~Plotter();
88 
89 
90  // ABSTRACT METHODS //
91 
92  // Top-Level GUI methods //
93 
94  // Shows/hides the plotter GUI.
95  virtual void showGUI(bool showGUI = true) = 0;
96 
97  // Returns the current size of the plotter GUI in pixels (width x height).
98  virtual std::pair<int, int> size() const = 0;
99 
100  // Sets the plotter GUI size in pixels
101  virtual void setSize(int width, int height) = 0;
102 
103  // Sets width=height but saves rectangular ratio
104  virtual void makeSquarePlot(bool square, bool wave) = 0;
105 
106  //Set the size of cached axes stack image
107  virtual void setCanvasCachedAxesStackImageSize( int width, int height );
108 
109  // Returns the plotter window's title.
110  virtual casacore::String windowTitle() const = 0;
111 
112  // Sets the plotter window's title to the given.
113  virtual void setWindowTitle(const casacore::String& newTitle) = 0;
114 
115  // Returns the size of the canvas area (i.e., minus bordering panels) in
116  // pixels (width x height).
117  virtual std::pair<int, int> canvasAreaSize() const = 0;
118 
119  // If the plotter has a single canvas, sets the size of the canvas to the
120  // given. If resizeWindow is true, the plotter is resized to fit the new
121  // canvas size.
122  virtual void setCanvasSize(int width, int height,
123  bool resizeWindow = true) = 0;
124 
125  // Returns the DPI used in the GUI display.
126  virtual int displayDPI() const = 0;
127 
128  // Returns true if the plotter window can be casted to a QWidget, false
129  // otherwise.
130  virtual bool isQWidget() const = 0;
131 
132  // Gets/sets cursor for the whole plotter. Can be overridden by individual
133  // canvases.
134  // <group>
135  virtual PlotCursor cursor() const = 0;
136  virtual void setCursor(PlotCursor cursor) = 0;
137  // </group>
138 
139  // Refreshes the plotter GUI.
140  virtual void refresh() = 0;
141 
142  //Forces the script client to refresh.
143  virtual void updateScriptGui() = 0;
144 
145  // Closes the plotter window.
146  virtual void close() = 0;
147 
148 
149  // Canvas Layout methods //
150 
151  // Returns the current layout, or a null pointer if none has been set.
152  virtual PlotCanvasLayoutPtr canvasLayout() = 0;
153 
154  // Sets the canvas layout to the given. Clears out old canvases as needed.
155  virtual void setCanvasLayout(PlotCanvasLayoutPtr layout) = 0;
156 
157  // Method for when the layout has changed (i.e. changed canvases, etc.).
158  // This should only be used by the layout currently being used by the
159  // plotter.
160  virtual void canvasLayoutChanged(PlotCanvasLayout& layout) = 0;
161 
162  // Gets/Sets the date format for the plotter and all current and future
163  // canvases. This format should be used anywhere date values are displayed
164  // to the user, such as for axis ticks and tracker tools. A format can
165  // consist of the following tags:
166  // * %y : year
167  // * %m : month
168  // * %d : day of month
169  // * %h : hours
170  // * %n : minutes
171  // * %s : seconds
172  // The format can optionally have the following tags:
173  // * %pX : precision to display for seconds, with X being an integer; if X
174  // is less than zero, the default is used. Applies to any seconds
175  // tags that are AFTER the precision tag.
176  // <group>
177  virtual const casacore::String& dateFormat() const = 0;
178  virtual void setDateFormat(const casacore::String& dateFormat) = 0;
179  // </group>
180 
181  // Gets/Sets the date format for relative values (i.e., for reference
182  // values on axes) for the plotter and all current and future canvases.
183  // This format should be used anywhere relative date values are displayed
184  // to the user, such as for axis ticks when a reference value is set. See
185  // dateFormat() for information on the format.
186  // <group>
187  virtual const casacore::String& relativeDateFormat() const = 0;
188  virtual void setRelativeDateFormat(const casacore::String& dateFormat) = 0;
189  // </group>
190 
191 
192  // Panel methods //
193 
194  // Returns whether or not the given default panel is shown.
195  virtual bool defaultPanelShown(DefaultPanel panel) = 0;
196 
197  // Shows/hides the given default panel. Note: the default panels are for
198  // convenience's sake and are left completely up to the implementation.
199  virtual void showDefaultPanel(DefaultPanel panel, bool show = true) = 0;
200 
201  // Adds the given plot panel and returns its index.
202  virtual int addPanel(PlotPanelPtr panel) = 0;
203 
204  // Returns all plot panels currently shown.
205  virtual std::vector<PlotPanelPtr> allPanels() = 0;
206 
207  // Returns the number of plot panels currently on the plotter.
208  virtual unsigned int numPanels() = 0;
209 
210  // Returns the plot panel at the given index, or a null pointer for an
211  // invalid index.
212  virtual PlotPanelPtr getPanel(int index) = 0;
213 
214  // Returns the index of the given plot panel, or -1 if not on canvas or
215  // null.
216  virtual int panelIndex(PlotPanelPtr panel) = 0;
217 
218  // Clears all plot panels from the plotter.
219  virtual void clearPanels() = 0;
220 
221  // Removes the given plot panel from the plotter.
222  virtual void removePanel(PlotPanelPtr panel) = 0;
223 
224  // Removes the plot panel with the given index from the plotter.
225  virtual void removePanel(int id) = 0;
226 
227  // Removes the last-added plot panel from the plotter.
228  virtual void removeLastPanel() = 0;
229 
230 
231  //Use a common x-/y- axis when plotting multiple graphs.
232  void setCommonAxisX(casacore::Bool commonAxis );
233  void setCommonAxisY(casacore::Bool commonAxis );
234  bool isCommonAxisX() const;
235  bool isCommonAxisY() const;
236  void setAxisLocation( PlotAxis xLocation, PlotAxis yLocation );
237  PlotAxis getAxisLocationX() const;
238  PlotAxis getAxisLocationY() const;
239 
240  // Plotting Functionality methods //
241 
242  // Returns the implementation of this plotter.
243  virtual Implementation implementation() const = 0;
244 
245  // Returns a new instance of a PlotFactory that can create plot items for
246  // this implementation. It is the caller's responsibility to delete the
247  // PlotFactory when finished.
248  virtual PlotFactory* implementationFactory() const = 0;
249 
250  // Exports the plotter (all canvases) using the given format.
251  virtual bool exportToFile(const PlotExportFormat& format) = 0;
252 
253  // Shows a file chooser dialog and returns the absolute filename that the
254  // user chooses. If a directory is given, start the dialog there. If the
255  // user cancels, an empty casacore::String is returned.
256  virtual casacore::String fileChooserDialog(const casacore::String& title = "File Chooser",
257  const casacore::String& directory = "") = 0;
258 
259 
260  // Event Handling methods //
261 
262  // Registers the given resize event handler with this plotter.
263  virtual void registerResizeHandler(PlotResizeEventHandlerPtr handler) = 0;
264 
265  // Returns a list of all registered resize event handlers for this plotter.
266  virtual std::vector<PlotResizeEventHandlerPtr> allResizeHandlers() const = 0;
267 
268  // Unregisters the given resize event handler with this plotter.
269  virtual void unregisterResizeHandler(PlotResizeEventHandlerPtr handler) =0;
270 
271 
272  // IMPLEMENTED METHODS //
273 
274  // See PlotCanvasLayout::canvasAt().
275  virtual PlotCanvasPtr canvasAt(const PlotLayoutCoordinate& coord);
276 
277  // See PlotCanvasLayout::canvas().
278  virtual PlotCanvasPtr canvas();
279 
280  // Sets the layout to a single layout with the given canvas.
281  virtual void setCanvas(PlotCanvasPtr canvas);
282 
283  // See PlotLogger::filterMinPriority().
285 
286  // See PlotLogger::setFilterMinPriority().
288 
289  // See PlotLogger::eventFlag().
290  virtual bool logFilterEventFlag(int flag) const;
291 
292  // See PlotLogger::setEventFlag().
293  virtual void setLogFilterEventFlag(int flag, bool on);
294 
295  // See PlotLogger::eventFlags().
296  virtual int logFilterEventFlags() const;
297 
298  // See PlotLogger::setEventFlags().
299  virtual void setLogFilterEventFlags(int flags);
300 
301  // Gets the PlotLogger associated with this Plotter. There should be
302  // exactly one PlotLogger per Plotter.
303  virtual PlotLoggerPtr logger() const;
304 
305  virtual bool exportPlot(const PlotExportFormat& format) = 0;
307 
308  virtual void refreshPageHeader() = 0;
309 
310  virtual void refreshPageHeaderDataModel(PageHeaderDataModelPtr dataModel) = 0 ;
311 
312 protected:
313  // Logger.
315 // PlotterControllerPtr m_controller;
320 };
322 
323 }
324 
325 #endif /*PLOTTER_H_*/
virtual void setCanvasCachedAxesStackImageSize(int width, int height)
Set the size of cached axes stack image.
(optionally) turn on/off tracker; (optionally) show/hide and position legend
Definition: Plotter.h:60
virtual int logFilterEventFlags() const
See PlotLogger::eventFlags().
virtual void removePanel(PlotPanelPtr panel)=0
Removes the given plot panel from the plotter.
virtual PlotCanvasPtr canvas()
See PlotCanvasLayout::canvas().
virtual void setCanvasSize(int width, int height, bool resizeWindow=true)=0
If the plotter has a single canvas, sets the size of the canvas to the given.
virtual bool defaultPanelShown(DefaultPanel panel)=0
Panel methods //.
PlotAxis axisLocationY
Definition: Plotter.h:319
virtual PlotFactory * implementationFactory() const =0
Returns a new instance of a PlotFactory that can create plot items for this implementation.
virtual bool isQWidget() const =0
Returns true if the plotter window can be casted to a QWidget, false otherwise.
virtual void setLogFilterEventFlag(int flag, bool on)
See PlotLogger::setEventFlag().
void setCommonAxisY(casacore::Bool commonAxis)
bool isCommonAxisY() const
virtual void setLogFilterEventFlags(int flags)
See PlotLogger::setEventFlags().
virtual PlotPanelPtr getPanel(int index)=0
Returns the plot panel at the given index, or a null pointer for an invalid index.
Plotter()
Non-Static //.
virtual ~Plotter()
Destructor.
virtual void updateScriptGui()=0
Forces the script client to refresh.
virtual void setCanvas(PlotCanvasPtr canvas)
Sets the layout to a single layout with the given canvas.
virtual Implementation implementation() const =0
Plotting Functionality methods //.
virtual void showDefaultPanel(DefaultPanel panel, bool show=true)=0
Shows/hides the given default panel.
virtual unsigned int numPanels()=0
Returns the number of plot panels currently on the plotter.
SMART POINTER DEFINITIONS *typedef casacore::CountedPtr< PlotCanvasLayout > PlotCanvasLayoutPtr
virtual void canvasLayoutChanged(PlotCanvasLayout &layout)=0
Method for when the layout has changed (i.e.
virtual casacore::String fileChooserDialog(const casacore::String &title="File Chooser", const casacore::String &directory="")=0
Shows a file chooser dialog and returns the absolute filename that the user chooses.
virtual void registerResizeHandler(PlotResizeEventHandlerPtr handler)=0
Event Handling methods //.
The idea behind a plot factory is to produce classes that are useful to the underlying implementation...
Definition: PlotFactory.h:52
A Plotter can be thought of as a frame that holds one or more PlotCanvases in a configuration determi...
Definition: Plotter.h:43
bool isVisible(PlotCanvasPtr &canvas)
Base class for any layout.
virtual void setDateFormat(const casacore::String &dateFormat)=0
virtual void makeSquarePlot(bool square, bool wave)=0
Sets width=height but saves rectangular ratio.
void show(const variant &v)
PlotLoggerPtr m_logger
Logger.
Definition: Plotter.h:314
virtual void refresh()=0
Refreshes the plotter GUI.
static casacore::String formattedDateString(const casacore::String &format, double value, PlotAxisScale scale, bool isRelative=false, int secPrecision=-1)
Returns a casacore::String for the given date value using the given format (see dateFormat()) and sca...
casacore::Bool commonAxisX
PlotterControllerPtr m_controller;.
Definition: Plotter.h:316
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
virtual int displayDPI() const =0
Returns the DPI used in the GUI display.
SMART POINTER DEFINITIONS *typedef casacore::CountedPtr< PlotPanel > PlotPanelPtr
Definition: PlotPanel.h:188
void setCommonAxisX(casacore::Bool commonAxis)
Use a common x-/y- axis when plotting multiple graphs.
virtual const casacore::String & relativeDateFormat() const =0
Gets/Sets the date format for relative values (i.e., for reference values on axes) for the plotter an...
virtual void close()=0
Closes the plotter window.
casacore::LogMessage::Priority logFilterMinPriority() const
See PlotLogger::filterMinPriority().
Implementation
Static //.
Definition: Plotter.h:48
virtual PlotLoggerPtr logger() const
Gets the PlotLogger associated with this Plotter.
static const casacore::String DEFAULT_RELATIVE_DATE_FORMAT
The default relative date format to use for the plotter.
Definition: Plotter.h:68
virtual PlotCursor cursor() const =0
Gets/sets cursor for the whole plotter.
virtual int panelIndex(PlotPanelPtr panel)=0
Returns the index of the given plot panel, or -1 if not on canvas or null.
virtual void setRelativeDateFormat(const casacore::String &dateFormat)=0
PlotCursor
Enum for cursors.
Definition: PlotOptions.h:94
PlotAxis
Enum for the four plot axes.
Definition: PlotOptions.h:62
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
PlotExportFormat contains parameters for exporting a canvas to a file.
Definition: PlotOptions.h:817
virtual std::pair< int, int > canvasAreaSize() const =0
Returns the size of the canvas area (i.e., minus bordering panels) in pixels (width x height)...
virtual void setCursor(PlotCursor cursor)=0
virtual int addPanel(PlotPanelPtr panel)=0
Adds the given plot panel and returns its index.
virtual std::pair< int, int > size() const =0
Returns the current size of the plotter GUI in pixels (width x height).
virtual void refreshPageHeaderDataModel(PageHeaderDataModelPtr dataModel)=0
virtual void showGUI(bool showGUI=true)=0
ABSTRACT METHODS //.
virtual std::vector< PlotPanelPtr > allPanels()=0
Returns all plot panels currently shown.
virtual void setSize(int width, int height)=0
Sets the plotter GUI size in pixels.
bool isCommonAxisX() const
casacore::Bool commonAxisY
Definition: Plotter.h:317
DefaultPanel
Default implementation-specific GUI panels that can be turned on or off.
Definition: Plotter.h:56
virtual void refreshPageHeader()=0
virtual PlotCanvasPtr canvasAt(const PlotLayoutCoordinate &coord)
IMPLEMENTED METHODS //.
PlotAxis getAxisLocationY() const
Priority
An &quot;importance&quot; which is assigned to each LogMessage.
Definition: LogMessage.h:105
virtual void setWindowTitle(const casacore::String &newTitle)=0
Sets the plotter window&#39;s title to the given.
PlotAxis axisLocationX
Definition: Plotter.h:318
static const casacore::String DEFAULT_DATE_FORMAT
The default date format to use for the plotter.
Definition: Plotter.h:64
casacore::CountedPtr< Plotter > PlotterPtr
Definition: Plotter.h:321
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1303
virtual const casacore::String & dateFormat() const =0
Gets/Sets the date format for the plotter and all current and future canvases.
void setAxisLocation(PlotAxis xLocation, PlotAxis yLocation)
virtual bool logFilterEventFlag(int flag) const
See PlotLogger::eventFlag().
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual PlotCanvasLayoutPtr canvasLayout()=0
Canvas Layout methods //.
virtual void clearPanels()=0
Clears all plot panels from the plotter.
Default plotter implementation is set here.
Definition: Plotter.h:52
virtual void setCanvasLayout(PlotCanvasLayoutPtr layout)=0
Sets the canvas layout to the given.
virtual void unregisterResizeHandler(PlotResizeEventHandlerPtr handler)=0
Unregisters the given resize event handler with this plotter.
GRID LAYOUT CLASSES casacore::Coordinate for a grid layout
virtual bool exportPlot(const PlotExportFormat &format)=0
virtual void removeLastPanel()=0
Removes the last-added plot panel from the plotter.
virtual std::vector< PlotResizeEventHandlerPtr > allResizeHandlers() const =0
Returns a list of all registered resize event handlers for this plotter.
PlotAxisScale
Enum for possible axis scales.
Definition: PlotOptions.h:78
virtual casacore::String windowTitle() const =0
Returns the plotter window&#39;s title.
void setLogFilterMinPriority(PlotLogMessage::Priority minPriority)
See PlotLogger::setFilterMinPriority().
PlotAxis getAxisLocationX() const
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
virtual bool exportToFile(const PlotExportFormat &format)=0
Exports the plotter (all canvases) using the given format.