DDDObject.h

Go to the documentation of this file.
00001 //# DDDObject.h: base object interface for DrawingDisplayData
00002 //# Copyright (C) 1999,2000,2001,2002
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 
00028 #ifndef TRIALDISPLAY_DDDOBJECT_H
00029 #define TRIALDISPLAY_DDDOBJECT_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Containers/Record.h>
00033 #include <casa/Containers/Block.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <display/Display/DisplayEnums.h>
00036 #include <display/DisplayEvents/WCRefreshEH.h>
00037 #include <display/DisplayEvents/WCMotionEH.h>
00038 #include <display/DisplayEvents/WCPositionEH.h>
00039 #include <display/DisplayDatas/DDDHandle.h>
00040 
00041 namespace casa { //# NAMESPACE CASA - BEGIN
00042 
00043         class WorldCanvas;
00044         class WCPositionEvent;
00045         class DrawingDisplayData;
00046 
00047 
00048 // <summary>
00049 // Base class describing interface for objects supported by DrawingDisplayData
00050 // </summary>
00051 
00052 // <synopsis>
00053 // This class defines the interface which objects that are drawable
00054 // by the DrawingDisplayData class must provide.
00055 //
00056 // World units of 'pix' and 'frac' are defined.  'pix' units are in
00057 // screen pixel units.  They are not very useful once the display
00058 // has been zoomed.  'frac' units have range [0,0] -> [1,1]
00059 // mapping to the display part of the pixel canvas.
00060 // </synopsis>
00061 
00062         class DDDObject : public WCRefreshEH, public WCMotionEH,
00063                 public WCPositionEH {
00064 
00065         public:
00066 
00067                 enum Mode {
00068                     None,
00069                     Handle,
00070                     Move,
00071                     Rotate
00072                 };
00073 
00074                 // Constructor taking a Record description.  Fields in the record
00075                 // are: <src>color</src> and <src>label</src>.
00076                 DDDObject(const Record &description, DrawingDisplayData *owner);
00077 
00078                 // Destructor.
00079                 virtual ~DDDObject();
00080 
00081                 // Draw this DrawingDisplayData object for the given reason on the
00082                 // provided WorldCanvas.
00083                 virtual void draw(const Display::RefreshReason &reason,
00084                                   WorldCanvas *worldcanvas) = 0;
00085 
00086                 // Indicate whether the object should show its handles or not.  The
00087                 // parent DrawingDisplayData will control this, and either ask all
00088                 // DDDObjects to show their handles or not, via the user setting an
00089                 // option.  This actually controls the state of whether this
00090                 // DDDObject is editable, so the parent DrawingDisplayData could
00091                 // also allow editing of only one DDDObject at a time.
00092                 virtual void showHandles(const Bool show, const Bool tellOwner = True);
00093 
00094                 // Query whether the object is showing its handles.
00095                 virtual Bool showingHandles() {
00096                         return itsShowHandles;
00097                 }
00098 
00099                 // Return a record describing this object.
00100                 virtual Record description();
00101 
00102                 // Update this object based on the information in the provided
00103                 // Record.
00104                 virtual void setDescription(const Record &rec);
00105 
00106                 // Store a click in the buffer and look for a double-click event.
00107                 // If one is found, then call the doubleClick function in the
00108                 // owning DisplayData.  Returns <src>True</src> if a double click
00109                 // was detected.
00110                 virtual Bool storeClick(const DisplayEvent &ev);
00111 
00112                 // Clear the click buffer.
00113                 virtual void clearClickBuffer();
00114 
00115                 // Return the unique id of this object.
00116                 Int objectID() const {
00117                         return itsObjectID;
00118                 }
00119 
00120                 // Event handlers.  The parent DrawingDisplayData will distribute
00121                 // events as necessary to the various DDDObjects which comprise it.
00122                 // <group>
00123                 virtual void operator()(const WCRefreshEvent &ev) = 0;
00124                 virtual void operator()(const WCPositionEvent &ev) = 0;
00125                 virtual void operator()(const WCMotionEvent &ev) = 0;
00126                 // </group>
00127 
00128         protected:
00129 
00130                 // Return the owner of this object.
00131                 DrawingDisplayData *owner() {
00132                         return itsOwner;
00133                 }
00134 
00135                 // Return the color to use to draw this object.
00136                 String color() const {
00137                         return itsColor;
00138                 }
00139 
00140                 // Return the label of this object.
00141                 String label() const {
00142                         return itsLabel;
00143                 }
00144 
00145                 // Return the line width of this object.
00146                 Int lineWidth() const {
00147                         return itsLineWidth;
00148                 }
00149 
00150                 Bool isEditable() const {
00151                         return itsEditable;
00152                 }
00153 
00154                 Bool isMovable() const {
00155                         return itsMovable;
00156                 }
00157 
00158                 Bool isFixed() const {
00159                         return !itsMovable && !itsEditable;
00160                 }
00161 
00162                 // (Required) default constructor.
00163                 DDDObject();
00164 
00165                 // (Required) copy constructor.
00166                 DDDObject(const DDDObject &other);
00167 
00168                 // (Required) copy assignment.
00169                 void operator=(const DDDObject &other);
00170 
00171                 // Translate Matrix
00172                 void translateMatrix(Matrix<Double>& points, Double dx, Double dy);
00173 
00174                 // Rotate Matrix
00175                 Matrix<Double> rotateMatrix(const Matrix<Double>& points, Double angle);
00176 
00177                 // Is point inside the polygon
00178                 // <group>
00179                 Bool inPolygon(const Matrix<Double>& points, Double x, Double y);
00180                 Bool inPolygon(const Vector<Double>& xP, const Vector<Double>& yP,
00181                                Double x, Double y);
00182                 // </group>
00183 
00184                 // Convert DisplayCoordinateSystem to screen pixels
00185                 void convertCoordinateSystem (DisplayCoordinateSystem& cSys, WorldCanvas* wcPtr) const;
00186 
00187                 // Is the point on a handle
00188                 Bool onHandle(const Block<DDDHandle>& handles,
00189                               Double x, Double y);
00190 
00191         private:
00192 
00193                 // DrawingDisplayData which owns this DDDObject.
00194                 DrawingDisplayData *itsOwner;
00195 
00196                 // Whether the handles are showing, and therefore whether this
00197                 // DDDObject is presently editable.
00198                 Bool itsShowHandles;
00199 
00200                 // Is this object editable
00201                 Bool itsEditable;
00202                 // Is it movable
00203                 Bool itsMovable;
00204 
00205                 // Timing for double clicks.
00206                 Double itsLastClickTime, its2ndLastClickTime;
00207 
00208                 // Color of this object.
00209                 String itsColor;
00210 
00211                 // Line width of the lines drawn
00212                 Int itsLineWidth;
00213 
00214                 // Label for this object.
00215                 String itsLabel;
00216 
00217                 // Unique identification for this object.
00218                 Int itsObjectID;
00219 
00220         };
00221 
00222 
00223 } //# NAMESPACE CASA - END
00224 
00225 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1