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

View File

@ -277,6 +277,9 @@ 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:
// ==================================================================

View 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);
}
}

View File

@ -462,5 +462,4 @@ protected:
SMESH_Mesh();
SMESH_Mesh(const SMESH_Mesh&) {};
};
#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_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() )
{