QCAD
Open Source 2D CAD
REntityData.h
Go to the documentation of this file.
1 
20 #ifndef RENTITYDATA_H
21 #define RENTITYDATA_H
22 
23 #include "core_global.h"
24 
25 #include <QList>
26 #include <QStack>
27 
28 #include "RBlock.h"
29 #include "RBox.h"
30 #include "RColor.h"
31 #include "RLayer.h"
32 #include "RLine.h"
33 #include "RMatrix.h"
34 #include "RObject.h"
35 #include "RPolyline.h"
36 #include "RRefPoint.h"
37 #include "RSettings.h"
38 #include "RView.h"
39 
41 class RDocument;
42 class REntity;
43 class RExporter;
44 
45 #ifndef RDEFAULT_QSET_INT
46 #define RDEFAULT_QSET_INT QSet<int>()
47 #endif
48 
49 #ifndef RDEFAULT_TOLERANCE_1E_MIN4
50 #define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
51 #endif
52 
66 
67  friend class REntity;
68 
69 public:
71 
72  virtual ~REntityData() {}
73 
75  return document;
76  }
77 
78  const RDocument* getDocument() const {
79  return document;
80  }
81 
83  this->document = document;
84  }
85 
86  virtual RS::EntityType getType() const {
87  return RS::EntityUnknown;
88  }
89 
90  virtual bool isValid() const {
91  return true;
92  }
93  virtual bool isSane() const {
94  return true;
95  }
96 
104  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const {
105  Q_UNUSED(queryBox)
106  Q_UNUSED(ignoreComplex)
107  Q_UNUSED(segment)
108 
109  return QList<QSharedPointer<RShape> >();
110  }
111 
116  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const;
117 
118  virtual RShape* castToShape() {
119  return NULL;
120  }
121 
125  virtual const RShape* castToConstShape() const {
126  return const_cast<REntityData*>(this)->castToShape();
127  }
128 
129  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
130 
131  virtual void to2D();
132 
140  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
141  return QList<RBox>() << getBoundingBox(ignoreEmpty);
142  }
143 
144  virtual RPolyline getHull(double offset) const;
145 
149  virtual bool isUpdatesEnabled() const {
150  return updatesEnabled;
151  }
152 
156  void setUpdatesEnabled(bool on) {
157  updatesEnabled = on;
158  }
159 
163  virtual bool cloneOnChange() const {
164  return false;
165  }
166 
171  virtual bool isSelected() const {
172  return selectionStatus;
173  }
174 
178  virtual void setSelected(bool on) {
179  selectionStatus = on;
180  }
181 
186  virtual int getDrawOrder() const {
187  return drawOrder;
188  }
189 
193  virtual void setDrawOrder(int drawOrder) {
194  this->drawOrder = drawOrder;
195  }
196 
197  virtual void setLayerId(RLayer::Id layerId) {
198  this->layerId = layerId;
199  }
200 
202  return layerId;
203  }
204 
205  QString getLayerName() const;
206 
207  virtual void setBlockId(RBlock::Id blockId) {
208  this->blockId = blockId;
209  }
210 
212  return blockId;
213  }
214 
215  virtual void setParentId(RObject::Id parentId) {
216  this->parentId = parentId;
217  }
218 
223  return parentId;
224  }
225 
226  QString getBlockName() const;
227 
232  virtual void setLinetypeId(RLinetype::Id linetypeId) {
233  this->linetypeId = linetypeId;
234  }
235 
239  virtual RLinetype::Id getLinetypeId() const {
240  return linetypeId;
241  }
242 
243  virtual void setLinetypePattern(const RLinetypePattern& p);
244  virtual RLinetypePattern getLinetypePattern() const;
245 
246  virtual RLinetype::Id getLinetypeId(bool resolve,
247  const QStack<REntity*>& blockRefStack) const;
248 
249  virtual void setLinetypeScale(double linetypeScale) {
250  this->linetypeScale = linetypeScale;
251  }
252 
253  virtual double getLinetypeScale() const {
254  return linetypeScale;
255  }
256 
258  return lineweight;
259  }
260 
261  virtual RLineweight::Lineweight getLineweight(bool resolve,
262  const QStack<REntity*>& blockRefStack) const;
263 
264  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
265 
267  this->lineweight = lineweight;
268 // if (RSettings::getAutoScaleLinetypePattern()) {
269 // this->linetypeScale = lineweight;
270 // }
271  }
272 
273  void setColor(const RColor& color) {
274  this->color = color;
275  }
276 
277  virtual RColor getColor() const {
278  return color;
279  }
280 
281  virtual RColor getColor(bool resolve, const QStack<REntity *>& blockRefStack) const;
282 
284  QStack<REntity*> stack;
285  return getColor(true, stack);
286  }
287 
295  return getReferencePoints(hint);
296  }
297 
303  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const = 0;
304 
305  virtual RVector getPointOnEntity() const;
306  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const;
307  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const;
308  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const;
309  virtual QList<RVector> getPointsWithDistanceToEnd(
310  double distance, int from = RS::FromAny, const RBox& queryBox = RDEFAULT_RBOX) const;
311 
312  virtual RVector getClosestPointOnEntity(const RVector& point,
313  double range=RNANDOUBLE, bool limited=true) const;
314 
315 // /**
316 // * Override to disable intersection point
317 // */
318 // virtual bool intersectionsEnabled() {
319 // return true;
320 // }
321 
322  virtual QList<RVector> getIntersectionPoints(
323  const REntityData& other, bool limited = true, bool same = false,
324  const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
325  virtual QList<RVector> getIntersectionPoints(
326  const RShape& shape, bool limited = true,
327  const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
328 
329  virtual RVector getVectorTo(const RVector& point, bool limited=true, double strictRange = RMAXDOUBLE) const;
330 
331  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
332 
337  virtual bool isInside(const RBox& box) const {
338  return box.contains(getBoundingBox());
339  }
340 
341  virtual bool isOnEntity(const RVector& point, bool limited = true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
342 
343  virtual bool intersectsWith(const RShape& shape) const;
344 
352  virtual bool moveReferencePoint(
353  const RVector& referencePoint, const RVector& targetPoint
354  ) = 0;
355 
356  virtual bool move(const RVector& offset);
357  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
358  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
359  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
360  virtual void scaleVisualProperties(double scaleFactor);
361  virtual bool mirror(const RLine& axis);
362  virtual bool mirror(const RVector& axis1, const RVector& axis2);
363  virtual bool flipHorizontal();
364  virtual bool flipVertical();
365  virtual bool stretch(const RPolyline& area, const RVector& offset);
366 
371  virtual void update() const {}
372  void setAutoUpdatesBlocked(bool on);
373 
374  static int getDefaultDrawOrder() {
375  return RMININT;
376  }
377 
378 protected:
392 };
393 
396 Q_DECLARE_METATYPE(QSharedPointer<REntityData>)
397 Q_DECLARE_METATYPE(QSharedPointer<REntityData>*)
398 
399 #endif
RObject::Id getParentId() const
Definition: REntityData.h:222
virtual bool isOnEntity(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: REntity.h:391
RDocument * getDocument()
Definition: REntityData.h:74
Represents a box e.g.
Definition: RBox.h:43
RBlock::Id getBlockId() const
Definition: REntityData.h:211
Base class for all entity data classes.
Definition: REntityData.h:65
RDocument * document
Definition: REntityData.h:379
void setLineweight(RLineweight::Lineweight lineweight)
Definition: REntityData.h:266
virtual void setLayerId(RLayer::Id layerId)
Definition: REntityData.h:197
RLineweight::Lineweight getLineweight() const
Definition: REntity.h:293
Unknown entity.
Definition: RS.h:89
virtual void to2D()
Definition: REntity.h:335
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual RShape * castToShape()
Definition: REntity.h:584
virtual QSharedPointer< RShape > getClosestShape(const RVector &pos, double range=RNANDOUBLE, bool ignoreComplex=false) const
Definition: REntity.h:370
#define RDEFAULT_RBOX
Definition: RBox.h:32
virtual RLineweight::Lineweight getLineweight() const
Definition: REntityData.h:257
virtual RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntity.h:461
RLinetype::Id linetypeId
Definition: REntityData.h:388
virtual bool flipVertical()
Definition: REntity.h:563
virtual RColor getDisplayColor()
Definition: REntityData.h:283
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:454
virtual RColor getColor() const
Definition: REntityData.h:277
virtual bool isSane() const
Definition: REntityData.h:93
QString getBlockName() const
Definition: REntity.h:224
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:76
virtual bool stretch(const RPolyline &area, const RVector &offset)
Stretches the end points of this entity that are inside area by offset.
Definition: REntity.h:570
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntity.h:328
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:104
virtual void setLinetypeScale(double linetypeScale)
Definition: REntityData.h:249
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint)
Moves the given reference point to the given target point or does nothing if this entity has no refer...
Definition: REntity.h:498
const RDocument * getDocument() const
Definition: REntityData.h:78
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:18
virtual bool isSelected() const
Definition: REntityData.h:171
#define QCADCORE_EXPORT
Definition: core_global.h:10
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:85
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:405
int Id
Definition: RObject.h:57
virtual RS::EntityType getType() const
Definition: REntityData.h:86
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition: REntityData.h:140
virtual void setSelected(bool on)
Selects or deselects this entity.
Definition: REntityData.h:178
RColor getColor() const
Definition: REntity.h:312
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLinetypePattern.h:45
bool updatesEnabled
Definition: REntityData.h:380
virtual RLinetype::Id getLinetypeId() const
Definition: REntityData.h:239
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:203
virtual RVector getPointOnEntity() const
Definition: REntity.h:433
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:131
#define RMININT
Definition: RMath.h:68
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
virtual const RShape * castToConstShape() const
Definition: REntityData.h:125
RLineweight::Lineweight lineweight
Definition: REntityData.h:390
double linetypeScale
Definition: REntityData.h:389
void setLinetypePattern(const RLinetypePattern &linetypePattern)
Definition: REntity.h:245
virtual void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition: REntityData.h:193
Base class for all entity classes.
Definition: REntity.h:64
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:412
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:109
virtual bool isInside(const RBox &box) const
Definition: REntityData.h:337
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:447
virtual double getLinetypeScale() const
Definition: REntityData.h:253
virtual void setAutoUpdatesBlocked(bool on)
Definition: REntity.h:607
#define RMAXDOUBLE
Definition: RMath.h:63
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:71
virtual int getDrawOrder() const
Definition: REntityData.h:186
double getLineweightInUnits(const QStack< REntity * > &blockRefStack) const
Definition: REntity.cpp:134
bool autoUpdatesBlocked
Block auto updates is true during imports, undo and redo.
Definition: REntityData.h:383
virtual void setLinetypeId(RLinetype::Id linetypeId)
Sets the linetype of this entity to the given linetype ID.
Definition: REntityData.h:232
void getIntersectionPoints(void e1, void e2, void limited)
Returns intersection points between the two given entities or shapes.
Definition: simple_info.js:12
virtual void scaleVisualProperties(double scaleFactor)
Definition: REntity.h:535
RLinetype::Id getLinetypeId() const
Definition: REntity.h:252
Low-level mathematical representation of a line.
Definition: RLine.h:41
QString getLayerName() const
Definition: REntity.h:203
Definition: RS.h:132
virtual bool isUpdatesEnabled() const
Definition: REntityData.h:149
RObject::Id parentId
Definition: REntityData.h:387
void setUpdatesEnabled(bool on)
Enables / disables cache updates.
Definition: REntityData.h:156
Abstract base class for exporters.
Definition: RExporter.h:71
int drawOrder
Definition: REntityData.h:384
RLayer::Id layerId
Definition: REntityData.h:385
virtual QList< RRefPoint > getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Can be overwritten to return internal, resolved reference points.
Definition: REntityData.h:294
static int getDefaultDrawOrder()
Definition: REntityData.h:374
virtual ~REntityData()
Definition: REntityData.h:72
RColor color
Definition: REntityData.h:391
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:470
virtual RShape * castToShape()
Definition: REntityData.h:118
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
RBlock::Id blockId
Definition: REntityData.h:386
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Definition: REntity.h:426
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: REntityData.h:50
RLayer::Id getLayerId() const
Definition: REntityData.h:201
virtual void setBlockId(RBlock::Id blockId)
Definition: REntityData.h:207
Block reference entity.
Definition: RBlockReferenceEntity.h:38
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool isValid() const
Definition: REntityData.h:90
virtual bool flipHorizontal()
Definition: REntity.h:556
bool contains(const RBox &other) const
Definition: RBox.cpp:229
virtual bool intersectsWith(const RShape &shape) const
Definition: REntity.h:398
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:371
virtual RPolyline getHull(double offset) const
Definition: REntity.h:349
RLinetypePattern getLinetypePattern() const
Definition: REntity.h:262
void setColor(const RColor &color)
Definition: REntityData.h:273
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: REntityData.h:163
void setDocument(RDocument *document)
Definition: REntityData.h:82
virtual void setParentId(RObject::Id parentId)
Definition: REntityData.h:215
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:440
bool selectionStatus
Definition: REntityData.h:381
RDocument * document
Definition: RObject.h:271