Created MeshLocker to replace Lock/Unlock + replacing std::cerr by exceptions + replacing assign in submesh by call to algo function

This commit is contained in:
Yoann Audouin 2022-10-03 08:01:36 +02:00
parent 43fc1c7182
commit 9ecd84933a
7 changed files with 111 additions and 30 deletions

View File

@ -92,6 +92,7 @@ SET(SMESHimpl_HEADERS
SMESH_Homard.hxx SMESH_Homard.hxx
SMESH_DriverMesh.hxx SMESH_DriverMesh.hxx
SMESH_DriverShape.hxx SMESH_DriverShape.hxx
SMESH_MeshLocker.hxx
) )
# --- sources --- # --- sources ---
@ -114,6 +115,7 @@ SET(SMESHimpl_SOURCES
SMESH_Homard.cxx SMESH_Homard.cxx
SMESH_DriverMesh.cxx SMESH_DriverMesh.cxx
SMESH_DriverShape.cxx SMESH_DriverShape.cxx
SMESH_MeshLocker.cxx
) )
# --- rules --- # --- rules ---

View 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 * \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 aShape - the shape
* \param ignoreAuxiliary - do not include auxiliary hypotheses in the list * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
* \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
* *
* List the hypothesis used by the algorithm associated to the shape. * List the hypothesis used by the algorithm associated to the shape.
* Hypothesis associated to father shape -are- taken into account (see * Hypothesis associated to father shape -are- taken into account (see
* GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in * 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. * case of several hypothesis simultaneously applicable.
*/ */
virtual const std::list <const SMESHDS_Hypothesis *> & virtual const std::list <const SMESHDS_Hypothesis *> &
@ -277,10 +277,13 @@ public:
// 6 - if algo !NeedDiscreteBoundary() but requires presence of // 6 - if algo !NeedDiscreteBoundary() but requires presence of
// hypotheses of dimension <dim> to generate all-dimensional mesh. // hypotheses of dimension <dim> to generate all-dimensional mesh.
// This info is used not to issue warnings on hiding of lower global algos. // 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: 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 * By default none listener is set
*/ */
virtual void SetEventListener(SMESH_subMesh* subMesh); virtual void SetEventListener(SMESH_subMesh* subMesh);
/*! /*!
* \brief Allow algo to do something after persistent restoration * \brief Allow algo to do something after persistent restoration
* \param subMesh - restored submesh * \param subMesh - restored submesh
@ -300,7 +303,7 @@ public:
* This method is called only if a submesh has HYP_OK algo_state. * This method is called only if a submesh has HYP_OK algo_state.
*/ */
virtual void SubmeshRestored(SMESH_subMesh* subMesh); virtual void SubmeshRestored(SMESH_subMesh* subMesh);
public: public:
// ================================================================== // ==================================================================
// Common algo utilities // Common algo utilities
@ -398,7 +401,7 @@ public:
enum EMeshError { MEr_OK = 0, MEr_HOLES, MEr_BAD_ORI, MEr_EMPTY }; 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); static EMeshError GetMeshError(SMESH_subMesh* subMesh);
@ -434,7 +437,7 @@ protected:
std::vector<std::string> _compatibleHypothesis; std::vector<std::string> _compatibleHypothesis;
std::list<const SMESHDS_Hypothesis *> _usedHypList; std::list<const SMESHDS_Hypothesis *> _usedHypList;
std::list<TopoDS_Shape> _assigedShapeList; // _usedHypList assigned to std::list<TopoDS_Shape> _assigedShapeList; // _usedHypList assigned to
// Algo features influencing which Compute() and how is called: // Algo features influencing which Compute() and how is called:
// in what turn and with what input shape. // in what turn and with what input shape.

View File

@ -26,6 +26,7 @@
// //
#include <utilities.h> #include <utilities.h>
#include <Utils_SALOME_Exception.hxx>
#include "SMESH_DriverShape.hxx" #include "SMESH_DriverShape.hxx"
// step include // step include
@ -62,8 +63,7 @@ int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
Interface_Static::SetIVal("read.step.nonmanifold", 1); Interface_Static::SetIVal("read.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str()); IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
if(aStat != IFSelect_RetDone){ if(aStat != IFSelect_RetDone){
std::cerr << "Reading error for " << shape_file << std::endl; throw SALOME_Exception("Reading error for " + shape_file);
return true;
} }
int NbTrans = reader.TransferRoots(); 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); IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
if(aStat != IFSelect_RetDone){ if(aStat != IFSelect_RetDone){
std::cerr << "Transfer error for " << shape_file << std::endl; throw SALOME_Exception("Reading error for " + shape_file);
return true;
} }
aStat = aWriter.Write(shape_file.c_str()); aStat = aWriter.Write(shape_file.c_str());
if(aStat != IFSelect_RetDone){ if(aStat != IFSelect_RetDone){
std::cerr << "Writing error for " << shape_file << std::endl; throw SALOME_Exception("Writing error for " + shape_file);
return true;
} }
return aStat; return aStat;
} }
@ -156,8 +154,7 @@ int importShape(const std::string shape_file, TopoDS_Shape& aShape){
} else if (type == ".step"){ } else if (type == ".step"){
return importSTEPShape(shape_file, aShape); return importSTEPShape(shape_file, aShape);
} else { } else {
std::cerr << "Unknow format: " << type << std::endl; throw SALOME_Exception("Unknow format for importShape: " + type);
return true;
} }
} }
@ -177,7 +174,6 @@ int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
} else if (type == ".step"){ } else if (type == ".step"){
return exportSTEPShape(shape_file, aShape); return exportSTEPShape(shape_file, aShape);
} else { } else {
std::cerr << "Unknow format: " << type << std::endl; throw SALOME_Exception("Unknow format for exportShape: " + type);
return true;
} }
} }

