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  void setCustomPattern(const RPattern& p) {
72  pattern = p;
73  }
74 
75  virtual bool cloneOnChange() const {
76  // force clone to preserve custom pattern for undo:
77  //return hasCustomPattern();
78  // 20190510: always clone (since allowing non-uniform scaling of hatches)
79  return true;
80  }
81 
82  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
83 
84  virtual RVector getPointOnEntity() const;
85  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
86  virtual bool intersectsWith(const RShape& shape) const;
87 
88  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint = RS::RenderTop) const;
89 
90  virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
91 
92  virtual bool move(const RVector& offset);
93  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
94  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
95  virtual bool mirror(const RLine& axis);
96  virtual bool stretch(const RPolyline& area, const RVector& offset);
97 
98  virtual RShape* castToShape() {
99  return NULL;
100  }
101 
102  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const;
103  virtual QList<QSharedPointer<RShape> > getExploded() const;
104 
105  bool isSolid() const {
106  return solid;
107  }
108 
109  void setSolid(bool on) {
110  solid = on;
112  }
113 
114  double getScale() const {
115  return scaleFactor;
116  }
117 
118  void setScale(double s) {
119  scaleFactor = s;
121  }
122 
123  double getAngle() const {
124  return angle;
125  }
126 
127  void setAngle(double a) {
128  angle = a;
130  }
131 
133  return originPoint;
134  }
135 
136  void setOriginPoint(const RVector& op, bool clearCustom = true) {
137  originPoint = op;
138  if (clearCustom) {
140  }
141  }
142 
143  QString getPatternName() const {
144  return patternName;
145  }
146 
147  void setPatternName(const QString& n) {
148  patternName = n;
150  }
151 
152  int getTransparency() const {
153  return transparency;
154  }
155 
156  void setTransparency(int t) {
157  transparency = t;
158  }
159 
160  void clearCustomPattern();
161 
162  void newLoop();
163  void cancelLoop();
164  void addBoundary(QSharedPointer<RShape> shape, bool addAutoLoops = true);
165  RPainterPath getBoundaryPath(double pixelSizeHint = RDEFAULT_MIN1) const;
166  virtual QList<RPainterPath> getPainterPaths(bool draft = false, double pixelSizeHint = RDEFAULT_MIN1) const;
167 
168  QList<QList<QSharedPointer<RShape> > > getBoundary() const {
169  return boundary;
170  }
171 
175  QPair<QSharedPointer<RShape>, QSharedPointer<RShape> > getBoundaryElementsAt(int index, int& internalIndex) const;
176 
177  virtual void update() const;
178  bool order();
179 
180  int getLoopCount() const {
181  return boundary.count();
182  }
183 
184  QList<QSharedPointer<RShape> > getLoopBoundary(int index) const;
185 
186  QList<RPolyline> getBoundaryAsPolylines(double segmentLength) const;
187 
188  int getComplexity() const;
189 
190  void setPattern(const RPattern& p) {
191  pattern = p;
192  }
193 
194  virtual RColor getColor() const {
196  c.setAlpha(transparency);
197  return c;
198  }
199 
200  virtual RColor getColor(const RColor& unresolvedColor, const QStack<REntity *>& blockRefStack) const {
201  RColor c = REntityData::getColor(unresolvedColor, blockRefStack);
202  c.setAlpha(transparency);
203  return c;
204  }
205  virtual RColor getColor(bool resolve, const QStack<REntity *>& blockRefStack) const {
206  RColor c = REntityData::getColor(resolve, blockRefStack);
207  c.setAlpha(transparency);
208  return c;
209  }
210 
211  static bool hasProxy() {
212  return hatchProxy!=NULL;
213  }
214 
218  static void setHatchProxy(RHatchProxy* p) {
219  if (hatchProxy!=NULL) {
220  delete hatchProxy;
221  }
222  hatchProxy = p;
223  }
224 
229  return hatchProxy;
230  }
231 
232 protected:
233  QList<RLine> getSegments(const RLine& line) const;
234 
235 private:
236  bool solid;
237  double scaleFactor;
238  double angle;
239  QString patternName;
242 
246  QList<QList<QSharedPointer<RShape> > > boundary;
247 
252  mutable RPattern pattern;
253 
255  mutable QList<RPainterPath> painterPaths;
256  mutable bool dirty;
257  mutable bool gotDraft;
258  mutable double gotPixelSizeHint;
259 
261 };
262 
266 Q_DECLARE_METATYPE(QSharedPointer<RHatchData>)
267 
268 #endif
RHatchEntity::clearCustomPattern
void clearCustomPattern()
Definition: RHatchEntity.h:185
REntity.h
RPainterPathSource
Interface for entity data classes that can deliver painter paths.
Definition: RPainterPathSource.h:40
REntityData::update
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty).
Definition: REntityData.h:408
RHatchData::patternName
QString patternName
Definition: RHatchData.h:239
REntityData::stretch
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:636
RHatchEntity::addBoundary
void addBoundary(QSharedPointer< RShape > shape)
Definition: RHatchEntity.h:129
RHatchData
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RHatchData.h:44
RHatchData::getPatternName
QString getPatternName() const
Definition: RHatchData.h:143
RPainterPathSource.h
RHatchData::painterPaths
QList< RPainterPath > painterPaths
Definition: RHatchData.h:255
REntityData::getBoundingBox
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntityData.cpp:303
RBox.h
RHatchData::solid
bool solid
Definition: RHatchData.h:236
RHatchData::gotPixelSizeHint
double gotPixelSizeHint
Definition: RHatchData.h:258
RHatchEntity::getComplexity
virtual int getComplexity() const
Definition: RHatchEntity.h:121
RHatchData::setOriginPoint
void setOriginPoint(const RVector &op, bool clearCustom=true)
Definition: RHatchData.h:136
RHatchData::setCustomPattern
void setCustomPattern(const RPattern &p)
Definition: RHatchData.h:71
RHatchData::getColor
virtual RColor getColor(bool resolve, const QStack< REntity * > &blockRefStack) const
Definition: RHatchData.h:205
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
REntityData::intersectsWith
virtual bool intersectsWith(const RShape &shape) const
Definition: REntityData.cpp:499
RHatchData::getBoundary
QList< QList< QSharedPointer< RShape > > > getBoundary() const
Definition: RHatchData.h:168
RHatchEntity::data
RHatchData data
Definition: RHatchEntity.h:211
RHatchEntity::getPainterPaths
QList< RPainterPath > getPainterPaths(bool draft=false, double pixelSizeHint=0.0) const
Definition: RHatchEntity.h:117
RS::EntityType
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:125
RHatchData::boundaryPath
RPainterPath boundaryPath
Definition: RHatchData.h:254
RHatchData::gotDraft
bool gotDraft
Definition: RHatchData.h:257
RHatchData::pattern
RPattern pattern
Custom pattern loaded from DXF file, not LIN file.
Definition: RHatchData.h:252
RHatchData::boundary
QList< QList< QSharedPointer< RShape > > > boundary
Hatch boundary, ordered by loops, in strictly defined order.
Definition: RHatchData.h:246
RLine.h
RHatchData::angle
double angle
Definition: RHatchData.h:238
RObject::document
RDocument * document
Definition: RObject.h:341
RHatchData::getLoopCount
int getLoopCount() const
Definition: RHatchData.h:180
RHatchData::getCustomPattern
RPattern getCustomPattern() const
Definition: RHatchData.h:67
RHatchEntity::getBoundaryAsPolylines
QList< RPolyline > getBoundaryAsPolylines(double segmentLength) const
Definition: RHatchEntity.h:193
RHatchData::hasCustomPattern
bool hasCustomPattern() const
Definition: RHatchData.h:63
QCADENTITY_EXPORT
#define QCADENTITY_EXPORT
Definition: entity_global.h:10
RHatchData::getHatchProxy
static RHatchProxy * getHatchProxy()
Definition: RHatchData.h:228
RHatchData::hasProxy
static bool hasProxy()
Definition: RHatchData.h:211
RHatchData::cloneOnChange
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: RHatchData.h:75
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RHatchProxy.h
RShape
Interface for geometrical shape classes.
Definition: RShape.h:72
RHatchData::getType
virtual RS::EntityType getType() const
Definition: RHatchData.h:56
RHatchData::getAngle
double getAngle() const
Definition: RHatchData.h:123
RPoint.h
RHatchProxy
Proxy for advanced hatch functionality.
Definition: RHatchProxy.h:35
RDEFAULT_RVECTOR
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
RDocument.h
RVector.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RPattern
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RPattern.h:44
RHatchData::castToShape
virtual RShape * castToShape()
Definition: RHatchData.h:98
REntityData::getReferencePoints
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
RHatchData::scaleFactor
double scaleFactor
Definition: RHatchData.h:237
REntityData
Base class for all entity data classes.
Definition: REntityData.h:67
RPattern.h
RDEFAULT_MIN1
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RExplodable.h:30
RHatchData::hatchProxy
static RHatchProxy * hatchProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RHatchData.h:260
RHatchData::setSolid
void setSolid(bool on)
Definition: RHatchData.h:109
RHatchEntity
Point entity.
Definition: RHatchEntity.h:38
RPainterPath
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
RS::EntityHatch
@ EntityHatch
Hatch.
Definition: RS.h:169
RHatchData::setPatternName
void setPatternName(const QString &n)
Definition: RHatchData.h:147
RDocument
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition: RDocument.h:72
REntityData::move
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntityData.cpp:571
RHatchData::transparency
int transparency
Definition: RHatchData.h:241
RHatchData::getScale
double getScale() const
Definition: RHatchData.h:114
RMAXDOUBLE
#define RMAXDOUBLE
Definition: RMath.h:63
REntityData::scale
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:591
RHatchData::setTransparency
void setTransparency(int t)
Definition: RHatchData.h:156
REntityData::mirror
virtual bool mirror(const RLine &axis)
Definition: REntityData.cpp:611
RHatchEntity::getLoopBoundary
QList< QSharedPointer< RShape > > getLoopBoundary(int index) const
Definition: RHatchEntity.h:189
RHatchData::setAngle
void setAngle(double a)
Definition: RHatchData.h:127
REntityData::rotate
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntityData.cpp:581
RHatchData::isSolid
bool isSolid() const
Definition: RHatchData.h:105
RHatchData::getColor
virtual RColor getColor(const RColor &unresolvedColor, const QStack< REntity * > &blockRefStack) const
Definition: RHatchData.h:200
RHatchData::setScale
void setScale(double s)
Definition: RHatchData.h:118
REntityData::getColor
virtual RColor getColor() const
Definition: REntityData.h:304
RS::ProjectionRenderingHint
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:185
RDEFAULT_RBOX
#define RDEFAULT_RBOX
Definition: RBox.h:32
REntityData::getPointOnEntity
virtual RVector getPointOnEntity() const
Definition: REntityData.cpp:362
RHatchData::setPattern
void setPattern(const RPattern &p)
Definition: RHatchData.h:190
RHatchData::dirty
bool dirty
Definition: RHatchData.h:256
RHatchData::setHatchProxy
static void setHatchProxy(RHatchProxy *p)
Definition: RHatchData.h:218
REntityData::getShapes
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:113
RHatchEntity::getExploded
virtual QList< QSharedPointer< RShape > > getExploded() const
Definition: RHatchEntity.h:201
RHatchData::getColor
virtual RColor getColor() const
Definition: RHatchData.h:194
RS::RenderTop
@ RenderTop
Definition: RS.h:186
RBox
Represents a box e.g.
Definition: RBox.h:43
REntityData::getDistanceTo
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntityData.cpp:289
entity_global.h
RPainterPath.h
RHatchEntity::newLoop
void newLoop()
Definition: RHatchEntity.h:125
RPolyline
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
RHatchData::originPoint
RVector originPoint
Definition: RHatchData.h:240
REntityData::moveReferencePoint
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...
RHatchData::getTransparency
int getTransparency() const
Definition: RHatchData.h:152
RColor
Color.
Definition: RColor.h:44
RHatchData::getOriginPoint
RVector getOriginPoint() const
Definition: RHatchData.h:132