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