QCAD
Open Source 2D CAD
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 "RDocument.h"
27 #include "REntity.h"
28 #include "RHatchProxy.h"
29 #include "RLine.h"
30 #include "RPattern.h"
31 #include "RPainterPath.h"
32 #include "RPainterPathSource.h"
33 #include "RPoint.h"
34 #include "RVector.h"
35 
45 
46  friend class RHatchEntity;
47 
48 protected:
50 
51 public:
52  RHatchData();
53  RHatchData(const RHatchData& other);
54  RHatchData(bool solid, double scaleFactor, double angle, const QString& patternName);
55 
56  RHatchData& operator=(const RHatchData& other);
57 
58  void clearBoundary();
59 
60  bool hasCustomPattern() const {
61  return !pattern.getPatternLines().isEmpty();
62  }
63 
65  return pattern;
66  }
67 
68  virtual bool cloneOnChange() const {
69  // force clone to preserve custom pattern for undo:
70  return hasCustomPattern();
71  }
72 
73  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
74 
75  virtual RVector getPointOnEntity() const;
76  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
77  virtual bool intersectsWith(const RShape& shape) const;
78 
79  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
80 
81  virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint);
82 
83  virtual bool move(const RVector& offset);
84  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
85  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
86  virtual bool mirror(const RLine& axis);
87  virtual bool stretch(const RPolyline& area, const RVector& offset);
88 
89  virtual RShape* castToShape() {
90  return NULL;
91  }
92 
93  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const;
94  virtual QList<QSharedPointer<RShape> > getExploded() const;
95 
96  bool isSolid() const {
97  return solid;
98  }
99 
100  void setSolid(bool on) {
101  solid = on;
103  }
104 
105  double getScale() const {
106  return scaleFactor;
107  }
108 
109  void setScale(double s) {
110  scaleFactor = s;
112  }
113 
114  double getAngle() const {
115  return angle;
116  }
117 
118  void setAngle(double a) {
119  angle = a;
121  }
122 
124  return originPoint;
125  }
126 
127  void setOriginPoint(const RVector& op) {
128  originPoint = op;
130  }
131 
132  QString getPatternName() const {
133  return patternName;
134  }
135 
136  void setPatternName(const QString& n) {
137  patternName = n;
139  }
140 
142  pattern.clear();
143  update();
144  }
145 
146  void newLoop();
147  void cancelLoop();
148  void addBoundary(QSharedPointer<RShape> shape);
149  RPainterPath getBoundaryPath(double pixelSizeHint = RDEFAULT_MIN1) const;
150  virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
151 
152  QList<QList<QSharedPointer<RShape> > > getBoundary() const {
153  return boundary;
154  }
155 
159  QPair<QSharedPointer<RShape>, QSharedPointer<RShape> > getBoundaryElementsAt(int index, int& internalIndex) const;
160 
161  virtual void update() const;
162  bool order();
163 
164  int getLoopCount() const {
165  return boundary.count();
166  }
167 
168  QList<QSharedPointer<RShape> > getLoopBoundary(int index) const;
169 
170  QList<RPolyline> getBoundaryAsPolylines(double segmentLength) const;
171 
172  int getComplexity() const;
173 
174  void setPattern(const RPattern& p) {
175  pattern = p;
176  }
177 
178  static bool hasProxy() {
179  return hatchProxy!=NULL;
180  }
181 
185  static void setHatchProxy(RHatchProxy* p) {
186  if (hatchProxy!=NULL) {
187  delete hatchProxy;
188  }
189  hatchProxy = p;
190  }
191 
196  return hatchProxy;
197  }
198 
199 protected:
200  QList<RLine> getSegments(const RLine& line) const;
201 
202 private:
203  bool solid;
204  double scaleFactor;
205  double angle;
206  QString patternName;
208 
212  QList<QList<QSharedPointer<RShape> > > boundary;
213 
214  // custom pattern loaded from DXF file, not LIN file:
215  mutable RPattern pattern;
216 
218  mutable QList<RPainterPath> painterPaths;
219  mutable bool dirty;
220  mutable bool gotDraft;
221  mutable double gotPixelSizeHint;
222 
224 };
225 
229 Q_DECLARE_METATYPE(QSharedPointer<RHatchData>)
230 
231 #endif
Represents a box e.g.
Definition: RBox.h:43
Base class for all entity data classes.
Definition: REntityData.h:65
virtual RShape * castToShape()
Definition: RHatchData.h:89
virtual RVector getPointOnEntity() const
Definition: REntityData.cpp:296
double scaleFactor
Definition: RHatchData.h:204
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
#define RDEFAULT_RBOX
Definition: RBox.h:32
RHatchData data
Definition: RHatchEntity.h:200
virtual bool mirror(const RLine &axis)
Definition: REntityData.cpp:534
bool hasCustomPattern() const
Definition: RHatchEntity.h:88
virtual QList< QSharedPointer< RShape > > getExploded() const
Definition: RHatchEntity.h:192
RVector originPoint
Definition: RHatchData.h:207
void setScale(double s)
Definition: RHatchData.h:109
double gotPixelSizeHint
Definition: RHatchData.h:221
virtual int getComplexity() const
Definition: RHatchEntity.h:119
#define QCADENTITY_EXPORT
Definition: entity_global.h:10
QList< QList< QSharedPointer< RShape > > > boundary
Hatch boundary, ordered by loops, in strictly defined order.
Definition: RHatchData.h:212
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:93
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntityData.cpp:494
QList< RPainterPath > getPainterPaths(bool draft=false, double pixelSizeHint=0.0) const
Definition: RHatchEntity.h:115
void newLoop()
Definition: RHatchEntity.h:123
bool solid
Definition: RHatchData.h:203
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RPattern.h:43
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntityData.cpp:248
double getScale() const
Definition: RHatchData.h:105
QList< QList< QSharedPointer< RShape > > > getBoundary() const
Definition: RHatchData.h:152
static void setHatchProxy(RHatchProxy *p)
Definition: RHatchData.h:185
RPattern getCustomPattern() const
Definition: RHatchData.h:64
QString patternName
Definition: RHatchData.h:206
virtual bool intersectsWith(const RShape &shape) const
Definition: REntityData.cpp:426
void addBoundary(QSharedPointer< RShape > shape)
Definition: RHatchEntity.h:127
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:131
QList< RPolyline > getBoundaryAsPolylines(double segmentLength) const
Definition: RHatchEntity.h:183
void setPattern(const RPattern &p)
Definition: RHatchData.h:174
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:514
RVector getOriginPoint() const
Definition: RHatchData.h:123
void setAngle(double a)
Definition: RHatchData.h:118
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntityData.cpp:262
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint)=0
Moves the given reference point to the given target point or does nothing if this entity has no refer...
QList< RPainterPath > painterPaths
Definition: RHatchData.h:218
Q_DECLARE_METATYPE(RMath *)
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RHatchData.h:44
QString getPatternName() const
Definition: RHatchData.h:132
void setSolid(bool on)
Definition: RHatchData.h:100
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:504
Interface for entity data classes that can deliver painter paths.
Definition: RPainterPathSource.h:40
#define RMAXDOUBLE
Definition: RMath.h:63
int getLoopCount() const
Definition: RHatchData.h:164
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:559
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
void setPatternName(const QString &n)
Definition: RHatchData.h:136
static bool hasProxy()
Definition: RHatchData.h:178
Low-level mathematical representation of a line.
Definition: RLine.h:41
Definition: RS.h:132
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
void clearCustomPattern()
Definition: RHatchEntity.h:175
void clearCustomPattern()
Definition: RHatchData.h:141
bool isSolid() const
Definition: RHatchData.h:96
RPainterPath boundaryPath
Definition: RHatchData.h:217
Point entity.
Definition: RHatchEntity.h:38
double angle
Definition: RHatchData.h:205
RPattern pattern
Definition: RHatchData.h:215
QList< QSharedPointer< RShape > > getLoopBoundary(int index) const
Definition: RHatchEntity.h:179
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
bool hasCustomPattern() const
Definition: RHatchData.h:60
bool gotDraft
Definition: RHatchData.h:220
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: RHatchData.h:68
static RHatchProxy * hatchProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RHatchData.h:223
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:360
Proxy for advanced hatch functionality.
Definition: RHatchProxy.h:35
bool dirty
Definition: RHatchData.h:219
void setOriginPoint(const RVector &op)
Definition: RHatchData.h:127
static RHatchProxy * getHatchProxy()
Definition: RHatchData.h:195
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
double getAngle() const
Definition: RHatchData.h:114
RDocument * document
Definition: RObject.h:271