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 <Model_AttributeRefList.h>
11 #include <GeomData_Point.h>
12 #include <GeomData_Point2D.h>
13 #include <GeomData_Dir.h>
14 #include <TDataStd_Name.hxx>
18 Model_Data::Model_Data()
22 void Model_Data::setLabel(TDF_Label& theLab)
27 string Model_Data::getName()
29 Handle(TDataStd_Name) aName;
30 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
31 return string(TCollection_AsciiString(aName->Get()).ToCString());
32 return ""; // not defined
35 void Model_Data::setName(string theName)
37 TDataStd_Name::Set(myLab, theName.c_str());
40 void Model_Data::addAttribute(string theID, string theAttrType)
42 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
43 ModelAPI_Attribute* anAttr = 0;
44 if (theAttrType == ModelAPI_AttributeDocRef::type())
45 anAttr = new Model_AttributeDocRef(anAttrLab);
46 else if (theAttrType == ModelAPI_AttributeDouble::type())
47 anAttr = new Model_AttributeDouble(anAttrLab);
48 else if (theAttrType == ModelAPI_AttributeReference::type())
49 anAttr = new Model_AttributeReference(anAttrLab);
50 else if (theAttrType == ModelAPI_AttributeRefAttr::type())
51 anAttr = new Model_AttributeRefAttr(anAttrLab);
52 else if (theAttrType == ModelAPI_AttributeRefList::type())
53 anAttr = new Model_AttributeRefList(anAttrLab);
54 else if (theAttrType == GeomData_Point::type())
55 anAttr = new GeomData_Point(anAttrLab);
56 else if (theAttrType == GeomData_Dir::type())
57 anAttr = new GeomData_Dir(anAttrLab);
58 else if (theAttrType == GeomData_Point2D::type())
59 anAttr = new GeomData_Point2D(anAttrLab);
62 myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
63 anAttr->setFeature(myFeature);
66 ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
69 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
71 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
72 if (aFound == myAttrs.end()) {
73 // TODO: generate error on unknown attribute request and/or add mechanism for customization
74 return boost::shared_ptr<ModelAPI_AttributeDocRef>();
76 boost::shared_ptr<ModelAPI_AttributeDocRef> aRes =
77 boost::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
79 // TODO: generate error on invalid attribute type request
84 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
86 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
87 if (aFound == myAttrs.end()) {
88 // TODO: generate error on unknown attribute request and/or add mechanism for customization
89 return boost::shared_ptr<ModelAPI_AttributeDouble>();
91 boost::shared_ptr<ModelAPI_AttributeDouble> aRes =
92 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
94 // TODO: generate error on invalid attribute type request
99 boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string theID)
101 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
102 if (aFound == myAttrs.end()) {
103 // TODO: generate error on unknown attribute request and/or add mechanism for customization
104 return boost::shared_ptr<ModelAPI_AttributeReference>();
106 boost::shared_ptr<ModelAPI_AttributeReference> aRes =
107 boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aFound->second);
109 // TODO: generate error on invalid attribute type request
114 boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const string theID)
116 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
117 if (aFound == myAttrs.end()) {
118 // TODO: generate error on unknown attribute request and/or add mechanism for customization
119 return boost::shared_ptr<ModelAPI_AttributeRefAttr>();
121 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRes =
122 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aFound->second);
124 // TODO: generate error on invalid attribute type request
129 boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const string theID)
131 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
132 if (aFound == myAttrs.end()) {
133 // TODO: generate error on unknown attribute request and/or add mechanism for customization
134 return boost::shared_ptr<ModelAPI_AttributeRefList>();
136 boost::shared_ptr<ModelAPI_AttributeRefList> aRes =
137 boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aFound->second);
139 // TODO: generate error on invalid attribute type request
144 boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
146 boost::shared_ptr<ModelAPI_Attribute> aResult;
147 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
149 return myAttrs[theID];
152 const string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute> theAttr)
154 map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
155 for(; anAttr != myAttrs.end(); anAttr++) {
156 if (anAttr->second == theAttr) return anAttr->first;
159 static string anEmpty;
163 bool Model_Data::isEqual(const boost::shared_ptr<ModelAPI_Data> theData)
165 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theData);
167 return myLab.IsEqual(aData->myLab) == Standard_True;
171 bool Model_Data::isValid()
173 return !myLab.IsNull() && myLab.HasAttribute();