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 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType();
48 case TopAbs_VERTEX: aTypeName = "VERT"; break;
49 case TopAbs_EDGE: aTypeName = "EDGE"; break;
50 case TopAbs_WIRE: aTypeName = "WIRE"; break;
51 case TopAbs_FACE: aTypeName = "FACE"; break;
52 case TopAbs_SHELL: aTypeName = "SHEL"; break;
53 case TopAbs_SOLID: aTypeName = "SOLD"; break;
54 case TopAbs_COMPOUND: aTypeName = "COMP"; break;
55 case TopAbs_COMPSOLID: aTypeName = "COMS"; break;
57 return; // invalid case => empty new attribute
59 aNewAttr->selectSubShape(aTypeName, theNamingName);
60 owner()->data()->sendAttributeUpdated(this);
63 int Model_AttributeSelectionList::size()
68 int Model_AttributeSelectionList::selectionType()
70 return (int) mySelectionType->Get();
73 void Model_AttributeSelectionList::setSelectionType(int theType)
75 mySelectionType->Set((double) theType);
78 std::shared_ptr<ModelAPI_AttributeSelection>
79 Model_AttributeSelectionList::value(const int theIndex)
81 TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1);
82 // create a new attribute each time, by demand
83 // supporting of old attributes is too slow (synch each time) and buggy on redo
84 // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid)
85 std::shared_ptr<Model_AttributeSelection> aNewAttr =
86 std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLabel));
88 aNewAttr->setObject(owner());
93 void Model_AttributeSelectionList::clear()
95 if (mySize->Get() != 0) {
97 TDF_ChildIterator aSubIter(mySize->Label());
98 for(; aSubIter.More(); aSubIter.Next()) {
99 aSubIter.Value().ForgetAllAttributes(Standard_True);
101 owner()->data()->sendAttributeUpdated(this);
105 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
107 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
108 if (!myIsInitialized) {
109 mySize = TDataStd_Integer::Set(theLabel, 0);
110 mySelectionType = TDataStd_Real::Set(theLabel, 0);
111 } else { // recollect mySubs
112 theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);