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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1