Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDMEM_I / MEDMEM_Mesh_i.cxx
index e42e214b39bd9aa40251524012e550dc7ea6c285..70a47184a9b49a199581ed14a509f0a0c82f37f0 100644 (file)
@@ -24,6 +24,9 @@
 #include "MEDMEM_Family.hxx"
 #include "MEDMEM_Group.hxx"
 #include "MEDMEM_CellModel.hxx"
+
+#include "SenderFactory.hxx"
+#include "MultiCommException.hxx"
 using namespace MEDMEM;
 
 // Initialisation des variables statiques
@@ -241,7 +244,7 @@ throw (SALOME::SALOME_Exception)
  * CORBA: Accessor for a specific coordinate
  */
 //=============================================================================
-double MESH_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
+CORBA::Double MESH_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
 throw (SALOME::SALOME_Exception)
 {
         if (_mesh==NULL)
@@ -290,6 +293,34 @@ throw (SALOME::SALOME_Exception)
        return myseq._retn();
 }
 //=============================================================================
+/*!
+ * CORBA: 2nd Accessor for Coordinates
+ */
+//=============================================================================
+SALOME::SenderDouble_ptr MESH_i::getSenderForCoordinates(SALOME_MED::medModeSwitch typeSwitch)
+    throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  SALOME::SenderDouble_ptr ret;
+  try
+    {
+      int spaceDimension=_mesh->getSpaceDimension();
+      int nbNodes=_mesh->getNumberOfNodes();
+      const double * coordinates =_mesh->getCoordinates(convertIdlModeToMedMode(typeSwitch));
+      ret=SenderFactory::buildSender(*this,coordinates,nbNodes*spaceDimension);
+    }
+  catch (MEDEXCEPTION &ex)
+    {       
+      MESSAGE("Unable to acces the coordinates");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+//=============================================================================
 /*!
  * CORBA: Accessor for Coordinates Names
  */
@@ -539,6 +570,197 @@ SCRUTE(nbelements);
         }
         return myseq._retn();
 }
