Salome HOME
#16559 EDF - Changes to the Concatenate function: non regression test fails
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index 031128e2965c245723f29088ce8509c964b5ba04..660c3e69f94115e98824b30ace7a2e3f83f7da20 100644 (file)
@@ -521,11 +521,10 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
 
   // Reading groups (sub-meshes are out of scope of MED import functionality)
   std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
-  int anId;
   std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
   for ( ; name_type != aGroupNames.end(); name_type++ )
   {
-    SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
+    SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str() );
     if ( aGroup ) {
       SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
       if ( aGroupDS ) {
@@ -1407,35 +1406,40 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
  *              The major version (x, where version is x.y.z) cannot be changed.
  *  \param [in] meshPart - mesh data to export
  *  \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
    *         - 1D if all mesh nodes lie on OX coordinate axis, or
    *         - 2D if all mesh nodes lie on XOY coordinate plane, or
    *         - 3D in the rest cases.
    *         If \a theAutoDimension is \c false, the space dimension is always 3.
*              - 1D if all mesh nodes lie on OX coordinate axis, or
*              - 2D if all mesh nodes lie on XOY coordinate plane, or
*              - 3D in the rest cases.
*              If \a theAutoDimension is \c false, the space dimension is always 3.
  *  \param [in] theAddODOnVertices - to create 0D elements on all vertices
  *  \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
+ *  \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
+ *              within a given tolerance, the coordinate is set to zero.
+ *              If \a ZTolerance is negative, the node coordinates are kept as is.
  *  \return int - mesh index in the file
  */
 //================================================================================
 
-void SMESH_Mesh::ExportMED(const char *        file, 
-                           const char*         theMeshName, 
+void SMESH_Mesh::ExportMED(const char *        file,
+                           const char*         theMeshName,
                            bool                theAutoGroups,
-                           int                 theMinor,
+                           int                 theVersion,
                            const SMESHDS_Mesh* meshPart,
                            bool                theAutoDimension,
                            bool                theAddODOnVertices,
+                           double              theZTolerance,
                            bool                theAllElemsToGroup)
-  throw(SALOME_Exception)
+throw(SALOME_Exception)
 {
-  //MESSAGE("MED_VERSION:"<< theVersion);
+  MESSAGE("MED_VERSION:"<< theVersion);
   SMESH_TRY;
 
   DriverMED_W_SMESHDS_Mesh myWriter;
-  myWriter.SetFile         ( file , theMinor);
+  myWriter.SetFile         ( file , theVersion);
   myWriter.SetMesh         ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS   );
   myWriter.SetAutoDimension( theAutoDimension );
   myWriter.AddODOnVertices ( theAddODOnVertices );
-  if ( !theMeshName ) 
+  myWriter.SetZTolerance   ( theZTolerance );
+  if ( !theMeshName )
     myWriter.SetMeshId     ( _id         );
   else {
     myWriter.SetMeshId     ( -1          );
@@ -1511,7 +1515,7 @@ void SMESH_Mesh::ExportSAUV(const char *file,
   system(cmd.c_str());
   ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
             /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
-            /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+            /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
 #ifdef WIN32
   cmd = "%PYTHONBIN% ";
 #else
@@ -2024,16 +2028,17 @@ bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
 
 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
                                    const char*               theName,
-                                   int&                      theId,
+                                   const int                 theId,
                                    const TopoDS_Shape&       theShape,
                                    const SMESH_PredicatePtr& thePredicate)
 {
-  if (_mapGroup.count(_groupId))
+  if ( _mapGroup.count( theId ))
     return NULL;
-  theId = _groupId;
-  SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
+  int id = ( theId < 0 ) ? _groupId : theId;
+  SMESH_Group* aGroup = new SMESH_Group ( id, this, theType, theName, theShape, thePredicate );
   GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
-  _mapGroup[_groupId++] = aGroup;
+  _mapGroup[ id ] = aGroup;
+  _groupId = 1 + _mapGroup.rbegin()->first;
   return aGroup;
 }
 
@@ -2045,7 +2050,7 @@ SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
 
 SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
 {
-  if ( !groupDS ) 
+  if ( !groupDS )
     throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
 
   std::map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
@@ -2070,7 +2075,7 @@ SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exce
 /*!
  * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
  *  \retval bool - true if new SMESH_Groups have been created
- * 
+ *
  */
 //================================================================================
 
@@ -2087,7 +2092,7 @@ bool SMESH_Mesh::SynchronizeGroups()
       _mapGroup[_groupId] = new SMESH_Group( groupDS );
   }
   if ( !_mapGroup.empty() )
-    _groupId = _mapGroup.rbegin()->first + 1;
+    _groupId = 1 + _mapGroup.rbegin()->first;
 
   return nbGroups < _mapGroup.size();
 }
@@ -2110,11 +2115,12 @@ SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
  */
 //=============================================================================
 
-SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
+SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID) const
 {
-  if (_mapGroup.find(theGroupID) == _mapGroup.end())
+  std::map <int, SMESH_Group*>::const_iterator id_grp = _mapGroup.find( theGroupID );
+  if ( id_grp == _mapGroup.end() )
     return NULL;
-  return _mapGroup[theGroupID];
+  return id_grp->second;
 }