Salome HOME
Do not over write CatalogResources for a job on localhost with SalomeLauncher.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SObject_i.cxx
index 04478d1deb0a47f7357450e349b5f91760f9b14f..0b660550e5ad9ec088e381a827884fc8c3605a06 100644 (file)
-//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  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 
-//  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 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// 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, 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 //  File   : SALOMEDS_SObject_i.cxx
-//  Author : Yves FRICAUD
+//  Author : Sergey RUIN
 //  Module : SALOME
-//  $Header$
-
+//
 #include "utilities.h"
 #include "SALOMEDS_SObject_i.hxx"
-//SALOMEDS Headers
+#include "SALOMEDS_Study_i.hxx"
 #include "SALOMEDS_SComponent_i.hxx"
 #include "SALOMEDS_GenericAttribute_i.hxx"
-#include "SALOMEDS_IORAttribute.hxx"
-#include <TDF_AttributeIterator.hxx>
-using namespace std;
+#include "SALOMEDS.hxx"
+#include "SALOMEDSImpl_GenericAttribute.hxx"
+#include "SALOMEDSImpl_SComponent.hxx"
+#include "SALOMEDSImpl_Study.hxx"
+#include "SALOMEDSImpl_AttributeIOR.hxx"
+#include "Basics_Utils.hxx"
+
+#include <map>
+
+#ifdef WIN32
+#include <process.h>
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+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);
+
+  return so_servant->_this();
+}
+
 
 //============================================================================
 /*! Function : constructor
- *  Purpose  : 
+ *  Purpose  :
  */
 //============================================================================
-SALOMEDS_SObject_i::SALOMEDS_SObject_i(const TDF_Label lab, CORBA::ORB_ptr orb)
-  :_lab(lab)
+SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb) :
+  GenericObj_i(SALOMEDS_Study_i::GetThePOA())
 {
+  _impl = 0;
+  if(!impl.IsNull()) {
+     if(impl.IsComponent()) {
+         SALOMEDSImpl_SComponent sco = impl;
+         _impl = sco.GetPersistentCopy();       
+     }
+     else {
+         _impl = impl.GetPersistentCopy();
+     }
+  }
   _orb = CORBA::ORB::_duplicate(orb);
-  _value = NULL;
-  _type = NULL;
-  _name = NULL;
-  _liste_ba_type.resize(0);
 }
-  
+
 
 //============================================================================
 /*! Function : destructor
- *  Purpose  : 
+ *  Purpose  :
  */
 //============================================================================
 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
 {
-  CORBA::string_free(_value);
-  CORBA::string_free(_type);
-  CORBA::string_free(_name);
+   if(_impl) delete _impl;    
 }
-  
-  
+
 //============================================================================
-/*! Function :
- *  Purpose  : 
- */
+/*!
+  \brief Get default POA for the servant object.
+
+  This function is implicitly called from "_this()" function.
+  Default POA can be set via the constructor.
+
+  \return reference to the default POA for the servant
+*/
 //============================================================================
-char* SALOMEDS_SObject_i::GetID()
+PortableServer::POA_ptr SALOMEDS_SObject_i::_default_POA()
+{
+  myPOA = PortableServer::POA::_duplicate(SALOMEDS_Study_i::GetThePOA());
+  //MESSAGE("SALOMEDS_SObject_i::_default_POA: " << myPOA);
+  return PortableServer::POA::_duplicate(myPOA);
+}
+
+//================================================================================
+/*!
+ * \brief Returns true if the %SObject does not belong to any %Study
+ */
+//================================================================================
+
+CORBA::Boolean SALOMEDS_SObject_i::IsNull()
 {
-  TCollection_AsciiString anEntry;
-  TDF_Tool::Entry (_lab,anEntry);
-  return CORBA::string_dup(anEntry.ToCString());
+  SALOMEDS::Locker lock;
+  return !_impl || _impl->IsNull();
 }
-  
+
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function :GetID
+ *  Purpose  :
  */
 //============================================================================
-SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
+char* SALOMEDS_SObject_i::GetID()
 {
-  TDF_Label LF = _lab;
-  while (!SALOMEDS_SComponent_i::IsA(LF) && !LF.IsRoot()) {
-    LF = LF.Father();
-  }
-  SALOMEDS_SComponent_i *  so_servant = new SALOMEDS_SComponent_i (LF,_orb);
-  SALOMEDS::SComponent_var so;
-  so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this()); 
-  return so;
+  SALOMEDS::Locker lock;
+  return CORBA::string_dup(_impl->GetID().c_str());
 }
-  
+
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetFatherComponent
+ *  Purpose  :
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
+SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
 {
-  TDF_Label LF = _lab.Father();
-
-  SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (LF,_orb);
-  SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); 
-  return so;
+  SALOMEDS::Locker lock;
+  SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
+  return sco._retn();
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetFather
+ *  Purpose  :
  */
 //============================================================================
-SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
+SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
 {
-  TDF_Label Root = _lab.Root();
-  Handle(SALOMEDS_IORAttribute) Att;
-  char* IOR;
-  if (Root.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
-    TCollection_AsciiString ch(Att->Get());
-    IOR = CORBA::string_dup(ch.ToCString());
-    CORBA::Object_var obj = _orb->string_to_object(IOR);
-    SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
-    ASSERT(!CORBA::is_nil(Study));
-    return SALOMEDS::Study::_duplicate(Study); //return Study = abort...
-  }
-  MESSAGE("Problem GetStudy");
-  return SALOMEDS::Study::_nil();
+  SALOMEDS::Locker lock;
+  SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
+  return so._retn();
 }
 
 //============================================================================
@@ -134,15 +154,17 @@ SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
  *  Purpose  : Find attribute of given type on this SObject
  */
 //============================================================================
-CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute, 
-                                                 const char* aTypeOfAttribute)
+CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
+                                                  const char* aTypeOfAttribute)
 {
-  Handle(TDF_Attribute) anAttr;
-  if (_lab.FindAttribute(SALOMEDS_GenericAttribute_i::GetGUID(aTypeOfAttribute), anAttr)) {
-    anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(_orb, anAttr));
-    return Standard_True;
+  SALOMEDS::Locker lock;
+  DF_Attribute* anAttr = NULL;
+  if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
+    anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
+    return true;
   }
-  return Standard_False;
+
+  return false;
 }
 
 //============================================================================
