]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Object.cxx
Salome HOME
Added object, attribute and data model organization in the document.
[modules/shaper.git] / src / Model / Model_Object.cxx
1 // File:        Model_Object.hxx
2 // Created:     21 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <Model_Object.h>
6 #include <Model_AttributeDocRef.h>
7 #include <TDataStd_Name.hxx>
8
9 using namespace std;
10
11 Model_Object::Model_Object()
12 {
13 }
14
15 void Model_Object::setLabel(TDF_Label& theLab)
16 {
17   myLab = theLab;
18 }
19
20 string Model_Object::getName()
21 {
22   Handle(TDataStd_Name) aName;
23   if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
24     return string(TCollection_AsciiString(aName->Get()).ToCString());
25   return ""; // not defined
26 }
27
28 void Model_Object::setName(string theName)
29 {
30   TDataStd_Name::Set(myLab, theName.c_str());
31 }
32
33 void Model_Object::addAttribute(string theID, string theAttrType)
34 {
35   TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
36   ModelAPI_Attribute* anAttr = 0;
37   if (theAttrType == ModelAPI_AttributeDocRef::type())
38     anAttr = new Model_AttributeDocRef(anAttrLab);
39   if (anAttr)
40     myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
41   else
42     ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
43 }
44
45 shared_ptr<ModelAPI_AttributeDocRef> Model_Object::docRef(const string theID)
46 {
47   map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
48   if (aFound == myAttrs.end()) {
49     // TODO: generate error on unknown attribute request and/or add mechanism for customization
50     return std::shared_ptr<ModelAPI_AttributeDocRef>();
51   }
52   shared_ptr<ModelAPI_AttributeDocRef> aRes = 
53     dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
54   if (!aRes) {
55     // TODO: generate error on invalid attribute type request
56   }
57   return aRes;
58 }