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  friend class RStorage;
69 
70 public:
71  static RPropertyTypeId PropertyCustom;
72  static RPropertyTypeId PropertyHandle;
73  static RPropertyTypeId PropertyProtected;
74  static RPropertyTypeId PropertyType;
75  static RPropertyTypeId PropertyBlock;
76  static RPropertyTypeId PropertyLayer;
77  static RPropertyTypeId PropertyLinetype;
78  static RPropertyTypeId PropertyLinetypeScale;
79  static RPropertyTypeId PropertyLineweight;
80  static RPropertyTypeId PropertyColor;
81  static RPropertyTypeId PropertyDisplayedColor;
82  static RPropertyTypeId PropertyDrawOrder;
83 
84  static RPropertyTypeId PropertyMinX;
85  static RPropertyTypeId PropertyMinY;
86  static RPropertyTypeId PropertyMaxX;
87  static RPropertyTypeId PropertyMaxY;
88  static RPropertyTypeId PropertySizeX;
89  static RPropertyTypeId PropertySizeY;
90 
91 public:
92  REntity(RDocument* document);
93  REntity(const REntity& other);
94  virtual ~REntity();
95 
96  static void init();
97 
98  static QSet<RPropertyTypeId> getStaticPropertyTypeIds() {
99  return RPropertyTypeId::getPropertyTypeIds(typeid(REntity));
100  }
101 
102  void setDocument(RDocument* document) {
103  RObject::setDocument(document);
104  getData().setDocument(document);
105  }
106 
107  virtual REntity* clone() const = 0;
108 
109  virtual RS::EntityType getType() const {
110  return getData().getType();
111  }
112 
113  static bool isComplex(const RS::EntityType type);
114  static bool isDimension(const RS::EntityType type);
115 
119  virtual REntityData& getData() = 0;
120 
124  virtual const REntityData& getData() const = 0;
125 
126  virtual bool isValid() const {
127  return getData().isValid();
128  }
129  virtual bool isSane() const {
130  return getData().isSane();
131  }
132 
138 // virtual bool isPartOfBlockReference(REntity::Id blockRefId) const {
139 // Q_UNUSED(blockRefId)
140 
141 // return false;
142 // }
143 
147 // virtual bool getAutoVisualize() const {
148 // return true;
149 // }
150 
154  bool isSelected() const {
155  return getData().isSelected();
156  }
157 
158  virtual void setSelected(bool on);
159 
160  virtual bool isUpdatesEnabled() const {
161  return getData().isUpdatesEnabled();
162  }
163 
164  void setUpdatesEnabled(bool on) {
165  getData().setUpdatesEnabled(on);
166  }
167 
168  virtual bool cloneOnChange() const {
169  return getData().cloneOnChange();
170  }
171 
175  void setDrawOrder(int drawOrder) {
176  getData().setDrawOrder(drawOrder);
177  }
178 
182  int getDrawOrder() const {
183  return getData().getDrawOrder();
184  }
185 
189  void setLayerId(RLayer::Id layerId) {
190  getData().setLayerId(layerId);
191  }
192 
197  return getData().getLayerId();
198  }
199 
203  QString getLayerName() const {
204  return getData().getLayerName();
205  }
206 
210  void setBlockId(RBlock::Id blockId) {
211  getData().setBlockId(blockId);
212  }
213 
218  return getData().getBlockId();
219  }
220 
224  QString getBlockName() const {
225  return getData().getBlockName();
226  }
227 
232  return getData().getParentId();
233  }
234 
238  void setLinetypeId(RLinetype::Id linetypeId) {
239  getData().setLinetypeId(linetypeId);
240  }
241 
245  void setLinetypePattern(const RLinetypePattern& linetypePattern) {
246  getData().setLinetypePattern(linetypePattern);
247  }
248 
253  return getData().getLinetypeId();
254  }
255 
256  RLinetype::Id getLinetypeId(bool resolve,
257  const QStack<REntity*>& blockRefStack) const;
258 
263  return getData().getLinetypePattern();
264  }
265 
269  void setLinetypeScale(double linetypeScale) {
270  if (linetypeScale<0.0) {
271  qDebug() << "setLinetypeScale to -1";
272  }
273  getData().setLinetypeScale(linetypeScale);
274  }
275 
279  double getLinetypeScale() const {
280  return getData().getLinetypeScale();
281  }
282 
287  getData().setLineweight(lineweight);
288  }
289 
294  return getData().getLineweight();
295  }
296 
297  RLineweight::Lineweight getLineweight(bool resolve,
298  const QStack<REntity*>& blockRefStack) const;
299 
300  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
301 
305  void setColor(const RColor& color) {
306  getData().setColor(color);
307  }
308 
312  RColor getColor() const {
313  return getData().getColor();
314  }
315 
316  RColor getColor(bool resolve, const QStack<REntity*>& blockRefStack);
317 
319  return getData().getDisplayColor();
320  }
321 
322  void copyAttributesFrom(const REntity* entity, bool copyBlockId=true);
323  void copyAttributesFrom(const REntityData& entityData, bool copyBlockId=true);
324 
328  virtual RBox getBoundingBox(bool ignoreEmpty=false) const {
329  return getData().getBoundingBox(ignoreEmpty);
330  }
331 
335  virtual void to2D() {
336  getData().to2D();
337  }
338 
342  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
343  return getData().getBoundingBoxes(ignoreEmpty);
344  }
345 
349  virtual RPolyline getHull(double offset) const {
350  return getData().getHull(offset);
351  }
352 
356 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
357 // return getData().getIdBoundingBoxes();
358 // }
359 
363  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const {
364  return getData().getShapes(queryBox, ignoreComplex, segment);
365  }
366 
370  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const {
371  return getData().getClosestShape(pos, range, ignoreComplex);
372  }
373 
377  virtual QSharedPointer<RShape> getClosestSimpleShape(const RVector& pos, double range = RNANDOUBLE) const {
378  return getClosestShape(pos, range, true);
379  }
380 
384  virtual bool isInside(const RBox& box) const {
385  return getData().isInside(box);
386  }
387 
391  virtual bool isOnEntity(const RVector& point, bool limited=true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const {
392  return getData().isOnEntity(point, limited, tolerance);
393  }
394 
398  virtual bool intersectsWith(const RShape& shape) const {
399  return getData().intersectsWith(shape);
400  }
401 
405  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const {
406  return getData().getDistanceTo(point, limited, range, draft, strictRange);
407  }
408 
412  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const {
413  return getData().getVectorTo(point, limited, strictRange);
414  }
415 
420  return getData().getInternalReferencePoints(hint);
421  }
422 
426  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
427  return getData().getReferencePoints(hint);
428  }
429 
433  virtual RVector getPointOnEntity() const {
434  return getData().getPointOnEntity();
435  }
436 
440  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
441  return getData().getEndPoints(queryBox);
442  }
443 
447  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
448  return getData().getMiddlePoints(queryBox);
449  }
450 
454  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
455  return getData().getCenterPoints(queryBox);
456  }
457 
462  double range=RNANDOUBLE, bool limited=true) const {
463 
464  return getData().getClosestPointOnEntity(point, range, limited);
465  }
466 
470  virtual QList<RVector> getPointsWithDistanceToEnd(
471  double distance,
472  int from = RS::FromAny,
473  const RBox& queryBox = RDEFAULT_RBOX) const {
474  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
475  }
476 
480  virtual QList<RVector> getIntersectionPoints(
481  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
482 
486  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
487 
491  virtual QList<RVector> getIntersectionPointsWithShape(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const {
492  return getIntersectionPoints(shape, limited, queryBox);
493  }
494 
498  virtual bool moveReferencePoint(
499  const RVector& referencePoint, const RVector& targetPoint) {
500  return getData().moveReferencePoint(referencePoint, targetPoint);
501  }
502 
506  virtual bool move(const RVector& offset) {
507  return getData().move(offset);
508  }
509 
513  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
514  return getData().rotate(rotation, center);
515  }
516 
520  virtual bool scale(const RVector& scaleFactors,
521  const RVector& center = RDEFAULT_RVECTOR) {
522 
523  return getData().scale(scaleFactors, center);
524  }
525 
529  virtual bool scale(double scaleFactor,
530  const RVector& center = RDEFAULT_RVECTOR) {
531 
532  return getData().scale(scaleFactor, center);
533  }
534 
535  virtual void scaleVisualProperties(double scaleFactor) {
536  getData().scaleVisualProperties(scaleFactor);
537  }
538 
542  virtual bool mirror(const RLine& axis) {
543  return getData().mirror(axis);
544  }
545 
549  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
550  return getData().mirror(axis1, axis2);
551  }
552 
556  virtual bool flipHorizontal() {
557  return getData().flipHorizontal();
558  }
559 
563  virtual bool flipVertical() {
564  return getData().flipVertical();
565  }
566 
570  virtual bool stretch(const RPolyline& area, const RVector& offset) {
571  return getData().stretch(area, offset);
572  }
573 
577  void update() const {
578  getData().update();
579  }
580 
584  virtual RShape* castToShape() {
585  return getData().castToShape();
586  }
587 
591  virtual const RShape* castToConstShape() const {
592  return getData().castToConstShape();
593  }
594 
600  virtual void exportEntity(RExporter& e, bool preview = false, bool forceSelected=false) const = 0;
601 
602  // from RObject:
604  return isSelected();
605  }
606 
607  virtual void setAutoUpdatesBlocked(bool on) {
608  getData().setAutoUpdatesBlocked(on);
609  }
610 
611  virtual QPair<QVariant, RPropertyAttributes> getProperty(
612  RPropertyTypeId& propertyTypeId,
613  bool humanReadable = false, bool noAttributes = false);
614 
615  virtual bool setProperty(RPropertyTypeId propertyTypeId,
616  const QVariant& value, RTransaction* transaction=NULL);
617 
618  virtual bool isVisible() const;
619  virtual bool isEditable(bool allowInvisible = false) const;
620 
621  virtual int getComplexity() const {
622  return 1;
623  }
624 
625 protected:
629  void setParentId(REntity::Id parentId) {
630  getData().setParentId(parentId);
631  }
632 
633  virtual void print(QDebug dbg) const;
634 };
635 
637 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
638 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
639 Q_DECLARE_METATYPE(QStack<REntity*>)
640 Q_DECLARE_METATYPE(QStack<REntity*>*)
641 
642 #endif
virtual bool isOnEntity(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: REntity.h:391
Represents a box e.g.
Definition: RBox.h:43
int getDrawOrder() const
Definition: REntity.h:182
Base class for all entity data classes.
Definition: REntityData.h:65
void setUpdatesEnabled(bool on)
Definition: REntity.h:164
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:154
RLineweight::Lineweight getLineweight() const
Definition: REntity.h:293
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual void to2D()
Definition: REntity.h:335
virtual RShape * castToShape()
Definition: REntity.h:584
RLayer::Id getLayerId() const
Definition: REntity.h:196
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 RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntity.h:461
virtual bool flipVertical()
Definition: REntity.h:563
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:454
virtual RS::EntityType getType() const
Definition: REntity.h:109
virtual bool cloneOnChange() const
Definition: REntity.h:168
virtual bool scale(double scaleFactor, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:529
QString getBlockName() const
Definition: REntity.h:224
virtual bool isSelectedForPropertyEditing()
Definition: REntity.h:603
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:570
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntity.h:328
virtual bool isUpdatesEnabled() const
Definition: REntity.h:160
virtual bool isSane() const
Definition: REntity.h:129
virtual bool isInside(const RBox &box) const
Definition: REntity.h:384
Abstract base class for all objects.
Definition: RObject.h:52
void setLineweight(RLineweight::Lineweight lineweight)
Definition: REntity.h:286
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
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPropertyTypeId.h:58
virtual QSharedPointer< RShape > getClosestSimpleShape(const RVector &pos, double range=RNANDOUBLE) const
Definition: REntity.h:377
#define QCADCORE_EXPORT
Definition: core_global.h:10
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:549
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:405
double getLinetypeScale() const
Definition: REntity.h:279
int Id
Definition: RObject.h:57
REntity::Id getParentId() const
Definition: REntity.h:231
This is the abstract base class for all storage implementations.
Definition: RStorage.h:62
Transaction implementation.
Definition: RTransaction.h:74
RColor getColor() const
Definition: REntity.h:312
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLinetypePattern.h:45
virtual bool mirror(const RLine &axis)
Definition: REntity.h:542
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:513
void setDocument(RDocument *document)
Definition: REntity.h:102
#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
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
virtual const RShape * castToConstShape() const
Definition: REntity.h:591
virtual QList< RRefPoint > getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Can be overwritten to return internal, resolved reference points.
Definition: REntity.h:419
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntity.h:363
void setLayerId(RLayer::Id layerId)
Definition: REntity.h:189
void setLinetypePattern(const RLinetypePattern &linetypePattern)
Definition: REntity.h:245
virtual int getComplexity() const
Definition: REntity.h:621
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition: REntity.h:342
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:90
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
void setLinetypeScale(double linetypeScale)
Definition: REntity.h:269
Q_DECLARE_METATYPE(RMath *)
void setBlockId(RBlock::Id blockId)
Definition: REntity.h:210
RBlock::Id getBlockId() const
Definition: REntity.h:217
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:447
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
Definition: REntity.h:506
virtual void setAutoUpdatesBlocked(bool on)
Definition: REntity.h:607
#define RMAXDOUBLE
Definition: RMath.h:63
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:42
void getIntersectionPoints(void e1, void e2, void limited)
Returns intersection points between the two given entities or shapes.
Definition: simple_info.js:12
void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntity.h:577
virtual void scaleVisualProperties(double scaleFactor)
Definition: REntity.h:535
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: REntity.h:520
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
void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition: REntity.h:175
Abstract base class for exporters.
Definition: RExporter.h:71
void init(void basePath)
Definition: AddBlockInit.js:2
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:470
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Definition: REntity.h:426
Block reference entity.
Definition: RBlockReferenceEntity.h:38
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool flipHorizontal()
Definition: REntity.h:556
void setParentId(REntity::Id parentId)
Definition: REntity.h:629
virtual bool intersectsWith(const RShape &shape) const
Definition: REntity.h:398
virtual RPolyline getHull(double offset) const
Definition: REntity.h:349
RLinetypePattern getLinetypePattern() const
Definition: REntity.h:262
void setColor(const RColor &color)
Definition: REntity.h:305
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual void print(QDebug dbg) const
Stream operator for QDebug.
Definition: RObject.cpp:566
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:491
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:440
virtual bool isValid() const
Definition: REntity.h:126
virtual RObject * clone() const =0
void setLinetypeId(RLinetype::Id linetypeId)
Sets the linetype of this entity to the given linetype ID.
Definition: REntity.h:238
RColor getDisplayColor()
Definition: REntity.h:318