Implement Cancel Compute

This commit is contained in:
adam 2011-03-17 11:03:40 +00:00
parent c9d186bf9d
commit 2cdf1b2ac7
9 changed files with 106 additions and 0 deletions

View File

@ -1661,6 +1661,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
comment << text(err); comment << text(err);
} }
catch (Standard_Failure& ex) catch (Standard_Failure& ex)
@ -1726,6 +1730,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
netgen::OCCGenerateMesh(occgeo, tmpNgMesh, startWith, endWith, optstr); netgen::OCCGenerateMesh(occgeo, tmpNgMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
// compute mesh on internal edges // compute mesh on internal edges
endWith = netgen::MESHCONST_MESHEDGES; endWith = netgen::MESHCONST_MESHEDGES;
err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, startWith, endWith, optstr);
@ -1760,6 +1768,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
comment << text(err); comment << text(err);
} }
catch (Standard_Failure& ex) catch (Standard_Failure& ex)
@ -1825,6 +1837,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
comment << text (err); comment << text (err);
} }
catch (Standard_Failure& ex) catch (Standard_Failure& ex)
@ -1887,6 +1903,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
comment << text(err); comment << text(err);
} }
catch (Standard_Failure& ex) catch (Standard_Failure& ex)
@ -1907,6 +1927,10 @@ bool NETGENPlugin_Mesher::Compute()
{ {
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
comment << text(err); comment << text(err);
} }
catch (Standard_Failure& ex) catch (Standard_Failure& ex)
@ -2062,6 +2086,10 @@ bool NETGENPlugin_Mesher::Evaluate(MapShapeNbElems& aResMap)
int startWith = netgen::MESHCONST_ANALYSE; int startWith = netgen::MESHCONST_ANALYSE;
int endWith = netgen::MESHCONST_MESHEDGES; int endWith = netgen::MESHCONST_MESHEDGES;
int err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); int err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
ngLib.setMesh(( Ng_Mesh*) ngMesh ); ngLib.setMesh(( Ng_Mesh*) ngMesh );
if (err) { if (err) {
if ( SMESH_subMesh* sm = _mesh->GetSubMeshContaining( _shape )) if ( SMESH_subMesh* sm = _mesh->GetSubMeshContaining( _shape ))

View File

@ -41,6 +41,13 @@
#include <list> #include <list>
#ifdef WITH_SMESH_CANCEL_COMPUTE
namespace nglib {
#include <nglib.h>
}
#include <meshing.hpp>
#endif
using namespace std; using namespace std;
//============================================================================= //=============================================================================
@ -122,6 +129,9 @@ bool NETGENPlugin_NETGEN_2D::CheckHypothesis
bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape& aShape)
{ {
#ifdef WITH_SMESH_CANCEL_COMPUTE
netgen::multithread.terminate = 0;
#endif
//SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); //SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
NETGENPlugin_Mesher mesher(&aMesh, aShape, false); NETGENPlugin_Mesher mesher(&aMesh, aShape, false);
@ -131,6 +141,12 @@ bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh,
return mesher.Compute(); return mesher.Compute();
} }
#ifdef WITH_SMESH_CANCEL_COMPUTE
void NETGENPlugin_NETGEN_2D::CancelCompute()
{
netgen::multithread.terminate = 1;
}
#endif
//============================================================================= //=============================================================================
/*! /*!

View File

@ -53,6 +53,10 @@ public:
virtual bool Compute(SMESH_Mesh& aMesh, virtual bool Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape); const TopoDS_Shape& aShape);
#ifdef WITH_SMESH_CANCEL_COMPUTE
virtual void CancelCompute();
#endif
virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
MapShapeNbElems& aResMap); MapShapeNbElems& aResMap);

View File

@ -41,6 +41,13 @@
#include <list> #include <list>
#ifdef WITH_SMESH_CANCEL_COMPUTE
namespace nglib {
#include <nglib.h>
}
#include <meshing.hpp>
#endif
using namespace std; using namespace std;
//============================================================================= //=============================================================================
@ -125,6 +132,9 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis
bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape& aShape)
{ {
#ifdef WITH_SMESH_CANCEL_COMPUTE
netgen::multithread.terminate = 0;
#endif
// SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); // SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
NETGENPlugin_Mesher mesher(&aMesh, aShape, true); NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
@ -134,6 +144,12 @@ bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh,
return mesher.Compute(); return mesher.Compute();
} }
#ifdef WITH_SMESH_CANCEL_COMPUTE
void NETGENPlugin_NETGEN_2D3D::CancelCompute()
{
netgen::multithread.terminate = 1;
}
#endif
//============================================================================= //=============================================================================
/*! /*!

View File

@ -53,6 +53,10 @@ public:
virtual bool Compute(SMESH_Mesh& aMesh, virtual bool Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape); const TopoDS_Shape& aShape);
#ifdef WITH_SMESH_CANCEL_COMPUTE
virtual void CancelCompute();
#endif
virtual bool Evaluate(SMESH_Mesh& aMesh, virtual bool Evaluate(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape, const TopoDS_Shape& aShape,
MapShapeNbElems& aResMap); MapShapeNbElems& aResMap);

View File

@ -362,6 +362,9 @@ static TError AddSegmentsToMesh(netgen::Mesh& ngMesh,
bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape& aShape)
{ {
#ifdef WITH_SMESH_CANCEL_COMPUTE
netgen::multithread.terminate = 0;
#endif
MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::Compute()"); MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::Compute()");
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
@ -461,6 +464,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
#endif #endif
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
if ( err ) if ( err )
error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task);
} }
@ -537,6 +544,12 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
return !err; return !err;
} }
#ifdef WITH_SMESH_CANCEL_COMPUTE
void NETGENPlugin_NETGEN_2D_ONLY::CancelCompute()
{
netgen::multithread.terminate = 1;
}
#endif
//============================================================================= //=============================================================================
/*! /*!

View File

@ -53,6 +53,10 @@ public:
virtual bool Compute(SMESH_Mesh& aMesh, virtual bool Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape); const TopoDS_Shape& aShape);
#ifdef WITH_SMESH_CANCEL_COMPUTE
virtual void CancelCompute();
#endif
virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
MapShapeNbElems& aResMap); MapShapeNbElems& aResMap);

View File

@ -180,6 +180,9 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh,
bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape) const TopoDS_Shape& aShape)
{ {
#ifdef WITH_SMESH_CANCEL_COMPUTE
netgen::multithread.terminate = 0;
#endif
MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume); MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume);
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
@ -335,6 +338,9 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh,
vector< const SMDS_MeshNode* >& nodeVec, vector< const SMDS_MeshNode* >& nodeVec,
Ng_Mesh * Netgen_mesh) Ng_Mesh * Netgen_mesh)
{ {
#ifdef WITH_SMESH_CANCEL_COMPUTE
netgen::multithread.terminate = 0;
#endif
netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh; netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh;
int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh);
@ -375,6 +381,10 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh,
#endif #endif
ngMesh->CalcLocalH(); ngMesh->CalcLocalH();
err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
#ifdef WITH_SMESH_CANCEL_COMPUTE
if(netgen::multithread.terminate)
return false;
#endif
if ( err ) if ( err )
error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task);
} }
@ -541,6 +551,13 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
return compute( aMesh, *aHelper, nodeVec, Netgen_mesh); return compute( aMesh, *aHelper, nodeVec, Netgen_mesh);
} }
#ifdef WITH_SMESH_CANCEL_COMPUTE
void NETGENPlugin_NETGEN_3D::CancelCompute()
{
netgen::multithread.terminate = 1;
}
#endif
//============================================================================= //=============================================================================
/*! /*!
* *

View File

@ -57,6 +57,10 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo
virtual bool Compute(SMESH_Mesh& aMesh, virtual bool Compute(SMESH_Mesh& aMesh,
SMESH_MesherHelper* aHelper); SMESH_MesherHelper* aHelper);
#ifdef WITH_SMESH_CANCEL_COMPUTE
virtual void CancelCompute();
#endif
virtual bool Evaluate(SMESH_Mesh& aMesh, virtual bool Evaluate(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape, const TopoDS_Shape& aShape,
MapShapeNbElems& aResMap); MapShapeNbElems& aResMap);