casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotMSAnnotator.h
Go to the documentation of this file.
00001 //# PlotMSAnnotator.h: Annotator tool for PlotMS.
00002 //# Copyright (C) 2009
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 PLOTMSANNOTATOR_H_
00028 #define PLOTMSANNOTATOR_H_
00029 
00030 #include <graphics/GenericPlotter/PlotTool.h>
00031 #include <plotms/Actions/PlotMSAction.h>
00032 #include <plotms/Plots/PlotMSPlotManager.h>
00033 
00034 #include <QAction>
00035 
00036 #include <casa/namespace.h>
00037 
00038 namespace casa {
00039 
00040 //# Forward Declarations.
00041 class PlotMSApp;
00042 
00043 
00044 // Subclass of PlotMouseTool for drawing/managing annotations on the plot
00045 // canvases of PlotMSApp.
00046 class PlotMSAnnotator : public PlotMouseTool, public PlotMSPlotManagerWatcher {
00047     
00048     //# Friend class declarations.
00049     friend class PlotMSPlotter;
00050     
00051 public:
00052     // Static //
00053     
00054     // Drawing mode for the annotator.
00055     enum Mode {
00056         TEXT = 0,
00057         RECTANGLE = 1
00058     };
00059     
00060     
00061     // Non-Static //
00062     
00063     // Constructor which takes the PlotMS parent and optional starting mode.
00064     PlotMSAnnotator(PlotMSApp* parent, Mode startingMode = TEXT);
00065     
00066     // Destructor.
00067     ~PlotMSAnnotator();
00068     
00069     
00070     // Gets/Sets the current drawing mode.
00071     // <group>
00072     Mode drawingMode() const;
00073     void setDrawingMode(Mode mode);
00074     // </group>
00075     
00076     // Gets/Sets the current text properties (null means default for
00077     // PlotAnnotation object).  Only applies to future text annotations.
00078     // <group>
00079     PlotFontPtr textFont() const;
00080     void setTextFont(const PlotFontPtr font);
00081     PlotLinePtr textOutline() const;
00082     void setTextOutline(const PlotLinePtr outline);
00083     PlotAreaFillPtr textBackground() const;
00084     void setTextBackground(const PlotAreaFillPtr background);
00085     // </group>
00086     
00087     // Gets/Sets the current rectangle properties (null means default for
00088     // PlotShapeRectangle object).  Only applies to future rectangle
00089     // annotations.
00090     // <group>
00091     PlotLinePtr rectangleLine() const;
00092     void setRectangleLine(const PlotLinePtr line);
00093     PlotAreaFillPtr rectangleAreaFill() const;
00094     void setRectangleAreaFill(const PlotAreaFillPtr fill);
00095     // </group>
00096     
00097     // Clears all text/rectangle annotations off the given canvas.  If the
00098     // given canvas is NULL, then it clears them from all canvases.
00099     // <group>
00100     void clearText(PlotCanvas* canvas = NULL);
00101     void clearRectangles(PlotCanvas* canvas = NULL);
00102     void clearAll(PlotCanvas* canvas = NULL);
00103     // </group>
00104     
00105     
00106     // Overrides PlotTool::setActive().
00107     void setActive(bool isActive = true);
00108     
00109     // Implements PlotMouseTool::handleMouseEvent().
00110     void handleMouseEvent(const PlotEvent& event);
00111     
00112     // Implements PlotMSPlotManagerWatcher::plotChanged().  Removes annotations
00113     // that are attached to canvases that no longer exist.
00114     void plotsChanged(const PlotMSPlotManager& manager);
00115     
00116 protected:
00117     // Sets the annotate and mode actions and the factory to the given.  MUST
00118     // be called before the annotator is used.
00119     void setActions(QAction* annotateAction,
00120             const QMap<PlotMSAction::Type, QAction*>& actionMap,
00121             PlotFactoryPtr factory);
00122     
00123     // Overrides PlotTool::attach().
00124     void attach(PlotCanvas* canvas);
00125     
00126     // Overrides PlotTool::detach().
00127     void detach();
00128     
00129 private:
00130     // Parent.
00131     PlotMSApp* itsParent_;
00132     
00133     // Factory for generating plot objects.
00134     PlotFactoryPtr itsFactory_;
00135     
00136     // Current drawing mode.
00137     Mode itsMode_;
00138     
00139     // Actions to keep updated.
00140     // <group>
00141     QAction* itsAnnotateAction_;    
00142     QMap<Mode, QAction*> itsModeActions_;
00143     // </group>
00144     
00145     // Text annotations.
00146     QMultiMap<PlotCanvas*, PlotAnnotationPtr> itsAText_;
00147     
00148     // Current text properties.
00149     // <group>
00150     PlotFontPtr itsTextFont_;
00151     PlotLinePtr itsTextOutline_;
00152     PlotAreaFillPtr itsTextFill_;
00153     // </group>
00154     
00155     // Rectangle annotations.
00156     QMultiMap<PlotCanvas*, PlotShapeRectanglePtr> itsARect_;
00157     
00158     // Current rectangle properties.
00159     // <group>
00160     PlotLinePtr itsRectLine_;
00161     PlotAreaFillPtr itsRectFill_;
00162     // </group>
00163     
00164     
00165     // Sets properties to their defaults.
00166     void setDefaults();
00167 };
00168 
00169 }
00170 
00171 #endif /* PLOTMSANNOTATOR_QO_H_ */