1 // File: Model_Object.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_Object.h>
6 #include <Model_AttributeDocRef.h>
7 #include <TDataStd_Name.hxx>
11 Model_Object::Model_Object()
15 void Model_Object::setLabel(TDF_Label& theLab)
20 string Model_Object::getName()
22 Handle(TDataStd_Name) aName;
23 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
24 return string(TCollection_AsciiString(aName->Get()).ToCString());
25 return ""; // not defined
28 void Model_Object::setName(string theName)
30 TDataStd_Name::Set(myLab, theName.c_str());
33 void Model_Object::addAttribute(string theID, string theAttrType)
35 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
36 ModelAPI_Attribute* anAttr = 0;
37 if (theAttrType == ModelAPI_AttributeDocRef::type())
38 anAttr = new Model_AttributeDocRef(anAttrLab);
40 myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
42 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
45 shared_ptr<ModelAPI_AttributeDocRef> Model_Object::docRef(const string theID)
47 map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
48 if (aFound == myAttrs.end()) {
49 // TODO: generate error on unknown attribute request and/or add mechanism for customization
50 return std::shared_ptr<ModelAPI_AttributeDocRef>();
52 shared_ptr<ModelAPI_AttributeDocRef> aRes =
53 dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
55 // TODO: generate error on invalid attribute type request