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  virtual RS::EntityType getType() const {
57  return RS::EntityHatch;
58  }
59  RHatchData& operator=(const RHatchData& other);
60 
61  void clearBoundary();
62 
63  bool hasCustomPattern() const {
64  return !pattern.getPatternLines().isEmpty();
65  }
66 
68  return pattern;
69  }
70 
71  virtual bool cloneOnChange() const {
72  // force clone to preserve custom pattern for undo:
73  return hasCustomPattern();
74  }
75 
76  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
77 
78  virtual RVector getPointOnEntity() const;
79  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
80  virtual bool intersectsWith(const RShape& shape) const;
81 
82  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
83 
84  virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint);
85 
86  virtual bool move(const RVector& offset);
87  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
88  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
89  virtual bool mirror(const RLine& axis);
90  virtual bool stretch(const RPolyline& area, const RVector& offset);
91 
92  virtual RShape* castToShape() {
93  return NULL;
94  }
95 
96  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const;
97  virtual QList<QSharedPointer<RShape> > getExploded() const;
98 
99  bool isSolid() const {
100  return solid;
101  }
102 
103  void setSolid(bool on) {
104  solid = on;
106  }
107 
108  double getScale() const {
109  return scaleFactor;
110  }
111 
112  void setScale(double s) {
113  scaleFactor = s;
115  }
116 
117  double getAngle() const {
118  return angle;
119  }
120 
121  void setAngle(double a) {
122  angle = a;
124  }
125 
127  return originPoint;
128  }
129 
130  void setOriginPoint(const RVector& op) {
131  originPoint = op;
133  }
134 
135  QString getPatternName() const {
136  return patternName;
137  }
138 
139  void setPatternName(const QString& n) {
140  patternName = n;
142  }
143 
145  pattern.clear();
146  update();
147  }
148 
149  void newLoop();
150  void cancelLoop();
151  void addBoundary(QSharedPointer<RShape> shape);
152  RPainterPath getBoundaryPath(double pixelSizeHint = RDEFAULT_MIN1) const;
153  virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
154 
155  QList<QList<QSharedPointer<RShape> > > getBoundary() const {
156  return boundary;
157  }
158 
162  QPair<QSharedPointer<RShape>, QSharedPointer<RShape> > getBoundaryElementsAt(int index, int& internalIndex) const;
163 
164  virtual void update() const;
165  bool order();
166 
167  int getLoopCount() const {
168  return boundary.count();
169  }
170 
171  QList<QSharedPointer<RShape> > getLoopBoundary(int index) const;
172 
173  QList<RPolyline> getBoundaryAsPolylines(double segmentLength) const;
174 
175  int getComplexity() const;
176 
177  void setPattern(const RPattern& p) {
178  pattern = p;
179  }
180 
181  static bool hasProxy() {
182  return hatchProxy!=NULL;
183  }
184 
188  static void setHatchProxy(RHatchProxy* p) {
189  if (hatchProxy!=NULL) {
190  delete hatchProxy;
191  }
192  hatchProxy = p;
193  }
194 
199  return hatchProxy;
200  }
201 
202 protected:
203  QList<RLine> getSegments(const RLine& line) const;
204 
205 private:
206  bool solid;
207  double scaleFactor;
208  double angle;
209  QString patternName;
211 
215  QList<QList<QSharedPointer<RShape> > > boundary;
216 
221  mutable RPattern pattern;
222 
224  mutable QList<RPainterPath> painterPaths;
225  mutable bool dirty;
226  mutable bool gotDraft;
227  mutable double gotPixelSizeHint;
228 
230 };
231 
235 Q_DECLARE_METATYPE(QSharedPointer<RHatchData>)
236 
237 #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:92
virtual RVector getPointOnEntity() const
Definition: REntityData.cpp:309
double scaleFactor
Definition: RHatchData.h:207
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
#define RDEFAULT_RBOX
Definition: RBox.h:32
RHatchData data
Definition: RHatchEntity.h:195
virtual bool mirror(const RLine &axis)
Definition: REntityData.cpp:547
bool hasCustomPattern() const
Definition: RHatchEntity.h:84
virtual QList< QSharedPointer< RShape > > getExploded() const
Definition: RHatchEntity.h:187
RVector originPoint
Definition: RHatchData.h:210
void setScale(double s)
Definition: RHatchData.h:112
double gotPixelSizeHint
Definition: RHatchData.h:227
virtual int getComplexity() const
Definition: RHatchEntity.h:115
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
#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:215
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:104
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntityData.cpp:507
QList< RPainterPath > getPainterPaths(bool draft=false, double pixelSizeHint=0.0) const
Definition: RHatchEntity.h:111
void newLoop()
Definition: RHatchEntity.h:119
bool solid
Definition: RHatchData.h:206
Copyright (c) 2011-2017 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:261
double getScale() const
Definition: RHatchData.h:108
QList< QList< QSharedPointer< RShape > > > getBoundary() const
Definition: RHatchData.h:155
static void setHatchProxy(RHatchProxy *p)
Definition: RHatchData.h:188
RPattern getCustomPattern() const
Definition: RHatchData.h:67
QString patternName
Definition: RHatchData.h:209
virtual bool intersectsWith(const RShape &shape) const
Definition: REntityData.cpp:439
void addBoundary(QSharedPointer< RShape > shape)
Definition: RHatchEntity.h:123
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:131
QList< RPolyline > getBoundaryAsPolylines(double segmentLength) const
Definition: RHatchEntity.h:179
Hatch.
Definition: RS.h:116
void setPattern(const RPattern &p)
Definition: RHatchData.h:177
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:527
RVector getOriginPoint() const
Definition: RHatchData.h:126
void setAngle(double a)
Definition: RHatchData.h:121
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntityData.cpp:275
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:224
Q_DECLARE_METATYPE(RMath *)
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RHatchData.h:44
QString getPatternName() const
Definition: RHatchData.h:135
void setSolid(bool on)
Definition: RHatchData.h:103
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:517
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:167
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:572
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
void setPatternName(const QString &n)
Definition: RHatchData.h:139
static bool hasProxy()
Definition: RHatchData.h:181
Low-level mathematical representation of a line.
Definition: RLine.h:41
Definition: RS.h:132
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
void clearCustomPattern()
Definition: RHatchEntity.h:171
void clearCustomPattern()
Definition: RHatchData.h:144
bool isSolid() const
Definition: RHatchData.h:99
RPainterPath boundaryPath
Definition: RHatchData.h:223
Point entity.
Definition: RHatchEntity.h:38
double angle
Definition: RHatchData.h:208
RPattern pattern
Custom pattern loaded from DXF file, not LIN file.
Definition: RHatchData.h:221
QList< QSharedPointer< RShape > > getLoopBoundary(int index) const
Definition: RHatchEntity.h:175
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
bool hasCustomPattern() const
Definition: RHatchData.h:63
bool gotDraft
Definition: RHatchData.h:226
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: RHatchData.h:71
static RHatchProxy * hatchProxy
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RHatchData.h:229
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:371
Proxy for advanced hatch functionality.
Definition: RHatchProxy.h:35
bool dirty
Definition: RHatchData.h:225
void setOriginPoint(const RVector &op)
Definition: RHatchData.h:130
static RHatchProxy * getHatchProxy()
Definition: RHatchData.h:198
virtual RS::EntityType getType() const
Definition: RHatchData.h:56
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
double getAngle() const
Definition: RHatchData.h:117
RDocument * document
Definition: RObject.h:271