QCAD
Open Source 2D CAD
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() const = 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 int countSelectedEntities() const {
369  return querySelectedEntities().size();
370  }
371 
375  virtual void clearEntitySelection(
376  QSet<REntity::Id>* affectedEntities=NULL
377  ) = 0;
378 
382  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
383 
393  virtual void selectEntity(
394  REntity::Id entityId,
395  bool add=false,
396  QSet<REntity::Id>* affectedEntities=NULL
397  ) = 0;
398 
408  virtual void selectEntities(
409  const QSet<REntity::Id>& entityIds,
410  bool add=false,
411  QSet<REntity::Id>* affectedEntities=NULL
412  ) = 0;
413 
421  virtual void deselectEntity(
422  REntity::Id entityId,
423  QSet<REntity::Id>* affectedEntities=NULL
424  ) = 0;
425 
433  virtual bool deselectEntities(
434  const QSet<REntity::Id>& entityIds,
435  QSet<REntity::Id>* affectedEntities=NULL
436  ) = 0;
437 
438  virtual bool isSelected(REntity::Id entityId) {
439  QSharedPointer<REntity> e = queryEntityDirect(entityId);
440  return (!e.isNull() && e->isSelected());
441  }
442 
443  virtual bool isEntity(RObject::Id objectId) {
444  QSharedPointer<REntity> e = queryEntityDirect(objectId);
445  return !e.isNull();
446  }
447 
448  virtual bool isLayerLocked(RLayer::Id layerId) const {
449  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
450  if (l.isNull()) {
451  return false;
452  }
453  return l->isLocked();
454  }
455 
456  virtual bool isLayerFrozen(RLayer::Id layerId) const {
457  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
458  if (l.isNull()) {
459  return false;
460  }
461  return l->isFrozen();
462  }
463 
464  virtual bool isBlockFrozen(RBlock::Id blockId) const {
465  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
466  if (b.isNull()) {
467  return false;
468  }
469  return b->isFrozen();
470  }
471 
472  void setObjectId(RObject& object, RObject::Id objectId);
473  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
474 
478  virtual bool hasSelection() const = 0;
479 
483  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty = false) const = 0;
484 
485  virtual RBox getSelectionBox() const = 0;
486 
487  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
488 
492  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
493 
497  virtual bool deleteObject(RObject::Id objectId) = 0;
498 
503  virtual int getLastTransactionId() {
504  return lastTransactionId;
505  }
506 
513  virtual void setLastTransactionId(int transactionId) {
514  lastTransactionId = transactionId;
515 
516  setModified(true);
517  }
518 
519  virtual void startTransactionGroup() {
520  lastTransactionGroup++;
521  }
522 
523  virtual int getTransactionGroup() const {
524  return lastTransactionGroup;
525  }
526 
530 // virtual int getLastTransactionGroup() {
531 // return lastTransactionGroup;
532 // }
533 
540 // virtual void setLastTransactionGroup(int transactionGroup) {
541 // lastTransactionGroup = transactionGroup;
542 
543 // setModified(true);
544 // }
545 
550  virtual void saveTransaction(RTransaction& transaction) = 0;
551 
558  virtual void deleteTransactionsFrom(int transactionId) = 0;
559 
560  virtual void resetTransactionStack() = 0;
561 
565  virtual RTransaction getTransaction(int transactionId) = 0;
566 
572  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
573 
577  virtual void toggleUndoStatus(RObject::Id object) = 0;
578 
579  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
580 
581  //virtual bool getUndoStatus(RObject::Id object) const = 0;
582 
587  virtual int getMaxTransactionId() = 0;
588 
589  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
590 
591  virtual RObject::Id getNewObjectId();
592  virtual RObject::Id getMaxObjectId();
593  virtual RObject::Handle getNewObjectHandle();
594  virtual RObject::Handle getMaxObjectHandle();
595 
596  virtual void setMaxDrawOrder(int m) {
597  maxDrawOrder = m;
598  }
599 
600  virtual int getMaxDrawOrder() {
601  return maxDrawOrder;
602  }
603 
604  virtual int getMinDrawOrder();
605 
610  virtual bool isInBackStorage(RObject::Id /*object*/) {
611  return false;
612  }
613 
614  static QString getKnownVariableName(RS::KnownVariable n);
615 
619  friend QDebug operator<<(QDebug dbg, RStorage& s);
620 
621  void setModified(bool m);
622 
623  bool isModified() const {
624  return modified;
625  }
626 
627  void addModifiedListener(RModifiedListener* l);
628 
632  virtual void update() {}
633 
634 protected:
635  bool modified;
636 
637 private:
645  //RLayer::Id currentLayerId;
648 
651 
652  QList<RModifiedListener*> modifiedListeners;
653 };
654 
657 
658 #endif
Represents a box e.g.
Definition: RBox.h:43
int Handle
Definition: RObject.h:55
RColor currentColor
Definition: RStorage.h:642
virtual QSharedPointer< RView > queryCurrentView()
Definition: RStorage.h:234
virtual QSharedPointer< RLinetype > queryCurrentLinetype() const
Definition: RStorage.h:273
virtual QSharedPointer< RObject > queryObjectDirect(RObject::Id objectId) const
Definition: RStorage.h:183
RObject::Handle handleCounter
Definition: RStorage.h:641
RDocument * document
Definition: RStorage.h:638
EntityType
Entity types used for property handling / filtering.
Definition: RS.h:75
RDocument * getDocument() const
Definition: RStorage.h:64
Abstract base class for all objects.
Definition: RObject.h:48
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RNonCopyable.h:32
virtual int getMaxDrawOrder()
Definition: RStorage.h:600
virtual QSharedPointer< RBlock > queryCurrentBlock()
Definition: RStorage.h:277
RBlock::Id currentBlockId
Definition: RStorage.h:647
Abstract base class for classes that are interested in the current state of a storage (modified or un...
Definition: RModifiedListener.h:34
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual void setLastTransactionId(int transactionId)
Sets the ID of the last created transaction.
Definition: RStorage.h:513
RView::Id currentViewId
Definition: RStorage.h:646
RLinetype::Id currentLinetypeId
Definition: RStorage.h:644
virtual QSharedPointer< RUcs > queryUcsDirect(RUcs::Id ucsId) const
Definition: RStorage.h:204
int Id
Definition: RObject.h:53
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RStorage.h:55
virtual QSharedPointer< RLayer > queryLayerDirect(RLayer::Id layerId) const
Definition: RStorage.h:220
int maxDrawOrder
Definition: RStorage.h:639
void setCurrentBlock(const QString &blockName)
Definition: RStorage.h:286
Transaction implementation.
Definition: RTransaction.h:70
void setDocument(RDocument *doc)
Definition: RStorage.h:60
QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition: RBox.cpp:393
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RLinetypePattern.h:45
virtual int getTransactionGroup() const
Definition: RStorage.h:523
virtual bool isEntity(RObject::Id objectId)
Definition: RStorage.h:443
virtual RBlock::Id getCurrentBlockId() const
Definition: RStorage.h:294
virtual RView::Id getCurrentViewId() const
Definition: RStorage.h:257
static const Id INVALID_ID
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RObject.h:54
Lineweight
Definition: RLineweight.h:42
Color.
Definition: RColor.h:42
virtual bool isLayerLocked(RLayer::Id layerId) const
Definition: RStorage.h:448
int lastTransactionId
Definition: RStorage.h:649
virtual bool isInBackStorage(RObject::Id)
Linked storages should return true if the given object is stored in the storage the linked storage li...
Definition: RStorage.h:610
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:63
virtual bool isLayerFrozen(RLayer::Id layerId) const
Definition: RStorage.h:456
Q_DECLARE_METATYPE(RMath *)
QList< RModifiedListener * > modifiedListeners
Definition: RStorage.h:652
void setCurrentView(const QString &viewName)
Definition: RStorage.h:304
int lastTransactionGroup
Definition: RStorage.h:650
KnownVariable
Well established document variables.
Definition: RS.h:282
virtual void update()
Clear caches:
Definition: RStorage.h:632
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:281
bool modified
Definition: RStorage.h:635
virtual QSharedPointer< RLayer > queryCurrentLayer()
Definition: RStorage.h:230
RObject::Id idCounter
Definition: RStorage.h:640
bool isModified() const
Definition: RStorage.h:623
virtual ~RStorage()
Definition: RStorage.h:58
All entities (for filters)
Definition: RS.h:76
virtual QSharedPointer< REntity > queryEntityDirect(REntity::Id entityId) const
Definition: RStorage.h:194
virtual void startTransactionGroup()
Definition: RStorage.h:519
void setCurrentView(RView::Id viewId)
Definition: RStorage.h:299
RLineweight::Lineweight currentLineweight
Definition: RStorage.h:643
virtual int countSelectedEntities() const
Definition: RStorage.h:368
Unit
Enum of supported units (values correspond to DXF spec).
Definition: RS.h:206
virtual bool isSelected(REntity::Id entityId)
Definition: RStorage.h:438
virtual void setMaxDrawOrder(int m)
Definition: RStorage.h:596
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RRequireHeap.h:30
virtual int getLastTransactionId()
Definition: RStorage.h:503
virtual bool isBlockFrozen(RBlock::Id blockId) const
Definition: RStorage.h:464
virtual bool hasVariable(const QString &key) const
Definition: RStorage.h:357