Salome HOME
22612: [CEA 1189] sauv2med should not change faces orientation
[tools/medcoupling.git] / src / MEDLoader / SauvMedConvertor.cxx
index f9dd4f6d5188e7dc8ac28e26cec1b5952ce9ee8b..a8fb6db55e41d3a29d97ffa8d72c7f047a9b6a9a 100644 (file)
@@ -2373,12 +2373,14 @@ Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsTo
 //================================================================================
 /*!
  * \brief Makes ParaMEDMEM::MEDFileData from self
+ *  \param [in] fix2DOri - to fix or not orientation of faces in 3D space
+ *  \return ParaMEDMEM::MEDFileData* - conversion result
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
+ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS(bool fix2DOri)
 {
-  MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh >  mesh   = makeMEDFileMesh();
+  MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh >  mesh   = makeMEDFileMesh(fix2DOri);
   MEDCouplingAutoRefCountObjectPtr< MEDFileFields > fields = makeMEDFileFields(mesh);
 
   MEDCouplingAutoRefCountObjectPtr< MEDFileMeshes > meshes = MEDFileMeshes::New();
@@ -2396,7 +2398,7 @@ ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
+ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh(bool fix2DOri)
 {
   // check if all needed piles are present
   checkDataAvailability();
@@ -2408,7 +2410,7 @@ ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
   if ( _spaceDim == 2 || _spaceDim == 1 )
     orientElements2D();
   else if ( _spaceDim == 3 )
-    orientElements3D();
+    orientElements3D( fix2DOri );
 
   // process groups
   decreaseHierarchicalDepthOfSubgroups();
@@ -2728,10 +2730,11 @@ void IntermediateMED::orientElements2D()
  */
 //================================================================================
 
-void IntermediateMED::orientElements3D()
+void IntermediateMED::orientElements3D(bool fix2DOri)
 {
   // set _reverse flags of faces
-  orientFaces3D();
+  if ( fix2DOri )
+    orientFaces3D();
 
   // -----------------
   // fix connectivity
@@ -3238,10 +3241,10 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
           grp._medGroup = DataArrayInt::New();
           grp._medGroup->setName( grp._name.c_str() );
           grp._medGroup->alloc( cell2order.size(), /*nbOfCompo=*/1 );
-          int * idsPrt = grp._medGroup->getPointer();
+          int * idsPtr = grp._medGroup->getPointer();
           TCellToOrderMap::iterator cell2orderIt, cell2orderEnd = cell2order.end();
           for ( cell2orderIt = cell2order.begin(); cell2orderIt != cell2orderEnd; ++cell2orderIt )
-            *idsPrt++ = (*cell2orderIt).first->_number - 1;
+            *idsPtr++ = (*cell2orderIt).first->_number - 1;
 
           // try to set the mesh name
           if ( !isMeshNameSet &&
@@ -3285,16 +3288,17 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
   int dim = getDim( grp );
 
   int nbElems = 0;
-  CellsByDimIterator dimCells( *this, dim );
-  while ( const std::set<Cell > * cells = dimCells.nextType() )
-    nbElems += cells->size();
-
-  const bool onAll = ( nbElems == grp->size() );
-
   if ( dim == 0 )
-    dimRel = 0;
+    {
+      nbElems = _nbNodes;
+      dimRel  = 0;
+    }
   else
     {
+      CellsByDimIterator dimCells( *this, dim );
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        nbElems += cells->size();
+
       int meshDim = 3;
       for ( ; meshDim > 0; --meshDim )
         {
@@ -3304,6 +3308,8 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
         }
       dimRel = dim - meshDim;
     }
+
+  bool onAll = ( nbElems == grp->size() );
   return onAll;
 }
 
@@ -3432,7 +3438,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
       DataArrayDouble * coo = mesh->getCoords();
       MEDCouplingAutoRefCountObjectPtr
         <DataArrayDouble> subCoo = coo->selectByTupleId(support->_medGroup->begin(),
-                                                        support->_medGroup->end()); 
+                                                        support->_medGroup->end());
       MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh =
         MEDCouplingUMesh::Build0DMeshFromCoords( subCoo );
       timeStamp->setMesh( nodeSubMesh );
@@ -3454,8 +3460,9 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   // set gauss points
   if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT )
     {
-      TGaussDef gaussDef( support->_cellType, fld->_sub[iSub].nbGauss() );
-      timeStamp->setGaussLocalizationOnType( support->_cellType,
+      TGaussDef gaussDef( fld->_sub[iSub]._support->_cellType,
+                          fld->_sub[iSub].nbGauss() );
+      timeStamp->setGaussLocalizationOnType( fld->_sub[iSub]._support->_cellType,
                                              gaussDef.myRefCoords,
                                              gaussDef.myCoords,
                                              gaussDef.myWeights );