Salome HOME
Merge branch 'OCCT780'
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index 7c634c4deb25ed577fc1a9d3f5751f09091afb27..2f7c6efa7599da99586107a7ee7f149bd28567b8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -57,7 +57,7 @@
 
 #include <GEOMUtils.hxx>
 
-#undef _Precision_HeaderFile
+//#undef _Precision_HeaderFile
 #include <BRepBndLib.hxx>
 #include <BRepPrimAPI_MakeBox.hxx>
 #include <Bnd_Box.hxx>
 #ifndef WIN32
 #include <boost/thread/thread.hpp>
 #include <boost/bind.hpp>
-#else 
+#else
 #include <pthread.h>
 #endif
 
+#ifndef WIN32
+#include <boost/filesystem.hpp>
+namespace fs=boost::filesystem;
+#endif
+
 // maximum stored group name length in MED file
 #define MAX_MED_GROUP_NAME_LENGTH 80
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
 
 typedef SMESH_HypoFilter THypType;
@@ -99,7 +98,7 @@ class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 
@@ -109,7 +108,7 @@ SMESH_Mesh::SMESH_Mesh(int               theLocalId,
                        SMESHDS_Document* theDocument):
   _groupId( 0 ), _nbSubShapes( 0 )
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
+  MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
   _id            = theLocalId;
   _gen           = theGen;
   _document    = theDocument;
@@ -168,13 +167,11 @@ namespace
 #ifndef WIN32
   void deleteMeshDS(SMESHDS_Mesh* meshDS)
   {
-    //cout << "deleteMeshDS( " << meshDS << endl;
     delete meshDS;
   }
 #else
   static void* deleteMeshDS(void* meshDS)
   {
-    //cout << "deleteMeshDS( " << meshDS << endl;
     SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
     if(m) {
       delete m;
@@ -192,7 +189,7 @@ namespace
 
 SMESH_Mesh::~SMESH_Mesh()
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh");
+  MESSAGE("SMESH_Mesh::~SMESH_Mesh");
 
   if ( _document ) // avoid destructing _meshDS from ~SMESH_Gen()
     _document->RemoveMesh( _id );
@@ -276,7 +273,7 @@ SMESH_Mesh* SMESH_Mesh::FindMesh( int meshId ) const
 
 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
+  MESSAGE("SMESH_Mesh::ShapeToMesh");
 
   if ( !aShape.IsNull() && _isShapeToMesh ) {
     if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
@@ -530,10 +527,12 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
   myReader.SetFile(theFileName);
   myReader.SetMeshName(theMeshName);
   Driver_Mesh::Status status = myReader.Perform();
-#ifdef _DEBUG_
-  SMESH_ComputeErrorPtr er = myReader.GetError();
-  if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
-#endif
+
+  if (SALOME::VerbosityActivated())
+  {
+    SMESH_ComputeErrorPtr er = myReader.GetError();
+    if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
+  }
 
   // Reading groups (sub-meshes are out of scope of MED import functionality)
   std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
@@ -629,7 +628,7 @@ SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 
@@ -638,7 +637,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
                           int                  anHypId,
                           std::string*         anError  )
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
+  MESSAGE("SMESH_Mesh::AddHypothesis");
 
   if ( anError )
     anError->clear();
@@ -662,7 +661,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
     std::string hypName = anHyp->GetName();
     if ( hypName == "NotConformAllowed" )
     {
-      if(MYDEBUG) MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
+      MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
       return SMESH_Hypothesis::HYP_INCOMPATIBLE;
     }
   }
@@ -705,7 +704,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
       while ( smIt->more() ) {
         SMESH_subMesh* sm = smIt->next();
         if ( sm->IsApplicableHypothesis( anHyp )) {
-          ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
+          ret2 = sm->CheckConcurrentHypothesis( anHyp );
           if (ret2 > ret) {
             ret = ret2;
             break;
@@ -717,14 +716,14 @@ 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);
+  if(SALOME::VerbosityActivated()) subMesh->DumpAlgoState(true);
+  SCRUTE(ret);
   return ret;
 }
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 
@@ -732,16 +731,16 @@ SMESH_Hypothesis::Hypothesis_Status
 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
                              int                    anHypId)
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
+  MESSAGE("SMESH_Mesh::RemoveHypothesis");
 
   StudyContextStruct *sc = _gen->GetStudyContext();
   if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
     throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
 
   SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
-  if(MYDEBUG) { SCRUTE(anHyp->GetType()); }
+  SCRUTE(anHyp->GetType());
 
-  // shape 
+  // shape
 
   bool                     isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
   SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
@@ -753,7 +752,7 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
   // there may appear concurrent hyps that were covered by the removed hyp
   if (ret < SMESH_Hypothesis::HYP_CONCURRENT &&
       subMesh->IsApplicableHypothesis( anHyp ) &&
-      subMesh->CheckConcurrentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
+      subMesh->CheckConcurrentHypothesis( anHyp ) != SMESH_Hypothesis::HYP_OK)
     ret = SMESH_Hypothesis::HYP_CONCURRENT;
 
   // sub-shapes
@@ -774,7 +773,7 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
       while ( smIt->more() ) {
         SMESH_subMesh* sm = smIt->next();
         if ( sm->IsApplicableHypothesis( anHyp )) {
-          ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
+          ret2 = sm->CheckConcurrentHypothesis( anHyp );
           if (ret2 > ret) {
             ret = ret2;
             break;
@@ -787,14 +786,14 @@ 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);
+  if(SALOME::VerbosityActivated()) subMesh->DumpAlgoState(true);
+  SCRUTE(ret);
   return ret;
 }
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 
@@ -861,7 +860,7 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh *   aSubM
       const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
     SortByMeshOrder( ancestors );
 
-    std::vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin(); 
+    std::vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
     for ( ; smIt != ancestors.end(); smIt++ )
     {
       const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
@@ -1004,7 +1003,7 @@ SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const int anHypId) const
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 
@@ -1015,7 +1014,7 @@ const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog()
 
 //=============================================================================
 /*!
- * 
+ *
  */
 //=============================================================================
 void SMESH_Mesh::ClearLog()
@@ -1416,8 +1415,7 @@ void SMESH_Mesh::exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& theWriter,
                                   bool                      theAutoDimension,
                                   bool                      theAddODOnVertices,
                                   double                    theZTolerance,
-                                  bool                      theSaveNumbers,
-                                  bool                      theAllElemsToGroup)
+                                  bool                      theSaveNumbers)
 {
   Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
 
@@ -1443,8 +1441,6 @@ void SMESH_Mesh::exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& theWriter,
     theWriter.AddGroupOf0DElems();
     theWriter.AddGroupOfBalls();
   }
