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:
80 
87 
88 public:
89  REntity(RDocument* document, Id objectId=-1) : RObject(document, objectId) {}
90  virtual ~REntity();
91 
92  static void init();
93 
94  static QSet<RPropertyTypeId> getStaticPropertyTypeIds() {
96  }
97 
98  void setDocument(RDocument* document) {
99  RObject::setDocument(document);
100  getData().setDocument(document);
101  }
102 
103  virtual REntity* clone() const = 0;
104 
105  virtual RS::EntityType getType() const {
106  return RS::EntityUnknown;
107  }
108 
109  static bool isComplex(const RS::EntityType type);
110  static bool isDimension(const RS::EntityType type);
111 
115  virtual REntityData& getData() = 0;
116 
120  virtual const REntityData& getData() const = 0;
121 
127 // virtual bool isPartOfBlockReference(REntity::Id blockRefId) const {
128 // Q_UNUSED(blockRefId)
129 
130 // return false;
131 // }
132 
136 // virtual bool getAutoVisualize() const {
137 // return true;
138 // }
139 
143  bool isSelected() const {
144  return getData().isSelected();
145  }
146 
147  virtual void setSelected(bool on);
148 
152  void setDrawOrder(int drawOrder) {
153  getData().setDrawOrder(drawOrder);
154  }
155 
159  int getDrawOrder() const {
160  return getData().getDrawOrder();
161  }
162 
166  void setLayerId(RLayer::Id layerId) {
167  getData().setLayerId(layerId);
168  }
169 
174  return getData().getLayerId();
175  }
176 
180  QString getLayerName() const {
181  return getData().getLayerName();
182  }
183 
187  void setBlockId(RBlock::Id blockId) {
188  getData().setBlockId(blockId);
189  }
190 
195  return getData().getBlockId();
196  }
197 
201  QString getBlockName() const {
202  return getData().getBlockName();
203  }
204 
208  void setParentId(REntity::Id parentId) {
209  getData().setParentId(parentId);
210  }
211 
216  return getData().getParentId();
217  }
218 
222  void setLinetypeId(RLinetype::Id linetypeId) {
223  getData().setLinetypeId(linetypeId);
224  }
225 
229  void setLinetypePattern(const RLinetypePattern& linetypePattern) {
230  getData().setLinetypePattern(linetypePattern);
231  }
232 
237  return getData().getLinetypeId();
238  }
239 
240  RLinetype::Id getLinetypeId(bool resolve,
241  const QStack<REntity*>& blockRefStack) const;
242 
247  return getData().getLinetypePattern();
248  }
249 
253  void setLinetypeScale(double linetypeScale) {
254  if (linetypeScale<0.0) {
255  qDebug() << "setLinetypeScale to -1";
256  }
257  getData().setLinetypeScale(linetypeScale);
258  }
259 
263  double getLinetypeScale() const {
264  return getData().getLinetypeScale();
265  }
266 
271  getData().setLineweight(lineweight);
272  }
273 
278  return getData().getLineweight();
279  }
280 
281  RLineweight::Lineweight getLineweight(bool resolve,
282  const QStack<REntity*>& blockRefStack) const;
283 
284  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
285 
289  void setColor(const RColor& color) {
290  getData().setColor(color);
291  }
292 
296  RColor getColor() const {
297  return getData().getColor();
298  }
299 
300  RColor getColor(bool resolve, const QStack<REntity*>& blockRefStack);
301 
302  void copyAttributesFrom(REntity* entity, bool copyBlockId=true);
303 
307  virtual RBox getBoundingBox(bool ignoreEmpty=false) const {
308  return getData().getBoundingBox(ignoreEmpty);
309  }
310 
314  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
315  return getData().getBoundingBoxes(ignoreEmpty);
316  }
317 
321  virtual RPolyline getHull(double offset) const {
322  return getData().getHull(offset);
323  }
324 
328 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
329 // return getData().getIdBoundingBoxes();
330 // }
331 
335  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false) const {
336  return getData().getShapes(queryBox, ignoreComplex);
337  }
338 
342  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const {
343  return getData().getClosestShape(pos, range, ignoreComplex);
344  }
345 
349  virtual QSharedPointer<RShape> getClosestSimpleShape(const RVector& pos, double range = RNANDOUBLE) const {
350  return getClosestShape(pos, range, true);
351  }
352 
356  virtual bool isInside(const RBox& box) const {
357  return getData().isInside(box);
358  }
359 
363  virtual bool isOnEntity(const RVector& point, bool limited=true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const {
364  return getData().isOnEntity(point, limited, tolerance);
365  }
366 
370  virtual bool intersectsWith(const RShape& shape) const {
371  return getData().intersectsWith(shape);
372  }
373 
377  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const {
378  return getData().getDistanceTo(point, limited, range, draft, strictRange);
379  }
380 
384  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const {
385  return getData().getVectorTo(point, limited, strictRange);
386  }
387 
392  return getData().getInternalReferencePoints(hint);
393  }
394 
398  virtual QList<RVector> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
399  return getData().getReferencePoints(hint);
400  }
401 
405  virtual RVector getPointOnEntity() const {
406  return getData().getPointOnEntity();
407  }
408 
412  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
413  return getData().getEndPoints(queryBox);
414  }
415 
419  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
420  return getData().getMiddlePoints(queryBox);
421  }
422 
426  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
427  return getData().getCenterPoints(queryBox);
428  }
429 
434  double range=RNANDOUBLE, bool limited=true) const {
435 
436  return getData().getClosestPointOnEntity(point, range, limited);
437  }
438 
442  virtual QList<RVector> getPointsWithDistanceToEnd(
443  double distance,
444  RS::From from = RS::FromAny,
445  const RBox& queryBox = RDEFAULT_RBOX) const {
446  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
447  }
448 
452  virtual QList<RVector> getIntersectionPoints(
453  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
454 
458  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
459 
463  virtual QList<RVector> getIntersectionPointsWithShape(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const {
464  return getIntersectionPoints(shape, limited, queryBox);
465  }
466 
470  virtual bool moveReferencePoint(
471  const RVector& referencePoint, const RVector& targetPoint) {
472  return getData().moveReferencePoint(referencePoint, targetPoint);
473  }
474 
478  virtual bool move(const RVector& offset) {
479  return getData().move(offset);
480  }
481 
485  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
486  return getData().rotate(rotation, center);
487  }
488 
492  virtual bool scale(const RVector& scaleFactors,
493  const RVector& center = RDEFAULT_RVECTOR) {
494 
495  return getData().scale(scaleFactors, center);
496  }
497 
501  virtual bool scale(double scaleFactor,
502  const RVector& center = RDEFAULT_RVECTOR) {
503 
504  return getData().scale(scaleFactor, center);
505  }
506 
510  virtual bool mirror(const RLine& axis) {
511  return getData().mirror(axis);
512  }
513 
517  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
518  return getData().mirror(axis1, axis2);
519  }
520 
524  virtual bool flipHorizontal() {
525  return getData().flipHorizontal();
526  }
527 
531  virtual bool flipVertical() {
532  return getData().flipVertical();
533  }
534 
538  virtual bool stretch(const RPolyline& area, const RVector& offset) {
539  return getData().stretch(area, offset);
540  }
541 
545  void update() const {
546  getData().update();
547  }
548 
552  virtual RShape* castToShape() {
553  return getData().castToShape();
554  }
555 
559  virtual const RShape* castToConstShape() const {
560  return getData().castToConstShape();
561  }
562 
568  virtual void exportEntity(RExporter& e, bool preview = false, bool forceSelected=false) const = 0;
569 
570  // from RObject:
572  return isSelected();
573  }
574 
575  virtual QPair<QVariant, RPropertyAttributes> getProperty(
576  RPropertyTypeId& propertyTypeId,
577  bool humanReadable = false, bool noAttributes = false);
578 
579  virtual bool setProperty(RPropertyTypeId propertyTypeId,
580  const QVariant& value, RTransaction* transaction=NULL);
581 
582  bool isVisible() const;
583  bool isEditable(bool allowInvisible = false) const;
584 
585  virtual int getComplexity() const {
586  return 1;
587  }
588 
589 protected:
590  virtual void print(QDebug dbg) const;
591 };
592 
594 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
595 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
596 Q_DECLARE_METATYPE(QStack<REntity*>)
597 Q_DECLARE_METATYPE(QStack<REntity*>*)
598 
599 #endif
virtual bool isOnEntity(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: REntity.h:363
Represents a box e.g.
Definition: RBox.h:43
int getDrawOrder() const
Definition: REntity.h:159
Base class for all entity data classes.
Definition: REntityData.h:64
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false) const
Definition: REntity.h:335
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:143
RLineweight::Lineweight getLineweight() const
Definition: REntity.h:277
Unknown.
Definition: RS.h:77
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual RShape * castToShape()
Definition: REntity.h:552
RLayer::Id getLayerId() const
Definition: REntity.h:173
virtual QSharedPointer< RShape > getClosestShape(const RVector &pos, double range=RNANDOUBLE, bool ignoreComplex=false) const
Definition: REntity.h:342
#define RDEFAULT_RBOX
Definition: RBox.h:32
virtual RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntity.h:433
virtual bool flipVertical()
Definition: REntity.h:531
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:426
virtual RS::EntityType getType() const
Definition: REntity.h:105
virtual bool scale(double scaleFactor, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:501
QString getBlockName() const
Definition: REntity.h:201
virtual bool isSelectedForPropertyEditing()
Definition: REntity.h:571
virtual bool setProperty(RPropertyTypeId propertyTypeId, const QVariant &value, RTransaction *transaction=NULL)
Sets the given property to the given value.
Definition: RObject.cpp:101
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:75
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:538
static RPropertyTypeId PropertySizeY
Definition: REntity.h:86
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntity.h:307
static RPropertyTypeId PropertyLineweight
Definition: REntity.h:77
virtual bool isInside(const RBox &box) const
Definition: REntity.h:356
Abstract base class for all objects.
Definition: RObject.h:48
void setLineweight(RLineweight::Lineweight lineweight)
Definition: REntity.h:270
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:470
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RPropertyTypeId.h:57
virtual QSharedPointer< RShape > getClosestSimpleShape(const RVector &pos, double range=RNANDOUBLE) const
Definition: REntity.h:349
static RPropertyTypeId PropertyHandle
Definition: REntity.h:70
#define QCADCORE_EXPORT
Definition: core_global.h:10
static RPropertyTypeId PropertyMinX
Definition: REntity.h:81
virtual QPair< QVariant, RPropertyAttributes > getProperty(RPropertyTypeId &propertyTypeId, bool humanReadable=false, bool noAttributes=false)
Definition: RObject.cpp:67
virtual bool mirror(const RVector &axis1, const RVector &axis2)
Definition: REntity.h:517
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:377
double getLinetypeScale() const
Definition: REntity.h:263
int Id
Definition: RObject.h:53
REntity::Id getParentId() const
Definition: REntity.h:215
Transaction implementation.
Definition: RTransaction.h:70
RColor getColor() const
Definition: REntity.h:296
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RLinetypePattern.h:45
static RPropertyTypeId PropertyType
Definition: REntity.h:72
virtual bool mirror(const RLine &axis)
Definition: REntity.h:510
static RPropertyTypeId PropertySizeX
Definition: REntity.h:85
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:485
virtual QList< RVector > getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Can be overwritten to return internal, resolved reference points.
Definition: REntity.h:391
static RPropertyTypeId PropertyCustom
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: REntity.h:69
void setDocument(RDocument *document)
Definition: REntity.h:98
static RPropertyTypeId PropertyDrawOrder
Definition: REntity.h:79
#define RNANDOUBLE
Definition: RMath.h:55
Start or end.
Definition: RS.h:187
virtual RVector getPointOnEntity() const
Definition: REntity.h:405
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:118
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
virtual const RShape * castToConstShape() const
Definition: REntity.h:559
static RPropertyTypeId PropertyLinetypeScale
Definition: REntity.h:76
void setLayerId(RLayer::Id layerId)
Definition: REntity.h:166
void setLinetypePattern(const RLinetypePattern &linetypePattern)
Definition: REntity.h:229
virtual int getComplexity() const
Definition: REntity.h:585
static RPropertyTypeId PropertyMaxX
Definition: REntity.h:83
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition: REntity.h:314
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:86
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:384
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:63
void setLinetypeScale(double linetypeScale)
Definition: REntity.h:253
Q_DECLARE_METATYPE(RMath *)
void setBlockId(RBlock::Id blockId)
Definition: REntity.h:187
RBlock::Id getBlockId() const
Definition: REntity.h:194
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:419
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntity.h:478
#define RMAXDOUBLE
Definition: RMath.h:50
static RPropertyTypeId PropertyMaxY
Definition: REntity.h:84
#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:545
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:492
RLinetype::Id getLinetypeId() const
Definition: REntity.h:236
Low-level mathematical representation of a line.
Definition: RLine.h:42
QString getLayerName() const
Definition: REntity.h:180
static QSet< RPropertyTypeId > getStaticPropertyTypeIds()
Definition: REntity.h:94
Definition: RS.h:119
void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition: REntity.h:152
virtual QList< RVector > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Definition: REntity.h:398
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:442
Abstract base class for exporters.
Definition: RExporter.h:63
static RPropertyTypeId PropertyProtected
Definition: REntity.h:71
static RPropertyTypeId PropertyMinY
Definition: REntity.h:82
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:184
static void init()
Definition: RObject.cpp:35
static RPropertyTypeId PropertyLayer
Definition: REntity.h:74
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
REntity(RDocument *document, Id objectId=-1)
Definition: REntity.h:89
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:524
void setParentId(REntity::Id parentId)
Definition: REntity.h:208
virtual bool intersectsWith(const RShape &shape) const
Definition: REntity.h:370
virtual RPolyline getHull(double offset) const
Definition: REntity.h:321
RLinetypePattern getLinetypePattern() const
Definition: REntity.h:246
void setColor(const RColor &color)
Definition: REntity.h:289
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual void print(QDebug dbg) const
Stream operator for QDebug.
Definition: RObject.cpp:441
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:463
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:412
virtual RObject * clone() const =0
void setLinetypeId(RLinetype::Id linetypeId)
Definition: REntity.h:222