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>
17 void Model_AttributeSelectionList::append(
18 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
20 int aNewTag = mySize->Get() + 1;
21 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
23 std::shared_ptr<Model_AttributeSelection> aNewAttr =
24 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
26 aNewAttr->setObject(owner());
29 aNewAttr->setValue(theContext, theSubShape);
30 owner()->data()->sendAttributeUpdated(this);
33 int Model_AttributeSelectionList::size()
38 int Model_AttributeSelectionList::selectionType()
40 return (int) mySelectionType->Get();
43 void Model_AttributeSelectionList::setSelectionType(int theType)
45 mySelectionType->Set((double) theType);
48 std::shared_ptr<ModelAPI_AttributeSelection>
49 Model_AttributeSelectionList::value(const int theIndex)
51 TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1);
52 // create a new attribute each time, by demand
53 // supporting of old attributes is too slow (synch each time) and buggy on redo
54 // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid)
55 std::shared_ptr<Model_AttributeSelection> aNewAttr =
56 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLabel));
58 aNewAttr->setObject(owner());
63 void Model_AttributeSelectionList::clear()
65 if (mySize->Get() != 0) {
67 TDF_ChildIterator aSubIter(mySize->Label());
68 for(; aSubIter.More(); aSubIter.Next()) {
69 aSubIter.Value().ForgetAllAttributes(Standard_True);
71 owner()->data()->sendAttributeUpdated(this);
75 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
77 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
78 if (!myIsInitialized) {
79 mySize = TDataStd_Integer::Set(theLabel, 0);
80 mySelectionType = TDataStd_Real::Set(theLabel, 0);
81 } else { // recollect mySubs
82 theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);