/**************************************************************************** ** Copyright (c) 2021, Fougue Ltd. ** All rights reserved. ** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt ****************************************************************************/ #pragma once #include "occ_handle.h" #include #include #include #include #include namespace Mayo { // Provides helper functions for OpenCascade CAF related libraries struct CafUtils { // Returns a string representation of tag list path to 'label' static const TCollection_AsciiString& labelTag(const TDF_Label& label); // Returns the name attribute(if any) attached to 'label' // Empty string is returned if no name attribute static const TCollection_ExtendedString& labelAttrStdName(const TDF_Label& label); // Is 'label' null or empty(ie no attributes)? static bool isNullOrEmpty(const TDF_Label& label); // Returns attribute of type 'AttributeType'(result may be null)? template static OccHandle findAttribute(const TDF_Label& label); // Is there an attribute of identifier 'attrGuid' attached to 'label'? static bool hasAttribute(const TDF_Label& label, const Standard_GUID& attrGuid); // Is there an attribute of type 'AttributeType' attached to 'label'? template static bool hasAttribute(const TDF_Label& label); // Returns a TDF_LabelSequence object built from initializer list static TDF_LabelSequence makeLabelSequence(std::initializer_list listLabel); }; } // namespace Mayo #if OCC_VERSION_HEX < 0x070800 #include namespace std { // Specialization of C++11 std::hash<> functor for TDF_Label template<> struct hash { inline size_t operator()(const TDF_Label& lbl) const { return TDF_LabelMapHasher::HashCode(lbl, INT_MAX); } }; } // namespace std #endif // -- // -- Implementation // -- namespace Mayo { template OccHandle CafUtils::findAttribute(const TDF_Label& label) { OccHandle attr; label.FindAttribute(AttributeType::GetID(), attr); return attr; } template bool CafUtils::hasAttribute(const TDF_Label& label) { return hasAttribute(label, AttributeType::GetID()); } } // namespace Mayo