QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RDocument.h
Go to the documentation of this file.
1 
20 #ifndef RDOCUMENT_H
21 #define RDOCUMENT_H
22 
23 #include "core_global.h"
24 
25 #include <QString>
26 #include <QSharedPointer>
27 
28 #include "RBlock.h"
29 #include "RBlockReferenceEntity.h"
30 #include "REntity.h"
31 #include "RNonCopyable.h"
32 #include "RRequireHeap.h"
33 #include "RSpatialIndex.h"
34 #include "RTransactionStack.h"
35 #include "RUcs.h"
36 #include "RLayer.h"
37 #include "RLinetype.h"
38 #include "RView.h"
39 
40 class RVector;
41 class RStorage;
42 
43 #ifndef RDEFAULT_QVARIANT
44 #define RDEFAULT_QVARIANT QVariant()
45 #endif
46 
47 #define RDEFAULT_QLIST_RS_ENTITYTYPE QList<RS::EntityType>()
48 
49 
63 public:
64  RDocument(RStorage& storage, RSpatialIndex& spatialIndex);
65  virtual ~RDocument();
66 
67  void init();
68 
69  RStorage& getStorage();
70  const RStorage& getStorage() const;
71  RSpatialIndex& getSpatialIndex();
72  RTransactionStack& getTransactionStack();
73 
74  void clear();
75 
76  REntity::Id queryClosestXY(
77  const RVector& wcsPosition,
78  double range,
79  bool draft,
80  bool includeLockedLayers = true
81  );
82  REntity::Id queryClosestXY(
83  QSet<REntity::Id>& candidates,
84  const RVector& wcsPosition,
85  double range,
86  bool draft
87  );
88 
89  QSet<RObject::Id> queryAllObjects() const;
90  QSet<REntity::Id> queryAllEntities(bool undone = false, bool allBlocks = false, RS::EntityType type = RS::EntityAll) const;
91  QSet<RUcs::Id> queryAllUcs() const;
92  QSet<RLayer::Id> queryAllLayers() const;
93  QSet<RBlock::Id> queryAllBlocks() const;
94  QSet<RView::Id> queryAllViews() const;
95  QSet<RLinetype::Id> queryAllLinetypes() const;
96 
97  QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) const;
98  QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) const;
99  QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll) const;
100  bool hasChildEntities(REntity::Id parentId) const;
101  QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) const;
102  QSet<REntity::Id> queryAllBlockReferences() const;
103 
104  QSet<REntity::Id> queryContainedEntities(
105  const RBox& box
106  );
107 
108  QSet<REntity::Id> queryInfiniteEntities();
109  QSet<REntity::Id> queryIntersectedEntitiesXY(
110  const RBox& box,
111  bool checkBoundingBoxOnly=false,
112  bool includeLockedLayers=true,
113  RBlock::Id blockId = RBlock::INVALID_ID,
114  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
115  );
116 
117  QMap<REntity::Id, QSet<int> > queryIntersectedShapesXY(
118  const RBox& box,
119  bool checkBoundingBoxOnly=false,
120  bool includeLockedLayers=true,
121  RBlock::Id blockId = RBlock::INVALID_ID,
122  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
123  );
124 
125  QSet<REntity::Id> queryContainedEntitiesXY(
126  const RBox& box
127  );
128 
129  QSet<REntity::Id> querySelectedEntities();
130 
131  QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
132  QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
133  QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
134  QSharedPointer<REntity> queryEntity(REntity::Id entityId) const;
135  QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const;
136  QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
137  QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
138  QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
139  QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
140  QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
141  QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
142  QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
143  QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
144  QSharedPointer<RView> queryView(RView::Id viewId) const;
145  QSharedPointer<RView> queryView(const QString& viewName) const;
146  QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
147  QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
148 
149  void clearSelection(
150  QSet<REntity::Id>* affectedEntities=NULL
151  );
152 
153  void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
154 
155  void selectEntity(
156  REntity::Id entityId,
157  bool add=false,
158  QSet<REntity::Id>* affectedEntities=NULL
159  );
160  void deselectEntity(
161  REntity::Id entityId,
162  QSet<REntity::Id>* affectedEntities=NULL
163  );
164  void selectEntities(
165  const QSet<REntity::Id>& entityId,
166  bool add=false,
167  QSet<REntity::Id>* affectedEntities=NULL
168  );
169  void deselectEntities(
170  const QSet<REntity::Id>& entityId,
171  QSet<REntity::Id>* affectedEntities=NULL
172  );
173  bool isSelected(REntity::Id entityId);
174  bool isLayerLocked(RLayer::Id layerId) const;
175  bool isEntityEditable(REntity::Id entityId) const;
176  //bool isEntityLayerLocked(REntity::Id entityId) const;
177  bool isLayerFrozen(RLayer::Id layerId) const;
178  bool isBlockFrozen(RBlock::Id blockId) const;
179  bool isEntityLayerFrozen(REntity::Id entityId) const;
180 
181  bool hasSelection() const;
182 
183  RBox getBoundingBox(bool includeHiddenLayer = true) const;
184  RBox getSelectionBox() const;
185 
186  //void addToSpatialIndex(RObject& object, bool isNew = false);
187  virtual void rebuildSpatialIndex();
188  //void addToSpatialIndex(QSharedPointer<REntity> entity);
189  void addToSpatialIndex(QSharedPointer<REntity> entity);
190 
191  bool blockContainsReferences(RBlock::Id blockId, RBlock::Id referencedBlockId);
192 
193  void removeBlockFromSpatialIndex(RBlock::Id blockId);
194  bool addBlockToSpatialIndex(RBlock::Id blockId, RObject::Id ignoreBlockId);
195  virtual void removeFromSpatialIndex(QSharedPointer<REntity> entity);
196  //virtual void removeFromSpatialIndex2(QSharedPointer<REntity> entity);
197 
198  void updateAllEntities();
199 
200  RTransaction undo();
201  RTransaction redo();
202  bool isUndoAvailable() const;
203  bool isRedoAvailable() const;
204  void resetTransactionStack();
205 
206  void setFileName(const QString& fn);
207  QString getFileName() const;
208 
209  void setFileVersion(const QString& fv);
210  QString getFileVersion() const;
211 
212  QSharedPointer<RLayer> queryCurrentLayer();
213  void setCurrentLayer(RLayer::Id layerId);
214  void setCurrentLayer(const QString& layerName);
215  RLayer::Id getCurrentLayerId();
216 
217  void setCurrentColor(const RColor& color);
218  RColor getCurrentColor() const;
219 
220  void setCurrentLineweight(RLineweight::Lineweight lw);
221  RLineweight::Lineweight getCurrentLineweight() const;
222 
223  void setCurrentLinetype(RLinetype lt);
224  RLinetype getCurrentLinetype() const;
225 
226  QSharedPointer<RBlock> queryCurrentBlock();
227  void setCurrentBlock(RBlock::Id blockId);
228  void setCurrentBlock(const QString& blockName);
229  RBlock::Id getCurrentBlockId() const;
230 
231  QSharedPointer<RView> queryCurrentView();
232  void setCurrentView(RView::Id viewId);
233  void setCurrentView(const QString& viewName);
234  RView::Id getCurrentViewId() const;
235 
236  QString getTempBlockName() const;
237  QString getBlockName(RBlock::Id blockId) const;
238  QSet<QString> getBlockNames() const;
239  QString getLayerName(RLayer::Id layerId) const;
240  QSet<QString> getLayerNames() const;
241  QSet<QString> getViewNames() const;
242 
243  bool hasLayer(const QString& layerName) const;
244  bool hasBlock(const QString& blockName) const;
245  bool hasView(const QString& viewName) const;
246  bool hasLinetype(const QString& linetypeName) const;
247 
248  RLayer::Id getLayerId(const QString& layerName) const;
249  RBlock::Id getBlockId(const QString& blockName) const;
250  RBlock::Id getModelSpaceBlockId() const;
251 
252  RLinetype::Id getLinetypeId(const QString& linetypeName) const;
254  return linetypeByLayerId;
255  }
257  return linetypeByBlockId;
258  }
259  QString getLinetypeName(RLinetype::Id linetypeId) const;
260  QSet<QString> getLinetypeNames() const;
261  bool isByLayer(RLinetype::Id linetypeId) const;
262  bool isByBlock(RLinetype::Id linetypeId) const;
263 
264  RLineweight::Lineweight getMaxLineweight() const;
265 
266  QStringList getVariables() const;
267  void setVariable(const QString& key, const QVariant& value, bool overwrite=true);
268  QVariant getVariable(const QString& key, const QVariant& defaultValue = RDEFAULT_QVARIANT, bool useSettings = false);
269  bool hasVariable(const QString& key) const;
270 
271  void setKnownVariable(RS::KnownVariable key, const QVariant& value);
272  void setKnownVariable(RS::KnownVariable key, const RVector& value);
273  QVariant getKnownVariable(RS::KnownVariable key, const QVariant& defaultValue = RDEFAULT_QVARIANT);
274 
275  void setUnit(RS::Unit unit);
276  RS::Unit getUnit() const;
277 
278  void setDimensionFont(const QString& f);
279  QString getDimensionFont() const;
280 
281  void setLinetypeScale(double v);
282  double getLinetypeScale() const;
283 
284  RS::LinearFormat getLinearFormat();
285  int getLinearPrecision();
286  bool showLeadingZeroes();
287  bool showTrailingZeroes();
288  bool showLeadingZeroesAngle();
289  bool showTrailingZeroesAngle();
290  RS::AngleFormat getAngleFormat();
291  int getAnglePrecision();
292 
293  bool isModified() const;
294  void setModified(bool m);
295 
296  /*
297  void copyToDocument(const RVector& reference, RDocument& other,
298  bool selectionOnly, bool clear, RTransaction& transaction);
299  void copyToDocument(REntity& entity, const RVector& reference,
300  RDocument& other, RTransaction& transaction);
301  */
302 
303  static RDocument& getClipboard();
304 
308  friend QDebug operator<<(QDebug dbg, RDocument& d);
309 
310  void dump();
311 
312 protected:
314 
315 private:
316  QString fileName;
317  QString fileVersion;
318 
325 };
326 
329 
330 #endif