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 <Model_AttributeDouble.h>
8 #include <TDataStd_Name.hxx>
12 Model_Object::Model_Object()
16 void Model_Object::setLabel(TDF_Label& theLab)
21 string Model_Object::getName()
23 Handle(TDataStd_Name) aName;
24 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
25 return string(TCollection_AsciiString(aName->Get()).ToCString());
26 return ""; // not defined
29 void Model_Object::setName(string theName)
31 TDataStd_Name::Set(myLab, theName.c_str());
34 void Model_Object::addAttribute(string theID, string theAttrType)
36 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
37 ModelAPI_Attribute* anAttr = 0;
38 if (theAttrType == ModelAPI_AttributeDocRef::type())
39 anAttr = new Model_AttributeDocRef(anAttrLab);
40 else if (theAttrType == ModelAPI_AttributeDouble::type())
41 anAttr = new Model_AttributeDouble(anAttrLab);
44 myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
46 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
49 shared_ptr<ModelAPI_AttributeDocRef> Model_Object::docRef(const string theID)
51 map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
52 if (aFound == myAttrs.end()) {
53 // TODO: generate error on unknown attribute request and/or add mechanism for customization
54 return std::shared_ptr<ModelAPI_AttributeDocRef>();
56 shared_ptr<ModelAPI_AttributeDocRef> aRes =
57 dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
59 // TODO: generate error on invalid attribute type request
64 shared_ptr<ModelAPI_AttributeDouble> Model_Object::real(const string theID)
66 map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
67 if (aFound == myAttrs.end()) {
68 // TODO: generate error on unknown attribute request and/or add mechanism for customization
69 return std::shared_ptr<ModelAPI_AttributeDouble>();
71 shared_ptr<ModelAPI_AttributeDouble> aRes =
72 dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
74 // TODO: generate error on invalid attribute type request