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