QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RStorage.h
Go to the documentation of this file.
1 #ifndef RSTORAGE_H
2 #define RSTORAGE_H
3 
4 #include <QString>
5 #include <QSharedPointer>
6 
7 #include "RBlock.h"
8 #include "RBox.h"
9 #include "REntity.h"
10 #include "RLayer.h"
11 #include "RLinetype.h"
12 #include "RModifiedListener.h"
13 #include "RNonCopyable.h"
14 #include "RRequireHeap.h"
15 #include "RTransaction.h"
16 #include "RUcs.h"
17 #include "RView.h"
18 
19 
32 public:
33  RStorage();
34  virtual ~RStorage() { }
35 
39  virtual void clear();
40 
46  virtual void beginTransaction() = 0;
47 
53  virtual void commitTransaction() = 0;
54 
59  virtual void rollbackTransaction() = 0;
60 
64  virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds) const;
65 
69  virtual QSet<RObject::Id> queryAllObjects() = 0;
70 
74  virtual QSet<REntity::Id> queryAllEntities(bool undone = false,
75  bool allBlocks = false) = 0;
76 
80  virtual QSet<RUcs::Id> queryAllUcs() = 0;
81 
85  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false) = 0;
86 
90  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false) = 0;
91 
95  virtual QSet<RView::Id> queryAllViews(bool undone = false) = 0;
96 
100  virtual QSet<RLinetype::Id> queryAllLinetypes() = 0;
101 
105  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) = 0;
106 
110  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) = 0;
111 
116  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) = 0;
117 
121  virtual QSet<REntity::Id> queryAllBlockReferences() = 0;
122 
126  virtual QSet<REntity::Id> querySelectedEntities() = 0;
127 
132  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
133 
134  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
135  return queryObject(objectId);
136  }
137 
142  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
143 
144  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
145  return queryEntity(entityId);
146  }
147 
152  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
153 
154  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
155  return queryUcs(ucsId);
156  }
157 
162  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
163 
168  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
169 
170  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
171  return queryLayer(layerId);
172  }
173 
178  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
179 
180  virtual QSharedPointer<RLayer> queryCurrentLayer() {
181  return queryLayer(getCurrentLayerId());
182  }
183 
184  virtual QSharedPointer<RView> queryCurrentView() {
185  return queryView(getCurrentViewId());
186  }
187 
188  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
189 
190  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
191 
192  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
193  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
194  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
195 
196  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
197  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
198 
199  void setCurrentLayer(RLayer::Id layerId) {
200  //setVariable("CurrentLayer", layerId);
201  currentLayerId = layerId;
202  }
203 
204  void setCurrentLayer(const QString& layerName) {
205  RLayer::Id id = getLayerId(layerName);
206  if (id == RLayer::INVALID_ID) {
207  return;
208  }
209  setCurrentLayer(id);
210  }
211 
213  //return (RLayer::Id) getVariable("CurrentLayer").toInt();
214  return currentLayerId;
215  }
216 
218  //return (RView::Id) getVariable("CurrentView").toInt();
219  return currentViewId;
220  }
221 
222  virtual void setCurrentColor(const RColor& color);
223  virtual RColor getCurrentColor();
224 
227 
228  void setCurrentLinetype(RLinetype lt);
229  virtual RLinetype getCurrentLinetype();
230 
231  virtual QSharedPointer<RBlock> queryCurrentBlock() {
232  return queryBlock(getCurrentBlockId());
233  }
234 
235  virtual void setCurrentBlock(RBlock::Id blockId) {
236  //setVariable("CurrentBlock", blockId);
237  currentBlockId = blockId;
238  }
239 
240  void setCurrentBlock(const QString& blockName) {
241  RBlock::Id id = getBlockId(blockName);
242  if (id == RBlock::INVALID_ID) {
243  return;
244  }
245  setCurrentBlock(id);
246  }
247 
248  virtual RBlock::Id getCurrentBlockId() const {
249  //return (RBlock::Id) getVariable("CurrentBlock").toInt();
250  return currentBlockId;
251  }
252 
253  void setCurrentView(RView::Id viewId) {
254  //setVariable("CurrentView", viewId);
255  currentViewId = viewId;
256  }
257 
258  void setCurrentView(const QString& viewName) {
259  RView::Id id = getViewId(viewName);
260  // unlike blocks and layers, the current view can be invalid:
261  setCurrentView(id);
262  }
263 
264  virtual RView::Id getCurrentViewId() const {
265  //return (RView::Id) getVariable("CurrentView").toInt();
266  return currentViewId;
267  }
268 
269  virtual void setUnit(RS::Unit unit);
270  virtual RS::Unit getUnit() const;
271 
272  virtual void setLinetypeScale(double v);
273  virtual double getLinetypeScale() const;
274 
275  virtual QString getBlockName(RBlock::Id blockId) const = 0;
276  virtual QSet<QString> getBlockNames() = 0;
277  virtual RBlock::Id getBlockId(const QString& blockName) = 0;
278  virtual bool hasBlock(const QString& blockName);
279 
280  virtual QString getViewName(RView::Id viewId) = 0;
281  virtual QSet<QString> getViewNames() = 0;
282  virtual RView::Id getViewId(const QString& viewName) = 0;
283  virtual bool hasView(const QString& viewName);
284 
285  virtual QString getLayerName(RLayer::Id layerId) = 0;
286  virtual QSet<QString> getLayerNames() = 0;
287  virtual RLayer::Id getLayerId(const QString& layerName) = 0;
288  virtual bool hasLayer(const QString& layerName);
289 
290  virtual QString getLinetypeName(RLinetype::Id linetypeId) = 0;
291  virtual QSet<QString> getLinetypeNames() = 0;
292  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) = 0;
293  virtual bool hasLinetype(const QString& linetypeName);
294 
295  virtual QStringList getVariables() const = 0;
296  virtual void setVariable(const QString& key, const QVariant & value) = 0;
301  virtual QVariant getVariable(const QString& key) const = 0;
302 
303  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value) = 0;
304  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
305 
309  virtual void clearEntitySelection(
310  QSet<REntity::Id>* affectedEntities=NULL
311  ) = 0;
312 
316  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
317 
327  virtual void selectEntity(
328  REntity::Id entityId,
329  bool add=false,
330  QSet<REntity::Id>* affectedEntities=NULL
331  ) = 0;
332 
342  virtual void selectEntities(
343  const QSet<REntity::Id>& entityIds,
344  bool add=false,
345  QSet<REntity::Id>* affectedEntities=NULL
346  ) = 0;
347 
355  virtual void deselectEntity(
356  REntity::Id entityId,
357  QSet<REntity::Id>* affectedEntities=NULL
358  ) = 0;
359 
367  virtual void deselectEntities(
368  const QSet<REntity::Id>& entityIds,
369  QSet<REntity::Id>* affectedEntities=NULL
370  ) = 0;
371 
372  virtual bool isSelected(REntity::Id entityId) {
373  QSharedPointer<REntity> e = queryEntityDirect(entityId);
374  return (!e.isNull() && e->isSelected());
375  }
376 
377  virtual bool isEntity(RObject::Id objectId) {
378  QSharedPointer<REntity> e = queryEntityDirect(objectId);
379  return !e.isNull();
380  }
381 
382  virtual bool isLayerLocked(RLayer::Id layerId) const {
383  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
384  if (l.isNull()) {
385  return false;
386  }
387  return l->isLocked();
388  }
389 
390  virtual bool isLayerFrozen(RLayer::Id layerId) const {
391  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
392  if (l.isNull()) {
393  return false;
394  }
395  return l->isFrozen();
396  }
397 
398  virtual bool isBlockFrozen(RBlock::Id blockId) const {
399  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
400  if (b.isNull()) {
401  return false;
402  }
403  return b->isFrozen();
404  }
405 
406  void setObjectId(RObject& object, RObject::Id objectId);
407  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
408 
412  virtual bool hasSelection() const = 0;
413 
417  virtual RBox getBoundingBox(bool includeHiddenLayer = true) = 0;
418 
419  virtual RBox getSelectionBox() = 0;
420 
424  virtual bool saveObject(QSharedPointer<RObject> object) = 0;
425 
429  virtual bool deleteObject(RObject::Id objectId) = 0;
430 
435  virtual int getLastTransactionId() {
436  //return getVariable("LastTransaction").toInt();
437  return lastTransactionId;
438  }
439 
446  virtual void setLastTransactionId(int transactionId) {
447  //setVariable("LastTransaction", transactionId);
448  lastTransactionId = transactionId;
449 
450  setModified(true);
451  }
452 
457  virtual void saveTransaction(RTransaction& transaction) = 0;
458 
465  virtual void deleteTransactionsFrom(int transactionId) = 0;
466 
467  virtual void resetTransactionStack() = 0;
468 
472  virtual RTransaction getTransaction(int transactionId) = 0;
473 
479  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
480 
484  virtual void toggleUndoStatus(RObject::Id object) = 0;
485 
486  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
487 
488  //virtual bool getUndoStatus(RObject::Id object) const = 0;
489 
494  virtual int getMaxTransactionId() = 0;
495 
496  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
497 
498  virtual RObject::Id getNewObjectId();
499  virtual RObject::Id getMaxObjectId();
502 
503  virtual void setMaxDrawOrder(int m) {
504  maxDrawOrder = m;
505  }
506 
507  virtual int getMaxDrawOrder() {
508  return maxDrawOrder;
509  }
510 
511  virtual int getMinDrawOrder();
512 
517  virtual bool isInBackStorage(RObject::Id /*object*/) {
518  return false;
519  }
520 
521  static QString getKnownVariableName(RS::KnownVariable n);
522 
526  friend QDebug operator<<(QDebug dbg, RStorage& s);
527 
528  void setModified(bool m);
529 
530  bool isModified() const {
531  return modified;
532  }
533 
535 
536 protected:
537  bool modified;
538 
539 private:
550 
551  QList<RModifiedListener*> modifiedListeners;
552 };
553 
555 
556 #endif