X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Mesh.cxx;h=2f3644e58682f3ef44e2f33bedeb6fd37418baeb;hb=7191b0d7359a31f9dee70d1020d8c0c7d8386e31;hp=52ac6154be2ad76167ccd7c1e4f5f23cf3b7b524;hpb=a710674f8336f2863fcb169aa59d0cc1917113ae;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 52ac6154b..2f3644e58 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SMESH SMESH : implementaion of SMESH idl descriptions // File : SMESH_Mesh.cxx // Author : Paul RASCLE, EDF @@ -98,10 +99,29 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId, _myMeshDS = theDocument->GetMesh(_idDoc); _isShapeToMesh = false; _isAutoColor = false; + _isModified = false; _shapeDiagonal = 0.0; + _rmGroupCallUp = 0; _myMeshDS->ShapeToMesh( PseudoShape() ); } +//================================================================================ +/*! + * \brief Constructor of SMESH_Mesh being a base of some descendant class + */ +//================================================================================ + +SMESH_Mesh::SMESH_Mesh(): + _groupId( 0 ), _nbSubShapes( 0 ) +{ + _myMeshDS = 0; + _isShapeToMesh = false; + _isAutoColor = false; + _isModified = false; + _shapeDiagonal = 0.0; + _rmGroupCallUp = 0; +} + //============================================================================= /*! * @@ -124,6 +144,9 @@ SMESH_Mesh::~SMESH_Mesh() delete aGroup; } _mapGroup.clear(); + + if ( _rmGroupCallUp) delete _rmGroupCallUp; + _rmGroupCallUp = 0; } //============================================================================= @@ -186,6 +209,7 @@ void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape) _shapeDiagonal = 0.0; _myMeshDS->ShapeToMesh( PseudoShape() ); } + _isModified = false; } //======================================================================= @@ -258,55 +282,14 @@ void SMESH_Mesh::Clear() _myMeshDS->ClearMesh(); // update compute state of submeshes - if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) { - SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, - /*complexShapeFirst=*/false); - while ( smIt->more() ) { - sm = smIt->next(); - sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); - } + if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) + { + sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); + sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918) + sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN ); } - -// // clear sub-meshes; get ready to re-compute as a side-effect - -// if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) -// { -// SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true, -// /*complexShapeFirst=*/false); -// while ( smIt->more() ) -// { -// sm = smIt->next(); -// TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType(); -// if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID ) -// // all other shapes depends on vertices so they are already cleaned -// sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); -// // to recompute even if failed -// sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE ); -// } -// } - -// // clear entities not on sub-meshes - -// SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator(); -// while ( vIt->more() ) -// _myMeshDS->RemoveFreeElement( vIt->next(), 0 ); - -// SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator(); -// while ( fIt->more() ) -// _myMeshDS->RemoveFreeElement( fIt->next(), 0 ); - -// SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator(); -// while ( eIt->more() ) -// _myMeshDS->RemoveFreeElement( eIt->next(), 0 ); - -// SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator(); -// while ( nIt->more() ) { -// const SMDS_MeshNode * node = nIt->next(); -// if ( node->NbInverseElements() == 0 ) -// _myMeshDS->RemoveFreeNode( node, 0 ); -// else -// _myMeshDS->RemoveNode(node); -// } + _isModified = false; } //======================================================================= @@ -494,6 +477,9 @@ SMESH_Hypothesis::Hypothesis_Status // NotConformAllowed can be only global if ( !isGlobalHyp ) { + // NOTE: this is not a correct way to check a name of hypothesis, + // there should be an attribute of hypothesis saying that it can/can't + // be global/local string hypName = anHyp->GetName(); if ( hypName == "NotConformAllowed" ) { @@ -536,6 +522,9 @@ SMESH_Hypothesis::Hypothesis_Status } } } + HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty + + GetMeshDS()->Modified(); if(MYDEBUG) subMesh->DumpAlgoState(true); if(MYDEBUG) SCRUTE(ret); @@ -607,7 +596,11 @@ SMESH_Hypothesis::Hypothesis_Status } } } - + + HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty + + GetMeshDS()->Modified(); + if(MYDEBUG) subMesh->DumpAlgoState(true); if(MYDEBUG) SCRUTE(ret); return ret; @@ -1004,6 +997,8 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h } } } + HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty + GetMeshDS()->Modified(); } //============================================================================= @@ -1023,6 +1018,57 @@ bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception) return _isAutoColor; } +//======================================================================= +//function : SetIsModified +//purpose : Set the flag meaning that the mesh has been edited "manually" +//======================================================================= + +void SMESH_Mesh::SetIsModified(bool isModified) +{ + _isModified = isModified; + + if ( _isModified ) + // check if mesh becomes empty as result of modification + HasModificationsToDiscard(); +} + +//======================================================================= +//function : HasModificationsToDiscard +//purpose : Return true if the mesh has been edited since a total re-compute +// and those modifications may prevent successful partial re-compute. +// As a side effect reset _isModified flag if mesh is empty +//issue : 0020693 +//======================================================================= + +bool SMESH_Mesh::HasModificationsToDiscard() const +{ + if ( ! _isModified ) + return false; + + // return true if there the next Compute() will be partial and + // existing but changed elements may prevent successful re-compute + bool hasComputed = false, hasNotComputed = false; + map ::const_iterator i_sm = _mapSubMesh.begin(); + for ( ; i_sm != _mapSubMesh.end() ; ++i_sm ) + switch ( i_sm->second->GetSubShape().ShapeType() ) + { + case TopAbs_EDGE: + case TopAbs_FACE: + case TopAbs_SOLID: + if ( i_sm->second->IsMeshComputed() ) + hasComputed = true; + else + hasNotComputed = true; + if ( hasComputed && hasNotComputed) + return true; + } + + if ( !hasComputed ) + const_cast(this)->_isModified = false; + + return false; +} + //============================================================================= /*! Export* methods. * To store mesh contents on disk in different formats. @@ -1146,7 +1192,7 @@ void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Ex */ //================================================================================ -int SMESH_Mesh::NbNodes() throw(SALOME_Exception) +int SMESH_Mesh::NbNodes() const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->NbNodes(); @@ -1158,7 +1204,7 @@ int SMESH_Mesh::NbNodes() throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception) +int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().Nb0DElements(); @@ -1170,7 +1216,7 @@ int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbEdges(order); @@ -1182,7 +1228,7 @@ int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbFaces(order); @@ -1194,7 +1240,7 @@ int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbTriangles(order); @@ -1206,7 +1252,7 @@ int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbQuadrangles(order); @@ -1218,7 +1264,7 @@ int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception */ //================================================================================ -int SMESH_Mesh::NbPolygons() throw(SALOME_Exception) +int SMESH_Mesh::NbPolygons() const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbPolygons(); @@ -1230,7 +1276,7 @@ int SMESH_Mesh::NbPolygons() throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbVolumes(order); @@ -1242,7 +1288,7 @@ int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbTetras(order); @@ -1254,7 +1300,7 @@ int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbHexas(order); @@ -1266,7 +1312,7 @@ int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbPyramids(order); @@ -1278,7 +1324,7 @@ int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception) +int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbPrisms(order); @@ -1290,7 +1336,7 @@ int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception) +int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->GetMeshInfo().NbPolyhedrons(); @@ -1302,7 +1348,7 @@ int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception) */ //================================================================================ -int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception) +int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception) { Unexpect aCatch(SalomeException); return _myMeshDS->NbSubMesh(); @@ -1392,6 +1438,18 @@ list SMESH_Mesh::GetGroupIds() const return anIds; } +//================================================================================ +/*! + * \brief Set a caller of RemoveGroup() at level of CORBA API implementation. + * The set upCaller will be deleted by SMESH_Mesh + */ +//================================================================================ + +void SMESH_Mesh::SetRemoveGroupCallUp( TRmGroupCallUp* upCaller ) +{ + if ( _rmGroupCallUp ) delete _rmGroupCallUp; + _rmGroupCallUp = upCaller; +} //============================================================================= /*! @@ -1399,13 +1457,16 @@ list SMESH_Mesh::GetGroupIds() const */ //============================================================================= -void SMESH_Mesh::RemoveGroup (const int theGroupID) +bool SMESH_Mesh::RemoveGroup (const int theGroupID) { if (_mapGroup.find(theGroupID) == _mapGroup.end()) - return; + return false; GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() ); delete _mapGroup[theGroupID]; _mapGroup.erase (theGroupID); + if (_rmGroupCallUp) + _rmGroupCallUp->RemoveGroup( theGroupID ); + return true; } //======================================================================= @@ -1594,6 +1655,7 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape) for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- ) for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next()) { + if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() ); TopTools_ListIteratorOfListOfShape ancIt (ancList); while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )