Salome HOME
Merge branch 'master' into agr/start_procedure
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SObject_i.cxx
index 1a8a25c919d1cda6c2f7b66ed7697602d9803a6c..ea5f8845c5844d1ad0bb44cd4c6c5e169bc64f92 100644 (file)
@@ -1,28 +1,29 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  File   : SALOMEDS_SObject_i.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
-
+//
 #include "utilities.h"
 #include "SALOMEDS_SObject_i.hxx"
 #include "SALOMEDS_SComponent_i.hxx"
 #include "SALOMEDSImpl_SComponent.hxx"
 #include "SALOMEDSImpl_Study.hxx"
 #include "SALOMEDSImpl_AttributeIOR.hxx"
+#include "Basics_Utils.hxx"
 
-// OCC Headers
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TColStd_HSequenceOfTransient.hxx>
 #include <map>
 
 #ifdef WIN32
 #include <unistd.h>
 #endif
 
-#include "OpUtil.hxx"
-
-using namespace std;
-
-SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const Handle(SALOMEDSImpl_SObject)& theImpl, CORBA::ORB_ptr theORB)
+SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const SALOMEDSImpl_SObject& theImpl, CORBA::ORB_ptr theORB)
 {
   SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
-  SALOMEDS::SObject_var so  = SALOMEDS::SObject::_narrow(so_servant->_this());
 
-  return so._retn();
+  return so_servant->_this();
 }
 
 
@@ -65,9 +58,18 @@ SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const Handle(SALOMEDSImpl_SObject)
  *  Purpose  :
  */
 //============================================================================
-SALOMEDS_SObject_i::SALOMEDS_SObject_i(const Handle(SALOMEDSImpl_SObject)& impl, CORBA::ORB_ptr orb)
-  : _impl(impl)
+SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb)
 {
+  _impl = 0;
+  if(!impl.IsNull()) {
+     if(impl.IsComponent()) {
+         SALOMEDSImpl_SComponent sco = impl;
+         _impl = sco.GetPersistentCopy();       
+     }
+     else {
+         _impl = impl.GetPersistentCopy();
+     }
+  }
   _orb = CORBA::ORB::_duplicate(orb);
    //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
 }
@@ -79,8 +81,21 @@ SALOMEDS_SObject_i::SALOMEDS_SObject_i(const Handle(SALOMEDSImpl_SObject)& impl,
  */
 //============================================================================
 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
-{}
+{
+   if(_impl) delete _impl;    
+}
 
+//================================================================================
+/*!
+ * \brief Returns true if the %SObject does not belong to any %Study
+ */
+//================================================================================
+
+CORBA::Boolean SALOMEDS_SObject_i::IsNull()
+{
+  SALOMEDS::Locker lock;
+  return !_impl || _impl->IsNull();
+}
 
 //============================================================================
 /*! Function :GetID
@@ -90,7 +105,7 @@ SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
 char* SALOMEDS_SObject_i::GetID()
 {
   SALOMEDS::Locker lock;
-  return CORBA::string_dup(_impl->GetID().ToCString());
+  return CORBA::string_dup(_impl->GetID().c_str());
 }
 
 //============================================================================
@@ -125,14 +140,14 @@ SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
 {
   SALOMEDS::Locker lock;
-  Handle(SALOMEDSImpl_Study) aStudy = _impl->GetStudy();
-  if(aStudy.IsNull()) {
+  SALOMEDSImpl_Study* aStudy = _impl->GetStudy();
+  if(!aStudy) {
     MESSAGE("Problem GetStudy");
     return SALOMEDS::Study::_nil();
   }
 
-  TCollection_AsciiString IOR = aStudy->GetTransientReference();
-  CORBA::Object_var obj = _orb->string_to_object(IOR.ToCString());
+  std::string IOR = aStudy->GetTransientReference();
+  CORBA::Object_var obj = _orb->string_to_object(IOR.c_str());
   SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
   ASSERT(!CORBA::is_nil(Study));
   return SALOMEDS::Study::_duplicate(Study);
@@ -144,16 +159,16 @@ SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
  */
 //============================================================================
 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
-                                                 const char* aTypeOfAttribute)
+                                                  const char* aTypeOfAttribute)
 {
   SALOMEDS::Locker lock;
-  Handle(TDF_Attribute) anAttr;
+  DF_Attribute* anAttr = NULL;
   if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
-    anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
-    return Standard_True;
+    anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
+    return true;
   }
 