View File

@ -462,5 +462,4 @@ protected:
SMESH_Mesh(); SMESH_Mesh();
SMESH_Mesh(const SMESH_Mesh&) {}; SMESH_Mesh(const SMESH_Mesh&) {};
}; };
#endif #endif

View File

@ -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();
}

View File

@ -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

View File

@ -37,6 +37,7 @@
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_MesherHelper.hxx" #include "SMESH_MesherHelper.hxx"
#include "SMESH_subMeshEventListener.hxx" #include "SMESH_subMeshEventListener.hxx"
#include "SMESH_MeshLocker.hxx"
#include "utilities.h" #include "utilities.h"
#include "Basics_Utils.hxx" #include "Basics_Utils.hxx"
@ -1393,16 +1394,13 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
else if (( event == COMPUTE || event == COMPUTE_SUBMESH ) else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
&& !_alwaysComputed ) && !_alwaysComputed )
{ {
// LOCK: Adding node to mesh SMESH_MeshLocker myLocker(_father);
_father->Lock();
const TopoDS_Vertex & V = TopoDS::Vertex( _subShape ); const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
gp_Pnt P = BRep_Tool::Pnt(V); gp_Pnt P = BRep_Tool::Pnt(V);
if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) { if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
_father->GetMeshDS()->SetNodeOnVertex(n,_Id); _father->GetMeshDS()->SetNodeOnVertex(n,_Id);
_computeState = COMPUTE_OK; _computeState = COMPUTE_OK;
} }
_father->Unlock();
// UNLOCK
} }
if ( event == MODIF_ALGO_STATE ) if ( event == MODIF_ALGO_STATE )
cleanDependants(); cleanDependants();
@ -1516,9 +1514,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
break; break;
} }
TopoDS_Shape shape = _subShape; TopoDS_Shape shape = _subShape;
_father->Lock(); algo->setSubMeshesToCompute(this);
algo->SubMeshesToCompute().assign( 1, this );
_father->Unlock();
// check submeshes needed // check submeshes needed
// In parallel there would be no submesh to check // In parallel there would be no submesh to check
if (_father->HasShapeToMesh() && !_father->IsParallel()) { if (_father->HasShapeToMesh() && !_father->IsParallel()) {
@ -1650,10 +1646,11 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
#ifdef PRINT_WHO_COMPUTE_WHAT #ifdef PRINT_WHO_COMPUTE_WHAT
for (subS.ReInit(); subS.More(); subS.Next()) for (subS.ReInit(); subS.More(); subS.Next())
{ {
_father->Lock(); const std::list <const SMESHDS_Hypothesis *> & hyps
const std::list <const SMESHDS_Hypothesis *> & hyps = {
_algo->GetUsedHypothesis( *_father, _subShape ); SMESH_MeshLocker myLocker(_father);
_father->Unlock(); hyps = _algo->GetUsedHypothesis( *_father, _subShape );
}
SMESH_Comment hypStr; SMESH_Comment hypStr;
if ( !hyps.empty() ) if ( !hyps.empty() )
{ {