Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SObject_i.cxx
index 2ff17b580562eb0865da39a5ac79f742419fde2a..35c5087af6385c4a68b45df0c587372444155b63 100644 (file)
@@ -188,7 +188,7 @@ namespace SALOMEDS{
     TAttrID2FunMap::const_iterator anEnd = __AttrID2FunMap__.end();
     for(; anIter != anEnd; anIter++){
       const TAttrID2FunMap::key_type& aKey = anIter->first;
-      const TAttrID2FunMap::data_type& aValue = anIter->second;
+      const TAttrID2FunMap::mapped_type& aValue = anIter->second;
       __GUID2AttrIDMap__[aValue.myGetGUID()] = aKey;
     };
 
@@ -223,7 +223,7 @@ namespace SALOMEDS{
   {
     TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
     if(anIter != __AttrID2FunMap__.end()){
-      const TAttrID2FunMap::data_type& aValue = anIter->second;
+      const TAttrID2FunMap::mapped_type& aValue = anIter->second;
       return aValue.myGetGUID();
     }
     // create tree node GUID by name
@@ -365,12 +365,19 @@ char* SALOMEDS_SObject_i::GetID()
  *  Purpose  : 
  */
 //============================================================================
+TDF_Label SALOMEDS_SObject_i::GetFatherComponentLabel()
+{
+  TDF_Label aLabel = _lab;
+  while(!SALOMEDS_SComponent_i::IsA(aLabel) && !aLabel.IsRoot())
+    aLabel = aLabel.Father();
+
+  return aLabel;
+}
+
 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
 {
-  TDF_Label aSCompLabel = _lab;
-  while(!SALOMEDS_SComponent_i::IsA(aSCompLabel) && !aSCompLabel.IsRoot()){
-    aSCompLabel = aSCompLabel.Father();
-  }
+  TDF_Label aSCompLabel = GetFatherComponentLabel();
+
   return SALOMEDS_SComponent_i::NewRef(_study,aSCompLabel)._retn();
 }
   
@@ -530,28 +537,8 @@ char* SALOMEDS_SObject_i::GetIOR() {
 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;
-    TAttrMap::const_iterator anIter = myAttrMap.find(anAttributeID);
-    if(anIter != myAttrMap.end())
-      anGenAttr = anIter->second;
-
-    SALOMEDS_GenericAttribute_i* anAttr = anGenAttr.first;
-    if(anAttr != NULL){
-      if(anAttr->GetAttribute() != theAttr)
-       anAttr->SetAttribute(theAttr);
-    }else{
-      anGenAttr = _CreateGenAttribute(theAttr,anAttributeID.c_str());
-    }
-  }
-
-  return anGenAttr;
+  std::string aType = GetType(theAttr);
+  return _FindGenAttribute(aType.c_str());
 }
 
 
@@ -588,10 +575,10 @@ SALOMEDS_SObject_i::_CreateGenAttribute(const Handle(TDF_Attribute)& theAttr,
   SALOMEDS_GenericAttribute_i* anAttr;
   TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
   if(anIter != __AttrID2FunMap__.end()){
-    const TAttrID2FunMap::data_type& aValue = anIter->second;
+    const TAttrID2FunMap::mapped_type& aValue = anIter->second;
     
-    if(aValue.myIsCheckLockedStudy())
-      _study->CheckLocked();
+    //if(aValue.myIsCheckLockedStudy()) // mpv 03.02.05: creation of CORBA objects does not modify the study
+    //  _study->CheckLocked();
     
     anAttr = aValue.myNewInstance(theAttr,this);
     return TAttrHolder(anAttr,anAttr->_this());
@@ -634,7 +621,7 @@ SALOMEDS_SObject_i::_FindGenAttribute(const char* theType)
     if(aGenAttr != NULL)
       myAttrMap[theType] = anAttrHolder;
   }else{
-    myAttrMap.erase(theType);
+    //myAttrMap.erase(theType);
     //if(anGenAttr != NULL)
     //  anGenAttr->Destroy();
     return TAttrHolder();
@@ -644,25 +631,17 @@ SALOMEDS_SObject_i::_FindGenAttribute(const char* theType)
 }
 
 
-SALOMEDS::GenericAttribute_ptr 
-SALOMEDS_SObject_i::_FindCORBAAttribute(const char* theType)
+CORBA::Boolean 
+SALOMEDS_SObject_i::FindAttribute(SALOMEDS::GenericAttribute_out theAttribute, 
+                                 const char* theType)
 {
   TAttrHolder anAttr = _FindGenAttribute(theType);
   SALOMEDS::GenericAttribute_var anGenAttr = anAttr.second;
   if(!CORBA::is_nil(anGenAttr)){
-    return anGenAttr._retn();
+    theAttribute = SALOMEDS::GenericAttribute::_duplicate(anGenAttr);
+    return true;
   }
-
-  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);
+  return false;
 }
 
 
@@ -677,7 +656,7 @@ Handle(TDF_Attribute)
   Handle(TDF_Attribute) anAttr;
   TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
   if(anIter != __AttrID2FunMap__.end()){
-    const TAttrID2FunMap::data_type& aValue = anIter->second;
+    const TAttrID2FunMap::mapped_type& aValue = anIter->second;
     
     if(aValue.myIsCheckLockedStudy())
       _study->CheckLocked();
@@ -699,7 +678,6 @@ Handle(TDF_Attribute)
     if(!_lab.FindAttribute(aGUID,anAttr)){
       _study->CheckLocked();
       anAttr = TDataStd_TreeNode::Set(_lab,aGUID);
-      _lab.AddAttribute(anAttr);
       return anAttr;
     }
   }
@@ -709,7 +687,6 @@ Handle(TDF_Attribute)
     if(!_lab.FindAttribute(aGUID,anAttr)){
       _study->CheckLocked();
       anAttr = TDataStd_UAttribute::Set(_lab,aGUID);
-      _lab.AddAttribute(anAttr);
       return anAttr;
     }
   }
@@ -756,7 +733,7 @@ void SALOMEDS_SObject_i::RemoveAttribute(const char* theType)
   }
   TAttrMap::iterator anIter = myAttrMap.find(theType);
   if(anIter != myAttrMap.end()){
-    myAttrMap.erase(anIter);
+    //myAttrMap.erase(anIter);
   }
   _lab.ForgetAttribute(::GetGUID(theType));
 }
@@ -776,8 +753,8 @@ void SALOMEDS_SObject_i::OnRemove()
     _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
   }
 
-  myAttrMap.clear();
+  //myAttrMap.clear();
 
-  SALOMEDS_Study_i::TSObjectMap& anSObjectMap = _study->GetSObjectMap();
-  anSObjectMap.erase(_lab);
+  //SALOMEDS_Study_i::TSObjectMap& anSObjectMap = _study->GetSObjectMap();
+  //anSObjectMap.erase(_lab);
 }