QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
REntity.h
Go to the documentation of this file.
1 #ifndef RENTITY_H
2 #define RENTITY_H
3 
4 #include <QList>
5 #include <QStack>
6 
7 #include "RBox.h"
8 #include "RColor.h"
9 #include "RDebug.h"
10 #include "REntityData.h"
11 #include "RLayer.h"
12 #include "RLineweight.h"
13 #include "RMatrix.h"
14 #include "RObject.h"
15 #include "RPropertyAttributes.h"
16 #include "RPropertyTypeId.h"
17 #include "RVector.h"
18 #include "RExplodable.h"
19 
20 class RDocument;
21 class REntity;
23 class RExporter;
24 
25 #ifndef RDEFAULT_QSET_INT
26 #define RDEFAULT_QSET_INT QSet<int>()
27 #endif
28 
39 class REntity : public RObject {
40 
41  Q_DECLARE_TR_FUNCTIONS(REntity)
42 
43 public:
53 
54 public:
56  virtual ~REntity();
57 
58  static void init();
59 
61  RObject::setDocument(document);
62  getData().setDocument(document);
63  }
64 
65  virtual REntity* clone() const = 0;
66 
67  virtual RS::EntityType getType() const {
68  return RS::EntityUnknown;
69  }
70 
74  virtual REntityData& getData() = 0;
75 
79  virtual const REntityData& getData() const = 0;
80 
84  bool isSelected() const {
85  return getData().isSelected();
86  }
87 
88  void setSelected(bool on);
89 
93  void setDrawOrder(int drawOrder) {
94  getData().setDrawOrder(drawOrder);
95  }
96 
100  int getDrawOrder() const {
101  return getData().getDrawOrder();
102  }
103 
107  void setLayerId(RLayer::Id layerId) {
108  getData().setLayerId(layerId);
109  }
110 
115  return getData().getLayerId();
116  }
117 
121  QString getLayerName() {
122  return getData().getLayerName();
123  }
124 
128  void setBlockId(RBlock::Id blockId) {
129  getData().setBlockId(blockId);
130  }
131 
136  return getData().getBlockId();
137  }
138 
142  QString getBlockName() {
143  return getData().getBlockName();
144  }
145 
149  void setLinetypeId(RLinetype::Id linetypeId) {
150  getData().setLinetypeId(linetypeId);
151  }
152 
156  void setLinetype(RLinetype linetype) {
157  getData().setLinetype(linetype);
158  }
159 
164  return getData().getLinetypeId();
165  }
166 
167  RLinetype::Id getLinetypeId(bool resolve,
168  const QStack<RBlockReferenceEntity*>& blockRefStack) const;
169 
174  getData().setLineweight(lineweight);
175  }
176 
181  return getData().getLineweight();
182  }
183 
185  const QStack<RBlockReferenceEntity*>& blockRefStack) const;
186 
187  double getLineweightInUnits(const QStack<RBlockReferenceEntity*>& blockRefStack) const;
188 
192  void setColor(const RColor& color) {
193  getData().setColor(color);
194  }
195 
199  RColor getColor() const {
200  return getData().getColor();
201  }
202 
203  RColor getColor(bool resolve, const QStack<RBlockReferenceEntity*>& blockRefStack);
204 
205  void copyAttributesFrom(REntity* entity);
206 
210  virtual RBox getBoundingBox() const {
211  return getData().getBoundingBox();
212  }
213 
217  virtual QList<RBox> getBoundingBoxes(/*REntity::Id subEntityId = REntity::INVALID_ID*/) const {
218  return getData().getBoundingBoxes(/*subEntityId*/);
219  }
220 
224 // virtual QList<QPair<REntity::Id, RBox> > getIdBoundingBoxes() const {
225 // return getData().getIdBoundingBoxes();
226 // }
227 
231  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX) const {
232  return getData().getShapes(queryBox);
233  }
234 
238  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE) const {
239  return getData().getClosestShape(pos, range);
240  }
241 
245  virtual bool isInside(const RBox& box) const {
246  return getData().isInside(box);
247  }
248 
252  virtual bool isOnEntity(const RVector& point, bool limited=true) const {
253  return getData().isOnEntity(point, limited);
254  }
255 
259  virtual bool intersectsWith(const RShape& shape) const {
260  return getData().intersectsWith(shape);
261  }
262 
266  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false) const {
267  return getData().getDistanceTo(point, limited, range, draft);
268  }
269 
273  virtual RVector getVectorTo(const RVector& point, bool limited = true) const {
274  return getData().getVectorTo(point, limited);
275  }
276 
280  virtual QList<RVector> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const {
281  return getData().getReferencePoints(hint);
282  }
283 
287  virtual RVector getPointOnEntity() const {
288  return getData().getPointOnEntity();
289  }
290 
294  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
295  return getData().getEndPoints(queryBox);
296  }
297 
301  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const {
302  return getData().getMiddlePoints(queryBox);
303  }
304 
308  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const {
309  return getData().getCenterPoints(queryBox);
310  }
311 
316  double range=RNANDOUBLE, bool limited=true) const {
317 
318  return getData().getClosestPointOnEntity(point, range, limited);
319  }
320 
324  virtual QList<RVector> getPointsWithDistanceToEnd(
325  double distance,
326  RS::From from = RS::FromAny,
327  const RBox& queryBox = RDEFAULT_RBOX) const {
328  return getData().getPointsWithDistanceToEnd(distance, from, queryBox);
329  }
330 
334  /*
335  virtual QList<RVector> getIntersectionPoints(RDocument& document) const {
336  return getData().getIntersectionPoints(document);
337  }
338  */
339 
343  virtual QList<RVector> getIntersectionPoints(
344  const REntity& other, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX
345  /*const QSet<int>& pos = RDEFAULT_QSET_INT, const QSet<int>& posOther = RDEFAULT_QSET_INT*/) const;
346 
350  virtual QList<RVector> getIntersectionPoints(const RShape& shape, bool limited = true, const RBox& queryBox = RDEFAULT_RBOX) const;
351 
355  virtual bool moveReferencePoint(
356  const RVector& referencePoint, const RVector& targetPoint) {
357  return getData().moveReferencePoint(referencePoint, targetPoint);
358  }
359 
363  virtual bool move(const RVector& offset) {
364  return getData().move(offset);
365  }
366 
370  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
371  return getData().rotate(rotation, center);
372  }
373 
377  virtual bool scale(const RVector& scaleFactors,
378  const RVector& center = RDEFAULT_RVECTOR) {
379 
380  return getData().scale(scaleFactors, center);
381  }
382 
386  virtual bool scale(double scaleFactor,
387  const RVector& center = RDEFAULT_RVECTOR) {
388 
389  return getData().scale(scaleFactor, center);
390  }
391 
395  virtual bool mirror(const RLine& axis) {
396  return getData().mirror(axis);
397  }
398 
402  virtual bool mirror(const RVector& axis1, const RVector& axis2) {
403  return getData().mirror(axis1, axis2);
404  }
405 
409  virtual bool flipHorizontal() {
410  return getData().flipHorizontal();
411  }
412 
416  virtual bool flipVertical() {
417  return getData().flipVertical();
418  }
419 
423  virtual bool stretch(const RPolyline& area, const RVector& offset) {
424  return getData().stretch(area, offset);
425  }
426 
430  void update() const {
431  getData().update();
432  }
433 
437  virtual RShape* castToShape() {
438  return getData().castToShape();
439  }
440 
444  virtual const RShape* castToConstShape() const {
445  return getData().castToConstShape();
446  }
447 
453  virtual void exportEntity(RExporter& e, bool preview = false) const = 0;
454 
455  // from RObject:
457  return isSelected();
458  }
459 
460  virtual QPair<QVariant, RPropertyAttributes> getProperty(
461  RPropertyTypeId propertyTypeId,
462  bool humanReadable = false, bool noAttributes = false);
463 
464  virtual bool setProperty(RPropertyTypeId propertyTypeId,
465  const QVariant& value);
466 
467  bool isVisible() const;
468  bool isEditable(bool allowInvisible = false) const;
469 
470  virtual int getComplexity() const {
471  return 1;
472  }
473 
474  void dump();
475 
476 protected:
477  virtual void print(QDebug dbg) const;
478 };
479 
481 Q_DECLARE_METATYPE(QSharedPointer<REntity>)
482 Q_DECLARE_METATYPE(QSharedPointer<REntity>*)
483 Q_DECLARE_METATYPE(QStack<REntity*>)
484 
485 #endif