casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DDDEllipse.h
Go to the documentation of this file.
00001 //# DDDEllipse.h: declaration of ellipse DDDObject
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 
00029 #ifndef TRIALDISPLAY_DDDELLIPSE_H
00030 #define TRIALDISPLAY_DDDELLIPSE_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <casa/Containers/Record.h>
00036 #include <casa/Containers/Block.h> 
00037 #include <casa/Logging/LogIO.h>
00038 #include <casa/Quanta/Quantum.h>
00039 #include <casa/Quanta/Unit.h>
00040 #include <coordinates/Coordinates/CoordinateSystem.h>
00041 #include <display/DisplayDatas/DDDObject.h>
00042 #include <display/DisplayDatas/DDDHandle.h>
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 class LogIO;
00047 class DisplayEvent;
00048 
00049 // <summary>
00050 // Implementation of an ellipse/rectangle object for DrawingDisplayData class.
00051 // </summary>
00052 
00053 // <synopsis>
00054 // This class implements the interface defined by DDDObject, to provide
00055 // an ellipse or rectangle object for registration with DrawingDisplayData objects.
00056 // The widths are all full widths.  
00057 // </synopsis>
00058 //
00059 // <todo>
00060 // Create a drawEllipse function on the world canvas and move
00061 // intelligence from here to there.
00062 // </todo>
00063 //
00064 
00065 class DDDEllipse : public DDDObject {
00066 
00067  public:
00068 
00069   // Constructor taking a Record description.  Fields in the record,
00070   // on top of what is consumed by the DDDObject constructor, are:
00071   // Required : <src>center</src> (vector of quanta length 2),
00072   // <src>major, minor, positionangle</src> (all quanta).  
00073   //
00074   // Units 'frac' ([0->1]) are available for the center only.
00075   // Units 'pix' (absolute 0-rel image pixels) are available for the 
00076   // major and minor only.
00077   //
00078   // Other, not required fields are <src>outline & editable</src>
00079   // which default to <src>True</src>.  When <src>editable=False</src>
00080   // the object can be moved but not reshaped, when <src>True</src>   
00081   // it can be moved and reshaped.   When   <src>outline=False</src> 
00082   // the ellipse is filled.   If the field <src>rectangle=True</src>
00083   // a rectangle is drawn. If it does not exist or is False, an ellipse
00084   // is drawn.
00085   //
00086   // Finally, field <src>doreference</src> which defaults to <src>False</src>
00087   // is used to control the location at which conversions to and from
00088   // pixel coordinates are done.  If <src>True</src> then all conversions
00089   // are done at the reference value. Otherwise, the conversions are 
00090   // done at the actual location of the shape.  For example, with
00091   // a DirectionCoordinate plane, setting <src>doreference=True</src>
00092   // will cause the shape to rotate as you move it about the display
00093   // as the position angle tracks the local North.  
00094   DDDEllipse(const Record &description, DrawingDisplayData *owner);
00095 
00096   // Destructor.
00097   virtual ~DDDEllipse();
00098   
00099   // Draw this object for the given reason on the provided
00100   // WorldCanvas.
00101   virtual void draw(const Display::RefreshReason &reason, 
00102                     WorldCanvas *worldcanvas);
00103   
00104   // Return a record describing this object.  Presently returns
00105   // only construction description.
00106   virtual Record description();
00107 
00108   // Update this object based on the information in the provided
00109   // Record.
00110   virtual void setDescription(const Record &rec);
00111   
00112   // Event handlers.  The parent DrawingDisplayData will distribute
00113   // events as necessary to the various DDDObjects which comprise it.
00114   // <group>
00115   virtual void operator()(const WCRefreshEvent &ev);
00116   virtual void operator()(const WCPositionEvent &ev);
00117   virtual void operator()(const WCMotionEvent &ev);
00118   // </group>
00119 
00120  protected:
00121 
00122   // (Required) default constructor.
00123   DDDEllipse();
00124 
00125   // (Required) copy constructor.
00126   DDDEllipse(const DDDEllipse &other);
00127 
00128   // (Required) copy assignment.
00129   void operator=(const DDDEllipse &other);
00130 
00131  private:
00132 
00133 // Fill style
00134   Bool itsOutline;
00135 
00136 // Define center x, center y, major, minor, pa in world
00137   Vector<Quantum<Double> > itsWorldParameters;
00138 
00139 // Define center x, center y, major, minor, pa (radians) in screen pixel
00140   Vector<Double> itsPixelCenter, itsPixelShape;
00141 
00142 // Rotated Rectangle Corners to draw in screen pixel
00143   Matrix<Double> itsCorners;
00144   Matrix<Double> itsPixelOffsets;
00145 
00146 // List of handles
00147 
00148   Block<DDDHandle> itsHandles;
00149 
00150 // Mode.
00151 
00152   DDDObject::Mode itsMode;
00153 
00154 // Store for movement bases.
00155 
00156   Double itsBaseMoveX, itsBaseMoveY;
00157 
00158 // Logger
00159 
00160   LogIO itsLogger;
00161 
00162 // CoordinateSystem in screen pixel coordinates
00163   CoordinateSystem itsCoordinateSystem;
00164   
00165 // pointer to world canvas (shallow copy)
00166   WorldCanvas* itsWorldCanvasPtr;
00167 
00168 // are we drawing a rectangle or an ellipse ?
00169   Bool itsRectangle;
00170 
00171 // Fractional indicators
00172   Bool itsFracX, itsFracY;
00173 
00174 // Do world/pixel conversions at reference location ?
00175    Bool itsDoRef;
00176 
00177 // COnvert parameters from world to pixel
00178    void convertToPixel ();
00179 
00180 // Update private world parameters from current pixel values
00181    void updateWorldValues ();
00182 
00183 // Decode record into private data
00184 
00185    void decode(const RecordInterface& description, Bool required);
00186 
00187 // Encode private data into record
00188    void encode(RecordInterface& description) const;
00189 
00190 // compute corners of rectangle
00191   void createCorners();
00192 
00193   Matrix<Int> toIntPixel(const Matrix<Double>& points);
00194 
00195 // Debugging routines
00196 
00197    void listWorld();
00198    void listPixel();
00199 
00200 };
00201 
00202 
00203 } //# NAMESPACE CASA - END
00204 
00205 #endif