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 
00086                 // Default constructor. Creates shape with default options set
00087                 DisplayShape();
00088                 // Copy constructor
00089                 DisplayShape(const DisplayShape& other);
00090                 // Destructor
00091                 virtual ~DisplayShape();
00092 
00093                 // These functions contol behaviour of handles during a call
00094                 // to the display shape object.
00095                 // (These calls should be propogated up through the class tree).
00096                 // <group>
00097                 virtual void draw(PixelCanvas* pc);
00098                 virtual void rotateAbout(const Float& relAngle, const Float& aboutX,
00099                                          const Float& aboutY) ;
00100                 virtual void move(const Float& dX, const Float& dY);
00101                 // </group>
00102 
00103 
00104                 // Rotate the supplied polygon (column 1 - x values, column 2 - y values)
00105                 // about the supplied point by the supplied angle. NB Angle in radians
00106                 virtual Matrix<Float> rotatePolygon(const Matrix<Float>& toRotate,
00107                                                     const Float& angle,
00108                                                     const Float& aboutX,
00109                                                     const Float& aboutY);
00110 
00111                 // Rotates a point around the point specified. NB Angle in radians.
00112                 virtual Vector<Float> rotatePoint(const Vector<Float>& toRotate,
00113                                                   const Float& angle,
00114                                                   const Float& aboutX, const Float& aboutY);
00115 
00116                 // Translate an entire matrix by the specified dx / dy amounts.
00117                 virtual Matrix<Float> translateMatrix(const Matrix<Float>& points,
00118                                                       const Float& dx, const Float& dy);
00119 
00120                 // Is xPos, YPos inside the supplied points (column 1 - x values,
00121                 // clolumn 2 - y values)
00122                 virtual Bool inPolygon(const Matrix<Float>& points, const Float& xPos,
00123                                        const Float& yPos);
00124 
00125                 // Determine the two vertices (firstVert, secondVert) which join the line
00126                 // closest to the xPos, yPos point supplied. If closedPoly is left as
00127                 // true, the points supplied are treated as a polygon, if not as a poly
00128                 // line.
00129                 virtual Bool closestLine(const Matrix<Float>& points, const Float& xPos,
00130                                          const Float& yPos,
00131                                          Int& firstVert, Int& secondVert,
00132                                          const Bool& closedPoly = True);
00133 
00134                 // For a specified set of points, find the closest to xPos,YPos. out
00135                 // relates the matrix index (row number) of the closest point.
00136                 virtual Bool closestPoint(const Matrix<Float>& points,
00137                                           const Float& xPos, const Float& yPos,
00138                                           Int& out);
00139 
00140                 // Find the closest two Points from a Matrix to the specified point.
00141                 virtual Bool closestPoints(const Matrix<Float>& points,
00142                                            const Float& xPos, const Float& yPos,
00143                                            Int& outClosest, Int& outSecond);
00144 
00145                 // Is the supplied point within the DisplayShape?
00146                 virtual Bool inObject(const Float& xPos, const Float& yPos) = 0;
00147 
00148                 // Convert degrees to radians
00149                 virtual Float toRadians(const Float& degrees);
00150 
00151                 // Conver radians to degree
00152                 virtual Float toDegrees(const Float& radians);
00153 
00154                 // Sets the center of the DisplayShape
00155                 virtual void setCenter(const Float& xPos, const Float& yPos) = 0;
00156 
00157                 // Returns the center of the DisplayShape (x,y).
00158                 virtual Vector<Float> getCenter() = 0;
00159 
00160                 // Changes the closest point to the supplied location to that location
00161                 virtual void changePoint(const Vector<Float>& newPos) = 0;
00162 
00163                 // Changes the nth point making up the DisplayShape ot the specified
00164                 // location.
00165                 virtual void changePoint(const Vector<Float>& newPoint,
00166                                          const Int nPoint) = 0;
00167 
00168                 // If applicable, this function will add a point to the shape in the
00169                 // most meaningful location.
00170                 virtual void addPoint(const Vector<Float>& /*newPoint*/) { };
00171 
00172                 // Rotate the shape about its center by a set angle (angle in degrees).
00173                 virtual void rotate(const Float& angle) = 0;
00174 
00175                 // Scale the shape about its center by the scaleFactor
00176                 virtual void scale(const Float& scaleFactor) = 0;
00177 
00178                 // Allow locking of other shapes onto this one. When a shape is locked,
00179                 // if the current shape is moved, so to will the locked shape.
00180                 virtual void addLocked(DisplayShape* toLock);
00181 
00182                 // Removes a lock from the specified shape.
00183                 virtual void removeLocked(DisplayShape* removeLock);
00184 
00185                 // Handle management.
00186                 // <group>
00187                 virtual void buildHandles(const Matrix<Float>& startPoints);
00188                 virtual Matrix<Float> getHandleLocations();
00189                 virtual void setHandlePositions(const Matrix<Float>& newPoints);
00190                 virtual DSClosed*  makeHandle(const Vector<Float>& newHandlePos);
00191                 virtual void addHandle(const Vector<Float>& newHandlePos,
00192                                        const Bool& atEnd = True
00193                                                , const Int position = 0);
00194                 virtual Bool removeHandle(const Vector<Float>& getRidOf);
00195                 virtual Bool removeHandle(const Int nHandle);
00196 
00197                 virtual Bool onHandles(const Float& xPos, const Float& yPos);
00198                 virtual Bool whichHandle(const Float& xPos, const Float& yPos, Int& out);
00199 
00200                 virtual void setDrawHandles(const Bool& shouldIDraw);
00201                 virtual Bool drawingHandles() {
00202                         return itsDrawHandles;
00203                 }
00204                 virtual void setHasHandles(const Bool& hasHandles);
00205                 virtual void setHandleShape(const DisplayShape::HandleShape& shape);
00206                 virtual void setHandleSize(const Int pixelSize);
00207                 virtual void setHandleColor(const String& handleColor);
00208                 virtual uInt nHandles();
00209                 // </group>
00210 
00211                 // Manage the color of object. (Does not include handles)
00212                 // <group>
00213                 virtual void setColor(const String& newColor);
00214                 virtual String getColor();
00215                 // </group>
00216 
00217                 // Settings
00218                 // <group>
00219                 virtual Record getOptions();
00220                 virtual Bool setOptions(const Record& settings);
00221                 // </group>
00222 
00223                 virtual void recalculateScreenPosition() {}
00224 
00225         private:
00226                 // Set default options
00227                 virtual void setDefaultOptions();
00228 
00229 
00230                 // Object
00231                 DParameterColorChoice* itsColor;
00232 
00233                 // Handles
00234                 PtrBlock<DSClosed*> itsHandles;
00235 
00236                 // Locks
00237                 PtrBlock<DisplayShape*> itsLocks;
00238 
00239                 // Do I have handles / can a user resize me?
00240                 // i.e. Do I *ever* want to draw handles (e.g. will be false for an object
00241                 //      which IS a handle!)
00242                 Bool itsHasHandles;
00243 
00244                 // Should handles be shown if they exist
00245                 Bool itsDrawHandles;
00246 
00247                 // Have valid handles been made/supplied yet?
00248                 Bool itsValidHandles;
00249 
00250                 // Handle settings
00251                 // <group>
00252                 String itsHandleColor;
00253                 DisplayShape::HandleShape itsHandleShape;
00254                 Int itsHandleSize;
00255                 // </group>
00256 
00257         };
00258 
00259 } //# NAMESPACE CASA - END
00260 
00261 #endif
00262 
00263 
00264 
00265 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1