casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DSArrow.h
Go to the documentation of this file.
00001 //# DSArrow.h: Arrow implementation for "DisplayShapes"
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_DSARROW_H
00029 #define TRIALDISPLAY_DSARROW_H
00030 
00031 #include <casa/aips.h>
00032 
00033 #include <display/DisplayShapes/DSLine.h> 
00034 #include <display/DisplayShapes/DSPoly.h>
00035 
00036 #include <casa/Arrays/Matrix.h>
00037 #include <casa/Arrays/Vector.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 class PixelCanvas;
00042 template <class T> class DParameterRange;
00043 
00044 // <summary>
00045 // Arrow implementation;adds a polygon to a DSLine to represent the arrow head
00046 // </summary>
00047 //
00048 // <prerequisite>
00049 // <li> <linkto class="DSLine">DSLine</linkto>
00050 // <li> <linkto class="DSPoly">DSPoly</linkto>
00051 // <li> <linkto class="DisplayShape">DisplayShape</linkto>
00052 // </prerequisite>
00053 //
00054 // <etymology>
00055 // DSArrow is a method of managing the drawing of a line and polygon onto a 
00056 // PixelCanvas.
00057 // </etymology>
00058 //
00059 // <synopsis>
00060 // DSArrow simply extends from DSLine, and adds the management of a polygon
00061 // to it. The polygon is used to represent the arrow head, and various options
00062 // regarding its apppearance can be changed.
00063 //
00064 // There are generally two ways to make DisplayShape(s); To create them in 
00065 // "one hit" by providing arguments to the constructor, or by using the 
00066 // default constructor and then the "setOptions" method. A simple interface 
00067 // for all classes inheriting from the 
00068 // <linkto class="DisplayShape">DisplayShape</linkto> class is provided by 
00069 // <linkto class="DisplayShapeInterface">DisplayShapeInterface</linkto>.
00070 // </synopsis>
00071 //
00072 // <motivation>
00073 // It was thought, especially in an annotations context, that an Arrow would be
00074 // a usefull drawing tool.
00075 // </motivation>
00076 //
00077 // <example>
00078 // <srcblock>
00079 // Vector<Float> startPoint(2); startPoint[0] = 100; startPoint[1] = 100;
00080 // Vector<Float> endPoint(2);   endPoint[0] = 200;   endPoint[1] = 200;
00081 //
00082 // DSArrow* myArrow = 
00083 // new DSArrow(startPoint, endPoint, DSArrow::Filled_Triangle, 10);
00084 //
00085 // myArrow->move(10,10);
00086 //
00087 // Vector<Float> newStart(2); newStart[0] = 50; newStart[1] = 50;
00088 // myArrow->setStartPoint(newStart);
00089 //
00090 // Record newArrow;
00091 // newArrow.define("arrowheadsize", 6);
00092 //
00093 // myArrow->setOptions(newArrow);
00094 // myArrow->draw(myPixelCanvas);
00095 // etc..
00096 // </srcblock>
00097 // </example>
00098 
00099 class DSArrow : public DSLine {
00100 
00101 public: 
00102 
00103   // Supported arrow head types
00104   enum ArrowHead { Open_Triangle, Filled_Triangle , Cool_Triangle};
00105 
00106   // For checking setoptions(arrowheadstyle = ?) 
00107   static const int numArrowHeads = 3; 
00108 
00109 
00110   // Default constructor. In order to make the arrow "valid", it must 
00111   // be supplied with a valid start and end point.
00112   DSArrow();
00113 
00114   // The start and end point are in pixel co-ordinates.
00115   DSArrow(const Vector<Float> &startPoint, const Vector<Float> &endPoint, 
00116           DSArrow::ArrowHead style = DSArrow::Cool_Triangle, 
00117           const Int arrowHeadSize = 8);
00118 
00119   // Copy constructor
00120   DSArrow(const DSArrow& other);
00121 
00122   // Destructor
00123   virtual ~DSArrow();
00124   
00125   // Standard Display Shape functions
00126   // <group>
00127   virtual void draw(PixelCanvas *pc);
00128   virtual void move(const Float& dX, const Float& dY);
00129   virtual void rotate(const Float& angle);
00130   virtual void scale(const Float& scaleFactor);
00131   virtual void setCenter(const Float& xPos, const Float& yPos);
00132   // </group>
00133 
00134   // Does nothing currently
00135   virtual void rotateAbout(const Float& angle, const Float& aboutX, 
00136                              const Float& aboutY);
00137 
00138   // Standard (changePoint) and specific funtions for altering the arrow. the 
00139   // changePoint method with only one argument will move the closest point to 
00140   // the specified new point. When speciffyin 'n', in this case only 0 or
00141   // 1 are valid. The 'startpoint' is the one with the arrow head on it.
00142   // <group>
00143   virtual void setStartPoint(const Vector<Float>& startPoint);
00144   virtual void setEndPoint(const Vector<Float>& endPoint);
00145   virtual void changePoint(const Vector<Float>&pos, const Int n);
00146   virtual void changePoint(const Vector<Float>& pos);
00147   // </group>
00148 
00149   // These are to enable the use of arrows more easily in vector plots
00150   // <group>
00151   virtual void setLength(const Float& pixelLength);
00152   virtual void setAngle(const Float& angle);
00153   // </group>
00154 
00155   // Return an option record describing the shape
00156   virtual Record getOptions();
00157   
00158   // Set options. 
00159   virtual Bool setOptions(const Record& newSettings);
00160 
00161 protected:
00162 
00163 private: 
00164   // If someone calls "setLength" before "setCenter", we can store our
00165   // length until they DO call setLength;
00166   Float itsLength;
00167   
00168   // Make a new arrow head (which is simply a DSPoly)
00169   virtual void buildArrowHead();
00170   
00171   // Caluclate angle etc.
00172   virtual void updateArrowHead();
00173 
00174   // Set default options
00175   virtual void setDefaultOptions();
00176 
00177   // Construct the line segment of the arrow when we have 
00178   // valid start / end points
00179   virtual void make();
00180 
00181   DParameterRange<Int>* itsHeadSize;
00182 
00183   DSPoly* itsArrowHead;
00184 
00185   // Temp storage while I am being set up
00186   // <group>
00187   Vector<Float> itsStartPoint;
00188   Vector<Float> itsEndPoint;
00189   // </group>
00190 
00191   // A Matrix of the unRotated arrow head 
00192   Matrix<Float> itsUnrotatedHead;
00193 
00194   // Offset needed to make sure the tip of the arrow is at the end of
00195   // the line.
00196   Float itsOffset;
00197 
00198   // Style of arrow head
00199   DSArrow::ArrowHead itsArrowHeadStyle;
00200 
00201   // Have I been supplied with valid points yet
00202   Bool itsValidStart,itsValidEnd;
00203 };
00204 
00205 
00206 } //# NAMESPACE CASA - END
00207 
00208 #endif
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221