QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RHatchData.h
Go to the documentation of this file.
1
20#ifndef RHATCHDATA_H
21#define RHATCHDATA_H
22
23#include "entity_global.h"
24
25#include "RBox.h"
26#include "REntityData.h"
27#include "RHatchProxy.h"
28#include "RPattern.h"
29#include "RPainterPath.h"
30#include "RPainterPathSource.h"
31#include "RVector.h"
32
33class RDocument;
34class REntity;
35class RLine;
36class RRefPoint;
37class RPolyline;
38
39#ifndef RDEFAULT_MIN1
40#define RDEFAULT_MIN1 -1
41#endif
42
52
53 friend class RHatchEntity;
54
55protected:
56 RHatchData(RDocument* document, const RHatchData& data);
57
58public:
59 RHatchData();
60 RHatchData(const RHatchData& other);
61 RHatchData(bool solid, double scaleFactor, double angle, const QString& patternName);
62
63 virtual RS::EntityType getType() const {
64 return RS::EntityHatch;
65 }
66 RHatchData& operator=(const RHatchData& other);
67
68 void clearBoundary();
69
70 bool hasCustomPattern() const {
71 return !pattern.getPatternLines().isEmpty();
72 }
73
75 return pattern;
76 }
77
78 void setCustomPattern(const RPattern& p) {
79 pattern = p;
80 }
81
82 virtual bool cloneOnChange() const {
83 // force clone to preserve custom pattern for undo:
84 //return hasCustomPattern();
85 // 20190510: always clone (since allowing non-uniform scaling of hatches)
86 return true;
87 }
88
89 virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
90
91 virtual RVector getPointOnEntity() const;
92 virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
93 virtual bool intersectsWith(const RShape& shape) const;
94
95 virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
96
97 virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
98
99 virtual bool move(const RVector& offset);
100 virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
101 virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
102 virtual bool mirror(const RLine& axis);
103 virtual bool stretch(const RPolyline& area, const RVector& offset);
104
105 virtual RShape* castToShape() {
106 return NULL;
107 }
108
109 virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false, QList<RObject::Id>* entityIds = NULL) const;
110 virtual QList<QSharedPointer<RShape> > getExploded() const;
111
112 bool isSolid() const {
113 return solid;
114 }
115
116 void setSolid(bool on) {
117 solid = on;
118 clearCustomPattern();
119 }
120
121 bool isWinding() const {
122 return winding;
123 }
124
125 void setWinding(bool on) {
126 winding = on;
127 clearCustomPattern();
128 }
129
130 bool getAutoRegen() const {
131 return autoRegen;
132 }
133
134 void setAutoRegen(bool on) {
135 autoRegen = on;
136 clearCustomPattern();
137 }
138
139 double getScale() const {
140 return scaleFactor;
141 }
142
143 void setScale(double s) {
144 scaleFactor = s;
145 clearCustomPattern();
146 }
147
148 double getAngle() const {
149 return angle;
150 }
151
152 void setAngle(double a) {
153 angle = a;
154 clearCustomPattern();
155 }
156
158 return originPoint;
159 }
160
161 void setOriginPoint(const RVector& op, bool clearCustom = true) {
162 originPoint = op;
163 if (clearCustom) {
164 clearCustomPattern();
165 }
166 }
167
168 QString getPatternName() const {
169 return patternName;
170 }
171
172 void setPatternName(const QString& n) {
173 patternName = n;
174 clearCustomPattern();
175 }
176
177 int getTransparency() const {
178 return transparency;
179 }
180
181 void setTransparency(int t) {
182 transparency = t;
183 }
184
185 double getLength() const;
186 double getArea() const;
187
188 void clearCustomPattern();
189
190 void newLoop();
191 void cancelLoop();
192 void addBoundary(QSharedPointer<RShape> shape, bool addAutoLoops = true);
193 void addBoundaryShape(QSharedPointer<RShape> shape, int loop) {
194 if (loop < boundary.length()) {
195 boundary[loop].append(shape);
196 }
197 }
198 RPainterPath getBoundaryPath(double pixelSizeHint = RDEFAULT_MIN1) const;
199 virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
200
201 QList<QList<QSharedPointer<RShape> > > getBoundary() const {
202 return boundary;
203 }
204
208 QPair<QSharedPointer<RShape>, QSharedPointer<RShape> > getBoundaryElementsAt(int index, int& internalIndex) const;
209
210 virtual void update() const;
211 bool order();
212
213 int getLoopCount() const {
214 return boundary.count();
215 }
216
217 QList<QSharedPointer<RShape> > getLoopBoundary(int index) const;
218
219 QList<RPolyline> getBoundaryAsPolylines(double segmentLength = RDEFAULT_MIN1) const;
220
222 if (hatchProxy!=NULL) {
223 hatchProxy->autoCloseLoops(*this);
224 }
225 }
226
227 int getComplexity() const;
228
229 void setPattern(const RPattern& p) {
230 pattern = p;
231 }
232
233 virtual RColor getColor() const {
235 c.setAlpha(transparency);
236 return c;
237 }
238
239 virtual RColor getColor(const RColor& unresolvedColor, const QStack<QSharedPointer<REntity> >& blockRefStack) const {
240 RColor c = REntityData::getColor(unresolvedColor, blockRefStack);
241 c.setAlpha(transparency);
242 return c;
243 }
244 virtual RColor getColor(bool resolve, const QStack<QSharedPointer<REntity> >& blockRefStack) const {
245 RColor c = REntityData::getColor(resolve, blockRefStack);
246 c.setAlpha(transparency);
247 return c;
248 }
249
250 static bool hasProxy() {
251 return hatchProxy!=NULL;
252 }
253
257 static void setHatchProxy(RHatchProxy* p) {
258 if (hatchProxy!=NULL) {
259 delete hatchProxy;
260 }
261 hatchProxy = p;
262 }
263
268 return hatchProxy;
269 }
270
271protected:
272 QList<RLine> getSegments(const RLine& line) const;
273
274private:
275 bool solid;
279 double angle;
280 QString patternName;
283
287 QList<QList<QSharedPointer<RShape> > > boundary;
288
294
296 mutable QList<RPainterPath> painterPaths;
297 mutable bool dirty;
298 mutable bool gotDraft;
299 mutable double gotPixelSizeHint;
300
302};
303
307Q_DECLARE_METATYPE(QSharedPointer<RHatchData>)
308
309#endif
#define RDEFAULT_RBOX
Definition RBox.h:35
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RExplodable.h:30
Q_DECLARE_METATYPE(RMath *)
#define RMAXDOUBLE
Definition RMath.h:66
#define RDEFAULT_RVECTOR
Definition RVector.h:38
Represents a box e.g.
Definition RBox.h:46
Color.
Definition RColor.h:43
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition RDocument.h:78
Base class for all entity data classes.
Definition REntityData.h:65
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition REntityData.cpp:675
virtual RVector getPointOnEntity() const
Definition REntityData.cpp:372
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition REntityData.cpp:299
virtual bool stretch(const RPolyline &area, const RVector &offset)
Stretches the end points of this entity that are inside area by offset.
Definition REntityData.cpp:740
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint, Qt::KeyboardModifiers modifiers=Qt::NoModifier)=0
Moves the given reference point to the given target point or does nothing if this entity has no refer...
virtual bool intersectsWith(const RShape &shape) const
Definition REntityData.cpp:582
virtual bool mirror(const RLine &axis)
Definition REntityData.cpp:715
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition REntityData.cpp:685
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition REntityData.cpp:313
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty).
Definition REntityData.h:415
virtual RColor getColor() const
Definition REntityData.h:312
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition REntityData.cpp:695
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false, QList< RObject::Id > *entityIds=NULL) const
Definition REntityData.h:111
Base class for all entity classes.
Definition REntity.h:63
Stores and manages all data that defines the geometry and appearance of a hatch or solid fill entity.
Definition RHatchData.h:51
RPattern pattern
Custom pattern loaded from DXF file, not LIN file.
Definition RHatchData.h:293
bool getAutoRegen() const
Definition RHatchData.h:130
virtual RShape * castToShape()
Definition RHatchData.h:105
bool hasCustomPattern() const
Definition RHatchData.h:70
QList< QList< QSharedPointer< RShape > > > boundary
Hatch boundary, ordered by loops, in strictly defined order.
Definition RHatchData.h:287
double gotPixelSizeHint
Definition RHatchData.h:299
void setWinding(bool on)
Definition RHatchData.h:125
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition RHatchData.h:82
void setSolid(bool on)
Definition RHatchData.h:116
virtual RColor getColor() const
Definition RHatchData.h:233
virtual RColor getColor(bool resolve, const QStack< QSharedPointer< REntity > > &blockRefStack) const
Definition RHatchData.h:244
RPattern getCustomPattern() const
Definition RHatchData.h:74
bool solid
Definition RHatchData.h:275
bool isSolid() const
Definition RHatchData.h:112
double getScale() const
Definition RHatchData.h:139
void setOriginPoint(const RVector &op, bool clearCustom=true)
Definition RHatchData.h:161
void setAutoRegen(bool on)
Definition RHatchData.h:134
virtual RColor getColor(const RColor &unresolvedColor, const QStack< QSharedPointer< REntity > > &blockRefStack) const
Definition RHatchData.h:239
void setPattern(const RPattern &p)
Definition RHatchData.h:229
int getTransparency() const
Definition RHatchData.h:177
bool isWinding() const
Definition RHatchData.h:121
void setTransparency(int t)
Definition RHatchData.h:181
void setAngle(double a)
Definition RHatchData.h:152
double scaleFactor
Definition RHatchData.h:278
QList< QList< QSharedPointer< RShape > > > getBoundary() const
Definition RHatchData.h:201
double getAngle() const
Definition RHatchData.h:148
QString getPatternName() const
Definition RHatchData.h:168
void autoCloseLoops()
Definition RHatchData.h:221
double angle
Definition RHatchData.h:279
static void setHatchProxy(RHatchProxy *p)
Definition RHatchData.h:257
void setScale(double s)
Definition RHatchData.h:143
RVector originPoint
Definition RHatchData.h:281
bool dirty
Definition RHatchData.h:297
RVector getOriginPoint() const
Definition RHatchData.h:157
void addBoundaryShape(QSharedPointer< RShape > shape, int loop)
Definition RHatchData.h:193
static RHatchProxy * hatchProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RHatchData.h:301
bool winding
Definition RHatchData.h:276
virtual RS::EntityType getType() const
Definition RHatchData.h:63
int transparency
Definition RHatchData.h:282
int getLoopCount() const
Definition RHatchData.h:213
bool autoRegen
Definition RHatchData.h:277
QList< RPainterPath > painterPaths
Definition RHatchData.h:296
RPainterPath boundaryPath
Definition RHatchData.h:295
static RHatchProxy * getHatchProxy()
Definition RHatchData.h:267
QString patternName
Definition RHatchData.h:280
static bool hasProxy()
Definition RHatchData.h:250
void setCustomPattern(const RPattern &p)
Definition RHatchData.h:78
void setPatternName(const QString &n)
Definition RHatchData.h:172
bool gotDraft
Definition RHatchData.h:298
Point entity.
Definition RHatchEntity.h:43
Proxy for advanced hatch functionality.
Definition RHatchProxy.h:35
Low-level mathematical representation of a line.
Definition RLine.h:41
Extended painter path with a z-level and a pen.
Definition RPainterPath.h:48
Interface for entity data classes that can deliver painter paths.
Definition RPainterPathSource.h:40
virtual QList< RPainterPath > getPainterPaths(bool draft=false, double pixelSizeHint=RDEFAULT_MIN1) const =0
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RPattern.h:38
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
Represents a reference point of an entity.
Definition RRefPoint.h:18
EntityType
Entity types used for property handling / filtering.
Definition RS.h:227
@ EntityHatch
Hatch.
Definition RS.h:273
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition RS.h:293
@ RenderTop
Definition RS.h:294
Interface for geometrical shape classes.
Definition RShape.h:72
Represents a 3d vector (x/y/z).
Definition RVector.h:47
#define QCADENTITY_EXPORT
Definition entity_global.h:10
char s
Definition opennurbs_string.cpp:32
#define NULL
Definition opennurbs_system.h:256