From 0e55a67f3c74e75b56b95e166e91b3cc4abac97c Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 3 Mar 2006 13:59:10 +0000 Subject: [PATCH] fix the problem that an existing mesh is not deleted when a "Quadratic Mesh" hypothesis is (un)assigned. Speed optimization of submesh notifiacation on hypothesis modification --- src/SMESH/SMESH_2D_Algo.cxx | 8 +- src/SMESH/SMESH_2D_Algo.hxx | 2 - src/SMESH/SMESH_Algo.cxx | 55 +++++++---- src/SMESH/SMESH_Algo.hxx | 21 +++- src/SMESH/SMESH_Gen.cxx | 15 +-- src/SMESH/SMESH_HypoFilter.cxx | 22 +++++ src/SMESH/SMESH_HypoFilter.hxx | 6 ++ src/SMESH/SMESH_Hypothesis.cxx | 18 ++-- src/SMESH/SMESH_Hypothesis.hxx | 19 +++- src/SMESH/SMESH_Mesh.cxx | 173 ++++++++++++++++++++++++--------- src/SMESH/SMESH_Mesh.hxx | 15 +-- src/SMESH/SMESH_subMesh.cxx | 60 +++++++----- src/SMESH/SMESH_subMesh.hxx | 10 +- 13 files changed, 296 insertions(+), 128 deletions(-) diff --git a/src/SMESH/SMESH_2D_Algo.cxx b/src/SMESH/SMESH_2D_Algo.cxx index ea44619be..1c9af478a 100644 --- a/src/SMESH/SMESH_2D_Algo.cxx +++ b/src/SMESH/SMESH_2D_Algo.cxx @@ -45,7 +45,6 @@ SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen) // _compatibleHypothesis.push_back("hypothese_2D_bidon"); _type = ALGO_2D; gen->_map2D_Algo[hypId] = this; - myCreateQuadratic = false; } //============================================================================= @@ -56,7 +55,6 @@ SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen) SMESH_2D_Algo::~SMESH_2D_Algo() { - myCreateQuadratic = false; } //============================================================================= @@ -85,12 +83,10 @@ int SMESH_2D_Algo::NumberOfPoints(SMESH_Mesh& aMesh, const TopoDS_Wire& W) for (TopExp_Explorer exp(W,TopAbs_EDGE); exp.More(); exp.Next()) { const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - if(myCreateQuadratic) + if(_quadraticMesh) nb = nb/2; - //SCRUTE(nb); - nbPoints += nb +1; // internal points plus 1 vertex of 2 (last point ?) + nbPoints += nb + 1; // internal points plus 1 vertex of 2 (last point ?) } - //SCRUTE(nbPoints); return nbPoints; } diff --git a/src/SMESH/SMESH_2D_Algo.hxx b/src/SMESH/SMESH_2D_Algo.hxx index 65857fced..259a51157 100644 --- a/src/SMESH/SMESH_2D_Algo.hxx +++ b/src/SMESH/SMESH_2D_Algo.hxx @@ -43,8 +43,6 @@ public: int NumberOfWires(const TopoDS_Shape& S); int NumberOfPoints(SMESH_Mesh& aMesh,const TopoDS_Wire& W); -protected: - bool myCreateQuadratic; }; #endif diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 9d439f763..6faae56c3 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -68,6 +68,7 @@ SMESH_Algo::SMESH_Algo(int hypId, int studyId, gen->_mapAlgo[hypId] = this; _onlyUnaryInput = _requireDescretBoundary = true; + _quadraticMesh = false; } //============================================================================= @@ -101,18 +102,17 @@ const vector < string > &SMESH_Algo::GetCompatibleHypothesis() */ //============================================================================= -const list & SMESH_Algo::GetUsedHypothesis( - SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) +const list & +SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape, + const bool ignoreAuxiliary) { _usedHypList.clear(); - if ( !_compatibleHypothesis.empty() ) + SMESH_HypoFilter filter; + if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) { - SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] )); - for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) - filter.Or( filter.HasName( _compatibleHypothesis[ i ] )); - aMesh.GetHypotheses( aShape, filter, _usedHypList, true ); - if ( _usedHypList.size() > 1 ) + if ( ignoreAuxiliary && _usedHypList.size() > 1 ) _usedHypList.clear(); //only one compatible hypothesis allowed } return _usedHypList; @@ -126,18 +126,16 @@ const list & SMESH_Algo::GetUsedHypothesis( */ //============================================================================= -const list & SMESH_Algo::GetAppliedHypothesis( - SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) +const list & +SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape, + const bool ignoreAuxiliary) { _appliedHypList.clear(); - if ( !_compatibleHypothesis.empty() ) - { - SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] )); - for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) - filter.Or( filter.HasName( _compatibleHypothesis[ i ] )); - + SMESH_HypoFilter filter; + if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) aMesh.GetHypotheses( aShape, filter, _appliedHypList, false ); - } + return _appliedHypList; } @@ -267,3 +265,26 @@ bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace, return Ne * Nf < 0.; } + +/*! + * \brief Make filter recognize only compatible hypotheses + * \param theFilter - the filter to initialize + * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses + */ +bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter, + const bool ignoreAuxiliary) const +{ + if ( !_compatibleHypothesis.empty() ) + { + theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] )); + for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) + theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] )); + + if ( ignoreAuxiliary ) + theFilter.AndNot( theFilter.IsAuxiliary() ); + + return true; + } + return false; +} + diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 5acc2b242..e4df42f84 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -42,6 +42,7 @@ class SMESH_Gen; class SMESH_Mesh; +class SMESH_HypoFilter; class TopoDS_Face; class SMESHDS_Mesh; class SMDS_MeshNode; @@ -60,13 +61,27 @@ class SMESH_Algo:public SMESH_Hypothesis virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0; virtual const std::list & - GetUsedHypothesis(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape); + GetUsedHypothesis(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape, + const bool ignoreAuxiliary=true); const list & - GetAppliedHypothesis(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape); + GetAppliedHypothesis(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape, + const bool ignoreAuxiliary=true); static double EdgeLength(const TopoDS_Edge & E); + + /*! + * \brief Make filter recognize only compatible hypotheses + * \param theFilter - the filter to initialize + * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses + * \retval bool - true if the algo has compatible hypotheses + */ + bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter, + const bool ignoreAuxiliary) const; + /*! * \brief Find out elements orientation on a geometrical face * \param theFace - The face correctly oriented in the shape being meshed @@ -101,6 +116,8 @@ class SMESH_Algo:public SMESH_Hypothesis std::list _appliedHypList; std::list _usedHypList; + // quadratic mesh creation required + bool _quadraticMesh; }; #endif diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index c5a611a29..ef2edcb70 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -633,13 +633,14 @@ SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) if ( algoList.empty() ) return NULL; - if (algoList.size() > 1 ) { // check if there is one algo several times - list ::iterator algo = algoList.begin(); - for ( ; algo != algoList.end(); ++algo ) - if ( (*algo) != algoList.front() && - (*algo)->GetName() != algoList.front()->GetName() ) - return NULL; - } + // Now it is checked in SMESH_Mesh::GetHypotheses() +// if (algoList.size() > 1 ) { // check if there is one algo several times +// list ::iterator algo = algoList.begin(); +// for ( ; algo != algoList.end(); ++algo ) +// if ( (*algo) != algoList.front() && +// (*algo)->GetName() != algoList.front()->GetName() ) +// return NULL; +// } return const_cast ( static_cast( algoList.front() )); } diff --git a/src/SMESH/SMESH_HypoFilter.cxx b/src/SMESH/SMESH_HypoFilter.cxx index ff14016d8..3482b1d57 100644 --- a/src/SMESH/SMESH_HypoFilter.cxx +++ b/src/SMESH/SMESH_HypoFilter.cxx @@ -75,6 +75,17 @@ bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp, return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType ); }; +//======================================================================= +//function : IsAuxiliaryPredicate::IsOk +//purpose : +//======================================================================= + +bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp, + const TopoDS_Shape& /*aShape*/) const +{ + return aHyp->IsAuxiliary(); +}; + //======================================================================= //function : ApplicablePredicate::ApplicablePredicate //purpose : @@ -190,6 +201,17 @@ SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo() return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO ); } +//======================================================================= +//function : IsAuxiliary +//purpose : +//======================================================================= + +SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary() +{ + return new IsAuxiliaryPredicate(); +} + + //======================================================================= //function : IsGlobal //purpose : diff --git a/src/SMESH/SMESH_HypoFilter.hxx b/src/SMESH/SMESH_HypoFilter.hxx index 6bc34bf53..9638495d1 100644 --- a/src/SMESH/SMESH_HypoFilter.hxx +++ b/src/SMESH/SMESH_HypoFilter.hxx @@ -67,6 +67,7 @@ class SMESH_HypoFilter: public SMESH_HypoPredicate // Create predicates static SMESH_HypoPredicate* IsAlgo(); + static SMESH_HypoPredicate* IsAuxiliary(); static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape); static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape); static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo); @@ -158,6 +159,11 @@ class SMESH_HypoFilter: public SMESH_HypoPredicate const TopoDS_Shape& aShape) const; }; + struct IsAuxiliaryPredicate : public SMESH_HypoPredicate { + bool IsOk(const SMESH_Hypothesis* aHyp, + const TopoDS_Shape& aShape) const; + }; + }; diff --git a/src/SMESH/SMESH_Hypothesis.cxx b/src/SMESH/SMESH_Hypothesis.cxx index 0107c3e36..268581791 100644 --- a/src/SMESH/SMESH_Hypothesis.cxx +++ b/src/SMESH/SMESH_Hypothesis.cxx @@ -72,13 +72,14 @@ SMESH_Hypothesis::~SMESH_Hypothesis() int SMESH_Hypothesis::GetDim() const { - int dim = -1; + int dim = 0; switch (_type) { case ALGO_1D: dim = 1; break; case ALGO_2D: dim = 2; break; case ALGO_3D: dim = 3; break; - case PARAM_ALGO: dim = _param_algo_dim; break; + case PARAM_ALGO: + dim = ( _param_algo_dim < 0 ) ? -_param_algo_dim : _param_algo_dim; break; } return dim; } @@ -124,14 +125,15 @@ void SMESH_Hypothesis::NotifySubMeshesHypothesisModification() itm++) { SMESH_Mesh* mesh = (*itm).second; - const list& subMeshes = - mesh->GetSubMeshUsingHypothesis(this); + mesh->NotifySubMeshesHypothesisModification( this ); +// const list& subMeshes = +// mesh->GetSubMeshUsingHypothesis(this); - //for all subMeshes using hypothesis +// //for all subMeshes using hypothesis - list::const_iterator its; - for (its = subMeshes.begin(); its != subMeshes.end(); its++) - (*its)->ComputeStateEngine(SMESH_subMesh::MODIF_HYP); +// list::const_iterator its; +// for (its = subMeshes.begin(); its != subMeshes.end(); its++) +// (*its)->ComputeStateEngine(SMESH_subMesh::MODIF_HYP); } } diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index 1d881a680..9f47d809d 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -54,13 +54,24 @@ public: SMESH_Hypothesis(int hypId, int studyId, SMESH_Gen* gen); virtual ~SMESH_Hypothesis(); - int GetDim() const; + virtual int GetDim() const; int GetStudyId() const; - void NotifySubMeshesHypothesisModification(); - int GetShapeType() const; - const char* GetLibName() const; + virtual void NotifySubMeshesHypothesisModification(); + virtual int GetShapeType() const; + virtual const char* GetLibName() const; void SetLibName(const char* theLibName); + /*! + * \brief Return true if me is an auxiliary hypothesis + * \retval bool - auxiliary or not + * + * An auxiliary hypothesis is optional, i.e. an algorithm + * can work without it and another hypothesis of the same + * dimention can be assigned to the shape + */ + virtual bool IsAuxiliary() const + { return GetType() == PARAM_ALGO && _param_algo_dim <= 0; } + protected: SMESH_Gen* _gen; int _studyId; diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index f36f08964..d73de739c 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -520,45 +520,62 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubS //purpose : //======================================================================= -bool SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape, - const SMESH_HypoFilter& aFilter, - list & aHypList, - const bool andAncestors) const +//================================================================================ +/*! + * \brief Return hypothesis assigned to the shape + * \param aSubShape - the shape to check + * \param aFilter - the hypothesis filter + * \param aHypList - the list of the found hypotheses + * \param andAncestors - flag to check hypos assigned to ancestors of the shape + * \retval int - number of unique hypos in aHypList + */ +//================================================================================ + +int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + list & aHypList, + const bool andAncestors) const { - int nbHyp = 0; + set hypTypes; // to exclude same type hypos from the result list + int nbHyps = 0; + + // fill in hypTypes + list::const_iterator hyp; + for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) + if ( hypTypes.insert( (*hyp)->GetName() ).second ) + nbHyps++; + + // get hypos from aSubShape { const list& hypList = _myMeshDS->GetHypothesis(aSubShape); - list::const_iterator hyp = hypList.begin(); - for ( ; hyp != hypList.end(); hyp++ ) - if ( aFilter.IsOk (static_cast( *hyp ), aSubShape)) { + for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ ) + if ( aFilter.IsOk (static_cast( *hyp ), aSubShape) && + hypTypes.insert( (*hyp)->GetName() ).second ) + { aHypList.push_back( *hyp ); - nbHyp++; + nbHyps++; } } - // get hypos from shape of one type only: if any hypo is found on edge, do - // not look up on faces - if ( !nbHyp && andAncestors ) + + // get hypos from ancestors of aSubShape + if ( andAncestors ) { TopTools_MapOfShape map; TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape )); - int shapeType = it.More() ? it.Value().ShapeType() : TopAbs_SHAPE; for (; it.More(); it.Next() ) { - if ( nbHyp && shapeType != it.Value().ShapeType() ) - break; - shapeType = it.Value().ShapeType(); - if ( !map.Add( it.Value() )) + if ( !map.Add( it.Value() )) continue; const list& hypList = _myMeshDS->GetHypothesis(it.Value()); - list::const_iterator hyp = hypList.begin(); - for ( ; hyp != hypList.end(); hyp++ ) - if (aFilter.IsOk( static_cast( *hyp ), it.Value() )) { - aHypList.push_back( *hyp ); - nbHyp++; - } + for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ ) + if (aFilter.IsOk( static_cast( *hyp ), it.Value() ) && + hypTypes.insert( (*hyp)->GetName() ).second ) { + aHypList.push_back( *hyp ); + nbHyps++; + } } } - return nbHyp; + return !aHypList.empty(); } //============================================================================= @@ -690,15 +707,17 @@ throw(SALOME_Exception) //======================================================================= bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, - const TopoDS_Shape & aSubShape) + const SMESH_subMesh* aSubMesh) { SMESH_Hypothesis* hyp = static_cast(anHyp); - // check if anHyp is applicable to aSubShape - SMESH_subMesh * subMesh = GetSubMeshContaining( aSubShape ); - if ( !subMesh || !subMesh->IsApplicableHypotesis( hyp )) + + // check if anHyp can be used to mesh aSubMesh + if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp )) return false; - SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape); + const TopoDS_Shape & aSubShape = const_cast( aSubMesh )->GetSubShape(); + + SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape ); // algorithm if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO) @@ -708,17 +727,19 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, if (algo) { // look trough hypotheses used by algo - const list &usedHyps = - algo->GetUsedHypothesis(*this, aSubShape); - return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() ); + SMESH_HypoFilter hypoKind; + if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) { + list usedHyps; + if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true )) + return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() ); + } } // look through all assigned hypotheses - SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp )); - return GetHypothesis( aSubShape, filter, true ); + //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp )); + return false; //GetHypothesis( aSubShape, filter, true ); } - //============================================================================= /*! * @@ -726,20 +747,78 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, //============================================================================= const list < SMESH_subMesh * >& - SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) -throw(SALOME_Exception) +SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) + throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis"); + map < int, SMESH_subMesh * >::iterator itsm; + _subMeshesUsingHypothesisList.clear(); + for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) + { + SMESH_subMesh *aSubMesh = (*itsm).second; + if ( IsUsedHypothesis ( anHyp, aSubMesh )) + _subMeshesUsingHypothesisList.push_back(aSubMesh); + } + return _subMeshesUsingHypothesisList; +} + +//======================================================================= +//function : NotifySubMeshesHypothesisModification +//purpose : Say all submeshes using theChangedHyp that it has been modified +//======================================================================= + +void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp) { Unexpect aCatch(SalomeException); - if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis"); - map < int, SMESH_subMesh * >::iterator itsm; - _subMeshesUsingHypothesisList.clear(); - for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) - { - SMESH_subMesh *aSubMesh = (*itsm).second; - if ( IsUsedHypothesis ( anHyp, aSubMesh->GetSubShape() )) - _subMeshesUsingHypothesisList.push_back(aSubMesh); - } - return _subMeshesUsingHypothesisList; + + const SMESH_Hypothesis* hyp = static_cast(theChangedHyp); + + const SMESH_Algo *foundAlgo = 0; + SMESH_HypoFilter algoKind( SMESH_HypoFilter::IsAlgo() ); + SMESH_HypoFilter compatibleHypoKind; + list usedHyps; + + + map < int, SMESH_subMesh * >::iterator itsm; + for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) + { + SMESH_subMesh *aSubMesh = (*itsm).second; + if ( aSubMesh->IsApplicableHypotesis( hyp )) + { + const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape(); + + if ( !foundAlgo ) // init filter for algo search + algoKind.And( algoKind.IsApplicableTo( aSubShape )); + + const SMESH_Algo *algo = static_cast + ( GetHypothesis( aSubShape, algoKind, true )); + + if ( algo ) + { + bool sameAlgo = ( algo == foundAlgo ); + if ( !sameAlgo && foundAlgo ) + sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0); + + if ( !sameAlgo ) { // init filter for used hypos search + if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() )) + continue; // algo does not use any hypothesis + foundAlgo = algo; + } + + // check if hyp is used by algo + usedHyps.clear(); + if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) && + find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() ) + { + aSubMesh->ComputeStateEngine(SMESH_subMesh::MODIF_HYP); + + if ( algo->GetDim() == 1 && IsPropagationHypothesis( aSubShape )) + CleanMeshOnPropagationChain( aSubShape ); + } + } + } + } } //============================================================================= diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 5054e0038..ea81e33f5 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -110,10 +110,10 @@ public: const SMESH_HypoFilter& aFilter, const bool andAncestors) const; - bool GetHypotheses(const TopoDS_Shape & aSubShape, - const SMESH_HypoFilter& aFilter, - list & aHypList, - const bool andAncestors) const; + int GetHypotheses(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + list & aHypList, + const bool andAncestors) const; const list & GetLog() throw(SALOME_Exception); @@ -134,12 +134,15 @@ public: SMESH_subMesh *GetSubMeshContaining(const int aShapeID) throw(SALOME_Exception); + void NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp); + // Say all submeshes that theChangedHyp has been modified + const list < SMESH_subMesh * >& GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) throw(SALOME_Exception); - bool IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, - const TopoDS_Shape & aSubShape); + bool IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, + const SMESH_subMesh * aSubMesh); // Return True if anHyp is used to mesh aSubShape bool IsNotConformAllowed() const; diff --git a/src/SMESH/SMESH_subMesh.cxx b/src/SMESH/SMESH_subMesh.cxx index 250040453..f354faee0 100644 --- a/src/SMESH/SMESH_subMesh.cxx +++ b/src/SMESH/SMESH_subMesh.cxx @@ -445,7 +445,7 @@ void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape) */ //============================================================================= -const TopoDS_Shape & SMESH_subMesh::GetSubShape() +const TopoDS_Shape & SMESH_subMesh::GetSubShape() const { //MESSAGE("SMESH_subMesh::GetSubShape"); return _subShape; @@ -554,7 +554,7 @@ SMESH_Hypothesis::Hypothesis_Status if ( ! CanAddHypothesis( anHyp )) return SMESH_Hypothesis::HYP_BAD_DIM; - if ( GetSimilarAttached( _subShape, anHyp ) ) + if ( /*!anHyp->IsAuxiliary() &&*/ GetSimilarAttached( _subShape, anHyp ) ) return SMESH_Hypothesis::HYP_ALREADY_EXIST; if ( !_meshDS->AddHypothesis(_subShape, anHyp)) @@ -563,9 +563,9 @@ SMESH_Hypothesis::Hypothesis_Status // Serve Propagation of 1D hypothesis if (event == ADD_HYP) { bool isPropagationOk = true; - string hypName = anHyp->GetName(); + bool isPropagationHyp = ( strcmp( "Propagation", anHyp->GetName() ) == 0 ); - if (hypName == "Propagation") { + if ( isPropagationHyp ) { TopExp_Explorer exp (_subShape, TopAbs_EDGE); TopTools_MapOfShape aMap; for (; exp.More(); exp.Next()) { @@ -593,7 +593,11 @@ SMESH_Hypothesis::Hypothesis_Status } else { } - if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) { + if ( isPropagationOk ) { + if ( isPropagationHyp ) + return ret; // nothing more to do for "Propagation" hypothesis + } + else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) { ret = SMESH_Hypothesis::HYP_CONCURENT; } } // Serve Propagation of 1D hypothesis @@ -612,7 +616,9 @@ SMESH_Hypothesis::Hypothesis_Status { bool isPropagationOk = true; SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" )); - if ( propagFilter.IsOk( anHyp, _subShape )) + bool isPropagationHyp = propagFilter.IsOk( anHyp, _subShape ); + + if ( isPropagationHyp ) { TopExp_Explorer exp (_subShape, TopAbs_EDGE); TopTools_MapOfShape aMap; @@ -634,7 +640,11 @@ SMESH_Hypothesis::Hypothesis_Status isPropagationOk = _father->RebuildPropagationChains(); } - if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) { + if ( isPropagationOk ) { + if ( isPropagationHyp ) + return ret; // nothing more to do for "Propagation" hypothesis + } + else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) { ret = SMESH_Hypothesis::HYP_CONCURENT; } } // Serve Propagation of 1D hypothesis @@ -712,7 +722,7 @@ SMESH_Hypothesis::Hypothesis_Status SetAlgoState(HYP_OK); if (SMESH_Hypothesis::IsStatusFatal( ret )) _meshDS->RemoveHypothesis(_subShape, anHyp); - else if (!_father->IsUsedHypothesis( anHyp, _subShape )) + else if (!_father->IsUsedHypothesis( anHyp, this )) { _meshDS->RemoveHypothesis(_subShape, anHyp); ret = SMESH_Hypothesis::HYP_INCOMPATIBLE; @@ -802,7 +812,7 @@ SMESH_Hypothesis::Hypothesis_Status // ret should be fatal: anHyp was not added ret = SMESH_Hypothesis::HYP_INCOMPATIBLE; } - else if (!_father->IsUsedHypothesis( anHyp, _subShape )) + else if (!_father->IsUsedHypothesis( anHyp, this )) ret = SMESH_Hypothesis::HYP_INCOMPATIBLE; if (SMESH_Hypothesis::IsStatusFatal( ret )) @@ -866,7 +876,7 @@ SMESH_Hypothesis::Hypothesis_Status ASSERT(algo); if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) { - if (_father->IsUsedHypothesis( anHyp, _subShape )) // new Hyp + if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp modifiedHyp = true; } else @@ -1626,8 +1636,9 @@ TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlg if ( mainShape.IsSame( _subShape )) return _subShape; + const bool ignoreAuxiliaryHyps = false; list aUsedHyp = - theAlgo->GetUsedHypothesis( *_father, _subShape ); // copy + theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy // put in a compound all shapes with the same hypothesis assigned // and a good ComputState @@ -1645,7 +1656,7 @@ TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlg if (subMesh->GetComputeState() == READY_TO_COMPUTE && anAlgo == theAlgo && - anAlgo->GetUsedHypothesis( *_father, S ) == aUsedHyp) + anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp) { aBuilder.Add( aCompound, S ); } @@ -1656,26 +1667,31 @@ TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlg //======================================================================= //function : GetSimilarAttached -//purpose : return nb of hypotheses attached to theShape. +//purpose : return a hypothesis attached to theShape. // If theHyp is provided, similar but not same hypotheses -// are countered; else only applicable ones having theHypType -// are countered +// is returned; else only applicable ones having theHypType +// is returned //======================================================================= const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape, const SMESH_Hypothesis * theHyp, const int theHypType) { - SMESH_HypoFilter filter; - filter.Init( SMESH_HypoFilter::HasType( theHyp ? theHyp->GetType() : theHypType )); + SMESH_HypoFilter hypoKind; + hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType )); if ( theHyp ) { - filter.And( SMESH_HypoFilter::HasDim( theHyp->GetDim() )); - filter.AndNot( SMESH_HypoFilter::Is( theHyp )); + hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() )); + hypoKind.AndNot( hypoKind.Is( theHyp )); + if ( theHyp->IsAuxiliary() ) + hypoKind.And( hypoKind.HasName( theHyp->GetName() )); + else + hypoKind.AndNot( hypoKind.IsAuxiliary()); + } + else { + hypoKind.And( hypoKind.IsApplicableTo( theShape )); } - else - filter.And( SMESH_HypoFilter::IsApplicableTo( theShape )); - return _father->GetHypothesis( theShape, filter, false ); + return _father->GetHypothesis( theShape, hypoKind, false ); } //======================================================================= diff --git a/src/SMESH/SMESH_subMesh.hxx b/src/SMESH/SMESH_subMesh.hxx index 8251c6b94..feada1512 100644 --- a/src/SMESH/SMESH_subMesh.hxx +++ b/src/SMESH/SMESH_subMesh.hxx @@ -70,7 +70,7 @@ class SMESH_subMesh const map < int, SMESH_subMesh * >&DependsOn(); //const map < int, SMESH_subMesh * >&Dependants(); - const TopoDS_Shape & GetSubShape(); + const TopoDS_Shape & GetSubShape() const; // bool _vertexSet; // only for vertex subMesh, set to false for dim > 0 @@ -103,17 +103,13 @@ class SMESH_subMesh SMESH_Hypothesis::Hypothesis_Status SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp); - int GetAlgoState() { return _algoState; } + int GetAlgoState() const { return _algoState; } + int GetComputeState() const { return _computeState; }; void DumpAlgoState(bool isMain); bool ComputeStateEngine(int event); - int GetComputeState() - { - return _computeState; - }; - bool IsConform(const SMESH_Algo* theAlgo); // check if a conform mesh will be produced by the Algo -- 2.39.2