DisplayShapeInterface.h

Go to the documentation of this file.
00001 //# DisplayShapeInterface.h: Simple wrapper 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_DISPLAYSHAPEINTERFACE_H
00029 #define TRIALDISPLAY_DISPLAYSHAPEINTERFACE_H
00030 
00031 
00032 #include <casa/aips.h>
00033 
00034 #include <display/DisplayShapes/DisplayShape.h>
00035 #include <display/Display/PixelCanvas.h>
00036 #include <display/Display/WorldCanvas.h>
00037 #include <casa/Containers/Record.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //class PixelCanvas;
00042 //class WorldCanvas;
00043 
00044 // <summary>
00045 // Wrapper for DisplayShapes;provides easier/unified constr. of DisplayShapes
00046 // </summary>
00047 //
00048 // <prerequisite>
00049 // <li> <linkto class="DisplayShape">DisplayShape</linkto>
00050 // </prerequisite>
00051 //
00052 // <etymology>
00053 // DisplayShapeInterface makes it easier to work with DisplayShapes.
00054 // </etymology>
00055 //
00056 // <synopsis>
00057 // DisplayShapeInterface simply contains a pointer to a DisplayShape object.
00058 // It allows all DisplayShapes to be constructed via a single constructor. i.e.
00059 // the DisplayShapeInterface constructor actually decides which shape to
00060 // create based on the information in the Record passed to it. It makes
00061 // creating new shapes look a little nice, since:
00062 // <srcblock>
00063 // record1.define("type", "square");
00064 // and
00065 // record2.define("type", "circle");
00066 // </srcblock>
00067 // can both be simply made into a new DisplayShapeInterface, e.g.
00068 // <srcblock>
00069 // DisplayShapeInterface* myShape = new DisplayShapeInterface(record1);
00070 // or
00071 // DisplayShapeInterface* myShape = new DisplayShapeInterface(record2);
00072 // </srcblock>
00073 // It also guarantees consistant interfaces between shapes.
00074 // </synopsis>
00075 //
00076 // <motivation>
00077 // The creation of an interface to DisplayShapes makes use of the simpler.
00078 // </motivation>
00079 //
00080 // <example>
00081 // </example>
00082 
00083 
00084 
00085 
00086         class DisplayShapeInterface {
00087 
00088         public:
00089                 enum Coord {Pixels, Relative, World};
00090 
00091                 // Constructor for a standard shape. The shape will be totally based on
00092                 // pixel sizes, both for it's position and sizes.
00093                 DisplayShapeInterface(const Record& shapeInfo);
00094 
00095                 // Constructor for shape based on relative screen positions. if
00096                 // scaled is true, relative screen positions will be used for
00097                 // height etc also. If not, positions only will be based on relative
00098                 // screen pos, heights will be based on an absolute pixel value.
00099                 DisplayShapeInterface(const Record& shapeInfo, const PixelCanvas* pc,
00100                                       const Bool scale = True);
00101 
00102                 // Constructor for shape based on world co-ordinates (NYI)
00103                 DisplayShapeInterface(const Record shapeInfo, const WorldCanvas* wc);
00104 
00105                 // Copy cons
00106                 DisplayShapeInterface(const DisplayShapeInterface& other);
00107 
00108                 virtual ~DisplayShapeInterface();
00109 
00110 
00111                 // DisplayShape functionality. All of these functions simply wrap those
00112                 // of the underlying DisplayShape (and add conversion functionality).
00113                 // Please see <linkto class="DisplayShape">DisplayShape</linkto>
00114                 // for a full description of these functions.
00115                 // <group>
00116                 virtual Bool inObject(const Float xPos, const Float yPos);
00117                 virtual Bool onHandles(const Float xPos, const Float yPos);
00118                 virtual Vector<Float> getCenter() const;
00119                 virtual void setCenter(const Float xPos, const Float yPos);
00120                 virtual Bool whichHandle(const Float xPos, const Float yPos, Int& out);
00121                 virtual void changePoint(const Vector<Float>& newPos);
00122                 virtual void changePoint(const Vector<Float>& newPoint, const Int nPoint);
00123                 virtual void addPoint(const Vector<Float>& newPoint);
00124                 virtual void rotate(const Float angle);
00125                 virtual void scale(const Float angle);
00126                 virtual void draw(PixelCanvas* toDrawTo);
00127                 virtual void move(const Float dX, const Float dY);
00128                 virtual void addLocked(DisplayShapeInterface* toLock);
00129                 virtual void removeLocked(DisplayShapeInterface* removeLock);
00130                 virtual void setDrawHandles(const Bool& draw);
00131                 virtual Bool setOptions(const Record& newOptions);
00132                 virtual Record getOptions() ;
00133                 // </group>
00134 
00135                 // Update the pixel location of this shape, based on the stored information
00136                 // on its location. If the shape is being used in pixel mode this will do
00137                 // nothing. If being used in relative screen mode or WC mode, this will
00138                 // update its location. Returns false if a conversion to pixels fail.
00139                 virtual Bool updatePixelPosition();
00140 
00141                 // If the shape is being used in absolute pixel co-ordinates, this will do
00142                 // nothing. If being used in relative screen or WC mode, this will update
00143                 // the position based on its current pixel location. Returns false if the
00144                 // conversion to the other co-ord type fails.
00145                 virtual Bool updateNonPixelPosition();
00146 
00147                 // Returns the pointer to the underlying object
00148                 virtual DisplayShape* getObject();
00149 
00150                 // If the shape is a PolyLine, this function will change it to a polygon.
00151                 // This is designed for use in the creation of polygon by the user clicking
00152                 // out a polyline, for example.
00153                 virtual void toPolygon();
00154 
00155 
00156         private:
00157                 Record toPixOpts(const Record& notPix);
00158 
00159                 // Will return an option set with whatever the current
00160                 // coords method is.
00161                 Record fromPixOpts(const Record& pix) ;
00162 
00163                 Record pixToRelOpts(const Record& pixel);
00164                 Record relToPixOpts(const Record& relative);
00165                 Record pixToWorldOpts(const Record& pix);
00166                 Record worldToPixOpts(const Record& world);
00167 
00168                 Vector<Float> pixToRel(const Vector<Float>& pix);
00169                 Vector<Float> relToPix(const Vector<Float>& rel);
00170                 Float relToPixWidth(const Float rel);
00171                 Float relToPixHeight(const Float rel);
00172                 Float pixToRelWidth(const Float pix);
00173                 Float pixToRelHeight(const Float pix);
00174 
00175                 DisplayShape* itsShape;
00176                 DisplayShapeInterface::Coord itsCoords;
00177                 const PixelCanvas* itsPc;
00178                 const WorldCanvas* itsWc;
00179 
00180                 void makeShape(const Record& shapeInfo);
00181 
00182                 // Scale widths and heights in relative mode?
00183                 Bool itsScale;
00184 
00185                 // Copy of shape, however in its alternate coord form
00186                 Record altCoords;
00187         };
00188 
00189 
00190 
00191 } //# NAMESPACE CASA - END
00192 
00193 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1