Salome HOME
Merge branch 'V8_4_BR'
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index a3e707247e2c920bd2fdbcdac14250e3cc28b802..3e21e9a1179530cf07bbdfc6d7f9a349c5fefd94 100644 (file)
@@ -559,7 +559,7 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
 //purpose  : 
 //=======================================================================
 
-int SMESH_Mesh::STLToMesh(const char* theFileName)
+std::string SMESH_Mesh::STLToMesh(const char* theFileName)
 {
   if(_isShapeToMesh)
     throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
@@ -571,7 +571,7 @@ int SMESH_Mesh::STLToMesh(const char* theFileName)
   myReader.SetMeshId(-1);
   myReader.Perform();
 
-  return 1;
+  return myReader.GetName();
 }
 
 //================================================================================
@@ -661,7 +661,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
     string hypName = anHyp->GetName();
     if ( hypName == "NotConformAllowed" )
     {
-      if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
+      if(MYDEBUG) MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
       return SMESH_Hypothesis::HYP_INCOMPATIBLE;
     }
   }
@@ -697,14 +697,14 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
       }
     }
 
-    // check concurent hypotheses on ancestors
-    if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
+    // check concurrent hypotheses on ancestors
+    if (ret < SMESH_Hypothesis::HYP_CONCURRENT && !isGlobalHyp )
     {
       SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
       while ( smIt->more() ) {
         SMESH_subMesh* sm = smIt->next();
-        if ( sm->IsApplicableHypotesis( anHyp )) {
-          ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
+        if ( sm->IsApplicableHypothesis( anHyp )) {
+          ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
           if (ret2 > ret) {
             ret = ret2;
             break;
@@ -714,6 +714,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
     }
   }
   HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
+  GetMeshDS()->Modified();
 
   if(MYDEBUG) subMesh->DumpAlgoState(true);
   if(MYDEBUG) SCRUTE(ret);
@@ -750,10 +751,10 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
   SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
 
   // there may appear concurrent hyps that were covered by the removed hyp
-  if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
-      subMesh->IsApplicableHypotesis( anHyp ) &&
-      subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
-    ret = SMESH_Hypothesis::HYP_CONCURENT;
+  if (ret < SMESH_Hypothesis::HYP_CONCURRENT &&
+      subMesh->IsApplicableHypothesis( anHyp ) &&
+      subMesh->CheckConcurrentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
+    ret = SMESH_Hypothesis::HYP_CONCURRENT;
 
   // sub-shapes
   if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
@@ -766,14 +767,14 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
     if (ret2 > ret) // more severe
       ret = ret2;
 
-    // check concurent hypotheses on ancestors
-    if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
+    // check concurrent hypotheses on ancestors
+    if (ret < SMESH_Hypothesis::HYP_CONCURRENT && !IsMainShape( aSubShape ) )
     {
       SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
       while ( smIt->more() ) {
         SMESH_subMesh* sm = smIt->next();
-        if ( sm->IsApplicableHypotesis( anHyp )) {
-          ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
+        if ( sm->IsApplicableHypothesis( anHyp )) {
+          ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
           if (ret2 > ret) {
             ret = ret2;
             break;
@@ -784,6 +785,7 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
   }
 
   HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
+  GetMeshDS()->Modified();
 
   if(MYDEBUG) subMesh->DumpAlgoState(true);
   if(MYDEBUG) SCRUTE(ret);
@@ -1078,7 +1080,7 @@ SMESH_subMesh * SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
 
 //=============================================================================
 /*!
- * Get the SMESH_subMesh object implementation. Dont create it, return null
+ * Get the SMESH_subMesh object implementation. Don't create it, return null
  * if it does not exist.
  */
 //=============================================================================
@@ -1092,7 +1094,7 @@ SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
 
 //=============================================================================
 /*!
- * Get the SMESH_subMesh object implementation. Dont create it, return null
+ * Get the SMESH_subMesh object implementation. Don't create it, return null
  * if it does not exist.
  */
 //=============================================================================
@@ -1167,7 +1169,7 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
   SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
 
   // check if anHyp can be used to mesh aSubMesh
-  if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
+  if ( !aSubMesh || !aSubMesh->IsApplicableHypothesis( hyp ))
     return false;
 
   SMESH_Algo *algo = aSubMesh->GetAlgo();
@@ -1230,7 +1232,7 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h
     {
       const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
 
-      if (( aSubMesh->IsApplicableHypotesis( hyp )) &&
+      if (( aSubMesh->IsApplicableHypothesis( hyp )) &&
           ( algo = aSubMesh->GetAlgo() )            &&
           ( compatibleHypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() )) &&
           ( compatibleHypoKind->IsOk( hyp, aSubShape )))
@@ -1258,15 +1260,14 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h
     return;
 
   // if all meshed EDGEs will be notified then the notification is equivalent
-  // to the whole mesh clearing
-  if ( allMeshedEdgesNotified )
+  // to the whole mesh clearing, which is usually faster
+  if ( allMeshedEdgesNotified && NbNodes() > 0 )
   {
-    if ( NbNodes() > 0 )
-      Clear();
+    Clear();
   }
   else
   {
-    // notify in reverse order to avoid filling of the pool of IDs
+    // notify in reverse order to avoid filling the pool of IDs
     for ( int i = smToNotify.size()-1; i >= 0; --i )
       smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
                                      const_cast< SMESH_Hypothesis*>( hyp ));
@@ -1385,6 +1386,8 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
      *         - 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)
  *  \return int - mesh index in the file
  */
 //================================================================================
@@ -1395,9 +1398,11 @@ void SMESH_Mesh::ExportMED(const char *        file,
                            int                 theVersion,
                            const SMESHDS_Mesh* meshPart,
                            bool                theAutoDimension,
-                           bool                theAddODOnVertices)
+                           bool                theAddODOnVertices,
+                           bool                theAllElemsToGroup)
   throw(SALOME_Exception)
 {
+  //MESSAGE("MED_VERSION:"<< theVersion);
   SMESH_TRY;
 
   DriverMED_W_SMESHDS_Mesh myWriter;
@@ -1417,7 +1422,11 @@ void SMESH_Mesh::ExportMED(const char *        file,
     myWriter.AddGroupOfEdges();
     myWriter.AddGroupOfFaces();
     myWriter.AddGroupOfVolumes();
+    myWriter.AddGroupOf0DElems();
+    myWriter.AddGroupOfBalls();
   }
+  if ( theAllElemsToGroup )
+    myWriter.AddAllToGroup();
 
   // Pass groups to writer. Provide unique group names.
   //set<string> aGroupNames; // Corrected for Mantis issue 0020028
@@ -1473,7 +1482,9 @@ void SMESH_Mesh::ExportSAUV(const char *file,
   cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
   cmd += "\"";
   system(cmd.c_str());
-  ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, 1);
+  ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*theVersion=*/1,
+            /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
+            /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
 #ifdef WIN32
   cmd = "%PYTHONBIN% ";
 #else
@@ -1527,6 +1538,7 @@ void SMESH_Mesh::ExportUNV(const char *        file,
   myWriter.SetMeshId(_id);
   //  myWriter.SetGroups(_mapGroup);
 
+  // pass group names to SMESHDS
   if ( !meshPart )
   {
     for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
@@ -1550,6 +1562,7 @@ void SMESH_Mesh::ExportUNV(const char *        file,
 
 void SMESH_Mesh::ExportSTL(const char *        file,
                            const bool          isascii,
+                           const char *        name,
                            const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
 {
   Unexpect aCatch(SalomeException);
@@ -1558,6 +1571,7 @@ void SMESH_Mesh::ExportSTL(const char *        file,
   myWriter.SetIsAscii( isascii );
   myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
   myWriter.SetMeshId(_id);
+  if ( name ) myWriter.SetName( name );
   myWriter.Perform();
 }
 
@@ -1569,17 +1583,37 @@ void SMESH_Mesh::ExportSTL(const char *        file,
 
 void SMESH_Mesh::ExportCGNS(const char *        file,
                             const SMESHDS_Mesh* meshDS,
-                            const char *        meshName)
+                            const char *        meshName,
+                            const bool          groupElemsByType)
 {
   int res = Driver_Mesh::DRS_FAIL;
+
+  // pass group names to SMESHDS
+  for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
+    SMESH_Group*       group   = it->second;
+    SMESHDS_GroupBase* groupDS = group->GetGroupDS();
+    if ( groupDS ) {
+      string groupName = group->GetName();
+      groupDS->SetStoreName( groupName.c_str() );
+    }
+  }
 #ifdef WITH_CGNS
+
   DriverCGNS_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
   myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
   if ( meshName && meshName[0] )
     myWriter.SetMeshName( meshName );
+  myWriter.SetElementsByType( groupElemsByType );
   res = myWriter.Perform();
+  if ( res != Driver_Mesh::DRS_OK )
+  {
+    SMESH_ComputeErrorPtr err = myWriter.GetError();
+    if ( err && !err->IsOK() && !err->myComment.empty() )
+      throw SALOME_Exception(("Export failed: " + err->myComment ).c_str() );
+  }
+
 #endif
   if ( res != Driver_Mesh::DRS_OK )
     throw SALOME_Exception("Export failed");
@@ -1857,6 +1891,19 @@ int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exceptio
   return _myMeshDS->GetMeshInfo().NbPrisms(order);
 }
 
+int SMESH_Mesh::NbQuadPrisms() const throw (SALOME_Exception)
+{
+  Unexpect aCatch(SalomeException);
+  return _myMeshDS->GetMeshInfo().NbQuadPrisms();
+}
+
+int SMESH_Mesh::NbBiQuadPrisms() const throw (SALOME_Exception)
+{
+  Unexpect aCatch(SalomeException);
+  return _myMeshDS->GetMeshInfo().NbBiQuadPrisms();
+}
+
+
 //================================================================================
 /*!
  * \brief  Return number of hexagonal prisms in the mesh
@@ -1919,7 +1966,7 @@ int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
 
 //=======================================================================
 //function : IsNotConformAllowed
-//purpose  : check if a hypothesis alowing notconform mesh is present
+//purpose  : check if a hypothesis allowing notconform mesh is present
 //=======================================================================
 
 bool SMESH_Mesh::IsNotConformAllowed() const
@@ -2091,7 +2138,7 @@ bool SMESH_Mesh::RemoveGroup( const int theGroupID )
 //=======================================================================
 //function : GetAncestors
 //purpose  : return list of ancestors of theSubShape in the order
-//           that lower dimention shapes come first.
+//           that lower dimension shapes come first.
 //=======================================================================
 
 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
@@ -2142,7 +2189,7 @@ ostream& SMESH_Mesh::Dump(ostream& save)
         save << clause << ".3) Faces in detail: " << endl;
         map <int,int>::iterator itF;
         for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
-          save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
+          save << "--> nb nodes: " << itF->first << " - nb elements:\t" << itF->second << endl;
       }
     }
     save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
@@ -2167,7 +2214,7 @@ ostream& SMESH_Mesh::Dump(ostream& save)
         save << clause << ".5) Volumes in detail: " << endl;
         map <int,int>::iterator itV;
         for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
-          save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
+          save << "--> nb nodes: " << itV->first << " - nb elements:\t" << itV->second << endl;
       }
     }
     save << endl;
@@ -2369,7 +2416,7 @@ bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) con
   vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
   vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
 
-  // iterate on ordered submeshes and insert them in detected positions
+  // iterate on ordered sub-meshes and insert them in detected positions
   map< int, TPosInList >::iterator i_pos = sortedPos.begin();
   for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
     *(i_pos->second) = *onlyBIt;
@@ -2387,18 +2434,27 @@ bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
                             const SMESH_subMesh* smAfter ) const
 {
   TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
-  TListOfInt::const_iterator idBef, idAft;
   for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
   {
     const TListOfInt& listOfId = *listIdsIt;
-    idBef = std::find( listOfId.begin(), listOfId.end(), smBefore->GetId() );
-    if ( idBef != listOfId.end() )
-      idAft = std::find( listOfId.begin(), listOfId.end(), smAfter->GetId() );
-    if ( idAft != listOfId.end () )
-      return ( std::distance( listOfId.begin(), idBef ) <
-               std::distance( listOfId.begin(), idAft )   );
+    int iB = -1, iA = -1, i = 0;
+    for ( TListOfInt::const_iterator id = listOfId.begin(); id != listOfId.end(); ++id, ++i )
+    {
+      if ( *id == smBefore->GetId() )
+      {
+        iB = i;
+        if ( iA > -1 )
+          return iB < iA;
+      }
+      else if ( *id == smAfter->GetId() )
+      {
+        iA = i;
+        if ( iB > -1 )
+          return iB < iA;
+      }
+    }
   }
-  return true; // no order imposed to given submeshes
+  return true; // no order imposed to given sub-meshes
 } 
 
 //=============================================================================