+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+CORBA::Short SALOMEDS_SObject_i::Depth()
+{
+ return _lab.Depth();
+}
+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
+{
+ try {
+ Handle(SALOMEDS_IORAttribute) anAttr;
+ if(_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
+ CORBA::ORB_var anORB = _study->GetStudyManager()->GetORB();
+ return anORB->string_to_object(Str(anAttr->Get()));
+ }
+ }catch(...){
+ }
+ return CORBA::Object::_nil();
+}
+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+char* SALOMEDS_SObject_i::GetName() {
+ Handle(TDataStd_Name) anAttr;
+ if(_lab.FindAttribute(TDataStd_Name::GetID(),anAttr))
+ return CORBA::string_dup(Str(anAttr->Get()));
+
+ return CORBA::string_dup("");
+}
+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+char* SALOMEDS_SObject_i::GetComment() {
+ Handle(TDataStd_Comment) anAttr;
+ if(_lab.FindAttribute(TDataStd_Comment::GetID(), anAttr))
+ return CORBA::string_dup(Str(anAttr->Get()));
+
+ return CORBA::string_dup("");
+}
+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+char* SALOMEDS_SObject_i::GetIOR() {
+ Handle(SALOMEDS_IORAttribute) anAttr;
+ if(_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr))
+ return CORBA::string_dup(Str(anAttr->Get()));
+
+ return CORBA::string_dup("");
+}
+
+
+//============================================================================
+/*! Function : GetAllAttributes
+ * Purpose : Returns list of all attributes for this sobject
+ */
+//============================================================================
+SALOMEDS_SObject_i::TAttrHolder
+SALOMEDS_SObject_i::_FindGenAttribute(const Handle(TDF_Attribute)& theAttr)
+{
+ TAttrHolder anGenAttr;
+
+ Standard_GUID aGUID = theAttr->ID();
+
+ TGUID2AttrIDMap::const_iterator anIter = __GUID2AttrIDMap__.find(aGUID);
+ if(anIter != __GUID2AttrIDMap__.end()){
+ const TAttributeID& anAttributeID = anIter->second;
+ anGenAttr = _FindGenAttribute(anAttributeID.c_str());
+ }
+
+ return anGenAttr;
+}
+
+
+SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
+{
+ SALOMEDS::ListOfAttributes_var aSeqOfAttr = new SALOMEDS::ListOfAttributes;
+ if(_lab.NbAttributes() > 0){
+ Standard_Integer i = 0;
+ for(TDF_AttributeIterator iter(_lab); iter.More(); iter.Next()) {
+ Handle(TDF_Attribute) anAttr = iter.Value();
+ TAttrHolder anAttrHolder = _FindGenAttribute(anAttr);
+ SALOMEDS::GenericAttribute_var anGenAttr = anAttrHolder.second;
+ if(!anGenAttr->_is_nil())
+ {
+ aSeqOfAttr->length(++i);
+ aSeqOfAttr[i-1] = anGenAttr._retn();
+ }
+ }
+ }
+
+ return aSeqOfAttr._retn();
+}
+
+
+//============================================================================
+/*! Function : FindAttribute
+ * Purpose : Find attribute of given type on this SObject
+ */
+//============================================================================
+SALOMEDS_SObject_i::TAttrHolder
+SALOMEDS_SObject_i::_CreateGenAttribute(const Handle(TDF_Attribute)& theAttr,
+ const char* theType)
+{
+ SALOMEDS_GenericAttribute_i* anAttr;
+ TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
+ if(anIter != __AttrID2FunMap__.end()){
+ const TAttrID2FunMap::data_type& aValue = anIter->second;
+
+ if(aValue.myIsCheckLockedStudy())
+ _study->CheckLocked();
+
+ anAttr = aValue.myNewInstance(theAttr,this);
+ return TAttrHolder(anAttr,anAttr->_this());
+ }
+
+ if(strncmp(theType,"AttributeTreeNode",17) == 0){
+ anAttr = new SALOMEDS_AttributeTreeNode_i(theAttr,this);
+ return TAttrHolder(anAttr,anAttr->_this());
+ }
+
+ if(strncmp(theType,"AttributeUserID",15) == 0){
+ anAttr = new SALOMEDS_AttributeUserID_i(theAttr,this);
+ return TAttrHolder(anAttr,anAttr->_this());
+ }
+
+ return TAttrHolder();
+}
+
+
+SALOMEDS_SObject_i::TAttrHolder
+SALOMEDS_SObject_i::_FindGenAttribute(const char* theType)
+{
+ TAttrHolder anAttrHolder;
+ TAttrMap::const_iterator anIter = myAttrMap.find(theType);
+ if(anIter != myAttrMap.end())
+ anAttrHolder = anIter->second;
+
+ Standard_GUID aGUID = ::GetGUID(theType);
+ Handle(TDF_Attribute) anAttr;
+
+ if(_lab.FindAttribute(aGUID,anAttr)){
+ SALOMEDS_GenericAttribute_i* aGenAttr = anAttrHolder.first;
+ if(aGenAttr != NULL){
+ if(aGenAttr->GetAttribute() != anAttr)
+ aGenAttr->SetAttribute(anAttr);
+ }else{
+ anAttrHolder = _CreateGenAttribute(anAttr,theType);
+ }
+ aGenAttr = anAttrHolder.first;
+ if(aGenAttr != NULL)
+ myAttrMap[theType] = anAttrHolder;
+ }else{
+ //myAttrMap.erase(theType);
+ //if(anGenAttr != NULL)
+ // anGenAttr->Destroy();
+ return TAttrHolder();
+ }
+
+ return anAttrHolder;
+}
+
+
+SALOMEDS::GenericAttribute_ptr
+SALOMEDS_SObject_i::_FindCORBAAttribute(const char* theType)
+{
+ TAttrHolder anAttr = _FindGenAttribute(theType);
+ SALOMEDS::GenericAttribute_var anGenAttr = anAttr.second;
+ if(!CORBA::is_nil(anGenAttr)){
+ return anGenAttr._retn();
+ }
+
+ return SALOMEDS::GenericAttribute::_nil();
+}
+
+
+CORBA::Boolean
+SALOMEDS_SObject_i::FindAttribute(SALOMEDS::GenericAttribute_out theAttribute,
+ const char* theType)
+{
+ theAttribute = _FindCORBAAttribute(theType);
+ return !CORBA::is_nil(theAttribute);
+}
+
+
+//============================================================================
+/*! Function : FindAttribute
+ * Purpose : Find attribute of given type on this SObject
+ */
+//============================================================================
+Handle(TDF_Attribute)
+ SALOMEDS_SObject_i::_AddAttribute(const char* theType)
+{
+ Handle(TDF_Attribute) anAttr;
+ TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
+ if(anIter != __AttrID2FunMap__.end()){
+ const TAttrID2FunMap::data_type& aValue = anIter->second;
+
+ if(aValue.myIsCheckLockedStudy())
+ _study->CheckLocked();
+
+ anAttr = aValue.myNewAttribute();
+ _lab.AddAttribute(anAttr);
+ return anAttr;
+ }
+
+ if(strncmp(theType, "AttributeTreeNode",17) == 0){
+ Standard_GUID aGUID;
+ if(strcmp(theType, "AttributeTreeNode") == 0){
+ aGUID = TDataStd_TreeNode::GetDefaultTreeID();
+ }else{
+ char aString[40] = "";
+ sprintf(aString, &theType[21]);
+ aGUID = Standard_GUID(aString); // create tree node GUID by name
+ }
+ if(!_lab.FindAttribute(aGUID,anAttr)){
+ _study->CheckLocked();
+ anAttr = TDataStd_TreeNode::Set(_lab,aGUID);
+ _lab.AddAttribute(anAttr);
+ return anAttr;
+ }
+ }
+
+ if(strncmp(theType, "AttributeUserID",15) == 0){
+ Standard_GUID aGUID = SALOMEDS_AttributeUserID_i::GetGUID();
+ if(!_lab.FindAttribute(aGUID,anAttr)){
+ _study->CheckLocked();
+ anAttr = TDataStd_UAttribute::Set(_lab,aGUID);
+ _lab.AddAttribute(anAttr);
+ return anAttr;
+ }
+ }
+
+
+ return anAttr;
+}
+
+
+SALOMEDS::GenericAttribute_ptr
+SALOMEDS_SObject_i::FindOrCreateAttribute(const char* theType)
+{
+ TAttrHolder anAttrHolder = _FindGenAttribute(theType);
+ SALOMEDS::GenericAttribute_var anGenAttr = anAttrHolder.second;
+ if(!anGenAttr->_is_nil())
+ return anGenAttr._retn();
+
+ Handle(TDF_Attribute) anAttr = _AddAttribute(theType);
+ if(!anAttr.IsNull()){
+ anAttrHolder = _CreateGenAttribute(anAttr,theType);
+ anGenAttr = anAttrHolder.second;
+ if(!anGenAttr->_is_nil())
+ return anGenAttr._retn();
+ }
+
+ return SALOMEDS::GenericAttribute::_nil();
+}
+
+
+//============================================================================
+/*! Function : FindAttribute
+ * Purpose : Find attribute of given type on this SObject
+ */
+//============================================================================
+void SALOMEDS_SObject_i::RemoveAttribute(const char* theType)
+{
+ _study->CheckLocked();
+ if(strcmp(theType, "AttributeIOR") == 0) { // postponed removing of CORBA objects
+ Handle(SALOMEDS_IORAttribute) anAttr;
+ if(_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
+ _study->AddPostponed(Str(anAttr->Get()));
+ else
+ return;
+ }
+ TAttrMap::iterator anIter = myAttrMap.find(theType);
+ if(anIter != myAttrMap.end()){
+ //myAttrMap.erase(anIter);
+ }
+ _lab.ForgetAttribute(::GetGUID(theType));
+}
+
+
+void SALOMEDS_SObject_i::OnRemove()
+{
+ Handle(TDF_Reference) aReference;
+ if(_lab.FindAttribute(TDF_Reference::GetID(),aReference)){
+ Handle(SALOMEDS_TargetAttribute) aTarget;
+ if(aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
+ aTarget->Remove(_lab);
+ }
+
+ Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
+ if(_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
+ _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+ }
+
+ //myAttrMap.clear();
+
+ //SALOMEDS_Study_i::TSObjectMap& anSObjectMap = _study->GetSObjectMap();
+ //anSObjectMap.erase(_lab);
+}