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