Salome HOME
Created MeshLocker to replace Lock/Unlock + replacing std::cerr by exceptions + repla...
authorYoann Audouin <yoann.audouin@edf.fr>
Mon, 3 Oct 2022 06:01:36 +0000 (08:01 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Tue, 18 Oct 2022 13:02:19 +0000 (15:02 +0200)
src/SMESH/CMakeLists.txt
src/SMESH/SMESH_Algo.hxx
src/SMESH/SMESH_DriverShape.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESH/SMESH_MeshLocker.cxx [new file with mode: 0644]
src/SMESH/SMESH_MeshLocker.hxx [new file with mode: 0644]
src/SMESH/SMESH_subMesh.cxx

index afe51250917f5f0e5bada4349c4c072903f962b4..88d42d87573ac1155c820392a0ca6b14c0da542c 100644 (file)
@@ -92,6 +92,7 @@ SET(SMESHimpl_HEADERS
   SMESH_Homard.hxx
   SMESH_DriverMesh.hxx
   SMESH_DriverShape.hxx
+  SMESH_MeshLocker.hxx
 )
 
 # --- sources ---
@@ -114,6 +115,7 @@ SET(SMESHimpl_SOURCES
   SMESH_Homard.cxx
   SMESH_DriverMesh.cxx
   SMESH_DriverShape.cxx
+  SMESH_MeshLocker.cxx
 )
 
 # --- rules ---
index 3beb89ae12c68c5e97c698bf46df9eaec4d48fac..580d73d681ee389d23ffb6e1d1655765daceb398 100644 (file)
@@ -198,15 +198,15 @@ class SMESH_EXPORT SMESH_Algo : public SMESH_Hypothesis
 
   /*!
    * \brief Return a list of compatible hypotheses used to mesh a shape
-    * \param aMesh - the mesh 
+    * \param aMesh - the mesh
     * \param aShape - the shape
     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
-   * 
+   *
    *  List the hypothesis used by the algorithm associated to the shape.
    *  Hypothesis associated to father shape -are- taken into account (see
    *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
-   *  the algorithm. This method could be surcharged by specific algorithms, in 
+   *  the algorithm. This method could be surcharged by specific algorithms, in
    *  case of several hypothesis simultaneously applicable.
    */
   virtual const std::list <const SMESHDS_Hypothesis *> &
@@ -277,10 +277,13 @@ public:
   // 6 - if algo !NeedDiscreteBoundary() but requires presence of
   // hypotheses of dimension <dim> to generate all-dimensional mesh.
   // This info is used not to issue warnings on hiding of lower global algos.
+  //
+
+  virtual void setSubMeshesToCompute(SMESH_subMesh * aSubMesh) {SubMeshesToCompute().assign( 1, aSubMesh );}
 
 public:
   // ==================================================================
-  // Methods to track non hierarchical dependencies between submeshes 
+  // Methods to track non hierarchical dependencies between submeshes
   // ==================================================================
 
   /*!
@@ -292,7 +295,7 @@ public:
    * By default none listener is set
    */
   virtual void SetEventListener(SMESH_subMesh* subMesh);
-  
+
   /*!
    * \brief Allow algo to do something after persistent restoration
     * \param subMesh - restored submesh
@@ -300,7 +303,7 @@ public:
    * This method is called only if a submesh has HYP_OK algo_state.
    */
   virtual void SubmeshRestored(SMESH_subMesh* subMesh);
-  
+
 public:
   // ==================================================================
   // Common algo utilities
@@ -398,7 +401,7 @@ public:
   enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY };
 
   /*!
-   * \brief Finds topological errors of a sub-mesh 
+   * \brief Finds topological errors of a sub-mesh
    */
   static EMeshError GetMeshError(SMESH_subMesh* subMesh);
 
@@ -434,7 +437,7 @@ protected:
   std::vector<std::string>              _compatibleHypothesis;
   std::list<const SMESHDS_Hypothesis *> _usedHypList;
   std::list<TopoDS_Shape>               _assigedShapeList; // _usedHypList assigned to
-  
+
 
   // Algo features influencing which Compute() and how is called:
   // in what turn and with what input shape.
index d8cf96473d9650a9e44223beee848968fe1499f5..fd725274e28ba4dc480b60b823692ca0195d24be 100644 (file)
@@ -26,6 +26,7 @@
 //
 
 #include <utilities.h>
+#include <Utils_SALOME_Exception.hxx>
 #include "SMESH_DriverShape.hxx"
 
 // step include
@@ -62,8 +63,7 @@ int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
   Interface_Static::SetIVal("read.step.nonmanifold", 1);
   IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
   if(aStat != IFSelect_RetDone){
-    std::cerr << "Reading error for "  << shape_file << std::endl;
-    return true;
+    throw SALOME_Exception("Reading error for " + shape_file);
   }
 
   int NbTrans = reader.TransferRoots();
