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) 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> queryIntersectedEntitiesXY(
109  const RBox& box,
110  bool checkBoundingBoxOnly=false,
111  bool includeLockedLayers=true,
112  RBlock::Id blockId = RBlock::INVALID_ID,
113  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
114  );
115 
116  QMap<REntity::Id, QSet<int> > queryIntersectedShapesXY(
117  const RBox& box,
118  bool checkBoundingBoxOnly=false,
119  bool includeLockedLayers=true,
120  RBlock::Id blockId = RBlock::INVALID_ID,
121  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
122  );
123 
124  QSet<REntity::Id> queryContainedEntitiesXY(
125  const RBox& box
126  );
127 
128  QSet<REntity::Id> querySelectedEntities();
129 
130  QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
131  QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
132  QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
133  QSharedPointer<REntity> queryEntity(REntity::Id entityId) const;
134  QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const;
135  QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
136  QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
137  QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
138  QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
139  QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
140  QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
141  QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
142  QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
143  QSharedPointer<RView> queryView(RView::Id viewId) const;
144  QSharedPointer<RView> queryView(const QString& viewName) const;
145  QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
146  QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
147 
148  void clearSelection(
149  QSet<REntity::Id>* affectedEntities=NULL
150  );
151 
152  void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
153 
154  void selectEntity(
155  REntity::Id entityId,
156  bool add=false,
157  QSet<REntity::Id>* affectedEntities=NULL
158  );
159  void deselectEntity(
160  REntity::Id entityId,
161  QSet<REntity::Id>* affectedEntities=NULL
162  );
163  void selectEntities(
164  const QSet<REntity::Id>& entityId,
165  bool add=false,
166  QSet<REntity::Id>* affectedEntities=NULL
167  );
168  void deselectEntities(
169  const QSet<REntity::Id>& entityId,
170  QSet<REntity::Id>* affectedEntities=NULL
171  );
172  bool isSelected(REntity::Id entityId);
173  bool isLayerLocked(RLayer::Id layerId) const;
174  bool isEntityEditable(REntity::Id entityId) const;
175  //bool isEntityLayerLocked(REntity::Id entityId) const;
176  bool isLayerFrozen(RLayer::Id layerId) const;
177  bool isBlockFrozen(RBlock::Id blockId) const;
178  bool isEntityLayerFrozen(REntity::Id entityId) const;
179 
180  bool hasSelection() const;
181 
182  RBox getBoundingBox(bool includeHiddenLayer = true);
183  RBox getSelectionBox();
184 
185  //void addToSpatialIndex(RObject& object, bool isNew = false);
186  virtual void rebuildSpatialIndex();
187  //void addToSpatialIndex(QSharedPointer<REntity> entity);
188  void addToSpatialIndex(QSharedPointer<REntity> entity);
189 
190  bool blockContainsReferences(RBlock::Id blockId, RBlock::Id referencedBlockId);
191 
192  void removeBlockFromSpatialIndex(RBlock::Id blockId);
193  bool addBlockToSpatialIndex(RBlock::Id blockId, RObject::Id ignoreBlockId);
194  virtual void removeFromSpatialIndex(QSharedPointer<REntity> entity);
195  //virtual void removeFromSpatialIndex2(QSharedPointer<REntity> entity);
196 
197  void updateAllEntities();
198 
199  RTransaction undo();
200  RTransaction redo();
201  bool isUndoAvailable() const;
202  bool isRedoAvailable() const;
203  void resetTransactionStack();
204 
205  void setFileName(const QString& fn);
206  QString getFileName() const;
207 
208  void setFileVersion(const QString& fv);
209  QString getFileVersion() const;
210 
211  QSharedPointer<RLayer> queryCurrentLayer();
212  void setCurrentLayer(RLayer::Id layerId);
213  void setCurrentLayer(const QString& layerName);
214  RLayer::Id getCurrentLayerId();
215 
216  void setCurrentColor(const RColor& color);
217  RColor getCurrentColor();
218 
219  void setCurrentLineweight(RLineweight::Lineweight lw);
220  RLineweight::Lineweight getCurrentLineweight();
221 
222  void setCurrentLinetype(RLinetype lt);
223  RLinetype getCurrentLinetype();
224 
225  QSharedPointer<RBlock> queryCurrentBlock();
226  void setCurrentBlock(RBlock::Id blockId);
227  void setCurrentBlock(const QString& blockName);
228  RBlock::Id getCurrentBlockId();
229 
230  QSharedPointer<RView> queryCurrentView();
231  void setCurrentView(RView::Id viewId);
232  void setCurrentView(const QString& viewName);
233  RView::Id getCurrentViewId();
234 
235  QString getBlockName(RBlock::Id blockId) const;
236  QSet<QString> getBlockNames() const;
237  QString getLayerName(RLayer::Id layerId) const;
238  QSet<QString> getLayerNames() const;
239  QSet<QString> getViewNames() const;
240 
241  bool hasLayer(const QString& layerName);
242  bool hasBlock(const QString& blockName);
243  bool hasView(const QString& viewName);
244  bool hasLinetype(const QString& linetypeName);
245 
246  RLayer::Id getLayerId(const QString& layerName);
247  RBlock::Id getBlockId(const QString& blockName);
248  RBlock::Id getModelSpaceBlockId() const;
249 
250  RLinetype::Id getLinetypeId(const QString& linetypeName);
252  return linetypeByLayerId;
253  }
254  QString getLinetypeName(RLinetype::Id linetypeId);
255  QSet<QString> getLinetypeNames();
256  bool isByLayer(RLinetype::Id linetypeId);
257  bool isByBlock(RLinetype::Id linetypeId);
258 
259  RLineweight::Lineweight getMaxLineweight() const;
260 
261  QStringList getVariables() const;
262  void setVariable(const QString& key, const QVariant& value, bool overwrite=true);
263  QVariant getVariable(const QString& key, const QVariant& defaultValue = RDEFAULT_QVARIANT, bool useSettings = false);
264  bool hasVariable(const QString& key) const;
265 
266  void setKnownVariable(RS::KnownVariable key, const QVariant& value);
267  void setKnownVariable(RS::KnownVariable key, const RVector& value);
268  QVariant getKnownVariable(RS::KnownVariable key, const QVariant& defaultValue = RDEFAULT_QVARIANT);
269 
270  void setUnit(RS::Unit unit);
271  RS::Unit getUnit() const;
272 
273  void setLinetypeScale(double v);
274  double getLinetypeScale() const;
275 
276  RS::LinearFormat getLinearFormat();
277  int getLinearPrecision();
278  bool showLeadingZeroes();
279  bool showTrailingZeroes();
280  bool showLeadingZeroesAngle();
281  bool showTrailingZeroesAngle();
282  RS::AngleFormat getAngleFormat();
283  int getAnglePrecision();
284 
285  bool isModified() const;
286  void setModified(bool m);
287 
288  /*
289  void copyToDocument(const RVector& reference, RDocument& other,
290  bool selectionOnly, bool clear, RTransaction& transaction);
291  void copyToDocument(REntity& entity, const RVector& reference,
292  RDocument& other, RTransaction& transaction);
293  */
294 
295  static RDocument& getClipboard();
296 
300  friend QDebug operator<<(QDebug dbg, RDocument& d);
301 
302  void dump();
303 
304 protected:
306 
307 private:
308  QString fileName;
309  QString fileVersion;
310 
317 };
318 
321 
322 #endif