1 // File: Model_Data.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_Data.h>
6 #include <Model_AttributeDocRef.h>
7 #include <Model_AttributeDouble.h>
8 #include <GeomData_Point.h>
9 #include <GeomData_Point2D.h>
10 #include <TDataStd_Name.hxx>
14 Model_Data::Model_Data()
18 void Model_Data::setLabel(TDF_Label& theLab)
23 string Model_Data::getName()
25 Handle(TDataStd_Name) aName;
26 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
27 return string(TCollection_AsciiString(aName->Get()).ToCString());
28 return ""; // not defined
31 void Model_Data::setName(string theName)
33 TDataStd_Name::Set(myLab, theName.c_str());
36 void Model_Data::addAttribute(string theID, string theAttrType)
38 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
39 ModelAPI_Attribute* anAttr = 0;
40 if (theAttrType == ModelAPI_AttributeDocRef::type())
41 anAttr = new Model_AttributeDocRef(anAttrLab);
42 else if (theAttrType == ModelAPI_AttributeDouble::type())
43 anAttr = new Model_AttributeDouble(anAttrLab);
44 else if (theAttrType == GeomData_Point::type())
45 anAttr = new GeomData_Point(anAttrLab);
46 else if (theAttrType == GeomData_Point2D::type())
47 anAttr = new GeomData_Point2D(anAttrLab);
50 myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
52 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
55 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
57 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
58 if (aFound == myAttrs.end()) {
59 // TODO: generate error on unknown attribute request and/or add mechanism for customization
60 return boost::shared_ptr<ModelAPI_AttributeDocRef>();
62 boost::shared_ptr<ModelAPI_AttributeDocRef> aRes =
63 boost::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
65 // TODO: generate error on invalid attribute type request
70 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
72 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
73 if (aFound == myAttrs.end()) {
74 // TODO: generate error on unknown attribute request and/or add mechanism for customization
75 return boost::shared_ptr<ModelAPI_AttributeDouble>();
77 boost::shared_ptr<ModelAPI_AttributeDouble> aRes =
78 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
80 // TODO: generate error on invalid attribute type request
85 boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
87 boost::shared_ptr<ModelAPI_Attribute> aResult;
88 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
90 return myAttrs[theID];