@@ -94,15 +94,13 @@ int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
 
   IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
   if(aStat != IFSelect_RetDone){
-    std::cerr << "Transfer error for "  << shape_file << std::endl;
-    return true;
+    throw SALOME_Exception("Reading error for " + shape_file);
   }
 
   aStat = aWriter.Write(shape_file.c_str());
 
   if(aStat != IFSelect_RetDone){
-    std::cerr << "Writing error for "  << shape_file << std::endl;
-    return true;
+    throw SALOME_Exception("Writing error for " + shape_file);
   }
   return aStat;
 }
@@ -156,8 +154,7 @@ int importShape(const std::string shape_file, TopoDS_Shape& aShape){
   } else if (type == ".step"){
     return importSTEPShape(shape_file, aShape);
   } else {
-    std::cerr << "Unknow format: " << type << std::endl;
-    return true;
+    throw SALOME_Exception("Unknow format for importShape: " + type);
   }
 }
 
@@ -177,7 +174,6 @@ int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
   } else if (type == ".step"){
     return exportSTEPShape(shape_file, aShape);
   } else {
-    std::cerr << "Unknow format: " << type << std::endl;
-    return true;
+    throw SALOME_Exception("Unknow format for exportShape: " + type);
   }
 }
index 28a5b5a2b0a51492f3e85dc8c0d3e76614b30529..8c4d0b18be68707fc0f5ed2cc470537b6d981ee6 100644 (file)
@@ -462,5 +462,4 @@ protected:
   SMESH_Mesh();
   SMESH_Mesh(const SMESH_Mesh&) {};
 };
-
 #endif
diff --git a/src/SMESH/SMESH_MeshLocker.cxx b/src/SMESH/SMESH_MeshLocker.cxx
new file mode 100644 (file)
index 0000000..b90fb05
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  File   : SMESH_MeshLocker.cxx
+//  Author : Yoann AUDOUIN, EDF
+//  Module : SMESH
+//
+
+#include "SMESH_MeshLocker.hxx"
+
+#include "SMESH_Mesh.hxx"
+
+SMESH_MeshLocker::SMESH_MeshLocker(SMESH_Mesh * aMesh) : _myMesh(aMesh)
+{
+  _myMesh->Lock();
+}
+
+SMESH_MeshLocker::~SMESH_MeshLocker()
+{
+  _myMesh->Unlock();
+}
diff --git a/src/SMESH/SMESH_MeshLocker.hxx b/src/SMESH/SMESH_MeshLocker.hxx
new file mode 100644 (file)
index 0000000..e38c31b
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  File   : SMESH_Mesh.hxx
+//  Author : Paul RASCLE, EDF
+//  Module : SMESH
+//
+#ifndef _SMESH_MESHLOCKER_HXX_
+#define _SMESH_MESHLOCKER_HXX_
+
+class SMESH_Mesh;
+
+class SMESH_MeshLocker{
+public:
+  SMESH_MeshLocker(SMESH_Mesh * aMesh);
+  ~SMESH_MeshLocker();
+
+protected:
+  SMESH_MeshLocker();
+
+private:
+  SMESH_Mesh * _myMesh=nullptr;
+};
+
+#endif
index b5661535a85de400479c9b1160a6a5e135fd45e9..ace4c6f1ffb0c69951362b10df5a96106fd4fcbc 100644 (file)
@@ -37,6 +37,7 @@
 #include "SMESH_Mesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMeshEventListener.hxx"
+#include "SMESH_MeshLocker.hxx"
 
 #include "utilities.h"
 #include "Basics_Utils.hxx"
@@ -1393,16 +1394,13 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
     else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
              && !_alwaysComputed )
     {
-      // LOCK: Adding node to mesh
-      _father->Lock();
+      SMESH_MeshLocker myLocker(_father);
       const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
       gp_Pnt P = BRep_Tool::Pnt(V);
       if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
         _father->GetMeshDS()->SetNodeOnVertex(n,_Id);
         _computeState = COMPUTE_OK;
       }
-      _father->Unlock();
-      // UNLOCK
     }
     if ( event == MODIF_ALGO_STATE )
       cleanDependants();
@@ -1516,9 +1514,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
           break;
         }
         TopoDS_Shape shape = _subShape;
-        _father->Lock();
-        algo->SubMeshesToCompute().assign( 1, this );
-        _father->Unlock();
+        algo->setSubMeshesToCompute(this);
         // check submeshes needed
         // In parallel there would be no submesh to check
         if (_father->HasShapeToMesh() && !_father->IsParallel()) {
@@ -1650,10 +1646,11 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
 #ifdef PRINT_WHO_COMPUTE_WHAT
         for (subS.ReInit(); subS.More(); subS.Next())
         {
-          _father->Lock();
-          const std::list <const SMESHDS_Hypothesis *> & hyps =
-            _algo->GetUsedHypothesis( *_father, _subShape );
-          _father->Unlock();
+          const std::list <const SMESHDS_Hypothesis *> & hyps
+          {
+            SMESH_MeshLocker myLocker(_father);
+            hyps = _algo->GetUsedHypothesis( *_father, _subShape );
+          }
           SMESH_Comment hypStr;
           if ( !hyps.empty() )
           {