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 <Model_AttributeReference.h>
9 #include <Model_AttributeRefAttr.h>
10 #include <GeomData_Point.h>
11 #include <GeomData_Point2D.h>
12 #include <GeomData_Dir.h>
13 #include <TDataStd_Name.hxx>
17 Model_Data::Model_Data()
21 void Model_Data::setLabel(TDF_Label& theLab)
26 string Model_Data::getName()
28 Handle(TDataStd_Name) aName;
29 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
30 return string(TCollection_AsciiString(aName->Get()).ToCString());
31 return ""; // not defined
34 void Model_Data::setName(string theName)
36 TDataStd_Name::Set(myLab, theName.c_str());
39 void Model_Data::addAttribute(string theID, string theAttrType)
41 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
42 ModelAPI_Attribute* anAttr = 0;
43 if (theAttrType == ModelAPI_AttributeDocRef::type())
44 anAttr = new Model_AttributeDocRef(anAttrLab);
45 else if (theAttrType == ModelAPI_AttributeDouble::type())
46 anAttr = new Model_AttributeDouble(anAttrLab);
47 else if (theAttrType == ModelAPI_AttributeReference::type())
48 anAttr = new Model_AttributeReference(anAttrLab);
49 else if (theAttrType == ModelAPI_AttributeRefAttr::type())
50 anAttr = new Model_AttributeRefAttr(anAttrLab);
51 else if (theAttrType == GeomData_Point::type())
52 anAttr = new GeomData_Point(anAttrLab);
53 else if (theAttrType == GeomData_Dir::type())
54 anAttr = new GeomData_Dir(anAttrLab);
55 else if (theAttrType == GeomData_Point2D::type())
56 anAttr = new GeomData_Point2D(anAttrLab);
59 myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
60 anAttr->setFeature(myFeature);
63 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
66 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
68 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
69 if (aFound == myAttrs.end()) {
70 // TODO: generate error on unknown attribute request and/or add mechanism for customization
71 return boost::shared_ptr<ModelAPI_AttributeDocRef>();
73 boost::shared_ptr<ModelAPI_AttributeDocRef> aRes =
74 boost::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
76 // TODO: generate error on invalid attribute type request
81 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
83 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
84 if (aFound == myAttrs.end()) {
85 // TODO: generate error on unknown attribute request and/or add mechanism for customization
86 return boost::shared_ptr<ModelAPI_AttributeDouble>();
88 boost::shared_ptr<ModelAPI_AttributeDouble> aRes =
89 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
91 // TODO: generate error on invalid attribute type request
96 boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string theID)
98 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
99 if (aFound == myAttrs.end()) {
100 // TODO: generate error on unknown attribute request and/or add mechanism for customization
101 return boost::shared_ptr<ModelAPI_AttributeReference>();
103 boost::shared_ptr<ModelAPI_AttributeReference> aRes =
104 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aFound->second);
106 // TODO: generate error on invalid attribute type request
111 boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const string theID)
113 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
114 if (aFound == myAttrs.end()) {
115 // TODO: generate error on unknown attribute request and/or add mechanism for customization
116 return boost::shared_ptr<ModelAPI_AttributeRefAttr>();
118 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRes =
119 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aFound->second);
121 // TODO: generate error on invalid attribute type request
126 boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
128 boost::shared_ptr<ModelAPI_Attribute> aResult;
129 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
131 return myAttrs[theID];
134 const string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute> theAttr)
136 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
137 for(; anAttr != myAttrs.end(); anAttr++) {
138 if (anAttr->second == theAttr) return anAttr->first;
141 static string anEmpty;