QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
61 
62  Q_DECLARE_TR_FUNCTIONS(REntity)
63 
64 public:
74 
79 
80 public:
81  REntity(RDocument* document, Id objectId=-1) : RObject(document, objectId) {}
82  virtual ~REntity();
83 
84  static void init();
85 
86  static QSet<RPropertyTypeId> getStaticPropertyTypeIds() {
88  }
89 
90  void setDocument(RDocument* document) {
91  RObject::setDocument(document);
92  getData().setDocument(document);
93  }
94 
95  virtual REntity* clone() const = 0;
96 
97  virtual RS::EntityType getType() const {
98  return RS::EntityUnknown;
99  }
100 
104  virtual REntityData& getData() = 0;
105 
109  virtual const REntityData& getData() const = 0;
110 
116 // virtual bool isPartOfBlockReference(REntity::Id blockRefId) const {
117 // Q_UNUSED(blockRefId)
118 
119 // return false;
120 // }
121 
125 // virtual bool getAutoVisualize() const {
126 // return true;
127 // }
128 
132  bool isSelected() const {
133  return getData().isSelected();
134  }
135 
136  virtual void setSelected(bool on);
137 
141  void setDrawOrder(int drawOrder) {
142  getData().setDrawOrder(drawOrder);
143  }
144 
148  int getDrawOrder() const {
149  return getData().getDrawOrder();
150  }
151 
155  void setLayerId(RLayer::Id layerId) {
156  getData().setLayerId(layerId);
157  }
158 
163  return getData().getLayerId();
164  }
165 
169  QString getLayerName() const {
170  return getData().getLayerName();
171  }
172 
176  void setBlockId(RBlock::Id blockId) {
177  getData().setBlockId(blockId);
178  }
179 
184  return getData().getBlockId();
185  }
186 
190  QString getBlockName() const {
191  return getData().getBlockName();
192  }
193 
197  void setParentId(REntity::Id parentId) {
198  getData().setParentId(parentId);
199  }
200 
205  return getData().getParentId();
206  }
207 
211  void setLinetypeId(RLinetype::Id linetypeId) {
212  getData().setLinetypeId(linetypeId);
213  }
214 
218  void setLinetype(RLinetype linetype) {
219  getData().setLinetype(linetype);
220  }
221 
226  return getData().getLinetypeId();
227  }
228 
229  RLinetype::Id getLinetypeId(bool resolve,
230  const QStack<RBlockReferenceEntity*>& blockRefStack) const;
231 
236  getData().setLineweight(lineweight);
237  }
238 
243  return getData().getLineweight();
244  }
245 
246  RLineweight::Lineweight getLineweight(bool resolve,
247  const QStack<RBlockReferenceEntity*>& blockRefStack) const;
248 
249  double getLineweightInUnits(const QStack<RBlockReferenceEntity*>& blockRefStack) const;
250 
254  void setColor(const RColor& color) {
255  getData().setColor(color);
256  }
257 
261  RColor getColor() const {
262  return getData().getColor();
263  }
264 
265  RColor getColor(bool resolve, const QStack<RBlockReferenceEntity*>& blockRefStack);
266 
267  void copyAttributesFrom(REntity* entity, bool copyBlockId=true);
268 
272  virtual RBox getBoundingBox() const {
273  return getData().getBoundingBox();
274  }
275 
279  virtual QList<RBox> getBoundingBoxes(/*REntity::Id subEntityId = REntity::INVALID_ID*/) const {
280  return getData().getBoundingBoxes(/*subEntityId*/);
281  }
282 
286 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
287 // return getData().getIdBoundingBoxes();
288 // }
289 
293  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX) const {
294  return getData().getShapes(queryBox);
295  }
296 
300  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE) const {
301  return getData().getClosestShape(pos, range);
302  }
303 
307  virtual bool isInside(const RBox& box) const {
308  return getData().isInside(box);
309  }
310 
314  virtual bool isOnEntity(const RVector& point, bool limited=true) const {
315  return getData().isOnEntity(point, limited);
316  }
317 
321  virtual bool intersectsWith(const RShape& shape) const {
322  return getData().intersectsWith(shape);
323  }
324 
328  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false) const {
329  return getData().getDistanceTo(point, limited, range, draft);
330  }
331 
335  virtual RVector getVectorTo(const RVector& point, bool limited = true) const {
336  return getData().getVectorTo(point, limited);
337  }
338 
343  return getData().getInternalReferencePoints(hint);
344  }
345 
349  virtual QList<RVector> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
350  return getData().getReferencePoints(hint);
351  }
352 
356  virtual RVector getPointOnEntity() const {
357  return getData().getPointOnEntity();
358  }
359 
363  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
364  return getData().getEndPoints(queryBox);
365  }
366 
370  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
371  return getData().getMiddlePoints(queryBox);
372  }
373 
377  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
378  return getData().getCenterPoints(queryBox);
379  }
380 
384  virtual RVector getClosestPointOnEntity(const RVector& point,
385  double range=RNANDOUBLE, bool limited=true) const {
386 
387  return getData().getClosestPointOnEntity(point, range, limited);
388  }
389 
393  virtual QList<RVector> getPointsWithDistanceToEnd(
394  double distance,
395  RS::From from = RS::FromAny,
396  const RBox& queryBox = RDEFAULT_RBOX) const {
397  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
398  }
399 
403  virtual QList<RVector> getIntersectionPoints(
404  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const;
405 
409  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const;
410 
414  virtual bool moveReferencePoint(
415  const RVector& referencePoint, const RVector& targetPoint) {
416  return getData().moveReferencePoint(referencePoint, targetPoint);
417  }
418 
422  virtual bool move(const RVector& offset) {
423  return getData().move(offset);
424  }
425 
429  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
430  return getData().rotate(rotation, center);
431  }
432 
436  virtual bool scale(const RVector& scaleFactors,
437  const RVector& center = RDEFAULT_RVECTOR) {
438 
439  return getData().scale(scaleFactors, center);
440  }
441 
445  virtual bool scale(double scaleFactor,
446  const RVector& center = RDEFAULT_RVECTOR) {
447 
448  return getData().scale(scaleFactor, center);
449  }
450 
454  virtual bool mirror(const RLine& axis) {
455  return getData().mirror(axis);
456  }
457 
461  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
462  return getData().mirror(axis1, axis2);
463  }
464 
468  virtual bool flipHorizontal() {
469  return getData().flipHorizontal();
470  }
471 
475  virtual bool flipVertical() {
476  return getData().flipVertical();
477  }
478 
482  virtual bool stretch(const RPolyline& area, const RVector& offset) {
483  return getData().stretch(area, offset);
484  }
485 
489  void update() const {
490  getData().update();
491  }
492 
496  virtual RShape* castToShape() {
497  return getData().castToShape();
498  }
499 
503  virtual const RShape* castToConstShape() const {
504  return getData().castToConstShape();
505  }
506 
512  virtual void exportEntity(RExporter& e, bool preview = false) const = 0;
513 
514  // from RObject:
516  return isSelected();
517  }
518 
519  virtual QPair<QVariant, RPropertyAttributes> getProperty(
520  RPropertyTypeId& propertyTypeId,
521  bool humanReadable = false, bool noAttributes = false);
522 
523  virtual bool setProperty(RPropertyTypeId propertyTypeId,
524  const QVariant& value, RTransaction* transaction=NULL);
525 
526  bool isVisible() const;
527  bool isEditable(bool allowInvisible = false) const;
528 
529  virtual int getComplexity() const {
530  return 1;
531  }
532 
533  void dump();
534 
535 protected:
536  virtual void print(QDebug dbg) const;
537 };
538 
540 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
541 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
542 Q_DECLARE_METATYPE(QStack<REntity*>)
543 
544 #endif