QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RStorage.h
Go to the documentation of this file.
1 
20 #ifndef RSTORAGE_H
21 #define RSTORAGE_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 "RBox.h"
31 #include "RDocumentVariables.h"
32 #include "REntity.h"
33 #include "RLayer.h"
34 #include "RLinetype.h"
35 #include "RLinetypePattern.h"
36 #include "RModifiedListener.h"
37 #include "RNonCopyable.h"
38 #include "RRequireHeap.h"
39 #include "RTransaction.h"
40 #include "RUcs.h"
41 #include "RView.h"
42 
43 
56 public:
57  RStorage();
58  virtual ~RStorage() { }
59 
60  void setDocument(RDocument* doc) {
61  document = doc;
62  }
63 
65  return document;
66  }
67 
71  virtual void clear();
72 
78  virtual void beginTransaction() = 0;
79 
85  virtual void commitTransaction() = 0;
86 
91  virtual void rollbackTransaction() = 0;
92 
96  virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds) const;
97 
101  virtual QSet<RObject::Id> queryAllObjects() = 0;
102 
106  virtual QSet<REntity::Id> queryAllEntities(bool undone = false,
107  bool allBlocks = false, RS::EntityType type = RS::EntityAll) = 0;
108 
112  virtual QSet<RUcs::Id> queryAllUcs() = 0;
113 
117  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false) = 0;
118 
122  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false) = 0;
123 
127  virtual QSet<RView::Id> queryAllViews(bool undone = false) = 0;
128 
132  virtual QSet<RLinetype::Id> queryAllLinetypes() = 0;
133 
137  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) = 0;
138 
142  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) = 0;
143 
149  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll) = 0;
150 
151  virtual bool hasChildEntities(REntity::Id parentId) = 0;
152 
157  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) = 0;
158 
162  virtual QSet<REntity::Id> queryAllBlockReferences() = 0;
163 
167  virtual QSet<REntity::Id> querySelectedEntities() = 0;
168 
172  virtual QSet<REntity::Id> queryInfiniteEntities() = 0;
173 
174  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const = 0;
175  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const = 0;
176 
181  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
182 
183  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
184  return queryObject(objectId);
185  }
186  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const = 0;
187 
192  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
193 
194  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
195  return queryEntity(entityId);
196  }
197 
202  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
203 
204  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
205  return queryUcs(ucsId);
206  }
207 
212  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
213 
218  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
219 
220  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
221  return queryLayer(layerId);
222  }
223 
228  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
229 
230  virtual QSharedPointer<RLayer> queryCurrentLayer() {
231  return queryLayer(getCurrentLayerId());
232  }
233 
234  virtual QSharedPointer<RView> queryCurrentView() {
235  return queryView(getCurrentViewId());
236  }
237 
238  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const = 0;
239  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
240  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
241 
242  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
243  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
244  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
245 
246  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
247  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
248 
249  //RTransaction setCurrentLayer(RLayer::Id layerId);
250  //RTransaction setCurrentLayer(const QString& layerName);
251  //void setCurrentLayer(RTransaction& transaction, RLayer::Id layerId);
252  //void setCurrentLayer(RTransaction& transaction, const QString& layerName);
253  void setCurrentLayer(RLayer::Id layerId, RTransaction* transaction=NULL);
254  void setCurrentLayer(const QString& layerName, RTransaction* transaction=NULL);
255 
256  virtual RLayer::Id getCurrentLayerId() const;
257  virtual RView::Id getCurrentViewId() const {
258  //return (RView::Id) getVariable("CurrentView").toInt();
259  return currentViewId;
260  }
261 
262  virtual void setCurrentColor(const RColor& color);
263  virtual RColor getCurrentColor() const;
264 
265  void setCurrentLineweight(RLineweight::Lineweight lw);
266  virtual RLineweight::Lineweight getCurrentLineweight() const;
267 
268  void setCurrentLinetype(RLinetype::Id ltId);
269  void setCurrentLinetype(const QString& name);
270  void setCurrentLinetypePattern(const RLinetypePattern& p);
271  virtual RLinetype::Id getCurrentLinetypeId() const;
272  virtual RLinetypePattern getCurrentLinetypePattern() const;
273  virtual QSharedPointer<RLinetype> queryCurrentLinetype() const {
274  return queryLinetype(getCurrentLinetypeId());
275  }
276 
277  virtual QSharedPointer<RBlock> queryCurrentBlock() {
278  return queryBlock(getCurrentBlockId());
279  }
280 
281  virtual void setCurrentBlock(RBlock::Id blockId) {
282  //setVariable("CurrentBlock", blockId);
283  currentBlockId = blockId;
284  }
285 
286  void setCurrentBlock(const QString& blockName) {
287  RBlock::Id id = getBlockId(blockName);
288  if (id == RBlock::INVALID_ID) {
289  return;
290  }
291  setCurrentBlock(id);
292  }
293 
294  virtual RBlock::Id getCurrentBlockId() const {
295  //return (RBlock::Id) getVariable("CurrentBlock").toInt();
296  return currentBlockId;
297  }
298 
299  void setCurrentView(RView::Id viewId) {
300  //setVariable("CurrentView", viewId);
301  currentViewId = viewId;
302  }
303 
304  void setCurrentView(const QString& viewName) {
305  RView::Id id = getViewId(viewName);
306  // unlike blocks and layers, the current view can be invalid:
307  setCurrentView(id);
308  }
309 
310  QSharedPointer<RDocumentVariables> startDocumentVariablesTransaction(RTransaction*& transaction, bool& useLocalTransaction);
311  void endDocumentVariablesTransaction(RTransaction* transaction, bool useLocalTransaction, QSharedPointer<RDocumentVariables> docVars);
312 
313  void setUnit(RS::Unit unit, RTransaction* transaction=NULL);
314  //void setUnit(RTransaction& transaction, RS::Unit unit);
315  RS::Unit getUnit() const;
316 
317  virtual void setDimensionFont(const QString& f, RTransaction* transaction=NULL);
318  virtual QString getDimensionFont() const;
319 
320  virtual void setLinetypeScale(double v, RTransaction* transaction=NULL);
321  virtual double getLinetypeScale() const;
322 
323  virtual QString getBlockName(RBlock::Id blockId) const = 0;
324  virtual QSet<QString> getBlockNames() const = 0;
325  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
326  virtual bool hasBlock(const QString& blockName) const;
327 
328  virtual QString getViewName(RView::Id viewId) const = 0;
329  virtual QSet<QString> getViewNames() const = 0;
330  virtual RView::Id getViewId(const QString& viewName) const = 0;
331  virtual bool hasView(const QString& viewName) const;
332 
333  virtual QString getLayerName(RLayer::Id layerId) const = 0;
334  virtual QSet<QString> getLayerNames() const = 0;
335  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
336  virtual bool hasLayer(const QString& layerName) const;
337 
338  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
339  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const = 0;
340  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const = 0;
341  virtual QSet<QString> getLinetypeNames() const = 0;
342  virtual QList<RLinetypePattern> getLinetypePatterns() const = 0;
343  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
344  virtual bool hasLinetype(const QString& linetypeName) const;
345 
346  virtual QStringList getVariables() const = 0;
347  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
352  virtual QVariant getVariable(const QString& key) const = 0;
353 
357  virtual bool hasVariable(const QString& key) const {
358  QVariant value = getVariable(key);
359  return value.isValid();
360  }
361 
362  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL) = 0;
363  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
364 
368  virtual void clearEntitySelection(
369  QSet<REntity::Id>* affectedEntities=NULL
370  ) = 0;
371 
375  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
376 
386  virtual void selectEntity(
387  REntity::Id entityId,
388  bool add=false,
389  QSet<REntity::Id>* affectedEntities=NULL
390  ) = 0;
391 
401  virtual void selectEntities(
402  const QSet<REntity::Id>& entityIds,
403  bool add=false,
404  QSet<REntity::Id>* affectedEntities=NULL
405  ) = 0;
406 
414  virtual void deselectEntity(
415  REntity::Id entityId,
416  QSet<REntity::Id>* affectedEntities=NULL
417  ) = 0;
418 
426  virtual void deselectEntities(
427  const QSet<REntity::Id>& entityIds,
428  QSet<REntity::Id>* affectedEntities=NULL
429  ) = 0;
430 
431  virtual bool isSelected(REntity::Id entityId) {
432  QSharedPointer<REntity> e = queryEntityDirect(entityId);
433  return (!e.isNull() && e->isSelected());
434  }
435 
436  virtual bool isEntity(RObject::Id objectId) {
437  QSharedPointer<REntity> e = queryEntityDirect(objectId);
438  return !e.isNull();
439  }
440 
441  virtual bool isLayerLocked(RLayer::Id layerId) const {
442  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
443  if (l.isNull()) {
444  return false;
445  }
446  return l->isLocked();
447  }
448 
449  virtual bool isLayerFrozen(RLayer::Id layerId) const {
450  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
451  if (l.isNull()) {
452  return false;
453  }
454  return l->isFrozen();
455  }
456 
457  virtual bool isBlockFrozen(RBlock::Id blockId) const {
458  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
459  if (b.isNull()) {
460  return false;
461  }
462  return b->isFrozen();
463  }
464 
465  void setObjectId(RObject& object, RObject::Id objectId);
466  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
467 
471  virtual bool hasSelection() const = 0;
472 
476  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty = false) const = 0;
477 
478  virtual RBox getSelectionBox() const = 0;
479 
480  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
481 
485  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
486 
490  virtual bool deleteObject(RObject::Id objectId) = 0;
491 
496  virtual int getLastTransactionId() {
497  //return getVariable("LastTransaction").toInt();
498  return lastTransactionId;
499  }
500 
507  virtual void setLastTransactionId(int transactionId) {
508  //setVariable("LastTransaction", transactionId);
509  lastTransactionId = transactionId;
510 
511  setModified(true);
512  }
513 
518  virtual void saveTransaction(RTransaction& transaction) = 0;
519 
526  virtual void deleteTransactionsFrom(int transactionId) = 0;
527 
528  virtual void resetTransactionStack() = 0;
529 
533  virtual RTransaction getTransaction(int transactionId) = 0;
534 
540  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
541 
545  virtual void toggleUndoStatus(RObject::Id object) = 0;
546 
547  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
548 
549  //virtual bool getUndoStatus(RObject::Id object) const = 0;
550 
555  virtual int getMaxTransactionId() = 0;
556 
557  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
558 
559  virtual RObject::Id getNewObjectId();
560  virtual RObject::Id getMaxObjectId();
561  virtual RObject::Handle getNewObjectHandle();
562  virtual RObject::Handle getMaxObjectHandle();
563 
564  virtual void setMaxDrawOrder(int m) {
565  maxDrawOrder = m;
566  }
567 
568  virtual int getMaxDrawOrder() {
569  return maxDrawOrder;
570  }
571 
572  virtual int getMinDrawOrder();
573 
578  virtual bool isInBackStorage(RObject::Id /*object*/) {
579  return false;
580  }
581 
582  static QString getKnownVariableName(RS::KnownVariable n);
583 
587  friend QDebug operator<<(QDebug dbg, RStorage& s);
588 
589  void setModified(bool m);
590 
591  bool isModified() const {
592  return modified;
593  }
594 
595  void addModifiedListener(RModifiedListener* l);
596 
600  virtual void update() {}
601 
602 protected:
603  bool modified;
604 
605 private:
613  //RLayer::Id currentLayerId;
617 
618  QList<RModifiedListener*> modifiedListeners;
619 };
620 
623 
624 #endif