Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM_I / MEDMEM_Support_i.cxx
index e94d16e4630fab55b348d02224335018042f9be6..6f2095724181f23154fd863b15f2901fd19e960c 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "MEDMEM_define.hxx"
 #include "MEDMEM_Support.hxx"
+#include "MEDMEM_Mesh.hxx"
 
 #include "MEDMEM_Support_i.hxx"
 #include "MEDMEM_Mesh_i.hxx"
@@ -161,35 +162,84 @@ throw (SALOME::SALOME_Exception)
 //=============================================================================
 
 SALOME_MED::SUPPORT::supportInfos * SUPPORT_i::getSupportGlobal()
-throw (SALOME::SALOME_Exception)
+  throw (SALOME::SALOME_Exception)
 {
-        if (_support==NULL)
-                THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
-                                             SALOME::INTERNAL_ERROR);
-        SALOME_MED::SUPPORT::supportInfos_var all = new SALOME_MED::SUPPORT::supportInfos;
-        try
-        {
-                all->name               = CORBA::string_dup(_support->getName().c_str());
-                all->description        = CORBA::string_dup(_support->getDescription().c_str());
-                const int numberOfTypes = _support->getNumberOfTypes();
-                all->numberOfGeometricType = numberOfTypes;
-               all->entity = _support->getEntity();
-               all->isOnAllElements    = _support->isOnAllElements();
-                all->types.length(numberOfTypes);
-                all->nbEltTypes.length(numberOfTypes);
-                const medGeometryElement * elemts = _support->getTypes();
-                for (int i=0;i<numberOfTypes;i++)
-                {
-                        all->types[i]      = convertMedEltToIdlElt(elemts[i]);
-                        all->nbEltTypes[i] = _support->getNumberOfElements(elemts[i]);
-                }
+  if (_support==NULL)
+    THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
+                                 SALOME::INTERNAL_ERROR);
+  SALOME_MED::SUPPORT::supportInfos_var all = new SALOME_MED::SUPPORT::supportInfos;
+  try
+  {
+    all->name               = CORBA::string_dup(_support->getName().c_str());
+    all->description        = CORBA::string_dup(_support->getDescription().c_str());
+    const int numberOfTypes = _support->getNumberOfTypes();
+    all->numberOfGeometricType = numberOfTypes;
+    all->entity = _support->getEntity();
+    all->isOnAllElements    = _support->isOnAllElements();
+    all->types.length(numberOfTypes);
+    all->nbEltTypes.length(numberOfTypes);
+    all->nodalConnectivityLength.length(numberOfTypes);
+    const medGeometryElement * types = _support->getTypes();
+    for (int i=0;i<numberOfTypes;i++)
+    {
+      int nbelements = _support->getNumberOfElements(types[i]);
+      int connLength = 0;
+      MESH* mesh = _support->getMesh();
+      switch ( types[i] )
+      {
+      case MED_EN::MED_POLYGON: {
+        if (_support->isOnAllElements() ) {
+          connLength = mesh->getPolygonsConnectivityLength(MED_EN::MED_NODAL,
+                                                           _support->getEntity());
         }
-        catch (MEDEXCEPTION &ex)
-        {
-                MESSAGE("Unable to access the description of the support ");
-                THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+        else {
+          const int * index = mesh->getPolygonsConnectivityIndex(MED_EN::MED_NODAL,
+                                                                 _support->getEntity());
+          const int * numbers=_support->getNumber(types[i]);
+          int canonicNb = mesh->getNumberOfElements(_support->getEntity(),
+                                                    MED_EN::MED_ALL_ELEMENTS);
+          for (int j=0;j<nbelements;j++)
+          {
+            int elem = numbers[j]-canonicNb-1;
+            connLength += index[ elem+1 ] - index[ elem ];
+          }
+        }
+        break;
+      }
+      case MED_EN::MED_POLYHEDRA: {
+        if (_support->isOnAllElements() ) {
+          connLength = mesh->getPolyhedronConnectivityLength(MED_EN::MED_NODAL);
         }
-        return all._retn();
+        else {
+          const int * index = mesh->getPolyhedronIndex(MED_EN::MED_NODAL);
+          const int * faceIndex = mesh->getPolyhedronFacesIndex();
+          const int * numbers=_support->getNumber(types[i]);
+          int canonicNb = mesh->getNumberOfElements(_support->getEntity(),
+                                                    MED_EN::MED_ALL_ELEMENTS);
+          for (int j=0;j<nbelements;j++)
+          {
+            int elem = numbers[j]-canonicNb-1 ;
+            int f1 = index[ elem ]-1,   f2 = index[ elem+1 ]-2;
+            int i1 = faceIndex[ f1 ]-1, i2 = faceIndex[ f2+1 ]-1;
+            connLength += i2 - i1;
+          }
+        }
+        break;
+      }
+      default:
+        connLength = nbelements * ( types[i] % 100 );
+      }
+      all->types[i]                   = convertMedEltToIdlElt(types[i]);
+      all->nbEltTypes[i]              = nbelements;
+      all->nodalConnectivityLength[i] = connLength;
+    }
+  }
+  catch (MEDEXCEPTION &ex)
+  {
+    MESSAGE("Unable to access the description of the support ");
+    THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+  }
+  return all._retn();
 
 }
 
@@ -215,7 +265,7 @@ throw (SALOME::SALOME_Exception)
                SCRUTE(mesh) ;
 
                MESH_i * m1 = new MESH_i(mesh);
-               SALOME_MED::MESH_ptr m2 = m1->POA_SALOME_MED::MESH::_this();
+               SALOME_MED::MESH_ptr m2 = m1->_this();
                MESSAGE("SALOME_MED::MESH_ptr SUPPORT_i::getMesh() checking des pointeurs CORBA");
 
                SCRUTE(m1);
@@ -404,6 +454,45 @@ SCRUTE(numbers[i]);
        
 }
 
+//=============================================================================
+/*!
+ * CORBA: get Nodes from file
+ */
+//=============================================================================
+SALOME_MED::long_array *  SUPPORT_i::getNumberFromFile(SALOME_MED::medGeometryElement geomElement) 
+throw (SALOME::SALOME_Exception)
+{
+  SCRUTE(_support);
+  SCRUTE(geomElement);
+  SCRUTE(convertIdlEltToMedElt(geomElement));
+
+       if (_support==NULL)
+               THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
+                                            SALOME::INTERNAL_ERROR);
+        SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
+        try
+        {
+                int nbelements=_support->getNumberOfElements(convertIdlEltToMedElt(geomElement));
+                myseq->length(nbelements);
+SCRUTE(_support->getName());
+SCRUTE(nbelements);
+SCRUTE(convertIdlEltToMedElt(geomElement));
+                const int * numbers=_support->getNumberFromFile(convertIdlEltToMedElt(geomElement));
+                for (int i=0;i<nbelements;i++)
+                {
+                        myseq[i]=numbers[i];
+SCRUTE(numbers[i]);
+                }
+        }
+        catch (MEDEXCEPTION &ex)
+        {
+               MESSAGE("Unable to access the support optionnal index");
+               THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
+        }
+        return myseq._retn();
+       
+}
+
 //=============================================================================
 /*!
  * CORBA: 2nd get Nodes 
@@ -512,14 +601,13 @@ throw (SALOME::SALOME_Exception)
         {
                 (const_cast< ::SUPPORT *>(_support))->getBoundaryElements();
         }
-        catch (MEDEXCEPTION &ex)
+        catch (MEDEXCEPTION &)
         {
                 MESSAGE("Unable to access elements");
                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
                                                 ,SALOME::INTERNAL_ERROR);
         }
 }
-
 //=============================================================================
 /*!
  * CORBA: add the Support in the StudyManager 
@@ -569,7 +657,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
   }
   MESSAGE(LOC << " Find SObject MESH (represent mesh in support)");
 
-  string meshName = getMesh()->getName() ;
+  string meshName = _support->getMesh()->getName() ;
   string meshNameStudy = meshName;
 
   for (string::size_type pos=0; pos<meshNameStudy.size();++pos)
@@ -583,7 +671,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
     THROW_SALOME_CORBA_EXCEPTION("SObject Mesh in Support not Found",SALOME::INTERNAL_ERROR);
   // perhaps add MESH automatically ?
   
-  MESSAGE("Add a support Object under /MED/MESH/MESHNAME");
+  MESSAGE("Add a support Object under /Med/MESH/MESHNAME");
 
   char * medsupfatherName;
   int lenName = 15 + strlen(meshName.c_str()) + 1;
@@ -606,28 +694,11 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
 
   //myBuilder->NewCommand();
 
-  string supportName = _support->getName();
-
-  SCRUTE(supportName);
-
-  SCRUTE(meshNameStudy);
+  string supportEntryPath = getEntryPath( _support );
 
-  char * supportEntryPath;
-  lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str())+1;
-  supportEntryPath = new char[lenName];
-  supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/");
-  supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_");
-  supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str());
-  supportEntryPath = strcat(supportEntryPath,"/");
-  supportEntryPath = strcat(supportEntryPath,supportName.c_str());
+  SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath.c_str());
 
-  //SCRUTE(supportEntryPath);
 
-  MESSAGE("supportEntryPath in support " << supportEntryPath << " length " << lenName);
-
-//   SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str());
-                        // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!!
-  SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath);
 
   if ( CORBA::is_nil(supportEntry) ) 
   {
@@ -637,10 +708,10 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
     CORBA::ORB_var &orb = init(0,0);
-    string iorStr = orb->object_to_string(myIor);
+    CORBA::String_var iorStr = orb->object_to_string(myIor);
     anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
     aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-    aIOR->SetValue(iorStr.c_str());
+    aIOR->SetValue(iorStr.in());
     anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
     aName = SALOMEDS::AttributeName::_narrow(anAttr);
     aName->SetValue(_support->getName().c_str());
@@ -652,14 +723,14 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
     CORBA::ORB_var &orb = init(0,0);
-    string iorStr = orb->object_to_string(myIor);
+    CORBA::String_var iorStr = orb->object_to_string(myIor);
     anAttr = myBuilder->FindOrCreateAttribute(supportEntry, "AttributeIOR");
     aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-    aIOR->SetValue(iorStr.c_str());
+    aIOR->SetValue(iorStr.in());
   }
   myBuilder->CommitCommand();
 
-  SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath);
+  SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath.c_str());
 
   MESSAGE("Just for checking, reuse of the corba pointer");
 
@@ -673,7 +744,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
     }
 
   delete [] medsupfatherName;
-  delete [] supportEntryPath;
+
 
   // register the Corba pointer: increase the referrence count
   MESSAGE("Registering of the Corba Support pointer");
@@ -681,3 +752,23 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr
 
   END_OF(LOC);
 }
+
+//=======================================================================
+//function : getEntryPath
+//purpose  : 
+//=======================================================================
+  
+string SUPPORT_i::getEntryPath(const ::MEDMEM::SUPPORT * aSupport)
+{
+  string meshNameStudy( aSupport->getMeshName() );
+  for (string::size_type pos=0; pos<meshNameStudy.size();++pos)
+    if (isspace(meshNameStudy[pos])) meshNameStudy[pos] = '_';
+
+  string supportName = aSupport->getName();
+  string supportNameStudy( supportName.c_str(), strlen( supportName.c_str() ));
+  string supportEntryPath =
+    "/Med/MEDMESH/MEDSUPPORTS_OF_" + meshNameStudy + "/" + supportNameStudy;
+  SCRUTE( supportEntryPath );
+
+  return supportEntryPath;
+}