casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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   // Return a record describing this object.
00099   virtual Record description();
00100 
00101   // Update this object based on the information in the provided
00102   // Record.
00103   virtual void setDescription(const Record &rec);
00104 
00105   // Store a click in the buffer and look for a double-click event.
00106   // If one is found, then call the doubleClick function in the 
00107   // owning DisplayData.  Returns <src>True</src> if a double click
00108   // was detected.
00109   virtual Bool storeClick(const DisplayEvent &ev);
00110 
00111   // Clear the click buffer.
00112   virtual void clearClickBuffer();
00113 
00114   // Return the unique id of this object.
00115   Int objectID() const
00116     { return itsObjectID; }
00117 
00118   // Event handlers.  The parent DrawingDisplayData will distribute
00119   // events as necessary to the various DDDObjects which comprise it.
00120   // <group>
00121   virtual void operator()(const WCRefreshEvent &ev) = 0;
00122   virtual void operator()(const WCPositionEvent &ev) = 0;
00123   virtual void operator()(const WCMotionEvent &ev) = 0;
00124   // </group>
00125   
00126  protected:
00127 
00128   // Return the owner of this object.
00129   DrawingDisplayData *owner()
00130     { return itsOwner; }
00131 
00132   // Return the color to use to draw this object.
00133   String color() const
00134     { return itsColor; }
00135 
00136   // Return the label of this object.
00137   String label() const
00138   { return itsLabel; }
00139 
00140   // Return the line width of this object.
00141   Int lineWidth() const
00142   { return itsLineWidth; }
00143 
00144   Bool isEditable() const
00145   { return itsEditable; }
00146 
00147   Bool isMovable() const
00148   { return itsMovable; }
00149 
00150   Bool isFixed() const
00151   { return !itsMovable && !itsEditable; }
00152 
00153   // (Required) default constructor.
00154   DDDObject();
00155   
00156   // (Required) copy constructor.
00157   DDDObject(const DDDObject &other);
00158 
00159   // (Required) copy assignment.
00160   void operator=(const DDDObject &other);
00161 
00162   // Translate Matrix
00163   void translateMatrix(Matrix<Double>& points, Double dx, Double dy);
00164 
00165   // Rotate Matrix
00166   Matrix<Double> rotateMatrix(const Matrix<Double>& points, Double angle);
00167 
00168   // Is point inside the polygon
00169   // <group>
00170   Bool inPolygon(const Matrix<Double>& points, Double x, Double y);
00171   Bool inPolygon(const Vector<Double>& xP, const Vector<Double>& yP,
00172                  Double x, Double y);
00173   // </group>
00174 
00175   // Convert CoordinateSystem to screen pixels
00176   void convertCoordinateSystem (CoordinateSystem& cSys, WorldCanvas* wcPtr) const;
00177 
00178   // Is the point on a handle
00179   Bool onHandle(const Block<DDDHandle>& handles,
00180                 Double x, Double y);
00181 
00182  private:
00183 
00184   // DrawingDisplayData which owns this DDDObject.
00185   DrawingDisplayData *itsOwner;
00186 
00187   // Whether the handles are showing, and therefore whether this
00188   // DDDObject is presently editable.
00189   Bool itsShowHandles;
00190 
00191   // Is this object editable
00192   Bool itsEditable;
00193   // Is it movable
00194   Bool itsMovable;
00195 
00196   // Timing for double clicks.
00197   Double itsLastClickTime, its2ndLastClickTime;
00198 
00199   // Color of this object.
00200   String itsColor;
00201 
00202   // Line width of the lines drawn
00203   Int itsLineWidth;
00204 
00205   // Label for this object.
00206   String itsLabel;
00207 
00208   // Unique identification for this object.
00209   Int itsObjectID;
00210 
00211 };
00212 
00213 
00214 } //# NAMESPACE CASA - END
00215 
00216 #endif