+AttributePtr Model_Data::addFloatingAttribute(
+ const std::string& theID, const std::string theAttrType, const std::string& theGroup)
+{
+ // compute the index of the attribute placement
+ int anIndex;
+ TDF_Label aLab;
+ if (myLab.IsAttribute(TDF_TagSource::GetID())) {
+ // check this is re-init of attributes, so, check attribute with this name already there
+ TDF_ChildIDIterator anIter(myLab, kGroupAttributeID, false);
+ for(; anIter.More(); anIter.Next()) {
+ TCollection_AsciiString aThisName(Handle(TDataStd_Name)::DownCast(anIter.Value())->Get());
+ if (theID == aThisName.ToCString()) {
+ TDF_Label aChildLab = anIter.Value()->Label();
+ Handle(TDataStd_Name) aGName;
+ if (aChildLab.FindAttribute(kGroupAttributeGroupID, aGName)) {
+ TCollection_AsciiString aGroupName(aGName->Get());
+ if (theGroup == aGroupName.ToCString()) {
+ return addAttribute(theGroup + "__" + theID, theAttrType, aChildLab.Tag());
+ }
+ }
+ }
+ }
+ aLab = myLab.NewChild(); // already exists a floating attribute, create the next
+ anIndex = aLab.Tag();
+ } else { // put the first floating attribute, quite far from other standard attributes
+ anIndex = int(myAttrs.size()) + 1000;
+ TDF_TagSource::Set(myLab)->Set(anIndex);
+ aLab = myLab.FindChild(anIndex, true);
+ }
+ // store the group ID and the attribute ID (to restore correctly)
+ TDataStd_Name::Set(aLab, kGroupAttributeGroupID, theGroup.c_str());
+ TDataStd_Name::Set(aLab, kGroupAttributeID, theID.c_str());
+
+ return addAttribute(theGroup + "__" + theID, theAttrType, anIndex);
+}
+
+void Model_Data::allGroups(std::list<std::string>& theGroups)
+{
+ std::set<std::string> alreadyThere;
+ for(TDF_ChildIDIterator aGroup(myLab, kGroupAttributeGroupID); aGroup.More(); aGroup.Next()) {
+ Handle(TDataStd_Name) aGroupAttr = Handle(TDataStd_Name)::DownCast(aGroup.Value());
+ std::string aGroupID = TCollection_AsciiString(aGroupAttr->Get()).ToCString();
+ if (alreadyThere.find(aGroupID) == alreadyThere.end()) {
+ theGroups.push_back(aGroupID);
+ alreadyThere.insert(aGroupID);
+ }
+ }
+}
+
+void Model_Data::attributesOfGroup(const std::string& theGroup,
+ std::list<std::shared_ptr<ModelAPI_Attribute> >& theAttrs)
+{
+ for(TDF_ChildIDIterator aGroup(myLab, kGroupAttributeGroupID); aGroup.More(); aGroup.Next()) {
+ Handle(TDataStd_Name) aGroupID = Handle(TDataStd_Name)::DownCast(aGroup.Value());
+ if (aGroupID->Get().IsEqual(theGroup.c_str())) {
+ Handle(TDataStd_Name) anID;
+ if (aGroup.Value()->Label().FindAttribute(kGroupAttributeID, anID)) {
+ TCollection_AsciiString anAsciiID(aGroupID->Get() + "__" + anID->Get());
+ theAttrs.push_back(attribute(anAsciiID.ToCString()));
+ }
+ }
+ }
+}
+
+void Model_Data::removeAttributes(const std::string& theGroup)
+{
+ TDF_LabelList aLabsToRemove; // collect labels that must be erased after the cycle
+ for(TDF_ChildIDIterator aGroup(myLab, kGroupAttributeGroupID); aGroup.More(); aGroup.Next()) {
+ Handle(TDataStd_Name) aGroupID = Handle(TDataStd_Name)::DownCast(aGroup.Value());
+ if (aGroupID->Get().IsEqual(theGroup.c_str())) {
+ Handle(TDataStd_Name) anID;
+ if (!aGroup.Value()->Label().IsNull() &&
+ aGroup.Value()->Label().FindAttribute(kGroupAttributeID, anID)) {
+ aLabsToRemove.Append(aGroup.Value()->Label());
+ }
+ TCollection_AsciiString anAsciiID(aGroupID->Get() + "__" + anID->Get());
+ myAttrs.erase(anAsciiID.ToCString());
+ }
+ }
+ for(TDF_LabelList::Iterator aLab(aLabsToRemove); aLab.More(); aLab.Next()) {
+ aLab.ChangeValue().ForgetAllAttributes(true);
+ }
+}
+
+void Model_Data::clearAttributes()
+{
+ myAttrs.clear();
+}
+
+
+