QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RBlockReferenceData.h
Go to the documentation of this file.
1 
20 #ifndef RBLOCKREFERENCEDATA_H
21 #define RBLOCKREFERENCEDATA_H
22 
23 #include "core_global.h"
24 
25 #include "RBox.h"
26 #include "REntity.h"
27 #include "RVector.h"
28 #include "RBlock.h"
29 
30 class RDocument;
31 
39 
40 friend class RBlockReferenceEntity;
41 
42 protected:
44 
45 public:
47  RBlockReferenceData(RBlock::Id referencedBlockId,
48  const RVector& position, const RVector& scaleFactors, double angle);
49 
50  virtual RBox getBoundingBox() const;
51 
52  virtual QList<RVector> getInternalReferencePoints(
54  virtual QList<RVector> getReferencePoints(
56  virtual RVector getVectorTo(const RVector& point,
57  bool limited = true) const;
58  virtual double getDistanceTo(const RVector& point,
59  bool limited = true, double range = 0.0, bool draft = false) const;
60 
61  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX) const;
62 
63  //virtual void setSelected(bool on);
64 
65  virtual bool moveReferencePoint(const RVector& referencePoint,
66  const RVector& targetPoint);
67  virtual bool move(const RVector& offset);
68  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
69  virtual bool mirror(const RLine& axis);
70  virtual bool scale(const RVector& scaleFactors,
71  const RVector& center = RDEFAULT_RVECTOR);
72 
74  referencedBlockId = blockId;
75  }
76 
77  void groundReferencedBlockId() const {
78  referencedBlockId = RBlock::INVALID_ID;
79  }
80 
82  return referencedBlockId;
83  }
84 
85  void setReferencedBlockName(const QString& blockName);
86  QString getReferencedBlockName() const;
87 
88  RVector getPosition() const {
89  return position;
90  }
91 
92  void setPosition(const RVector& p) {
93  position = p;
94  }
95 
97  return scaleFactors;
98  }
99 
100  void setScaleFactors(const RVector& sf) {
101  scaleFactors = sf;
102  if (fabs(scaleFactors.x) < RS::PointTolerance) {
103  scaleFactors.x = 1.0;
104  }
105  if (fabs(scaleFactors.y) < RS::PointTolerance) {
106  scaleFactors.y = 1.0;
107  }
108  if (fabs(scaleFactors.z) < RS::PointTolerance) {
109  scaleFactors.z = 1.0;
110  }
111  }
112 
113  double getRotation() const {
114  return rotation;
115  }
116 
117  void setRotation(double r) {
118  rotation = r;
119  }
120 
121  virtual void update() const;
122  virtual void update(RObject::Id entityId) const;
123 
124  QSharedPointer<REntity> queryEntity(REntity::Id entityId) const;
125  bool applyTransformationTo(REntity& entity) const;
126  RVector mapToBlock(const RVector& v) const;
127 
128 private:
132  double rotation;
133  mutable RBox boundingBox;
134  mutable QMap<REntity::Id, QSharedPointer<REntity> > cache;
135 };
136 
140 
141 #endif