itom 2.2.1
K:/git-itom/sources/itom/common/shape.h
00001 /* ********************************************************************
00002 itom software
00003 URL: http://www.uni-stuttgart.de/ito
00004 Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005 Universitaet Stuttgart, Germany
00006 
00007 This file is part of itom and its software development toolkit (SDK).
00008 
00009 itom is free software; you can redistribute it and/or modify it
00010 under the terms of the GNU Library General Public Licence as published by
00011 the Free Software Foundation; either version 2 of the Licence, or (at
00012 your option) any later version.
00013 
00014 In addition, as a special exception, the Institut fuer Technische
00015 Optik (ITO) gives you certain additional rights.
00016 These rights are described in the ITO LGPL Exception version 1.0,
00017 which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019 itom is distributed in the hope that it will be useful, but
00020 WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022 General Public Licence for more details.
00023 
00024 You should have received a copy of the GNU Library General Public License
00025 along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 *********************************************************************** */
00027 
00028 #ifndef SHAPE_H
00029 #define SHAPE_H
00030 
00031 #include "typeDefs.h"
00032 #include "../shape/shapeCommon.h"
00033 
00034 //#include "../DataObject/dataobj.h"
00035 
00036 #include <qpolygon.h>
00037 #include <qtransform.h>
00038 #include <qregion.h>
00039 #include <qdatastream.h>
00040 
00041 #if !defined(Q_MOC_RUN) || defined(ITOMSHAPE_MOC) //only moc this file in itomShapeLib but not in other libraries or executables linking against this itomCommonQtLib
00042 
00043 namespace ito
00044 {
00045     class ShapePrivate;
00046     class Shape;
00047 
00048     QDataStream ITOMSHAPE_EXPORT &operator<<(QDataStream &out, const ito::Shape &shape);
00049 
00050         QDataStream ITOMSHAPE_EXPORT &operator>>(QDataStream &in, ito::Shape &shape);
00051 
00052 
00053         class ITOMSHAPE_EXPORT Shape
00054     {
00055 
00056     public:
00057 
00060         enum ShapeType
00061         {
00062             Invalid = 0,
00063             MultiPointPick = 0x00000001,    
00064             Point = 0x00000002,             
00065             Line = 0x00000004,              
00066             Rectangle = 0x00000008,         
00067             Square = 0x00000010,            
00068             Ellipse = 0x00000020,           
00069             Circle = 0x00000040,            
00070             Polygon = 0x00000080,           
00072             //REMARK: If this enumeration is changed, please identically change ItomQwtPlotEnums::ShapeType in the designer plugins!
00073         };
00074 
00075         enum ShapeFlag
00076         {
00077             MoveLock = 0x00010000,   
00078             RotateLock = 0x00020000, 
00079             ResizeLock = 0x00040000, 
00080         };
00081 
00082         enum ShapeMask
00083         {
00084             TypeMask = 0x0000FFFF,  
00085             FlagMask = 0xFFFF0000   
00086         };
00087 
00088         explicit Shape();
00089         explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QTransform &transform = QTransform());
00090         explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QTransform &transform = QTransform());
00091         explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QString &name, const QTransform &transform = QTransform());
00092         explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QString &name, const QTransform &transform = QTransform());
00093         Shape(const Shape &other);
00094         virtual ~Shape();
00095 
00096         Shape& operator =(const Shape &other);
00097         
00098         /* Returns a normalized shape; i.e., a rectangle, square, circle or ellipse that has a non-negative width and height. */
00099         Shape normalized() const; 
00100 
00101         bool isValid() const;
00102 
00103         unsigned int flags() const;
00104         void setFlags(const unsigned int &flags);
00105 
00106         int index() const;
00107         void setIndex(const int &index);
00108 
00109         QString name() const;
00110         void setName(const QString &name);
00111 
00112         unsigned int type() const;
00113         void setType(const unsigned int &type);
00114 
00115         QTransform transform() const;
00116         QTransform &rtransform() const;
00117         void setTransform(const QTransform &trafo);
00118 
00119         double rotationAngleDeg() const;
00120         double rotationAngleRad() const;
00121 
00122         ito::float64 userData1() const;
00123         void setUserData1(const ito::float64 &userData1);
00124 
00125         ito::float64 userData2() const;
00126         void setUserData2(const ito::float64 &userData2);
00127 
00128         QPolygonF basePoints() const; 
00129         QPolygonF &rbasePoints();
00130         const QPolygonF &rbasePoints() const;
00131         QPolygonF contour(bool applyTrafo = true, qreal tol = -1.0) const; 
00132         QRegion   region() const;
00133         
00134 
00135         void point1MoveTo(const QPointF &newPoint1);
00136 
00137                 QPointF centerPoint() const;
00138 
00139         double area() const;
00140         double circumference() const;
00141                 double distance(const Shape &otherShape) const;
00142                 double centerDistance(const Shape &otherShape) const;
00143 
00144                 double radius() const;
00145                 double radiusX() const;
00146                 double radiusY() const;
00147 
00148         static Shape fromRectangle(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00149         static Shape fromRectangle(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00150         static Shape fromSquare(const QPointF &center, qreal sideLength, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00151         static Shape fromEllipse(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00152         static Shape fromEllipse(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00153         static Shape fromCircle(const QPointF &center, qreal radius, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00154         static Shape fromLine(const QPointF &p1, const QPointF &p2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00155         static Shape fromLine(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00156         static Shape fromPoint(const QPointF &point, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00157         static Shape fromPoint(qreal x, qreal y, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00158         static Shape fromPolygon(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00159         static Shape fromMultipoint(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
00160 
00161                 static QString type2QString(const int type);
00162 
00163                 //static ito::DataObject maskFromMultipleShapes(const ito::DataObject &dataObject, const QVector<ito::Shape> &shapes, bool inverse = false);
00164                 //ito::DataObject mask(const ito::DataObject &dataObject, bool inverse = false) const;
00165 
00166     protected:
00167 
00168         ShapePrivate *d;
00169 
00170         QPolygonF ramerDouglasPeucker(qreal tol) const;
00171         //void maskHelper(const ito::DataObject &dataObject, ito::DataObject &mask, bool inverse = false) const;
00172 
00173                 static double distanceLine2Point2D(const Shape &line, const QPointF &point);
00174                 static double distanceLine2Line2D(const Shape &line1, const Shape &line2);
00175                 static double distancePoint2Point2D(const QPointF &point1, const QPointF &point2);
00176     };
00177 }
00178 
00179 
00180 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC)
00181 
00182 #endif //SHAPE_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends