Salome HOME
a test.
[tools/medcoupling.git] / src / MEDLoader / MEDFileMesh.cxx
index b68a6fa748d6386d5d7d9e30410e66cb6c171d03..90375565ad85666a92bd45a143b6840813e3dbde 100644 (file)
@@ -4001,6 +4001,8 @@ std::vector<const BigMemoryObject *> MEDFileStructuredMesh::getDirectChildren()
     ret.push_back((const DataArrayAsciiChar *)_names_faces);
   if((const DataArrayInt *)_rev_num_cells)
     ret.push_back((const DataArrayInt *)_rev_num_cells);
+  if((const MEDCoupling1SGTUMesh*)_faces_if_necessary)
+    ret.push_back((const MEDCoupling1SGTUMesh*)_faces_if_necessary);
   return ret;
 }
 
@@ -4698,7 +4700,11 @@ MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, b
       {
         if(!m)
           throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGenMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
-        return _faces_if_necessary;
+        buildMinusOneImplicitPartIfNeeded();
+        MEDCouplingMesh *ret(_faces_if_necessary);
+        if(ret)
+          ret->incrRef();
+        return ret;
       }
     default:
       throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support multi level for mesh 0 expected as input !");
@@ -4754,9 +4760,8 @@ int MEDFileStructuredMesh::buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellT
       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension())));
       if(cm.getReverseExtrudedType()!=gt)
         throw INTERP_KERNEL::Exception(MSG);
-      const MEDCouplingStructuredMesh *mcmesh(getStructuredMesh());
-      _faces_if_necessary=mcmesh->build1SGTSubLevelMesh();
-      return mcmesh->getNumberOfCellsOfSubLevelMesh();
+      buildImplicitPart();
+      return getStructuredMesh()->getNumberOfCellsOfSubLevelMesh();
     }
   else
     {
@@ -4766,6 +4771,21 @@ int MEDFileStructuredMesh::buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellT
     }
 }
 
+void MEDFileStructuredMesh::buildMinusOneImplicitPartIfNeeded() const
+{
+  const MEDCoupling1SGTUMesh *zeFaceMesh(_faces_if_necessary);
+  if(!zeFaceMesh)
+    buildImplicitPart();
+}
+
+void MEDFileStructuredMesh::buildImplicitPart() const
+{
+  const MEDCouplingStructuredMesh *mcmesh(getStructuredMesh());
+  if(!mcmesh)
+    throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::buildImplicitPart : Unable to build the implicit part of structured mesh because no structured mesh at level 0 defined !");
+  _faces_if_necessary=mcmesh->build1SGTSubLevelMesh();
+}
+
 void MEDFileStructuredMesh::releaseImplicitPartIfAny() const
 {
   _faces_if_necessary=0;