-  if ( theAllElemsToGroup )
-    theWriter.AddAllToGroup();
 
   // Pass groups to writer. Provide unique group names.
   //set<string> aGroupNames; // Corrected for Mantis issue 0020028
@@ -1499,8 +1495,7 @@ SMESH_Mesh::ExportMEDCoupling(const char*         theMeshName,
 {
   DriverMED_W_SMESHDS_Mesh_Mem writer;
   this->exportMEDCommmon( writer, theMeshName, theAutoGroups, theMeshPart, theAutoDimension,
-                          theAddODOnVertices, theZTolerance, theSaveNumbers,
-                          /*AllElemsToGroup(for ExportSAUV())=*/false);
+                          theAddODOnVertices, theZTolerance, theSaveNumbers);
   return writer.getData();
 }
 
@@ -1525,8 +1520,6 @@ SMESH_Mesh::ExportMEDCoupling(const char*         theMeshName,
  *              within a given tolerance, the coordinate is set to zero.
  *              If \a ZTolerance is negative, the node coordinates are kept as is.
  *  \param [in] theSaveNumbers : enable saving numbers of nodes and cells.
- *  \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413).
- *              It is used by ExportSAUV() only
  *  \return int - mesh index in the file
  */
 //================================================================================
@@ -1539,65 +1532,12 @@ void SMESH_Mesh::ExportMED(const char *        theFile,
                            bool                theAutoDimension,
                            bool                theAddODOnVertices,
                            double              theZTolerance,
-                           bool                theSaveNumbers,
-                           bool                theAllElemsToGroup)
+                           bool                theSaveNumbers)
 {
   MESSAGE("MED_VERSION:"<< theVersion);
   DriverMED_W_SMESHDS_Mesh writer;
   writer.SetFile( theFile, theVersion );
-  this->exportMEDCommmon( writer, theMeshName, theAutoGroups, theMeshPart, theAutoDimension, theAddODOnVertices, theZTolerance, theSaveNumbers, theAllElemsToGroup );
-}
-
-//================================================================================
-/*!
- * \brief Export the mesh to a SAUV file
- */
-//================================================================================
-
-void SMESH_Mesh::ExportSAUV(const char *theFile,
-                            const char* theMeshName,
-                            bool        theAutoGroups)
-{
-  std::string medfilename( theFile );
-  medfilename += ".med";
-  std::string cmd;
-#ifdef WIN32
-  cmd = "%PYTHONBIN% ";
-#else
-  cmd = "python3 ";
-#endif
-  cmd += "-c \"";
-  cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
-  cmd += "\"";
-  system(cmd.c_str());
-  try {
-    ExportMED( medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
-               /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
-               /*zTol=*/-1, /*theSaveNumbers=*/false,
-               /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
-  }
-  catch ( TooLargeForExport )
-  {
-    throw TooLargeForExport("SAUV");
-  }
-#ifdef WIN32
-  cmd = "%PYTHONBIN% ";
-#else
-  cmd = "python3 ";
-#endif
-  cmd += "-c \"";
-  cmd += "from medutilities import convert ; convert(r'" + medfilename + "', 'MED', 'GIBI', 1, r'" + theFile + "')";
-  cmd += "\"";
-  system(cmd.c_str());
-#ifdef WIN32
-  cmd = "%PYTHONBIN% ";
-#else
-  cmd = "python3 ";
-#endif
-  cmd += "-c \"";
-  cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
-  cmd += "\"";
-  system(cmd.c_str());
+  this->exportMEDCommmon( writer, theMeshName, theAutoGroups, theMeshPart, theAutoDimension, theAddODOnVertices, theZTolerance, theSaveNumbers );
 }
 
 //================================================================================
@@ -1786,7 +1726,7 @@ double SMESH_Mesh::GetComputeProgress() const
   const SMESH_subMesh* curSM = _gen->GetCurrentSubMesh();
 
   // get progress of a current algo
-  TColStd_MapOfInteger currentSubIds; 
+  TColStd_MapOfInteger currentSubIds;
   if ( curSM )
     if ( SMESH_Algo* algo = curSM->GetAlgo() )
     {
@@ -1807,9 +1747,8 @@ double SMESH_Mesh::GetComputeProgress() const
         rate = algo->GetProgress();
       }
       catch (...) {
-#ifdef _DEBUG_
-        std::cerr << "Exception in " << algo->GetName() << "::GetProgress()" << std::endl;
-#endif
+        if (SALOME::VerbosityActivated())
+          std::cerr << "Exception in " << algo->GetName() << "::GetProgress()" << std::endl;
       }
       if ( 0. < rate && rate < 1.001 )
       {
@@ -1820,7 +1759,6 @@ double SMESH_Mesh::GetComputeProgress() const
         rate = algo->GetProgressByTic();
         computedCost += algoDoneCost + rate * algoNotDoneCost;
       }
-      // cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
     }
 
   // get cost of already treated sub-meshes
