QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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 "RBox.h"
29#include "RColor.h"
30#include "RLineweight.h"
31#include "RMath.h"
32#include "RObject.h"
33
35class RDocument;
36class REntity;
37class RExporter;
39class RPolyline;
40class RRefPoint;
41class RLine;
42
43#ifndef RDEFAULT_QSET_INT
44#define RDEFAULT_QSET_INT QSet<int>()
45#endif
46
47#ifndef RDEFAULT_TOLERANCE_1E_MIN4
48#define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
49#endif
50
66
67 friend class REntity;
68
69public:
70 REntityData(RDocument* document=NULL);
71
72 virtual ~REntityData() {}
73
75 return document;
76 }
77
78 const RDocument* getDocument() const {
79 return document;
80 }
81
82 void setDocument(RDocument* document) {
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, QList<RObject::Id>* entityIds = NULL) const {
112 Q_UNUSED(queryBox)
113 Q_UNUSED(ignoreComplex)
114 Q_UNUSED(segment)
115 Q_UNUSED(entityIds)
116
117 return QList<QSharedPointer<RShape> >();
118 }
119
123 RObject::Id getClosestSubEntityId(const RVector& pos, double range, bool ignoreComplex) const {
125 QSharedPointer<RShape> shape = getClosestShape(pos, range, ignoreComplex, &ret);
126 return ret;
127 }
128
133 virtual QSharedPointer<RShape> getClosestShape(const RVector& pos, double range = RNANDOUBLE, bool ignoreComplex = false, RObject::Id* subEntityId = NULL) const;
134
135 virtual RShape* castToShape() {
136 return NULL;
137 }
138
142 virtual const RShape* castToConstShape() const {
143 return const_cast<REntityData*>(this)->castToShape();
144 }
145
146 virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
147
148 void copyAttributesFrom(const REntityData& entityData, bool copyBlockId = true);
149
150 virtual void to2D();
151 virtual void setZ(double z);
152
160 virtual QList<RBox> getBoundingBoxes(bool ignoreEmpty=false) const {
161 return QList<RBox>() << getBoundingBox(ignoreEmpty);
162 }
163
164 virtual RPolyline getHull(double offset) const;
165
169 virtual bool isUpdatesEnabled() const {
170 return updatesEnabled;
171 }
172
176 void setUpdatesEnabled(bool on) {
177 updatesEnabled = on;
178 }
179
183 virtual bool cloneOnChange() const {
184 return false;
185 }
186
191 virtual bool isSelected() const {
192 return selectionStatus;
193 }
194
198 virtual void setSelected(bool on) {
199 selectionStatus = on;
200 }
201
205 virtual bool isSelectedWorkingSet() const {
206 return selectionStatusWorkingSet;
207 }
208
212 virtual void setSelectedWorkingSet(bool on) {
213 selectionStatusWorkingSet = on;
214 }
215
220 virtual int getDrawOrder() const {
221 return drawOrder;
222 }
223
227 virtual void setDrawOrder(int drawOrder) {
228 this->drawOrder = drawOrder;
229 }
230
231 virtual void setLayerId(RObject::Id layerId) {
232 this->layerId = layerId;
233 }
234
236 return layerId;
237 }
238
239 void setLayerName(const QString& layerName);
240 QString getLayerName() const;
241
242 virtual void setBlockId(RObject::Id blockId) {
243 this->blockId = blockId;
244 }
245
247 return blockId;
248 }
249
250 virtual void setParentId(RObject::Id parentId) {
251 this->parentId = parentId;
252 }
253
258 return parentId;
259 }
260
261 QString getBlockName() const;
262
267 virtual void setLinetypeId(RObject::Id linetypeId) {
268 this->linetypeId = linetypeId;
269 }
270
274 virtual RObject::Id getLinetypeId() const {
275 return linetypeId;
276 }
277
278 virtual void setLinetypePattern(const RLinetypePattern& p);
279 virtual RLinetypePattern getLinetypePattern() const;
280
281 virtual RObject::Id getLinetypeId(bool resolve,
282 const QStack<QSharedPointer<REntity> >& blockRefStack) const;
283
284 virtual void setLinetypeScale(double linetypeScale) {
285 this->linetypeScale = linetypeScale;
286 }
287
288 virtual double getLinetypeScale() const {
289 return linetypeScale;
290 }
291
293 return lineweight;
294 }
295
296 virtual RLineweight::Lineweight getLineweight(bool resolve,
297 const QStack<QSharedPointer<REntity> >& blockRefStack) const;
298
299 double getLineweightInUnits(const QStack<QSharedPointer<REntity> >& blockRefStack) const;
300
302 this->lineweight = lineweight;
303// if (RSettings::getAutoScaleLinetypePattern()) {
304// this->linetypeScale = lineweight;
305// }
306 }
307
308 void setColor(const RColor& color) {
309 this->color = color;
310 }
311
312 virtual RColor getColor() const {
313 return color;
314 }
315
316 virtual RColor getColor(const RColor& unresolvedColor, const QStack<QSharedPointer<REntity> >& blockRefStack) const;
317 virtual RColor getColor(bool resolve, const QStack<QSharedPointer<REntity> >& blockRefStack) const;
318
320 QStack<QSharedPointer<REntity> > stack;
321 return getColor(true, stack);
322 }
323
330 virtual QList<RRefPoint> getInternalReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop, QList<RObject::Id>* subEntityIds = NULL) const;
331
337 virtual QList<RRefPoint> getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const = 0;
338
339 virtual RVector getPointOnEntity() const;
340 virtual QList<RVector> getEndPoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const;
341 virtual QList<RVector> getMiddlePoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const;
342 virtual QList<RVector> getCenterPoints(const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const;
343 virtual QList<RVector> getArcReferencePoints(const RBox& queryBox = RDEFAULT_RBOX) const;
344 virtual QList<RVector> getPointsWithDistanceToEnd(
345 double distance, int from = RS::FromAny, const RBox& queryBox = RDEFAULT_RBOX, QList<RObject::Id>* subEntityIds = NULL) const;
346
347 virtual RVector getClosestPointOnEntity(const RVector& point,
348 double range=RNANDOUBLE, bool limited=true, RObject::Id* subEntityId = NULL) const;
349
350// /**
351// * Override to disable intersection point
352// */
353// virtual bool intersectionsEnabled() {
354// return true;
355// }
356
357 virtual QList<RVector> getIntersectionPoints(
358 const REntityData& other, bool limited = true, bool same = false,
359 const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true,
360 QList<QPair<RObject::Id, RObject::Id> >* entityIds = NULL) const;
361 virtual QList<RVector> getIntersectionPoints(
362 const RShape& shape, bool limited = true,
363 const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = true) const;
364
365 virtual RVector getVectorTo(const RVector& point, bool limited=true, double strictRange = RMAXDOUBLE) const;
366
367 virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
368
373 virtual bool isInside(const RBox& box) const {
374 return box.contains(getBoundingBox());
375 }
376
377 virtual bool isOnEntity(const RVector& point, bool limited = true, double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
378
379 virtual bool intersectsWith(const RShape& shape) const;
380
386 virtual bool clickReferencePoint(const RVector& referencePoint) {
387 Q_UNUSED(referencePoint)
388 return false;
389 }
390
398 virtual bool moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint, Qt::KeyboardModifiers modifiers = Qt::NoModifier) = 0;
399
400 virtual bool move(const RVector& offset);
401 virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
402 virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
403 virtual bool scale(double scaleFactor, const RVector& center = RDEFAULT_RVECTOR);
404 virtual void scaleVisualProperties(double scaleFactor);
405 virtual bool mirror(const RLine& axis);
406 virtual bool mirror(const RVector& axis1, const RVector& axis2);
407 virtual bool flipHorizontal();
408 virtual bool flipVertical();
409 virtual bool stretch(const RPolyline& area, const RVector& offset);
410
415 virtual void update() const {}
416 void setAutoUpdatesBlocked(bool on);
417 bool getAutoUpdatesBlocked() const;
418
419 static int getDefaultDrawOrder() {
420 return RMININT;
421 }
422
423protected:
438};
439
442Q_DECLARE_METATYPE(QSharedPointer<REntityData>)
443Q_DECLARE_METATYPE(QSharedPointer<REntityData>*)
444
445#endif
#define RDEFAULT_RBOX
Definition RBox.h:35
#define RNANDOUBLE
Definition RMath.h:74
Q_DECLARE_METATYPE(RMath *)
#define RMININT
Definition RMath.h:71
#define RMAXDOUBLE
Definition RMath.h:66
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition RShape.h:43
#define RDEFAULT_RVECTOR
Definition RVector.h:38
Block reference entity.
Definition RBlockReferenceEntity.h:38
Represents a box e.g.
Definition RBox.h:46
bool contains(const RBox &other) const
Definition RBox.cpp:408
Color.
Definition RColor.h:43
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition RDocument.h:78
Base class for all entity data classes.
Definition REntityData.h:65
RDocument * getDocument()
Definition REntityData.h:74
virtual void setSelected(bool on)
Selects or deselects this entity.
Definition REntityData.h:198
bool autoUpdatesBlocked
Block auto updates is true during imports, undo and redo.
Definition REntityData.h:429
void setColor(const RColor &color)
Definition REntityData.h:308
double linetypeScale
Definition REntityData.h:435
virtual void setLinetypeId(RObject::Id linetypeId)
Sets the linetype of this entity to the given linetype ID.
Definition REntityData.h:267
static int getDefaultDrawOrder()
Definition REntityData.h:419
virtual void setLayerId(RObject::Id layerId)
Definition REntityData.h:231
virtual bool isSelected() const
Definition REntityData.h:191
virtual RS::EntityType getType() const
Definition REntityData.h:86
const RDocument * getDocument() const
Definition REntityData.h:78
void setLineweight(RLineweight::Lineweight lineweight)
Definition REntityData.h:301
RObject::Id parentId
Definition REntityData.h:433
virtual void setSelectedWorkingSet(bool on)
Selects or deselects this entity for addition to the current working set.
Definition REntityData.h:212
RObject::Id blockId
Definition REntityData.h:432
virtual bool isInside(const RBox &box) const
Definition REntityData.h:373
virtual RShape * castToShape()
Definition REntityData.h:135
virtual bool isSane() const
Definition REntityData.h:100
int drawOrder
Definition REntityData.h:430
RLineweight::Lineweight lineweight
Definition REntityData.h:436
virtual QList< RBox > getBoundingBoxes(bool ignoreEmpty=false) const
Definition REntityData.h:160
virtual RColor getDisplayColor()
Definition REntityData.h:319
virtual RObject::Id getLinetypeId() const
Definition REntityData.h:274
bool selectionStatusWorkingSet
Definition REntityData.h:427
RObject::Id getClosestSubEntityId(const RVector &pos, double range, bool ignoreComplex) const
Convenience function for scripts.
Definition REntityData.h:123
RObject::Id linetypeId
Definition REntityData.h:434
virtual void setParentId(RObject::Id parentId)
Definition REntityData.h:250
RObject::Id layerId
Definition REntityData.h:431
virtual void setLinetypeScale(double linetypeScale)
Definition REntityData.h:284
RObject::Id getParentId() const
Definition REntityData.h:257
virtual bool isSelectedWorkingSet() const
Definition REntityData.h:205
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint, Qt::KeyboardModifiers modifiers=Qt::NoModifier)=0
Moves the given reference point to the given target point or does nothing if this entity has no refer...
virtual RLineweight::Lineweight getLineweight() const
Definition REntityData.h:292
virtual int getDrawOrder() const
Definition REntityData.h:220
virtual bool isUpdatesEnabled() const
Definition REntityData.h:169
virtual ~REntityData()
Definition REntityData.h:72
virtual bool isValid() const
Definition REntityData.h:97
virtual void setBlockId(RObject::Id blockId)
Definition REntityData.h:242
void setUpdatesEnabled(bool on)
Enables / disables cache updates.
Definition REntityData.h:176
virtual void setDrawOrder(int drawOrder)
Sets the draw order of this entity.
Definition REntityData.h:227
RDocument * document
Definition REntityData.h:424
RObject::Id getLayerId() const
Definition REntityData.h:235
bool updatesEnabled
Definition REntityData.h:425
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const =0
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
Definition REntityData.h:183
virtual bool clickReferencePoint(const RVector &referencePoint)
Called when user clicks a reference point.
Definition REntityData.h:386
virtual double getLinetypeScale() const
Definition REntityData.h:288
void setDocument(RDocument *document)
Definition REntityData.h:82
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty).
Definition REntityData.h:415
RObject::Id getBlockId() const
Definition REntityData.h:246
virtual const RShape * castToConstShape() const
Definition REntityData.h:142
virtual RColor getColor() const
Definition REntityData.h:312
RColor color
Definition REntityData.h:437
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false, QList< RObject::Id > *entityIds=NULL) const
Definition REntityData.h:111
virtual bool isPointType() const
Definition REntityData.h:93
bool selectionStatus
Definition REntityData.h:426
Base class for all entity classes.
Definition REntity.h:63
Abstract base class for exporters.
Definition RExporter.h:78
Low-level mathematical representation of a line.
Definition RLine.h:41
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RLinetypePattern.h:42
Lineweight
Definition RLineweight.h:44
static const Id INVALID_ID
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RObject.h:70
int Id
Definition RObject.h:69
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
Represents a reference point of an entity.
Definition RRefPoint.h:18
@ FromAny
Start or end.
Definition RS.h:374
EntityType
Entity types used for property handling / filtering.
Definition RS.h:227
@ EntityUnknown
Unknown entity.
Definition RS.h:242
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition RS.h:293
@ RenderTop
Definition RS.h:294
Interface for geometrical shape classes.
Definition RShape.h:72
Represents a 3d vector (x/y/z).
Definition RVector.h:47
#define QCADCORE_EXPORT
Definition core_global.h:10
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:109
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition simple_modify.js:58
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:15
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition simple_modify.js:95
void getIntersectionPoints(void e1, void e2, void limited)
Returns intersection points between the two given entities or shapes.
Definition simple_info.js:12
#define NULL
Definition opennurbs_system.h:256