@@ -153,17 +175,20 @@ CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out
 
 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
 {
-  Standard_Integer NumAttr = _lab.NbAttributes();
+  SALOMEDS::Locker lock;
+  std::vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
   SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
-  //SeqOfAttr->length(NumAttr);
-  if (NumAttr != 0) {
-    Standard_Integer i = 0;
-    for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) {
-      Handle(TDF_Attribute) anAttr = iter.Value();
-      SALOMEDS::GenericAttribute_var anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(_orb, anAttr);
+  int length = aSeq.size();
+
+  SeqOfAttr->length(length);
+
+  if (length != 0) {
+    for(int i = 0; i < length; i++) {
+      SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
+      SALOMEDS::GenericAttribute_var anAttribute;
+      anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
       if (!CORBA::is_nil(anAttribute)) {
-       SeqOfAttr->length(++i);
-       SeqOfAttr[i - 1] = anAttribute;
+        SeqOfAttr[i] = anAttribute;
       }
     }
   }
@@ -173,133 +198,166 @@ SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
 
 //============================================================================
 /*! Function : ReferencedObject
- *  Purpose  : 
+ *  Purpose  :
  */
 //============================================================================
 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
 {
-  Handle(TDF_Reference) Ref;
-  if (!_lab.FindAttribute(TDF_Reference::GetID(),Ref))
-    return false;
-  
-  SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (Ref->Get(),_orb);
-  obj  = SALOMEDS::SObject::_narrow(so_servant->_this()); 
+  SALOMEDS::Locker lock;
+  SALOMEDSImpl_SObject aRefObj;
+  if(!_impl->ReferencedObject(aRefObj)) return false;
+
+  obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
   return true;
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : FindSubObject
+ *  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)
 {
-  TDF_Label L = _lab.FindChild(atag,false);
-  if (L.IsNull()) return false;
-  
-  SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (L,_orb);
-  obj  = SALOMEDS::SObject::_narrow(so_servant->_this()); 
+  SALOMEDS::Locker lock;
+  SALOMEDSImpl_SObject aSubObj;
+  if(!_impl->FindSubObject(atag, aSubObj)) return false;
+
+  obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
   return true;
-    
-}  
+
+}
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : Name
+ *  Purpose  : gets a name
  */
 //============================================================================
 char* SALOMEDS_SObject_i::Name()
 {
-  return CORBA::string_dup(_name);
+  SALOMEDS::Locker lock;
+  return CORBA::string_dup(_impl->Name().c_str());
 }
-  
+
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : Name
+ *  Purpose  : sets a name
  */
 //============================================================================
 void  SALOMEDS_SObject_i::Name(const char* name)
 {
-  _name = CORBA::string_dup(name);
+  SALOMEDS::Locker lock;
+  std::string aName((char*)name);
+  _impl->Name(aName);
 }
-  
+
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : Tag
+ *  Purpose  :
  */
 //============================================================================
 CORBA::Short SALOMEDS_SObject_i::Tag()
 {
-  return _lab.Tag();
+  SALOMEDS::Locker lock;
+  return _impl->Tag();
+}
+
+//============================================================================
+/*! Function : GetLastChildTag
+ *  Purpose  :
+ */
+//============================================================================
+CORBA::Short SALOMEDS_SObject_i::GetLastChildTag()
+{
+  SALOMEDS::Locker lock;
+  return (CORBA::Short) _impl->GetLastChildTag();
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : Depth
+ *  Purpose  :
  */
 //============================================================================
 CORBA::Short SALOMEDS_SObject_i::Depth()
 {
-  return _lab.Depth();
+  SALOMEDS::Locker lock;
+  return _impl->Depth();
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetObject
+ *  Purpose  :
  */
 //============================================================================
 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
 {
+  SALOMEDS::Locker lock;
   CORBA::Object_ptr obj = CORBA::Object::_nil();
   try {
-    Handle(SALOMEDS_IORAttribute) Att;
-    if (_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)) {
-      TCollection_AsciiString ch(Att->Get());
-      char* IOR = CORBA::string_dup(ch.ToCString());
-      obj = _orb->string_to_object(IOR);
-    }
+    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(...) {}
   return obj;
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetName
+ *  Purpose  :
  */
 //============================================================================
-char* SALOMEDS_SObject_i::GetName() {
-  CORBA::String_var aStr = CORBA::string_dup( "" );
-  Handle(TDataStd_Name) aName;
-  if (_lab.FindAttribute(TDataStd_Name::GetID(), aName)) {
-    aStr = CORBA::string_dup(TCollection_AsciiString(aName->Get()).ToCString());
-  }
+char* SALOMEDS_SObject_i::GetName()
+{
+  SALOMEDS::Locker lock;
+  CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
   return aStr._retn();
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetComment
+ *  Purpose  :
  */
 //============================================================================
-char* SALOMEDS_SObject_i::GetComment() {
-  CORBA::String_var aStr = CORBA::string_dup( "" );
-  Handle(TDataStd_Comment) aComment;
-  if (_lab.FindAttribute(TDataStd_Comment::GetID(), aComment)) {
-    aStr = CORBA::string_dup(TCollection_AsciiString(aComment->Get()).ToCString());
-  }
+char* SALOMEDS_SObject_i::GetComment()
+{
+  SALOMEDS::Locker lock;
+  CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
   return aStr._retn();
 }
 
 //============================================================================
-/*! Function :
- *  Purpose  : 
+/*! Function : GetIOR
+ *  Purpose  :
  */
 //============================================================================
-char* SALOMEDS_SObject_i::GetIOR() {
-  CORBA::String_var aStr = CORBA::string_dup( "" );
-  Handle(SALOMEDS_IORAttribute) anIOR;
-  if (_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anIOR)) {
-    aStr = CORBA::string_dup(TCollection_AsciiString(anIOR->Get()).ToCString());
-  }
+char* SALOMEDS_SObject_i::GetIOR()
+{
+  SALOMEDS::Locker lock;
+  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
+//===========================================================================
+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, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
+  return reinterpret_cast<CORBA::LongLong>(_impl);
+}