QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RMemoryStorage.h
Go to the documentation of this file.
1 
20 #ifndef RMEMORYSTORAGE_H_
21 #define RMEMORYSTORAGE_H_
22 
23 #include "core_global.h"
24 
25 #include <QSharedPointer>
26 
27 #include "RStorage.h"
28 #include "RBlockReferenceEntity.h"
29 #include "RDocumentVariables.h"
30 
38 public:
40  virtual ~RMemoryStorage();
41 
42  virtual void clear();
43 
44  virtual void setCurrentBlock(RBlock::Id blockId);
45 
46  virtual void beginTransaction();
47  virtual void commitTransaction();
48  virtual void rollbackTransaction();
49 
50  //virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds);
51 
52  virtual QSet<RObject::Id> queryAllObjects();
53  virtual QSet<REntity::Id> queryAllEntities(bool undone = false, bool allBlocks = false, RS::EntityType type = RS::EntityAll);
54  virtual QSet<RUcs::Id> queryAllUcs();
55  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false);
56  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false);
57  virtual QSet<RView::Id> queryAllViews(bool undone = false);
58  virtual QSet<RLinetype::Id> queryAllLinetypes();
59  virtual QSet<REntity::Id> queryInfiniteEntities();
60  virtual QSet<REntity::Id> querySelectedEntities();
61 
62  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false);
63  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId);
64  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll);
65  virtual bool hasChildEntities(REntity::Id parentId);
66  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId);
67  virtual QSet<REntity::Id> queryAllBlockReferences();
68  //virtual QSet<REntity::Id> queryViewEntities(RView::Id viewId);
69 
70  virtual QSharedPointer<RDocumentVariables> queryDocumentVariables() const;
71  virtual QSharedPointer<RDocumentVariables> queryDocumentVariablesDirect() const;
72  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const;
73  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const;
74  virtual QSharedPointer<RObject> queryObjectByHandleDirect(RObject::Handle objectHandle) const;
75  virtual QSharedPointer<REntity> queryEntity(REntity::Id objectId) const;
76  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const;
77  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const;
78  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const;
79  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const;
80  virtual QSharedPointer<RView> queryView(RView::Id viewId) const;
81  virtual QSharedPointer<RView> queryView(const QString& viewName) const;
82  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const;
83  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const;
84  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const;
85  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const;
86  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const;
87 
88  virtual void clearEntitySelection(QSet<REntity::Id>* affectedEntities = NULL);
89  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL);
90  virtual void selectEntity(REntity::Id entityId, bool add = false,
91  QSet<REntity::Id>* affectedEntities = NULL);
92  virtual void deselectEntity(REntity::Id entityId,
93  QSet<REntity::Id>* affectedEntities=NULL);
94  virtual void selectEntities(const QSet<REntity::Id>& entityIds,
95  bool add = false,
96  QSet<REntity::Id>* affectedEntities = NULL);
97  virtual void deselectEntities(const QSet<REntity::Id>& entityIds,
98  QSet<REntity::Id>* affectedEntities = NULL);
99  void setEntitySelected(QSharedPointer<REntity> entity, bool on,
100  QSet<REntity::Id>* affectedEntities = NULL, bool onlyDescend = false);
101  virtual bool isSelected(REntity::Id entityId);
102 
103  virtual bool hasSelection() const;
104 
105  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty=false) const;
106  virtual RBox getSelectionBox() const;
107 
108  virtual bool removeObject(QSharedPointer<RObject> object);
109  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false);
110  bool checkRecursion(
111  RBlock::Id blockId, RBlock::Id potentialChildBlockId
112  );
113  virtual bool deleteObject(RObject::Id objectId);
114  virtual void saveTransaction(RTransaction& transaction);
115  virtual void deleteTransactionsFrom(int transactionId);
116  virtual RTransaction getTransaction(int transactionId);
117 
118  virtual void resetTransactionStack();
119 
120  virtual void toggleUndoStatus(QSet<RObject::Id>& objects);
121  virtual void toggleUndoStatus(RObject::Id object);
122  virtual bool setUndoStatus(RObject::Id objectId, bool status);
123  //virtual bool getUndoStatus(RObject::Id objectId) const;
124  virtual int getMaxTransactionId();
125 
126  virtual QStringList getVariables() const;
127  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite = true);
128  virtual QVariant getVariable(const QString& key) const;
129 
130  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value, RTransaction* transaction = NULL);
131  virtual QVariant getKnownVariable(RS::KnownVariable key) const;
132 
133  virtual QString getLayerName(RLayer::Id layerId) const;
134  virtual QSet<QString> getLayerNames() const;
135  virtual RLayer::Id getLayerId(const QString& layerName) const;
136 
137  virtual QString getBlockName(RBlock::Id blockId) const;
138  virtual QSet<QString> getBlockNames() const;
139  virtual RBlock::Id getBlockId(const QString& blockName) const;
140 
141  virtual QString getViewName(RView::Id viewId) const;
142  virtual QSet<QString> getViewNames() const;
143  virtual RView::Id getViewId(const QString& viewName) const;
144 
145  virtual QString getLinetypeName(RLinetype::Id linetypeId) const;
146  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const;
147  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const;
148  virtual QSet<QString> getLinetypeNames() const;
149  virtual QList<RLinetypePattern> getLinetypePatterns() const;
150  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const;
151 
152  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const;
153  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id objectId) const;
154  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const;
155  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const;
156  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const;
157 
158  virtual void setLastTransactionId(int transactionId);
159 
161 
162  virtual void update();
163 
164  //virtual void setUnit(RS::Unit unit, RTransaction* transaction = NULL);
165  //virtual RS::Unit getUnit() const;
166 
167 // virtual void setDimensionFont(const QString& f);
168 // virtual QString getDimensionFont() const;
169 
170 // virtual void setLinetypeScale(double v, RTransaction* transaction);
171 // virtual double getLinetypeScale() const;
172 
173 protected:
175 
176  mutable RBox boundingBox[2][2];
177  mutable bool boundingBoxChanged;
178  //mutable bool boundingBoxIgnoreHiddenLayers;
179  //mutable bool boundingBoxIgnoreEmpty;
180 
182  QHash<RObject::Id, QSharedPointer<RObject> > objectMap;
183  QHash<RObject::Handle, QSharedPointer<RObject> > objectHandleMap;
184  QHash<REntity::Id, QSharedPointer<REntity> > entityMap;
185  QMultiHash<RBlock::Id, QSharedPointer<REntity> > blockEntityMap;
186  QHash<RBlock::Id, QSharedPointer<RBlock> > blockMap;
187  QHash<RLayer::Id, QSharedPointer<RLayer> > layerMap;
188  QHash<RLayer::Id, QSharedPointer<RLinetype> > linetypeMap;
189  QHash<int, RTransaction> transactionMap;
190 
191  // document wide variables are stored as custom properties in this object:
192  QSharedPointer<RDocumentVariables> documentVariables;
193 
194  QHash<QString, QVariant> variables;
195  QMap<QString, QString> variableCaseMap;
196  //QHash<RS::KnownVariable, QVariant> knownVariables;
197  //RS::Unit unit;
198  //QString dimensionFont;
199  //double linetypeScale;
200 };
201 
203 
204 #endif /* RMEMORYSTOARGE_H_ */