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 "RLinetypePattern.h"
35 #include "RModifiedListener.h"
36 #include "RNonCopyable.h"
37 #include "RRequireHeap.h"
38 #include "RTransaction.h"
39 #include "RUcs.h"
40 #include "RView.h"
41 
42 
55 public:
56  RStorage();
57  virtual ~RStorage() { }
58 
62  virtual void clear();
63 
69  virtual void beginTransaction() = 0;
70 
76  virtual void commitTransaction() = 0;
77 
82  virtual void rollbackTransaction() = 0;
83 
87  virtual QList<REntity::Id> orderBackToFront(const QSet<REntity::Id>& entityIds) const;
88 
92  virtual QSet<RObject::Id> queryAllObjects() = 0;
93 
97  virtual QSet<REntity::Id> queryAllEntities(bool undone = false,
98  bool allBlocks = false, RS::EntityType type = RS::EntityAll) = 0;
99 
103  virtual QSet<RUcs::Id> queryAllUcs() = 0;
104 
108  virtual QSet<RLayer::Id> queryAllLayers(bool undone = false) = 0;
109 
113  virtual QSet<RBlock::Id> queryAllBlocks(bool undone = false) = 0;
114 
118  virtual QSet<RView::Id> queryAllViews(bool undone = false) = 0;
119 
123  virtual QSet<RLinetype::Id> queryAllLinetypes() = 0;
124 
128  virtual QSet<REntity::Id> queryLayerEntities(RLayer::Id layerId, bool allBlocks = false) = 0;
129 
133  virtual QSet<REntity::Id> queryBlockEntities(RBlock::Id blockId) = 0;
134 
140  virtual QSet<REntity::Id> queryChildEntities(REntity::Id parentId, RS::EntityType type = RS::EntityAll) = 0;
141 
142  virtual bool hasChildEntities(REntity::Id parentId) = 0;
143 
148  virtual QSet<REntity::Id> queryBlockReferences(RBlock::Id blockId) = 0;
149 
153  virtual QSet<REntity::Id> queryAllBlockReferences() = 0;
154 
158  virtual QSet<REntity::Id> querySelectedEntities() = 0;
159 
163  virtual QSet<REntity::Id> queryInfiniteEntities() = 0;
164 
169  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
170 
171  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
172  return queryObject(objectId);
173  }
174  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const = 0;
175 
180  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
181 
182  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
183  return queryEntity(entityId);
184  }
185 
190  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
191 
192  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
193  return queryUcs(ucsId);
194  }
195 
200  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
201 
206  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
207 
208  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
209  return queryLayer(layerId);
210  }
211 
216  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
217 
218  virtual QSharedPointer<RLayer> queryCurrentLayer() {
219  return queryLayer(getCurrentLayerId());
220  }
221 
222  virtual QSharedPointer<RView> queryCurrentView() {
223  return queryView(getCurrentViewId());
224  }
225 
226  virtual QSharedPointer<RLinetype> queryLinetypeDirect(RLinetype::Id linetypeId) const = 0;
227  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
228  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
229 
230  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
231  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
232  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
233 
234  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
235  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
236 
237  void setCurrentLayer(RLayer::Id layerId) {
238  //setVariable("CurrentLayer", layerId);
239  currentLayerId = layerId;
240  }
241 
242  void setCurrentLayer(const QString& layerName) {
243  RLayer::Id id = getLayerId(layerName);
244  if (id == RLayer::INVALID_ID) {
245  return;
246  }
247  setCurrentLayer(id);
248  }
249 
251  //return (RLayer::Id) getVariable("CurrentLayer").toInt();
252  return currentLayerId;
253  }
254 
256  //return (RView::Id) getVariable("CurrentView").toInt();
257  return currentViewId;
258  }
259 
260  virtual void setCurrentColor(const RColor& color);
261  virtual RColor getCurrentColor();
262 
263  void setCurrentLineweight(RLineweight::Lineweight lw);
264  virtual RLineweight::Lineweight getCurrentLineweight() const;
265 
266  void setCurrentLinetype(RLinetype::Id ltId);
267  void setCurrentLinetype(const QString& name);
268  void setCurrentLinetypePattern(const RLinetypePattern& p);
269  virtual RLinetype::Id getCurrentLinetypeId() const;
270  virtual RLinetypePattern getCurrentLinetypePattern() const;
271  virtual QSharedPointer<RLinetype> queryCurrentLinetype() const {
272  return queryLinetype(getCurrentLinetypeId());
273  }
274 
275  virtual QSharedPointer<RBlock> queryCurrentBlock() {
276  return queryBlock(getCurrentBlockId());
277  }
278 
279  virtual void setCurrentBlock(RBlock::Id blockId) {
280  //setVariable("CurrentBlock", blockId);
281  currentBlockId = blockId;
282  }
283 
284  void setCurrentBlock(const QString& blockName) {
285  RBlock::Id id = getBlockId(blockName);
286  if (id == RBlock::INVALID_ID) {
287  return;
288  }
289  setCurrentBlock(id);
290  }
291 
292  virtual RBlock::Id getCurrentBlockId() const {
293  //return (RBlock::Id) getVariable("CurrentBlock").toInt();
294  return currentBlockId;
295  }
296 
297  void setCurrentView(RView::Id viewId) {
298  //setVariable("CurrentView", viewId);
299  currentViewId = viewId;
300  }
301 
302  void setCurrentView(const QString& viewName) {
303  RView::Id id = getViewId(viewName);
304  // unlike blocks and layers, the current view can be invalid:
305  setCurrentView(id);
306  }
307 
308  virtual RView::Id getCurrentViewId() const {
309  //return (RView::Id) getVariable("CurrentView").toInt();
310  return currentViewId;
311  }
312 
313  virtual void setUnit(RS::Unit unit);
314  virtual RS::Unit getUnit() const;
315 
316  virtual void setDimensionFont(const QString& f);
317  virtual QString getDimensionFont() const;
318 
319  virtual void setLinetypeScale(double v);
320  virtual double getLinetypeScale() const;
321 
322  virtual QString getBlockName(RBlock::Id blockId) const = 0;
323  virtual QSet<QString> getBlockNames() const = 0;
324  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
325  virtual bool hasBlock(const QString& blockName) const;
326 
327  virtual QString getViewName(RView::Id viewId) const = 0;
328  virtual QSet<QString> getViewNames() const = 0;
329  virtual RView::Id getViewId(const QString& viewName) const = 0;
330  virtual bool hasView(const QString& viewName) const;
331 
332  virtual QString getLayerName(RLayer::Id layerId) const = 0;
333  virtual QSet<QString> getLayerNames() const = 0;
334  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
335  virtual bool hasLayer(const QString& layerName) const;
336 
337  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
338  virtual QString getLinetypeDescription(RLinetype::Id linetypeId) const = 0;
339  virtual QString getLinetypeLabel(RLinetype::Id linetypeId) const = 0;
340  virtual QSet<QString> getLinetypeNames() const = 0;
341  virtual QList<RLinetypePattern> getLinetypePatterns() const = 0;
342  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
343  virtual bool hasLinetype(const QString& linetypeName) const;
344 
345  virtual QStringList getVariables() const = 0;
346  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
351  virtual QVariant getVariable(const QString& key) const = 0;
352 
356  virtual bool hasVariable(const QString& key) const {
357  QVariant value = getVariable(key);
358  return value.isValid();
359  }
360 
361  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value) = 0;
362  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
363 
367  virtual void clearEntitySelection(
368  QSet<REntity::Id>* affectedEntities=NULL
369  ) = 0;
370 
374  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
375 
385  virtual void selectEntity(
386  REntity::Id entityId,
387  bool add=false,
388  QSet<REntity::Id>* affectedEntities=NULL
389  ) = 0;
390 
400  virtual void selectEntities(
401  const QSet<REntity::Id>& entityIds,
402  bool add=false,
403  QSet<REntity::Id>* affectedEntities=NULL
404  ) = 0;
405 
413  virtual void deselectEntity(
414  REntity::Id entityId,
415  QSet<REntity::Id>* affectedEntities=NULL
416  ) = 0;
417 
425  virtual void deselectEntities(
426  const QSet<REntity::Id>& entityIds,
427  QSet<REntity::Id>* affectedEntities=NULL
428  ) = 0;
429 
430  virtual bool isSelected(REntity::Id entityId) {
431  QSharedPointer<REntity> e = queryEntityDirect(entityId);
432  return (!e.isNull() && e->isSelected());
433  }
434 
435  virtual bool isEntity(RObject::Id objectId) {
436  QSharedPointer<REntity> e = queryEntityDirect(objectId);
437  return !e.isNull();
438  }
439 
440  virtual bool isLayerLocked(RLayer::Id layerId) const {
441  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
442  if (l.isNull()) {
443  return false;
444  }
445  return l->isLocked();
446  }
447 
448  virtual bool isLayerFrozen(RLayer::Id layerId) const {
449  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
450  if (l.isNull()) {
451  return false;
452  }
453  return l->isFrozen();
454  }
455 
456  virtual bool isBlockFrozen(RBlock::Id blockId) const {
457  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
458  if (b.isNull()) {
459  return false;
460  }
461  return b->isFrozen();
462  }
463 
464  void setObjectId(RObject& object, RObject::Id objectId);
465  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
466 
470  virtual bool hasSelection() const = 0;
471 
475  virtual RBox getBoundingBox(bool ignoreHiddenLayers = true, bool ignoreEmpty = false) const = 0;
476 
477  virtual RBox getSelectionBox() const = 0;
478 
479  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
480 
484  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
485 
489  virtual bool deleteObject(RObject::Id objectId) = 0;
490 
495  virtual int getLastTransactionId() {
496  //return getVariable("LastTransaction").toInt();
497  return lastTransactionId;
498  }
499 
506  virtual void setLastTransactionId(int transactionId) {
507  //setVariable("LastTransaction", transactionId);
508  lastTransactionId = transactionId;
509 
510  setModified(true);
511  }
512 
517  virtual void saveTransaction(RTransaction& transaction) = 0;
518 
525  virtual void deleteTransactionsFrom(int transactionId) = 0;
526 
527  virtual void resetTransactionStack() = 0;
528 
532  virtual RTransaction getTransaction(int transactionId) = 0;
533 
539  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
540 
544  virtual void toggleUndoStatus(RObject::Id object) = 0;
545 
546  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
547 
548  //virtual bool getUndoStatus(RObject::Id object) const = 0;
549 
554  virtual int getMaxTransactionId() = 0;
555 
556  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
557 
558  virtual RObject::Id getNewObjectId();
559  virtual RObject::Id getMaxObjectId();
560  virtual RObject::Handle getNewObjectHandle();
561  virtual RObject::Handle getMaxObjectHandle();
562 
563  virtual void setMaxDrawOrder(int m) {
564  maxDrawOrder = m;
565  }
566 
567  virtual int getMaxDrawOrder() {
568  return maxDrawOrder;
569  }
570 
571  virtual int getMinDrawOrder();
572 
577  virtual bool isInBackStorage(RObject::Id /*object*/) {
578  return false;
579  }
580 
581  static QString getKnownVariableName(RS::KnownVariable n);
582 
586  friend QDebug operator<<(QDebug dbg, RStorage& s);
587 
588  void setModified(bool m);
589 
590  bool isModified() const {
591  return modified;
592  }
593 
594  void addModifiedListener(RModifiedListener* l);
595 
596 protected:
597  bool modified;
598 
599 private:
610 
611  QList<RModifiedListener*> modifiedListeners;
612 };
613 
616 
617 #endif