Open Source 2D CAD
Go to the documentation of this file.
23 #include "core_global.h"
25 #include <QSharedPointer>
27 #include "RStorage.h"
28 #include "RBlockReferenceEntity.h"
29 #include "RDocumentVariables.h"
38 public:
40  virtual ~RMemoryStorage();
42  virtual void clear();
44  virtual void setCurrentBlock(RBlock::Id blockId);
46  virtual void beginTransaction();
47  virtual void commitTransaction();
48  virtual void rollbackTransaction();
50  //virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds);
52  virtual QSet<RObject::Id> queryAllObjects();
53  virtual QSet<REntity::Id> queryAllVisibleEntities();
54  virtual QSet<REntity::Id> queryAllEntities(bool undone = false, bool allBlocks = false, RS::EntityType type = RS::EntityAll);
55  virtual QSet<REntity::Id> queryAllEntities(bool undone, bool allBlocks, QList<RS::EntityType> types);
56  virtual QSet<RUcs::Id> queryAllUcs();
57  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false);
58  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false);
59  virtual QSet<RBlock::Id> queryAllLayoutBlocks(bool undone = false);
60  virtual QSet<RView::Id> queryAllViews(bool undone = false);
61  virtual QSet<RLinetype::Id> queryAllLinetypes();
62  virtual QSet<REntity::Id> queryInfiniteEntities();
63  virtual QSet<REntity::Id> querySelectedEntities() const;
65  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false);
66  virtual bool hasBlockEntities(RBlock::Id blockId) const;
67  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId);
68  virtual QSet<REntity::Id> queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId);
69  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll);
70  virtual bool hasChildEntities(REntity::Id parentId);
71  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId);
72  virtual QSet<REntity::Id> queryAllBlockReferences();
73  //virtual QSet<REntity::Id> queryViewEntities(RView::Id viewId);
75  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const;
76  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const;
77  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
78  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
79  virtual QSharedPointer<RObject> queryObjectByHandleDirect(RObject::Handle objectHandle) const;
80  virtual QSharedPointer<REntity> queryEntity(REntity::Id objectId) const;
81  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
82  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
83  virtual QSharedPointer<RLayout> queryLayout(RLayout::Id layoutId) const;
84  virtual QSharedPointer<RLayout> queryLayout(const QString& layoutName) const;
85  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
86  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
87  virtual QSharedPointer<RView> queryView(RView::Id viewId) const;
88  virtual QSharedPointer<RView> queryView(const QString& viewName) const;
89  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
90  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
91  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const;
92  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
93  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
95  void clearSelectionCache();
96  void updateSelectedEntityMap() const;
98  virtual int countSelectedEntities() const;
99  virtual void clearEntitySelection(QSet<REntity::Id>* affectedEntities = NULL);
100  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
101  virtual void selectEntity(REntity::Id entityId, bool add = false,
102  QSet<REntity::Id>* affectedEntities = NULL);
103  virtual void deselectEntity(REntity::Id entityId,
104  QSet<REntity::Id>* affectedEntities=NULL);
105  virtual void selectEntities(const QSet<REntity::Id>& entityIds,
106  bool add = false,
107  QSet<REntity::Id>* affectedEntities = NULL);
108  virtual bool deselectEntities(const QSet<REntity::Id>& entityIds,
109  QSet<REntity::Id>* affectedEntities = NULL);
110  void setEntitySelected(QSharedPointer<REntity> entity, bool on,
111  QSet<REntity::Id>* affectedEntities = NULL, bool onlyDescend = false);
112  virtual bool isSelected(REntity::Id entityId);
114  virtual bool hasSelection() const;
116  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty=false) const;
117  virtual RBox getSelectionBox() const;
119  virtual bool removeObject(QSharedPointer<RObject> object);
120  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false);
121  bool checkRecursion(
122  RBlock::Id blockId, RBlock::Id potentialChildBlockId
123  );
124  virtual bool deleteObject(RObject::Id objectId);
125  virtual void saveTransaction(RTransaction& transaction);
126  virtual void deleteTransactionsFrom(int transactionId);
127  virtual RTransaction getTransaction(int transactionId);
129  virtual void resetTransactionStack();
131  virtual void toggleUndoStatus(QSet<RObject::Id>& objects);
132  virtual void toggleUndoStatus(RObject::Id object);
133  virtual bool setUndoStatus(RObject::Id objectId, bool status);
134  virtual void setUndoStatus(RObject& object, bool status);
135  //virtual bool getUndoStatus(RObject::Id objectId) const;
136  virtual int getMaxTransactionId();
138  virtual QStringList getVariables() const;
139  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite = true);
140  virtual QVariant getVariable(const QString& key) const;
141  virtual void removeVariable(const QString& key);
143  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL);
144  virtual QVariant getKnownVariable(RS::KnownVariable key) const;
146  virtual QString getLayerName(RLayer::Id layerId) const;
147  virtual QSet<QString> getLayerNames(const QString& rxStr = RDEFAULT_QSTRING) const;
148  virtual RLayer::Id getLayerId(const QString& layerName) const;
150  virtual QString getLayoutName(RLayout::Id layoutId) const;
151  virtual QSet<QString> getLayoutNames(const QString& rxStr = RDEFAULT_QSTRING) const;
152  virtual RLayout::Id getLayoutId(const QString& layoutName) const;
154  virtual QString getBlockName(RBlock::Id blockId) const;
155  virtual QSet<QString> getBlockNames(const QString& rxStr = RDEFAULT_QSTRING) const;
156  virtual RBlock::Id getBlockId(const QString& blockName) const;
158  virtual QString getViewName(RView::Id viewId) const;
159  virtual QSet<QString> getViewNames() const;
160  virtual RView::Id getViewId(const QString& viewName) const;
162  virtual QString getLinetypeName(RLinetype::Id linetypeId) const;
163  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const;
164  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const;
165  virtual QSet<QString> getLinetypeNames() const;
166  virtual QList<RLinetypePattern> getLinetypePatterns() const;
167  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const;
169  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
170  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id objectId) const;
171  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const;
172  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
173  virtual QSharedPointer<RLayout> queryLayoutDirect(RLayout::Id layoutId) const;
174  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
176  virtual void setObjectHandle(RObject& object, RObject::Handle objectHandle);
179  virtual void setLastTransactionId(int transactionId);
183  virtual void update();
185  virtual void setEntityParentId(REntity& entity, REntity::Id parentId);
187  //virtual void setUnit(RS::Unit unit, RTransaction* transaction = NULL);
188  //virtual RS::Unit getUnit() const;
190 // virtual void setDimensionFont(const QString& f);
191 // virtual QString getDimensionFont() const;
193 // virtual void setLinetypeScale(double v, RTransaction* transaction);
194 // virtual double getLinetypeScale() const;
196 protected:
202  mutable RBox boundingBox[2][2];
203  mutable bool boundingBoxDirty;
204  //mutable bool boundingBoxIgnoreHiddenLayers;
205  //mutable bool boundingBoxIgnoreEmpty;
208  QHash<RObject::Id, QSharedPointer<RObject> > objectMap;
209  QHash<RObject::Handle, QSharedPointer<RObject> > objectHandleMap;
210  QHash<REntity::Id, QSharedPointer<REntity> > entityMap;
211  mutable QHash<REntity::Id, QSharedPointer<REntity> > selectedEntityMap;
213  QMultiHash<RBlock::Id, QSharedPointer<REntity> > blockEntityMap;
214  QHash<RBlock::Id, QSharedPointer<RBlock> > blockMap;
215  QHash<RLayer::Id, QSharedPointer<RLayer> > layerMap;
216  QHash<RLayout::Id, QSharedPointer<RLayout> > layoutMap;
217  QHash<RLinetype::Id, QSharedPointer<RLinetype> > linetypeMap;
219  QMultiHash<REntity::Id, REntity::Id> childMap;
220  QHash<int, RTransaction> transactionMap;
222  // document wide variables are stored as custom properties in this object:
223  QSharedPointer<RDocumentVariables> documentVariables;
225  QHash<QString, QVariant> variables;
226  QMap<QString, QString> variableCaseMap;
227  //QHash<RS::KnownVariable, QVariant> knownVariables;
228  //RS::Unit unit;
229  //QString dimensionFont;
230  //double linetypeScale;
231 };
235 #endif /* RMEMORYSTOARGE_H_ */
virtual RLineweight::Lineweight getMaxLineweight() const =0
Represents a box e.g.
Definition: RBox.h:43
virtual void setVariable(const QString &key, const QVariant &value, bool overwrite=true)=0
Sets a custom variable in the context of this document.
virtual RBox getSelectionBox() const =0
virtual void saveTransaction(RTransaction &transaction)=0
Saves the given transaction.
int Handle
Definition: RObject.h:59
virtual QSet< REntity::Id > queryInfiniteEntities()=0
virtual QSet< REntity::Id > queryLayerBlockEntities(RLayer::Id layerId, RBlock::Id blockId)=0
virtual bool hasSelection() const =0
virtual QSharedPointer< RObject > queryObjectDirect(RObject::Id objectId) const
Definition: RStorage.h:207
virtual bool removeObject(QSharedPointer< RObject > object)=0
virtual QSet< REntity::Id > queryAllBlockReferences()=0
bool boundingBoxDirty
Definition: RMemoryStorage.h:203
virtual void selectEntities(const QSet< REntity::Id > &entityIds, bool add=false, QSet< REntity::Id > *affectedEntities=NULL)=0
Selects all entities with the given IDs.
virtual QSet< RLayer::Id > queryAllLayers(bool undone=false)=0
virtual RLinetype::Id getLinetypeId(const QString &linetypeName) const =0
virtual QList< RLinetypePattern > getLinetypePatterns() const =0
virtual QSet< RObject::Id > queryAllObjects()=0
Entity types used for property handling / filtering.
Definition: RS.h:76
virtual RBlock::Id getBlockId(const QString &blockName) const =0
virtual QSet< REntity::Id > queryBlockEntities(RBlock::Id blockId)=0
QHash< REntity::Id, QSharedPointer< REntity > > selectedEntityMap
Definition: RMemoryStorage.h:211
virtual RTransaction getTransaction(int transactionId)=0
Abstract base class for all objects.
Definition: RObject.h:52
virtual QVariant getKnownVariable(RS::KnownVariable key) const =0
virtual bool hasChildEntities(REntity::Id parentId)=0
virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const =0
Definition: core_global.h:10
virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const =0
virtual void setLastTransactionId(int transactionId)
Sets the ID of the last created transaction.
Definition: RStorage.h:617
virtual QSharedPointer< RUcs > queryUcs(RUcs::Id ucsId) const =0
virtual QSet< QString > getViewNames() const =0
virtual void deselectEntity(REntity::Id entityId, QSet< REntity::Id > *affectedEntities=NULL)=0
Deselects the entity with the given ID.
virtual QSharedPointer< RUcs > queryUcsDirect(RUcs::Id ucsId) const
Definition: RStorage.h:228
int Id
Definition: RObject.h:57
virtual QSet< REntity::Id > queryLayerEntities(RLayer::Id layerId, bool allBlocks=false)=0
QMap< QString, QString > variableCaseMap
Definition: RMemoryStorage.h:226
This is the abstract base class for all storage implementations.
Definition: RStorage.h:62
virtual QSharedPointer< RLayer > queryLayerDirect(RLayer::Id layerId) const
Definition: RStorage.h:244
Transaction implementation.
Definition: RTransaction.h:74
virtual void resetTransactionStack()=0
virtual void setObjectHandle(RObject &object, RObject::Handle objectHandle)
Definition: RStorage.cpp:59
virtual QSet< RBlock::Id > queryAllLayoutBlocks(bool undone=false)=0
virtual void rollbackTransaction()=0
Rolls the current transaction back in order to cancel it.
virtual QSet< RUcs::Id > queryAllUcs()=0
virtual QSharedPointer< RObject > queryObject(RObject::Id objectId) const =0
QHash< RBlock::Id, QSharedPointer< RBlock > > blockMap
Definition: RMemoryStorage.h:214
virtual bool deleteObject(RObject::Id objectId)=0
Deletes the object with the given ID.
Definition: RLineweight.h:42
QSharedPointer< RDocumentVariables > documentVariables
Definition: RMemoryStorage.h:223
virtual RBox getBoundingBox(bool ignoreHiddenLayers=true, bool ignoreEmpty=false) const =0
QHash< RObject::Handle, QSharedPointer< RObject > > objectHandleMap
Definition: RMemoryStorage.h:209
virtual QStringList getVariables() const =0
virtual QString getLinetypeName(RLinetype::Id linetypeId) const =0
virtual int getMaxTransactionId()=0
virtual void setEntityParentId(REntity &entity, REntity::Id parentId)
Definition: RStorage.h:573
virtual QSet< QString > getLayerNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSharedPointer< RLayout > queryLayout(RLayout::Id layoutId) const =0
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RMemoryStorage.h:37
virtual QSet< REntity::Id > querySelectedEntities() const =0
virtual bool hasBlockEntities(RBlock::Id blockId) const =0
virtual RLayout::Id getLayoutId(const QString &layoutName) const =0
Base class for all entity classes.
Definition: REntity.h:64
QHash< QString, QVariant > variables
Definition: RMemoryStorage.h:225
virtual void setKnownVariable(RS::KnownVariable key, const QVariant &value, RTransaction *transaction=NULL)=0
Sets a known DXF/DWG variable for this document.
virtual void clear()
Resets this storage to its initial, empty state.
Definition: RStorage.cpp:40
virtual QSharedPointer< RObject > queryObjectByHandle(RObject::Handle objectHandle) const =0
virtual QString getLayoutName(RLayout::Id layoutId) const =0
virtual QSharedPointer< RView > queryView(RView::Id viewId) const =0
virtual QSharedPointer< RDocumentVariables > queryDocumentVariables() const =0
virtual void removeVariable(const QString &key)=0
Removes the custom variable with the given key.
virtual bool saveObject(QSharedPointer< RObject > object, bool checkBlockRecursion=true, bool keepHandles=false)=0
Saves the given object to the storage.
QHash< RLayout::Id, QSharedPointer< RLayout > > layoutMap
Definition: RMemoryStorage.h:216
virtual QSharedPointer< RBlock > queryBlock(RBlock::Id blockId) const =0
virtual void commitTransaction()=0
Commits the current transaction.
virtual QString getBlockName(RBlock::Id blockId) const =0
QHash< RObject::Id, QSharedPointer< RObject > > objectMap
Definition: RMemoryStorage.h:208
Well established document variables.
Definition: RS.h:329
virtual QSharedPointer< REntity > queryEntity(REntity::Id entityId) const =0
virtual void update()
Clear caches:
Definition: RStorage.h:734
virtual void setCurrentBlock(RBlock::Id blockId)
Definition: RStorage.h:322
virtual QSharedPointer< RDocumentVariables > queryDocumentVariablesDirect() const =0
virtual RLayer::Id getLayerId(const QString &layerName) const =0
virtual QSet< QString > getLayoutNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSharedPointer< RLayer > queryLayer(RLayer::Id layerId) const =0
virtual RObject::Handle getNewObjectHandle()
Definition: RStorage.cpp:78
virtual void selectEntity(REntity::Id entityId, bool add=false, QSet< REntity::Id > *affectedEntities=NULL)=0
Selects the entity with the given ID.
virtual void toggleUndoStatus(QSet< RObject::Id > &objects)=0
Toggles the current undo status of all given objects.
virtual QSet< RLinetype::Id > queryAllLinetypes()=0
All entities (for filters)
Definition: RS.h:88
virtual QSharedPointer< REntity > queryEntityDirect(REntity::Id entityId) const
Definition: RStorage.h:218
virtual QSharedPointer< RBlock > queryBlockDirect(RBlock::Id blockId) const =0
virtual QString getViewName(RView::Id viewId) const =0
virtual QSet< REntity::Id > queryChildEntities(REntity::Id parentId, RS::EntityType type=RS::EntityAll)=0
virtual QSet< RView::Id > queryAllViews(bool undone=false)=0
virtual void clearEntitySelection(QSet< REntity::Id > *affectedEntities=NULL)=0
Clears the selection status of all entities.
virtual QSharedPointer< RLinetype > queryLinetypeDirect(RLinetype::Id linetypeId) const =0
QMultiHash< RBlock::Id, QSharedPointer< REntity > > blockEntityMap
Definition: RMemoryStorage.h:213
virtual QSet< REntity::Id > queryAllEntities(bool undone=false, bool allBlocks=false, RS::EntityType type=RS::EntityAll)=0
bool selectedEntityMapDirty
Definition: RMemoryStorage.h:212
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RDebug.h:48
QHash< RLinetype::Id, QSharedPointer< RLinetype > > linetypeMap
Definition: RMemoryStorage.h:217
virtual int countSelectedEntities() const
Definition: RStorage.h:469
virtual QSet< QString > getLinetypeNames() const =0
virtual QSet< QString > getBlockNames(const QString &rxStr=RDEFAULT_QSTRING) const =0
virtual QSet< REntity::Id > queryAllVisibleEntities()=0
virtual QSet< RBlock::Id > queryAllBlocks(bool undone=false)=0
virtual QString getLayerName(RLayer::Id layerId) const =0
virtual void beginTransaction()=0
Starts a new transaction.
virtual bool isSelected(REntity::Id entityId)
Definition: RStorage.h:539
QHash< int, RTransaction > transactionMap
Definition: RMemoryStorage.h:220
QHash< REntity::Id, QSharedPointer< REntity > > entityMap
Definition: RMemoryStorage.h:210
virtual void deleteTransactionsFrom(int transactionId)=0
Deletes all transactions with IDs from transactionId (inclusive) to the maximum transaction ID...
virtual QSharedPointer< RLayout > queryLayoutDirect(RLayout::Id layoutId) const
Definition: RStorage.h:267
RLineweight::Lineweight maxLineweight
Definition: RMemoryStorage.h:197
virtual QSharedPointer< RLinetype > queryLinetype(RLinetype::Id linetypeId) const =0
QMultiHash< REntity::Id, REntity::Id > childMap
maps parent entity IDs to child entity IDs
Definition: RMemoryStorage.h:219
virtual void selectAllEntites(QSet< REntity::Id > *affectedEntities=NULL)=0
Sets the selection status of all entities.
virtual QSet< REntity::Id > queryBlockReferences(RBlock::Id blockId)=0
virtual RView::Id getViewId(const QString &viewName) const =0
QHash< RLayer::Id, QSharedPointer< RLayer > > layerMap
Definition: RMemoryStorage.h:215
virtual QVariant getVariable(const QString &key) const =0
virtual void setUndoStatus(RObject &object, bool status)
Definition: RStorage.cpp:66
bool inTransaction
Definition: RMemoryStorage.h:207
virtual bool deselectEntities(const QSet< REntity::Id > &entityIds, QSet< REntity::Id > *affectedEntities=NULL)=0
Deselects all entities with the given IDs.