-  return Standard_False;
+  return false;
 }
 
 //============================================================================
@@ -165,19 +180,19 @@ CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out
 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
 {
   SALOMEDS::Locker lock;
-  Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllAttributes();
+  std::vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
   SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
-  Standard_Integer length = aSeq->Length();
+  int length = aSeq.size();
 
   SeqOfAttr->length(length);
 
   if (length != 0) {
-    for(int i = 1; i<= length; i++) {
-      Handle(SALOMEDSImpl_GenericAttribute) anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i));
+    for(int i = 0; i < length; i++) {
+      SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
       SALOMEDS::GenericAttribute_var anAttribute;
-      anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
+      anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
       if (!CORBA::is_nil(anAttribute)) {
-       SeqOfAttr[i - 1] = anAttribute;
+        SeqOfAttr[i] = anAttribute;
       }
     }
   }
@@ -193,7 +208,7 @@ SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
 {
   SALOMEDS::Locker lock;
-  Handle(SALOMEDSImpl_SObject) aRefObj;
+  SALOMEDSImpl_SObject aRefObj;
   if(!_impl->ReferencedObject(aRefObj)) return false;
 
   obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
@@ -205,10 +220,10 @@ CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
  *  Purpose  :
  */
 //============================================================================
-CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(long atag, SALOMEDS::SObject_out obj)
+CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
 {
   SALOMEDS::Locker lock;
-  Handle(SALOMEDSImpl_SObject) aSubObj;
+  SALOMEDSImpl_SObject aSubObj;
   if(!_impl->FindSubObject(atag, aSubObj)) return false;
 
   obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
@@ -224,7 +239,7 @@ CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(long atag, SALOMEDS::SObject_ou
 char* SALOMEDS_SObject_i::Name()
 {
   SALOMEDS::Locker lock;
-  return CORBA::string_dup(_impl->Name().ToCString());
+  return CORBA::string_dup(_impl->Name().c_str());
 }
 
 //============================================================================
@@ -235,7 +250,7 @@ char* SALOMEDS_SObject_i::Name()
 void  SALOMEDS_SObject_i::Name(const char* name)
 {
   SALOMEDS::Locker lock;
-  TCollection_AsciiString aName((char*)name);
+  std::string aName((char*)name);
   _impl->Name(aName);
 }
 
@@ -271,8 +286,8 @@ CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
   SALOMEDS::Locker lock;
   CORBA::Object_ptr obj = CORBA::Object::_nil();
   try {
-    TCollection_AsciiString IOR = _impl->GetIOR();
-    char* c_ior = CORBA::string_dup(IOR.ToCString());
+    std::string IOR = _impl->GetIOR();
+    char* c_ior = CORBA::string_dup(IOR.c_str());
     obj = _orb->string_to_object(c_ior);
     CORBA::string_free(c_ior);
   } catch(...) {}
@@ -287,7 +302,7 @@ CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
 char* SALOMEDS_SObject_i::GetName()
 {
   SALOMEDS::Locker lock;
-  CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().ToCString());
+  CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
   return aStr._retn();
 }
 
@@ -299,7 +314,7 @@ char* SALOMEDS_SObject_i::GetName()
 char* SALOMEDS_SObject_i::GetComment()
 {
   SALOMEDS::Locker lock;
-  CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().ToCString());
+  CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
   return aStr._retn();
 }
 
@@ -311,21 +326,31 @@ char* SALOMEDS_SObject_i::GetComment()
 char* SALOMEDS_SObject_i::GetIOR()
 {
   SALOMEDS::Locker lock;
-  CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().ToCString());
+  CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
   return aStr._retn();
 }
 
+//============================================================================
+/*! Function : SetAttrString
+ *  Purpose  :
+ */
+//============================================================================
+void SALOMEDS_SObject_i::SetAttrString(const char* name, const char* value)
+{
+  SALOMEDS::Locker lock;
+  _impl->SetAttrString(name,value);
+}
+
 //===========================================================================
 //   PRIVATE FUNCTIONS
 //===========================================================================
-long SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
+CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
 {
 #ifdef WIN32
   long pid = (long)_getpid();
 #else
   long pid = (long)getpid();
 #endif
-  isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
-  SALOMEDSImpl_SObject* local_impl = _impl.operator->();
-  return ((long)local_impl);
+  isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
+  return reinterpret_cast<CORBA::LongLong>(_impl);
 }