LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotTool.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 57 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 46 0.0 %

          Line data    Source code
       1             : //# PlotTool.h: Tool class definitions (higher-level event handlers).
       2             : //# Copyright (C) 2008
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id: $
      27             : #ifndef PLOTTOOL_H_
      28             : #define PLOTTOOL_H_
      29             : 
      30             : #include <graphics/GenericPlotter/PlotEventHandler.h>
      31             : #include <graphics/GenericPlotter/PlotOptions.h>
      32             : #include <graphics/GenericPlotter/PlotShape.h>
      33             : #include <graphics/GenericPlotter/PlotAnnotation.h>
      34             : 
      35             : namespace casa {
      36             : 
      37             : //# Forward Declarations
      38             : class PlotCanvas;
      39             : class PlotFactory;
      40             : class PlotPanToolNotifier;
      41             : class PlotSelectToolNotifier;
      42             : class PlotTrackerToolNotifier;
      43             : class PlotZoomToolNotifier;
      44             : 
      45             : 
      46             : 
      47             : ///////////////////////////
      48             : // ABSTRACT TOOL CLASSES //
      49             : ///////////////////////////
      50             : 
      51             : 
      52             : // A PlotTool is a higher-level event handler for a PlotCanvas.  The idea is to
      53             : // take common tasks which may require multiple events and put them in one
      54             : // place.  PlotTools also provide additional functionality in that they can be
      55             : // 1) active/inactive, and 2) blocking/non-blocking.  The PlotCanvas will only
      56             : // send events to active tools, and will not send events to later tools or
      57             : // event handlers if the latest tool was blocking.  In this way a single tool
      58             : // can be used to handle ALL user interaction via the GUI at one time, if
      59             : // desired.  The PlotTool class itself is abstract and deliberately non-binding
      60             : // as it is mainly meant for specialization in its children classes.  PlotTools
      61             : // can also specify which coordinate system and two axes they work on, and the
      62             : // PlotCanvas is expected to obey these constraints.
      63             : class PlotTool {
      64             :     friend class PlotCanvas;
      65             :     friend class PlotMouseToolGroup;
      66             :     
      67             : public:
      68             :     // Constructor which takes which coordinate system events should be
      69             :     // processed in.
      70             :     PlotTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
      71             :     
      72             :     // Constructor which takes the two axes and the coordinate system which
      73             :     // events should be processed in.
      74             :     PlotTool(PlotAxis xAxis, PlotAxis yAxis,
      75             :             PlotCoordinate::System sys = PlotCoordinate::WORLD);
      76             :     
      77             :     // Destructor.
      78             :     virtual ~PlotTool();
      79             :     
      80             :     
      81             :     // Returns whether this tool is currently active or not.
      82             :     virtual bool isActive() const;
      83             :     
      84             :     // Sets whether this tool is currently active or not.
      85             :     virtual void setActive(bool isActive = true);
      86             :     
      87             :     // Returns whether this tool is blocking or not.  When a PlotCanvas
      88             :     // encounters a blocking tool, it is expected to not send events to any
      89             :     // other handlers further in the chain.
      90             :     virtual bool isBlocking() const;
      91             :     
      92             :     // Sets whether this tool is blocking or not.
      93             :     virtual void setBlocking(bool blocking = true);
      94             :     
      95             :     // Gets the axes on which the tool operates.
      96             :     // <group>
      97             :     virtual PlotAxis getXAxis() const;
      98             :     virtual PlotAxis getYAxis() const;
      99             :     // </group>
     100             :     
     101             :     // Gets the coordinate system in which the tool wants to process events.
     102             :     // Events passed to this tool should use this coordinate system.
     103             :     virtual PlotCoordinate::System getCoordinateSystem() const;
     104             :     
     105             :     // Returns whether the last event was handled or not.  Mostly used for
     106             :     // blocking tools so that unused events can be passed along.
     107             :     virtual bool lastEventWasHandled() const;
     108             :     
     109             :     // Resets any internal state such as history/stacks.  Should be called by
     110             :     // the PlotCanvas when the state of the canvases changes (axes ranges,
     111             :     // adding/deleting items, etc.) and would thus invalidate tool states.
     112           0 :     virtual void reset() { }
     113             :     
     114             : 
     115             : 
     116             : protected:
     117             :     // Attached canvas (or NULL for none).
     118             :     PlotCanvas* m_canvas;
     119             :     
     120             :     // Factory for creating implementation-specific objects.
     121             :     PlotFactory* m_factory;
     122             :     
     123             :     // Whether this tool is active.
     124             :     bool m_active;
     125             :     
     126             :     // Whether this tool is blocking.
     127             :     bool m_blocking;
     128             :     
     129             :     // The tool axes.
     130             :     PlotAxis m_xAxis, m_yAxis;
     131             :     
     132             :     // The tool coordinate system.
     133             :     PlotCoordinate::System m_coordSystem;
     134             :     
     135             :     // Last event handled flag.
     136             :     bool m_lastEventHandled;
     137             :     
     138             :     
     139             :     // Returns the canvas this tool is attached to, or NULL for none.
     140             :     virtual PlotCanvas* canvas() const;
     141             :     
     142             :     // Returns a factory that can be used for generating
     143             :     // implementation-specific classes, or NULL for none.
     144             :     virtual PlotFactory* factory() const;
     145             :     
     146             :     // Returns true if this tool is attached to a canvas, false otherwise.
     147             :     virtual bool isAttached() const;
     148             :     
     149             :     // Attaches this tool to the given canvas.  Detaches from current canvas
     150             :     // if necessary.
     151             :     virtual void attach(PlotCanvas* canvas);
     152             :     
     153             :     // Detaches this tool from its canvas.
     154             :     virtual void detach();
     155             : };
     156             : 
     157             : typedef casacore::CountedPtr<PlotTool> PlotToolPtr;
     158             : 
     159             : 
     160             : 
     161             : 
     162             : // A PlotMouseTool is a specialization of PlotTool that handles all mouse
     163             : // events.  It is abstract, and combines all mouse event handling methods into
     164             : // one for convenience.
     165             : class PlotMouseTool : public virtual PlotTool,
     166             :                       public virtual PlotSelectEventHandler,
     167             :                       public virtual PlotClickEventHandler, 
     168             :                       public virtual PlotMousePressEventHandler,
     169             :                       public virtual PlotMouseReleaseEventHandler,
     170             :                       public virtual PlotMouseDragEventHandler,
     171             :                       public virtual PlotMouseMoveEventHandler,
     172             :                       public virtual PlotWheelEventHandler {
     173             : public:
     174             :     // Constructor which takes the tool's coordinate system.
     175           0 :     PlotMouseTool(PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
     176           0 :             PlotTool(coordSys) { }
     177             :     
     178             :     // Constructor which takes the tool's axes and coordinate system.
     179           0 :     PlotMouseTool(PlotAxis xAxis, PlotAxis yAxis,
     180             :             PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
     181           0 :             PlotTool(xAxis, yAxis, coordSys) { }
     182             :     
     183             :     // Destructor.
     184           0 :     virtual ~PlotMouseTool() { }
     185             : 
     186             : 
     187             :     // Event handling methods.
     188             :     // <group>
     189           0 :     virtual void handleSelect(const PlotSelectEvent& event) {
     190           0 :         handleMouseEvent(event); }
     191           0 :     virtual void handleClick(const PlotClickEvent& event) {
     192           0 :         handleMouseEvent(event); }
     193           0 :     virtual void handleMousePress(const PlotMousePressEvent& event) {
     194           0 :         handleMouseEvent(event); }
     195           0 :     virtual void handleMouseRelease(const PlotMouseReleaseEvent& event) {
     196           0 :         handleMouseEvent(event); }
     197           0 :     virtual void handleMouseDrag(const PlotMouseDragEvent& event) {
     198           0 :         handleMouseEvent(event); }
     199           0 :     virtual void handleMouseMove(const PlotMouseMoveEvent& event) {
     200           0 :         handleMouseEvent(event); }
     201           0 :     virtual void handleWheel(const PlotWheelEvent& event) {
     202           0 :         handleMouseEvent(event); }
     203             :     // </group>
     204             :     
     205             :     
     206             :     // ABSTRACT METHODS //
     207             :     
     208             :     // Handles the given mouse event.  Guaranteed to be one of the mouse
     209             :     // events (select, click, press, release, drag, move, wheel).  The
     210             :     // implementing class should also update the last event handled flag as
     211             :     // necessary.
     212             :     virtual void handleMouseEvent(const PlotEvent& event) = 0;
     213             : };
     214           0 : INHERITANCE_POINTER2(PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr)
     215             : 
     216             : 
     217             : 
     218             : 
     219             : 
     220             : 
     221             : ///////////////////////////
     222             : // CONCRETE TOOL CLASSES //
     223             : ///////////////////////////
     224             : 
     225             : 
     226             : 
     227             : 
     228             : // Was in PlotStandardMouseToolGroup, but needed here, so it can be  passed
     229             : // to setActiveTool, which needs it to adjust the Select tool to either work
     230             : // normal or as Subtraction tool.
     231             : 
     232             : // Enum for standard tools in group.
     233             : enum ToolCode {
     234             :     SELECT_TOOL,   
     235             :     SUBTRACT_TOOL,   
     236             :     ZOOM_TOOL, 
     237             :     PAN_TOOL, 
     238             :     FLAGALL_TOOL,
     239             :     NONE_TOOL
     240             : };
     241             :     
     242             : 
     243             : 
     244             : 
     245             : 
     246             : // A PlotSelectTool is a concrete subclass of PlotMouseTool that mainly handles
     247             : // select events.  Note that plotting implementations may wish to override
     248             : // this class with an implementation-specific version that may be more
     249             : // efficient.  PlotSelectTool is responsible for:
     250             : // 1) managing the select line (the line show while the user is click-dragging
     251             : //    to select a region on the canvas) and cursors,
     252             : // 2) keeping track of selected regions,
     253             : // 3) showing/hiding the regions on the canvas, and
     254             : // 4) notifying any interested classes whenever the selected regions changes.
     255             : class PlotSelectTool : public virtual PlotMouseTool {
     256             : public:
     257             :     // Constructor which takes the tool's coordinate system.
     258             :     PlotSelectTool(PlotCoordinate::System system = PlotCoordinate::WORLD);
     259             :     
     260             :     // Constructor which takes the tool's axes and coordinate system.
     261             :     PlotSelectTool(PlotAxis xAxis, PlotAxis yAxis,
     262             :                    PlotCoordinate::System system = PlotCoordinate::WORLD);
     263             :     
     264             :     // Destructor.
     265             :     virtual ~PlotSelectTool();
     266             :     
     267             :     // Adds the given notifier.  This object will be notified when the list
     268             :     // of selected regions changes (either by adding one from the mouse, or
     269             :     // clearing them).
     270             :     virtual void addNotifier(PlotSelectToolNotifier* notifier);
     271             :     
     272             :     // Sets the selection line to the given.
     273             :     // <group>
     274             :     virtual void setSelectLine(PlotLinePtr line);
     275             :     virtual void setSubtractLine(PlotLinePtr line);
     276             :     virtual void setSelectLine(bool on = true);
     277             :     // </group>
     278             :     
     279             :     // Sets the attributes for drawing selected regions.
     280             :     // <group>
     281             :     virtual void setDrawRects(bool on = true);
     282             :     virtual void setRectLine(PlotLinePtr line);
     283             :     virtual void setRectFill(PlotAreaFillPtr fill);
     284             :     // </group>
     285             :     
     286             :     // Selected regions.
     287             :     // <group>
     288             :     virtual unsigned int numSelectedRects() const;
     289             :     virtual void getSelectedRects( 
     290             :                 std::vector<double>& upperLeftXs,
     291             :                 std::vector<double>& upperLeftYs, 
     292             :                 std::vector<double>& lowerRightXs,
     293             :                 std::vector<double>& lowerRightYs,
     294             :                 PlotCoordinate::System system = PlotCoordinate::WORLD)  const;
     295             :     virtual std::vector<PlotRegion> getSelectedRects(
     296             :                 PlotCoordinate::System system = PlotCoordinate::WORLD)  const;
     297             :     virtual void clearSelectedRects();
     298             :     virtual int getSelectedRectCount();
     299             :     // </group>
     300             :     
     301             :     // Overrides PlotTool::setActive().
     302             :     virtual void setActive(bool active = true);
     303             :     
     304             :     // Implements PlotMouseTool::handleMouseEvent().
     305             :     virtual void handleMouseEvent(const PlotEvent& event);
     306             :     
     307             :     bool inSubtractionMode()      { return m_subtraction_mode; }
     308             : 
     309             : 
     310             : 
     311             :     bool m_subtraction_mode;
     312             : 
     313             : 
     314             : protected:
     315             :     // Notifiers.
     316             :     std::vector<PlotSelectToolNotifier*> m_notifiers;
     317             :     
     318             :     // Copy of selection line to set on the canvas, or NULL if none has been
     319             :     // set.
     320             :     PlotLinePtr m_selLine;
     321             :     PlotLinePtr m_subLine;
     322             :     
     323             :     // Whether or not to draw selected regions on the canvas.
     324             :     bool m_drawRects;
     325             :     
     326             :     // Line for drawing selected regions, or NULL if none has been set.
     327             :     PlotLinePtr m_rectLine;
     328             :     
     329             :     // Area fill for drawing selected regions, or NULL if none has been set.
     330             :     PlotAreaFillPtr m_rectFill;
     331             :     
     332             :     // Selected regions.
     333             :     std::vector<PlotShapeRectanglePtr> m_rects;
     334             :     
     335             : 
     336             :     
     337             :     // Overrides PlotTool::attach().
     338             :     virtual void attach(PlotCanvas* canvas);
     339             :     
     340             :     // Overrides PlotTool::detach().
     341             :     virtual void detach();
     342             : };
     343             : 
     344             : 
     345           0 : INHERITANCE_POINTER(PlotSelectTool, PlotSelectToolPtr, PlotMouseTool,
     346             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     347             : 
     348             : 
     349             : 
     350             : 
     351             : 
     352             : 
     353             : 
     354             : 
     355             : 
     356             : // A PlotZoomTool is a concrete subclass of PlotMouseTool that provides
     357             : // convenient zooming functionality.  Standard behavior is to zoom on a
     358             : // select event, go through the zoom stack on a wheel event, go to the zoom
     359             : // stack base on a right click, and zoom in 50% centered on a double-click.
     360             : // Note that plotting implementations may wish to override this class with an
     361             : // implementation-specific version that may be more efficient.  A PlotZoomTool
     362             : // is responsible for:
     363             : // 1) managing behavior described above,
     364             : // 2) managing a zoom stack,
     365             : // 3) managing the canvas's select line/cursor, and
     366             : // 3) notifying interested objects when the zoom changes.
     367             : class PlotZoomTool : public virtual PlotMouseTool {
     368             : public:
     369             :     // Constructor which takes the tool's coordinate system.
     370             :     PlotZoomTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
     371             :     
     372             :     // Constructor which takes the tool's axes and coordinate system.
     373             :     PlotZoomTool(PlotAxis xAxis, PlotAxis yAxis,
     374             :                  PlotCoordinate::System sys = PlotCoordinate::WORLD);
     375             :     
     376             :     // Destructor.
     377             :     virtual ~PlotZoomTool();
     378             :     
     379             :     // Adds the given notifier.  This object will be notified when the zoom
     380             :     // changes.
     381             :     virtual void addNotifier(PlotZoomToolNotifier* notifier);
     382             :     
     383             :     // Sets the selection line to the given.
     384             :     // <group>
     385             :     virtual void setSelectLine(PlotLinePtr line);
     386             :     virtual void setSelectLine(bool on = true);
     387             :     // </group>
     388             :     
     389             :     // Gets the zoom stack.
     390             :     virtual std::vector<PlotRegion> getZoomStack(PlotCoordinate::System sytem =
     391             :                                             PlotCoordinate::WORLD) const;
     392             :     
     393             :     // Gets the zoom stack index.
     394             :     virtual unsigned int getStackIndex() const;
     395             :     
     396             :     // Overrides PlotTool::setActive().
     397             :     virtual void setActive(bool active = true);
     398             :     
     399             :     // Implements PlotMouseTool::handleMouseEvent().
     400             :     virtual void handleMouseEvent(const PlotEvent& event);
     401             :     
     402             :     // Overrides PlotTool::reset().
     403             :     virtual void reset();
     404             :     
     405             : protected:
     406             :     // Notifiers.
     407             :     std::vector<PlotZoomToolNotifier*> m_notifiers;
     408             :     
     409             :     // Copy of canvas selection line, or NULL if none has been set.
     410             :     PlotLinePtr m_selLine;
     411             :     
     412             :     // Common canvas stack.
     413             :     PlotAxesStack* m_stack;
     414             :     
     415             :     
     416             :     // Overrides PlotTool::attach().
     417             :     virtual void attach(PlotCanvas* canvas);
     418             :     
     419             :     // Overrides PlotTool::detach().
     420             :     virtual void detach();
     421             :     
     422             :     // Notifies all registered listeners that the zoom has changed.
     423             :     virtual void notifyWatchers();
     424             : };
     425           0 : INHERITANCE_POINTER(PlotZoomTool, PlotZoomToolPtr, PlotMouseTool,
     426             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     427             : 
     428             : 
     429             : 
     430             : 
     431             : // A PlotPanTool is a concrete subclass of PlotMouseTool that provides
     432             : // convenient panning functionality.  Standard behavior is to pan the canvas
     433             : // on a drag event, go through the pan stack on a wheel event, and go to the
     434             : // pan stack base on a right click.  Note that plotting implementations may
     435             : // wish to override this class with an implementation-specific version that may
     436             : // be more efficient.  A PlotPanTool is responsible for:
     437             : // 1) managing behavior described above,
     438             : // 2) managing a pan stack,
     439             : // 3) managing the canvas's cursor, and
     440             : // 4) notifying interested objects when the pan changes.
     441             : class PlotPanTool : public virtual PlotMouseTool {
     442             : public:
     443             :     // Constructor which takes the tool's coordinate system.
     444             :     PlotPanTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
     445             :     
     446             :     // Constructor which takes the tool's axes and coordinate system.
     447             :     PlotPanTool(PlotAxis xAxis, PlotAxis yAxis,
     448             :                 PlotCoordinate::System sys = PlotCoordinate::WORLD);
     449             :     
     450             :     // Destructor.
     451             :     virtual ~PlotPanTool();
     452             :     
     453             :     // Adds the given notifier.  This object will be notified when the pan
     454             :     // changes.
     455             :     virtual void addNotifier(PlotPanToolNotifier* notifier);
     456             :     
     457             :     // Gets the pan stack.
     458             :     virtual std::vector<PlotRegion> getPanStack(PlotCoordinate::System system =
     459             :                                            PlotCoordinate::WORLD) const;
     460             :     
     461             :     // Gets the pan stack index.
     462             :     virtual unsigned int getStackIndex() const;
     463             :     
     464             :     // Overrides PlotTool::setActive().
     465             :     virtual void setActive(bool active = true);
     466             :     
     467             :     // Implements PlotMouseTool::handleMouseEvent().
     468             :     virtual void handleMouseEvent(const PlotEvent& event);
     469             :     
     470             :     // Overrides PlotTool::reset().
     471             :     virtual void reset();
     472             :     
     473             : protected:
     474             :     // Notifiers.
     475             :     std::vector<PlotPanToolNotifier*> m_notifiers;
     476             :     
     477             :     // Whether we're in dragging mode or not.
     478             :     bool m_inDraggingMode;
     479             :     
     480             :     // Last coordinate in dragging mode.
     481             :     PlotCoordinate m_lastCoord;
     482             :     
     483             :     // Common canvas stack.
     484             :     PlotAxesStack* m_stack;
     485             :     
     486             :     
     487             :     // Overrides PlotTool::attach().
     488             :     virtual void attach(PlotCanvas* canvas);
     489             :     
     490             :     // Overrides PlotTool::detach().
     491             :     virtual void detach();
     492             :     
     493             :     // Notifies all registered listeners that the pan has changed.
     494             :     virtual void notifyWatchers();
     495             : };
     496           0 : INHERITANCE_POINTER(PlotPanTool, PlotPanToolPtr, PlotMouseTool,
     497             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     498             : 
     499             : 
     500             : 
     501             : 
     502             : // A PlotTrackerTool is a concrete subclass of PlotMouseTool that provides
     503             : // convenient tracker functionality.  Note that plotting implementations may
     504             : // wish to override this class with an implementation-specific version that may
     505             : // be more efficient.  A PlotTrackerTool can:
     506             : // 1) show a label with the current position hovering over the mouse,
     507             : // 2) let an external class handle the tracking via notifications, or
     508             : // 3) both.
     509             : class PlotTrackerTool : public virtual PlotMouseTool {
     510             :     friend class PlotStandardMouseToolGroup; // Why is this necessary to access
     511             :                                              // attach() and detach()? >:(
     512             :     
     513             : public:
     514             :     // Static //
     515             :     
     516             :     // Returns a casacore::String for the given position in the given format, with the
     517             :     // given canvas and axes.
     518             :     static casacore::String formattedString(const casacore::String& format, double x, double y,
     519             :                        PlotCanvas* canvas, PlotAxis xAxis, PlotAxis yAxis);
     520             :     
     521             :     
     522             :     // Non-Static //
     523             :     
     524             :     // Constructor which takes the tool's coordinate system.
     525             :     PlotTrackerTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
     526             :         
     527             :     // Constructor which takes the tool's axes and coordinate system.
     528             :     PlotTrackerTool(PlotAxis xAxis, PlotAxis yAxis,
     529             :                     PlotCoordinate::System sys = PlotCoordinate::WORLD);
     530             :     
     531             :     // Destructor.
     532             :     virtual ~PlotTrackerTool();
     533             :     
     534             :     // Adds the given notifier.  This object will be notified when the tracker
     535             :     // changes (and a new coordinate is ready for display).
     536             :     virtual void addNotifier(PlotTrackerToolNotifier* notifier);
     537             :     
     538             :     // Returns true if the tracker text is drawn on the canvas, false otherwise.
     539             :     virtual bool drawsText() const;
     540             :     
     541             :     // Sets whether the tracker will draw the text on the canvas or not.
     542             :     virtual void setDrawText(bool draw = true);
     543             :     
     544             :     // Sets the tracker text format to the given.  The following tags can be
     545             :     // used in the format:
     546             :     // * %%x%% : x value
     547             :     // * %%y%% : y values
     548             :     // * %%pX%% : sets the precision to X for any following numbers.
     549             :     // NOTICE: if the x or y value is a date, the date format set on the
     550             :     // canvas this tool is attached to will be used to display the value.
     551             :     // Default format is "(%%x%%, %%y%%)".
     552             :     virtual void setFormat(const casacore::String& format);
     553             :     
     554             :     // Returns the formatted tracker text for the given position.
     555           0 :     virtual casacore::String formattedString(double x, double y) {
     556           0 :         return formattedString(m_format, x, y, m_canvas, m_xAxis, m_yAxis); }
     557             :     
     558             :     // Returns the annotation used to store the coordinates/text.
     559             :     virtual PlotAnnotationPtr getAnnotation();
     560             :     
     561             :     // Gets the tracker's current position.
     562             :     virtual PlotCoordinate getCoordinate(PlotCoordinate::System =
     563             :                                          PlotCoordinate::WORLD) const;
     564             :     
     565             :     // Overrides PlotTool::setActive().
     566             :     virtual void setActive(bool active = true);
     567             :     
     568             :     // Implements PlotMouseTool::handleMouseEvent().
     569             :     virtual void handleMouseEvent(const PlotEvent& event);
     570             :     
     571             :     int getSelectedRectCount() const;
     572             :     std::vector<PlotRegion> getSelectedRects() const;
     573             : 
     574             : protected:
     575             :     // Notifiers.
     576             :     std::vector<PlotTrackerToolNotifier*> m_notifiers;
     577             :     
     578             :     // Annotation that holds current position (even if not drawn on canvas).
     579             :     PlotAnnotationPtr m_annotation;
     580             :     
     581             :     // Whether to draw the annotation or not.
     582             :     bool m_drawText;
     583             :     
     584             :     // Tracker text format.
     585             :     casacore::String m_format;
     586             :     
     587             :     // Overrides PlotTool::attach().
     588             :     virtual void attach(PlotCanvas* canvas);
     589             :     
     590             :     // Overrides PlotTool::detach().
     591             :     virtual void detach();
     592             :     
     593             :     // Notifies all registered listeners that the tracker has changed.
     594             :     virtual void notifyWatchers();
     595             :     
     596             :     
     597             :     // Static //
     598             :     
     599             :     // casacore::Format constants.
     600             :     // <group>
     601             :     static const casacore::String FORMAT_DIVIDER;
     602             :     static const casacore::String FORMAT_X, FORMAT_Y;
     603             :     static const casacore::String FORMAT_PRECISION;
     604             :     static const casacore::String DEFAULT_FORMAT;
     605             :     // </group>
     606             : };
     607           0 : INHERITANCE_POINTER(PlotTrackerTool, PlotTrackerToolPtr, PlotMouseTool,
     608             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     609             : 
     610             : 
     611             : // A PlotFlagAllTool is a concrete subclass of PlotMouseTool that handles
     612             : // one-click data flag functionality.
     613             : // PlotFlagAllTool is responsible for:
     614             : // 1) the behavior described above
     615             : class PlotFlagAllTool : public virtual PlotMouseTool {
     616             : public:
     617             :     // enum for canvas state
     618             :     enum PPFlagType {
     619             :       PPFLAG_FLAG,
     620             :       PPFLAG_UNFLAG,
     621             :       PPFLAG_NONE
     622             :     };
     623             : 
     624             :     // Constructor which takes the tool's coordinate system.
     625             :     PlotFlagAllTool(PlotCoordinate::System system = PlotCoordinate::WORLD);
     626             : 
     627             :     // Constructor which takes the tool's axes and coordinate system.
     628             :     PlotFlagAllTool(PlotAxis xAxis, PlotAxis yAxis,
     629             :                    PlotCoordinate::System system = PlotCoordinate::WORLD);
     630             : 
     631             :     // Destructor.
     632             :     virtual ~PlotFlagAllTool();
     633             : 
     634             :     // Implements PlotMouseTool::handleMouseEvent().
     635             :     virtual void handleMouseEvent(const PlotEvent& event);
     636             : 
     637             :     // Sets the attributes for updating background
     638             :     virtual void setUpdateBackground(bool on = true);
     639             : 
     640             :     // Inquiry if update of background is active
     641             :     virtual bool isUpdateBackgroundActive();
     642             : 
     643             :     // Manipulate mark
     644             :     void clearMark();
     645             : 
     646             :     // Inquiry if it is marked
     647             :     bool isMarkedForFlag() const;
     648             :     bool isMarkedForUnflag() const;
     649             : 
     650             :     // Inquiry if bgcolor is changed
     651             :     bool isBackgroundColorChanged() const;
     652             : 
     653             :     //
     654             :     void setAllFlagged();
     655             : 
     656             : protected:
     657             :     // boolean flag for whether update of background is active
     658             :     bool m_draw;
     659             : 
     660             :     // boolean flag for background color
     661             :     bool m_bgcolor_changed;
     662             : 
     663             :     // boolean flag for whether canvas is marked for flag
     664             :     PlotFlagAllTool::PPFlagType m_marked;
     665             : 
     666             :     // keep default background setting
     667             :     PlotAreaFillPtr m_defaultBackground;
     668             : 
     669             : private:
     670             :     // internal methods for shared operations
     671             :     void markAsFlag();
     672             :     void markAsUnflag();
     673             : 
     674             : };
     675           0 : INHERITANCE_POINTER(PlotFlagAllTool, PlotFlagAllToolPtr, PlotMouseTool,
     676             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     677             : 
     678             : 
     679             : ///////////////////////////////
     680             : // TOOL NOTIFICATION CLASSES //
     681             : ///////////////////////////////
     682             : 
     683             : 
     684             : // Interface for objects that want to be notified when the selection tool
     685             : // changes.
     686             : class PlotSelectToolNotifier {
     687             :     friend class PlotSelectTool;
     688             :     
     689             : public:
     690             :     PlotSelectToolNotifier() { }
     691             :     virtual ~PlotSelectToolNotifier() { }
     692             :     
     693             : protected:
     694             :     // This method is called AFTER the selection has been added.
     695             :     virtual void notifySelectionAdded(PlotSelectTool& tool) = 0;
     696             : };
     697             : 
     698             : 
     699             : // Interface for objects that want to be notified when the zoom tool
     700             : // changes.
     701             : class PlotZoomToolNotifier {
     702             :     friend class PlotZoomTool;
     703             :     
     704             : public:
     705             :     PlotZoomToolNotifier() { }
     706             :     virtual ~PlotZoomToolNotifier() { }
     707             :     
     708             : protected:
     709             :     // This method is called AFTER the canvas has been zoomed.
     710             :     virtual void notifyZoomChanged(PlotZoomTool& tool) = 0;
     711             : };
     712             : 
     713             : 
     714             : // Interface for objects that want to be notified when the pan tool
     715             : // changes.
     716             : class PlotPanToolNotifier {
     717             :     friend class PlotPanTool;
     718             :     
     719             : public:
     720             :     PlotPanToolNotifier() { }
     721             :     virtual ~PlotPanToolNotifier() { }
     722             :     
     723             : protected:
     724             :     // This method is called AFTER the canvas has been panned.
     725             :     virtual void notifyPanChanged(PlotPanTool& tool) = 0;
     726             : };
     727             : 
     728             : 
     729             : // Interface for objects that want to be notified when the tracker tool
     730             : // changes.
     731             : class PlotTrackerToolNotifier {
     732             :     friend class PlotTrackerTool;
     733             :     
     734             : public:
     735             :     PlotTrackerToolNotifier() { }
     736             :     virtual ~PlotTrackerToolNotifier() { }
     737             :     
     738             : protected:
     739             :     // This method is called AFTER the tracker has been updated.
     740             :     virtual void notifyTrackerChanged(PlotTrackerTool& tool) = 0;
     741             : };
     742             : 
     743             : 
     744             : ////////////////////////
     745             : // TOOL GROUP CLASSES //
     746             : ////////////////////////
     747             : 
     748             : 
     749             : // A PlotMouseToolGroup provides an interface for a group of PlotMouseTools
     750             : // where only one (or none) is active at a time.
     751             : class PlotMouseToolGroup : public virtual PlotMouseTool {
     752             : public:
     753             :     // Constructor for empty group.
     754             :     PlotMouseToolGroup();
     755             :     
     756             :     // Destructor.
     757             :     virtual ~PlotMouseToolGroup();    
     758             :        
     759             :     // Returns the number of tools in the group.
     760             :     unsigned int numTools() const;    
     761             :     
     762             :     // Returns the tools in the group.
     763             :     std::vector<PlotMouseToolPtr> tools() const;
     764             :     
     765             :     // Adds the given tool to the group and returns its index.  If makeActive
     766             :     // is true, the given tool becomes the group's active tool.
     767             :     // Note (dec 2010): used to take 2nd arg, boolean, to make tool active.
     768             :     // This is confusing design.  Caller of addTool should just call  setActiveTool(tool)
     769             :     // after calling addTool() if it wants the tool to become active.
     770             :     // In practice, source code does not anywhere call addTool with make_active=true.
     771             :     unsigned int addTool(PlotMouseToolPtr tool);
     772             :     
     773             :     // Removes the given tool from the group, and returns true on success.
     774             :     // <group>
     775             :     bool removeTool(PlotMouseToolPtr tool);    
     776             :     bool removeTool(unsigned int index) { return removeTool(toolAt(index)); }
     777             :     // </group>
     778             :     
     779             :     // Returns the tool at the given index, or NULL for invalid.
     780             :     PlotMouseToolPtr toolAt(unsigned int index) const;
     781             :     
     782             :     // Returns the index of the given tool, or numTools() for invalid.
     783             :     unsigned int indexOf(PlotMouseToolPtr tool) const;
     784             :     
     785             :     // Returns true if the given tool is in this group, false otherwise.
     786             :     bool containsTool(PlotMouseToolPtr tool) const {
     787             :         return indexOf(tool) < m_tools.size(); }
     788             :     
     789             :     // Returns the currently active tool, or NULL for none.
     790             :     PlotMouseToolPtr activeTool() const { return m_activeTool; }
     791             :     
     792             :     // Sets the active tool to the given.  If the given tool is not in the
     793             :     // group it is first added.
     794             :     // Toolcode is optional - meaningful only if tool has double usage, like
     795             :     // Select tool which doubles as the Subtraction tool.  Otherwise, just stuff NONE_TOOL
     796             :     // in for that arg.
     797             :     void setActiveTool(PlotMouseToolPtr tool,  ToolCode toolcode=NONE_TOOL);
     798             :     
     799             :     // Sets the active tool to the one at the given index.
     800           0 :     void setActiveTool(unsigned int index, ToolCode c=NONE_TOOL)   { 
     801           0 :             setActiveTool(toolAt(index), c); 
     802           0 :             }
     803             :     
     804             :     // Overrides PlotTool::setActive().
     805             :     void setActive(bool isActive = true);
     806             :     
     807             :     // Overrides PlotTool::setBlocking().
     808             :     void setBlocking(bool blocking = true);    
     809             :     
     810             :     // Implements PlotMouseTool::handleMouseEvent().
     811             :     void handleMouseEvent(const PlotEvent& event);
     812             :     
     813             :     // Overrides PlotMouseTool's event handling methods.
     814             :     // <group>
     815             :     void handleSelect(const PlotSelectEvent& event);
     816             :     void handleClick(const PlotClickEvent& event);
     817             :     void handleMousePress(const PlotMousePressEvent& event);
     818             :     void handleMouseRelease(const PlotMouseReleaseEvent& event);
     819             :     void handleMouseDrag(const PlotMouseDragEvent& event);
     820             :     void handleMouseMove(const PlotMouseMoveEvent& event);
     821             :     void handleWheel(const PlotWheelEvent& event);
     822             :     // </group>
     823             :     
     824             :     // Overrides PlotTool::getXAxis().
     825             :     PlotAxis getXAxis() const;
     826             :     
     827             :     // Overrides PlotTool::getYAxis().
     828             :     PlotAxis getYAxis() const;
     829             :     
     830             :     // Overrides PlotTool::getCoordinateSystem().
     831             :     PlotCoordinate::System getCoordinateSystem() const;
     832             :     
     833             :     // Overrides PlotTool::lastEventWasHandled().
     834             :     bool lastEventWasHandled() const;
     835             :     
     836             :     // Overrides PlotTool::reset().
     837             :     void reset();
     838             :     
     839             : protected:
     840             :     // All tools.
     841             :     std::vector<PlotMouseToolPtr> m_tools;
     842             :     
     843             :     // Active tool (or NULL for no active tool).
     844             :     PlotMouseToolPtr m_activeTool;
     845             :     
     846             :     // Overrides PlotTool::attach().
     847             :     virtual void attach(PlotCanvas* canvas);
     848             :     
     849             :     // Overrides PlotTool::detach().
     850             :     virtual void detach();
     851             : };
     852           0 : INHERITANCE_POINTER(PlotMouseToolGroup, PlotMouseToolGroupPtr, PlotMouseTool,
     853             :                     PlotMouseToolPtr, PlotTool, PlotToolPtr)
     854             : 
     855             : 
     856             : // PlotStandardMouseToolGroup is a specialized PlotMouseToolGroup where the
     857             : // tools in the group are:
     858             : // 1) select,
     859             : // 2) zoom, and
     860             : // 3) pan.
     861             : // A tracker is also provided that is not in the group so that it can be active
     862             : // at the same time other tools are active.
     863             : class PlotStandardMouseToolGroup : public PlotMouseToolGroup {
     864             : public:
     865             :     // Static //
     866             :     
     867             :     // Non-Static //
     868             :     
     869             :     // Constructor which creates default tools with the given coordinate
     870             :     // system, and sets the active tool to the given.
     871             :     PlotStandardMouseToolGroup(ToolCode activeTool = NONE_TOOL,
     872             :             PlotCoordinate::System system = PlotCoordinate::WORLD);
     873             :     
     874             :     // Constructor which creates default tools with the given coordinate
     875             :     // system and axes, and sets the active tool to the given.
     876             :     PlotStandardMouseToolGroup(PlotAxis xAxis, PlotAxis yAxis,
     877             :             ToolCode activeTool = NONE_TOOL,
     878             :             PlotCoordinate::System system = PlotCoordinate::WORLD);
     879             :     
     880             :     // Constructor which uses the given tools (or creates default tools if the
     881             :     // given ones are invalid), and sets the active tool to the given.
     882             :     PlotStandardMouseToolGroup(PlotSelectToolPtr selectTool,
     883             :                                PlotZoomToolPtr zoomTool,
     884             :                                PlotPanToolPtr panTool,
     885             :                                PlotFlagAllToolPtr flagAllTool,
     886             :                                PlotTrackerToolPtr trackerTool,
     887             :                                ToolCode activeTool = NONE_TOOL);
     888             :     
     889             :     // Destructor.
     890             :     ~PlotStandardMouseToolGroup();
     891             :     
     892             :     // Gets/sets the active standard tool.
     893             :     // <group>
     894             :     void setActiveTool(ToolCode tool);
     895             :     ToolCode activeToolType() const;
     896             :     // </group>
     897             :     
     898             :     // Provides access to the tracker.
     899             :     // <group>
     900             :     void turnTracker(bool on);
     901             :     bool trackerIsOn() const;
     902             :     void turnTrackerDrawText(bool on);
     903             :     bool trackerDrawsText() const;
     904             :     // </group>
     905             :     
     906             :     int getSelectedRectCount();
     907             :     std::vector<PlotRegion> getSelectedRects();
     908             :     void clearSelectedRects();
     909             : 
     910             :     // methods related to per-panel flag mode
     911             :     void clearMark();
     912             :     bool isMarkedForFlag();
     913             :     bool isMarkedForUnflag();
     914             :     bool isBackgroundColorChanged();
     915             :     void setAllFlagged();
     916             : 
     917             :     // Provides access to the individual tools.  Note: this should be avoided
     918             :     // if possible.
     919             :     // <group>
     920             :     PlotSelectToolPtr selectTool();
     921             :     PlotZoomToolPtr zoomTool();
     922             :     PlotPanToolPtr panTool();
     923             :     PlotFlagAllToolPtr flagAllTool();
     924             :     PlotTrackerToolPtr trackerTool();
     925             :     // </group>
     926             :     
     927             :     // Overrides PlotMouseToolGroup handler methods to give events to the
     928             :     // tracker first.
     929             :     // <group>
     930           0 :     void handleMouseEvent(const PlotEvent& event) {
     931           0 :         if(m_tracker->isActive()) m_tracker->handleMouseEvent(event);
     932           0 :         PlotMouseToolGroup::handleMouseEvent(event); }
     933             :         
     934           0 :     void handleSelect(const PlotSelectEvent& event) {
     935           0 :         if(m_tracker->isActive()) m_tracker->handleSelect(event);
     936           0 :         PlotMouseToolGroup::handleSelect(event); }
     937             :         
     938           0 :     void handleClick(const PlotClickEvent& event) {
     939           0 :         if(m_tracker->isActive()) m_tracker->handleClick(event);
     940           0 :         PlotMouseToolGroup::handleClick(event); }
     941             :         
     942           0 :     void handleMousePress(const PlotMousePressEvent& event) {
     943           0 :         if(m_tracker->isActive()) m_tracker->handleMousePress(event);
     944           0 :         PlotMouseToolGroup::handleMousePress(event); }
     945             :         
     946           0 :     void handleMouseRelease(const PlotMouseReleaseEvent& event) {
     947           0 :         if(m_tracker->isActive()) m_tracker->handleMouseRelease(event);
     948           0 :         PlotMouseToolGroup::handleMouseRelease(event); }
     949             :         
     950           0 :     void handleMouseDrag(const PlotMouseDragEvent& event) {
     951           0 :         if(m_tracker->isActive()) m_tracker->handleMouseDrag(event);
     952           0 :         PlotMouseToolGroup::handleMouseDrag(event); }
     953             :         
     954           0 :     void handleMouseMove(const PlotMouseMoveEvent& event) {
     955           0 :         if(m_tracker->isActive()) m_tracker->handleMouseMove(event);
     956           0 :         PlotMouseToolGroup::handleMouseMove(event); }
     957             :         
     958           0 :     void handleWheel(const PlotWheelEvent& event) {
     959           0 :         if(m_tracker->isActive()) m_tracker->handleWheel(event);
     960           0 :         PlotMouseToolGroup::handleWheel(event); }
     961             :     // </group>
     962             :     
     963             : protected:
     964             :     // Overrides PlotMouseToolGroup::attach().
     965             :     void attach(PlotCanvas* canvas);
     966             :     
     967             :     // Overrides PlotMouseToolGroup::detach().
     968             :     void detach();
     969             :     
     970             : private:
     971             :     // Tracker.
     972             :     PlotTrackerToolPtr m_tracker;
     973             : };
     974           0 : INHERITANCE_POINTER(PlotStandardMouseToolGroup, PlotStandardMouseToolGroupPtr,
     975             :                     PlotMouseToolGroup, PlotMouseToolGroupPtr,
     976             :                     PlotTool, PlotToolPtr)
     977             : 
     978             : }
     979             : 
     980             : #endif /* PLOTTOOL_H_ */

Generated by: LCOV version 1.16