1 // File: Model_AttributeSelectionList.h
2 // Created: 22 Oct 2014
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeSelectionList.h"
6 #include "Model_AttributeSelection.h"
7 #include "Model_Application.h"
8 #include "Model_Events.h"
9 #include "Model_Data.h"
11 #include <TDF_ChildIterator.hxx>
15 void Model_AttributeSelectionList::append(
16 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
18 int aNewTag = mySize->Get() + 1;
19 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
21 std::shared_ptr<Model_AttributeSelection> aNewAttr =
22 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
24 aNewAttr->setObject(owner());
27 aNewAttr->setValue(theContext, theSubShape);
28 owner()->data()->sendAttributeUpdated(this);
31 int Model_AttributeSelectionList::size()
36 int Model_AttributeSelectionList::selectionType()
38 return (int) mySelectionType->Get();
41 void Model_AttributeSelectionList::setSelectionType(int theType)
43 mySelectionType->Set((double) theType);
46 std::shared_ptr<ModelAPI_AttributeSelection>
47 Model_AttributeSelectionList::value(const int theIndex)
49 TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1);
50 // create a new attribute each time, by demand
51 // supporting of old attributes is too slow (synch each time) and buggy on redo
52 // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid)
53 std::shared_ptr<Model_AttributeSelection> aNewAttr =
54 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLabel));
56 aNewAttr->setObject(owner());
61 void Model_AttributeSelectionList::clear()
63 if (mySize->Get() != 0) {
65 TDF_ChildIterator aSubIter(mySize->Label());
66 for(; aSubIter.More(); aSubIter.Next()) {
67 aSubIter.Value().ForgetAllAttributes(Standard_True);
69 owner()->data()->sendAttributeUpdated(this);
73 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
75 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
76 if (!myIsInitialized) {
77 mySize = TDataStd_Integer::Set(theLabel, 0);
78 mySelectionType = TDataStd_Real::Set(theLabel, 0);
79 } else { // recollect mySubs
80 theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);