1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_subMesh.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_subMesh.hxx"
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_HypoFilter.hxx"
33 #include "SMESH_Hypothesis.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_MesherHelper.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Comment.hxx"
38 #include "SMDS_SetIterator.hxx"
39 #include "SMDSAbs_ElementType.hxx"
41 #include <Basics_OCCTVersion.hxx>
43 #include "utilities.h"
45 #include "Basics_Utils.hxx"
47 #include <BRep_Builder.hxx>
48 #include <BRep_Tool.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopoDS_Compound.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopoDS_Iterator.hxx>
58 #include <Standard_OutOfMemory.hxx>
59 #include <Standard_ErrorHandler.hxx>
65 //=============================================================================
67 * \brief Allocate some memory at construction and release it at destruction.
68 * Is used to be able to continue working after mesh generation breaks due to
71 //=============================================================================
76 MemoryReserve(): myBuf( new char[1024*1024*2] ){}
77 ~MemoryReserve() { delete [] myBuf; }
80 //=============================================================================
82 * default constructor:
84 //=============================================================================
86 SMESH_subMesh::SMESH_subMesh(int Id,
88 SMESHDS_Mesh * meshDS,
89 const TopoDS_Shape & aSubShape)
91 _subShape = aSubShape;
92 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
95 _dependenceAnalysed = _alwaysComputed = false;
97 if (_subShape.ShapeType() == TopAbs_VERTEX)
100 _computeState = READY_TO_COMPUTE;
104 _algoState = NO_ALGO;
105 _computeState = NOT_READY;
107 _computeCost = 0; // how costly is to compute this sub-mesh
108 _realComputeCost = 0;
111 //=============================================================================
115 //=============================================================================
117 SMESH_subMesh::~SMESH_subMesh()
119 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
121 deleteOwnListeners();
124 //=============================================================================
128 //=============================================================================
130 int SMESH_subMesh::GetId() const
132 //MESSAGE("SMESH_subMesh::GetId");
136 //=============================================================================
140 //=============================================================================
142 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
144 // submesh appears in DS only when a mesher set nodes and elements on a shape
145 return _subMeshDS ? _subMeshDS : _subMeshDS = _father->GetMeshDS()->MeshElements(_subShape); // may be null
148 //=============================================================================
152 //=============================================================================
154 const SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS() const
156 return ((SMESH_subMesh*) this )->GetSubMeshDS();
159 //=============================================================================
163 //=============================================================================
165 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
167 if ( !GetSubMeshDS() ) {
168 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
169 meshDS->NewSubMesh( meshDS->ShapeToIndex( _subShape ) );
171 return GetSubMeshDS();
174 //=============================================================================
178 //=============================================================================
180 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
182 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(true,false);
183 while ( smIt->more() ) {
184 SMESH_subMesh *sm = smIt->next();
185 if ( sm->GetComputeState() == READY_TO_COMPUTE )
188 return 0; // nothing to compute
191 //================================================================================
193 * \brief Returns a current algorithm
195 //================================================================================
197 SMESH_Algo* SMESH_subMesh::GetAlgo() const
200 ((SMESH_subMesh*)this)->_algo = _father->GetGen()->GetAlgo(*_father, _subShape);
204 //================================================================================
206 * \brief Allow algo->Compute() if a sub-shape of lower dim is meshed but
207 * none mesh entity is bound to it (PAL13615, 2nd part)
209 //================================================================================
211 void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
213 _alwaysComputed = isAlCo;
214 if ( _alwaysComputed )
215 _computeState = COMPUTE_OK;
217 ComputeStateEngine( CHECK_COMPUTE_STATE );
220 //=======================================================================
222 * \brief Return true if no mesh entities is bound to the submesh
224 //=======================================================================
226 bool SMESH_subMesh::IsEmpty() const
228 if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS())
229 return (!subMeshDS->NbElements() && !subMeshDS->NbNodes());
233 //=======================================================================
234 //function : IsMeshComputed
235 //purpose : check if _subMeshDS contains mesh elements
236 //=======================================================================
238 bool SMESH_subMesh::IsMeshComputed() const
240 if ( _alwaysComputed )
242 // algo may bind a submesh not to _subShape, eg 3D algo
243 // sets nodes on SHELL while _subShape may be SOLID
245 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
246 int dim = SMESH_Gen::GetShapeDim( _subShape );
247 int type = _subShape.ShapeType();
248 for ( ; type <= TopAbs_VERTEX; type++) {
249 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
251 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
252 for ( ; exp.More(); exp.Next() )
254 if ( SMESHDS_SubMesh * smDS = meshDS->MeshElements( exp.Current() ))
256 bool computed = (dim > 0) ? smDS->NbElements() : smDS->NbNodes();
269 //=============================================================================
271 * Return true if all sub-meshes have been meshed
273 //=============================================================================
275 bool SMESH_subMesh::SubMeshesComputed(bool * isFailedToCompute/*=0*/) const
277 int myDim = SMESH_Gen::GetShapeDim( _subShape );
278 int dimToCheck = myDim - 1;
279 bool subMeshesComputed = true;
280 if ( isFailedToCompute ) *isFailedToCompute = false;
281 // check subMeshes with upper dimension => reverse iteration
282 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
283 while ( smIt->more() )
285 SMESH_subMesh *sm = smIt->next();
286 if ( sm->_alwaysComputed )
288 const TopoDS_Shape & ss = sm->GetSubShape();
290 // MSV 07.04.2006: restrict checking to myDim-1 only. Ex., there is no sense
291 // in checking of existence of edges if the algo needs only faces. Moreover,
292 // degenerated edges may have no submesh, as after computing NETGEN_2D.
293 if ( !_algo || _algo->NeedDiscreteBoundary() ) {
294 int dim = SMESH_Gen::GetShapeDim( ss );
295 if (dim < dimToCheck)
296 break; // the rest subMeshes are all of less dimension
298 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
299 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
300 (ds && ( dimToCheck ? ds->NbElements() : ds->NbNodes() )));
303 subMeshesComputed = false;
304 if ( isFailedToCompute && !(*isFailedToCompute) )
305 *isFailedToCompute = ( sm->GetComputeState() == FAILED_TO_COMPUTE );
307 // int type = ss.ShapeType();
311 // case TopAbs_COMPOUND:
313 // MESSAGE("The not computed sub mesh is a COMPOUND");
316 // case TopAbs_COMPSOLID:
318 // MESSAGE("The not computed sub mesh is a COMPSOLID");
321 // case TopAbs_SHELL:
323 // MESSAGE("The not computed sub mesh is a SHEL");
328 // MESSAGE("The not computed sub mesh is a WIRE");
331 // case TopAbs_SOLID:
333 // MESSAGE("The not computed sub mesh is a SOLID");
338 // MESSAGE("The not computed sub mesh is a FACE");
343 // MESSAGE("The not computed sub mesh is a EDGE");
348 // MESSAGE("The not computed sub mesh is of unknown type");
353 if ( !isFailedToCompute )
357 return subMeshesComputed;
360 //================================================================================
362 * \brief Return cost of computing this sub-mesh. If hypotheses are not well defined,
364 * \return int - the computation cost in abstract units.
366 //================================================================================
368 int SMESH_subMesh::GetComputeCost() const
370 return _realComputeCost;
373 //================================================================================
375 * \brief Return cost of computing this sub-mesh. The cost depends on the shape type
376 * and number of sub-meshes this one DependsOn().
377 * \return int - the computation cost in abstract units.
379 //================================================================================
381 int SMESH_subMesh::computeCost() const
386 switch ( _subShape.ShapeType() ) {
388 case TopAbs_SHELL: computeCost = 5000; break;
389 case TopAbs_FACE: computeCost = 500; break;
390 case TopAbs_EDGE: computeCost = 2; break;
391 default: computeCost = 1;
393 SMESH_subMeshIteratorPtr childIt = getDependsOnIterator(/*includeSelf=*/false);
394 while ( childIt->more() )
395 computeCost += childIt->next()->computeCost();
397 ((SMESH_subMesh*)this)->_computeCost = computeCost;
402 //=============================================================================
406 //=============================================================================
408 // bool SMESH_subMesh::SubMeshesReady()
410 // bool subMeshesReady = true;
411 // SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
412 // while ( smIt->more() ) {
413 // SMESH_subMesh *sm = smIt->next();
414 // bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
415 // sm->GetComputeState() == READY_TO_COMPUTE);
418 // subMeshesReady = false;
419 // SCRUTE(sm->GetId());
423 // return subMeshesReady;
426 //=============================================================================
428 * Construct dependence on first level subMeshes. complex shapes (compsolid,
429 * shell, wire) are not analysed the same way as simple shapes (solid, face,
431 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
432 * with possible multiples occurences. Multiples occurences corresponds to
433 * internal frontiers within shapes of the collection and must not be keeped.
434 * See FinalizeDependence.
436 //=============================================================================
438 const map < int, SMESH_subMesh * >& SMESH_subMesh::DependsOn()
440 if (_dependenceAnalysed)
443 //MESSAGE("SMESH_subMesh::DependsOn");
445 int type = _subShape.ShapeType();
449 case TopAbs_COMPOUND:
451 //MESSAGE("compound");
452 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();exp.Next())
454 insertDependence(exp.Current());
456 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More(); exp.Next())
458 if ( BRep_Tool::IsClosed(exp.Current() ))
459 insertDependence(exp.Current()); //only shell not in solid
461 for (TopExp_Explorer expF(exp.Current(), TopAbs_FACE); expF.More();expF.Next())
462 insertDependence(expF.Current()); // issue 0020959: HEXA_3D fails on shell
465 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();exp.Next())
467 insertDependence(exp.Current());
469 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();exp.Next())
471 insertDependence(exp.Current());
473 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX, TopAbs_EDGE); exp.More();exp.Next())
475 insertDependence(exp.Current());
479 case TopAbs_COMPSOLID:
481 //MESSAGE("compsolid");
482 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More(); exp.Next())
484 insertDependence(exp.Current());
491 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More(); exp.Next())
493 insertDependence(exp.Current());
500 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More(); exp.Next())
502 insertDependence(exp.Current());
509 if(_father->HasShapeToMesh()) {
510 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();exp.Next())
512 insertDependence(exp.Current());
520 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();exp.Next())
522 insertDependence(exp.Current());
529 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More(); exp.Next())
531 insertDependence(exp.Current());
544 _dependenceAnalysed = true;
548 //================================================================================
550 * \brief Return a key for SMESH_subMesh::_mapDepend map
552 //================================================================================
555 int dependsOnMapKey( const SMESH_subMesh* sm )
557 int type = sm->GetSubShape().ShapeType();
558 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
559 int cle = sm->GetId();
560 cle += 10000000 * ordType; // sort map by ordType then index
565 //=============================================================================
567 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
569 //=============================================================================
571 void SMESH_subMesh::insertDependence(const TopoDS_Shape aSubShape)
573 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
574 int cle = dependsOnMapKey( aSubMesh );
575 if ( _mapDepend.find( cle ) == _mapDepend.end())
577 _mapDepend[cle] = aSubMesh;
578 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
579 _mapDepend.insert( subMap.begin(), subMap.end() );
583 //================================================================================
585 * \brief Return \c true if \a this sub-mesh depends on \a other
587 //================================================================================
589 bool SMESH_subMesh::DependsOn( const SMESH_subMesh* other ) const
591 return other ? _mapDepend.count( dependsOnMapKey( other )) : false;
594 //=============================================================================
596 * Return a shape of \a this sub-mesh
598 //=============================================================================
600 const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
605 //=======================================================================
606 //function : CanAddHypothesis
607 //purpose : return true if theHypothesis can be attached to me:
608 // its dimention is checked
609 //=======================================================================
611 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
613 int aHypDim = theHypothesis->GetDim();
614 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
615 // issue 21106. Forbid 3D mesh on the SHELL
616 // if (aHypDim == 3 && aShapeDim == 3) {
617 // // check case of open shell
618 // //if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed())
619 // if (_subShape.ShapeType() == TopAbs_SHELL && !BRep_Tool::IsClosed(_subShape))
622 if ( aHypDim <= aShapeDim )
628 //=======================================================================
629 //function : IsApplicableHypotesis
631 //=======================================================================
633 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
634 const TopAbs_ShapeEnum theShapeType)
636 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
639 if ( theHypothesis->GetShapeType() & (1<< theShapeType))
640 // issue 21106. Forbid 3D mesh on the SHELL
641 return !( theHypothesis->GetDim() == 3 && theShapeType == TopAbs_SHELL );
647 switch ( theShapeType ) {
652 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
655 // Special case for algorithms, building 2D mesh on a whole shell.
656 // Before this fix there was a problem after restoring from study,
657 // because in that case algorithm is assigned before hypothesis
658 // (on shell in problem case) and hypothesis is checked on faces
659 // (because it is 2D), where we have NO_ALGO state.
660 // Now 2D hypothesis is also applicable to shells.
661 return (theHypothesis->GetDim() == 2 || theHypothesis->GetDim() == 3);
664 // case TopAbs_COMPSOLID:
665 // case TopAbs_COMPOUND:
671 //=============================================================================
675 //=============================================================================
677 SMESH_Hypothesis::Hypothesis_Status
678 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
680 // **** les retour des evenement shape sont significatifs
681 // (add ou remove fait ou non)
682 // le retour des evenement father n'indiquent pas que add ou remove fait
684 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
686 SMESHDS_Mesh* meshDS =_father->GetMeshDS();
687 SMESH_Algo* algo = 0;
690 if (_subShape.ShapeType() == TopAbs_VERTEX )
692 if ( anHyp->GetDim() != 0) {
693 if (event == ADD_HYP || event == ADD_ALGO)
694 return SMESH_Hypothesis::HYP_BAD_DIM;
696 return SMESH_Hypothesis::HYP_OK;
699 else if ( _algoState == HYP_OK ) {
700 // update default _algoState
701 if ( event != REMOVE_FATHER_ALGO )
703 _algoState = NO_ALGO;
706 _algoState = MISSING_HYP;
707 if ( event == REMOVE_FATHER_HYP ||
708 algo->CheckHypothesis(*_father,_subShape, aux_ret))
715 int oldAlgoState = _algoState;
716 bool modifiedHyp = (event == MODIF_HYP); // if set to true, force event MODIF_ALGO_STATE
717 SMESH_Algo* algoRequiringCleaning = 0;
719 bool isApplicableHyp = IsApplicableHypotesis( anHyp );
721 if (event == ADD_ALGO || event == ADD_FATHER_ALGO)
723 // -------------------------------------------
724 // check if a shape needed by algo is present
725 // -------------------------------------------
726 algo = static_cast< SMESH_Algo* >( anHyp );
727 if ( !_father->HasShapeToMesh() && algo->NeedShape() )
728 return SMESH_Hypothesis::HYP_NEED_SHAPE;
729 // ----------------------
730 // check mesh conformity
731 // ----------------------
732 if (isApplicableHyp && !_father->IsNotConformAllowed() && !IsConform( algo ))
733 return SMESH_Hypothesis::HYP_NOTCONFORM;
735 // check if all-dimensional algo is hidden by other local one
736 if ( event == ADD_ALGO ) {
737 SMESH_HypoFilter filter( SMESH_HypoFilter::HasType( algo->GetType() ));
738 filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+1 ));
739 filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+2 ));
740 if ( SMESH_Algo * curAlgo = (SMESH_Algo*)_father->GetHypothesis(_subShape, filter, true ))
741 if ( !curAlgo->NeedDiscreteBoundary() )
742 algoRequiringCleaning = curAlgo;
746 // ----------------------------------
747 // add a hypothesis to DS if possible
748 // ----------------------------------
749 if (event == ADD_HYP || event == ADD_ALGO)
751 if ( ! CanAddHypothesis( anHyp )) // check dimension
752 return SMESH_Hypothesis::HYP_BAD_DIM;
754 if ( /*!anHyp->IsAuxiliary() &&*/ getSimilarAttached( _subShape, anHyp ) )
755 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
757 if ( !meshDS->AddHypothesis(_subShape, anHyp))
758 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
761 // --------------------------
762 // remove a hypothesis from DS
763 // --------------------------
764 if (event == REMOVE_HYP || event == REMOVE_ALGO)
766 if (!meshDS->RemoveHypothesis(_subShape, anHyp))
767 return SMESH_Hypothesis::HYP_OK; // nothing changes
769 if (event == REMOVE_ALGO)
771 algo = dynamic_cast<SMESH_Algo*> (anHyp);
772 if (!algo->NeedDiscreteBoundary())
773 algoRequiringCleaning = algo;
777 // ------------------
778 // analyse algo state
779 // ------------------
780 if (!isApplicableHyp)
781 return ret; // not applicable hypotheses do not change algo state
786 // ----------------------------------------------------------------------
795 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
796 setAlgoState(HYP_OK);
797 else if ( algo->IsStatusFatal( aux_ret )) {
798 meshDS->RemoveHypothesis(_subShape, anHyp);
802 setAlgoState(MISSING_HYP);
809 case ADD_FATHER_ALGO: { // Algo just added in father
812 if ( algo == anHyp ) {
813 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
814 setAlgoState(HYP_OK);
816 setAlgoState(MISSING_HYP);
820 case REMOVE_FATHER_HYP:
822 case REMOVE_FATHER_ALGO: {
826 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
827 setAlgoState(HYP_OK);
829 setAlgoState(MISSING_HYP);
833 case MODIF_HYP: break;
840 // ----------------------------------------------------------------------
848 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
849 setAlgoState(HYP_OK);
850 if (SMESH_Hypothesis::IsStatusFatal( ret ))
851 meshDS->RemoveHypothesis(_subShape, anHyp);
852 else if (!_father->IsUsedHypothesis( anHyp, this ))
854 meshDS->RemoveHypothesis(_subShape, anHyp);
855 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
859 case ADD_ALGO: { //already existing algo : on father ?
862 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
863 setAlgoState(HYP_OK);
864 else if ( algo->IsStatusFatal( aux_ret )) {
865 meshDS->RemoveHypothesis(_subShape, anHyp);
869 setAlgoState(MISSING_HYP);
874 case REMOVE_ALGO: { // perhaps a father algo applies ?
876 if (algo == NULL) // no more algo applying on sub-shape...
878 setAlgoState(NO_ALGO);
882 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
883 setAlgoState(HYP_OK);
885 setAlgoState(MISSING_HYP);
889 case MODIF_HYP: // assigned hypothesis value may become good
890 case ADD_FATHER_HYP: {
893 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
894 setAlgoState(HYP_OK);
896 setAlgoState(MISSING_HYP);
899 case ADD_FATHER_ALGO: { // new father algo
902 if ( algo == anHyp ) {
903 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
904 setAlgoState(HYP_OK);
906 setAlgoState(MISSING_HYP);
910 case REMOVE_FATHER_HYP: // nothing to do
912 case REMOVE_FATHER_ALGO: {
914 if (algo == NULL) // no more applying algo on father
916 setAlgoState(NO_ALGO);
920 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
921 setAlgoState(HYP_OK);
923 setAlgoState(MISSING_HYP);
933 // ----------------------------------------------------------------------
941 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
943 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
944 // ret should be fatal: anHyp was not added
945 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
947 else if (!_father->IsUsedHypothesis( anHyp, this ))
948 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
950 if (SMESH_Hypothesis::IsStatusFatal( ret ))
952 MESSAGE("do not add extra hypothesis");
953 meshDS->RemoveHypothesis(_subShape, anHyp);
961 case ADD_ALGO: { //already existing algo : on father ?
963 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
964 // check if algo changes
966 f.Init( SMESH_HypoFilter::IsAlgo() );
967 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
968 f.AndNot( SMESH_HypoFilter::Is( algo ));
969 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
971 string(algo->GetName()) != string(prevAlgo->GetName()) )
975 setAlgoState(MISSING_HYP);
981 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
982 setAlgoState(HYP_OK);
984 setAlgoState(MISSING_HYP);
988 case REMOVE_ALGO: { // perhaps a father algo applies ?
990 if (algo == NULL) // no more algo applying on sub-shape...
992 setAlgoState(NO_ALGO);
996 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
997 // check if algo remains
998 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
1002 setAlgoState(MISSING_HYP);
1006 case MODIF_HYP: // hypothesis value may become bad
1007 case ADD_FATHER_HYP: { // new father hypothesis ?
1010 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
1012 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
1016 setAlgoState(MISSING_HYP);
1019 case ADD_FATHER_ALGO: {
1021 if ( algo == anHyp ) { // a new algo on father
1022 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1023 // check if algo changes
1025 f.Init( SMESH_HypoFilter::IsAlgo() );
1026 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
1027 f.AndNot( SMESH_HypoFilter::Is( algo ));
1028 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
1030 string(algo->GetName()) != string(prevAlgo->GetName()) )
1034 setAlgoState(MISSING_HYP);
1038 case REMOVE_FATHER_HYP: {
1041 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1042 // is there the same local hyp or maybe a new father algo applied?
1043 if ( !getSimilarAttached( _subShape, anHyp ) )
1047 setAlgoState(MISSING_HYP);
1050 case REMOVE_FATHER_ALGO: {
1051 // IPAL21346. Edges not removed when Netgen 1d-2d is removed from a SOLID.
1052 // CLEAN was not called at event REMOVE_ALGO because the algo is not applicable to SOLID.
1053 algo = dynamic_cast<SMESH_Algo*> (anHyp);
1054 if (!algo->NeedDiscreteBoundary())
1055 algoRequiringCleaning = algo;
1057 if (algo == NULL) // no more applying algo on father
1059 setAlgoState(NO_ALGO);
1063 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1064 // check if algo changes
1065 if ( string(algo->GetName()) != string( anHyp->GetName()) )
1069 setAlgoState(MISSING_HYP);
1079 // ----------------------------------------------------------------------
1086 // detect algorithm hiding
1088 if ( ret == SMESH_Hypothesis::HYP_OK &&
1089 ( event == ADD_ALGO || event == ADD_FATHER_ALGO ) &&
1090 algo->GetName() == anHyp->GetName() )
1093 SMESH_Gen* gen = _father->GetGen();
1094 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1095 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && it.More()); it.Next() ) {
1096 if ( SMESH_Algo* upperAlgo = gen->GetAlgo( *_father, it.Value() ))
1097 if ( !upperAlgo->NeedDiscreteBoundary() && !upperAlgo->SupportSubmeshes())
1098 ret = SMESH_Hypothesis::HYP_HIDDEN_ALGO;
1101 if ( ret == SMESH_Hypothesis::HYP_OK &&
1102 !algo->NeedDiscreteBoundary() &&
1103 !algo->SupportSubmeshes()) {
1104 TopoDS_Shape algoAssignedTo, otherAssignedTo;
1105 gen->GetAlgo( *_father, _subShape, &algoAssignedTo );
1106 map<int, SMESH_subMesh*>::reverse_iterator i_sm = _mapDepend.rbegin();
1107 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && i_sm != _mapDepend.rend()) ; ++i_sm )
1108 if ( gen->GetAlgo( *_father, i_sm->second->_subShape, &otherAssignedTo ) &&
1109 SMESH_MesherHelper::IsSubShape( /*sub=*/otherAssignedTo, /*main=*/algoAssignedTo ))
1110 ret = SMESH_Hypothesis::HYP_HIDING_ALGO;
1114 bool stateChange = ( _algoState != oldAlgoState );
1116 if ( stateChange && _algoState == HYP_OK ) // hyp becomes OK
1117 algo->SetEventListener( this );
1119 if ( event == REMOVE_ALGO || event == REMOVE_FATHER_ALGO )
1122 notifyListenersOnEvent( event, ALGO_EVENT, anHyp );
1124 if ( stateChange && oldAlgoState == HYP_OK ) { // hyp becomes KO
1125 deleteOwnListeners();
1126 SetIsAlwaysComputed( false );
1127 if (_subShape.ShapeType() == TopAbs_VERTEX ) {
1128 // restore default states
1129 _algoState = HYP_OK;
1130 _computeState = READY_TO_COMPUTE;
1134 if ( algoRequiringCleaning ) {
1135 // added or removed algo is all-dimensional
1136 ComputeStateEngine( CLEAN );
1137 cleanDependsOn( algoRequiringCleaning );
1138 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1141 if (stateChange || modifiedHyp)
1142 ComputeStateEngine(MODIF_ALGO_STATE);
1144 _realComputeCost = ( _algoState == HYP_OK ) ? computeCost() : 0;
1149 //=======================================================================
1150 //function : IsConform
1151 //purpose : check if a conform mesh will be produced by the Algo
1152 //=======================================================================
1154 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
1156 // MESSAGE( "SMESH_subMesh::IsConform" );
1157 if ( !theAlgo ) return false;
1159 // Suppose that theAlgo is applicable to _subShape, do not check it here
1160 //if ( !IsApplicableHypotesis( theAlgo )) return false;
1162 // check only algo that doesn't NeedDiscreteBoundary(): because mesh made
1163 // on a sub-shape will be ignored by theAlgo
1164 if ( theAlgo->NeedDiscreteBoundary() ||
1165 !theAlgo->OnlyUnaryInput() ) // all adjacent shapes will be meshed by this algo?
1168 SMESH_Gen* gen =_father->GetGen();
1170 // only local algo is to be checked
1171 //if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1172 if ( _subShape.ShapeType() == _father->GetMeshDS()->ShapeToMesh().ShapeType() )
1175 // check algo attached to adjacent shapes
1177 // loop on one level down sub-meshes
1178 TopoDS_Iterator itsub( _subShape );
1179 for (; itsub.More(); itsub.Next())
1181 // loop on adjacent subShapes
1182 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1183 for (; it.More(); it.Next())
1185 const TopoDS_Shape& adjacent = it.Value();
1186 if ( _subShape.IsSame( adjacent )) continue;
1187 if ( adjacent.ShapeType() != _subShape.ShapeType())
1190 // check algo attached to smAdjacent
1191 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1193 !algo->NeedDiscreteBoundary() &&
1194 algo->OnlyUnaryInput())
1195 return false; // NOT CONFORM MESH WILL BE PRODUCED
1202 //=============================================================================
1206 //=============================================================================
1208 void SMESH_subMesh::setAlgoState(algo_state state)
1213 //=============================================================================
1217 //=============================================================================
1218 SMESH_Hypothesis::Hypothesis_Status
1219 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1220 SMESH_Hypothesis * anHyp)
1222 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1223 //EAP: a wire (dim==1) should notify edges (dim==1)
1224 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1225 //if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1227 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1228 while ( smIt->more() ) {
1229 SMESH_Hypothesis::Hypothesis_Status ret2 =
1230 smIt->next()->AlgoStateEngine(event, anHyp);
1238 //================================================================================
1240 * \brief Remove elements from sub-meshes.
1241 * \param algoRequiringCleaning - an all-dimensional algorithm whose presence
1242 * causes the cleaning.
1244 //================================================================================
1246 void SMESH_subMesh::cleanDependsOn( SMESH_Algo* algoRequiringCleaning/*=0*/ )
1248 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,
1249 /*complexShapeFirst=*/true);
1250 if ( _father->NbNodes() == 0 )
1252 while ( smIt->more() )
1253 smIt->next()->ComputeStateEngine(CHECK_COMPUTE_STATE);
1255 else if ( !algoRequiringCleaning || !algoRequiringCleaning->SupportSubmeshes() )
1257 while ( smIt->more() )
1258 smIt->next()->ComputeStateEngine(CLEAN);
1260 else if ( algoRequiringCleaning && algoRequiringCleaning->SupportSubmeshes() )
1262 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
1264 // find sub-meshes to keep elements on
1265 set< SMESH_subMesh* > smToKeep;
1266 TopAbs_ShapeEnum prevShapeType = TopAbs_SHAPE;
1267 bool toKeepPrevShapeType = false;
1268 while ( smIt->more() )
1270 SMESH_subMesh* sm = smIt->next();
1271 sm->ComputeStateEngine(CHECK_COMPUTE_STATE);
1272 if ( !sm->IsEmpty() )
1274 const bool sameShapeType = ( prevShapeType == sm->GetSubShape().ShapeType() );
1275 bool keepSubMeshes = ( sameShapeType && toKeepPrevShapeType );
1276 if ( !sameShapeType )
1278 // check if the algo allows presence of global algos of dimension the algo
1279 // can generate it-self
1280 int shapeDim = SMESH_Gen::GetShapeDim( sm->GetSubShape() );
1281 keepSubMeshes = algoRequiringCleaning->NeedLowerHyps( shapeDim );
1282 prevShapeType = sm->GetSubShape().ShapeType();
1283 toKeepPrevShapeType = keepSubMeshes;
1285 if ( !keepSubMeshes )
1287 // look for an algo assigned to sm
1288 bool algoFound = false;
1289 const list<const SMESHDS_Hypothesis*>& hyps = meshDS->GetHypothesis( sm->_subShape );
1290 list<const SMESHDS_Hypothesis*>::const_iterator h = hyps.begin();
1291 for ( ; ( !algoFound && h != hyps.end() ); ++h )
1292 algoFound = ((*h)->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
1293 keepSubMeshes = algoFound;
1295 // remember all sub-meshes of sm
1296 if ( keepSubMeshes )
1298 SMESH_subMeshIteratorPtr smIt2 = getDependsOnIterator(false,true);
1299 while ( smIt2->more() )
1300 smToKeep.insert( smIt2->next() );
1305 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
1306 while ( smIt->more() )
1308 SMESH_subMesh* sm = smIt->next();
1309 if ( !smToKeep.count( sm ))
1310 sm->ComputeStateEngine(CLEAN);
1315 //=============================================================================
1319 //=============================================================================
1321 void SMESH_subMesh::DumpAlgoState(bool isMain)
1323 // if (dim < 1) return;
1326 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1328 map < int, SMESH_subMesh * >::const_iterator itsub;
1329 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1331 SMESH_subMesh *sm = (*itsub).second;
1332 sm->DumpAlgoState(false);
1335 //int type = _subShape.ShapeType();
1336 MESSAGE("dim = " << SMESH_Gen::GetShapeDim(_subShape) <<
1337 " type of shape " << _subShape.ShapeType());
1341 MESSAGE(" AlgoState = NO_ALGO");
1344 MESSAGE(" AlgoState = MISSING_HYP");
1347 MESSAGE(" AlgoState = HYP_OK");
1350 switch (_computeState)
1353 MESSAGE(" ComputeState = NOT_READY");
1355 case READY_TO_COMPUTE:
1356 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1359 MESSAGE(" ComputeState = COMPUTE_OK");
1361 case FAILED_TO_COMPUTE:
1362 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1367 //================================================================================
1369 * \brief Remove nodes and elements bound to submesh
1370 * \param subMesh - submesh containing nodes and elements
1372 //================================================================================
1374 static void cleanSubMesh( SMESH_subMesh * subMesh )
1377 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1378 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1379 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1380 while (ite->more()) {
1381 const SMDS_MeshElement * elt = ite->next();
1382 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1383 //meshDS->RemoveElement(elt);
1384 meshDS->RemoveFreeElement(elt, 0);
1387 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1388 while (itn->more()) {
1389 const SMDS_MeshNode * node = itn->next();
1390 //MESSAGE( " RM node: "<<node->GetID());
1391 if ( node->NbInverseElements() == 0 )
1392 meshDS->RemoveFreeNode(node, 0);
1393 else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another
1394 meshDS->RemoveNode(node);
1401 //=============================================================================
1405 //=============================================================================
1407 bool SMESH_subMesh::ComputeStateEngine(int event)
1410 case MODIF_ALGO_STATE:
1412 case COMPUTE_SUBMESH:
1413 //case COMPUTE_CANCELED:
1415 //case SUBMESH_COMPUTED:
1416 //case SUBMESH_RESTORED:
1417 //case SUBMESH_LOADED:
1418 //case MESH_ENTITY_REMOVED:
1419 //case CHECK_COMPUTE_STATE:
1420 _computeError.reset(); break;
1424 if ( event == CLEAN )
1425 _alwaysComputed = false; // Unset 'true' set by MergeNodes() (issue 0022182)
1427 if (_subShape.ShapeType() == TopAbs_VERTEX)
1429 _computeState = READY_TO_COMPUTE;
1430 SMESHDS_SubMesh* smDS = GetSubMeshDS();
1431 if ( smDS && smDS->NbNodes() )
1433 if ( event == CLEAN ) {
1435 cleanSubMesh( this );
1438 _computeState = COMPUTE_OK;
1440 else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
1441 && !_alwaysComputed )
1443 const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
1444 gp_Pnt P = BRep_Tool::Pnt(V);
1445 if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
1446 _father->GetMeshDS()->SetNodeOnVertex(n,_Id);
1447 _computeState = COMPUTE_OK;
1450 if ( event == MODIF_ALGO_STATE )
1454 SMESH_Gen *gen = _father->GetGen();
1455 SMESH_Algo *algo = 0;
1457 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1458 //algo_state oldAlgoState = (algo_state) GetAlgoState();
1460 switch (_computeState)
1463 // ----------------------------------------------------------------------
1468 case MODIF_ALGO_STATE:
1470 if (algo && !algo->NeedDiscreteBoundary())
1471 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1472 if ( _algoState == HYP_OK )
1473 _computeState = READY_TO_COMPUTE;
1475 case COMPUTE: // nothing to do
1476 case COMPUTE_SUBMESH:
1478 case COMPUTE_CANCELED: // nothing to do
1482 removeSubMeshElementsAndNodes();
1484 case SUBMESH_COMPUTED: // nothing to do
1486 case SUBMESH_RESTORED:
1487 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1489 case MESH_ENTITY_REMOVED:
1491 case SUBMESH_LOADED:
1492 loadDependentMeshes();
1493 ComputeSubMeshStateEngine( SUBMESH_LOADED );
1495 case CHECK_COMPUTE_STATE:
1496 if ( IsMeshComputed() )
1497 _computeState = COMPUTE_OK;
1505 // ----------------------------------------------------------------------
1507 case READY_TO_COMPUTE:
1510 case MODIF_ALGO_STATE:
1511 _computeState = NOT_READY;
1515 if (!algo->NeedDiscreteBoundary())
1516 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1517 if ( _algoState == HYP_OK )
1518 _computeState = READY_TO_COMPUTE;
1522 case COMPUTE_SUBMESH:
1526 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1529 MESSAGE("***** verify compute state *****");
1530 _computeState = NOT_READY;
1531 setAlgoState(MISSING_HYP);
1534 TopoDS_Shape shape = _subShape;
1535 algo->SubMeshesToCompute().assign( 1, this );
1536 // check submeshes needed
1537 if (_father->HasShapeToMesh() ) {
1538 bool subComputed = false, subFailed = false;
1539 if (!algo->OnlyUnaryInput()) {
1540 if ( event == COMPUTE /*&&
1541 ( algo->NeedDiscreteBoundary() || algo->SupportSubmeshes() )*/)
1542 shape = getCollection( gen, algo, subComputed, subFailed, algo->SubMeshesToCompute());
1544 subComputed = SubMeshesComputed( & subFailed );
1547 subComputed = SubMeshesComputed();
1549 ret = ( algo->NeedDiscreteBoundary() ? subComputed :
1550 algo->SupportSubmeshes() ? !subFailed :
1551 ( !subComputed || _father->IsNotConformAllowed() ));
1554 _computeState = FAILED_TO_COMPUTE;
1555 if ( !algo->NeedDiscreteBoundary() && !subFailed )
1557 SMESH_ComputeError::New(COMPERR_BAD_INPUT_MESH,
1558 "Unexpected computed submesh",algo);
1564 // to restore cout that may be redirected by algo
1565 std::streambuf* coutBuffer = std::cout.rdbuf();
1567 //cleanDependants(); for "UseExisting_*D" algos
1568 //removeSubMeshElementsAndNodes();
1569 loadDependentMeshes();
1571 _computeState = FAILED_TO_COMPUTE;
1572 _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
1574 #if OCC_VERSION_LARGE > 0x06010000
1577 algo->InitComputeError();
1579 MemoryReserve aMemoryReserve;
1580 SMDS_Mesh::CheckMemory();
1581 Kernel_Utils::Localizer loc;
1582 if ( !_father->HasShapeToMesh() ) // no shape
1584 SMESH_MesherHelper helper( *_father );
1585 helper.SetSubShape( shape );
1586 helper.SetElementsOnShape( true );
1587 ret = algo->Compute(*_father, &helper );
1591 ret = algo->Compute((*_father), shape);
1593 if ( !_computeError || (/* !ret && */_computeError->IsOK() ) ) // algo can set _computeError of submesh
1594 _computeError = algo->GetComputeError();
1596 catch ( ::SMESH_ComputeError& comperr ) {
1597 cout << " SMESH_ComputeError caught" << endl;
1598 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1599 *_computeError = comperr;
1601 catch ( std::bad_alloc& exc ) {
1602 MESSAGE("std::bad_alloc thrown inside algo->Compute()");
1603 if ( _computeError ) {
1604 _computeError->myName = COMPERR_MEMORY_PB;
1605 //_computeError->myComment = exc.what();
1607 cleanSubMesh( this );
1610 catch ( Standard_OutOfMemory& exc ) {
1611 MESSAGE("Standard_OutOfMemory thrown inside algo->Compute()");
1612 if ( _computeError ) {
1613 _computeError->myName = COMPERR_MEMORY_PB;
1614 //_computeError->myComment = exc.what();
1616 cleanSubMesh( this );
1617 throw std::bad_alloc();
1619 catch (Standard_Failure& ex) {
1620 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1621 _computeError->myName = COMPERR_OCC_EXCEPTION;
1622 _computeError->myComment += ex.DynamicType()->Name();
1623 if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) {
1624 _computeError->myComment += ": ";
1625 _computeError->myComment += ex.GetMessageString();
1628 catch ( SALOME_Exception& S_ex ) {
1629 const int skipSalomeShift = 7; /* to skip "Salome " of
1630 "Salome Exception" prefix returned
1631 by SALOME_Exception::what() */
1632 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1633 _computeError->myName = COMPERR_SLM_EXCEPTION;
1634 _computeError->myComment = S_ex.what() + skipSalomeShift;
1636 catch ( std::exception& exc ) {
1637 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1638 _computeError->myName = COMPERR_STD_EXCEPTION;
1639 _computeError->myComment = exc.what();
1642 if ( _computeError )
1643 _computeError->myName = COMPERR_EXCEPTION;
1647 std::cout.rdbuf( coutBuffer ); // restore cout that could be redirected by algo
1649 // check if an error reported on any sub-shape
1650 bool isComputeErrorSet = !checkComputeError( algo, ret, shape );
1651 if ( isComputeErrorSet )
1653 // check if anything was built
1654 TopExp_Explorer subS(shape, _subShape.ShapeType());
1657 for (; ret && subS.More(); subS.Next())
1658 ret = _father->GetSubMesh( subS.Current() )->IsMeshComputed();
1660 // Set _computeError
1661 if (!ret && !isComputeErrorSet)
1663 for (subS.ReInit(); subS.More(); subS.Next())
1665 SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
1666 if ( !sm->IsMeshComputed() )
1668 if ( !sm->_computeError )
1669 sm->_computeError = SMESH_ComputeError::New();
1670 if ( sm->_computeError->IsOK() )
1671 sm->_computeError->myName = COMPERR_ALGO_FAILED;
1672 sm->_computeState = FAILED_TO_COMPUTE;
1673 sm->_computeError->myAlgo = algo;
1677 if (ret && _computeError && _computeError->myName != COMPERR_WARNING )
1679 _computeError.reset();
1682 // send event SUBMESH_COMPUTED
1684 if ( !algo->NeedDiscreteBoundary() )
1685 // send SUBMESH_COMPUTED to dependants of all sub-meshes of shape
1686 for (subS.ReInit(); subS.More(); subS.Next())
1688 SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
1689 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(false,false);
1690 while ( smIt->more() ) {
1692 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1693 sm->updateDependantsState( SUBMESH_COMPUTED );
1699 updateDependantsState( SUBMESH_COMPUTED );
1703 case COMPUTE_CANCELED: // nothing to do
1707 removeSubMeshElementsAndNodes();
1708 _computeState = NOT_READY;
1712 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1714 _computeState = READY_TO_COMPUTE;
1716 setAlgoState(MISSING_HYP);
1719 case SUBMESH_COMPUTED: // nothing to do
1721 case SUBMESH_RESTORED:
1722 // check if a mesh is already computed that may
1723 // happen after retrieval from a file
1724 ComputeStateEngine( CHECK_COMPUTE_STATE );
1725 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1727 if (algo) algo->SubmeshRestored( this );
1729 case MESH_ENTITY_REMOVED:
1731 case SUBMESH_LOADED:
1732 loadDependentMeshes();
1733 ComputeSubMeshStateEngine( SUBMESH_LOADED );
1735 case CHECK_COMPUTE_STATE:
1736 if ( IsMeshComputed() )
1737 _computeState = COMPUTE_OK;
1745 // ----------------------------------------------------------------------
1750 case MODIF_ALGO_STATE:
1751 ComputeStateEngine( CLEAN );
1753 if (algo && !algo->NeedDiscreteBoundary())
1754 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1756 case COMPUTE: // nothing to do
1758 case COMPUTE_CANCELED: // nothing to do
1761 cleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1762 removeSubMeshElementsAndNodes();
1763 _computeState = NOT_READY;
1764 if ( _algoState == HYP_OK )
1765 _computeState = READY_TO_COMPUTE;
1767 case SUBMESH_COMPUTED: // nothing to do
1769 case SUBMESH_RESTORED:
1770 ComputeStateEngine( CHECK_COMPUTE_STATE );
1771 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1773 if (algo) algo->SubmeshRestored( this );
1775 case MESH_ENTITY_REMOVED:
1776 updateDependantsState ( CHECK_COMPUTE_STATE );
1777 ComputeStateEngine ( CHECK_COMPUTE_STATE );
1778 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1780 case CHECK_COMPUTE_STATE:
1781 if ( !IsMeshComputed() ) {
1782 if (_algoState == HYP_OK)
1783 _computeState = READY_TO_COMPUTE;
1785 _computeState = NOT_READY;
1788 case SUBMESH_LOADED:
1789 // already treated event, thanks to which _computeState == COMPUTE_OK
1797 // ----------------------------------------------------------------------
1799 case FAILED_TO_COMPUTE:
1802 case MODIF_ALGO_STATE:
1804 ComputeStateEngine( CLEAN );
1806 if (algo && !algo->NeedDiscreteBoundary())
1807 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1808 if (_algoState == HYP_OK)
1809 _computeState = READY_TO_COMPUTE;
1811 _computeState = NOT_READY;
1813 case COMPUTE: // nothing to do
1814 case COMPUTE_SUBMESH:
1816 case COMPUTE_CANCELED:
1819 algo->CancelCompute();
1823 cleanDependants(); // submeshes dependent on me should be cleaned as well
1824 removeSubMeshElementsAndNodes();
1826 case SUBMESH_COMPUTED: // allow retry compute
1827 if (_algoState == HYP_OK)
1828 _computeState = READY_TO_COMPUTE;
1830 _computeState = NOT_READY;
1832 case SUBMESH_RESTORED:
1833 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1835 case MESH_ENTITY_REMOVED:
1837 case CHECK_COMPUTE_STATE:
1838 if ( IsMeshComputed() )
1839 _computeState = COMPUTE_OK;
1841 if (_algoState == HYP_OK)
1842 _computeState = READY_TO_COMPUTE;
1844 _computeState = NOT_READY;
1846 // case SUBMESH_LOADED:
1854 // ----------------------------------------------------------------------
1860 notifyListenersOnEvent( event, COMPUTE_EVENT );
1866 //=============================================================================
1870 //=============================================================================
1872 bool SMESH_subMesh::Evaluate(MapShapeNbElems& aResMap)
1874 _computeError.reset();
1878 if (_subShape.ShapeType() == TopAbs_VERTEX) {
1879 vector<int> aVec(SMDSEntity_Last,0);
1880 aVec[SMDSEntity_Node] = 1;
1881 aResMap.insert(make_pair(this,aVec));
1885 //SMESH_Gen *gen = _father->GetGen();
1886 SMESH_Algo *algo = 0;
1887 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1890 if(algo && !aResMap.count(this) )
1892 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1893 if (!ret) return false;
1895 if (_father->HasShapeToMesh() && algo->NeedDiscreteBoundary())
1897 // check submeshes needed
1898 bool subMeshEvaluated = true;
1899 int dimToCheck = SMESH_Gen::GetShapeDim( _subShape ) - 1;
1900 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,/*complexShapeFirst=*/true);
1901 while ( smIt->more() && subMeshEvaluated )
1903 SMESH_subMesh* sm = smIt->next();
1904 int dim = SMESH_Gen::GetShapeDim( sm->GetSubShape() );
1905 if (dim < dimToCheck) break; // the rest subMeshes are all of less dimension
1906 const vector<int> & nbs = aResMap[ sm ];
1907 subMeshEvaluated = (std::accumulate( nbs.begin(), nbs.end(), 0 ) > 0 );
1909 if ( !subMeshEvaluated )
1912 _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
1913 ret = algo->Evaluate((*_father), _subShape, aResMap);
1915 aResMap.insert( make_pair( this,vector<int>(0)));
1922 //=======================================================================
1924 * \brief Update compute_state by _computeError and send proper events to
1925 * dependent submeshes
1926 * \retval bool - true if _computeError is NOT set
1928 //=======================================================================
1930 bool SMESH_subMesh::checkComputeError(SMESH_Algo* theAlgo,
1931 const bool theComputeOK,
1932 const TopoDS_Shape& theShape)
1934 bool noErrors = true;
1936 if ( !theShape.IsNull() )
1938 // Check state of submeshes
1939 if ( !theAlgo->NeedDiscreteBoundary())
1941 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1942 while ( smIt->more() )
1943 if ( !smIt->next()->checkComputeError( theAlgo, theComputeOK ))
1947 // Check state of neighbours
1948 if ( !theAlgo->OnlyUnaryInput() &&
1949 theShape.ShapeType() == TopAbs_COMPOUND &&
1950 !theShape.IsSame( _subShape ))
1952 for (TopoDS_Iterator subIt( theShape ); subIt.More(); subIt.Next()) {
1953 SMESH_subMesh* sm = _father->GetSubMesh( subIt.Value() );
1955 if ( !sm->checkComputeError( theAlgo, theComputeOK, sm->GetSubShape() ))
1957 updateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1964 // Set my _computeState
1966 if ( !_computeError || _computeError->IsOK() )
1968 // no error description is set to this sub-mesh, check if any mesh is computed
1969 _computeState = IsMeshComputed() ? COMPUTE_OK : FAILED_TO_COMPUTE;
1970 if ( _computeState != COMPUTE_OK )
1972 if ( _subShape.ShapeType() == TopAbs_EDGE &&
1973 SMESH_Algo::isDegenerated( TopoDS::Edge( _subShape )) )
1974 _computeState = COMPUTE_OK;
1975 else if ( theComputeOK )
1976 _computeError = SMESH_ComputeError::New(COMPERR_NO_MESH_ON_SHAPE,"",theAlgo);
1980 if ( _computeError && !_computeError->IsOK() )
1982 if ( !_computeError->myAlgo )
1983 _computeError->myAlgo = theAlgo;
1987 text << theAlgo->GetName() << " failed on sub-shape #" << _Id << " with error ";
1988 if (_computeError->IsCommon() )
1989 text << _computeError->CommonName();
1991 text << _computeError->myName;
1992 if ( _computeError->myComment.size() > 0 )
1993 text << " \"" << _computeError->myComment << "\"";
1997 _computeState = _computeError->IsKO() ? FAILED_TO_COMPUTE : COMPUTE_OK;
2005 //=======================================================================
2006 //function : updateSubMeshState
2008 //=======================================================================
2010 void SMESH_subMesh::updateSubMeshState(const compute_state theState)
2012 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
2013 while ( smIt->more() )
2014 smIt->next()->_computeState = theState;
2017 //=======================================================================
2018 //function : ComputeSubMeshStateEngine
2020 //=======================================================================
2022 void SMESH_subMesh::ComputeSubMeshStateEngine(int event, const bool includeSelf)
2024 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(includeSelf,false);
2025 while ( smIt->more() )
2026 smIt->next()->ComputeStateEngine(event);
2029 //=======================================================================
2030 //function : updateDependantsState
2032 //=======================================================================
2034 void SMESH_subMesh::updateDependantsState(const compute_event theEvent)
2036 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
2037 for (; it.More(); it.Next())
2039 const TopoDS_Shape& ancestor = it.Value();
2040 if ( SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor))
2041 aSubMesh->ComputeStateEngine( theEvent );
2045 //=============================================================================
2049 //=============================================================================
2051 void SMESH_subMesh::cleanDependants()
2053 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
2055 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
2056 for (; it.More(); it.Next())
2058 const TopoDS_Shape& ancestor = it.Value();
2059 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
2060 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
2061 // will erase mesh on other shapes in a compound
2062 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
2063 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
2065 !aSubMesh->IsEmpty() ) // prevent infinite CLEAN via event lesteners
2066 aSubMesh->ComputeStateEngine(CLEAN);
2072 //=============================================================================
2076 //=============================================================================
2078 void SMESH_subMesh::removeSubMeshElementsAndNodes()
2080 cleanSubMesh( this );
2082 // algo may bind a submesh not to _subShape, eg 3D algo
2083 // sets nodes on SHELL while _subShape may be SOLID
2085 int dim = SMESH_Gen::GetShapeDim( _subShape );
2086 int type = _subShape.ShapeType() + 1;
2087 for ( ; type <= TopAbs_EDGE; type++) {
2088 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
2090 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
2091 for ( ; exp.More(); exp.Next() )
2092 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
2099 //=======================================================================
2100 //function : getCollection
2101 //purpose : return a shape containing all sub-shapes of the MainShape that can be
2102 // meshed at once along with _subShape
2103 //=======================================================================
2105 TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * theGen,
2106 SMESH_Algo* theAlgo,
2107 bool & theSubComputed,
2108 bool & theSubFailed,
2109 std::vector<SMESH_subMesh*>& theSubs)
2111 theSubComputed = SubMeshesComputed( & theSubFailed );
2113 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
2115 if ( mainShape.IsSame( _subShape ))
2118 const bool ignoreAuxiliaryHyps = false;
2119 list<const SMESHDS_Hypothesis*> aUsedHyp =
2120 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
2122 // put in a compound all shapes with the same hypothesis assigned
2123 // and a good ComputState
2125 TopoDS_Compound aCompound;
2126 BRep_Builder aBuilder;
2127 aBuilder.MakeCompound( aCompound );
2131 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
2132 for ( ; anExplorer.More(); anExplorer.Next() )
2134 const TopoDS_Shape& S = anExplorer.Current();
2135 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
2136 theSubs.push_back( subMesh );
2137 if ( subMesh == this )
2139 aBuilder.Add( aCompound, S );
2141 else if ( subMesh->GetComputeState() == READY_TO_COMPUTE )
2143 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
2144 if (strcmp( anAlgo->GetName(), theAlgo->GetName()) == 0 && // same algo
2145 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp) // same hyps
2146 aBuilder.Add( aCompound, S );
2147 if ( !subMesh->SubMeshesComputed() )
2148 theSubComputed = false;
2155 //=======================================================================
2156 //function : getSimilarAttached
2157 //purpose : return a hypothesis attached to theShape.
2158 // If theHyp is provided, similar but not same hypotheses
2159 // is returned; else only applicable ones having theHypType
2161 //=======================================================================
2163 const SMESH_Hypothesis* SMESH_subMesh::getSimilarAttached(const TopoDS_Shape& theShape,
2164 const SMESH_Hypothesis * theHyp,
2165 const int theHypType)
2167 SMESH_HypoFilter hypoKind;
2168 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
2170 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
2171 hypoKind.AndNot( hypoKind.Is( theHyp ));
2172 if ( theHyp->IsAuxiliary() )
2173 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
2175 hypoKind.AndNot( hypoKind.IsAuxiliary());
2178 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
2181 return _father->GetHypothesis( theShape, hypoKind, false );
2184 //=======================================================================
2185 //function : CheckConcurentHypothesis
2186 //purpose : check if there are several applicable hypothesis attached to
2188 //=======================================================================
2190 SMESH_Hypothesis::Hypothesis_Status
2191 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
2193 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
2195 // is there local hypothesis on me?
2196 if ( getSimilarAttached( _subShape, 0, theHypType ) )
2197 return SMESH_Hypothesis::HYP_OK;
2200 TopoDS_Shape aPrevWithHyp;
2201 const SMESH_Hypothesis* aPrevHyp = 0;
2202 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
2203 for (; it.More(); it.Next())
2205 const TopoDS_Shape& ancestor = it.Value();
2206 const SMESH_Hypothesis* hyp = getSimilarAttached( ancestor, 0, theHypType );
2209 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
2211 aPrevWithHyp = ancestor;
2214 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
2215 return SMESH_Hypothesis::HYP_CONCURENT;
2217 return SMESH_Hypothesis::HYP_OK;
2220 return SMESH_Hypothesis::HYP_OK;
2223 //================================================================================
2225 * \brief Constructor of OwnListenerData
2227 //================================================================================
2229 SMESH_subMesh::OwnListenerData::OwnListenerData( SMESH_subMesh* sm, EventListener* el):
2231 myMeshID( sm ? sm->GetFather()->GetId() : -1 ),
2232 mySubMeshID( sm ? sm->GetId() : -1 ),
2237 //================================================================================
2239 * \brief Sets an event listener and its data to a submesh
2240 * \param listener - the listener to store
2241 * \param data - the listener data to store
2242 * \param where - the submesh to store the listener and it's data
2244 * It remembers the submesh where it puts the listener in order to delete
2245 * them when HYP_OK algo_state is lost
2246 * After being set, event listener is notified on each event of where submesh.
2248 //================================================================================
2250 void SMESH_subMesh::SetEventListener(EventListener* listener,
2251 EventListenerData* data,
2252 SMESH_subMesh* where)
2254 if ( listener && where ) {
2255 where->setEventListener( listener, data );
2256 _ownListeners.push_back( OwnListenerData( where, listener ));
2260 //================================================================================
2262 * \brief Sets an event listener and its data to a submesh
2263 * \param listener - the listener to store
2264 * \param data - the listener data to store
2266 * After being set, event listener is notified on each event of a submesh.
2268 //================================================================================
2270 void SMESH_subMesh::setEventListener(EventListener* listener,
2271 EventListenerData* data)
2273 map< EventListener*, EventListenerData* >::iterator l_d =
2274 _eventListeners.find( listener );
2275 if ( l_d != _eventListeners.end() ) {
2276 EventListenerData* curData = l_d->second;
2277 if ( curData && curData != data && curData->IsDeletable() )
2283 for ( l_d = _eventListeners.begin(); l_d != _eventListeners.end(); ++l_d )
2284 if ( listener->GetName() == l_d->first->GetName() )
2286 EventListenerData* curData = l_d->second;
2287 if ( curData && curData != data && curData->IsDeletable() )
2289 if ( l_d->first->IsDeletable() )
2291 _eventListeners.erase( l_d );
2294 _eventListeners.insert( make_pair( listener, data ));
2298 //================================================================================
2300 * \brief Return an event listener data
2301 * \param listener - the listener whose data is
2302 * \retval EventListenerData* - found data, maybe NULL
2304 //================================================================================
2306 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
2308 map< EventListener*, EventListenerData* >::const_iterator l_d =
2309 _eventListeners.find( listener );
2310 if ( l_d != _eventListeners.end() )
2315 //================================================================================
2317 * \brief Return an event listener data
2318 * \param listenerName - the listener name
2319 * \retval EventListenerData* - found data, maybe NULL
2321 //================================================================================
2323 EventListenerData* SMESH_subMesh::GetEventListenerData(const string& listenerName) const
2325 map< EventListener*, EventListenerData* >::const_iterator l_d = _eventListeners.begin();
2326 for ( ; l_d != _eventListeners.end(); ++l_d )
2327 if ( listenerName == l_d->first->GetName() )
2332 //================================================================================
2334 * \brief Notify stored event listeners on the occured event
2335 * \param event - algo_event or compute_event itself
2336 * \param eventType - algo_event or compute_event
2337 * \param hyp - hypothesis, if eventType is algo_event
2339 //================================================================================
2341 void SMESH_subMesh::notifyListenersOnEvent( const int event,
2342 const event_type eventType,
2343 SMESH_Hypothesis* hyp)
2345 list< pair< EventListener*, EventListenerData* > > eventListeners( _eventListeners.begin(),
2346 _eventListeners.end());
2347 list< pair< EventListener*, EventListenerData* > >::iterator l_d = eventListeners.begin();
2348 for ( ; l_d != eventListeners.end(); ++l_d )
2350 std::pair< EventListener*, EventListenerData* > li_da = *l_d;
2351 if ( !_eventListeners.count( li_da.first )) continue;
2353 if ( li_da.first->myBusySM.insert( this ).second )
2355 const bool isDeletable = li_da.first->IsDeletable();
2357 li_da.first->ProcessEvent( event, eventType, this, li_da.second, hyp );
2359 if ( !isDeletable || _eventListeners.count( li_da.first ))
2360 li_da.first->myBusySM.erase( this ); // a listener is hopefully not dead
2365 //================================================================================
2367 * \brief Unregister the listener and delete listener's data
2368 * \param listener - the event listener
2370 //================================================================================
2372 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
2374 map< EventListener*, EventListenerData* >::iterator l_d =
2375 _eventListeners.find( listener );
2376 if ( l_d != _eventListeners.end() && l_d->first )
2378 if ( l_d->second && l_d->second->IsDeletable() )
2382 l_d->first->myBusySM.erase( this );
2383 if ( l_d->first->IsDeletable() )
2385 l_d->first->BeforeDelete( this, l_d->second );
2388 _eventListeners.erase( l_d );
2392 //================================================================================
2394 * \brief Delete event listeners depending on algo of this submesh
2396 //================================================================================
2398 void SMESH_subMesh::deleteOwnListeners()
2400 list< OwnListenerData >::iterator d;
2401 for ( d = _ownListeners.begin(); d != _ownListeners.end(); ++d )
2403 if ( !_father->MeshExists( d->myMeshID ))
2405 if ( _father->GetId() == d->myMeshID && !_father->GetSubMeshContaining( d->mySubMeshID ))
2407 d->mySubMesh->DeleteEventListener( d->myListener );
2409 _ownListeners.clear();
2412 //=======================================================================
2413 //function : loadDependentMeshes
2414 //purpose : loads dependent meshes on SUBMESH_LOADED event
2415 //=======================================================================
2417 void SMESH_subMesh::loadDependentMeshes()
2419 list< OwnListenerData >::iterator d;
2420 for ( d = _ownListeners.begin(); d != _ownListeners.end(); ++d )
2421 if ( _father != d->mySubMesh->_father )
2422 d->mySubMesh->_father->Load();
2424 // map< EventListener*, EventListenerData* >::iterator l_d = _eventListeners.begin();
2425 // for ( ; l_d != _eventListeners.end(); ++l_d )
2426 // if ( l_d->second )
2428 // const list<SMESH_subMesh*>& smList = l_d->second->mySubMeshes;
2429 // list<SMESH_subMesh*>::const_iterator sm = smList.begin();
2430 // for ( ; sm != smList.end(); ++sm )
2431 // if ( _father != (*sm)->_father )
2432 // (*sm)->_father->Load();
2436 //================================================================================
2438 * \brief Do something on a certain event
2439 * \param event - algo_event or compute_event itself
2440 * \param eventType - algo_event or compute_event
2441 * \param subMesh - the submesh where the event occures
2442 * \param data - listener data stored in the subMesh
2443 * \param hyp - hypothesis, if eventType is algo_event
2445 * The base implementation translates CLEAN event to the subMesh
2446 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
2447 * successful COMPUTE event.
2449 //================================================================================
2451 void SMESH_subMeshEventListener::ProcessEvent(const int event,
2452 const int eventType,
2453 SMESH_subMesh* subMesh,
2454 EventListenerData* data,
2455 const SMESH_Hypothesis* /*hyp*/)
2457 if ( data && !data->mySubMeshes.empty() &&
2458 eventType == SMESH_subMesh::COMPUTE_EVENT)
2460 ASSERT( data->mySubMeshes.front() != subMesh );
2461 list<SMESH_subMesh*>::iterator smIt = data->mySubMeshes.begin();
2462 list<SMESH_subMesh*>::iterator smEnd = data->mySubMeshes.end();
2464 case SMESH_subMesh::CLEAN:
2465 for ( ; smIt != smEnd; ++ smIt)
2466 (*smIt)->ComputeStateEngine( event );
2468 case SMESH_subMesh::COMPUTE:
2469 case SMESH_subMesh::COMPUTE_SUBMESH:
2470 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
2471 for ( ; smIt != smEnd; ++ smIt)
2472 (*smIt)->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
2481 //================================================================================
2483 * \brief Iterator over submeshes and optionally prepended or appended one
2485 //================================================================================
2487 struct _Iterator : public SMDS_Iterator<SMESH_subMesh*>
2489 _Iterator(SMDS_Iterator<SMESH_subMesh*>* subIt,
2490 SMESH_subMesh* prepend,
2491 SMESH_subMesh* append): myIt(subIt),myAppend(append)
2493 myCur = prepend ? prepend : myIt->more() ? myIt->next() : append;
2494 if ( myCur == append ) append = 0;
2496 /// Return true if and only if there are other object in this iterator
2501 /// Return the current object and step to the next one
2502 virtual SMESH_subMesh* next()
2504 SMESH_subMesh* res = myCur;
2505 if ( myIt->more() ) { myCur = myIt->next(); }
2506 else { myCur = myAppend; myAppend = 0; }
2513 SMESH_subMesh *myAppend, *myCur;
2514 SMDS_Iterator<SMESH_subMesh*> *myIt;
2518 //================================================================================
2520 * \brief Return iterator on the submeshes this one depends on
2521 * \param includeSelf - this submesh to be returned also
2522 * \param reverse - if true, complex shape submeshes go first
2524 //================================================================================
2526 SMESH_subMeshIteratorPtr SMESH_subMesh::getDependsOnIterator(const bool includeSelf,
2527 const bool reverse) const
2529 SMESH_subMesh *me = (SMESH_subMesh*) this;
2530 SMESH_subMesh *prepend=0, *append=0;
2531 if ( includeSelf ) {
2532 if ( reverse ) prepend = me;
2535 typedef map < int, SMESH_subMesh * > TMap;
2538 return SMESH_subMeshIteratorPtr
2539 ( new _Iterator( new SMDS_mapReverseIterator<TMap>( me->DependsOn() ), prepend, append ));
2542 return SMESH_subMeshIteratorPtr
2543 ( new _Iterator( new SMDS_mapIterator<TMap>( me->DependsOn() ), prepend, append ));
2547 //================================================================================
2549 * \brief Find common submeshes (based on shared sub-shapes with other
2550 * \param theOther submesh to check
2551 * \param theSetOfCommon set of common submesh
2553 //================================================================================
2555 bool SMESH_subMesh::FindIntersection(const SMESH_subMesh* theOther,
2556 std::set<const SMESH_subMesh*>& theSetOfCommon ) const
2558 int oldNb = theSetOfCommon.size();
2559 // check main submeshes
2560 const map <int, SMESH_subMesh*>::const_iterator otherEnd = theOther->_mapDepend.end();
2561 if ( theOther->_mapDepend.find(this->GetId()) != otherEnd )
2562 theSetOfCommon.insert( this );
2563 if ( _mapDepend.find(theOther->GetId()) != _mapDepend.end() )
2564 theSetOfCommon.insert( theOther );
2565 // check common submeshes
2566 map <int, SMESH_subMesh*>::const_iterator mapIt = _mapDepend.begin();
2567 for( ; mapIt != _mapDepend.end(); mapIt++ )
2568 if ( theOther->_mapDepend.find((*mapIt).first) != otherEnd )
2569 theSetOfCommon.insert( (*mapIt).second );
2570 return oldNb < theSetOfCommon.size();