itom  4.1.0
shape.h
1 /* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, 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 <qpolygon.h>
35 #include <qtransform.h>
36 #include <qregion.h>
37 #include <qcolor.h>
38 #include <qdatastream.h>
39 
40 #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
41 
42 namespace ito
43 {
44  class ShapePrivate;
45  class Shape;
46 
47  QDataStream ITOMSHAPE_EXPORT &operator<<(QDataStream &out, const ito::Shape &shape);
48 
49  QDataStream ITOMSHAPE_EXPORT &operator>>(QDataStream &in, ito::Shape &shape);
50 
51 
52  class ITOMSHAPE_EXPORT Shape
53  {
54 
55  public:
56 
59  enum ShapeType
60  {
61  Invalid = 0,
62  MultiPointPick = 0x00000001,
63  Point = 0x00000002,
64  Line = 0x00000004,
65  Rectangle = 0x00000008,
66  Square = 0x00000010,
67  Ellipse = 0x00000020,
68  Circle = 0x00000040,
69  Polygon = 0x00000080,
71  //REMARK: If this enumeration is changed, please identically change ItomQwtPlotEnums::ShapeType in the designer plugins!
72  };
73 
74  enum ShapeFlag
75  {
76  MoveLock = 0x00010000,
77  RotateLock = 0x00020000,
78  ResizeLock = 0x00040000,
79  };
80 
81  enum ShapeMask
82  {
83  TypeMask = 0x0000FFFF,
84  FlagMask = 0xFFFF0000
85  };
86 
87  explicit Shape();
88  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QTransform &transform = QTransform());
89  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QTransform &transform = QTransform());
90  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, int index, const QString &name, const QTransform &transform = QTransform());
91  explicit Shape(unsigned int type, unsigned int flags, const QPolygonF &basePoints, const QString &name, const QTransform &transform = QTransform());
92  Shape(const Shape &other);
93  virtual ~Shape();
94 
95  Shape& operator =(const Shape &other);
96 
97  /* Returns a normalized shape; i.e., a rectangle, square, circle or ellipse that has a non-negative width and height. */
98  Shape normalized() const;
99 
100  bool isValid() const;
101 
102  unsigned int flags() const;
103  void setFlags(const unsigned int &flags);
104 
105  bool unclosed() const;
106  void setUnclosed(bool unclosed);
107 
108  int index() const;
109  void setIndex(const int &index);
110 
111  QString name() const;
112  void setName(const QString &name);
113 
114  unsigned int type() const;
115  void setType(const unsigned int &type);
116 
117  QColor color() const;
118  void setColor(const QColor &color);
119 
120  QTransform transform() const;
121  QTransform &rtransform() const;
122  void setTransform(const QTransform &trafo);
123 
124  double rotationAngleDeg() const;
125  double rotationAngleRad() const;
127  void setRotationAngleDeg(double degree);
128  void setRotationAngleRad(double radians);
130  void rotateByCenterDeg(double degree);
131  void rotateByCenterRad(double radians);
133  void translate(const QPointF &delta);
135  ito::float64 userData1() const;
136  void setUserData1(const ito::float64 &userData1);
137 
138  ito::float64 userData2() const;
139  void setUserData2(const ito::float64 &userData2);
140 
141  QPolygonF basePoints() const;
142  QPolygonF &rbasePoints();
143  const QPolygonF &rbasePoints() const;
144  QPolygonF contour(bool applyTrafo = true, qreal tol = -1.0) const;
145  QRegion region() const;
146 
147 
148  void point1MoveTo(const QPointF &newPoint1);
149 
150  QPointF centerPoint() const;
151  QPointF baseCenterPoint() const;
153  double area() const;
154  double circumference() const;
155  double distance(const Shape &otherShape) const;
156  double centerDistance(const Shape &otherShape) const;
157 
158  double radius() const;
159  double radiusX() const;
160  double radiusY() const;
161 
162  bool contains(const QPointF &point) const;
163  QVector<bool> contains(const QPolygonF &points) const;
165  static Shape fromRectangle(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
166  static Shape fromRectangle(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
167  static Shape fromSquare(const QPointF &center, qreal sideLength, int index = -1, QString name = "", const QTransform &trafo = QTransform());
168  static Shape fromEllipse(const QRectF &rect, int index = -1, QString name = "", const QTransform &trafo = QTransform());
169  static Shape fromEllipse(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
170  static Shape fromCircle(const QPointF &center, qreal radius, int index = -1, QString name = "", const QTransform &trafo = QTransform());
171  static Shape fromLine(const QPointF &p1, const QPointF &p2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
172  static Shape fromLine(qreal x1, qreal y1, qreal x2, qreal y2, int index = -1, QString name = "", const QTransform &trafo = QTransform());
173  static Shape fromPoint(const QPointF &point, int index = -1, QString name = "", const QTransform &trafo = QTransform());
174  static Shape fromPoint(qreal x, qreal y, int index = -1, QString name = "", const QTransform &trafo = QTransform());
175  static Shape fromPolygon(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
176  static Shape fromMultipoint(const QPolygonF &polygon, int index = -1, QString name = "", const QTransform &trafo = QTransform());
177 
178  static QString type2QString(const int type);
179 
180  //static ito::DataObject maskFromMultipleShapes(const ito::DataObject &dataObject, const QVector<ito::Shape> &shapes, bool inverse = false);
181  //ito::DataObject mask(const ito::DataObject &dataObject, bool inverse = false) const;
182 
183  protected:
184 
185  ShapePrivate *d;
186 
187  QPolygonF ramerDouglasPeucker(qreal tol) const;
188  //void maskHelper(const ito::DataObject &dataObject, ito::DataObject &mask, bool inverse = false) const;
189 
190  static double distanceLine2Point2D(const Shape &line, const QPointF &point);
191  static double distanceLine2Line2D(const Shape &line1, const Shape &line2);
192  static double distancePoint2Point2D(const QPointF &point1, const QPointF &point2);
193  };
194 }
195 
196 
197 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC)
198 
199 #endif //SHAPE_H
Definition: apiFunctionsGraph.cpp:39
ShapeType
Definition: shape.h:59
ShapeFlag
Definition: shape.h:74
Definition: shape.cpp:58
Definition: shape.h:52
ShapeMask
Definition: shape.h:81