PlotTool.h

Go to the documentation of this file.
00001 //# PlotTool.h: Tool class definitions (higher-level event handlers).
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 PLOTTOOL_H_
00028 #define PLOTTOOL_H_
00029 
00030 #include <graphics/GenericPlotter/PlotEventHandler.h>
00031 #include <graphics/GenericPlotter/PlotOptions.h>
00032 #include <graphics/GenericPlotter/PlotShape.h>
00033 #include <graphics/GenericPlotter/PlotAnnotation.h>
00034 
00035 namespace casa {
00036 
00037 //# Forward Declarations
00038 class PlotCanvas;
00039 class PlotFactory;
00040 class PlotPanToolNotifier;
00041 class PlotSelectToolNotifier;
00042 class PlotTrackerToolNotifier;
00043 class PlotZoomToolNotifier;
00044 
00045 
00046 
00048 // ABSTRACT TOOL CLASSES //
00050 
00051 
00052 // A PlotTool is a higher-level event handler for a PlotCanvas.  The idea is to
00053 // take common tasks which may require multiple events and put them in one
00054 // place.  PlotTools also provide additional functionality in that they can be
00055 // 1) active/inactive, and 2) blocking/non-blocking.  The PlotCanvas will only
00056 // send events to active tools, and will not send events to later tools or
00057 // event handlers if the latest tool was blocking.  In this way a single tool
00058 // can be used to handle ALL user interaction via the GUI at one time, if
00059 // desired.  The PlotTool class itself is abstract and deliberately non-binding
00060 // as it is mainly meant for specialization in its children classes.  PlotTools
00061 // can also specify which coordinate system and two axes they work on, and the
00062 // PlotCanvas is expected to obey these constraints.
00063 class PlotTool {
00064     friend class PlotCanvas;
00065     friend class PlotMouseToolGroup;
00066     
00067 public:
00068     // Constructor which takes which coordinate system events should be
00069     // processed in.
00070     PlotTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00071     
00072     // Constructor which takes the two axes and the coordinate system which
00073     // events should be processed in.
00074     PlotTool(PlotAxis xAxis, PlotAxis yAxis,
00075             PlotCoordinate::System sys = PlotCoordinate::WORLD);
00076     
00077     // Destructor.
00078     virtual ~PlotTool();
00079     
00080     
00081     // Returns whether this tool is currently active or not.
00082     virtual bool isActive() const;
00083     
00084     // Sets whether this tool is currently active or not.
00085     virtual void setActive(bool isActive = true);
00086     
00087     // Returns whether this tool is blocking or not.  When a PlotCanvas
00088     // encounters a blocking tool, it is expected to not send events to any
00089     // other handlers further in the chain.
00090     virtual bool isBlocking() const;
00091     
00092     // Sets whether this tool is blocking or not.
00093     virtual void setBlocking(bool blocking = true);
00094     
00095     // Gets the axes on which the tool operates.
00096     // <group>
00097     virtual PlotAxis getXAxis() const;
00098     virtual PlotAxis getYAxis() const;
00099     // </group>
00100     
00101     // Gets the coordinate system in which the tool wants to process events.
00102     // Events passed to this tool should use this coordinate system.
00103     virtual PlotCoordinate::System getCoordinateSystem() const;
00104     
00105     // Returns whether the last event was handled or not.  Mostly used for
00106     // blocking tools so that unused events can be passed along.
00107     virtual bool lastEventWasHandled() const;
00108     
00109     // Resets any internal state such as history/stacks.  Should be called by
00110     // the PlotCanvas when the state of the canvases changes (axes ranges,
00111     // adding/deleting items, etc.) and would thus invalidate tool states.
00112     virtual void reset() { }
00113     
00114 
00115 
00116 protected:
00117     // Attached canvas (or NULL for none).
00118     PlotCanvas* m_canvas;
00119     
00120     // Factory for creating implementation-specific objects.
00121     PlotFactory* m_factory;
00122     
00123     // Whether this tool is active.
00124     bool m_active;
00125     
00126     // Whether this tool is blocking.
00127     bool m_blocking;
00128     
00129     // The tool axes.
00130     PlotAxis m_xAxis, m_yAxis;
00131     
00132     // The tool coordinate system.
00133     PlotCoordinate::System m_coordSystem;
00134     
00135     // Last event handled flag.
00136     bool m_lastEventHandled;
00137     
00138     
00139     // Returns the canvas this tool is attached to, or NULL for none.
00140     virtual PlotCanvas* canvas() const;
00141     
00142     // Returns a factory that can be used for generating
00143     // implementation-specific classes, or NULL for none.
00144     virtual PlotFactory* factory() const;
00145     
00146     // Returns true if this tool is attached to a canvas, false otherwise.
00147     virtual bool isAttached() const;
00148     
00149     // Attaches this tool to the given canvas.  Detaches from current canvas
00150     // if necessary.
00151     virtual void attach(PlotCanvas* canvas);
00152     
00153     // Detaches this tool from its canvas.
00154     virtual void detach();
00155 };
00156 
00157 typedef CountedPtr<PlotTool> PlotToolPtr;
00158 
00159 
00160 
00161 
00162 // A PlotMouseTool is a specialization of PlotTool that handles all mouse
00163 // events.  It is abstract, and combines all mouse event handling methods into
00164 // one for convenience.
00165 class PlotMouseTool : public virtual PlotTool,
00166                       public virtual PlotSelectEventHandler,
00167                       public virtual PlotClickEventHandler, 
00168                       public virtual PlotMousePressEventHandler,
00169                       public virtual PlotMouseReleaseEventHandler,
00170                       public virtual PlotMouseDragEventHandler,
00171                       public virtual PlotMouseMoveEventHandler,
00172                       public virtual PlotWheelEventHandler {
00173 public:
00174     // Constructor which takes the tool's coordinate system.
00175     PlotMouseTool(PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
00176             PlotTool(coordSys) { }
00177     
00178     // Constructor which takes the tool's axes and coordinate system.
00179     PlotMouseTool(PlotAxis xAxis, PlotAxis yAxis,
00180             PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
00181             PlotTool(xAxis, yAxis, coordSys) { }
00182     
00183     // Destructor.
00184     virtual ~PlotMouseTool() { }
00185 
00186 
00187     // Event handling methods.
00188     // <group>
00189     virtual void handleSelect(const PlotSelectEvent& event) {
00190         handleMouseEvent(event); }
00191     virtual void handleClick(const PlotClickEvent& event) {
00192         handleMouseEvent(event); }
00193     virtual void handleMousePress(const PlotMousePressEvent& event) {
00194         handleMouseEvent(event); }
00195     virtual void handleMouseRelease(const PlotMouseReleaseEvent& event) {
00196         handleMouseEvent(event); }
00197     virtual void handleMouseDrag(const PlotMouseDragEvent& event) {
00198         handleMouseEvent(event); }
00199     virtual void handleMouseMove(const PlotMouseMoveEvent& event) {
00200         handleMouseEvent(event); }
00201     virtual void handleWheel(const PlotWheelEvent& event) {
00202         handleMouseEvent(event); }
00203     // </group>
00204     
00205     
00206     // ABSTRACT METHODS //
00207     
00208     // Handles the given mouse event.  Guaranteed to be one of the mouse
00209     // events (select, click, press, release, drag, move, wheel).  The
00210     // implementing class should also update the last event handled flag as
00211     // necessary.
00212     virtual void handleMouseEvent(const PlotEvent& event) = 0;
00213 };
00214 INHERITANCE_POINTER2(PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr)
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 // CONCRETE TOOL CLASSES //
00224 
00225 
00226 
00227 
00228 // Was in PlotStandardMouseToolGroup, but needed here, so it can be  passed
00229 // to setActiveTool, which needs it to adjust the Select tool to either work
00230 // normal or as Subtraction tool.
00231 
00232 // Enum for standard tools in group.
00233 enum ToolCode {
00234     SELECT_TOOL,   
00235     SUBTRACT_TOOL,   
00236     ZOOM_TOOL, 
00237     PAN_TOOL, 
00238     NONE_TOOL
00239 };
00240     
00241 
00242 
00243 
00244 
00245 // A PlotSelectTool is a concrete subclass of PlotMouseTool that mainly handles
00246 // select events.  Note that plotting implementations may wish to override
00247 // this class with an implementation-specific version that may be more
00248 // efficient.  PlotSelectTool is responsible for:
00249 // 1) managing the select line (the line show while the user is click-dragging
00250 //    to select a region on the canvas) and cursors,
00251 // 2) keeping track of selected regions,
00252 // 3) showing/hiding the regions on the canvas, and
00253 // 4) notifying any interested classes whenever the selected regions changes.
00254 class PlotSelectTool : public virtual PlotMouseTool {
00255 public:
00256     // Constructor which takes the tool's coordinate system.
00257     PlotSelectTool(PlotCoordinate::System system = PlotCoordinate::WORLD);
00258     
00259     // Constructor which takes the tool's axes and coordinate system.
00260     PlotSelectTool(PlotAxis xAxis, PlotAxis yAxis,
00261                    PlotCoordinate::System system = PlotCoordinate::WORLD);
00262     
00263     // Destructor.
00264     virtual ~PlotSelectTool();
00265     
00266     // Adds the given notifier.  This object will be notified when the list
00267     // of selected regions changes (either by adding one from the mouse, or
00268     // clearing them).
00269     virtual void addNotifier(PlotSelectToolNotifier* notifier);
00270     
00271     // Sets the selection line to the given.
00272     // <group>
00273     virtual void setSelectLine(PlotLinePtr line);
00274     virtual void setSubtractLine(PlotLinePtr line);
00275     virtual void setSelectLine(bool on = true);
00276     // </group>
00277     
00278     // Sets the attributes for drawing selected regions.
00279     // <group>
00280     virtual void setDrawRects(bool on = true);
00281     virtual void setRectLine(PlotLinePtr line);
00282     virtual void setRectFill(PlotAreaFillPtr fill);
00283     // </group>
00284     
00285     // Selected regions.
00286     // <group>
00287     virtual unsigned int numSelectedRects() const;
00288     virtual void getSelectedRects( 
00289                 vector<double>& upperLeftXs,
00290                 vector<double>& upperLeftYs, 
00291                 vector<double>& lowerRightXs,
00292                 vector<double>& lowerRightYs,
00293                 PlotCoordinate::System system = PlotCoordinate::WORLD)  const;
00294     virtual vector<PlotRegion> getSelectedRects(
00295                 PlotCoordinate::System system = PlotCoordinate::WORLD)  const;
00296     virtual void clearSelectedRects();
00297     virtual int getSelectedRectCount();
00298     // </group>
00299     
00300     // Overrides PlotTool::setActive().
00301     virtual void setActive(bool active = true);
00302     
00303     // Implements PlotMouseTool::handleMouseEvent().
00304     virtual void handleMouseEvent(const PlotEvent& event);
00305     
00306     bool inSubtractionMode()      { return m_subtraction_mode; }
00307 
00308 
00309 
00310     bool m_subtraction_mode;
00311 
00312 
00313 protected:
00314     // Notifiers.
00315     vector<PlotSelectToolNotifier*> m_notifiers;
00316     
00317     // Copy of selection line to set on the canvas, or NULL if none has been
00318     // set.
00319     PlotLinePtr m_selLine;
00320     PlotLinePtr m_subLine;
00321     
00322     // Whether or not to draw selected regions on the canvas.
00323     bool m_drawRects;
00324     
00325     // Line for drawing selected regions, or NULL if none has been set.
00326     PlotLinePtr m_rectLine;
00327     
00328     // Area fill for drawing selected regions, or NULL if none has been set.
00329     PlotAreaFillPtr m_rectFill;
00330     
00331     // Selected regions.
00332     vector<PlotShapeRectanglePtr> m_rects;
00333     
00334 
00335     
00336     // Overrides PlotTool::attach().
00337     virtual void attach(PlotCanvas* canvas);
00338     
00339     // Overrides PlotTool::detach().
00340     virtual void detach();
00341 };
00342 
00343 
00344 INHERITANCE_POINTER(PlotSelectTool, PlotSelectToolPtr, PlotMouseTool,
00345                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 // A PlotZoomTool is a concrete subclass of PlotMouseTool that provides
00356 // convenient zooming functionality.  Standard behavior is to zoom on a
00357 // select event, go through the zoom stack on a wheel event, go to the zoom
00358 // stack base on a right click, and zoom in 50% centered on a double-click.
00359 // Note that plotting implementations may wish to override this class with an
00360 // implementation-specific version that may be more efficient.  A PlotZoomTool
00361 // is responsible for:
00362 // 1) managing behavior described above,
00363 // 2) managing a zoom stack,
00364 // 3) managing the canvas's select line/cursor, and
00365 // 3) notifying interested objects when the zoom changes.
00366 class PlotZoomTool : public virtual PlotMouseTool {
00367 public:
00368     // Constructor which takes the tool's coordinate system.
00369     PlotZoomTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00370     
00371     // Constructor which takes the tool's axes and coordinate system.
00372     PlotZoomTool(PlotAxis xAxis, PlotAxis yAxis,
00373                  PlotCoordinate::System sys = PlotCoordinate::WORLD);
00374     
00375     // Destructor.
00376     virtual ~PlotZoomTool();
00377     
00378     // Adds the given notifier.  This object will be notified when the zoom
00379     // changes.
00380     virtual void addNotifier(PlotZoomToolNotifier* notifier);
00381     
00382     // Sets the selection line to the given.
00383     // <group>
00384     virtual void setSelectLine(PlotLinePtr line);
00385     virtual void setSelectLine(bool on = true);
00386     // </group>
00387     
00388     // Gets the zoom stack.
00389     virtual vector<PlotRegion> getZoomStack(PlotCoordinate::System sytem =
00390                                             PlotCoordinate::WORLD) const;
00391     
00392     // Gets the zoom stack index.
00393     virtual unsigned int getStackIndex() const;
00394     
00395     // Overrides PlotTool::setActive().
00396     virtual void setActive(bool active = true);
00397     
00398     // Implements PlotMouseTool::handleMouseEvent().
00399     virtual void handleMouseEvent(const PlotEvent& event);
00400     
00401     // Overrides PlotTool::reset().
00402     virtual void reset();
00403     
00404 protected:
00405     // Notifiers.
00406     vector<PlotZoomToolNotifier*> m_notifiers;
00407     
00408     // Copy of canvas selection line, or NULL if none has been set.
00409     PlotLinePtr m_selLine;
00410     
00411     // Common canvas stack.
00412     PlotAxesStack* m_stack;
00413     
00414     
00415     // Overrides PlotTool::attach().
00416     virtual void attach(PlotCanvas* canvas);
00417     
00418     // Overrides PlotTool::detach().
00419     virtual void detach();
00420     
00421     // Notifies all registered listeners that the zoom has changed.
00422     virtual void notifyWatchers();
00423 };
00424 INHERITANCE_POINTER(PlotZoomTool, PlotZoomToolPtr, PlotMouseTool,
00425                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
00426 
00427 
00428 
00429 
00430 // A PlotPanTool is a concrete subclass of PlotMouseTool that provides
00431 // convenient panning functionality.  Standard behavior is to pan the canvas
00432 // on a drag event, go through the pan stack on a wheel event, and go to the
00433 // pan stack base on a right click.  Note that plotting implementations may
00434 // wish to override this class with an implementation-specific version that may
00435 // be more efficient.  A PlotPanTool is responsible for:
00436 // 1) managing behavior described above,
00437 // 2) managing a pan stack,
00438 // 3) managing the canvas's cursor, and
00439 // 4) notifying interested objects when the pan changes.
00440 class PlotPanTool : public virtual PlotMouseTool {
00441 public:
00442     // Constructor which takes the tool's coordinate system.
00443     PlotPanTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00444     
00445     // Constructor which takes the tool's axes and coordinate system.
00446     PlotPanTool(PlotAxis xAxis, PlotAxis yAxis,
00447                 PlotCoordinate::System sys = PlotCoordinate::WORLD);
00448     
00449     // Destructor.
00450     virtual ~PlotPanTool();
00451     
00452     // Adds the given notifier.  This object will be notified when the pan
00453     // changes.
00454     virtual void addNotifier(PlotPanToolNotifier* notifier);
00455     
00456     // Gets the pan stack.
00457     virtual vector<PlotRegion> getPanStack(PlotCoordinate::System system =
00458                                            PlotCoordinate::WORLD) const;
00459     
00460     // Gets the pan stack index.
00461     virtual unsigned int getStackIndex() const;
00462     
00463     // Overrides PlotTool::setActive().
00464     virtual void setActive(bool active = true);
00465     
00466     // Implements PlotMouseTool::handleMouseEvent().
00467     virtual void handleMouseEvent(const PlotEvent& event);
00468     
00469     // Overrides PlotTool::reset().
00470     virtual void reset();
00471     
00472 protected:
00473     // Notifiers.
00474     vector<PlotPanToolNotifier*> m_notifiers;
00475     
00476     // Whether we're in dragging mode or not.
00477     bool m_inDraggingMode;
00478     
00479     // Last coordinate in dragging mode.
00480     PlotCoordinate m_lastCoord;
00481     
00482     // Common canvas stack.
00483     PlotAxesStack* m_stack;
00484     
00485     
00486     // Overrides PlotTool::attach().
00487     virtual void attach(PlotCanvas* canvas);
00488     
00489     // Overrides PlotTool::detach().
00490     virtual void detach();
00491     
00492     // Notifies all registered listeners that the pan has changed.
00493     virtual void notifyWatchers();
00494 };
00495 INHERITANCE_POINTER(PlotPanTool, PlotPanToolPtr, PlotMouseTool,
00496                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
00497 
00498 
00499 
00500 
00501 // A PlotTrackerTool is a concrete subclass of PlotMouseTool that provides
00502 // convenient tracker functionality.  Note that plotting implementations may
00503 // wish to override this class with an implementation-specific version that may
00504 // be more efficient.  A PlotTrackerTool can:
00505 // 1) show a label with the current position hovering over the mouse,
00506 // 2) let an external class handle the tracking via notifications, or
00507 // 3) both.
00508 class PlotTrackerTool : public virtual PlotMouseTool {
00509     friend class PlotStandardMouseToolGroup; // Why is this necessary to access
00510                                              // attach() and detach()? >:(
00511     
00512 public:
00513     // Static //
00514     
00515     // Returns a String for the given position in the given format, with the
00516     // given canvas and axes.
00517     static String formattedString(const String& format, double x, double y,
00518                        PlotCanvas* canvas, PlotAxis xAxis, PlotAxis yAxis);
00519     
00520     
00521     // Non-Static //
00522     
00523     // Constructor which takes the tool's coordinate system.
00524     PlotTrackerTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00525         
00526     // Constructor which takes the tool's axes and coordinate system.
00527     PlotTrackerTool(PlotAxis xAxis, PlotAxis yAxis,
00528                     PlotCoordinate::System sys = PlotCoordinate::WORLD);
00529     
00530     // Destructor.
00531     virtual ~PlotTrackerTool();
00532     
00533     // Adds the given notifier.  This object will be notified when the tracker
00534     // changes (and a new coordinate is ready for display).
00535     virtual void addNotifier(PlotTrackerToolNotifier* notifier);
00536     
00537     // Returns true if the tracker text is drawn on the canvas, false otherwise.
00538     virtual bool drawsText() const;
00539     
00540     // Sets whether the tracker will draw the text on the canvas or not.
00541     virtual void setDrawText(bool draw = true);
00542     
00543     // Sets the tracker text format to the given.  The following tags can be
00544     // used in the format:
00545     // * %%x%% : x value
00546     // * %%y%% : y values
00547     // * %%pX%% : sets the precision to X for any following numbers.
00548     // NOTICE: if the x or y value is a date, the date format set on the
00549     // canvas this tool is attached to will be used to display the value.
00550     // Default format is "(%%x%%, %%y%%)".
00551     virtual void setFormat(const String& format);
00552     
00553     // Returns the formatted tracker text for the given position.
00554     virtual String formattedString(double x, double y) {
00555         return formattedString(m_format, x, y, m_canvas, m_xAxis, m_yAxis); }
00556     
00557     // Returns the annotation used to store the coordinates/text.
00558     virtual PlotAnnotationPtr getAnnotation();
00559     
00560     // Gets the tracker's current position.
00561     virtual PlotCoordinate getCoordinate(PlotCoordinate::System =
00562                                          PlotCoordinate::WORLD) const;
00563     
00564     // Overrides PlotTool::setActive().
00565     virtual void setActive(bool active = true);
00566     
00567     // Implements PlotMouseTool::handleMouseEvent().
00568     virtual void handleMouseEvent(const PlotEvent& event);
00569     
00570     int getSelectedRectCount() const;
00571     vector<PlotRegion> getSelectedRects() const;
00572 
00573 protected:
00574     // Notifiers.
00575     vector<PlotTrackerToolNotifier*> m_notifiers;
00576     
00577     // Annotation that holds current position (even if not drawn on canvas).
00578     PlotAnnotationPtr m_annotation;
00579     
00580     // Whether to draw the annotation or not.
00581     bool m_drawText;
00582     
00583     // Tracker text format.
00584     String m_format;
00585     
00586     // Overrides PlotTool::attach().
00587     virtual void attach(PlotCanvas* canvas);
00588     
00589     // Overrides PlotTool::detach().
00590     virtual void detach();
00591     
00592     // Notifies all registered listeners that the tracker has changed.
00593     virtual void notifyWatchers();
00594     
00595     
00596     // Static //
00597     
00598     // Format constants.
00599     // <group>
00600     static const String FORMAT_DIVIDER;
00601     static const String FORMAT_X, FORMAT_Y;
00602     static const String FORMAT_PRECISION;
00603     static const String DEFAULT_FORMAT;
00604     // </group>
00605 };
00606 INHERITANCE_POINTER(PlotTrackerTool, PlotTrackerToolPtr, PlotMouseTool,
00607                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
00608 
00609 
00610 
00611 // TOOL NOTIFICATION CLASSES //
00613 
00614 
00615 // Interface for objects that want to be notified when the selection tool
00616 // changes.
00617 class PlotSelectToolNotifier {
00618     friend class PlotSelectTool;
00619     
00620 public:
00621     PlotSelectToolNotifier() { }
00622     virtual ~PlotSelectToolNotifier() { }
00623     
00624 protected:
00625     // This method is called AFTER the selection has been added.
00626     virtual void notifySelectionAdded(PlotSelectTool& tool) = 0;
00627 };
00628 
00629 
00630 // Interface for objects that want to be notified when the zoom tool
00631 // changes.
00632 class PlotZoomToolNotifier {
00633     friend class PlotZoomTool;
00634     
00635 public:
00636     PlotZoomToolNotifier() { }
00637     virtual ~PlotZoomToolNotifier() { }
00638     
00639 protected:
00640     // This method is called AFTER the canvas has been zoomed.
00641     virtual void notifyZoomChanged(PlotZoomTool& tool) = 0;
00642 };
00643 
00644 
00645 // Interface for objects that want to be notified when the pan tool
00646 // changes.
00647 class PlotPanToolNotifier {
00648     friend class PlotPanTool;
00649     
00650 public:
00651     PlotPanToolNotifier() { }
00652     virtual ~PlotPanToolNotifier() { }
00653     
00654 protected:
00655     // This method is called AFTER the canvas has been panned.
00656     virtual void notifyPanChanged(PlotPanTool& tool) = 0;
00657 };
00658 
00659 
00660 // Interface for objects that want to be notified when the tracker tool
00661 // changes.
00662 class PlotTrackerToolNotifier {
00663     friend class PlotTrackerTool;
00664     
00665 public:
00666     PlotTrackerToolNotifier() { }
00667     virtual ~PlotTrackerToolNotifier() { }
00668     
00669 protected:
00670     // This method is called AFTER the tracker has been updated.
00671     virtual void notifyTrackerChanged(PlotTrackerTool& tool) = 0;
00672 };
00673 
00674 
00676 // TOOL GROUP CLASSES //
00678 
00679 
00680 // A PlotMouseToolGroup provides an interface for a group of PlotMouseTools
00681 // where only one (or none) is active at a time.
00682 class PlotMouseToolGroup : public virtual PlotMouseTool {
00683 public:
00684     // Constructor for empty group.
00685     PlotMouseToolGroup();
00686     
00687     // Destructor.
00688     virtual ~PlotMouseToolGroup();    
00689        
00690     // Returns the number of tools in the group.
00691     unsigned int numTools() const;    
00692     
00693     // Returns the tools in the group.
00694     vector<PlotMouseToolPtr> tools() const;
00695     
00696     // Adds the given tool to the group and returns its index.  If makeActive
00697     // is true, the given tool becomes the group's active tool.
00698     // Note (dec 2010): used to take 2nd arg, boolean, to make tool active.
00699     // This is confusing design.  Caller of addTool should just call  setActiveTool(tool)
00700     // after calling addTool() if it wants the tool to become active.
00701     // In practice, source code does not anywhere call addTool with make_active=true.
00702     unsigned int addTool(PlotMouseToolPtr tool);
00703     
00704     // Removes the given tool from the group, and returns true on success.
00705     // <group>
00706     bool removeTool(PlotMouseToolPtr tool);    
00707     bool removeTool(unsigned int index) { return removeTool(toolAt(index)); }
00708     // </group>
00709     
00710     // Returns the tool at the given index, or NULL for invalid.
00711     PlotMouseToolPtr toolAt(unsigned int index) const;
00712     
00713     // Returns the index of the given tool, or numTools() for invalid.
00714     unsigned int indexOf(PlotMouseToolPtr tool) const;
00715     
00716     // Returns true if the given tool is in this group, false otherwise.
00717     bool containsTool(PlotMouseToolPtr tool) const {
00718         return indexOf(tool) < m_tools.size(); }
00719     
00720     // Returns the currently active tool, or NULL for none.
00721     PlotMouseToolPtr activeTool() const { return m_activeTool; }
00722     
00723     // Sets the active tool to the given.  If the given tool is not in the
00724     // group it is first added.
00725     // Toolcode is optional - meaningful only if tool has double usage, like
00726     // Select tool which doubles as the Subtraction tool.  Otherwise, just stuff NONE_TOOL
00727     // in for that arg.
00728     void setActiveTool(PlotMouseToolPtr tool,  ToolCode toolcode=NONE_TOOL);
00729     
00730     // Sets the active tool to the one at the given index.
00731     void setActiveTool(unsigned int index, ToolCode c=NONE_TOOL)   { 
00732             setActiveTool(toolAt(index), c); 
00733             }
00734     
00735     // Overrides PlotTool::setActive().
00736     void setActive(bool isActive = true);
00737     
00738     // Overrides PlotTool::setBlocking().
00739     void setBlocking(bool blocking = true);    
00740     
00741     // Implements PlotMouseTool::handleMouseEvent().
00742     void handleMouseEvent(const PlotEvent& event);
00743     
00744     // Overrides PlotMouseTool's event handling methods.
00745     // <group>
00746     void handleSelect(const PlotSelectEvent& event);
00747     void handleClick(const PlotClickEvent& event);
00748     void handleMousePress(const PlotMousePressEvent& event);
00749     void handleMouseRelease(const PlotMouseReleaseEvent& event);
00750     void handleMouseDrag(const PlotMouseDragEvent& event);
00751     void handleMouseMove(const PlotMouseMoveEvent& event);
00752     void handleWheel(const PlotWheelEvent& event);
00753     // </group>
00754     
00755     // Overrides PlotTool::getXAxis().
00756     PlotAxis getXAxis() const;
00757     
00758     // Overrides PlotTool::getYAxis().
00759     PlotAxis getYAxis() const;
00760     
00761     // Overrides PlotTool::getCoordinateSystem().
00762     PlotCoordinate::System getCoordinateSystem() const;
00763     
00764     // Overrides PlotTool::lastEventWasHandled().
00765     bool lastEventWasHandled() const;
00766     
00767     // Overrides PlotTool::reset().
00768     void reset();
00769     
00770 protected:
00771     // All tools.
00772     vector<PlotMouseToolPtr> m_tools;
00773     
00774     // Active tool (or NULL for no active tool).
00775     PlotMouseToolPtr m_activeTool;
00776     
00777     // Overrides PlotTool::attach().
00778     virtual void attach(PlotCanvas* canvas);
00779     
00780     // Overrides PlotTool::detach().
00781     virtual void detach();
00782 };
00783 INHERITANCE_POINTER(PlotMouseToolGroup, PlotMouseToolGroupPtr, PlotMouseTool,
00784                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
00785 
00786 
00787 // PlotStandardMouseToolGroup is a specialized PlotMouseToolGroup where the
00788 // tools in the group are:
00789 // 1) select,
00790 // 2) zoom, and
00791 // 3) pan.
00792 // A tracker is also provided that is not in the group so that it can be active
00793 // at the same time other tools are active.
00794 class PlotStandardMouseToolGroup : public PlotMouseToolGroup {
00795 public:
00796     // Static //
00797     
00798     // Non-Static //
00799     
00800     // Constructor which creates default tools with the given coordinate
00801     // system, and sets the active tool to the given.
00802     PlotStandardMouseToolGroup(ToolCode activeTool = NONE_TOOL,
00803             PlotCoordinate::System system = PlotCoordinate::WORLD);
00804     
00805     // Constructor which creates default tools with the given coordinate
00806     // system and axes, and sets the active tool to the given.
00807     PlotStandardMouseToolGroup(PlotAxis xAxis, PlotAxis yAxis,
00808             ToolCode activeTool = NONE_TOOL,
00809             PlotCoordinate::System system = PlotCoordinate::WORLD);
00810     
00811     // Constructor which uses the given tools (or creates default tools if the
00812     // given ones are invalid), and sets the active tool to the given.
00813     PlotStandardMouseToolGroup(PlotSelectToolPtr selectTool,
00814                                PlotZoomToolPtr zoomTool,
00815                                PlotPanToolPtr panTool,
00816                                PlotTrackerToolPtr trackerTool,
00817                                ToolCode activeTool = NONE_TOOL);
00818     
00819     // Destructor.
00820     ~PlotStandardMouseToolGroup();
00821     
00822     // Gets/sets the active standard tool.
00823     // <group>
00824     void setActiveTool(ToolCode tool);
00825     ToolCode activeToolType() const;
00826     // </group>
00827     
00828     // Provides access to the tracker.
00829     // <group>
00830     void turnTracker(bool on);
00831     bool trackerIsOn() const;
00832     void turnTrackerDrawText(bool on);
00833     bool trackerDrawsText() const;
00834     // </group>
00835     
00836     int getSelectedRectCount();
00837     vector<PlotRegion> getSelectedRects();
00838     void clearSelectedRects();
00839 
00840     // Provides access to the individual tools.  Note: this should be avoided
00841     // if possible.
00842     // <group>
00843     PlotSelectToolPtr selectTool();
00844     PlotZoomToolPtr zoomTool();
00845     PlotPanToolPtr panTool();
00846     PlotTrackerToolPtr trackerTool();
00847     // </group>
00848     
00849     // Overrides PlotMouseToolGroup handler methods to give events to the
00850     // tracker first.
00851     // <group>
00852     void handleMouseEvent(const PlotEvent& event) {
00853         if(m_tracker->isActive()) m_tracker->handleMouseEvent(event);
00854         PlotMouseToolGroup::handleMouseEvent(event); }
00855         
00856     void handleSelect(const PlotSelectEvent& event) {
00857         if(m_tracker->isActive()) m_tracker->handleSelect(event);
00858         PlotMouseToolGroup::handleSelect(event); }
00859         
00860     void handleClick(const PlotClickEvent& event) {
00861         if(m_tracker->isActive()) m_tracker->handleClick(event);
00862         PlotMouseToolGroup::handleClick(event); }
00863         
00864     void handleMousePress(const PlotMousePressEvent& event) {
00865         if(m_tracker->isActive()) m_tracker->handleMousePress(event);
00866         PlotMouseToolGroup::handleMousePress(event); }
00867         
00868     void handleMouseRelease(const PlotMouseReleaseEvent& event) {
00869         if(m_tracker->isActive()) m_tracker->handleMouseRelease(event);
00870         PlotMouseToolGroup::handleMouseRelease(event); }
00871         
00872     void handleMouseDrag(const PlotMouseDragEvent& event) {
00873         if(m_tracker->isActive()) m_tracker->handleMouseDrag(event);
00874         PlotMouseToolGroup::handleMouseDrag(event); }
00875         
00876     void handleMouseMove(const PlotMouseMoveEvent& event) {
00877         if(m_tracker->isActive()) m_tracker->handleMouseMove(event);
00878         PlotMouseToolGroup::handleMouseMove(event); }
00879         
00880     void handleWheel(const PlotWheelEvent& event) {
00881         if(m_tracker->isActive()) m_tracker->handleWheel(event);
00882         PlotMouseToolGroup::handleWheel(event); }
00883     // </group>
00884     
00885 protected:
00886     // Overrides PlotMouseToolGroup::attach().
00887     void attach(PlotCanvas* canvas);
00888     
00889     // Overrides PlotMouseToolGroup::detach().
00890     void detach();
00891     
00892 private:
00893     // Tracker.
00894     PlotTrackerToolPtr m_tracker;
00895 };
00896 INHERITANCE_POINTER(PlotStandardMouseToolGroup, PlotStandardMouseToolGroupPtr,
00897                     PlotMouseToolGroup, PlotMouseToolGroupPtr,
00898                     PlotTool, PlotToolPtr)
00899 
00900 }
00901 
00902 #endif /* PLOTTOOL_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1