+//=============================================================================
+/*!
+ * CORBA: 2nd Accessor for connectivities
+ */
+//=============================================================================
+SALOME::SenderInt_ptr MESH_i::getSenderForConnectivity(SALOME_MED::medModeSwitch typeSwitch,
+                                              SALOME_MED::medConnectivity mode, 
+                                              SALOME_MED::medEntityMesh entity, 
+                                              SALOME_MED::medGeometryElement geomElement)
+throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  if (verifieParam(entity,geomElement)==false)
+    THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
+                                SALOME::BAD_PARAM);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements=_mesh->getConnectivityLength(convertIdlModeToMedMode(typeSwitch),
+                                                convertIdlConnToMedConn(mode),
+                                                convertIdlEntToMedEnt(entity),
+                                                convertIdlEltToMedElt(geomElement));
+      const int * numbers=_mesh->getConnectivity(convertIdlModeToMedMode(typeSwitch),
+                                                convertIdlConnToMedConn(mode),
+                                                convertIdlEntToMedEnt(entity),
+                                                convertIdlEltToMedElt(geomElement));
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
+//=======================================================================
+//function : getSenderForPolygonsConnectivity
+//purpose  : 
+//=======================================================================
+
+SALOME::SenderInt_ptr MESH_i::getSenderForPolygonsConnectivity(SALOME_MED::medConnectivity mode,
+                                                               SALOME_MED::medEntityMesh entity)
+  throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  if (verifieParam(entity,SALOME_MED::MED_POLYGON)==false)
+    THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
+                                SALOME::BAD_PARAM);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements = _mesh->getPolygonsConnectivityLength(convertIdlConnToMedConn(mode),
+                                                            convertIdlEntToMedEnt(entity));
+      const int * numbers=_mesh->getPolygonsConnectivity (convertIdlConnToMedConn(mode),
+                                                          convertIdlEntToMedEnt(entity));
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
+//=======================================================================
+//function : getSenderForPolygonsConnectivityIndex
+//purpose  : 
+//=======================================================================
+
+SALOME::SenderInt_ptr MESH_i::getSenderForPolygonsConnectivityIndex(SALOME_MED::medConnectivity mode,
+                                                            SALOME_MED::medEntityMesh entity)
+      throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  if (verifieParam(entity,SALOME_MED::MED_POLYGON)==false)
+    THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
+                                SALOME::BAD_PARAM);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements = _mesh->getNumberOfPolygons() + 1;
+      const int * numbers=_mesh->getPolygonsConnectivityIndex (convertIdlConnToMedConn(mode),
+                                                               convertIdlEntToMedEnt(entity));
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
+//=======================================================================
+//function : getSenderForPolyhedronConnectivity
+//purpose  : 
+//=======================================================================
+
+SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronConnectivity(SALOME_MED::medConnectivity mode)
+    throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements = _mesh->getPolyhedronConnectivityLength(convertIdlConnToMedConn(mode));
+      const int * numbers=_mesh->getPolyhedronConnectivity( convertIdlConnToMedConn(mode) );
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
+//=======================================================================
+//function : getSenderForPolyhedronIndex
+//purpose  : 
+//=======================================================================
+
+SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronIndex(SALOME_MED::medConnectivity mode)
+    throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements = _mesh->getNumberOfPolyhedron() + 1;
+      const int * numbers = _mesh->getPolyhedronIndex( convertIdlConnToMedConn( mode ) );
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
+//=======================================================================
+//function : getSenderForPolyhedronFacesIndex
+//purpose  : 
+//=======================================================================
+
+SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronFacesIndex()
+    throw (SALOME::SALOME_Exception)
+{
+  if (_mesh==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
+                                SALOME::INTERNAL_ERROR);
+  SALOME::SenderInt_ptr ret;
+  try
+    {
+      int nbelements = _mesh->getNumberOfPolyhedronFaces() + 1;
+      const int * numbers=_mesh->getPolyhedronFacesIndex();
+      ret=SenderFactory::buildSender(*this,numbers,nbelements);
+    }
+  catch (MEDEXCEPTION &ex)
+    {
+      MESSAGE("Unable to acces connectivities");
+      THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+    }
+  catch(MultiCommException &ex2)
+    THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
+  return ret;
+}
+
 //=============================================================================
 /*!
  * CORBA: Accessor for connectivities
@@ -649,15 +871,7 @@ throw (SALOME::SALOME_Exception)
         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
         try
         {
-                int nbelements; 
-               if ( mode == SALOME_MED::MED_DESCENDING)
-               {
-                  nbelements =(_mesh->getNumberOfNodes())+1;
-               }
-               else
-               {
-                  nbelements = _mesh->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS);
-               }
+                int nbelements=_mesh->getReverseConnectivityLength(convertIdlConnToMedConn(mode));
                SCRUTE(nbelements);
                 myseq->length(nbelements);
                 const int * numbers=_mesh->getReverseConnectivity(convertIdlConnToMedConn(mode));
@@ -687,24 +901,7 @@ throw (SALOME::SALOME_Exception)
         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
         try
         {
-                int nbelements; 
-               if ( mode == SALOME_MED::MED_DESCENDING)
-               {
-                  nbelements =_mesh->getNumberOfNodes();
-               }
-               else
-               {
-                  int dim=_mesh->getMeshDimension();
-                  if ( dim == 3)       
-                       nbelements = _mesh->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS);
-                  else
-                  if (dim == 2)        
-                       nbelements = _mesh->getNumberOfElements(MED_EDGE,MED_ALL_ELEMENTS);
-                  else
-                       THROW_SALOME_CORBA_EXCEPTION("Pb ", \
-                                             SALOME::INTERNAL_ERROR);
-               }
-
+                int nbelements=_mesh->getReverseConnectivityIndexLength(convertIdlConnToMedConn(mode));
                 myseq->length(nbelements);
                 const int * numbers=_mesh->getReverseConnectivityIndex(convertIdlConnToMedConn(mode));
                 for (int i=0;i<nbelements;i++)
@@ -782,10 +979,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbfam;i++)
                 {
                         FAMILY_i * f1=new FAMILY_i(fam[i]);
-                        SALOME_MED::FAMILY_ptr f2 =
-                                        f1->POA_SALOME_MED::FAMILY::_this();
-                        f1->_remove_ref();
-                        myseq[i] = f2;
+                        myseq[i] = f1->POA_SALOME_MED::FAMILY::_this();
                 }
         }
         catch (MEDEXCEPTION &ex)
@@ -847,15 +1041,16 @@ throw (SALOME::SALOME_Exception)
         {
                 all->numberOfNodes  = _mesh->getNumberOfNodes();
 
-                int nbTypes=_mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
-                const medGeometryElement * elemts  =_mesh->getTypes(
+                int nbTypes=_mesh->getNumberOfTypesWithPoly(convertIdlEntToMedEnt(entity));
+                const medGeometryElement * elemts  =_mesh->getTypesWithPoly(
                                        convertIdlEntToMedEnt(entity));
                 all->meshTypes.length(nbTypes);
                 all->numberOfElements.length(nbTypes);
+               all->entityDimension=_mesh->getConnectivityptr()->getEntityDimension();
                 for (int i=0; i<nbTypes; i++)
                 {
                         all->meshTypes[i]=convertMedEltToIdlElt(elemts[i]);
-                        all->numberOfElements[i]=_mesh->getNumberOfElements(
+                        all->numberOfElements[i]=_mesh->getNumberOfElementsWithPoly(
                                        convertIdlEntToMedEnt(entity),elemts[i]);
                 }
         }
@@ -883,9 +1078,7 @@ throw (SALOME::SALOME_Exception)
         {
                 const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i);
                 FAMILY_i * f1=new FAMILY_i(fam);
-                SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FAMILY::_duplicate(f2));
+               return f1->POA_SALOME_MED::FAMILY::_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -921,9 +1114,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbFam;i++)
                 {
                         FAMILY_i * f1=new FAMILY_i(vNode[i]);
-                        SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
-                        f1->_remove_ref();
-                        all->famNode[i] = f2;
+                        all->famNode[i] = f1->POA_SALOME_MED::FAMILY::_this();
                 }
 
                 nbFam = _mesh->getNumberOfFamilies(MED_EDGE);
@@ -934,9 +1125,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbFam;i++)
                 {
                         FAMILY_i * f1=new FAMILY_i(vEdge[i]);
-                        SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
-                        f1->_remove_ref();
-                        all->famEdge[i] = f2;
+                        all->famEdge[i] = f1->POA_SALOME_MED::FAMILY::_this();
                 }
 
                 nbFam = _mesh->getNumberOfFamilies(MED_FACE);
@@ -946,9 +1135,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbFam;i++)
                 {
                         FAMILY_i * f1=new FAMILY_i(vFace[i]);
-                        SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
-                        f1->_remove_ref();
-                        all->famFace[i] = f2;
+                        all->famFace[i] = f1->POA_SALOME_MED::FAMILY::_this();
                 }
 
                 nbFam = _mesh->getNumberOfFamilies(MED_CELL);
@@ -958,9 +1145,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbFam;i++)
                 {
                         FAMILY_i * f1=new FAMILY_i(vCell[i]);
-                        SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
-                        f1->_remove_ref();
-                        all->famCell[i] = f2;
+                        all->famCell[i] = f1->POA_SALOME_MED::FAMILY::_this();
                 }
 
                 int nbGroup = _mesh->getNumberOfGroups(MED_NODE);
@@ -970,9 +1155,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbGroup;i++)
                 {
                         GROUP_i * f1=new GROUP_i(gNode[i]);
-                        SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                        f1->_remove_ref();
-                        all->groupNode[i] = f2;
+                        all->groupNode[i] = f1->POA_SALOME_MED::GROUP::_this();
                 }
 
                 nbGroup = _mesh->getNumberOfGroups(MED_EDGE);
@@ -982,9 +1165,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbGroup;i++)
                 {
                         GROUP_i * f1=new GROUP_i(gEdge[i]);
-                        SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                        f1->_remove_ref();
-                        all->groupEdge[i] = f2;
+                        all->groupEdge[i] = f1->POA_SALOME_MED::GROUP::_this();
                 }
                 nbGroup = _mesh->getNumberOfGroups(MED_FACE);
                 all->groupFace.length(nbGroup);
@@ -993,9 +1174,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbGroup;i++)
                 {
                         GROUP_i * f1=new GROUP_i(gFace[i]);
-                        SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                        f1->_remove_ref();
-                        all->groupFace[i] = f2;
+                        all->groupFace[i] = f1->POA_SALOME_MED::GROUP::_this();
                 }
 
                 nbGroup = _mesh->getNumberOfGroups(MED_CELL);
@@ -1005,9 +1184,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbGroup;i++)
                 {
                         GROUP_i * f1=new GROUP_i(gCell[i]);
-                        SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                        f1->_remove_ref();
-                        all->groupCell[i] = f2;
+                        all->groupCell[i] = f1->POA_SALOME_MED::GROUP::_this();
                 }
 
         }
@@ -1039,9 +1216,7 @@ throw (SALOME::SALOME_Exception)
                 for (int i=0;i<nbgroups;i++)
                 {
                        GROUP_i * f1=new GROUP_i(groups[i]);
-                       SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                        f1->_remove_ref();
-                        myseq[i] = f2;
+                        myseq[i] = f1->POA_SALOME_MED::GROUP::_this();
                 }
         }
         catch (MEDEXCEPTION &ex)
@@ -1067,9 +1242,7 @@ throw (SALOME::SALOME_Exception)
         {
                 const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i);
                 GROUP_i * f1=new GROUP_i(grou);
-                SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
-                f1->_remove_ref();
-               return (SALOME_MED::GROUP::_duplicate(f2));
+               return f1->POA_SALOME_MED::GROUP::_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1092,8 +1265,7 @@ throw (SALOME::SALOME_Exception)
         {
                 SUPPORT * myNewSupport = _mesh->getBoundaryElements(convertIdlEntToMedEnt(entity));
                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
-                SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this() ;
-                return (SALOME_MED::SUPPORT::_duplicate(mySupportIOR));
+                return mySupportI->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1117,12 +1289,8 @@ throw (SALOME::SALOME_Exception)
                ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
                const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 ::FIELD<double>*f=_mesh->getVolume( myCppSupport);
-               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
-               POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
-                   new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
-               SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FIELD::_duplicate(f2));
+               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(f);
+               return medf->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1148,8 +1316,7 @@ throw (SALOME::SALOME_Exception)
                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 SUPPORT * myNewSupport = _mesh->getSkin(myCppSupport);
                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
-                SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this() ;
-                return (SALOME_MED::SUPPORT::_duplicate(mySupportIOR));
+                return mySupportI->_this() ;
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1174,12 +1341,8 @@ throw (SALOME::SALOME_Exception)
                ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
                const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 ::FIELD<double>*f=_mesh->getArea( myCppSupport);
-               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
-               POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
-                   new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
-               SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FIELD::_duplicate(f2));
+               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(f);
+               return medf->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1204,12 +1367,8 @@ throw (SALOME::SALOME_Exception)
                ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
                const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 ::FIELD<double>*f=_mesh->getLength( myCppSupport);
-               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
-               POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
-                   new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
-               SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FIELD::_duplicate(f2));
+               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(f);
+               return medf->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1234,12 +1393,8 @@ throw (SALOME::SALOME_Exception)
                ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
                const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 ::FIELD<double>*f=_mesh->getNormal( myCppSupport);
-               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
-               POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
-                   new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
-               SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FIELD::_duplicate(f2));
+               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(f);
+               return medf->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1264,12 +1419,8 @@ throw (SALOME::SALOME_Exception)
                ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
                const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
                 ::FIELD<double>*f=_mesh->getBarycenter( myCppSupport);
-               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
-               POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
-                   new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
-               SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
-                f1->_remove_ref();
-               return (SALOME_MED::FIELD::_duplicate(f2));
+               FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(f);
+               return medf->_this();
         }
         catch (MEDEXCEPTION &ex)
         {
@@ -1318,17 +1469,26 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
          THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
 
        // Create SObject labelled 'MESH' if it doesn't already exit
-       SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
+//     SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
+//     if ( CORBA::is_nil(medmeshfather) ) 
+//     {
+//                     MESSAGE("Add Object MEDMESH");
+//                     medmeshfather = myBuilder->NewObject(medfather);
+//             //medmeshfather.Name = "MEDMESH" ;
+//                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
+//                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
+//                 aName->SetValue("MEDMESH");
+
+//     } ;
+
+       SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath("/Med/MEDMESH");
        if ( CORBA::is_nil(medmeshfather) ) 
-       {
-               MESSAGE("Add Object MEDMESH");
-               medmeshfather = myBuilder->NewObject(medfather);
-               //medmeshfather.Name = "MEDMESH" ;
-                anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
-                aName = SALOMEDS::AttributeName::_narrow(anAttr);
-                aName->SetValue("MEDMESH");
+         {
+           MESSAGE("Add Object MEDMESH");
 
-       } ;
+           myBuilder->AddDirectory("/Med/MEDMESH");
+            medmeshfather = myStudy->FindObjectByPath("/Med/MEDMESH");
+         } ;
 
        MESSAGE("Add a mesh Object under MED/MEDMESH");
        SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
@@ -1346,6 +1506,10 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
        _meshId = newObj->GetID();
        myBuilder->CommitCommand();
 
+       // register the Corba pointer: increase the referrence count
+       MESSAGE("Registering of the Corba Mesh pointer");
+       Register();
+
        END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
 }
 //=============================================================================
@@ -1408,6 +1572,10 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
         _meshId = newObj->GetID();
         myBuilder->CommitCommand();
 
+       // register the Corba pointer: increase the referrence count
+       MESSAGE("Registering of the Corba Mesh pointer");
+       Register();
+
         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
 }
 //=============================================================================
@@ -1504,3 +1672,25 @@ throw (SALOME::SALOME_Exception)
         }
 }
 
+//=============================================================================
+/*!
+ * CORBA : Test if this and other aggregate the same MESH using the MESH::operator==
+ */
+//=============================================================================
+CORBA::Boolean MESH_i::areEquals(SALOME_MED::MESH_ptr other)
+{
+  PortableServer::ServantBase *baseServ;
+  try {
+    baseServ=_default_POA()->reference_to_servant(other);
+  }
+  catch(...){
+    baseServ=0;
+  }
+  if(baseServ)
+    {
+     baseServ->_remove_ref();
+     MESH_i *otherServ=dynamic_cast<MESH_i *>(baseServ);
+     return *_mesh==*otherServ->_mesh;
+    }
+  return false;
+}