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 "REntity.h"
32 #include "RLayer.h"
33 #include "RLinetype.h"
34 #include "RModifiedListener.h"
35 #include "RNonCopyable.h"
36 #include "RRequireHeap.h"
37 #include "RTransaction.h"
38 #include "RUcs.h"
39 #include "RView.h"
40 
41 
54 public:
55  RStorage();
56  virtual ~RStorage() { }
57 
61  virtual void clear();
62 
68  virtual void beginTransaction() = 0;
69 
75  virtual void commitTransaction() = 0;
76 
81  virtual void rollbackTransaction() = 0;
82 
86  virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds) const;
87 
91  virtual QSet<RObject::Id> queryAllObjects() = 0;
92 
96  virtual QSet<REntity::Id> queryAllEntities(bool undone = false,
97  bool allBlocks = false) = 0;
98 
102  virtual QSet<RUcs::Id> queryAllUcs() = 0;
103 
107  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false) = 0;
108 
112  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false) = 0;
113 
117  virtual QSet<RView::Id> queryAllViews(bool undone = false) = 0;
118 
122  virtual QSet<RLinetype::Id> queryAllLinetypes() = 0;
123 
127  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) = 0;
128 
132  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) = 0;
133 
139  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll) = 0;
140 
141  virtual bool hasChildEntities(REntity::Id parentId) = 0;
142 
147  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) = 0;
148 
152  virtual QSet<REntity::Id> queryAllBlockReferences() = 0;
153 
157  virtual QSet<REntity::Id> querySelectedEntities() = 0;
158 
163  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
164 
165  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
166  return queryObject(objectId);
167  }
168  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const = 0;
169 
174  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
175 
176  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
177  return queryEntity(entityId);
178  }
179 
184  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
185 
186  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
187  return queryUcs(ucsId);
188  }
189 
194  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
195 
200  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
201 
202  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
203  return queryLayer(layerId);
204  }
205 
210  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
211 
212  virtual QSharedPointer<RLayer> queryCurrentLayer() {
213  return queryLayer(getCurrentLayerId());
214  }
215 
216  virtual QSharedPointer<RView> queryCurrentView() {
217  return queryView(getCurrentViewId());
218  }
219 
220  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
221 
222  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
223 
224  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
225  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
226  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
227 
228  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
229  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
230 
231  void setCurrentLayer(RLayer::Id layerId) {
232  //setVariable("CurrentLayer", layerId);
233  currentLayerId = layerId;
234  }
235 
236  void setCurrentLayer(const QString& layerName) {
237  RLayer::Id id = getLayerId(layerName);
238  if (id == RLayer::INVALID_ID) {
239  return;
240  }
241  setCurrentLayer(id);
242  }
243 
245  //return (RLayer::Id) getVariable("CurrentLayer").toInt();
246  return currentLayerId;
247  }
248 
250  //return (RView::Id) getVariable("CurrentView").toInt();
251  return currentViewId;
252  }
253 
254  virtual void setCurrentColor(const RColor& color);
255  virtual RColor getCurrentColor();
256 
257  void setCurrentLineweight(RLineweight::Lineweight lw);
258  virtual RLineweight::Lineweight getCurrentLineweight();
259 
260  void setCurrentLinetype(RLinetype lt);
261  virtual RLinetype getCurrentLinetype() const;
262 
263  virtual QSharedPointer<RBlock> queryCurrentBlock() {
264  return queryBlock(getCurrentBlockId());
265  }
266 
267  virtual void setCurrentBlock(RBlock::Id blockId) {
268  //setVariable("CurrentBlock", blockId);
269  currentBlockId = blockId;
270  }
271 
272  void setCurrentBlock(const QString& blockName) {
273  RBlock::Id id = getBlockId(blockName);
274  if (id == RBlock::INVALID_ID) {
275  return;
276  }
277  setCurrentBlock(id);
278  }
279 
280  virtual RBlock::Id getCurrentBlockId() const {
281  //return (RBlock::Id) getVariable("CurrentBlock").toInt();
282  return currentBlockId;
283  }
284 
285  void setCurrentView(RView::Id viewId) {
286  //setVariable("CurrentView", viewId);
287  currentViewId = viewId;
288  }
289 
290  void setCurrentView(const QString& viewName) {
291  RView::Id id = getViewId(viewName);
292  // unlike blocks and layers, the current view can be invalid:
293  setCurrentView(id);
294  }
295 
296  virtual RView::Id getCurrentViewId() const {
297  //return (RView::Id) getVariable("CurrentView").toInt();
298  return currentViewId;
299  }
300 
301  virtual void setUnit(RS::Unit unit);
302  virtual RS::Unit getUnit() const;
303 
304  virtual void setLinetypeScale(double v);
305  virtual double getLinetypeScale() const;
306 
307  virtual QString getBlockName(RBlock::Id blockId) const = 0;
308  virtual QSet<QString> getBlockNames() const = 0;
309  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
310  virtual bool hasBlock(const QString& blockName) const;
311 
312  virtual QString getViewName(RView::Id viewId) const = 0;
313  virtual QSet<QString> getViewNames() const = 0;
314  virtual RView::Id getViewId(const QString& viewName) const = 0;
315  virtual bool hasView(const QString& viewName) const;
316 
317  virtual QString getLayerName(RLayer::Id layerId) const = 0;
318  virtual QSet<QString> getLayerNames() const = 0;
319  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
320  virtual bool hasLayer(const QString& layerName) const;
321 
322  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
323  virtual QSet<QString> getLinetypeNames() const = 0;
324  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
325  virtual bool hasLinetype(const QString& linetypeName) const;
326 
327  virtual QStringList getVariables() const = 0;
328  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
333  virtual QVariant getVariable(const QString& key) const = 0;
334 
338  virtual bool hasVariable(const QString& key) const {
339  QVariant value = getVariable(key);
340  return value.isValid();
341  }
342 
343  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value) = 0;
344  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
345 
349  virtual void clearEntitySelection(
350  QSet<REntity::Id>* affectedEntities=NULL
351  ) = 0;
352 
356  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
357 
367  virtual void selectEntity(
368  REntity::Id entityId,
369  bool add=false,
370  QSet<REntity::Id>* affectedEntities=NULL
371  ) = 0;
372 
382  virtual void selectEntities(
383  const QSet<REntity::Id>& entityIds,
384  bool add=false,
385  QSet<REntity::Id>* affectedEntities=NULL
386  ) = 0;
387 
395  virtual void deselectEntity(
396  REntity::Id entityId,
397  QSet<REntity::Id>* affectedEntities=NULL
398  ) = 0;
399 
407  virtual void deselectEntities(
408  const QSet<REntity::Id>& entityIds,
409  QSet<REntity::Id>* affectedEntities=NULL
410  ) = 0;
411 
412  virtual bool isSelected(REntity::Id entityId) {
413  QSharedPointer<REntity> e = queryEntityDirect(entityId);
414  return (!e.isNull() && e->isSelected());
415  }
416 
417  virtual bool isEntity(RObject::Id objectId) {
418  QSharedPointer<REntity> e = queryEntityDirect(objectId);
419  return !e.isNull();
420  }
421 
422  virtual bool isLayerLocked(RLayer::Id layerId) const {
423  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
424  if (l.isNull()) {
425  return false;
426  }
427  return l->isLocked();
428  }
429 
430  virtual bool isLayerFrozen(RLayer::Id layerId) const {
431  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
432  if (l.isNull()) {
433  return false;
434  }
435  return l->isFrozen();
436  }
437 
438  virtual bool isBlockFrozen(RBlock::Id blockId) const {
439  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
440  if (b.isNull()) {
441  return false;
442  }
443  return b->isFrozen();
444  }
445 
446  void setObjectId(RObject& object, RObject::Id objectId);
447  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
448 
452  virtual bool hasSelection() const = 0;
453 
457  virtual RBox getBoundingBox(bool includeHiddenLayer = true) = 0;
458 
459  virtual RBox getSelectionBox() = 0;
460 
461  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
462 
466  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
467 
471  virtual bool deleteObject(RObject::Id objectId) = 0;
472 
477  virtual int getLastTransactionId() {
478  //return getVariable("LastTransaction").toInt();
479  return lastTransactionId;
480  }
481 
488  virtual void setLastTransactionId(int transactionId) {
489  //setVariable("LastTransaction", transactionId);
490  lastTransactionId = transactionId;
491 
492  setModified(true);
493  }
494 
499  virtual void saveTransaction(RTransaction& transaction) = 0;
500 
507  virtual void deleteTransactionsFrom(int transactionId) = 0;
508 
509  virtual void resetTransactionStack() = 0;
510 
514  virtual RTransaction getTransaction(int transactionId) = 0;
515 
521  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
522 
526  virtual void toggleUndoStatus(RObject::Id object) = 0;
527 
528  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
529 
530  //virtual bool getUndoStatus(RObject::Id object) const = 0;
531 
536  virtual int getMaxTransactionId() = 0;
537 
538  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
539 
540  virtual RObject::Id getNewObjectId();
541  virtual RObject::Id getMaxObjectId();
542  virtual RObject::Handle getNewObjectHandle();
543  virtual RObject::Handle getMaxObjectHandle();
544 
545  virtual void setMaxDrawOrder(int m) {
546  maxDrawOrder = m;
547  }
548 
549  virtual int getMaxDrawOrder() {
550  return maxDrawOrder;
551  }
552 
553  virtual int getMinDrawOrder();
554 
559  virtual bool isInBackStorage(RObject::Id /*object*/) {
560  return false;
561  }
562 
563  static QString getKnownVariableName(RS::KnownVariable n);
564 
568  friend QDebug operator<<(QDebug dbg, RStorage& s);
569 
570  void setModified(bool m);
571 
572  bool isModified() const {
573  return modified;
574  }
575 
576  void addModifiedListener(RModifiedListener* l);
577 
578 protected:
579  bool modified;
580 
581 private:
592 
593  QList<RModifiedListener*> modifiedListeners;
594 };
595 
598 
599 #endif