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 <GeomData_Dir.h>
11 #include <TDataStd_Name.hxx>
15 Model_Data::Model_Data()
19 void Model_Data::setLabel(TDF_Label& theLab)
24 string Model_Data::getName()
26 Handle(TDataStd_Name) aName;
27 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
28 return string(TCollection_AsciiString(aName->Get()).ToCString());
29 return ""; // not defined
32 void Model_Data::setName(string theName)
34 TDataStd_Name::Set(myLab, theName.c_str());
37 void Model_Data::addAttribute(string theID, string theAttrType)
39 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
40 ModelAPI_Attribute* anAttr = 0;
41 if (theAttrType == ModelAPI_AttributeDocRef::type())
42 anAttr = new Model_AttributeDocRef(anAttrLab);
43 else if (theAttrType == ModelAPI_AttributeDouble::type())
44 anAttr = new Model_AttributeDouble(anAttrLab);
45 else if (theAttrType == GeomData_Point::type())
46 anAttr = new GeomData_Point(anAttrLab);
47 else if (theAttrType == GeomData_Dir::type())
48 anAttr = new GeomData_Dir(anAttrLab);
49 else if (theAttrType == GeomData_Point2D::type())
50 anAttr = new GeomData_Point2D(anAttrLab);
53 myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
54 anAttr->setFeature(myFeature);
57 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
60 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
62 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
63 if (aFound == myAttrs.end()) {
64 // TODO: generate error on unknown attribute request and/or add mechanism for customization
65 return boost::shared_ptr<ModelAPI_AttributeDocRef>();
67 boost::shared_ptr<ModelAPI_AttributeDocRef> aRes =
68 boost::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
70 // TODO: generate error on invalid attribute type request
75 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
77 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
78 if (aFound == myAttrs.end()) {
79 // TODO: generate error on unknown attribute request and/or add mechanism for customization
80 return boost::shared_ptr<ModelAPI_AttributeDouble>();
82 boost::shared_ptr<ModelAPI_AttributeDouble> aRes =
83 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
85 // TODO: generate error on invalid attribute type request
90 boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
92 boost::shared_ptr<ModelAPI_Attribute> aResult;
93 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
95 return myAttrs[theID];