10 #ifndef smtk_model_EntityRef_h
11 #define smtk_model_EntityRef_h
14 #include "smtk/CoreExports.h"
16 #include "smtk/SystemConfig.h"
18 #include "smtk/common/UUID.h"
20 #include "smtk/model/Arrangement.h"
21 #include "smtk/model/AttributeAssignments.h"
22 #include "smtk/model/Entity.h"
23 #include "smtk/model/EntityTypeBits.h"
24 #include "smtk/model/Events.h"
25 #include "smtk/model/FloatData.h"
26 #include "smtk/model/IntegerData.h"
43 #define SMTK_ENTITYREF_CLASS(thisclass, superclass, typecheck) \
44 SMTK_DERIVED_TYPE(thisclass, superclass); \
46 thisclass(const EntityRef& other) \
50 thisclass(smtk::model::ResourcePtr inResource, const smtk::common::UUID& entityId) \
51 : superclass(inResource, entityId) \
54 thisclass(EntityPtr src) \
58 m_resource = src->modelResource(); \
59 m_entity = src->id(); \
62 ~thisclass() override = default; \
63 bool isValid() const { return this->EntityRef::isValid(); } \
64 bool isValid(EntityPtr* entRec) const override \
69 this->EntityRef::isValid(&er) && er && smtk::model::typecheck(er->entityFlags())) \
89 typedef std::vector<Group> Groups;
113 class SMTKCORE_EXPORT EntityRef
116 SMTK_BASE_TYPE(EntityRef);
121 virtual ~EntityRef() =
default;
133 int dimension()
const;
134 int dimensionBits()
const;
135 void setDimensionBits(
BitFlags dim);
137 std::string flagSummary(
int form = 0)
const;
139 int maxParametricDimension()
const;
141 int embeddingDimension()
const;
143 std::string name()
const;
144 void setName(
const std::string& n);
145 std::string assignDefaultName(
bool overwrite =
false);
147 bool hasVisibility()
const;
148 bool visible()
const;
149 void setVisible(
bool vis);
161 FloatList color()
const;
162 bool hasColor()
const;
163 void setColor(
const FloatList& rgba);
164 void setColor(
double r,
double g,
double b,
double a = 1.);
166 bool isValid()
const;
167 virtual bool isValid(
EntityPtr* entityRecord)
const;
170 bool isCellEntity()
const {
return smtk::model::isCellEntity(this->entityFlags()); }
171 bool isUseEntity()
const {
return smtk::model::isUseEntity(this->entityFlags()); }
172 bool isShellEntity()
const {
return smtk::model::isShellEntity(this->entityFlags()); }
173 bool isGroup()
const {
return smtk::model::isGroup(this->entityFlags()); }
174 bool isModel()
const {
return smtk::model::isModel(this->entityFlags()); }
175 bool isInstance()
const {
return smtk::model::isInstance(this->entityFlags()); }
176 bool isSessionRef()
const {
return smtk::model::isSessionRef(this->entityFlags()); }
177 bool isAuxiliaryGeometry()
const {
return smtk::model::isAuxiliaryGeometry(this->entityFlags()); }
178 bool isConcept()
const {
return smtk::model::isConcept(this->entityFlags()); }
180 bool isVertex()
const {
return smtk::model::isVertex(this->entityFlags()); }
181 bool isEdge()
const {
return smtk::model::isEdge(this->entityFlags()); }
182 bool isFace()
const {
return smtk::model::isFace(this->entityFlags()); }
183 bool isVolume()
const {
return smtk::model::isVolume(this->entityFlags()); }
184 bool isChain()
const {
return smtk::model::isChain(this->entityFlags()); }
185 bool isLoop()
const {
return smtk::model::isLoop(this->entityFlags()); }
186 bool isShell()
const {
return smtk::model::isShell(this->entityFlags()); }
187 bool isVertexUse()
const {
return smtk::model::isVertexUse(this->entityFlags()); }
188 bool isEdgeUse()
const {
return smtk::model::isEdgeUse(this->entityFlags()); }
189 bool isFaceUse()
const {
return smtk::model::isFaceUse(this->entityFlags()); }
190 bool isVolumeUse()
const {
return smtk::model::isVolumeUse(this->entityFlags()); }
204 template<
typename S,
typename T>
205 static void EntityRefsFromUUIDs(S& result,
ResourcePtr,
const T& uids);
207 template<
typename S,
typename T>
208 static void EntityRefsToUUIDs(S& uids,
const T& entRefs);
210 EntityRefs bordantEntities(
int ofDimension = -2)
const;
211 EntityRefs boundaryEntities(
int ofDimension = -2)
const;
213 std::vector<double> boundingBox()
const;
214 std::vector<double> unionBoundingBox(
const std::vector<double>& b1,
const std::vector<double>& b2)
216 std::vector<double> unionBoundingBox(
217 const std::vector<double>& b1,
218 const std::array<double, 6>& b2)
const;
220 EntityRefs lowerDimensionalBoundaries(
int lowerDimension);
221 EntityRefs higherDimensionalBordants(
int higherDimension);
225 T relationsAs()
const;
237 int setTessellation(
const Tessellation* tess,
int analysisMesh = 0,
bool updateBBox =
false);
238 int setTessellationAndBoundingBox(
const Tessellation* tess,
int analysisMesh = 0)
240 return this->setTessellation(tess, analysisMesh,
true);
242 bool removeTessellation(
bool removeGen =
false);
243 void findEntitiesWithTessellation(
244 std::map<smtk::model::EntityRef, smtk::model::EntityRef>& entityrefMap,
245 std::set<smtk::model::EntityRef>& touched)
const;
246 int tessellationGeneration()
const;
247 bool setTessellationGeneration(
int gen);
248 void setBoundingBox(
const double bbox[6]);
250 bool hasAttributes()
const;
253 bool associateAttribute(
256 bool disassociateAttribute(
259 bool disassociateAttribute(
267 bool disassociateAttributes(
const T& attribPtrs)
269 bool removedAny =
false;
270 for (
const auto& attribPtr : attribPtrs)
272 removedAny |= this->disassociateAttribute(attribPtr->attributeResource(), attribPtr->id());
286 bool removeProperty(
const std::string& name);
288 void setFloatProperty(
const std::string& propName, smtk::model::Float propValue);
289 void setFloatProperty(
const std::string& propName,
const smtk::model::FloatList& propValue);
290 smtk::model::FloatList
const& floatProperty(
const std::string& propName)
const;
291 smtk::model::FloatList& floatProperty(
const std::string& propName);
292 bool hasFloatProperty(
const std::string& propName)
const;
293 bool removeFloatProperty(
const std::string& propName);
294 bool hasFloatProperties()
const;
295 std::set<std::string> floatPropertyNames()
const;
301 bool hasStringProperty(
const std::string& propName)
const;
302 bool removeStringProperty(
const std::string& propName);
303 bool hasStringProperties()
const;
304 std::set<std::string> stringPropertyNames()
const;
306 void setIntegerProperty(
const std::string& propName, smtk::model::Integer propValue);
307 void setIntegerProperty(
const std::string& propName,
const smtk::model::IntegerList& propValue);
308 smtk::model::IntegerList
const& integerProperty(
const std::string& propName)
const;
309 smtk::model::IntegerList& integerProperty(
const std::string& propName);
310 bool hasIntegerProperty(
const std::string& propName)
const;
311 bool removeIntegerProperty(
const std::string& propName);
312 bool hasIntegerProperties()
const;
313 std::set<std::string> integerPropertyNames()
const;
318 bool clearArrangements();
327 EntityRef& embedEntities(
const T& container,
bool checkExistence =
true);
330 bool unembedEntity(
const EntityRef& thingToUnembed);
332 EntityRef& unembedEntities(
const T& container);
334 T embeddedEntities()
const;
339 Model owningModel()
const;
341 Groups containingGroups()
const;
343 bool isMember(
const EntityRef& entity)
const;
346 bool operator==(
const EntityRef& other)
const;
347 bool operator!=(
const EntityRef& other)
const;
348 bool operator<(
const EntityRef& other)
const;
350 operator bool()
const {
return this->isValid(); }
352 std::size_t hash()
const;
357 friend class SessionRef;
363 EntityRef& addMemberEntity(
const EntityRef& memberToAdd);
365 EntityRef& addMemberEntities(T begin, T end);
366 EntityRef& removeMemberEntity(
const EntityRef& memberToRemove);
367 EntityRef& removeMemberEntity(
int indexOfMemberToRemove);
369 EntityRef& removeMemberEntities(T begin, T end);
375 SMTKCORE_EXPORT std::ostream&
operator<<(std::ostream& os,
const EntityRef& c);
377 SMTKCORE_EXPORT std::size_t entityrefHash(
const EntityRef& c);
388 smtk::common::UUIDArray::const_iterator it;
389 for (it = entRec->relations().begin(); it != entRec->relations().end(); ++it)
391 typename T::value_type entry(mgr, *it);
394 result.insert(result.end(), entry);
400 template<
typename S,
typename T>
403 for (
typename T::const_iterator it = uids.begin(); it != uids.end(); ++it)
405 typename S::value_type entry(mgr, *it);
408 result.insert(result.end(), entry);
413 template<
typename S,
typename T>
414 void EntityRef::EntityRefsToUUIDs(S& uids,
const T& entRefs)
416 for (
typename T::const_iterator it = entRefs.begin(); it != entRefs.end(); ++it)
420 uids.insert(uids.end(), it->entity());
428 for (
typename T::const_iterator it = container.begin(); it != container.end(); ++it)
436 EntityRef& EntityRef::unembedEntities(
const T& container)
438 for (
typename T::const_iterator it = container.begin(); it != container.end(); ++it)
446 EntityRef& EntityRef::addMemberEntities(T begin, T end)
448 for (T it = begin; it != end; ++it)
454 EntityRef& EntityRef::removeMemberEntities(T begin, T end)
456 for (T it = begin; it != end; ++it)