1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeSelectionList.h
4 // Created: 22 Oct 2014
5 // Author: Mikhail PONIKAROV
7 #include "Model_AttributeSelectionList.h"
8 #include "Model_AttributeSelection.h"
9 #include "Model_Application.h"
10 #include "Model_Events.h"
11 #include "Model_Data.h"
13 #include <TDF_ChildIterator.hxx>
14 #include <TopAbs_ShapeEnum.hxx>
18 void Model_AttributeSelectionList::append(
19 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
21 int aNewTag = mySize->Get() + 1;
22 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
24 std::shared_ptr<Model_AttributeSelection> aNewAttr =
25 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
27 aNewAttr->setObject(owner());
30 aNewAttr->setValue(theContext, theSubShape);
31 owner()->data()->sendAttributeUpdated(this);
34 void Model_AttributeSelectionList::append(std::string theNamingName)
36 int aNewTag = mySize->Get() + 1;
37 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
39 std::shared_ptr<Model_AttributeSelection> aNewAttr =
40 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
42 aNewAttr->setObject(owner());
45 aNewAttr->selectSubShape(selectionType(), theNamingName);
46 owner()->data()->sendAttributeUpdated(this);
49 int Model_AttributeSelectionList::size()
54 const std::string Model_AttributeSelectionList::selectionType() const
56 return TCollection_AsciiString(mySelectionType->Get()).ToCString();
59 void Model_AttributeSelectionList::setSelectionType(const std::string& theType)
61 mySelectionType->Set(theType.c_str());
64 std::shared_ptr<ModelAPI_AttributeSelection>
65 Model_AttributeSelectionList::value(const int theIndex)
67 TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1);
68 // create a new attribute each time, by demand
69 // supporting of old attributes is too slow (synch each time) and buggy on redo
70 // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid)
71 std::shared_ptr<Model_AttributeSelection> aNewAttr =
72 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLabel));
74 aNewAttr->setObject(owner());
79 void Model_AttributeSelectionList::clear()
81 if (mySize->Get() != 0) {
83 TDF_ChildIterator aSubIter(mySize->Label());
84 for(; aSubIter.More(); aSubIter.Next()) {
85 aSubIter.Value().ForgetAllAttributes(Standard_True);
87 owner()->data()->sendAttributeUpdated(this);
91 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
93 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
94 if (!myIsInitialized) {
95 mySize = TDataStd_Integer::Set(theLabel, 0);
96 mySelectionType = TDataStd_Comment::Set(theLabel, "");
97 } else { // recollect mySubs
98 theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);