itom  3.0.0
shape.h
1 /* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5 Universitaet Stuttgart, Germany
6 
7 This file is part of itom and its software development toolkit (SDK).
8 
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13 
14 In addition, as a special exception, the Institut fuer Technische
15 Optik (ITO) gives you certain additional rights.
16 These rights are described in the ITO LGPL Exception version 1.0,
17 which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19 itom is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22 General Public Licence for more details.
23 
24 You should have received a copy of the GNU Library General Public License
25 along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef SHAPE_H
29 #define SHAPE_H
30 
31 #include "typeDefs.h"
32 #include "../shape/shapeCommon.h"
33 
34 //#include "../DataObject/dataobj.h"
35 
36 #include <qpolygon.h>
37 #include <qtransform.h>
38 #include <qregion.h>
39 #include <qdatastream.h>
40 
41 #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
42 
43 namespace ito
44 {
45  class ShapePrivate;
46  class Shape;
47 
48  QDataStream ITOMSHAPE_EXPORT &operator<<(QDataStream &out, const ito::Shape &shape);
49 
50  QDataStream ITOMSHAPE_EXPORT &operator>>(QDataStream &in, ito::Shape &shape);
51 
52 
53  class ITOMSHAPE_EXPORT Shape
54  {
55 
56  public:
57 
60  enum ShapeType
61  {
62  Invalid = 0,
63  MultiPointPick = 0x00000001,
64  Point = 0x00000002,
65  Line = 0x00000004,
66  Rectangle = 0x00000008,
67  Square = 0x00000010,
68  Ellipse = 0x00000020,
69  Circle = 0x00000040,
70  Polygon = 0x00000080,
72  //REMARK: If this enumeration is changed, please identically change ItomQwtPlotEnums::ShapeType in the designer plugins!
73  };
74 
75  enum ShapeFlag
76  {
77  MoveLock = 0x00010000,
78  RotateLock = 0x00020000,
79  ResizeLock = 0x00040000,
80  };
81 
82  enum ShapeMask
83  {
84  TypeMask = 0x0000FFFF,
85  FlagMask = 0xFFFF0000
86  };
87 
88  explicit Shape();
89  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QTransform &transform = QTransform());
90  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QTransform &transform = QTransform());
91  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QString &name, const QTransform &transform = QTransform());
92  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QString &name, const QTransform &transform = QTransform());
93  Shape(const Shape &other);
94  virtual ~Shape();
95 
96  Shape& operator =(const Shape &other);
97 
98  /* Returns a normalized shape; i.e., a rectangle, square, circle or ellipse that has a non-negative width and height. */
99  Shape normalized() const;
100 
101  bool isValid() const;
102 
103  unsigned int flags() const;
104  void setFlags(const unsigned int &flags);
105 
106  int index() const;
107  void setIndex(const int &index);
108 
109  QString name() const;
110  void setName(const QString &name);
111 
112  unsigned int type() const;
113  void setType(const unsigned int &type);
114 
115  QTransform transform() const;
116  QTransform &rtransform() const;
117  void setTransform(const QTransform &trafo);
118 
119  double rotationAngleDeg() const;
120  double rotationAngleRad() const;
121 
122  ito::float64 userData1() const;
123  void setUserData1(const ito::float64 &userData1);
124 
125  ito::float64 userData2() const;
126  void setUserData2(const ito::float64 &userData2);
127 
128  QPolygonF basePoints() const;
129  QPolygonF &rbasePoints();
130  const QPolygonF &rbasePoints() const;
131  QPolygonF contour(bool applyTrafo = true, qreal tol = -1.0) const;
132  QRegion region() const;
133 
134 
135  void point1MoveTo(const QPointF &newPoint1);
136 
137  QPointF centerPoint() const;
138 
139  double area() const;
140  double circumference() const;
141  double distance(const Shape &otherShape) const;
142  double centerDistance(const Shape &otherShape) const;
143 
144  double radius() const;
145  double radiusX() const;
146  double radiusY() const;
147 
148  static Shape fromRectangle(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
149  static Shape fromRectangle(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
150  static Shape fromSquare(const QPointF &center, qreal sideLength, int index = -1, QString name = "", const QTransform &trafo = QTransform());
151  static Shape fromEllipse(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
152  static Shape fromEllipse(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
153  static Shape fromCircle(const QPointF &center, qreal radius, int index = -1, QString name = "", const QTransform &trafo = QTransform());
154  static Shape fromLine(const QPointF &p1, const QPointF &p2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
155  static Shape fromLine(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
156  static Shape fromPoint(const QPointF &point, int index = -1, QString name = "", const QTransform &trafo = QTransform());
157  static Shape fromPoint(qreal x, qreal y, int index = -1, QString name = "", const QTransform &trafo = QTransform());
158  static Shape fromPolygon(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
159  static Shape fromMultipoint(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
160 
161  static QString type2QString(const int type);
162 
163  //static ito::DataObject maskFromMultipleShapes(const ito::DataObject &dataObject, const QVector<ito::Shape> &shapes, bool inverse = false);
164  //ito::DataObject mask(const ito::DataObject &dataObject, bool inverse = false) const;
165 
166  protected:
167 
168  ShapePrivate *d;
169 
170  QPolygonF ramerDouglasPeucker(qreal tol) const;
171  //void maskHelper(const ito::DataObject &dataObject, ito::DataObject &mask, bool inverse = false) const;
172 
173  static double distanceLine2Point2D(const Shape &line, const QPointF &point);
174  static double distanceLine2Line2D(const Shape &line1, const Shape &line2);
175  static double distancePoint2Point2D(const QPointF &point1, const QPointF &point2);
176  };
177 }
178 
179 
180 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC)
181 
182 #endif //SHAPE_H
Definition: apiFunctionsGraph.cpp:39
ShapeType
Definition: shape.h:60
ShapeFlag
Definition: shape.h:75
Definition: shape.cpp:55
Definition: shape.h:53
ShapeMask
Definition: shape.h:82