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 friend class RViewportEntity;
42 
43 protected:
45 
46 public:
48  RBlockReferenceData(RBlock::Id referencedBlockId,
49  const RVector& position, const RVector& scaleFactors, double angle);
50 
51  virtual RBox getBoundingBox(bool ignoreEmpty=false) const;
52 
53  virtual QList<RVector> getInternalReferencePoints(
55  virtual QList<RVector> getReferencePoints(
57  virtual RVector getVectorTo(const RVector& point,
58  bool limited = true, double strictRange = RMAXDOUBLE) const;
59  virtual double getDistanceTo(const RVector& point,
60  bool limited = true, double range = 0.0, bool draft = false, double strictRange = RMAXDOUBLE) const;
61 
62  virtual QList<QSharedPointer<RShape> > getShapes(const RBox& queryBox = RDEFAULT_RBOX, bool ignoreComplex = false) const;
63 
64  //virtual void setSelected(bool on);
65 
66  virtual bool moveReferencePoint(const RVector& referencePoint,
67  const RVector& targetPoint);
68  virtual bool move(const RVector& offset);
69  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
70  virtual bool mirror(const RLine& axis);
71  virtual bool scale(const RVector& scaleFactors,
72  const RVector& center = RDEFAULT_RVECTOR);
73 
75  referencedBlockId = blockId;
76  }
77 
78  void groundReferencedBlockId() const {
79  referencedBlockId = RBlock::INVALID_ID;
80  }
81 
83  return referencedBlockId;
84  }
85 
86  void setReferencedBlockName(const QString& blockName);
87  QString getReferencedBlockName() const;
88 
89  RVector getPosition() const {
90  return position;
91  }
92 
93  void setPosition(const RVector& p) {
94  position = p;
95  }
96 
98  return scaleFactors;
99  }
100 
101  void setScaleFactors(const RVector& sf) {
102  scaleFactors = sf;
103  if (fabs(scaleFactors.x) < RS::PointTolerance) {
104  scaleFactors.x = 1.0;
105  }
106  if (fabs(scaleFactors.y) < RS::PointTolerance) {
107  scaleFactors.y = 1.0;
108  }
109  if (fabs(scaleFactors.z) < RS::PointTolerance) {
110  scaleFactors.z = 1.0;
111  }
112  }
113 
114  double getRotation() const {
115  return rotation;
116  }
117 
118  void setRotation(double r) {
119  rotation = r;
120  }
121 
122  virtual void update() const;
123  virtual void update(RObject::Id entityId) const;
124 
125  QSharedPointer<REntity> queryEntity(REntity::Id entityId) const;
126  bool applyTransformationTo(REntity& entity) const;
127  RVector mapToBlock(const RVector& v) const;
128 
129 private:
133  double rotation;
134  mutable RBox boundingBox;
135  mutable QMap<REntity::Id, QSharedPointer<REntity> > cache;
136 };
137 
141 
142 #endif