QCAD
Open Source 2D CAD
REntityData.h
Go to the documentation of this file.
1 
20 #ifndef RENTITYDATA_H
21 #define RENTITYDATA_H
22 
23 #include "core_global.h"
24 
25 #include <QList>
26 #include <QStack>
27 
28 #include "RBlock.h"
29 #include "RBox.h"
30 #include "RColor.h"
31 #include "RLayer.h"
32 #include "RLine.h"
33 #include "RMatrix.h"
34 #include "RObject.h"
35 #include "RPolyline.h"
36 #include "RRefPoint.h"
37 #include "RSettings.h"
38 #include "RView.h"
39 
41 class RDocument;
42 class REntity;
43 class RExporter;
44 
45 #ifndef RDEFAULT_QSET_INT
46 #define RDEFAULT_QSET_INT QSet<int>()
47 #endif
48 
49 #ifndef RDEFAULT_TOLERANCE_1E_MIN4
50 #define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
51 #endif
52 
66 
67  friend class REntity;
68 
69 public:
71 
72  virtual ~REntityData() {}
73 
75  return document;
76  }
77 
78  const RDocument* getDocument() const {
79  return document;
80  }
81 
83  this->document = document;
84  }
85 
86  virtual RS::EntityType getType() const {
87  return RS::EntityUnknown;
88  }
89 
93  virtual bool isPointType() const {
94  return false;
95  }
96 
97  virtual bool isValid() const {
98  return true;
99  }
100  virtual bool isSane() const {
101  return true;
102  }
103 
111  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false, bool segment = false) const {
112  Q_UNUSED(queryBox)
113  Q_UNUSED(ignoreComplex)
114  Q_UNUSED(segment)
115 
116  return QList<QSharedPointer<RShape> >();
117  }
118 
123  virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false) const;
124 
125  virtual RShape* castToShape() {
126  return NULL;
127  }
128 
132  virtual const RShape* castToConstShape() const {
133  return const_cast<REntityData*>(this)->castToShape();
134  }
135 
136  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
137 
138  virtual void to2D();
139  virtual void setZ(double z);
140 
148  virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
149  return QList<RBox>() << getBoundingBox(ignoreEmpty);
150  }
151 
152  virtual RPolyline getHull(double offset) const;
153 
157  virtual bool isUpdatesEnabled() const {
158  return updatesEnabled;
159  }
160 
164  void setUpdatesEnabled(bool on) {
165  updatesEnabled = on;
166  }
167 
171  virtual bool cloneOnChange() const {
172  return false;
173  }
174 
179  virtual bool isSelected() const {
180  return selectionStatus;
181  }
182 
186  virtual void setSelected(bool on) {
187  selectionStatus = on;
188  }
189 
194  virtual int getDrawOrder() const {
195  return drawOrder;
196  }
197 
201  virtual void setDrawOrder(int drawOrder) {
202  this->drawOrder = drawOrder;
203  }
204 
205  virtual void setLayerId(RLayer::Id layerId) {
206  this->layerId = layerId;
207  }
208 
210  return layerId;
211  }
212 
213  void setLayerName(const QString& layerName);
214  QString getLayerName() const;
215 
216  virtual void setBlockId(RBlock::Id blockId) {
217  this->blockId = blockId;
218  }
219 
221  return blockId;
222  }
223 
224  virtual void setParentId(RObject::Id parentId) {
225  this->parentId = parentId;
226  }
227 
232  return parentId;
233  }
234 
235  QString getBlockName() const;
236 
241  virtual void setLinetypeId(RLinetype::Id linetypeId) {
242  this->linetypeId = linetypeId;
243  }
244 
248  virtual RLinetype::Id getLinetypeId() const {
249  return linetypeId;
250  }
251 
252  virtual void setLinetypePattern(const RLinetypePattern& p);
253  virtual RLinetypePattern getLinetypePattern() const;
254 
255  virtual RLinetype::Id getLinetypeId(bool resolve,
256  const QStack<REntity*>& blockRefStack) const;
257 
258  virtual void setLinetypeScale(double linetypeScale) {
259  this->linetypeScale = linetypeScale;
260  }
261 
262  virtual double getLinetypeScale() const {
263  return linetypeScale;
264  }
265 
267  return lineweight;
268  }
269 
270  virtual RLineweight::Lineweight getLineweight(bool resolve,
271  const QStack<REntity*>& blockRefStack) const;
272 
273  double getLineweightInUnits(const QStack<REntity*>& blockRefStack) const;
274 
276  this->lineweight = lineweight;
277 // if (RSettings::getAutoScaleLinetypePattern()) {
278 // this->linetypeScale = lineweight;
279 // }
280  }
281 
282  void setColor(const RColor& color) {
283  this->color = color;
284  }
285 
286  virtual RColor getColor() const {
287  return color;
288  }
289 
290  virtual RColor getColor(bool resolve, const QStack<REntity *>& blockRefStack) const;
291 
293  QStack<REntity*> stack;
294  return getColor(true, stack);
295  }
296 
304  return getReferencePoints(hint);
305  }
306 
312  virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const = 0;
313 
314  virtual RVector getPointOnEntity() const;
315  virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX) const;
316  virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX) const;
317  virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX) const;
318  virtual QList<RVector> getPointsWithDistanceToEnd(
319  double distance, int from = RS::FromAny, const RBox& queryBox = RDEFAULT_RBOX) const;
320 
321  virtual RVector getClosestPointOnEntity(const RVector& point,
322  double range=RNANDOUBLE, bool limited=true) const;
323 
324 // /**
325 // * Override to disable intersection point
326 // */
327 // virtual bool intersectionsEnabled() {
328 // return true;
329 // }
330 
331  virtual QList<RVector> getIntersectionPoints(
332  const REntityData& other, bool limited = true, bool same = false,
333  const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
334  virtual QList<RVector> getIntersectionPoints(
335  const RShape& shape, bool limited = true,
336  const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
337 
338  virtual RVector getVectorTo(const RVector& point, bool limited=true, double strictRange = RMAXDOUBLE) const;
339 
340  virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
341 
346  virtual bool isInside(const RBox& box) const {
347  return box.contains(getBoundingBox());
348  }
349 
350  virtual bool isOnEntity(const RVector& point, bool limited = true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
351 
352  virtual bool intersectsWith(const RShape& shape) const;
353 
359  virtual bool clickReferencePoint(const RVector& referencePoint) {
360  Q_UNUSED(referencePoint)
361  return false;
362  }
363 
371  virtual bool moveReferencePoint(
372  const RVector& referencePoint, const RVector& targetPoint
373  ) = 0;
374 
375  virtual bool move(const RVector& offset);
376  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
377  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
378  virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
379  virtual void scaleVisualProperties(double scaleFactor);
380  virtual bool mirror(const RLine& axis);
381  virtual bool mirror(const RVector& axis1, const RVector& axis2);
382  virtual bool flipHorizontal();
383  virtual bool flipVertical();
384  virtual bool stretch(const RPolyline& area, const RVector& offset);
385 
390  virtual void update() const {}
391  void setAutoUpdatesBlocked(bool on);
392 
393  static int getDefaultDrawOrder() {
394  return RMININT;
395  }
396 
397 protected:
411 };
412 
415 Q_DECLARE_METATYPE(QSharedPointer<REntityData>)
416 Q_DECLARE_METATYPE(QSharedPointer<REntityData>*)
417 
418 #endif
RObject::Id getParentId() const
Definition: REntityData.h:231
virtual bool isOnEntity(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: REntity.h:409
RDocument * getDocument()
Definition: REntityData.h:74
Represents a box e.g.
Definition: RBox.h:43
RBlock::Id getBlockId() const
Definition: REntityData.h:220
Base class for all entity data classes.
Definition: REntityData.h:65
RDocument * document
Definition: REntityData.h:398
void setLineweight(RLineweight::Lineweight lineweight)
Definition: REntityData.h:275
virtual bool isPointType() const
Definition: REntityData.h:93
virtual void setLayerId(RLayer::Id layerId)
Definition: REntityData.h:205
RLineweight::Lineweight getLineweight() const
Definition: REntity.h:304
Unknown entity.
Definition: RS.h:138
virtual void to2D()
Definition: REntity.h:346
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual RShape * castToShape()
Definition: REntity.h:609
virtual QSharedPointer< RShape > getClosestShape(const RVector &pos, double range=RNANDOUBLE, bool ignoreComplex=false) const
Definition: REntity.h:388
#define RDEFAULT_RBOX
Definition: RBox.h:32
virtual RLineweight::Lineweight getLineweight() const
Definition: REntityData.h:266
virtual RVector getClosestPointOnEntity(const RVector &point, double range=RNANDOUBLE, bool limited=true) const
Definition: REntity.h:479
RLinetype::Id linetypeId
Definition: REntityData.h:407
virtual bool flipVertical()
Definition: REntity.h:588
virtual RColor getDisplayColor()
Definition: REntityData.h:292
virtual QList< RVector > getCenterPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:472
virtual RColor getColor() const
Definition: REntityData.h:286
virtual bool isSane() const
Definition: REntityData.h:100
QString getBlockName() const
Definition: REntity.h:235
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:125
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:595
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
Definition: REntity.h:339
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false) const
Definition: REntityData.h:111
virtual void setLinetypeScale(double linetypeScale)
Definition: REntityData.h:258
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:523
const RDocument * getDocument() const
Definition: REntityData.h:78
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:81
virtual bool isSelected() const
Definition: REntityData.h:179
#define QCADCORE_EXPORT
Definition: core_global.h:10
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:109
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
Definition: REntity.h:423
int Id
Definition: RObject.h:66
virtual RS::EntityType getType() const
Definition: REntityData.h:86
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition: REntityData.h:148
virtual void setSelected(bool on)
Selects or deselects this entity.
Definition: REntityData.h:186
RColor getColor() const
Definition: REntity.h:323
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RLinetypePattern.h:45
bool updatesEnabled
Definition: REntityData.h:399
virtual RLinetype::Id getLinetypeId() const
Definition: REntityData.h:248
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:255
virtual RVector getPointOnEntity() const
Definition: REntity.h:451
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:183
#define RMININT
Definition: RMath.h:68
Lineweight
Definition: RLineweight.h:46
Color.
Definition: RColor.h:44
virtual const RShape * castToConstShape() const
Definition: REntityData.h:132
RLineweight::Lineweight lineweight
Definition: REntityData.h:409
double linetypeScale
Definition: REntityData.h:408
void setLinetypePattern(const RLinetypePattern &linetypePattern)
Definition: REntity.h:256
virtual void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition: REntityData.h:201
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:430
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:25
virtual bool isInside(const RBox &box) const
Definition: REntityData.h:346
virtual QList< RVector > getMiddlePoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:465
virtual double getLinetypeScale() const
Definition: REntityData.h:262
virtual void setAutoUpdatesBlocked(bool on)
Definition: REntity.h:632
#define RMAXDOUBLE
Definition: RMath.h:63
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:95
virtual int getDrawOrder() const
Definition: REntityData.h:194
double getLineweightInUnits(const QStack< REntity * > &blockRefStack) const
Definition: REntity.cpp:135
bool autoUpdatesBlocked
Block auto updates is true during imports, undo and redo.
Definition: REntityData.h:402
virtual void setLinetypeId(RLinetype::Id linetypeId)
Sets the linetype of this entity to the given linetype ID.
Definition: REntityData.h:241
virtual void setZ(double z)
Definition: REntity.h:353
void getIntersectionPoints(void e1, void e2, void limited)
Returns intersection points between the two given entities or shapes.
Definition: simple_info.js:12
virtual void scaleVisualProperties(double scaleFactor)
Definition: REntity.h:560
RLinetype::Id getLinetypeId() const
Definition: REntity.h:263
Low-level mathematical representation of a line.
Definition: RLine.h:41
QString getLayerName() const
Definition: REntity.h:214
Definition: RS.h:184
virtual bool isUpdatesEnabled() const
Definition: REntityData.h:157
RObject::Id parentId
Definition: REntityData.h:406
void setUpdatesEnabled(bool on)
Enables / disables cache updates.
Definition: REntityData.h:164
Abstract base class for exporters.
Definition: RExporter.h:71
int drawOrder
Definition: REntityData.h:403
RLayer::Id layerId
Definition: REntityData.h:404
virtual QList< RRefPoint > getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Can be overwritten to return internal, resolved reference points.
Definition: REntityData.h:303
virtual bool clickReferencePoint(const RVector &referencePoint)
Called when user clicks a reference point.
Definition: REntityData.h:359
static int getDefaultDrawOrder()
Definition: REntityData.h:393
virtual ~REntityData()
Definition: REntityData.h:72
RColor color
Definition: REntityData.h:410
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny, const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:488
virtual RShape * castToShape()
Definition: REntityData.h:125
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
RBlock::Id blockId
Definition: REntityData.h:405
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
Definition: REntity.h:444
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: REntityData.h:50
RLayer::Id getLayerId() const
Definition: REntityData.h:209
virtual void setBlockId(RBlock::Id blockId)
Definition: REntityData.h:216
Block reference entity.
Definition: RBlockReferenceEntity.h:38
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual bool isValid() const
Definition: REntityData.h:97
virtual bool flipHorizontal()
Definition: REntity.h:581
bool contains(const RBox &other) const
Definition: RBox.cpp:381
virtual bool intersectsWith(const RShape &shape) const
Definition: REntity.h:416
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty)...
Definition: REntityData.h:390
virtual RPolyline getHull(double offset) const
Definition: REntity.h:367
RLinetypePattern getLinetypePattern() const
Definition: REntity.h:273
void setColor(const RColor &color)
Definition: REntityData.h:282
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition: REntityData.h:171
void setDocument(RDocument *document)
Definition: REntityData.h:82
virtual void setParentId(RObject::Id parentId)
Definition: REntityData.h:224
void setLayerName(const QString &n)
Definition: REntity.h:200
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual QList< RVector > getEndPoints(const RBox &queryBox=RDEFAULT_RBOX) const
Definition: REntity.h:458
bool selectionStatus
Definition: REntityData.h:400
RDocument * document
Definition: RObject.h:306