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, RS::EntityType type = RS::EntityAll) = 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 
162  virtual QSet<REntity::Id> queryInfiniteEntities() = 0;
163 
168  virtual QSharedPointer<RObject> queryObject(RObject::Id objectId) const = 0;
169 
170  virtual QSharedPointer<RObject> queryObjectDirect(RObject::Id objectId) const {
171  return queryObject(objectId);
172  }
173  virtual QSharedPointer<RObject> queryObjectByHandle(RObject::Handle objectHandle) const = 0;
174 
179  virtual QSharedPointer<REntity> queryEntity(REntity::Id entityId) const = 0;
180 
181  virtual QSharedPointer<REntity> queryEntityDirect(REntity::Id entityId) const {
182  return queryEntity(entityId);
183  }
184 
189  virtual QSharedPointer<RUcs> queryUcs(RUcs::Id ucsId) const = 0;
190 
191  virtual QSharedPointer<RUcs> queryUcsDirect(RUcs::Id ucsId) const {
192  return queryUcs(ucsId);
193  }
194 
199  virtual QSharedPointer<RUcs> queryUcs(const QString& ucsName) const = 0;
200 
205  virtual QSharedPointer<RLayer> queryLayer(RLayer::Id layerId) const = 0;
206 
207  virtual QSharedPointer<RLayer> queryLayerDirect(RLayer::Id layerId) const {
208  return queryLayer(layerId);
209  }
210 
215  virtual QSharedPointer<RLayer> queryLayer(const QString& layerName) const = 0;
216 
217  virtual QSharedPointer<RLayer> queryCurrentLayer() {
218  return queryLayer(getCurrentLayerId());
219  }
220 
221  virtual QSharedPointer<RView> queryCurrentView() {
222  return queryView(getCurrentViewId());
223  }
224 
225  virtual QSharedPointer<RLinetype> queryLinetype(RLinetype::Id linetypeId) const = 0;
226 
227  virtual QSharedPointer<RLinetype> queryLinetype(const QString& linetypeName) const = 0;
228 
229  virtual QSharedPointer<RBlock> queryBlock(RBlock::Id blockId) const = 0;
230  virtual QSharedPointer<RBlock> queryBlockDirect(RBlock::Id blockId) const = 0;
231  virtual QSharedPointer<RBlock> queryBlock(const QString& blockName) const = 0;
232 
233  virtual QSharedPointer<RView> queryView(RView::Id viewId) const = 0;
234  virtual QSharedPointer<RView> queryView(const QString& viewName) const = 0;
235 
236  void setCurrentLayer(RLayer::Id layerId) {
237  //setVariable("CurrentLayer", layerId);
238  currentLayerId = layerId;
239  }
240 
241  void setCurrentLayer(const QString& layerName) {
242  RLayer::Id id = getLayerId(layerName);
243  if (id == RLayer::INVALID_ID) {
244  return;
245  }
246  setCurrentLayer(id);
247  }
248 
250  //return (RLayer::Id) getVariable("CurrentLayer").toInt();
251  return currentLayerId;
252  }
253 
255  //return (RView::Id) getVariable("CurrentView").toInt();
256  return currentViewId;
257  }
258 
259  virtual void setCurrentColor(const RColor& color);
260  virtual RColor getCurrentColor();
261 
262  void setCurrentLineweight(RLineweight::Lineweight lw);
263  virtual RLineweight::Lineweight getCurrentLineweight() const;
264 
265  void setCurrentLinetype(RLinetype lt);
266  virtual RLinetype getCurrentLinetype() const;
267 
268  virtual QSharedPointer<RBlock> queryCurrentBlock() {
269  return queryBlock(getCurrentBlockId());
270  }
271 
272  virtual void setCurrentBlock(RBlock::Id blockId) {
273  //setVariable("CurrentBlock", blockId);
274  currentBlockId = blockId;
275  }
276 
277  void setCurrentBlock(const QString& blockName) {
278  RBlock::Id id = getBlockId(blockName);
279  if (id == RBlock::INVALID_ID) {
280  return;
281  }
282  setCurrentBlock(id);
283  }
284 
285  virtual RBlock::Id getCurrentBlockId() const {
286  //return (RBlock::Id) getVariable("CurrentBlock").toInt();
287  return currentBlockId;
288  }
289 
290  void setCurrentView(RView::Id viewId) {
291  //setVariable("CurrentView", viewId);
292  currentViewId = viewId;
293  }
294 
295  void setCurrentView(const QString& viewName) {
296  RView::Id id = getViewId(viewName);
297  // unlike blocks and layers, the current view can be invalid:
298  setCurrentView(id);
299  }
300 
301  virtual RView::Id getCurrentViewId() const {
302  //return (RView::Id) getVariable("CurrentView").toInt();
303  return currentViewId;
304  }
305 
306  virtual void setUnit(RS::Unit unit);
307  virtual RS::Unit getUnit() const;
308 
309  virtual void setDimensionFont(const QString& f);
310  virtual QString getDimensionFont() const;
311 
312  virtual void setLinetypeScale(double v);
313  virtual double getLinetypeScale() const;
314 
315  virtual QString getBlockName(RBlock::Id blockId) const = 0;
316  virtual QSet<QString> getBlockNames() const = 0;
317  virtual RBlock::Id getBlockId(const QString& blockName) const = 0;
318  virtual bool hasBlock(const QString& blockName) const;
319 
320  virtual QString getViewName(RView::Id viewId) const = 0;
321  virtual QSet<QString> getViewNames() const = 0;
322  virtual RView::Id getViewId(const QString& viewName) const = 0;
323  virtual bool hasView(const QString& viewName) const;
324 
325  virtual QString getLayerName(RLayer::Id layerId) const = 0;
326  virtual QSet<QString> getLayerNames() const = 0;
327  virtual RLayer::Id getLayerId(const QString& layerName) const = 0;
328  virtual bool hasLayer(const QString& layerName) const;
329 
330  virtual QString getLinetypeName(RLinetype::Id linetypeId) const = 0;
331  virtual QSet<QString> getLinetypeNames() const = 0;
332  virtual RLinetype::Id getLinetypeId(const QString& linetypeName) const = 0;
333  virtual bool hasLinetype(const QString& linetypeName) const;
334 
335  virtual QStringList getVariables() const = 0;
336  virtual void setVariable(const QString& key, const QVariant& value, bool overwrite=true) = 0;
341  virtual QVariant getVariable(const QString& key) const = 0;
342 
346  virtual bool hasVariable(const QString& key) const {
347  QVariant value = getVariable(key);
348  return value.isValid();
349  }
350 
351  virtual void setKnownVariable(RS::KnownVariable key, const QVariant& value) = 0;
352  virtual QVariant getKnownVariable(RS::KnownVariable key) const = 0;
353 
357  virtual void clearEntitySelection(
358  QSet<REntity::Id>* affectedEntities=NULL
359  ) = 0;
360 
364  virtual void selectAllEntites(QSet<REntity::Id>* affectedEntities = NULL) = 0;
365 
375  virtual void selectEntity(
376  REntity::Id entityId,
377  bool add=false,
378  QSet<REntity::Id>* affectedEntities=NULL
379  ) = 0;
380 
390  virtual void selectEntities(
391  const QSet<REntity::Id>& entityIds,
392  bool add=false,
393  QSet<REntity::Id>* affectedEntities=NULL
394  ) = 0;
395 
403  virtual void deselectEntity(
404  REntity::Id entityId,
405  QSet<REntity::Id>* affectedEntities=NULL
406  ) = 0;
407 
415  virtual void deselectEntities(
416  const QSet<REntity::Id>& entityIds,
417  QSet<REntity::Id>* affectedEntities=NULL
418  ) = 0;
419 
420  virtual bool isSelected(REntity::Id entityId) {
421  QSharedPointer<REntity> e = queryEntityDirect(entityId);
422  return (!e.isNull() && e->isSelected());
423  }
424 
425  virtual bool isEntity(RObject::Id objectId) {
426  QSharedPointer<REntity> e = queryEntityDirect(objectId);
427  return !e.isNull();
428  }
429 
430  virtual bool isLayerLocked(RLayer::Id layerId) const {
431  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
432  if (l.isNull()) {
433  return false;
434  }
435  return l->isLocked();
436  }
437 
438  virtual bool isLayerFrozen(RLayer::Id layerId) const {
439  QSharedPointer<RLayer> l = queryLayerDirect(layerId);
440  if (l.isNull()) {
441  return false;
442  }
443  return l->isFrozen();
444  }
445 
446  virtual bool isBlockFrozen(RBlock::Id blockId) const {
447  QSharedPointer<RBlock> b = queryBlockDirect(blockId);
448  if (b.isNull()) {
449  return false;
450  }
451  return b->isFrozen();
452  }
453 
454  void setObjectId(RObject& object, RObject::Id objectId);
455  void setObjectHandle(RObject& object, RObject::Handle objectHandle);
456 
460  virtual bool hasSelection() const = 0;
461 
465  virtual RBox getBoundingBox(bool includeHiddenLayer = true) const = 0;
466 
467  virtual RBox getSelectionBox() const = 0;
468 
469  virtual bool removeObject(QSharedPointer<RObject> object) = 0;
470 
474  virtual bool saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion = true, bool keepHandles = false) = 0;
475 
479  virtual bool deleteObject(RObject::Id objectId) = 0;
480 
485  virtual int getLastTransactionId() {
486  //return getVariable("LastTransaction").toInt();
487  return lastTransactionId;
488  }
489 
496  virtual void setLastTransactionId(int transactionId) {
497  //setVariable("LastTransaction", transactionId);
498  lastTransactionId = transactionId;
499 
500  setModified(true);
501  }
502 
507  virtual void saveTransaction(RTransaction& transaction) = 0;
508 
515  virtual void deleteTransactionsFrom(int transactionId) = 0;
516 
517  virtual void resetTransactionStack() = 0;
518 
522  virtual RTransaction getTransaction(int transactionId) = 0;
523 
529  virtual void toggleUndoStatus(QSet<RObject::Id>& objects) = 0;
530 
534  virtual void toggleUndoStatus(RObject::Id object) = 0;
535 
536  virtual bool setUndoStatus(RObject::Id object, bool status) = 0;
537 
538  //virtual bool getUndoStatus(RObject::Id object) const = 0;
539 
544  virtual int getMaxTransactionId() = 0;
545 
546  virtual RLineweight::Lineweight getMaxLineweight() const = 0;
547 
548  virtual RObject::Id getNewObjectId();
549  virtual RObject::Id getMaxObjectId();
550  virtual RObject::Handle getNewObjectHandle();
551  virtual RObject::Handle getMaxObjectHandle();
552 
553  virtual void setMaxDrawOrder(int m) {
554  maxDrawOrder = m;
555  }
556 
557  virtual int getMaxDrawOrder() {
558  return maxDrawOrder;
559  }
560 
561  virtual int getMinDrawOrder();
562 
567  virtual bool isInBackStorage(RObject::Id /*object*/) {
568  return false;
569  }
570 
571  static QString getKnownVariableName(RS::KnownVariable n);
572 
576  friend QDebug operator<<(QDebug dbg, RStorage& s);
577 
578  void setModified(bool m);
579 
580  bool isModified() const {
581  return modified;
582  }
583 
584  void addModifiedListener(RModifiedListener* l);
585 
586 protected:
587  bool modified;
588 
589 private:
600 
601  QList<RModifiedListener*> modifiedListeners;
602 };
603 
606 
607 #endif