From 9ecd84933aa3c8fbd2d1f06f0efa7fb2c79df6f8 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Mon, 3 Oct 2022 08:01:36 +0200 Subject: [PATCH] Created MeshLocker to replace Lock/Unlock + replacing std::cerr by exceptions + replacing assign in submesh by call to algo function --- src/SMESH/CMakeLists.txt | 2 ++ src/SMESH/SMESH_Algo.hxx | 19 ++++++++------ src/SMESH/SMESH_DriverShape.cxx | 16 +++++------- src/SMESH/SMESH_Mesh.hxx | 1 - src/SMESH/SMESH_MeshLocker.cxx | 40 ++++++++++++++++++++++++++++++ src/SMESH/SMESH_MeshLocker.hxx | 44 +++++++++++++++++++++++++++++++++ src/SMESH/SMESH_subMesh.cxx | 19 ++++++-------- 7 files changed, 111 insertions(+), 30 deletions(-) create mode 100644 src/SMESH/SMESH_MeshLocker.cxx create mode 100644 src/SMESH/SMESH_MeshLocker.hxx diff --git a/src/SMESH/CMakeLists.txt b/src/SMESH/CMakeLists.txt index afe512509..88d42d875 100644 --- a/src/SMESH/CMakeLists.txt +++ b/src/SMESH/CMakeLists.txt @@ -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 --- diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 3beb89ae1..580d73d68 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -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 - 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 & @@ -277,10 +277,13 @@ public: // 6 - if algo !NeedDiscreteBoundary() but requires presence of // hypotheses of dimension 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 _compatibleHypothesis; std::list _usedHypList; std::list _assigedShapeList; // _usedHypList assigned to - + // Algo features influencing which Compute() and how is called: // in what turn and with what input shape. diff --git a/src/SMESH/SMESH_DriverShape.cxx b/src/SMESH/SMESH_DriverShape.cxx index d8cf96473..fd725274e 100644 --- a/src/SMESH/SMESH_DriverShape.cxx +++ b/src/SMESH/SMESH_DriverShape.cxx @@ -26,6 +26,7 @@ // #include +#include #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); } } diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 28a5b5a2b..8c4d0b18b 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -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 index 000000000..b90fb0529 --- /dev/null +++ b/src/SMESH/SMESH_MeshLocker.cxx @@ -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 index 000000000..e38c31b29 --- /dev/null +++ b/src/SMESH/SMESH_MeshLocker.hxx @@ -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 diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index b5661535a..ace4c6f1f 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -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 & hyps = - _algo->GetUsedHypothesis( *_father, _subShape ); - _father->Unlock(); + const std::list & hyps + { + SMESH_MeshLocker myLocker(_father); + hyps = _algo->GetUsedHypothesis( *_father, _subShape ); + } SMESH_Comment hypStr; if ( !hyps.empty() ) { -- 2.39.2