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  bool hasCustomPattern() const {
59  return !pattern.getPatternLines().isEmpty();
60  }
61 
63  return pattern;
64  }
65 
66  virtual bool cloneOnChange() const {
67  // force clone to preserve custom pattern for undo:
68  return hasCustomPattern();
69  }
70 
71  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
72 
73  virtual RVector getPointOnEntity() const;
74  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
75  virtual bool intersectsWith(const RShape& shape) const;
76 
77  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
78 
79  virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint);
80 
81  virtual bool move(const RVector& offset);
82  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
83  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
84  virtual bool mirror(const RLine& axis);
85  virtual bool stretch(const RPolyline& area, const RVector& offset);
86 
87  virtual RShape* castToShape() {
88  return NULL;
89  }
90 
91  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false) const;
92  virtual QList<QSharedPointer<RShape> > getExploded() const;
93 
94  bool isSolid() const {
95  return solid;
96  }
97 
98  void setSolid(bool on) {
99  solid = on;
101  }
102 
103  double getScale() const {
104  return scaleFactor;
105  }
106 
107  void setScale(double s) {
108  scaleFactor = s;
110  }
111 
112  double getAngle() const {
113  return angle;
114  }
115 
116  void setAngle(double a) {
117  angle = a;
119  }
120 
122  return originPoint;
123  }
124 
125  void setOriginPoint(const RVector& op) {
126  originPoint = op;
128  }
129 
130  QString getPatternName() const {
131  return patternName;
132  }
133 
134  void setPatternName(const QString& n) {
135  patternName = n;
137  }
138 
140  pattern.clear();
141  update();
142  }
143 
144  void newLoop();
145  void cancelLoop();
146  void addBoundary(QSharedPointer<RShape> shape);
147  RPainterPath getBoundaryPath(double pixelSizeHint = RDEFAULT_MIN1) const;
148  virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
149 
150  QList<QList<QSharedPointer<RShape> > > getBoundary() const {
151  return boundary;
152  }
153 
157  QPair<QSharedPointer<RShape>, QSharedPointer<RShape> > getBoundaryElementsAt(int index, int& internalIndex) const;
158 
159  virtual void update() const;
160  bool order();
161 
162  int getLoopCount() const {
163  return boundary.count();
164  }
165 
166  QList<QSharedPointer<RShape> > getLoopBoundary(int index) const;
167 
168  QList<RPolyline> getBoundaryAsPolylines(double segmentLength) const;
169 
170  int getComplexity() const;
171 
172  void setPattern(const RPattern& p) {
173  pattern = p;
174  }
175 
176  static bool hasProxy() {
177  return hatchProxy!=NULL;
178  }
179 
183  static void setHatchProxy(RHatchProxy* p) {
184  if (hatchProxy!=NULL) {
185  delete hatchProxy;
186  }
187  hatchProxy = p;
188  }
189 
194  return hatchProxy;
195  }
196 
197 protected:
198  QList<RLine> getSegments(const RLine& line) const;
199 
200 private:
201  bool solid;
202  double scaleFactor;
203  double angle;
204  QString patternName;
206 
210  QList<QList<QSharedPointer<RShape> > > boundary;
211 
212  // custom pattern loaded from DXF file, not LIN file:
213  mutable RPattern pattern;
214 
216  mutable QList<RPainterPath> painterPaths;
217  mutable bool dirty;
218  mutable bool gotDraft;
219  mutable double gotPixelSizeHint;
220 
222 };
223 
227 Q_DECLARE_METATYPE(QSharedPointer<RHatchData>)
228 
229 #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:87
virtual RVector getPointOnEntity() const
Definition: REntityData.cpp:288
double scaleFactor
Definition: RHatchData.h:202
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:519
bool hasCustomPattern() const
Definition: RHatchEntity.h:88
virtual QList< QSharedPointer< RShape > > getExploded() const
Definition: RHatchEntity.h:192
RVector originPoint
Definition: RHatchData.h:205
void setScale(double s)
Definition: RHatchData.h:107
double gotPixelSizeHint
Definition: RHatchData.h:219
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:210
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntityData.cpp:479
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:201
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:103
QList< QList< QSharedPointer< RShape > > > getBoundary() const
Definition: RHatchData.h:150
static void setHatchProxy(RHatchProxy *p)
Definition: RHatchData.h:183
RPattern getCustomPattern() const
Definition: RHatchData.h:62
QString patternName
Definition: RHatchData.h:204
virtual bool intersectsWith(const RShape &shape) const
Definition: REntityData.cpp:418
void addBoundary(QSharedPointer< RShape > shape)
Definition: RHatchEntity.h:127
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:129
QList< RPolyline > getBoundaryAsPolylines(double segmentLength) const
Definition: RHatchEntity.h:183
void setPattern(const RPattern &p)
Definition: RHatchData.h:172
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:499
RVector getOriginPoint() const
Definition: RHatchData.h:121
void setAngle(double a)
Definition: RHatchData.h:116
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:216
Q_DECLARE_METATYPE(RMath *)
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RHatchData.h:44
QString getPatternName() const
Definition: RHatchData.h:130
void setSolid(bool on)
Definition: RHatchData.h:98
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:489
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:162
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:544
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false) const
Definition: REntityData.h:89
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
void setPatternName(const QString &n)
Definition: RHatchData.h:134
static bool hasProxy()
Definition: RHatchData.h:176
Low-level mathematical representation of a line.
Definition: RLine.h:42
Definition: RS.h:130
#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:139
bool isSolid() const
Definition: RHatchData.h:94
RPainterPath boundaryPath
Definition: RHatchData.h:215
Point entity.
Definition: RHatchEntity.h:38
double angle
Definition: RHatchData.h:203
RPattern pattern
Definition: RHatchData.h:213
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:50
bool hasCustomPattern() const
Definition: RHatchData.h:58
bool gotDraft
Definition: RHatchData.h:218
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: RHatchData.h:66
static RHatchProxy * hatchProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RHatchData.h:221
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:346
Proxy for advanced hatch functionality.
Definition: RHatchProxy.h:35
bool dirty
Definition: RHatchData.h:217
void setOriginPoint(const RVector &op)
Definition: RHatchData.h:125
static RHatchProxy * getHatchProxy()
Definition: RHatchData.h:193
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
double getAngle() const
Definition: RHatchData.h:112
RDocument * document
Definition: RObject.h:267