QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RDocument.h
Go to the documentation of this file.
1 #ifndef RDOCUMENT_H
2 #define RDOCUMENT_H
3 
4 #include <QString>
5 #include <QSharedPointer>
6 
7 #include "RBlock.h"
8 #include "REntity.h"
9 #include "RNonCopyable.h"
10 #include "RRequireHeap.h"
11 #include "RSpatialIndex.h"
12 #include "RTransactionStack.h"
13 #include "RUcs.h"
14 #include "RLayer.h"
15 #include "RLinetype.h"
16 #include "RView.h"
17 
18 class RVector;
19 class RStorage;
20 
21 #ifndef RDEFAULT_QVARIANT
22 #define RDEFAULT_QVARIANT QVariant()
23 #endif
24 
25 #define RDEFAULT_QLIST_RS_ENTITYTYPE QList<RS::EntityType>()
26 
27 
41 public:
43  virtual ~RDocument();
44 
45  void init();
46 
48  const RStorage& getStorage() const;
51 
52  void clear();
53 
55  const RVector& wcsPosition,
56  double range,
57  bool draft,
58  bool includeLockedLayers = true
59  );
61  QSet<REntity::Id>& candidates,
62  const RVector& wcsPosition,
63  double range,
64  bool draft
65  );
66 
67  QSet<RObject::Id> queryAllObjects() const;
68  QSet<REntity::Id> queryAllEntities(bool undone = false, bool allBlocks = false) const;
69  QSet<RUcs::Id> queryAllUcs() const;
70  QSet<RLayer::Id> queryAllLayers() const;
71  QSet<RBlock::Id> queryAllBlocks() const;
72  QSet<RView::Id> queryAllViews() const;
73  QSet<RLinetype::Id> queryAllLinetypes() const;
74 
75  QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId) const;
76  QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) const;
77  QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) const;
78  QSet<REntity::Id> queryAllBlockReferences() const;
79 
80  QSet<REntity::Id> queryContainedEntities(
81  const RBox& box
82  );
83 
84  QSet<REntity::Id> queryIntersectedEntitiesXY(
85  const RBox& box,
86  bool checkBoundingBoxOnly=false,
87  bool includeLockedLayers=true,
89  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
90  );
91 
92  QMap<REntity::Id, QSet<int> > queryIntersectedShapesXY(
93  const RBox& box,
94  bool checkBoundingBoxOnly=false,
95  bool includeLockedLayers=true,
97  const QList<RS::EntityType>& filter = RDEFAULT_QLIST_RS_ENTITYTYPE
98  );
99 
100  QSet<REntity::Id> queryContainedEntitiesXY(
101  const RBox& box
102  );
103 
104  QSet<REntity::Id> querySelectedEntities();
105 
106  QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
107  QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
108  QSharedPointer<REntity> queryEntity(REntity::Id entityId) const;
109  QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const;
110  QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
111  QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
112  QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
113  QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
114  QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
115  QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
116  QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
117  QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
118  QSharedPointer<RView> queryView(RView::Id viewId) const;
119  QSharedPointer<RView> queryView(const QString& viewName) const;
120  QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
121  QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
122 
123  void clearSelection(
124  QSet<REntity::Id>* affectedEntities=NULL
125  );
126 
127  void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
128 
129  void selectEntity(
130  REntity::Id entityId,
131  bool add=false,
132  QSet<REntity::Id>* affectedEntities=NULL
133  );
134  void deselectEntity(
135  REntity::Id entityId,
136  QSet<REntity::Id>* affectedEntities=NULL
137  );
138  void selectEntities(
139  const QSet<REntity::Id>& entityId,
140  bool add=false,
141  QSet<REntity::Id>* affectedEntities=NULL
142  );
143  void deselectEntities(
144  const QSet<REntity::Id>& entityId,
145  QSet<REntity::Id>* affectedEntities=NULL
146  );
147  bool isSelected(REntity::Id entityId);
148  bool isLayerLocked(RLayer::Id layerId) const;
149  bool isEntityEditable(REntity::Id entityId) const;
150  //bool isEntityLayerLocked(REntity::Id entityId) const;
151  bool isLayerFrozen(RLayer::Id layerId) const;
152  bool isBlockFrozen(RBlock::Id blockId) const;
153  bool isEntityLayerFrozen(REntity::Id entityId) const;
154 
155  bool hasSelection() const;
156 
157  RBox getBoundingBox(bool includeHiddenLayer = true);
159 
160  //void addToSpatialIndex(RObject& object, bool isNew = false);
161  virtual void rebuildSpatialIndex();
162  //void addToSpatialIndex(QSharedPointer<REntity> entity);
163  void addToSpatialIndex(QSharedPointer<REntity> entity);
164 
165  bool blockContainsReferences(RBlock::Id blockId, RBlock::Id referencedBlockId);
166 
168  bool addBlockToSpatialIndex(RBlock::Id blockId, RObject::Id ignoreBlockId);
169  virtual void removeFromSpatialIndex(QSharedPointer<REntity> entity);
170  //virtual void removeFromSpatialIndex2(QSharedPointer<REntity> entity);
171 
172  void updateAllEntities();
173 
174  RTransaction undo();
175  RTransaction redo();
176  bool isUndoAvailable() const;
177  bool isRedoAvailable() const;
178  void resetTransactionStack();
179 
180  void setFileName(const QString& fn);
181  QString getFileName() const;
182 
183  void setFileVersion(const QString& fv);
184  QString getFileVersion() const;
185 
186  QSharedPointer<RLayer> queryCurrentLayer();
187  void setCurrentLayer(RLayer::Id layerId);
188  void setCurrentLayer(const QString& layerName);
190 
191  void setCurrentColor(const RColor& color);
193 
196 
197  void setCurrentLinetype(RLinetype lt);
199 
200  QSharedPointer<RBlock> queryCurrentBlock();
201  void setCurrentBlock(RBlock::Id blockId);
202  void setCurrentBlock(const QString& blockName);
204 
205  QSharedPointer<RView> queryCurrentView();
206  void setCurrentView(RView::Id viewId);
207  void setCurrentView(const QString& viewName);
209 
210  QString getBlockName(RBlock::Id blockId) const;
211  QSet<QString> getBlockNames();
212  QString getLayerName(RLayer::Id layerId);
213  QSet<QString> getLayerNames();
214  QSet<QString> getViewNames();
215 
216  bool hasLayer(const QString& layerName);
217  bool hasBlock(const QString& blockName);
218  bool hasView(const QString& viewName);
219  bool hasLinetype(const QString& linetypeName);
220 
221  RLayer::Id getLayerId(const QString& layerName);
222  RBlock::Id getBlockId(const QString& blockName);
224 
225  RLinetype::Id getLinetypeId(const QString& linetypeName);
227  return linetypeByLayerId;
228  }
229  QString getLinetypeName(RLinetype::Id linetypeId);
230  QSet<QString> getLinetypeNames();
231  bool isByLayer(RLinetype::Id linetypeId);
232  bool isByBlock(RLinetype::Id linetypeId);
233 
235 
236  QStringList getVariables() const;
237  void setVariable(const QString& key, const QVariant & value);
238  QVariant getVariable(const QString& key, const QVariant& defaultValue = RDEFAULT_QVARIANT, bool useSettings = false);
239 
240  void setKnownVariable(RS::KnownVariable key, const QVariant& value);
241  void setKnownVariable(RS::KnownVariable key, const RVector& value);
242  QVariant getKnownVariable(RS::KnownVariable key, const QVariant& defaultValue = RDEFAULT_QVARIANT);
243 
244  void setUnit(RS::Unit unit);
245  RS::Unit getUnit() const;
246 
247  void setLinetypeScale(double v);
248  double getLinetypeScale() const;
249 
251  int getLinearPrecision();
252  bool showLeadingZeroes();
253  bool showTrailingZeroes();
254  bool showLeadingZeroesAngle();
257  int getAnglePrecision();
258 
259  bool isModified() const;
260  void setModified(bool m);
261 
262  /*
263  void copyToDocument(const RVector& reference, RDocument& other,
264  bool selectionOnly, bool clear, RTransaction& transaction);
265  void copyToDocument(REntity& entity, const RVector& reference,
266  RDocument& other, RTransaction& transaction);
267  */
268 
269  static RDocument& getClipboard();
270 
274  friend QDebug operator<<(QDebug dbg, RDocument& d);
275 
276  void dump();
277 
278 protected:
280 
281 private:
282  QString fileName;
283  QString fileVersion;
284 
291 };
292 
294 
295 #endif