SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Entity.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 #ifndef smtk_model_Entity_h
11 #define smtk_model_Entity_h
12 
13 #include "smtk/CoreExports.h" // for SMTKCORE_EXPORT macro
14 #include "smtk/SystemConfig.h"
15 
16 #include "smtk/resource/Component.h"
17 
18 #include "smtk/model/Arrangement.h" // for Arrangement, ArrangementKind
19 #include "smtk/model/EntityTypeBits.h" // for entityFlags values
20 #include "smtk/model/IntegerData.h" // for IntegerList
21 #include "smtk/model/StringData.h" // for StringList
22 
23 #include <map>
24 #include <set>
25 #include <sstream>
26 #include <string>
27 #include <vector>
28 
29 namespace smtk
30 {
31 namespace model
32 {
33 
46 class SMTKCORE_EXPORT Entity : public smtk::resource::Component
47 {
48  friend class smtk::model::Resource;
49 
50 public:
51  using UUID = smtk::common::UUID;
52  using QueryFunctor = std::function<bool(const smtk::resource::Component&)>;
53  //using ResourcePtr = smtk::resource::ResourcePtr;
54 
58  ~Entity() override;
59 
60  static EntityPtr create(
61  const UUID& uid,
62  BitFlags entityFlags = EntityTypeBits::INVALID,
63  ResourcePtr resource = nullptr);
64  static EntityPtr create(BitFlags entityFlags, int dimension, ResourcePtr resource = nullptr);
65  EntityPtr setup(
66  BitFlags entityFlags,
67  int dimension,
68  ResourcePtr resource = nullptr,
69  bool resetRelations = true);
70 
71  const smtk::resource::ResourcePtr resource() const override;
72  ResourcePtr modelResource() const;
73 
75  EntityPtr owningModel() const;
76 
78  template<typename T>
79  T referenceAs() const
80  {
81  return T(this->modelResource(), this->id());
82  }
83 
84  bool reparent(ResourcePtr newParent);
85 
86  std::string name() const override;
87 
88  int dimension() const;
89  BitFlags dimensionBits() const;
90  BitFlags entityFlags() const;
91  bool setEntityFlags(BitFlags flags);
92 
93  smtk::common::UUIDArray& relations();
94  const smtk::common::UUIDArray& relations() const;
95 
96  int appendRelation(const smtk::common::UUID& b, bool useHoles = true);
97  EntityPtr pushRelation(const smtk::common::UUID& b);
98  EntityPtr removeRelation(const smtk::common::UUID& b);
99  void resetRelations();
100 
101  int findOrAppendRelation(const smtk::common::UUID& r);
102  int invalidateRelation(const smtk::common::UUID& r);
103  int invalidateRelationByIndex(int relIdx);
104 
105  std::string flagSummary(int form = 0) const
106  {
107  return Entity::flagSummary(this->entityFlags(), form);
108  }
109  std::string flagDescription(int form = 0) const
110  {
111  return Entity::flagDescription(this->entityFlags(), form);
112  }
113 
114  static std::string flagDimensionList(BitFlags entityFlags, bool& plural);
115  static std::string flagSummaryHelper(BitFlags entityFlags, int form = 0);
116  static std::string flagSummary(BitFlags entityFlags, int form = 0);
117  static std::string flagDescription(BitFlags entityFlags, int form = 0);
118  static int countForType(BitFlags flags, IntegerList& counters, bool incr = false);
119  static std::string
120  defaultNameFromCounters(BitFlags entityFlags, IntegerList& counters, bool incr = true);
121  static std::string flagToSpecifierString(BitFlags flagsOrMask, bool textual = true);
122  static BitFlags specifierStringToFlag(const std::string& spec);
123  static BitFlags dimensionToDimensionBits(int dim);
124  static int dimensionBitsToDimension(BitFlags dimBits);
125 
126  static QueryFunctor filterStringToQueryFunctor(const std::string& spec);
127 
128  int arrange(ArrangementKind, const Arrangement& arr, int index = -1);
129  int unarrange(ArrangementKind, int index, bool removeIfLast = false);
130  bool clearArrangements();
131 
132  const Arrangements* hasArrangementsOfKind(ArrangementKind) const;
133  Arrangements* hasArrangementsOfKind(ArrangementKind);
134 
135  Arrangements& arrangementsOfKind(ArrangementKind);
136 
137  const Arrangement* findArrangement(ArrangementKind kind, int index) const;
138  Arrangement* findArrangement(ArrangementKind kind, int index);
140  bool findDualArrangements(ArrangementKind kind, int index, ArrangementReferences& duals) const;
141 
142  const KindsToArrangements& arrangementMap() const { return m_arrangements; }
143 
144  const common::UUID& id() const override { return m_id; }
145  bool setId(const common::UUID& uid) override
146  {
147  m_id = uid;
148  return true;
149  }
150 
151  bool isCellEntity() const { return smtk::model::isCellEntity(this->entityFlags()); }
152  bool isUseEntity() const { return smtk::model::isUseEntity(this->entityFlags()); }
153  bool isShellEntity() const { return smtk::model::isShellEntity(this->entityFlags()); }
154  bool isGroup() const { return smtk::model::isGroup(this->entityFlags()); }
155  bool isModel() const { return smtk::model::isModel(this->entityFlags()); }
156  bool isInstance() const { return smtk::model::isInstance(this->entityFlags()); }
157  bool isSessionRef() const { return smtk::model::isSessionRef(this->entityFlags()); }
158  bool isAuxiliaryGeometry() const { return smtk::model::isAuxiliaryGeometry(this->entityFlags()); }
159  bool isConcept() const { return smtk::model::isConcept(this->entityFlags()); }
160 
161  bool isVertex() const { return smtk::model::isVertex(this->entityFlags()); }
162  bool isEdge() const { return smtk::model::isEdge(this->entityFlags()); }
163  bool isFace() const { return smtk::model::isFace(this->entityFlags()); }
164  bool isVolume() const { return smtk::model::isVolume(this->entityFlags()); }
165  bool isChain() const { return smtk::model::isChain(this->entityFlags()); }
166  bool isLoop() const { return smtk::model::isLoop(this->entityFlags()); }
167  bool isShell() const { return smtk::model::isShell(this->entityFlags()); }
168  bool isVertexUse() const { return smtk::model::isVertexUse(this->entityFlags()); }
169  bool isEdgeUse() const { return smtk::model::isEdgeUse(this->entityFlags()); }
170  bool isFaceUse() const { return smtk::model::isFaceUse(this->entityFlags()); }
171  bool isVolumeUse() const { return smtk::model::isVolumeUse(this->entityFlags()); }
172 
173  // Attribute Stuff
176 
177 protected:
178  Entity();
179  int consumeInvalidIndex(const smtk::common::UUID& uid);
180  smtk::model::Resource* rawModelResource() const;
181 
182  BitFlags m_entityFlags{ INVALID };
183  smtk::common::UUIDArray m_relations;
184  smtk::model::WeakResourcePtr m_resource;
185  KindsToArrangements m_arrangements;
186  int m_firstInvalid{ -1 };
187  smtk::common::UUID m_id;
188  mutable smtk::model::Resource* m_rawResource = nullptr;
189 };
190 
192 typedef std::pair<smtk::common::UUID, Entity> UUIDEntityPair;
193 
194 } // namespace model
195 } // namespace smtk
196 
197 #endif // smtk_model_Entity_h
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::model::Entity
A solid model entity, defined by a type and relations to other entities.
Definition: Entity.h:46
smtk::model::Resource::dimension
int dimension(const smtk::common::UUID &ofEntity) const
Return the dimension of the manifold that the passed entity represents.
Definition: Resource.cxx:687
smtk::model::Entity::referenceAs
T referenceAs() const
Return the templated object (usually EntityRef or a subclass) that points to this component.
Definition: Entity.h:79
smtk::attribute::Attributes
std::vector< smtk::attribute::AttributePtr > Attributes
Definition: PublicPointerDefs.h:464
smtk::resource::Resource::name
std::string name() const override
Return the user-assigned name of the resource.
Definition: Resource.cxx:199
smtk::model::Resource::findDualArrangements
bool findDualArrangements(const smtk::common::UUID &entityId, ArrangementKind kind, int index, ArrangementReferences &duals) const
Find the inverse of the given arrangement, if it exists.
Definition: Resource.cxx:2271
smtk::model::BitFlags
unsigned int BitFlags
The integer type used to hold bit values describing an entity's type.
Definition: EntityTypeBits.h:25
smtk::model::INVALID
@ INVALID
The entity is invalid.
Definition: EntityTypeBits.h:169
smtk::resource::Resource::index
virtual Index index() const
index is a compile-time intrinsic of the derived resource; as such, it cannot be set.
Definition: Resource.h:95
smtk::common::UUID
Definition: UUID.h:38
smtk::model::Arrangements
std::vector< smtk::model::Arrangement > Arrangements
A vector of Arrangements is associated to each Manager entity.
Definition: PublicPointerDefs.h:141
StringData.h
smtk::model::Resource::findArrangementInvolvingEntity
int findArrangementInvolvingEntity(const smtk::common::UUID &entityId, ArrangementKind kind, const smtk::common::UUID &involved) const
Find an arrangement of type kind that relates entityId to involvedEntity.
Definition: Resource.cxx:2235
smtk::model::EntityPtr
smtk::shared_ptr< smtk::model::Entity > EntityPtr
Definition: PublicPointerDefs.h:423
smtk::model::KindsToArrangements
std::map< ArrangementKind, Arrangements > KindsToArrangements
A map holding Arrangements of different ArrangementKinds.
Definition: Arrangement.h:171
smtk::model::Resource::findArrangement
const Arrangement * findArrangement(const smtk::common::UUID &entityId, ArrangementKind kind, int index) const
Retrieve arrangement information for a cell.
Definition: Resource.cxx:2194
smtk::model::Resource::clearArrangements
bool clearArrangements(const smtk::common::UUID &entityId)
Erase all arrangements for the given entityId.
Definition: Resource.cxx:2137
smtk::common::UUIDArray
std::vector< smtk::common::UUID > UUIDArray
Definition: PublicPointerDefs.h:35
smtk::model::Resource
Store information about solid models.
Definition: Resource.h:91
smtkTypeMacro
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:128
smtk::model::WeakResourcePtr
smtk::weak_ptr< smtk::model::Resource > WeakResourcePtr
Definition: PublicPointerDefs.h:421
smtk::model::Entity::setId
bool setId(const common::UUID &uid) override
Assign an ID to this object (used by readers; not for arbitrary reuse).
Definition: Entity.h:145
smtk::model::ResourcePtr
smtk::shared_ptr< smtk::model::Resource > ResourcePtr
Definition: PublicPointerDefs.h:419
smtkSharedPtrCreateMacro
#define smtkSharedPtrCreateMacro(...)
A convenience macro for declaring shared_from_this and create methods.
Definition: SharedFromThis.h:267
smtkSuperclassMacro
#define smtkSuperclassMacro(...)
Add a typedef to the superclass of this class.
Definition: SharedFromThis.h:147
smtk::model::Entity::id
const common::UUID & id() const override
Return a unique identifier for the object which will be persistent across sessions.
Definition: Entity.h:144
smtk::resource::Component
Component is the base class for records stored in an smtk::resource::Resource.
Definition: Component.h:43
smtk::model::UUIDEntityPair
std::pair< smtk::common::UUID, Entity > UUIDEntityPair
An abbreviation for the record type used by maps of Entity records.
Definition: Entity.h:192
smtk::model::ArrangementKind
ArrangementKind
Specification of how a cell's relations are arranged.
Definition: ArrangementKind.h:48
smtk::resource::PersistentObject
An abstract base class for SMTK resources and their components.
Definition: PersistentObject.h:39
smtk::resource::ResourcePtr
smtk::shared_ptr< smtk::resource::Resource > ResourcePtr
Definition: PublicPointerDefs.h:295
smtk::model::ArrangementReferences
std::vector< smtk::model::ArrangementReference > ArrangementReferences
An array of ArrangementReference objects used, for instance, to enumerate inverse relations.
Definition: PublicPointerDefs.h:138
smtk::attribute::ConstDefinitionPtr
smtk::shared_ptr< const smtk::attribute::Definition > ConstDefinitionPtr
Definition: PublicPointerDefs.h:452