X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Mesh.cxx;h=73030e901a943a47e4012b9870bc435b4411c03d;hp=dcdf7fe3f81ecb4cba3b7eff76455e3e5347230b;hb=53a2fb6d670a8c71eb30dfa339447a25cd728e80;hpb=fa9a9581d37a45a53111f7df9ae5429c9692851f diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index dcdf7fe3f..73030e901 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2015 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 @@ -55,6 +55,8 @@ #include "DriverCGNS_Write.hxx" #endif +#include + #undef _Precision_HeaderFile #include #include @@ -70,11 +72,12 @@ #include "SMESH_TryCatch.hxx" // include after OCCT headers! #include "Utils_ExceptHandlers.hxx" + #ifndef WIN32 #include #include #else -#include +#include #endif using namespace std; @@ -178,6 +181,11 @@ SMESH_Mesh::~SMESH_Mesh() { MESSAGE("SMESH_Mesh::~SMESH_Mesh"); + // avoid usual removal of elements while processing RemoveHypothesis( algo ) event + SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes(); + while ( smIt->more() ) + const_cast( smIt->next() )->Clear(); + // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study // Notify event listeners at least that something happens if ( SMESH_subMesh * sm = GetSubMeshContaining(1)) @@ -226,7 +234,7 @@ SMESH_Mesh::~SMESH_Mesh() bool SMESH_Mesh::MeshExists( int meshId ) const { - return _myDocument ? _myDocument->GetMesh( meshId ) : false; + return _myDocument ? bool( _myDocument->GetMesh( meshId )) : false; } //============================================================================= @@ -327,8 +335,18 @@ double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape) { if ( !aShape.IsNull() ) { Bnd_Box Box; - BRepBndLib::Add(aShape, Box); - return sqrt( Box.SquareExtent() ); + // avoid too long waiting on large shapes. PreciseBoundingBox() was added + // to assure same result which else depends on presence of triangulation (IPAL52557). + const int maxNbFaces = 4000; + int nbFaces = 0; + for ( TopExp_Explorer f( aShape, TopAbs_FACE ); f.More() && nbFaces < maxNbFaces; f.Next() ) + ++nbFaces; + if ( nbFaces < maxNbFaces ) + GEOMUtils::PreciseBoundingBox(aShape, Box); + else + BRepBndLib::Add( aShape, Box); + if ( !Box.IsVoid() ) + return sqrt( Box.SquareExtent() ); } return 0; } @@ -601,12 +619,16 @@ SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName, //============================================================================= SMESH_Hypothesis::Hypothesis_Status - SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape, - int anHypId ) throw(SALOME_Exception) +SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape, + int anHypId, + std::string* anError ) throw(SALOME_Exception) { Unexpect aCatch(SalomeException); if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis"); + if ( anError ) + anError->clear(); + SMESH_subMesh *subMesh = GetSubMesh(aSubShape); if ( !subMesh || !subMesh->GetId()) return SMESH_Hypothesis::HYP_BAD_SUBSHAPE; @@ -631,23 +653,36 @@ SMESH_Hypothesis::Hypothesis_Status } } - // shape + // shape - bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO ); - int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP; + bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO ); + int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP; SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp); + if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() ) + *anError = subMesh->GetComputeError()->myComment; + // sub-shapes - if (!SMESH_Hypothesis::IsStatusFatal(ret) && - anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father + if ( !SMESH_Hypothesis::IsStatusFatal(ret) && + anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father { event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP; SMESH_Hypothesis::Hypothesis_Status ret2 = - subMesh->SubMeshesAlgoStateEngine(event, anHyp); + subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true); if (ret2 > ret) + { ret = ret2; + if ( SMESH_Hypothesis::IsStatusFatal( ret )) + { + if ( anError && subMesh->GetComputeError() ) + *anError = subMesh->GetComputeError()->myComment; + // remove anHyp + event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP; + subMesh->AlgoStateEngine(event, anHyp); + } + } // check concurent hypotheses on ancestors if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp ) @@ -892,16 +927,19 @@ int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh, const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape(); const list& hypList = _myMeshDS->GetHypothesis(aSubShape); for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ ) - if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) && - ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) && - hypTypes.insert( (*hyp)->GetName() ).second ) + { + const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp ); + if (( aFilter.IsOk( h, aSubShape )) && + ( h->IsAuxiliary() || !mainHypFound ) && + ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second )) { aHypList.push_back( *hyp ); nbHyps++; - if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() ) + if ( !h->IsAuxiliary() ) mainHypFound = true; if ( assignedTo ) assignedTo->push_back( aSubShape ); } + } } // get hypos from ancestors of aSubShape @@ -918,16 +956,19 @@ int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh, const TopoDS_Shape& curSh = (*smIt)->GetSubShape(); const list& hypList = _myMeshDS->GetHypothesis(curSh); for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ ) - if (( aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh )) && - ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) && - ( hypTypes.insert( (*hyp)->GetName() ).second )) + { + const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp ); + if (( aFilter.IsOk( h, curSh )) && + ( h->IsAuxiliary() || !mainHypFound ) && + ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second )) { aHypList.push_back( *hyp ); nbHyps++; - if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() ) + if ( !h->IsAuxiliary() ) mainHypFound = true; if ( assignedTo ) assignedTo->push_back( curSh ); } + } } } return nbHyps; @@ -1189,7 +1230,8 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h // other possible changes are not interesting. (IPAL0052457 - assigning hyp performance pb) if ( aSubMesh->GetComputeState() != SMESH_subMesh::COMPUTE_OK && aSubMesh->GetComputeState() != SMESH_subMesh::FAILED_TO_COMPUTE && - aSubMesh->GetAlgoState() != SMESH_subMesh::MISSING_HYP ) + aSubMesh->GetAlgoState() != SMESH_subMesh::MISSING_HYP && + !hyp->DataDependOnParams() ) continue; const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape(); @@ -1844,6 +1886,18 @@ int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception) return _myMeshDS->NbSubMesh(); } +//================================================================================ +/*! + * \brief Returns number of meshes in the Study, that is supposed to be + * equal to SMESHDS_Document::NbMeshes() + */ +//================================================================================ + +int SMESH_Mesh::NbMeshes() const // nb meshes in the Study +{ + return _myDocument->NbMeshes(); +} + //======================================================================= //function : IsNotConformAllowed //purpose : check if a hypothesis alowing notconform mesh is present @@ -2127,9 +2181,9 @@ SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID ) return aGroup; SMESH_Group* anOldGrp = (*itg).second; - SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS(); - if ( !anOldGrp || !anOldGrpDS ) + if ( !anOldGrp || !anOldGrp->GetGroupDS() ) return aGroup; + SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS(); // create new standalone group aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() ); @@ -2210,8 +2264,8 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape) TopTools_ListIteratorOfListOfShape ancIt (ancList); while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType ) ancIt.Next(); - if ( ancIt.More() ) - ancList.InsertBefore( theShape, ancIt ); + if ( ancIt.More() ) ancList.InsertBefore( theShape, ancIt ); + else ancList.Append( theShape ); } } else // else added for 52457: Addition of hypotheses is 8 time longer than meshing