ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvObject.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // LOCAL
11 #include "CVTypes.h"
12 #include "CV_db.h"
13 #include "ecvColorTypes.h"
14 #include "ecvSerializableObject.h"
15 
16 // QT
17 #include <QSharedPointer>
18 #include <QVariant>
19 
23 public:
24  static constexpr unsigned InvalidUniqueID = 0xFFFFFFFF;
25  static constexpr unsigned MinUniqueID = 0x00000100;
26 
28  using Shared = QSharedPointer<ccUniqueIDGenerator>;
29 
31  ccUniqueIDGenerator() : m_lastUniqueID(MinUniqueID) {}
32 
34  void reset() { m_lastUniqueID = MinUniqueID; }
36  unsigned fetchOne() { return ++m_lastUniqueID; }
38  unsigned getLast() const { return m_lastUniqueID; }
40  void update(unsigned ID) {
41  if (ID > m_lastUniqueID) m_lastUniqueID = ID;
42  }
43 
44 protected:
45  unsigned m_lastUniqueID;
46 };
47 
50 public:
52 
56  ccObject(QString name = QString());
57 
59  ccObject(const ccObject& object);
60 
62  static unsigned GetCurrentDBVersion();
67 
69  virtual CV_CLASS_ENUM getClassID() const = 0;
70 
72  virtual inline QString getName() const { return m_name; }
73 
75  virtual inline void setName(const QString& name) { m_name = name; }
76 
78  virtual inline void setRemoveFlag(bool removeFlag) {
79  m_removeFlag = removeFlag;
80  }
81 
83  virtual inline bool getRemoveFlag() { return m_removeFlag; }
84 
86  virtual inline unsigned getUniqueID() const { return m_uniqueID; }
87 
89 
92  virtual void setUniqueID(unsigned ID);
93 
95 
97  virtual inline bool isEnabled() const { return getFlagState(CC_ENABLED); }
98 
100 
102  virtual inline void setEnabled(bool state) {
103  setFlagState(CC_ENABLED, state);
104  }
105 
107  virtual inline void toggleActivation() { setEnabled(!isEnabled()); }
108 
110 
112  virtual inline bool isLocked() const { return getFlagState(CC_LOCKED); }
113 
115 
117  virtual inline void setLocked(bool state) {
118  setFlagState(CC_LOCKED, state);
119  }
120 
121  // shortcuts
122  inline bool isLeaf() const { return (getClassID() & CC_LEAF_BIT) != 0; }
123  inline bool isCustom() const { return (getClassID() & CC_CUSTOM_BIT) != 0; }
124  inline bool isHierarchy() const {
125  return (getClassID() & CC_HIERARCH_BIT) != 0;
126  }
127 
128  inline bool isKindOf(CV_CLASS_ENUM type) const {
129  return (getClassID() & type) == type;
130  }
131  inline bool isA(CV_CLASS_ENUM type) const { return (getClassID() == type); }
132 
134 
138  static unsigned GetNextUniqueID();
139 
141 
145  static unsigned GetLastUniqueID();
146 
148 
150  static CV_CLASS_ENUM ReadClassIDFromFile(QFile& in, short dataVersion);
151 
153 
156  QVariant getMetaData(const QString& key) const;
157 
159 
162  bool removeMetaData(const QString& key);
163 
165 
168  void setMetaData(const QString& key, const QVariant& data);
169 
171 
175  void setMetaData(const QVariantMap& dataset, bool overwrite = false);
176 
178 
181  bool hasMetaData(const QString& key) const;
182 
184  const QVariantMap& metaData() const { return m_metaData; }
185 
186  inline void setBaseName(const QString& baseName) { m_baseName = baseName; }
187  inline QString getBaseName() const { return m_baseName; }
188 
189  inline void setFullPath(const QString& fullPaht) { m_filePath = fullPaht; }
190  inline QString getFullPath() const { return m_filePath; }
191 
192 protected:
194  virtual inline bool getFlagState(CV_OBJECT_FLAG flag) const {
195  return (m_flags & flag);
196  }
197 
199 
202  virtual void setFlagState(CV_OBJECT_FLAG flag, bool state);
203 
204  // inherited from ccSerializableObject
205  bool toFile(QFile& out, short dataVersion) const override;
206  short minimumFileVersion() const override;
207 
209 
213  bool fromFile(QFile& in,
214  short dataVersion,
215  int flags,
216  LoadedIDMap& oldToNewIDMap) override;
217 
219  QString m_name;
220 
221  QString m_baseName;
222  QString m_filePath;
223 
225 
227  unsigned m_flags;
228 
230  QVariantMap m_metaData;
231 
232 private:
234  unsigned m_uniqueID;
235 };
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CC_HIERARCH_BIT
Definition: CVTypes.h:35
CV_OBJECT_FLAG
Type of a single scalar field value.
Definition: CVTypes.h:28
@ CC_ENABLED
Definition: CVTypes.h:30
@ CC_LOCKED
Definition: CVTypes.h:31
#define CC_CUSTOM_BIT
Definition: CVTypes.h:43
#define CC_LEAF_BIT
Definition: CVTypes.h:36
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
char type
Generic "CLOUDVIEWER Object" template.
Definition: ecvObject.h:49
bool m_removeFlag
Definition: ecvObject.h:224
virtual bool getRemoveFlag()
Returns removeFlag.
Definition: ecvObject.h:83
QString getBaseName() const
Definition: ecvObject.h:187
short minimumFileVersion() const override
Returns the minimum file version required to save this instance.
virtual void setFlagState(CV_OBJECT_FLAG flag, bool state)
Sets flag state.
virtual void setLocked(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:117
const QVariantMap & metaData() const
Returns meta-data map (const only)
Definition: ecvObject.h:184
void setBaseName(const QString &baseName)
Definition: ecvObject.h:186
static unsigned GetLastUniqueID()
Returns last assigned unique ID.
virtual bool isLocked() const
Returns whether the object is locked or not.
Definition: ecvObject.h:112
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual unsigned getUniqueID() const
Returns object unique ID.
Definition: ecvObject.h:86
unsigned m_flags
Object flags.
Definition: ecvObject.h:227
QString m_baseName
Definition: ecvObject.h:221
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
bool isA(CV_CLASS_ENUM type) const
Definition: ecvObject.h:131
void setMetaData(const QVariantMap &dataset, bool overwrite=false)
Sets several meta-data elements at a time.
QVariant getMetaData(const QString &key) const
Returns a given associated meta data.
virtual bool getFlagState(CV_OBJECT_FLAG flag) const
Returns flag state.
Definition: ecvObject.h:194
bool hasMetaData(const QString &key) const
Returns whether a meta-data element with the given key exists or not.
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
QString getFullPath() const
Definition: ecvObject.h:190
static CV_CLASS_ENUM ReadClassIDFromFile(QFile &in, short dataVersion)
Helper: reads out class ID from a binary stream.
void setFullPath(const QString &fullPaht)
Definition: ecvObject.h:189
virtual void setEnabled(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:102
bool isCustom() const
Definition: ecvObject.h:123
bool isHierarchy() const
Definition: ecvObject.h:124
bool isLeaf() const
Definition: ecvObject.h:122
virtual CV_CLASS_ENUM getClassID() const =0
Returns class ID.
ccObject(QString name=QString())
Default constructor.
bool removeMetaData(const QString &key)
Removes a given associated meta-data.
virtual bool isEnabled() const
Returns whether the object is enabled or not.
Definition: ecvObject.h:97
QVariantMap m_metaData
Associated meta-data.
Definition: ecvObject.h:230
virtual void setUniqueID(unsigned ID)
Changes unique ID.
static unsigned GetNextUniqueID()
Returns a new unassigned unique ID.
bool toFile(QFile &out, short dataVersion) const override
Saves data to binary stream.
virtual void setRemoveFlag(bool removeFlag)
Sets removeFlag.
Definition: ecvObject.h:78
bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Reimplemented from ccSerializableObject::fromFile.
static unsigned GetCurrentDBVersion()
Returns current database version.
ccObject(const ccObject &object)
Copy constructor.
bool isKindOf(CV_CLASS_ENUM type) const
Definition: ecvObject.h:128
QString m_filePath
Definition: ecvObject.h:222
static ccUniqueIDGenerator::Shared GetUniqueIDGenerator()
Returns the unique ID generator.
virtual void toggleActivation()
Toggles the "enabled" property.
Definition: ecvObject.h:107
static void SetUniqueIDGenerator(ccUniqueIDGenerator::Shared generator)
Sets the unique ID generator.
QString m_name
Object name.
Definition: ecvObject.h:219
Serializable object interface.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
ccUniqueIDGenerator()
Default constructor.
Definition: ecvObject.h:31
unsigned fetchOne()
Returns a (new) unique ID.
Definition: ecvObject.h:36
void update(unsigned ID)
Updates the value of the last generated unique ID with the current one.
Definition: ecvObject.h:40
void reset()
Resets the unique ID.
Definition: ecvObject.h:34
unsigned m_lastUniqueID
Definition: ecvObject.h:45
unsigned getLast() const
Returns the value of the last generated unique ID.
Definition: ecvObject.h:38
QSharedPointer< ccUniqueIDGenerator > Shared
Shared type.
Definition: ecvObject.h:28