casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DisplayShape.h
Go to the documentation of this file.
00001 //# DisplayShape.h: Abstract base class for all shapes/annotations objects
00002 //# Copyright (C) 1998,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_DISPLAYSHAPE_H
00029 #define TRIALDISPLAY_DISPLAYSHAPE_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Matrix.h> 
00033 #include <casa/Containers/Record.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 class DSShape;
00038 class DSClosed;
00039 class DisplayEnums;
00040 class PixelCanvas;
00041 class DParameterColorChoice;
00042 
00043 
00044 // <summary>
00045 // The abstract base class for all "DisplayShapes".
00046 // </summary>
00047 //
00048 // <prerequisite>
00049 // </prerequisite>
00050 //
00051 // <etymology>
00052 // DisplayShape is a way of providing a consistant interface to a large number
00053 // of different shapes.
00054 // </etymology>
00055 //
00056 // <synopsis>
00057 // DisplayShape provides a framework from which a large number of different 
00058 // shapes can be made, all with the same interface. Any new DisplayShape 
00059 // should inherit from this class, or higher level classes 
00060 // (see <linkto class="DSPoly">DSPoly</linkto> etc).
00061 //
00062 // There are generally two ways to make DisplayShape(s); To create them in 
00063 // "one hit" by providing arguments to the constructor, or by using the 
00064 // default constructor and then the "setOptions" method. A simple interface 
00065 // for all classes inheriting from the 
00066 // <linkto class="DisplayShape">DisplayShape</linkto> class is provided 
00067 // by <linkto class="DisplayShapeInterface">DisplayShapeInterface</linkto>.
00068 // </synopsis>
00069 //
00070 // <motivation>
00071 // A common interface to a large number of shapes was desired.
00072 // </motivation>
00073 //
00074 // <example>
00075 // </example>
00076 
00077 class DisplayShape {
00078 
00079 public:
00080   // Handle style
00081   enum HandleShape {Filled_Square=0, Open_Square, Filled_Circle, 
00082                     Open_Circle, Filled_Triangle, Open_Triangle};
00083   
00084  
00085   // Default constructor. Creates shape with default options set
00086   DisplayShape();
00087   // Copy constructor
00088   DisplayShape(const DisplayShape& other);
00089   // Destructor
00090   virtual ~DisplayShape();
00091 
00092   // These functions contol behaviour of handles during a call
00093   // to the display shape object.
00094   // (These calls should be propogated up through the class tree).
00095   // <group>
00096   virtual void draw(PixelCanvas* pc);
00097   virtual void rotateAbout(const Float& relAngle, const Float& aboutX, 
00098            const Float& aboutY) ;
00099   virtual void move(const Float& dX, const Float& dY);
00100   // </group>
00101 
00102 
00103   // Rotate the supplied polygon (column 1 - x values, column 2 - y values)
00104   // about the supplied point by the supplied angle. NB Angle in radians
00105   virtual Matrix<Float> rotatePolygon(const Matrix<Float>& toRotate, 
00106                                       const Float& angle,
00107                                       const Float& aboutX, 
00108                                       const Float& aboutY);
00109 
00110   // Rotates a point around the point specified. NB Angle in radians.
00111   virtual Vector<Float> rotatePoint(const Vector<Float>& toRotate, 
00112                                     const Float& angle,
00113                                     const Float& aboutX, const Float& aboutY);
00114 
00115   // Translate an entire matrix by the specified dx / dy amounts.
00116   virtual Matrix<Float> translateMatrix(const Matrix<Float>& points, 
00117                                         const Float& dx, const Float& dy);
00118 
00119   // Is xPos, YPos inside the supplied points (column 1 - x values, 
00120   // clolumn 2 - y values)
00121   virtual Bool inPolygon(const Matrix<Float>& points, const Float& xPos, 
00122                          const Float& yPos);
00123 
00124   // Determine the two vertices (firstVert, secondVert) which join the line
00125   // closest to the xPos, yPos point supplied. If closedPoly is left as
00126   // true, the points supplied are treated as a polygon, if not as a poly
00127   // line. 
00128   virtual Bool closestLine(const Matrix<Float>& points, const Float& xPos, 
00129                            const Float& yPos,
00130                            Int& firstVert, Int& secondVert, 
00131                            const Bool& closedPoly = True); 
00132 
00133   // For a specified set of points, find the closest to xPos,YPos. out
00134   // relates the matrix index (row number) of the closest point.
00135   virtual Bool closestPoint(const Matrix<Float>& points, 
00136                             const Float& xPos, const Float& yPos, 
00137                             Int& out);
00138 
00139   // Find the closest two Points from a Matrix to the specified point.
00140   virtual Bool closestPoints(const Matrix<Float>& points, 
00141                             const Float& xPos, const Float& yPos, 
00142                             Int& outClosest, Int& outSecond);
00143 
00144   // Is the supplied point within the DisplayShape?
00145   virtual Bool inObject(const Float& xPos, const Float& yPos) = 0;
00146 
00147   // Convert degrees to radians
00148   virtual Float toRadians(const Float& degrees);
00149 
00150   // Conver radians to degree
00151   virtual Float toDegrees(const Float& radians);
00152 
00153   // Sets the center of the DisplayShape
00154   virtual void setCenter(const Float& xPos, const Float& yPos) = 0;
00155 
00156   // Returns the center of the DisplayShape (x,y).
00157   virtual Vector<Float> getCenter() = 0;
00158 
00159   // Changes the closest point to the supplied location to that location
00160   virtual void changePoint(const Vector<Float>& newPos) = 0;
00161 
00162   // Changes the nth point making up the DisplayShape ot the specified
00163   // location.
00164   virtual void changePoint(const Vector<Float>& newPoint, 
00165                            const Int nPoint) = 0;
00166 
00167   // If applicable, this function will add a point to the shape in the
00168   // most meaningful location.
00169   virtual void addPoint(const Vector<Float>& /*newPoint*/) { };
00170 
00171   // Rotate the shape about its center by a set angle (angle in degrees).
00172   virtual void rotate(const Float& angle) = 0;
00173 
00174   // Scale the shape about its center by the scaleFactor
00175   virtual void scale(const Float& scaleFactor) = 0;
00176 
00177   // Allow locking of other shapes onto this one. When a shape is locked,
00178   // if the current shape is moved, so to will the locked shape.
00179   virtual void addLocked(DisplayShape* toLock);
00180 
00181   // Removes a lock from the specified shape.
00182   virtual void removeLocked(DisplayShape* removeLock);
00183 
00184   // Handle management. 
00185   // <group>
00186   virtual void buildHandles(const Matrix<Float>& startPoints);
00187   virtual Matrix<Float> getHandleLocations();
00188   virtual void setHandlePositions(const Matrix<Float>& newPoints);
00189   virtual DSClosed*  makeHandle(const Vector<Float>& newHandlePos);
00190   virtual void addHandle(const Vector<Float>& newHandlePos, 
00191                          const Bool& atEnd = True
00192                          , const Int position = 0); 
00193   virtual Bool removeHandle(const Vector<Float>& getRidOf);
00194   virtual Bool removeHandle(const Int nHandle);
00195 
00196   virtual Bool onHandles(const Float& xPos, const Float& yPos);
00197   virtual Bool whichHandle(const Float& xPos, const Float& yPos, Int& out);
00198 
00199   virtual void setDrawHandles(const Bool& shouldIDraw);
00200   virtual Bool drawingHandles() {
00201     return itsDrawHandles;
00202   }
00203   virtual void setHasHandles(const Bool& hasHandles);
00204   virtual void setHandleShape(const DisplayShape::HandleShape& shape);
00205   virtual void setHandleSize(const Int pixelSize);
00206   virtual void setHandleColor(const String& handleColor);
00207   virtual uInt nHandles();
00208   // </group>
00209 
00210   // Manage the color of object. (Does not include handles)
00211   // <group>
00212   virtual void setColor(const String& newColor);
00213   virtual String getColor();
00214   // </group>
00215 
00216   // Settings
00217   // <group>
00218   virtual Record getOptions();
00219   virtual Bool setOptions(const Record& settings);
00220   // </group>
00221   
00222   virtual void recalculateScreenPosition() {}
00223 
00224 private:
00225   // Set default options
00226   virtual void setDefaultOptions();
00227 
00228   
00229   // Object
00230   DParameterColorChoice* itsColor;
00231 
00232   // Handles
00233   PtrBlock<DSClosed*> itsHandles;
00234   
00235   // Locks
00236   PtrBlock<DisplayShape*> itsLocks;
00237 
00238   // Do I have handles / can a user resize me? 
00239   // i.e. Do I *ever* want to draw handles (e.g. will be false for an object 
00240   //      which IS a handle!) 
00241   Bool itsHasHandles;      
00242 
00243   // Should handles be shown if they exist 
00244   Bool itsDrawHandles;     
00245 
00246   // Have valid handles been made/supplied yet?
00247   Bool itsValidHandles;    
00248 
00249   // Handle settings
00250   // <group>
00251   String itsHandleColor;
00252   DisplayShape::HandleShape itsHandleShape;
00253   Int itsHandleSize;
00254   // </group>
00255 
00256 };
00257 
00258 } //# NAMESPACE CASA - END
00259 
00260 #endif
00261 
00262 
00263 
00264