PlotCanvas.h

Go to the documentation of this file.
00001 //# PlotCanvas.h: Main drawing area for different plot items to be attached.
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 PLOTCANVAS_H_
00028 #define PLOTCANVAS_H_
00029 
00030 #include <graphics/GenericPlotter/Plot.h>
00031 #include <graphics/GenericPlotter/PlotAnnotation.h>
00032 #include <graphics/GenericPlotter/PlotEventHandler.h>
00033 #include <graphics/GenericPlotter/PlotItem.h>
00034 #include <graphics/GenericPlotter/PlotLogger.h>
00035 #include <graphics/GenericPlotter/PlotOperation.h>
00036 #include <graphics/GenericPlotter/PlotOptions.h>
00037 #include <graphics/GenericPlotter/PlotShape.h>
00038 #include <graphics/GenericPlotter/PlotTool.h>
00039 
00040 #include <casa/BasicSL/String.h>
00041 
00042 #include <casa/namespace.h>
00043 
00044 namespace casa {
00045 
00046 //# Forward Declarations
00047 class PlotFactory;
00048 
00049 
00050 // Abstract parent for any class that wants to be notified when the canvas
00051 // is about to start drawing.  This class is needed because a canvas could
00052 // start redrawing for a number of reasons (user-requested, items changing the
00053 // scale, resizing, ...) and instead of forcing applications to catch all cases
00054 // this class can be used to notify when a drawing has begun for any reason.
00055 class PlotDrawWatcher {
00056 public:
00057     // Constructor.
00058     PlotDrawWatcher() { }
00059     
00060     // Destructor.
00061     virtual ~PlotDrawWatcher() { }
00062     
00063     
00064     // This method should be called by the canvas whenever drawing is about to
00065     // begin.  The watcher is given:
00066     // * A pointer to the PlotOperation object which is updated with progress
00067     //   information,
00068     // * A flag indicating whether the drawing will happen in its own thread or
00069     //   not,
00070     // * A flag indicating which layers are going to be drawn (bitwise-or of
00071     //   PlotCanvasLayer values).
00072     // The method should return true UNLESS the watcher wants to stop the
00073     // canvas from drawing.  For example, if a canvas does not have threaded
00074     // drawing, the watcher may want to stop drawing initially in order to
00075     // spawn a new thread and then redraw.
00076     virtual bool canvasDrawBeginning(PlotOperationPtr drawOperation,
00077             bool drawingIsThreaded, int drawnLayersFlag) = 0;
00078 };
00079 typedef CountedPtr<PlotDrawWatcher> PlotDrawWatcherPtr;
00080 
00081 
00082 // PlotCanvas is an area for different PlotItems to be attached and drawn.  It
00083 // also has axes and other properties.  It's one of the more important plotting
00084 // classes.
00085 class PlotCanvas {
00086 public:
00087     // Static //
00088     
00089     // Position that the legend can be in, relative to the canvas.
00090     enum LegendPosition {
00091         INT_URIGHT, // inside the canvas, on the upper right
00092         INT_LRIGHT, // inside the canvas, on the lower right
00093         INT_ULEFT,  // inside the canvas, on the upper left
00094         INT_LLEFT,  // inside the canvas, on the lower left
00095         EXT_RIGHT,  // outside the canvas, on the right
00096         EXT_TOP,    // outside the canvas, on the top
00097         EXT_LEFT,   // outside the canvas, on the left
00098         EXT_BOTTOM  // outside the canvas, on the bottom
00099     };
00100     
00101     // Returns all legend positions.
00102     // <group>
00103     static vector<LegendPosition> allLegendPositions(); 
00104     static vector<String> allLegendPositionStrings();
00105     // </group>
00106     
00107     // Converts between legend positions and their String representations.
00108     // <group>
00109     static String legendPosition(LegendPosition p); 
00110     static LegendPosition legendPosition(String p, bool* ok = NULL);
00111     // </group>
00112     
00113     // Indicates whether the given legend position is internal to the canvas or
00114     // not.
00115     static bool legendPositionIsInternal(LegendPosition p);
00116     
00117     // Returns a vector containing all values in the PlotAxis enum, ordered
00118     // from lowest value to highest value.
00119     static vector<PlotAxis> allAxes();
00120     
00121     // Returns the or'ed value of all PlotAxis enum values.
00122     static int allAxesFlag();
00123     
00124     // Returns a vector containing all values in the PlotCanvasLayer enum,
00125     // ordered from lowest value to highest value.
00126     static vector<PlotCanvasLayer> allLayers();
00127     
00128     // Returns the or'ed value of all PlotCanvasLayer enum values.
00129     static int allLayersFlag();
00130     
00131     // Convenient access to operation names.
00132     // <group>
00133     static const String OPERATION_DRAW;
00134     static const String OPERATION_EXPORT;
00135     // </group>
00136     
00137     
00138     // Non-Static //
00139     
00140     // Constructor.
00141     PlotCanvas();
00142     
00143     // Destructor.
00144     virtual ~PlotCanvas();
00145 
00146     
00147     // Support Methods //
00148     
00149     // See PlotFactory::canvasHasThreadedDrawing().
00150     // DEFAULT IMPLEMENTATION.
00151     virtual bool hasThreadedDrawing() const;
00152     
00153     // See PlotFactory::canvasHasCachedLayerDrawing().
00154     // DEFAULT IMPLEMENTATION.
00155     virtual bool hasCachedLayerDrawing() const;
00156     
00157     // See PlotFactory::hasCachedAxesStack().
00158     // DEFAULT IMPLEMENTATION.
00159     virtual bool hasCachedAxesStack() const;
00160     
00161     
00162     // GUI Methods //
00163     
00164     // Returns the canvas size in pixels (width x height).
00165     virtual pair<int, int> size() const = 0;
00166     
00167     // Returns the text of the canvas title, or an empty String if none is
00168     // shown.  The title is shown above the plotting area.
00169     virtual String title() const = 0;
00170     
00171     // Sets the text of the canvas title to the given.  Setting the title to an
00172     // empty string should remove the title from the canvas.
00173     virtual void setTitle(const String& title) = 0;
00174     
00175     // Returns a copy of the font used for the canvas title.  If no title is
00176     // shown this behavior is undefined.
00177     virtual PlotFontPtr titleFont() const = 0;
00178     
00179     // Set the font of the canvas title to the given.
00180     virtual void setTitleFont(const PlotFont& font) = 0;
00181     
00182     // Convenience method for setting title font.
00183     // DEFAULT IMPLEMENTATION.
00184     virtual void setTitleFont(const PlotFontPtr font);
00185     
00186     // Returns a copy of the canvas background.
00187     virtual PlotAreaFillPtr background() const = 0;
00188     
00189     // Sets the background of the canvas to the given.
00190     virtual void setBackground(const PlotAreaFill& areaFill) = 0;
00191     
00192     // Convenience methods for setting background.
00193     // DEFAULT IMPLEMENTATION.
00194     // <group>
00195     virtual void setBackground(const PlotAreaFillPtr areaFill);
00196     virtual void setBackground(const String& color,
00197             PlotAreaFill::Pattern pattern = PlotAreaFill::FILL);
00198     // </group>
00199     
00200     // Gets/sets the cursor for this canvas.
00201     // <group>
00202     virtual PlotCursor cursor() const = 0;
00203     virtual void setCursor(PlotCursor cursor) = 0;
00204     // </group>    
00205     
00206     // Refreshes the GUI, which includes redrawing plot items as needed even if
00207     // drawing is currently being held.
00208     virtual void refresh() = 0;
00209     
00210     // Refreshes the GUI, ONLY for the layers as indicated by the flag.  The
00211     // flag should be a bitwise-or of PlotCanvasLayer values.
00212     virtual void refresh(int drawLayersFlag) = 0;
00213     
00214     // Indicates whether a cast to QWidget would succeed for this object.
00215     virtual bool isQWidget() const = 0;
00216     
00217     
00218     // Axes Methods //
00219     
00220     // Returns a bitwise-or of PlotAxis values corresponding to which are shown
00221     // or hidden.
00222     virtual int shownAxes() const = 0;
00223     
00224     // Shows/Hides axes based on the given flag, which should be a bitwise-or
00225     // of PlotAxis values.
00226     virtual void showAxes(int axesFlag) = 0;
00227     
00228     // Returns true if the given axis is shown, false otherwise.
00229     // DEFAULT IMPLEMENTATION.
00230     virtual bool axisShown(PlotAxis axis) const;
00231     
00232     // Shows/hides the given axis.
00233     // DEFAULT IMPLEMENTATION.
00234     virtual void showAxis(PlotAxis axis, bool show = true);
00235     
00236     // Convenience method for showing/hiding two axes at once.
00237     // DEFAULT IMPLEMENTATION.
00238     virtual void showAxes(PlotAxis xAxis, PlotAxis yAxis, bool show = true);
00239     
00240     // Convenience method for showing/hiding all four axes at once.
00241     // DEFAULT IMPLEMENTATION.
00242     virtual void showAxes(bool show = true);
00243     
00244     // Returns the scale for the given axis.
00245     virtual PlotAxisScale axisScale(PlotAxis axis) const = 0;
00246     
00247     // Sets the scale for the given axis and rescales accordingly.  May reset
00248     // tool stacks.
00249     virtual void setAxisScale(PlotAxis axis, PlotAxisScale scale) = 0;
00250     
00251     // Convenience method for setting the axis scale for two axes at once.  May
00252     // reset tool stacks.
00253     // DEFAULT IMPLEMENTATION.
00254     virtual void setAxesScales(PlotAxis xAxis, PlotAxisScale xScale,
00255             PlotAxis yAxis, PlotAxisScale yScale);
00256     
00257     // Gets/Sets the reference values for the given axis.  If a reference value
00258     // is set for an axis, its tick labels use an offset from that value
00259     // instead of the actual tick value.  For example, if a reference value is
00260     // set to 15, instead of ticks reading "14 15 16" they would read "-1 0 1".
00261     // <group>
00262     virtual bool axisReferenceValueSet(PlotAxis axis) const = 0;
00263     virtual double axisReferenceValue(PlotAxis axis) const = 0;
00264     virtual void setAxisReferenceValue(PlotAxis axis, bool on,
00265                 double value = 0) = 0;
00266     // </group>
00267     
00268     // Returns whether the given Cartesian axis is shown or not.  (See
00269     // showCartesianAxis().)
00270     virtual bool cartesianAxisShown(PlotAxis axis) const = 0;
00271     
00272     // Show or hide the given Cartesian axis.  A Cartesian axis is different
00273     // from a normal axis in that it is inside the graph, corresponding to the
00274     // (0,0) location of the plot(s), rather than outside the graph.  The
00275     // secondary axis is the axis at which the mirrored axis will be placed at
00276     // the 0 value of.  For example, to show the Cartesian X_BOTTOM axis you'd
00277     // likely want to mirror the axis at Y_LEFT = 0, so that would be the
00278     // secondary axis.  If hideNormalAxis is true, it is equivalent to
00279     // showAxis(mirrorAxis, !hideNormalAxis).
00280     virtual void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
00281             bool show = true, bool hideNormalAxis = true) = 0;
00282     
00283     // Convenience methods for most common Cartesian axes cases.
00284     // DEFAULT IMPLEMENTATION.
00285     // <group>
00286     virtual void showCartesianAxis(PlotAxis mirrorAxis, bool show = true,
00287                                    bool hideNormalAxis = true);
00288     virtual void showCartesianAxes(bool show = true, bool hideNormal = true);
00289     // </group>
00290     
00291     // Returns the label for the given axis, or an empty String if none is
00292     // shown.
00293     virtual String axisLabel(PlotAxis axis) const = 0;
00294     
00295     // Sets the label of an axis title to the given.  Setting the title to an
00296     // empty string should remove the title from the axis.
00297     virtual void setAxisLabel(PlotAxis axis, const String& title) = 0;
00298     
00299     // Convenience method for clearing labels from all axes.
00300     // DEFAULT IMPLEMENTATION.
00301     virtual void clearAxesLabels();
00302     
00303     // Returns a copy of the font used for the given axis label.  If no title
00304     // is shown this behavior is undefined.
00305     virtual PlotFontPtr axisFont(PlotAxis axis) const = 0;
00306     
00307     // Set the font of the axis title to the given.
00308     virtual void setAxisFont(PlotAxis axis, const PlotFont& font) = 0;
00309     
00310     // Convenience method for setting axis font.
00311     // DEFAULT IMPLEMENTATION.
00312     virtual void setAxisFont(PlotAxis axis, const PlotFontPtr font);
00313     
00314     // Returns true if a color bar is shown on the given axis, false otherwise.
00315     // A color bar should only be shown when one of more of the items on the
00316     // canvas is a RasterPlot or a SpectrogramPlot.  If there are multiple
00317     // raster or spectrograms, behavior is undefined.
00318     virtual bool colorBarShown(PlotAxis axis = Y_RIGHT) const = 0;
00319     
00320     // Shows/hides a color bar is shown on the given axis.  (See
00321     // colorBarShown().)
00322     virtual void showColorBar(bool show = true, PlotAxis axis = Y_RIGHT) = 0;
00323     
00324     
00325     // Axes Range Methods //
00326     
00327     // Returns the displayed range of the given axis, in world coordinates.
00328     virtual prange_t axisRange(PlotAxis axis) const = 0;
00329     
00330     // Returns the displayed ranges of the given axes, in world coordinates.
00331     // DEFAULT IMPLEMENTATION.
00332     virtual PlotRegion axesRanges(PlotAxis xAxis, PlotAxis yAxis) const;
00333     
00334     // Sets the displayed range of the given axis, in world coordinates.
00335     // Implies setAxesAutoRescale(false), and does NOT reset tool stacks since
00336     // the tools may be using this method.
00337     virtual void setAxisRange(PlotAxis axis, double from, double to) = 0;
00338     
00339     // See setAxisRange(PlotAxis, double, double).
00340     // DEFAULT IMPLEMTNATION.
00341     virtual void setAxisRange(PlotAxis axis, const prange_t& range);
00342     
00343     // Sets the displayed ranges of the given axes, in world coordinates.
00344     // Implies setAxesAutoRescale(false), and does NOT reset tool stacks since
00345     // the tools may be using this method.  It is recommended that subclasses
00346     // reimplement this to be more efficient.
00347     // DEFAULT IMPLEMENTATION.
00348     // <group>
00349     virtual void setAxesRanges(PlotAxis xAxis, double xFrom, double xTo,
00350                                PlotAxis yAxis, double yFrom, double yTo);    
00351     virtual void setAxesRanges(PlotAxis xAxis, const prange_t& xRange,
00352             PlotAxis yAxis, const prange_t& yRange);
00353     // </group>
00354     
00355     // Sets the displayed range of the given axes. Implies
00356     // setAxesAutoRescale(false),  and does NOT reset tool stacks since the
00357     // tools may be using this method.
00358     // DEFAULT IMPLEMENTATION.
00359     virtual void setAxesRegion(PlotAxis xAxis, PlotAxis yAxis,
00360             const PlotRegion& region);
00361     
00362     // Moves (pans) the axes range by the given delta, in world coordinates.
00363     // Implies setAxesAutoRescale(false), and does NOT reset tool stacks since
00364     // the tools may be using these methods.
00365     // DEFAULT IMPLEMENTATION.
00366     // <group>
00367     virtual void moveAxisRange(PlotAxis axis, double delta);
00368     virtual void moveAxesRanges(PlotAxis xAxis, double xDelta,
00369                                 PlotAxis yAxis, double yDelta);
00370     // </group>
00371     
00372     // Returns true if the axes are set to autorescale when a new plot item is
00373     // added, false otherwise.
00374     virtual bool axesAutoRescale() const = 0;
00375     
00376     // Sets auto-rescaling for future plot items.  If autoRescale is true,
00377     // implies setAxesRatioLocked(false).
00378     virtual void setAxesAutoRescale(bool autoRescale = true) = 0;
00379     
00380     // Rescales the axis to show all plot items on the canvas.  Implies
00381     // setAxesAutoRescale(false), and may reset PlotTools.
00382     virtual void rescaleAxes() = 0;
00383     
00384     // Returns true if the axes ratio is locked, false otherwise.  If the
00385     // ratio is locked, resizing one axis will resize the others
00386     // proportionally.
00387     virtual bool axesRatioLocked() const = 0;
00388     
00389     // Sets whether the axes ratio is locked or not.
00390     virtual void setAxesRatioLocked(bool locked = true) = 0;
00391     
00392     
00393     // Stack Methods //
00394     
00395     // Returns a single PlotAxesStack associated with this canvas.  Note that
00396     // the canvas itself doesn't modify/use this stack AT ALL; it is expressly
00397     // for outside tools/classes/etc to have a single stack per canvas.
00398     // DEFAULT IMPLEMENTATION.
00399     // <group>
00400     virtual PlotAxesStack& axesStack();
00401     virtual const PlotAxesStack& axesStack() const;
00402     // </group>
00403     
00404     // Convenience method to move along the PlotAxesStack associated with this
00405     // canvas (see axesStack()).  Calls the stack's moveAndReturn method, and
00406     // then sets the axes ranges to the returned PlotRegion.  If delta is 0,
00407     // the stack is moved to its base; otherwise it moves forward or backward
00408     // from the current stack index (see PlotAxesStack::moveAndReturn()).
00409     // Returns true if the operation succeeded, false otherwise (for invalid
00410     // delta).
00411     // DEFAULT IMPLEMENTATION.
00412     virtual bool axesStackMove(int delta);
00413     
00414     // Gets/Sets the length limit on the PlotAxesStack associated with this
00415     // canvas.  See PlotAxesStack::lengthLimit() and
00416     // PlotAxesStack::setLengthLimit().
00417     // DEFAULT IMPLEMENTATION.
00418     // <group>
00419     virtual int axesStackLengthLimit() const;
00420     virtual void setAxesStackLengthLimit(int lengthLimit);
00421     // </group>
00422     
00423     // Gets/Sets the size limit, in kilobytes, on the draw cache for the axes
00424     // stack associated with this canvas (see
00425     // PlotFactory::canvasHasCachedAxesStack()).  A zero or negative value
00426     // means no limit.  NOTE: Only valid for implementations that supports a
00427     // cached axes stack.
00428     // <group>
00429     virtual int cachedAxesStackSizeLimit() const = 0;
00430     virtual void setCachedAxesStackSizeLimit(int sizeInKilobytes) = 0;
00431     // </group>
00432     
00433     // Gets/Sets the size of the image used for the cached axes stack, in
00434     // pixels.  The default implementation is set to (-1, -1) which means that
00435     // the images are set to the current size of the canvas.  It could be
00436     // useful to set this value to a large size so that, for example, resizing
00437     // wouldn't require a redraw of the whole canvas but rather just resizing
00438     // the larger image to a smaller one.
00439     // DEFAULT IMPLEMENTATION.
00440     // <group>
00441     virtual pair<int, int> cachedAxesStackImageSize() const;
00442     virtual void setCachedAxesStackImageSize(int width, int height);
00443     // </group>
00444     
00445     
00446     // Plot Methods //
00447     
00448     // Adds the given plot item to this canvas, if not null or otherwise
00449     // invalid.  Returns whether the adding succeeded or not.  May reset
00450     // registered PlotTools.
00451     virtual bool plotItem(PlotItemPtr item, PlotCanvasLayer layer = MAIN) = 0;
00452     
00453     // Item-specific add methods.
00454     // DEFAULT IMPLEMENTATION.
00455     // <group>
00456     virtual bool plot(PlotPtr plot, bool overplot = true);
00457     virtual bool plotPoint(PlotPointPtr point);
00458     virtual bool drawShape(PlotShapePtr shape);
00459     virtual bool drawAnnotation(PlotAnnotationPtr annotation);
00460     // </group>
00461     
00462     // Returns all plot items currently on the canvas.
00463     virtual vector<PlotItemPtr> allPlotItems() const = 0;
00464     
00465     // Item-specific all methods.
00466     // DEFAULT IMPLEMENTATION.
00467     // <group>
00468     virtual vector<PlotPtr> allPlots() const;
00469     virtual vector<PlotPointPtr> allPoints() const;
00470     virtual vector<PlotShapePtr> allShapes() const;
00471     virtual vector<PlotAnnotationPtr> allAnnotations() const;
00472     // </group>
00473     
00474     // Returns the number of plot items currently on the canvas.
00475     // DEFAULT IMPLEMENTATION.
00476     virtual unsigned int numPlotItems() const;
00477     
00478     // Item-specific num methods.
00479     // DEFAULT IMPLEMENTATION.
00480     // <group>
00481     virtual unsigned int numPlots() const;
00482     virtual unsigned int numPoints() const;
00483     virtual unsigned int numShapes() const;
00484     virtual unsigned int numAnnotations() const;
00485     // </group>
00486     
00487     // Returns all plot items currently on the given layer of the canvas.
00488     virtual vector<PlotItemPtr> layerPlotItems(PlotCanvasLayer layer) const= 0;
00489     
00490     // Item-specific layer methods.
00491     // DEFAULT IMPLEMENTATION.
00492     // <group>
00493     virtual vector<PlotPtr> layerPlots(PlotCanvasLayer layer) const;
00494     virtual vector<PlotPointPtr> layerPoints(PlotCanvasLayer layer) const;
00495     virtual vector<PlotShapePtr> layerShapes(PlotCanvasLayer layer) const;
00496     virtual vector<PlotAnnotationPtr> layerAnnotations(PlotCanvasLayer l)const;
00497     // </group>
00498     
00499     // Returns the number of plot items currently on the given layer of the
00500     // canvas.
00501     // DEFAULT IMPLEMENTATION.
00502     virtual unsigned int numLayerPlotItems(PlotCanvasLayer layer) const;
00503     
00504     // Item-specific layer num methods.
00505     // DEFAULT IMPLEMENTATION.
00506     // <group>
00507     virtual unsigned int numLayerPlots(PlotCanvasLayer layer) const;
00508     virtual unsigned int numLayerPoints(PlotCanvasLayer layer) const;
00509     virtual unsigned int numLayerShapes(PlotCanvasLayer layer) const;
00510     virtual unsigned int numLayerAnnotations(PlotCanvasLayer layer) const;
00511     // </group>    
00512     
00513     // Removes the given item from this canvas (if valid) and updates the GUI.
00514     // May reset registered PlotTools.
00515     // DEFAULT IMPLEMENTATION.
00516     virtual void removePlotItem(PlotItemPtr item);
00517     
00518     // Item-specific remove methods.
00519     // DEFAULT IMPLEMENTATION.
00520     // <group>
00521     virtual void removePlot(PlotPtr plot);
00522     virtual void removePoint(PlotPointPtr point);
00523     virtual void removeShape(PlotShapePtr shape);
00524     virtual void removeAnnotation(PlotAnnotationPtr annotation);
00525     // </group>
00526     
00527     // Removes the given items from this canvas (if valid) and updates the GUI.
00528     // May reset registered PlotTools.
00529     virtual void removePlotItems(const vector<PlotItemPtr>& items) = 0;
00530     
00531     // Removes the last plot item added to the canvas and updates the GUI.  May
00532     // reset registered PlotTools.
00533     // DEFAULT IMPLEMENTATION.
00534     virtual void removeLastPlotItem();
00535     
00536     // Item-specific remove last methods.
00537     // DEFAULT IMPLEMENTATION.
00538     // <group>
00539     virtual void removeLastPlot();
00540     virtual void removeLastPoint();
00541     virtual void removeLastShape();
00542     virtual void removeLastAnnotation();
00543     // </group>
00544     
00545     // Clears all plot items from this canvas and updates the GUI.  May reset
00546     // registered PlotTools.
00547     // DEFAULT IMPLEMENTATION.
00548     virtual void clearItems();
00549     
00550     // Item-specific clear methods.
00551     // DEFAULT IMPLEMENTATION.
00552     // <group>
00553     virtual void clearPlots();
00554     virtual void clearPoints();
00555     virtual void clearShapes();
00556     virtual void clearAnnotations();
00557     // </group>
00558     
00559     // Clears all plot items from the given layer on this canvas and updates
00560     // the GUI.  May reset registered PlotTools.
00561     // DEFAULT IMPLEMENTATION.
00562     virtual void clearLayer(PlotCanvasLayer layer);
00563     
00564     
00565     // Draw Methods //
00566     
00567     // Hold or release drawing of plot items on the canvas.  This can be used,
00568     // for example, when adding many items to a canvas to avoid redrawing the
00569     // canvas until all items are on.  Hold/release are NOT recursive.
00570     // <group>
00571     virtual void holdDrawing() = 0;
00572     virtual void releaseDrawing() = 0;
00573     virtual bool drawingIsHeld() const = 0;
00574     // </group>
00575     
00576     // Registers/Unregisters the given draw watcher for this canvas.  See
00577     // documentation for PlotDrawWatcher.
00578     // DEFAULT IMPLEMENTATION.
00579     // <group>
00580     virtual void registerDrawWatcher(PlotDrawWatcherPtr watcher);    
00581     virtual void unregisterDrawWatcher(PlotDrawWatcherPtr watcher);
00582     // </group>
00583     
00584     // Returns a PlotOperation object that can be used to track drawing
00585     // progress across threads.  There must be one PlotOperation for drawing
00586     // per canvas.
00587     // DEFAULT IMPLEMENTATION.
00588     // <group>
00589     virtual PlotOperationPtr operationDraw();
00590     virtual PlotOperationPtr operationDraw(PlotMutexPtr mutex);
00591     // </group>
00592     
00593     
00594     // Selection Methods //
00595     
00596     // Returns true if a line is shown for the selection tool, false otherwise.
00597     // DEFAULT IMPLEMENTATION.
00598     virtual bool selectLineShown() const;
00599     
00600     // Sets whether a line is shown for the selection tool.
00601     virtual void setSelectLineShown(bool shown = true) = 0;
00602     
00603     // returns a copy of the line for the selection tool
00604     virtual PlotLinePtr selectLine() const = 0;
00605     
00606     // set the line for the selection tool
00607     virtual void setSelectLine(const PlotLine& line) = 0;
00608     
00609     // Convenience methods for setting selection line.
00610     // DEFAULT IMPLEMENTATION.
00611     // <group>
00612     virtual void setSelectLine(const PlotLinePtr line);
00613     virtual void setSelectLine(const String& color,
00614                                PlotLine::Style style = PlotLine::SOLID,
00615                                double width = 1.0);
00616     // </group>
00617     
00618     
00619     // Grid Methods //
00620     
00621     // Returns true if any grid lines are shown, false otherwise.  If bool
00622     // parameters are given, they will be set for if each line group is shown
00623     // or not.
00624     virtual bool gridShown(bool* xMajor = NULL, bool* xMinor = NULL,
00625             bool* yMajor = NULL, bool* yMinor = NULL) const = 0;
00626     
00627     // Sets whether the grid is shown, for each of the given line groups.
00628     virtual void showGrid(bool xMajor, bool xMinor, bool yMajor,bool yMinor)=0;
00629     
00630     // Convenience methods for showing/hiding the grid.
00631     // DEFAULT IMPLEMENTATION.
00632     // <group>
00633     virtual void showGrid(bool showAll = true);
00634     virtual void showGridMajor(bool show = true);
00635     virtual void showGridMinor(bool show = true);
00636     // </group>
00637     
00638     // Gets/Sets whether major grid lines are shown for the x-axis.
00639     // DEFAULT IMPLEMENTATION.
00640     // <group>
00641     virtual bool gridXMajorShown() const;
00642     virtual void showGridXMajor(bool s = true);
00643     // </group>
00644     
00645     // Gets/Sets  whether minor grid lines are shown for the x-axis.
00646     // DEFAULT IMPLEMENTATION.
00647     // <group>
00648     virtual bool gridXMinorShown() const;
00649     virtual void showGridXMinor(bool s = true);
00650     // </group>
00651     
00652     // Gets/Sets whether major grid lines are shown for the y-axis.
00653     // DEFAULT IMPLEMENTATION.
00654     // <group>
00655     virtual bool gridYMajorShown() const;
00656     virtual void showGridYMajor(bool s = true);
00657     // </group>
00658 
00659     // Gets/Sets whether minor grid lines are shown for the y-axis.
00660     // DEFAULT IMPLEMENTATION.
00661     // <group>
00662     virtual bool gridYMinorShown() const;
00663     virtual void showGridYMinor(bool s = true);
00664     // </group>
00665     
00666     // Returns a copy of the line used to draw the major grid lines.
00667     virtual PlotLinePtr gridMajorLine() const = 0;
00668     
00669     // Sets the line used to draw the major grid lines.
00670     virtual void setGridMajorLine(const PlotLine& line) = 0;
00671     
00672     // Returns a copy of the line used to draw the minor grid lines.
00673     virtual PlotLinePtr gridMinorLine() const = 0;
00674     
00675     // Sets the line used to draw the minor grid lines.
00676     virtual void setGridMinorLine(const PlotLine& line) = 0;
00677     
00678     // Convenience methods for setting major/minor grid lines.
00679     // DEFAULT IMPLEMENTATION.
00680     // <group>
00681     virtual void setGridMajorLine(const PlotLinePtr line);
00682     virtual void setGridMajorLine(const String& color,
00683             PlotLine::Style style = PlotLine::SOLID, double width = 1.0);
00684     virtual void setGridMinorLine(const PlotLinePtr line);
00685     virtual void setGridMinorLine(const String& color,
00686             PlotLine::Style style = PlotLine::SOLID, double width = 1.0);
00687     // </group>
00688     
00689     
00690     // Legend Methods //
00691     
00692     // Returns whether the legend is shown or not
00693     virtual bool legendShown() const = 0;
00694     
00695     // Show/hide the legend.  If on is true, show the legend in the given
00696     // position.
00697     virtual void showLegend(bool on = true,
00698                             LegendPosition position = EXT_BOTTOM) = 0;
00699     
00700     // Returns the position of the legend.  Note: if the legend is hidden,
00701     // this behavior is undefined.
00702     virtual LegendPosition legendPosition() const = 0;
00703     
00704     // Sets the position of the legend, if it is shown.
00705     virtual void setLegendPosition(LegendPosition position) = 0;
00706     
00707     // Returns a copy of the line used to outline the legend.
00708     virtual PlotLinePtr legendLine() const = 0;
00709     
00710     // Sets the line used to outline the legend.
00711     virtual void setLegendLine(const PlotLine& line) = 0;
00712     
00713     // Convenience methods for setting legend line.
00714     // DEFAULT IMPLEMENTATION.
00715     // <group>
00716     virtual void setLegendLine(const PlotLinePtr line);
00717     virtual void setLegendLine(const String& color,
00718             PlotLine::Style style = PlotLine::SOLID, double width = 1.0);
00719     // </group>
00720     
00721     // Returns a copy of the area fill used for the legend background
00722     virtual PlotAreaFillPtr legendFill() const = 0;
00723     
00724     // Sets the area fill used for the legend background
00725     virtual void setLegendFill(const PlotAreaFill& area) = 0;
00726     
00727     // Convenience methods for setting legend background.
00728     // DEFAULT IMPLEMENTATION.
00729     // <group>
00730     virtual void setLegendFill(const PlotAreaFillPtr area);
00731     virtual void setLegendFill(const String& color,
00732             PlotAreaFill::Pattern pattern = PlotAreaFill::FILL);
00733     // </group>
00734     
00735     // Returns a copy of the font used for the legend text.
00736     virtual PlotFontPtr legendFont() const = 0;
00737     
00738     // Sets the font used for the legend text.
00739     virtual void setLegendFont(const PlotFont& font) = 0;
00740     
00741     // Convenience method for setting legend font.
00742     // DEFAULT IMPLEMENTATION.
00743     virtual void setLegendFont(const PlotFontPtr font);
00744 
00745 
00746     // Miscellaneous Plotting Functionality //
00747     
00748     // Returns true if autoincrementcolors is on, false otherwise.  (See
00749     // setAutoIncrementColors().)
00750     virtual bool autoIncrementColors() const = 0;
00751     
00752     // Sets whether adding new overplotted plots should automatically
00753     // "increment" colors or not.  If this property is true, each new
00754     // overplotted plot should have a different color.  The specific handling
00755     // of this behavior is left up to the implementation.
00756     virtual void setAutoIncrementColors(bool autoInc = true) = 0;
00757 
00758     // Exports this canvas to the given format and returns true on success.
00759     virtual bool exportToFile(const PlotExportFormat& format) = 0;
00760     
00761     // Returns a PlotOperation object that can be used to track export
00762     // progress across threads.  There must be one PlotOperation for export
00763     // per canvas.
00764     // DEFAULT IMPLEMENTATION.
00765     // <group>
00766     virtual PlotOperationPtr operationExport();
00767     virtual PlotOperationPtr operationExport(PlotMutexPtr mutex);
00768     // </group>
00769     
00770     // Shows a file chooser dialog and return the absolute filename that the
00771     // user chooses.  If a directory is given, start the dialog there.  If the
00772     // user cancels the dialog, an empty String should be returned.
00773     virtual String fileChooserDialog(const String& title = "File Chooser",
00774                                      const String& directory = "") = 0;
00775     
00776     // Gets/Sets the date format for this canvas.  See Plotter::dateFormat().
00777     // <group>
00778     virtual const String& dateFormat() const = 0;
00779     virtual void setDateFormat(const String& dateFormat) = 0;
00780     // </group>
00781     
00782     // Gets/Sets the date format for values relative to a reference value for
00783     // this canvas.  See Plotter::relativeDateFormat().
00784     // <group>
00785     virtual const String& relativeDateFormat() const = 0;
00786     virtual void setRelativeDateFormat(const String& dateFormat) = 0;
00787     // </group>
00788 
00789     // Converts the given coordinate into a coordinate with the given system.
00790     virtual PlotCoordinate convertCoordinate(const PlotCoordinate& coord,
00791            PlotCoordinate::System newSystem = PlotCoordinate::WORLD) const = 0;
00792     
00793     // Converts the given region into a region with the given system.
00794     // DEFAULT IMPLEMENTATION.
00795     virtual PlotRegion convertRegion(const PlotRegion& region,
00796                                      PlotCoordinate::System newSystem) const;
00797     
00798     // Returns the width, height, and descent for the given text in the given
00799     // font.  Note: this was put into place for use in a matplotlib backend,
00800     // but probably doesn't have much use outside that.
00801     virtual vector<double> textWidthHeightDescent(const String& text,
00802             PlotFontPtr font) const = 0;
00803     
00804     // Returns the width, height, and descent for the given annotation.  Note:
00805     // this was put into place for use in a matplotlib backend, but probably
00806     // doesn't have much use outside that.
00807     // DEFAULT IMPLEMENTATION.
00808     virtual vector<double> annotationWidthHeightDescent(
00809             const PlotAnnotationPtr annot) const;
00810     
00811     // Returns the implementation of this canvas as a Plotter::Implementation
00812     // value.
00813     virtual int implementation() const = 0;
00814     
00815     // Returns a new instance of a PlotFactory that can create plot items for
00816     // this implementation.  It is the caller's responsibility to delete the
00817     // PlotFactory when finished.
00818     virtual PlotFactory* implementationFactory() const = 0;
00819     
00820     // Returns a mutex appropriate for this implementation.
00821     // DEFAULT IMPLEMENTATION.
00822     virtual PlotMutexPtr mutex() const;
00823     
00824     // Locate data indices that have values within the given region such that:
00825     // x >= region.upperLeft().x() && x <= region.lowerRight().x() &&
00826     // y <= region.upperLeft().y() && y >= region.lowerRight().y().
00827     // The returned vector has length equal to allPlots().size() (in other
00828     // words, each plot on the canvas has an index in the returned vector).
00829     // Each element of the returned vector is a list of all the data indices
00830     // that are in the region.  Each element in this list is a range of indices.
00831     // For plots that have no data in the region, the list is empty.
00832     // 
00833     // For example, say there are two plots on the canvas.  In the first plot,
00834     // indices 1, 2, 3, 7, and 10 are in the region; in the second plot,
00835     // indices 6 and 7 are in the region.  The returned value would be a vector
00836     // of size 2.  The first element would be the list [(1, 3), (7, 7),
00837     // (10, 10)] while the second element would be the list [(6, 7)].
00838     // DEFAULT IMPLEMENTATION.
00839     virtual vector<vector<pair<unsigned int, unsigned int> > >* locate(
00840             const PlotRegion& region) const;
00841     
00842     // Calls locate() and posts the result to the given log.
00843     // DEFAULT IMPLEMENTATION.
00844     virtual void locateAndLog(const PlotRegion& region,
00845             PlotLoggerPtr logger) const;
00846     
00847     
00848     // Tool Methods //
00849     
00850     // Manage mouse tools.
00851     // DEFAULT IMPLEMENTATION.
00852     // <group>
00853     virtual void registerMouseTool(PlotMouseToolPtr tool, bool activate = true,
00854             bool blocking = false);
00855     virtual vector<PlotMouseToolPtr> allMouseTools() const;
00856     virtual vector<PlotMouseToolPtr> activeMouseTools() const;
00857     virtual void unregisterMouseTool(PlotMouseToolPtr tool);
00858     // </group>
00859     
00860     // Returns the standard mouse tools associated with this canvas.  If none
00861     // is associated, creates and associates one that is non-active.
00862     // DEFAULT IMPLEMENTATION.
00863     virtual PlotStandardMouseToolGroupPtr standardMouseTools();
00864     
00865     
00866     // Event Handler Methods //
00867     
00868     // Manage select handlers.
00869     // DEFAULT IMPLEMENTATION.
00870     // <group>
00871     virtual void registerSelectHandler(PlotSelectEventHandlerPtr handler,
00872             PlotCoordinate::System system = PlotCoordinate::WORLD);
00873     virtual vector<PlotSelectEventHandlerPtr> allSelectHandlers() const;
00874     virtual void unregisterSelectHandler(PlotSelectEventHandlerPtr handler);
00875     // </group>
00876     
00877     // Manage click handlers.
00878     // DEFAULT IMPLEMENTATION.
00879     // <group>
00880     virtual void registerClickHandler(PlotClickEventHandlerPtr handler,
00881             PlotCoordinate::System system = PlotCoordinate::WORLD);
00882     virtual vector<PlotClickEventHandlerPtr> allClickHandlers() const;
00883     virtual void unregisterClickHandler(PlotClickEventHandlerPtr handler);
00884     // </group>
00885     
00886     // Manage mouse press handlers.
00887     // DEFAULT IMPLEMENTATION.
00888     // <group>
00889     virtual void registerMousePressHandler(PlotMousePressEventHandlerPtr hndlr,
00890             PlotCoordinate::System system = PlotCoordinate::WORLD);
00891     virtual vector<PlotMousePressEventHandlerPtr>
00892             allMousePressHandlers() const;
00893     virtual void unregisterMousePressHandler(
00894             PlotMousePressEventHandlerPtr handler);
00895     // </group>
00896     
00897     // Manage mouse release handlers.
00898     // DEFAULT IMPLEMENTATION.
00899     // <group>
00900     virtual void registerMouseReleaseHandler(
00901             PlotMouseReleaseEventHandlerPtr handler,
00902             PlotCoordinate::System system = PlotCoordinate::WORLD);
00903     virtual vector<PlotMouseReleaseEventHandlerPtr>
00904             allMouseReleaseHandlers() const;
00905     virtual void unregisterMouseReleaseHandler(
00906             PlotMouseReleaseEventHandlerPtr handler);
00907     // </group>
00908     
00909     // Manage mouse drag handlers.
00910     // DEFAULT IMPLEMENTATION.
00911     // <group>
00912     virtual void registerMouseDragHandler(PlotMouseDragEventHandlerPtr h,
00913             PlotCoordinate::System system = PlotCoordinate::WORLD);
00914     virtual vector<PlotMouseDragEventHandlerPtr> allMouseDragHandlers() const;
00915     virtual void unregisterMouseDragHandler(PlotMouseDragEventHandlerPtr h);
00916     // </group>
00917     
00918     // Manage mouse move handlers.  NOTE: since this can be costly, it should
00919     // be avoided if possible.  Implementation canvases are expected to
00920     // conserve resources if no move handlers are registered.
00921     // DEFAULT IMPLEMENTATION.
00922     // <group>
00923     virtual void registerMouseMoveHandler(PlotMouseMoveEventHandlerPtr h,
00924             PlotCoordinate::System system = PlotCoordinate::WORLD);
00925     virtual vector<PlotMouseMoveEventHandlerPtr> allMouseMoveHandlers() const;
00926     virtual void unregisterMouseMoveHandler(PlotMouseMoveEventHandlerPtr h);
00927     // </group>
00928     
00929     // Manage wheel handlers.
00930     // DEFAULT IMPLEMENTATION.
00931     // <group>
00932     virtual void registerWheelHandler(PlotWheelEventHandlerPtr handler,
00933             PlotCoordinate::System system = PlotCoordinate::WORLD);
00934     virtual vector<PlotWheelEventHandlerPtr> allWheelHandlers() const;
00935     virtual void unregisterWheelHandler(PlotWheelEventHandlerPtr handler);
00936     // </group>
00937     
00938     // Manage key handlers.
00939     // DEFAULT IMPLEMENTATION.
00940     // <group>
00941     virtual void registerKeyHandler(PlotKeyEventHandlerPtr handler);
00942     virtual vector<PlotKeyEventHandlerPtr> allKeyHandlers() const;
00943     virtual void unregisterKeyHandler(PlotKeyEventHandlerPtr handler);
00944     // </group>
00945     
00946     // Manage resize handlers.
00947     // DEFAULT IMPLEMENTATION.
00948     // <group>
00949     virtual void registerResizeHandler(PlotResizeEventHandlerPtr handler);
00950     virtual vector<PlotResizeEventHandlerPtr> allResizeHandlers() const;
00951     virtual void unregisterResizeHandler(PlotResizeEventHandlerPtr handler);
00952     // </group>
00953     
00954 protected:    
00955     // One-per-canvas axes stack.
00956     PlotAxesStack m_stack;
00957     
00958     // One-per-canvas operations.
00959     // <group>
00960     PlotOperationPtr m_drawOperation;
00961     PlotOperationPtr m_exportOperation;
00962     // </group>
00963     
00964     // Draw watchers.
00965     vector<PlotDrawWatcherPtr> m_drawWatchers;
00966     
00967     // One-per-canvas standard mouse tools.
00968     PlotStandardMouseToolGroupPtr m_standardTools;
00969     
00970     // Registered mouse tools.
00971     vector<PlotMouseToolPtr> m_mouseTools;
00972     
00973     // Event handlers.
00974     // <group>
00975     vector<pair<PlotSelectEventHandlerPtr, PlotCoordinate::System> >
00976         m_selectHandlers;
00977     vector<pair<PlotClickEventHandlerPtr, PlotCoordinate::System> >
00978         m_clickHandlers;
00979     vector<pair<PlotMousePressEventHandlerPtr, PlotCoordinate::System> >
00980         m_pressHandlers;
00981     vector<pair<PlotMouseReleaseEventHandlerPtr, PlotCoordinate::System> >
00982         m_releaseHandlers;
00983     vector<pair<PlotMouseDragEventHandlerPtr, PlotCoordinate::System> >
00984         m_dragHandlers;
00985     vector<pair<PlotMouseMoveEventHandlerPtr, PlotCoordinate::System> >
00986         m_moveHandlers;
00987     vector<pair<PlotWheelEventHandlerPtr, PlotCoordinate::System> >
00988         m_wheelHandlers;
00989     vector<PlotKeyEventHandlerPtr> m_keyHandlers;
00990     vector<PlotResizeEventHandlerPtr> m_resizeHandlers;
00991     // </group>
00992     
00993     
00994     // Resets mouse tools.
00995     void resetMouseTools();
00996     
00997     // Notifies any registered draw watchers that a draw is about to begin, and
00998     // returns the AND of the PlotDrawWatcher::canvasDrawBeginning() results.
00999     // See PlotDrawWatcher::canvasDrawBeginning() for parameters.
01000     bool notifyDrawWatchers(PlotOperationPtr drawOperation,
01001             bool drawingIsThreaded, int drawnLayersFlag);
01002     
01003     // Notification methods for event handlers.  Returns true if one mouse tool
01004     // or event handler was available to handle the event, false otherwise.
01005     // <group>
01006     bool notifySelectHandlers(const PlotRegion& selectedRegion);
01007     bool notifyMouseHandlers(PlotMouseEvent::Type type,
01008             PlotMouseEvent::Button button, const PlotCoordinate& coord);
01009     bool notifyClickHandlers(PlotMouseEvent::Button button,
01010             const PlotCoordinate& coord);
01011     bool notifyPressHandlers(PlotMouseEvent::Button button,
01012             const PlotCoordinate& coord);
01013     bool notifyReleaseHandlers(PlotMouseEvent::Button button,
01014             const PlotCoordinate& coord);
01015     bool notifyDragHandlers(PlotMouseEvent::Button button,
01016             const PlotCoordinate& coord);
01017     bool notifyMoveHandlers(PlotMouseEvent::Button button,
01018             const PlotCoordinate& coord);
01019     bool notifyWheelHandlers(int delta, const PlotCoordinate& coord);
01020     bool notifyKeyHandlers(char key,
01021             const vector<PlotKeyEvent::Modifier>& modifiers);
01022     bool notifyResizeHandlers(int oldWidth, int oldHeight,
01023             int newWidth, int newHeight);
01024     // </group>
01025 };
01026 typedef CountedPtr<PlotCanvas> PlotCanvasPtr;
01027 
01028 }
01029 
01030 #endif /*PLOTCANVAS_H_*/

Generated on Thu Aug 27 21:08:46 2009 for NRAOCASA by  doxygen 1.5.1