From 2cdf1b2ac7243875750580f670debe754d3f4d80 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 17 Mar 2011 11:03:40 +0000 Subject: [PATCH] Implement Cancel Compute --- src/NETGENPlugin/NETGENPlugin_Mesher.cxx | 28 +++++++++++++++++++ src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx | 16 +++++++++++ src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx | 4 +++ src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx | 16 +++++++++++ src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx | 4 +++ .../NETGENPlugin_NETGEN_2D_ONLY.cxx | 13 +++++++++ .../NETGENPlugin_NETGEN_2D_ONLY.hxx | 4 +++ src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 17 +++++++++++ src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx | 4 +++ 9 files changed, 106 insertions(+) diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index 4840012..2c8a24c 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -1661,6 +1661,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif comment << text(err); } catch (Standard_Failure& ex) @@ -1726,6 +1730,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; netgen::OCCGenerateMesh(occgeo, tmpNgMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif // compute mesh on internal edges endWith = netgen::MESHCONST_MESHEDGES; err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, startWith, endWith, optstr); @@ -1760,6 +1768,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif comment << text(err); } catch (Standard_Failure& ex) @@ -1825,6 +1837,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif comment << text (err); } catch (Standard_Failure& ex) @@ -1887,6 +1903,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif comment << text(err); } catch (Standard_Failure& ex) @@ -1907,6 +1927,10 @@ bool NETGENPlugin_Mesher::Compute() { OCC_CATCH_SIGNALS; err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif comment << text(err); } catch (Standard_Failure& ex) @@ -2062,6 +2086,10 @@ bool NETGENPlugin_Mesher::Evaluate(MapShapeNbElems& aResMap) int startWith = netgen::MESHCONST_ANALYSE; int endWith = netgen::MESHCONST_MESHEDGES; 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 ); if (err) { if ( SMESH_subMesh* sm = _mesh->GetSubMeshContaining( _shape )) diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx index ed5526a..4d6d898 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cxx @@ -41,6 +41,13 @@ #include +#ifdef WITH_SMESH_CANCEL_COMPUTE +namespace nglib { +#include +} +#include +#endif + using namespace std; //============================================================================= @@ -122,6 +129,9 @@ bool NETGENPlugin_NETGEN_2D::CheckHypothesis bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + netgen::multithread.terminate = 0; +#endif //SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); NETGENPlugin_Mesher mesher(&aMesh, aShape, false); @@ -131,6 +141,12 @@ bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh& aMesh, return mesher.Compute(); } +#ifdef WITH_SMESH_CANCEL_COMPUTE +void NETGENPlugin_NETGEN_2D::CancelCompute() +{ + netgen::multithread.terminate = 1; +} +#endif //============================================================================= /*! diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx index 2c25b82..018d526 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.hxx @@ -53,6 +53,10 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); +#ifdef WITH_SMESH_CANCEL_COMPUTE + virtual void CancelCompute(); +#endif + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx index 3ce64cc..9946523 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.cxx @@ -41,6 +41,13 @@ #include +#ifdef WITH_SMESH_CANCEL_COMPUTE +namespace nglib { +#include +} +#include +#endif + using namespace std; //============================================================================= @@ -125,6 +132,9 @@ bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + netgen::multithread.terminate = 0; +#endif // SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); NETGENPlugin_Mesher mesher(&aMesh, aShape, true); @@ -134,6 +144,12 @@ bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh, return mesher.Compute(); } +#ifdef WITH_SMESH_CANCEL_COMPUTE +void NETGENPlugin_NETGEN_2D3D::CancelCompute() +{ + netgen::multithread.terminate = 1; +} +#endif //============================================================================= /*! diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx index 539dc25..a37a056 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D3D.hxx @@ -53,6 +53,10 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); +#ifdef WITH_SMESH_CANCEL_COMPUTE + virtual void CancelCompute(); +#endif + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index 298c948..883823a 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -362,6 +362,9 @@ static TError AddSegmentsToMesh(netgen::Mesh& ngMesh, bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + netgen::multithread.terminate = 0; +#endif MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::Compute()"); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); @@ -461,6 +464,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, OCC_CATCH_SIGNALS; #endif err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif if ( err ) 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; } +#ifdef WITH_SMESH_CANCEL_COMPUTE +void NETGENPlugin_NETGEN_2D_ONLY::CancelCompute() +{ + netgen::multithread.terminate = 1; +} +#endif //============================================================================= /*! diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx index b608caf..1a9fee8 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx @@ -53,6 +53,10 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); +#ifdef WITH_SMESH_CANCEL_COMPUTE + virtual void CancelCompute(); +#endif + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index a28ad1f..8ab7b3e 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -180,6 +180,9 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + netgen::multithread.terminate = 0; +#endif MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume); SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); @@ -335,6 +338,9 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, vector< const SMDS_MeshNode* >& nodeVec, Ng_Mesh * Netgen_mesh) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + netgen::multithread.terminate = 0; +#endif netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh; int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); @@ -375,6 +381,10 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, #endif ngMesh->CalcLocalH(); err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(netgen::multithread.terminate) + return false; +#endif if ( err ) 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); } +#ifdef WITH_SMESH_CANCEL_COMPUTE +void NETGENPlugin_NETGEN_3D::CancelCompute() +{ + netgen::multithread.terminate = 1; +} +#endif + //============================================================================= /*! * diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx index 54ba49f..9a795f0 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx @@ -57,6 +57,10 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo virtual bool Compute(SMESH_Mesh& aMesh, SMESH_MesherHelper* aHelper); +#ifdef WITH_SMESH_CANCEL_COMPUTE + virtual void CancelCompute(); +#endif + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap);