QCAD
Open Source 2D CAD
RRefPoint.h
Go to the documentation of this file.
1 #ifndef RREFPOINT_H
2 #define RREFPOINT_H
3 
4 #include "../core_global.h"
5 
6 #include <QFlags>
7 #include <QList>
8 
9 #include "RVector.h"
10 
19 public:
20  enum Flag {
21  NoFlags = 0x000,
22  Secondary = 0x001,
23  Center = 0x002,
24  Ignore = 0x004,
25  Start = 0x008,
26  End = 0x010
27  };
28  Q_DECLARE_FLAGS(Flags, Flag)
29 
30  static QList<RVector> toVectorList(const QList<RRefPoint>& list) {
31  QList<RVector> ret;
32  for (int i=0; i<list.length(); i++) {
33  ret.append(list.at(i));
34  }
35  return ret;
36  }
37 
38  static QList<RRefPoint> toRefPointList(const QList<RVector>& list, RRefPoint::Flags flags = RRefPoint::NoFlags) {
39  QList<RRefPoint> ret;
40  for (int i=0; i<list.length(); i++) {
41  ret.append(RRefPoint(list.at(i), flags));
42  }
43  return ret;
44  }
45 
46  RRefPoint() : RVector() {}
47  RRefPoint(const RVector& v, RRefPoint::Flags f) : RVector(v), flags(f) {}
48  RRefPoint(const RVector& v) : RVector(v) {}
49  RRefPoint(double vx, double vy, double vz = 0.0, bool valid_in = true) : RVector(vx, vy, vz, valid_in) {}
50 
51  bool isSecondary() const {
52  return getFlag(RRefPoint::Secondary);
53  }
54 
55  void setSecondary(bool on) {
56  setFlag(RRefPoint::Secondary, on);
57  }
58 
59  bool isIgnore() const {
60  return getFlag(RRefPoint::Ignore);
61  }
62 
63  void setIgnore(bool on) {
64  setFlag(RRefPoint::Ignore, on);
65  }
66 
67  bool isCenter() const {
68  return getFlag(RRefPoint::Center);
69  }
70 
71  void setCenter(bool on) {
72  setFlag(RRefPoint::Center, on);
73  }
74 
75  bool isStart() const {
76  return getFlag(RRefPoint::Start);
77  }
78 
79  void setStart(bool on) {
80  setFlag(RRefPoint::Start, on);
81  }
82 
83  bool isEnd() const {
84  return getFlag(RRefPoint::End);
85  }
86 
87  void setEnd(bool on) {
88  setFlag(RRefPoint::End, on);
89  }
90 
91  void setFlag(RRefPoint::Flag flag, bool on) {
92  if (on) {
93  flags |= flag;
94  } else {
95  flags &= ~flag;
96  }
97  }
98 
99  bool getFlag(RRefPoint::Flag flag) const {
100  return (flags & flags) == flag;
101  }
102 
103  RRefPoint::Flags getFlags() const {
104  return flags;
105  }
106 
107  void setFlags(RRefPoint::Flags f) {
108  flags = f;
109  }
110 
111 private:
112  Flags flags;
113 };
114 
115 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RRefPoint& v);
116 
117 Q_DECLARE_METATYPE(QList<RRefPoint>)
119 typedef QMultiMap<int, RRefPoint> _RMapIntRefPoint;
120 Q_DECLARE_METATYPE(_RMapIntRefPoint*)
126 Q_DECLARE_METATYPE(QFlags<RRefPoint::Flag>)
127 Q_DECLARE_METATYPE(QFlags<RRefPoint::Flag>*)
128 
129 #endif
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Definition: RRefPoint.h:21
Represents a reference point of an entity.
Definition: RRefPoint.h:18
RRefPoint(const RVector &v)
Definition: RRefPoint.h:48
#define QCADCORE_EXPORT
Definition: core_global.h:10
Reference point is a start point.
Definition: RRefPoint.h:26
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RRefPoint &v)
Definition: RRefPoint.cpp:3
bool isStart() const
Definition: RRefPoint.h:75
Reference point is a center point.
Definition: RRefPoint.h:23
void setFlags(RRefPoint::Flags f)
Definition: RRefPoint.h:107
RRefPoint(double vx, double vy, double vz=0.0, bool valid_in=true)
Definition: RRefPoint.h:49
Secondary reference point (typically shown with different color)
Definition: RRefPoint.h:22
void setSecondary(bool on)
Definition: RRefPoint.h:55
bool isCenter() const
Definition: RRefPoint.h:67
Q_DECLARE_METATYPE(RMath *)
bool isEnd() const
Definition: RRefPoint.h:83
void setEnd(bool on)
Definition: RRefPoint.h:87
RRefPoint()
Definition: RRefPoint.h:46
void setIgnore(bool on)
Definition: RRefPoint.h:63
bool isSecondary() const
Definition: RRefPoint.h:51
static QList< RRefPoint > toRefPointList(const QList< RVector > &list, RRefPoint::Flags flags=RRefPoint::NoFlags)
Definition: RRefPoint.h:38
Reference point is a start point.
Definition: RRefPoint.h:25
QMultiMap< int, RRefPoint > _RMapIntRefPoint
Definition: RRefPoint.h:119
bool isIgnore() const
Definition: RRefPoint.h:59
Ignore reference point for drag and drop.
Definition: RRefPoint.h:24
Flag
Definition: RRefPoint.h:20
RRefPoint::Flags getFlags() const
Definition: RRefPoint.h:103
void setFlag(RRefPoint::Flag flag, bool on)
Definition: RRefPoint.h:91
bool getFlag(RRefPoint::Flag flag) const
Definition: RRefPoint.h:99
void setStart(bool on)
Definition: RRefPoint.h:79
void setCenter(bool on)
Definition: RRefPoint.h:71
RRefPoint(const RVector &v, RRefPoint::Flags f)
Definition: RRefPoint.h:47
Flags flags
Definition: RRefPoint.h:112