QCAD
Open Source 2D CAD
REntity.h
Go to the documentation of this file.
1 
20 #ifndef RENTITY_H
21 #define RENTITY_H
22 
23 #include "core_global.h"
24 
25 #include <QList>
26 #include <QStack>
27 
28 #include "RBox.h"
29 #include "RColor.h"
30 #include "RDebug.h"
31 #include "REntityData.h"
32 #include "RLayer.h"
33 #include "RLineweight.h"
34 #include "RMatrix.h"
35 #include "RObject.h"
36 #include "RPropertyAttributes.h"
37 #include "RPropertyTypeId.h"
38 #include "RVector.h"
39 #include "RExplodable.h"
40 
41 class RDocument;
42 class REntity;
44 class RExporter;
45 
46 #ifndef RDEFAULT_QSET_INT
47 #define RDEFAULT_QSET_INT QSet<int>()
48 #endif
49 
50 #ifndef RDEFAULT_TOLERANCE_1E_MIN4
51 #define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
52 #endif
53 
65 
66  Q_DECLARE_TR_FUNCTIONS(REntity)
67 
68 public:
81 
88 
89 public:
90  REntity(RDocument* document);
91  REntity(const REntity& other);
92  virtual ~REntity();
93 
94  static void init();
95 
96  static QSet<RPropertyTypeId> getStaticPropertyTypeIds() {
98  }
99 
100  void setDocument(RDocument* document) {
101  RObject::setDocument(document);
102  getData().setDocument(document);
103  }
104 
105  virtual REntity* clone() const = 0;
106 
107  virtual RS::EntityType getType() const {
108  return RS::EntityUnknown;
109  }
110 
111  static bool isComplex(const RS::EntityType type);
112  static bool isDimension(const RS::EntityType type);
113 
117  virtual REntityData& getData() = 0;
118 
122  virtual const REntityData& getData() const = 0;
123 
129 // virtual bool isPartOfBlockReference(REntity::Id blockRefId) const {
130 // Q_UNUSED(blockRefId)
131 
132 // return false;
133 // }
134 
138 // virtual bool getAutoVisualize() const {
139 // return true;
140 // }
141 
145  bool isSelected() const {
146  return getData().isSelected();
147  }
148 
149  virtual void setSelected(bool on);
150 
151  virtual bool isUpdatesEnabled() const {
152  return getData().isUpdatesEnabled();
153  }
154 
155  void setUpdatesEnabled(bool on) {
156  getData().setUpdatesEnabled(on);
157  }
158 
159  virtual bool cloneOnChange() const {
160  return getData().cloneOnChange();
161  }
162 
166  void setDrawOrder(int drawOrder) {
167  getData().setDrawOrder(drawOrder);
168  }
169 
173  int getDrawOrder() const {
174  return getData().getDrawOrder();
175  }
176 
180  void setLayerId(RLayer::Id layerId) {
181  getData().setLayerId(layerId);
182  }
183 
188  return getData().getLayerId();
189  }
190 
194  QString getLayerName() const {
195  return getData().getLayerName();
196  }
197 
201  void setBlockId(RBlock::Id blockId) {
202  getData().setBlockId(blockId);
203  }
204 
209  return getData().getBlockId();
210  }
211 
215  QString getBlockName() const {
216  return getData().getBlockName();
217  }
218 
222  void setParentId(REntity::Id parentId) {
223  getData().setParentId(parentId);
224  }
225 
230  return getData().getParentId();
231  }
232 
236  void setLinetypeId(RLinetype::Id linetypeId) {
237  getData().setLinetypeId(linetypeId);
238  }
239 
243  void setLinetypePattern(const RLinetypePattern& linetypePattern) {
244  getData().setLinetypePattern(linetypePattern);
245  }
246 
251  return getData().getLinetypeId();
252  }
253 
254  RLinetype::Id getLinetypeId(bool resolve,
255  const QStack<REntity*>& blockRefStack) const;
256 
261  return getData().getLinetypePattern();
262  }
263 
267  void setLinetypeScale(double linetypeScale) {
268  if (linetypeScale<0.0) {
269  qDebug() << "setLinetypeScale to -1";
270  }
271  getData().setLinetypeScale(linetypeScale);
272  }
273 
277  double getLinetypeScale() const {
278  return getData().getLinetypeScale();
279  }
280 
285  getData().setLineweight(lineweight);
286  }
287 
292  return getData().getLineweight();
293  }
294 
295  RLineweight::Lineweight getLineweight(bool resolve,
296  const QStack<REntity*>& blockRefStack) const;
297 
298  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
299 
303  void setColor(const RColor& color) {
304  getData().setColor(color);
305  }
306 
310  RColor getColor() const {
311  return getData().getColor();
312  }
313 
314  RColor getColor(bool resolve, const QStack<REntity*>& blockRefStack);
315 
317  return getData().getDisplayColor();
318  }
319 
320  void copyAttributesFrom(const REntity* entity, bool copyBlockId=true);
321  void copyAttributesFrom(const REntityData& entityData, bool copyBlockId=true);
322 
326  virtual RBox getBoundingBox(bool ignoreEmpty=false) const {
327  return getData().getBoundingBox(ignoreEmpty);
328  }
329 
333  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
334  return getData().getBoundingBoxes(ignoreEmpty);
335  }
336 
340  virtual RPolyline getHull(double offset) const {
341  return getData().getHull(offset);
342  }
343 
347 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
348 // return getData().getIdBoundingBoxes();
349 // }
350 
354  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false) const {
355  return getData().getShapes(queryBox, ignoreComplex);
356  }
357 
361  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const {
362  return getData().getClosestShape(pos, range, ignoreComplex);
363  }
364 
368  virtual QSharedPointer<RShape> getClosestSimpleShape(const RVector& pos, double range = RNANDOUBLE) const {
369  return getClosestShape(pos, range, true);
370  }
371 
375  virtual bool isInside(const RBox& box) const {
376  return getData().isInside(box);
377  }
378 
382  virtual bool isOnEntity(const RVector& point, bool limited=true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const {
383  return getData().isOnEntity(point, limited, tolerance);
384  }
385 
389  virtual bool intersectsWith(const RShape& shape) const {
390  return getData().intersectsWith(shape);
391  }
392 
396  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const {
397  return getData().getDistanceTo(point, limited, range, draft, strictRange);
398  }
399 
403  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const {
404  return getData().getVectorTo(point, limited, strictRange);
405  }
406 
411  return getData().getInternalReferencePoints(hint);
412  }
413 
417  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
418  return getData().getReferencePoints(hint);
419  }
420 
424  virtual RVector getPointOnEntity() const {
425  return getData().getPointOnEntity();
426  }
427 
431  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
432  return getData().getEndPoints(queryBox);
433  }
434 
438  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
439  return getData().getMiddlePoints(queryBox);
440  }
441 
445  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
446  return getData().getCenterPoints(queryBox);
447  }
448 
453  double range=RNANDOUBLE, bool limited=true) const {
454 
455  return getData().getClosestPointOnEntity(point, range, limited);
456  }
457 
461  virtual QList<RVector> getPointsWithDistanceToEnd(
462  double distance,
463  RS::From from = RS::FromAny,
464  const RBox& queryBox = RDEFAULT_RBOX) const {
465  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
466  }
467 
471  virtual QList<RVector> getIntersectionPoints(
472  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
473 
477  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
478 
482  virtual QList<RVector> getIntersectionPointsWithShape(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const {
483  return getIntersectionPoints(shape, limited, queryBox);
484  }
485 
489  virtual bool moveReferencePoint(
490  const RVector& referencePoint, const RVector& targetPoint) {
491  return getData().moveReferencePoint(referencePoint, targetPoint);
492  }
493 
497  virtual bool move(const RVector& offset) {
498  return getData().move(offset);
499  }
500 
504  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
505  return getData().rotate(rotation, center);
506  }
507 
511  virtual bool scale(const RVector& scaleFactors,
512  const RVector& center = RDEFAULT_RVECTOR) {
513 
514  return getData().scale(scaleFactors, center);
515  }
516 
520  virtual bool scale(double scaleFactor,
521  const RVector& center = RDEFAULT_RVECTOR) {
522 
523  return getData().scale(scaleFactor, center);
524  }
525 
526  virtual void scaleVisualProperties(double scaleFactor) {
527  getData().scaleVisualProperties(scaleFactor);
528  }
529 
533  virtual bool mirror(const RLine& axis) {
534  return getData().mirror(axis);
535  }
536 
540  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
541  return getData().mirror(axis1, axis2);
542  }
543 
547  virtual bool flipHorizontal() {
548  return getData().flipHorizontal();
549  }
550 
554  virtual bool flipVertical() {
555  return getData().flipVertical();
556  }
557 
561  virtual bool stretch(const RPolyline& area, const RVector& offset) {
562  return getData().stretch(area, offset);
563  }
564 
568  void update() const {
569  getData().update();
570  }
571 
575  virtual RShape* castToShape() {
576  return getData().castToShape();
577  }
578 
582  virtual const RShape* castToConstShape() const {
583  return getData().castToConstShape();
584  }
585 
591  virtual void exportEntity(RExporter& e, bool preview = false, bool forceSelected=false) const = 0;
592 
593  // from RObject:
595  return isSelected();
596  }
597 
598  virtual void setAutoUpdatesBlocked(bool on) {
599  getData().setAutoUpdatesBlocked(on);
600  }
601 
602  virtual QPair<QVariant, RPropertyAttributes> getProperty(
603  RPropertyTypeId& propertyTypeId,
604  bool humanReadable = false, bool noAttributes = false);
605 
606  virtual bool setProperty(RPropertyTypeId propertyTypeId,
607  const QVariant& value, RTransaction* transaction=NULL);
608 
609  bool isVisible() const;
610  bool isEditable(bool allowInvisible = false) const;
611 
612  virtual int getComplexity() const {
613  return 1;
614  }
615 
616 protected:
617  virtual void print(QDebug dbg) const;
618 };
619 
621 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
622 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
623 Q_DECLARE_METATYPE(QStack<REntity*>)
624 Q_DECLARE_METATYPE(QStack<REntity*>*)
625 
626 #endif
virtual bool isOnEntity(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: REntity.h:382
Represents a box e.g.
Definition: RBox.h:43
int getDrawOrder() const
Definition: REntity.h:173
Base class for all entity data classes.
Definition: REntityData.h:65
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false) const
Definition: REntity.h:354
void setUpdatesEnabled(bool on)
Definition: REntity.h:155
static RPropertyTypeId PropertyBlock
Definition: REntity.h:73
bool isSelected() const
Reimplemented by entities that are part of a block reference but not stored as part of the block defi...
Definition: REntity.h:145
RLineweight::Lineweight getLineweight() const
Definition: REntity.h:291
Unknown entity.
Definition: RS.h:87
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual RShape * castToShape()
Definition: REntity.h:575
RLayer::Id getLayerId() const
Definition: REntity.h:187
virtual QSharedPointer< RShape > getClosestShape(const RVector &pos, double range=RNANDOUBLE, bool ignoreComplex=false) const
Definition: REntity.h:361
#define RDEFAULT_RBOX
Definition: RBox.h:32
virtual RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntity.h:452
virtual bool flipVertical()
Definition: REntity.h:554
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:445
virtual RS::EntityType getType() const
Definition: REntity.h:107
virtual bool cloneOnChange() const
Definition: REntity.h:159
virtual bool scale(double scaleFactor, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:520
QString getBlockName() const
Definition: REntity.h:215
virtual bool isSelectedForPropertyEditing()
Definition: REntity.h:594
virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant &value, RTransaction *transaction=NULL)
Sets the given property to the given value.
Definition: RObject.cpp:129
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:561
static RPropertyTypeId PropertySizeY
Definition: REntity.h:87
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntity.h:326
virtual bool isUpdatesEnabled() const
Definition: REntity.h:151
static RPropertyTypeId PropertyLineweight
Definition: REntity.h:77
virtual bool isInside(const RBox &box) const
Definition: REntity.h:375
Abstract base class for all objects.
Definition: RObject.h:48
void setLineweight(RLineweight::Lineweight lineweight)
Definition: REntity.h:284
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:489
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RPropertyTypeId.h:58
virtual QSharedPointer< RShape > getClosestSimpleShape(const RVector &pos, double range=RNANDOUBLE) const
Definition: REntity.h:368
static RPropertyTypeId PropertyHandle
Definition: REntity.h:70
#define QCADCORE_EXPORT
Definition: core_global.h:10
static RPropertyTypeId PropertyMinX
Definition: REntity.h:82
virtual QPair< QVariant, RPropertyAttributes > getProperty(RPropertyTypeId &propertyTypeId, bool humanReadable=false, bool noAttributes=false)
Definition: RObject.cpp:94
virtual bool mirror(const RVector &axis1, const RVector &axis2)
Definition: REntity.h:540
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:396
double getLinetypeScale() const
Definition: REntity.h:277
int Id
Definition: RObject.h:53
REntity::Id getParentId() const
Definition: REntity.h:229
Transaction implementation.
Definition: RTransaction.h:70
RColor getColor() const
Definition: REntity.h:310
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLinetypePattern.h:45
static RPropertyTypeId PropertyType
Definition: REntity.h:72
virtual bool mirror(const RLine &axis)
Definition: REntity.h:533
static RPropertyTypeId PropertySizeX
Definition: REntity.h:86
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:504
static RPropertyTypeId PropertyCustom
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: REntity.h:69
void setDocument(RDocument *document)
Definition: REntity.h:100
static RPropertyTypeId PropertyDrawOrder
Definition: REntity.h:80
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:200
virtual RVector getPointOnEntity() const
Definition: REntity.h:424
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:128
Lineweight
Definition: RLineweight.h:42
static RPropertyTypeId PropertyDisplayedColor
Definition: REntity.h:79
Color.
Definition: RColor.h:42
virtual const RShape * castToConstShape() const
Definition: REntity.h:582
virtual QList< RRefPoint > getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Can be overwritten to return internal, resolved reference points.
Definition: REntity.h:410
static RPropertyTypeId PropertyLinetypeScale
Definition: REntity.h:76
void setLayerId(RLayer::Id layerId)
Definition: REntity.h:180
void setLinetypePattern(const RLinetypePattern &linetypePattern)
Definition: REntity.h:243
virtual int getComplexity() const
Definition: REntity.h:612
static RPropertyTypeId PropertyMaxX
Definition: REntity.h:84
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition: REntity.h:333
static QSet< RPropertyTypeId > getPropertyTypeIds(const std::type_info &classInfo)
Gets all property type IDs that where registered for the given class.
Definition: RPropertyTypeId.cpp:229
void setDocument(RDocument *document)
Definition: RObject.h:84
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:403
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
void setLinetypeScale(double linetypeScale)
Definition: REntity.h:267
Q_DECLARE_METATYPE(RMath *)
void setBlockId(RBlock::Id blockId)
Definition: REntity.h:201
RBlock::Id getBlockId() const
Definition: REntity.h:208
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:438
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntity.h:497
virtual void setAutoUpdatesBlocked(bool on)
Definition: REntity.h:598
#define RMAXDOUBLE
Definition: RMath.h:63
static RPropertyTypeId PropertyMaxY
Definition: REntity.h:85
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:42
static RPropertyTypeId PropertyColor
Definition: REntity.h:78
void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntity.h:568
virtual void scaleVisualProperties(double scaleFactor)
Definition: REntity.h:526
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:511
RLinetype::Id getLinetypeId() const
Definition: REntity.h:250
Low-level mathematical representation of a line.
Definition: RLine.h:42
QString getLayerName() const
Definition: REntity.h:194
static QSet< RPropertyTypeId > getStaticPropertyTypeIds()
Definition: REntity.h:96
Definition: RS.h:129
void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition: REntity.h:166
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:461
Abstract base class for exporters.
Definition: RExporter.h:71
static RPropertyTypeId PropertyProtected
Definition: REntity.h:71
static RPropertyTypeId PropertyMinY
Definition: REntity.h:83
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:197
static void init()
Definition: RObject.cpp:61
static RPropertyTypeId PropertyLayer
Definition: REntity.h:74
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Definition: REntity.h:417
static RPropertyTypeId PropertyLinetype
Definition: REntity.h:75
Block reference entity.
Definition: RBlockReferenceEntity.h:38
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool flipHorizontal()
Definition: REntity.h:547
void setParentId(REntity::Id parentId)
Definition: REntity.h:222
virtual bool intersectsWith(const RShape &shape) const
Definition: REntity.h:389
virtual RPolyline getHull(double offset) const
Definition: REntity.h:340
RLinetypePattern getLinetypePattern() const
Definition: REntity.h:260
void setColor(const RColor &color)
Definition: REntity.h:303
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual void print(QDebug dbg) const
Stream operator for QDebug.
Definition: RObject.cpp:512
virtual QList< RVector > getIntersectionPointsWithShape(const RShape &shape, bool limited=true, const RBox &queryBox=RDEFAULT_RBOX) const
Make getIntersectionPoints with shape parameter accessible for script wrappers.
Definition: REntity.h:482
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:431
virtual RObject * clone() const =0
void setLinetypeId(RLinetype::Id linetypeId)
Definition: REntity.h:236
RColor getDisplayColor()
Definition: REntity.h:316