@@ -1841,9 +1779,6 @@ double SMESH_Mesh::GetComputeProgress() const
       }
     }
   }
-  // cout << "Total: " << totalCost
-  //      << " computed: " << computedCost << " progress: " << computedCost / totalCost
-  //      << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
   return computedCost / totalCost;
 }
 
@@ -2086,7 +2021,7 @@ int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
 
 bool SMESH_Mesh::IsNotConformAllowed() const
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
+  MESSAGE("SMESH_Mesh::IsNotConformAllowed");
 
   static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
   return GetHypothesis( _meshDS->ShapeToMesh(), filter, false );
@@ -2094,7 +2029,7 @@ bool SMESH_Mesh::IsNotConformAllowed() const
 
 //=======================================================================
 //function : IsMainShape
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
@@ -2114,7 +2049,7 @@ TopoDS_Shape SMESH_Mesh::GetShapeByEntry(const std::string& entry) const
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -2228,7 +2163,7 @@ std::list<int> SMESH_Mesh::GetGroupIds() const
   std::map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin();
   for ( ; it != _mapGroup.end(); it++ )
     anIds.push_back( it->first );
-  
+
   return anIds;
 }
 
@@ -2247,7 +2182,7 @@ void SMESH_Mesh::SetCallUp( TCallUp* upCaller )
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -2605,7 +2540,7 @@ bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
     }
   }
   return true; // no order imposed to given sub-meshes
-} 
+}
 
 //=============================================================================
 /*!