-
Notifications
You must be signed in to change notification settings - Fork 411
/
RLeaderData.h
260 lines (220 loc) · 8.17 KB
/
RLeaderData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
*
* This file is part of the QCAD project.
*
* QCAD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QCAD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QCAD.
*/
#ifndef RLEADERDATA_H
#define RLEADERDATA_H
#include "entity_global.h"
#include "RDocument.h"
#include "RDimLinearData.h"
#include "RPolyline.h"
#include "RTriangle.h"
#include "RVector.h"
/**
* Leader entity data class.
*
* \scriptable
* \copyable
* \ingroup entity
*/
class QCADENTITY_EXPORT RLeaderData: public REntityData, public RPolyline {
friend class RLeaderEntity;
protected:
RLeaderData(RDocument* document, const RLeaderData& data);
public:
RLeaderData();
RLeaderData(const RPolyline& polyline, bool arrowHead);
virtual RS::EntityType getType() const {
return RS::EntityLeader;
}
virtual RShape* castToShape() {
return this;
}
bool isValid() const {
return RPolyline::isValid();
}
virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const {
return REntityData::getEndPoints(queryBox, subEntityIds);
}
virtual void setZ(double z) {
RPolyline::setZ(z);
}
virtual void to2D() {
RPolyline::to2D();
}
virtual RBox getBoundingBox(bool ignoreEmpty=false) const {
return REntityData::getBoundingBox();
}
virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const {
return REntityData::getMiddlePoints(queryBox, subEntityIds);
}
virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const {
return REntityData::getCenterPoints(queryBox, subEntityIds);
}
virtual QList<RVector> getArcReferencePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
return REntityData::getArcReferencePoints(queryBox);
}
virtual QList<RVector> getPointsWithDistanceToEnd(double distance, int from = RS::FromAny, const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const {
return REntityData::getPointsWithDistanceToEnd(distance, from, queryBox, subEntityIds);
}
virtual QList<RVector> getIntersectionPoints(const REntityData& other, bool limited = true, bool same = false, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true, QList<QPair<RObject::Id, RObject::Id> >* entityIds = NULL) const {
return REntityData::getIntersectionPoints(other, limited, same, queryBox, ignoreComplex, entityIds);
}
virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const {
return REntityData::getIntersectionPoints(shape, limited, queryBox, ignoreComplex);
}
virtual RVector getVectorTo(const RVector& point, bool limited=true, double strictRange = RMAXDOUBLE) const {
return REntityData::getVectorTo(point, limited, strictRange);
}
virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const {
return REntityData::getDistanceTo(point, limited, range, draft, strictRange);
}
virtual bool intersectsWith(const RShape& shape) const {
return REntityData::intersectsWith(shape);
}
virtual bool move(const RVector& offset) {
return RPolyline::move(offset);
}
virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
return RPolyline::rotate(rotation, center);
}
virtual bool mirror(const RLine& axis) {
return RPolyline::mirror(axis);
}
virtual bool mirror(const RVector& axis1, const RVector& axis2) {
return REntityData::mirror(axis1, axis2);
}
virtual bool flipHorizontal() {
return REntityData::flipHorizontal();
}
virtual bool flipVertical() {
return REntityData::flipVertical();
}
double getDimasz(bool scale = true) const {
double v = 2.5;
// get value from override:
if (dimasz>0.0) {
v = dimasz;
}
else if (document!=NULL) {
QSharedPointer<RDimStyle> dimStyle = document->queryDimStyleDirect();
if (!dimStyle.isNull()) {
// get value from dimension style:
v = dimStyle->getDouble(RS::DIMASZ);
}
else {
// TODO: get value from document (should never happen):
Q_ASSERT(false);
}
}
if (scale) {
v *= getDimscale();
}
return v;
}
void setDimasz(double v) {
dimasz = v;
update();
}
double getDimscale() const {
// get value from override:
if (dimscale>0.0) {
return dimscale;
}
double v = 1.0;
if (document!=NULL) {
QSharedPointer<RDimStyle> dimStyle = document->queryDimStyleDirect();
if (!dimStyle.isNull()) {
// get value from dimension style:
v = dimStyle->getDouble(RS::DIMSCALE);
}
else {
// TODO: get value from document (should never happen):
Q_ASSERT(false);
}
}
return v;
}
void setDimscale(double f) {
dimscale = f;
update();
}
virtual void scaleVisualProperties(double scaleFactor);
void setArrowHead(bool on);
bool hasArrowHead() const {
return arrowHead;
}
bool canHaveArrowHead() const;
bool updateArrowHead() const;
// void setPolyline(const RPolyline& polyline) {
// *((RPolyline*)this) = polyline;
// }
RVector getEndPoint() const {
return RPolyline::getEndPoint();
}
RVector getStartPoint() const {
return RPolyline::getStartPoint();
}
int countVertices() const {
return RPolyline::countVertices();
}
int countSegments() const {
return RPolyline::countSegments();
}
void appendVertex(const RVector& vertex) {
RPolyline::appendVertex(vertex);
}
bool isSplineShaped() const {
return splineShaped;
}
void setSplineShaped(bool on) {
splineShaped = on;
}
virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const {
return RPolyline::getExploded(segments);
}
virtual bool scale(const RVector& scaleFactors, const RVector& center);
virtual bool stretch(const RPolyline& area, const RVector& offset);
virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false, QList<RObject::Id>* entityIds = NULL) const;
RTriangle getArrowShape() const;
REntity::Id getDimLeaderBlockId() const;
void setDimLeaderBlockId(REntity::Id id);
virtual void update() const;
void clearStyleOverrides() {
dimscale = -1.0;
dimasz = -1.0;
update();
}
private:
/** Arrow head on / off */
mutable bool arrowHead;
/** Arrow size */
double dimasz;
/** Dimension scale */
double dimscale;
/** Block to use instead of arrow */
RBlock::Id dimLeaderBlockId;
/** Spline shaped leader */
bool splineShaped;
};
Q_DECLARE_METATYPE(RLeaderData)
Q_DECLARE_METATYPE(RLeaderData*)
Q_DECLARE_METATYPE(const RLeaderData*)
Q_DECLARE_METATYPE(QSharedPointer<RLeaderData>)
#endif