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 
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:
79 
84 
85 public:
86  REntity(RDocument* document, Id objectId=-1) : RObject(document, objectId) {}
87  virtual ~REntity();
88 
89  static void init();
90 
91  static QSet<RPropertyTypeId> getStaticPropertyTypeIds() {
93  }
94 
95  void setDocument(RDocument* document) {
96  RObject::setDocument(document);
97  getData().setDocument(document);
98  }
99 
100  virtual REntity* clone() const = 0;
101 
102  virtual RS::EntityType getType() const {
103  return RS::EntityUnknown;
104  }
105 
106  static bool isComplex(const RS::EntityType type);
107  static bool isDimension(const RS::EntityType type);
108 
112  virtual REntityData& getData() = 0;
113 
117  virtual const REntityData& getData() const = 0;
118 
124 // virtual bool isPartOfBlockReference(REntity::Id blockRefId) const {
125 // Q_UNUSED(blockRefId)
126 
127 // return false;
128 // }
129 
133 // virtual bool getAutoVisualize() const {
134 // return true;
135 // }
136 
140  bool isSelected() const {
141  return getData().isSelected();
142  }
143 
144  virtual void setSelected(bool on);
145 
149  void setDrawOrder(int drawOrder) {
150  getData().setDrawOrder(drawOrder);
151  }
152 
156  int getDrawOrder() const {
157  return getData().getDrawOrder();
158  }
159 
163  void setLayerId(RLayer::Id layerId) {
164  getData().setLayerId(layerId);
165  }
166 
171  return getData().getLayerId();
172  }
173 
177  QString getLayerName() const {
178  return getData().getLayerName();
179  }
180 
184  void setBlockId(RBlock::Id blockId) {
185  getData().setBlockId(blockId);
186  }
187 
192  return getData().getBlockId();
193  }
194 
198  QString getBlockName() const {
199  return getData().getBlockName();
200  }
201 
205  void setParentId(REntity::Id parentId) {
206  getData().setParentId(parentId);
207  }
208 
213  return getData().getParentId();
214  }
215 
219  void setLinetypeId(RLinetype::Id linetypeId) {
220  getData().setLinetypeId(linetypeId);
221  }
222 
226  void setLinetypePattern(const RLinetypePattern& linetypePattern) {
227  getData().setLinetypePattern(linetypePattern);
228  }
229 
234  return getData().getLinetypeId();
235  }
236 
237  RLinetype::Id getLinetypeId(bool resolve,
238  const QStack<REntity*>& blockRefStack) const;
239 
244  return getData().getLinetypePattern();
245  }
246 
250  void setLinetypeScale(double linetypeScale) {
251  if (linetypeScale<0.0) {
252  qDebug() << "setLinetypeScale to -1";
253  }
254  getData().setLinetypeScale(linetypeScale);
255  }
256 
260  double getLinetypeScale() const {
261  return getData().getLinetypeScale();
262  }
263 
268  getData().setLineweight(lineweight);
269  }
270 
275  return getData().getLineweight();
276  }
277 
278  RLineweight::Lineweight getLineweight(bool resolve,
279  const QStack<REntity*>& blockRefStack) const;
280 
281  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
282 
286  void setColor(const RColor& color) {
287  getData().setColor(color);
288  }
289 
293  RColor getColor() const {
294  return getData().getColor();
295  }
296 
297  RColor getColor(bool resolve, const QStack<REntity*>& blockRefStack);
298 
299  void copyAttributesFrom(REntity* entity, bool copyBlockId=true);
300 
304  virtual RBox getBoundingBox(bool ignoreEmpty=false) const {
305  return getData().getBoundingBox(ignoreEmpty);
306  }
307 
311  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
312  return getData().getBoundingBoxes(ignoreEmpty);
313  }
314 
318  virtual RPolyline getHull(double offset) const {
319  return getData().getHull(offset);
320  }
321 
325 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
326 // return getData().getIdBoundingBoxes();
327 // }
328 
332  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false) const {
333  return getData().getShapes(queryBox, ignoreComplex);
334  }
335 
339  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const {
340  return getData().getClosestShape(pos, range, ignoreComplex);
341  }
342 
346  virtual QSharedPointer<RShape> getClosestSimpleShape(const RVector& pos, double range = RNANDOUBLE) const {
347  return getClosestShape(pos, range, true);
348  }
349 
353  virtual bool isInside(const RBox& box) const {
354  return getData().isInside(box);
355  }
356 
360  virtual bool isOnEntity(const RVector& point, bool limited=true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const {
361  return getData().isOnEntity(point, limited, tolerance);
362  }
363 
367  virtual bool intersectsWith(const RShape& shape) const {
368  return getData().intersectsWith(shape);
369  }
370 
374  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const {
375  return getData().getDistanceTo(point, limited, range, draft, strictRange);
376  }
377 
381  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const {
382  return getData().getVectorTo(point, limited, strictRange);
383  }
384 
389  return getData().getInternalReferencePoints(hint);
390  }
391 
395  virtual QList<RVector> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
396  return getData().getReferencePoints(hint);
397  }
398 
402  virtual RVector getPointOnEntity() const {
403  return getData().getPointOnEntity();
404  }
405 
409  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
410  return getData().getEndPoints(queryBox);
411  }
412 
416  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
417  return getData().getMiddlePoints(queryBox);
418  }
419 
423  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
424  return getData().getCenterPoints(queryBox);
425  }
426 
430  virtual RVector getClosestPointOnEntity(const RVector& point,
431  double range=RNANDOUBLE, bool limited=true) const {
432 
433  return getData().getClosestPointOnEntity(point, range, limited);
434  }
435 
439  virtual QList<RVector> getPointsWithDistanceToEnd(
440  double distance,
441  RS::From from = RS::FromAny,
442  const RBox& queryBox = RDEFAULT_RBOX) const {
443  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
444  }
445 
449  virtual QList<RVector> getIntersectionPoints(
450  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
451 
455  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
456 
460  virtual QList<RVector> getIntersectionPointsWithShape(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const {
461  return getIntersectionPoints(shape, limited, queryBox);
462  }
463 
467  virtual bool moveReferencePoint(
468  const RVector& referencePoint, const RVector& targetPoint) {
469  return getData().moveReferencePoint(referencePoint, targetPoint);
470  }
471 
475  virtual bool move(const RVector& offset) {
476  return getData().move(offset);
477  }
478 
482  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
483  return getData().rotate(rotation, center);
484  }
485 
489  virtual bool scale(const RVector& scaleFactors,
490  const RVector& center = RDEFAULT_RVECTOR) {
491 
492  return getData().scale(scaleFactors, center);
493  }
494 
498  virtual bool scale(double scaleFactor,
499  const RVector& center = RDEFAULT_RVECTOR) {
500 
501  return getData().scale(scaleFactor, center);
502  }
503 
507  virtual bool mirror(const RLine& axis) {
508  return getData().mirror(axis);
509  }
510 
514  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
515  return getData().mirror(axis1, axis2);
516  }
517 
521  virtual bool flipHorizontal() {
522  return getData().flipHorizontal();
523  }
524 
528  virtual bool flipVertical() {
529  return getData().flipVertical();
530  }
531 
535  virtual bool stretch(const RPolyline& area, const RVector& offset) {
536  return getData().stretch(area, offset);
537  }
538 
542  void update() const {
543  getData().update();
544  }
545 
549  virtual RShape* castToShape() {
550  return getData().castToShape();
551  }
552 
556  virtual const RShape* castToConstShape() const {
557  return getData().castToConstShape();
558  }
559 
565  virtual void exportEntity(RExporter& e, bool preview = false, bool forceSelected=false) const = 0;
566 
567  // from RObject:
569  return isSelected();
570  }
571 
572  virtual QPair<QVariant, RPropertyAttributes> getProperty(
573  RPropertyTypeId& propertyTypeId,
574  bool humanReadable = false, bool noAttributes = false);
575 
576  virtual bool setProperty(RPropertyTypeId propertyTypeId,
577  const QVariant& value, RTransaction* transaction=NULL);
578 
579  bool isVisible() const;
580  bool isEditable(bool allowInvisible = false) const;
581 
582  virtual int getComplexity() const {
583  return 1;
584  }
585 
586  void dump();
587 
588 protected:
589  virtual void print(QDebug dbg) const;
590 };
591 
593 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
594 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
595 Q_DECLARE_METATYPE(QStack<REntity*>)
596 Q_DECLARE_METATYPE(QStack<REntity*>*)
597 
598 #endif