1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : SMESH_subMesh.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_subMesh.hxx"
32 #include "SMESH_subMeshEventListener.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_Hypothesis.hxx"
36 #include "SMESH_Algo.hxx"
37 #include "SMESH_HypoFilter.hxx"
39 #include "utilities.h"
42 #include <BRep_Builder.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <TopTools_MapOfShape.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
53 #include <BRep_Tool.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
58 #include <Standard_Failure.hxx>
59 #include <Standard_ErrorHandler.hxx>
61 //=============================================================================
63 * default constructor:
65 //=============================================================================
67 SMESH_subMesh::SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
68 const TopoDS_Shape & aSubShape)
70 _subShape = aSubShape;
72 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
75 _dependenceAnalysed = false;
77 if (_subShape.ShapeType() == TopAbs_VERTEX)
80 _computeState = READY_TO_COMPUTE;
85 _computeState = NOT_READY;
89 //=============================================================================
93 //=============================================================================
95 SMESH_subMesh::~SMESH_subMesh()
97 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
101 //=============================================================================
105 //=============================================================================
107 int SMESH_subMesh::GetId() const
109 //MESSAGE("SMESH_subMesh::GetId");
113 //=============================================================================
117 //=============================================================================
119 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
121 // submesh appears in DS only when a mesher set nodes and elements on it
122 if (_subMeshDS==NULL)
124 _subMeshDS = _meshDS->MeshElements(_subShape); // may be null ...
125 // if (_subMeshDS==NULL)
127 // MESSAGE("problem... subMesh still empty");
133 //=============================================================================
137 //=============================================================================
139 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
141 if ( !GetSubMeshDS() )
142 _meshDS->NewSubMesh( _meshDS->ShapeToIndex( _subShape ) );
144 return GetSubMeshDS();
147 //=============================================================================
151 //=============================================================================
153 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
155 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
156 SMESH_subMesh *firstToCompute = 0;
158 map < int, SMESH_subMesh * >::const_iterator itsub;
159 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
161 SMESH_subMesh *sm = (*itsub).second;
162 bool readyToCompute = (sm->GetComputeState() == READY_TO_COMPUTE);
171 return firstToCompute; // a subMesh of this
173 if (_computeState == READY_TO_COMPUTE)
177 return 0; // nothing to compute
180 //=============================================================================
184 //=============================================================================
186 bool SMESH_subMesh::SubMeshesComputed()
188 //MESSAGE("SMESH_subMesh::SubMeshesComputed");
189 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
191 int myDim = SMESH_Gen::GetShapeDim( _subShape );
192 int dimToCheck = myDim - 1;
193 bool subMeshesComputed = true;
194 map < int, SMESH_subMesh * >::const_iterator itsub;
195 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
197 SMESH_subMesh *sm = (*itsub).second;
198 const TopoDS_Shape & ss = sm->GetSubShape();
199 // MSV 07.04.2006: restrict checking to myDim-1 only. Ex., there is no sense
200 // in checking of existence of edges if the algo needs only faces. Moreover,
201 // degenerated edges may have no submesh, as after computing NETGEN_2D.
202 int dim = SMESH_Gen::GetShapeDim( ss );
203 if (dim < dimToCheck)
205 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
207 // There are some tricks with compute states, e.g. Penta_3D leaves
208 // one face with READY_TO_COMPUTE state in order to be able to
209 // recompute 3D when a locale triangle hypo changes (see PAL7428).
210 // So we check if mesh is really present
211 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
212 (ds && ( ds->GetNodes()->more() || ds->GetElements()->more() )));
215 int type = ss.ShapeType();
217 subMeshesComputed = false;
221 case TopAbs_COMPOUND:
223 MESSAGE("The not computed sub mesh is a COMPOUND");
226 case TopAbs_COMPSOLID:
228 MESSAGE("The not computed sub mesh is a COMPSOLID");
233 MESSAGE("The not computed sub mesh is a SHEL");
238 MESSAGE("The not computed sub mesh is a WIRE");
243 MESSAGE("The not computed sub mesh is a SOLID");
248 MESSAGE("The not computed sub mesh is a FACE");
253 MESSAGE("The not computed sub mesh is a EDGE");
258 MESSAGE("The not computed sub mesh is of unknown type");
266 return subMeshesComputed;
269 //=============================================================================
273 //=============================================================================
275 bool SMESH_subMesh::SubMeshesReady()
277 MESSAGE("SMESH_subMesh::SubMeshesReady");
278 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
280 bool subMeshesReady = true;
281 map < int, SMESH_subMesh * >::const_iterator itsub;
282 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
284 SMESH_subMesh *sm = (*itsub).second;
285 bool computeOk = ((sm->GetComputeState() == COMPUTE_OK)
286 || (sm->GetComputeState() == READY_TO_COMPUTE));
289 subMeshesReady = false;
294 return subMeshesReady;
297 //=============================================================================
299 * Construct dependence on first level subMeshes. complex shapes (compsolid,
300 * shell, wire) are not analysed the same way as simple shapes (solid, face,
302 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
303 * with possible multiples occurences. Multiples occurences corresponds to
304 * internal frontiers within shapes of the collection and must not be keeped.
305 * See FinalizeDependence.
307 //=============================================================================
309 const map < int, SMESH_subMesh * >&SMESH_subMesh::DependsOn()
311 if (_dependenceAnalysed)
314 //MESSAGE("SMESH_subMesh::DependsOn");
316 int type = _subShape.ShapeType();
320 case TopAbs_COMPOUND:
322 //MESSAGE("compound");
323 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
326 InsertDependence(exp.Current());
328 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More();
331 InsertDependence(exp.Current()); //only shell not in solid
333 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();
336 InsertDependence(exp.Current());
338 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();
341 InsertDependence(exp.Current());
345 case TopAbs_COMPSOLID:
347 //MESSAGE("compsolid");
348 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
351 InsertDependence(exp.Current());
358 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
361 InsertDependence(exp.Current());
368 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
371 InsertDependence(exp.Current());
378 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
381 InsertDependence(exp.Current());
388 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
391 InsertDependence(exp.Current());
398 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More();
401 InsertDependence(exp.Current());
414 _dependenceAnalysed = true;
418 //=============================================================================
420 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
422 //=============================================================================
424 void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape)
426 //MESSAGE("SMESH_subMesh::InsertDependence");
427 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
428 int type = aSubShape.ShapeType();
429 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
430 int cle = aSubMesh->GetId();
431 cle += 10000000 * ordType; // sort map by ordType then index
432 if ( _mapDepend.find( cle ) == _mapDepend.end())
434 _mapDepend[cle] = aSubMesh;
435 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
436 _mapDepend.insert( subMap.begin(), subMap.end() );
440 //=============================================================================
444 //=============================================================================
446 const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
448 //MESSAGE("SMESH_subMesh::GetSubShape");
453 //=======================================================================
454 //function : CanAddHypothesis
455 //purpose : return true if theHypothesis can be attached to me:
456 // its dimention is checked
457 //=======================================================================
459 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
461 int aHypDim = theHypothesis->GetDim();
462 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
463 if ( aHypDim <= aShapeDim )
465 // if ( aHypDim < aShapeDim )
466 // return ( _father->IsMainShape( _subShape ));
471 //=======================================================================
472 //function : IsApplicableHypotesis
474 //=======================================================================
476 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
477 const TopAbs_ShapeEnum theShapeType)
479 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
481 return ( theHypothesis->GetShapeType() & (1<< theShapeType));
484 switch ( theShapeType ) {
488 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
491 // Special case for algorithms, building 2D mesh on a whole shell.
492 // Before this fix there was a problem after restoring from study,
493 // because in that case algorithm is assigned before hypothesis
494 // (on shell in problem case) and hypothesis is checked on faces
495 // (because it is 2D), where we have NO_ALGO state.
496 // Now 2D hypothesis is also applicable to shells.
497 return (theHypothesis->GetDim() == 2 || theHypothesis->GetDim() == 3);
500 // case TopAbs_COMPSOLID:
501 // case TopAbs_COMPOUND:
507 //=============================================================================
511 //=============================================================================
513 SMESH_Hypothesis::Hypothesis_Status
514 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
516 // MESSAGE("SMESH_subMesh::AlgoStateEngine");
517 //SCRUTE(_algoState);
520 // **** les retour des evenement shape sont significatifs
521 // (add ou remove fait ou non)
522 // le retour des evenement father n'indiquent pas que add ou remove fait
524 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
526 int dim = SMESH_Gen::GetShapeDim(_subShape);
531 if (event == ADD_HYP || event == ADD_ALGO)
532 return SMESH_Hypothesis::HYP_BAD_DIM; // do not allow to assign any hyp
534 return SMESH_Hypothesis::HYP_OK;
537 SMESH_Gen* gen =_father->GetGen();
538 SMESH_Algo* algo = 0;
539 int oldAlgoState = _algoState;
540 bool modifiedHyp = false; // if set to true, force event MODIF_ALGO_STATE
541 // in ComputeStateEngine
543 // ----------------------
544 // check mesh conformity
545 // ----------------------
546 if (event == ADD_ALGO)
548 if (IsApplicableHypotesis( anHyp ) &&
549 !_father->IsNotConformAllowed() &&
550 !IsConform( static_cast< SMESH_Algo* >( anHyp )))
551 return SMESH_Hypothesis::HYP_NOTCONFORM;
554 // ----------------------------------
555 // add a hypothesis to DS if possible
556 // ----------------------------------
557 if (event == ADD_HYP || event == ADD_ALGO)
559 if ( ! CanAddHypothesis( anHyp ))
560 return SMESH_Hypothesis::HYP_BAD_DIM;
562 if ( /*!anHyp->IsAuxiliary() &&*/ GetSimilarAttached( _subShape, anHyp ) )
563 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
565 if ( !_meshDS->AddHypothesis(_subShape, anHyp))
566 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
568 // Serve Propagation of 1D hypothesis
569 if (event == ADD_HYP) {
570 bool isPropagationOk = true;
571 bool isPropagationHyp = ( strcmp( "Propagation", anHyp->GetName() ) == 0 );
573 if ( isPropagationHyp ) {
574 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
575 TopTools_MapOfShape aMap;
576 for (; exp.More(); exp.Next()) {
577 if (aMap.Add(exp.Current())) {
578 if (!_father->BuildPropagationChain(exp.Current())) {
579 isPropagationOk = false;
584 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
585 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
586 TopTools_MapOfShape aMap;
587 for (; exp.More(); exp.Next()) {
588 if (aMap.Add(exp.Current())) {
589 TopoDS_Shape aMainEdge;
590 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
591 isPropagationOk = _father->RebuildPropagationChains();
592 } else if (_father->IsPropagationHypothesis(exp.Current())) {
593 isPropagationOk = _father->BuildPropagationChain(exp.Current());
601 if ( isPropagationOk ) {
602 if ( isPropagationHyp )
603 return ret; // nothing more to do for "Propagation" hypothesis
605 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
606 ret = SMESH_Hypothesis::HYP_CONCURENT;
608 } // Serve Propagation of 1D hypothesis
611 // --------------------------
612 // remove a hypothesis from DS
613 // --------------------------
614 if (event == REMOVE_HYP || event == REMOVE_ALGO)
616 if (!_meshDS->RemoveHypothesis(_subShape, anHyp))
617 return SMESH_Hypothesis::HYP_OK; // nothing changes
619 // Serve Propagation of 1D hypothesis
620 if (event == REMOVE_HYP)
622 bool isPropagationOk = true;
623 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
624 bool isPropagationHyp = propagFilter.IsOk( anHyp, _subShape );
626 if ( isPropagationHyp )
628 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
629 TopTools_MapOfShape aMap;
630 for (; exp.More(); exp.Next()) {
631 if (aMap.Add(exp.Current()) &&
632 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
633 // no more Propagation on the current edge
634 if (!_father->RemovePropagationChain(exp.Current())) {
635 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
639 // rebuild propagation chains, because removing one
640 // chain can resolve concurention, existing before
641 isPropagationOk = _father->RebuildPropagationChains();
643 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
645 isPropagationOk = _father->RebuildPropagationChains();
648 if ( isPropagationOk ) {
649 if ( isPropagationHyp )
650 return ret; // nothing more to do for "Propagation" hypothesis
652 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
653 ret = SMESH_Hypothesis::HYP_CONCURENT;
655 } // Serve Propagation of 1D hypothesis
656 else // event == REMOVE_ALGO
658 algo = dynamic_cast<SMESH_Algo*> (anHyp);
659 if (!algo->NeedDescretBoundary())
661 // clean all mesh in the tree of the current submesh;
662 // we must perform it now because later
663 // we will have no information about the type of the removed algo
665 ComputeStateEngine( CLEAN );
671 // ------------------
672 // analyse algo state
673 // ------------------
674 if (!IsApplicableHypotesis( anHyp ))
675 return ret; // not applicable hypotheses do not change algo state
680 // ----------------------------------------------------------------------
687 algo = gen->GetAlgo((*_father), _subShape);
689 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
690 SetAlgoState(HYP_OK);
691 else if ( algo->IsStatusFatal( aux_ret )) {
692 _meshDS->RemoveHypothesis(_subShape, anHyp);
696 SetAlgoState(MISSING_HYP);
705 case ADD_FATHER_ALGO: { // Algo just added in father
706 algo = gen->GetAlgo((*_father), _subShape);
708 if ( algo == anHyp ) {
709 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
710 SetAlgoState(HYP_OK);
712 SetAlgoState(MISSING_HYP);
716 case REMOVE_FATHER_HYP:
718 case REMOVE_FATHER_ALGO: {
719 algo = gen->GetAlgo((*_father), _subShape);
722 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
723 SetAlgoState(HYP_OK);
725 SetAlgoState(MISSING_HYP);
735 // ----------------------------------------------------------------------
741 algo = gen->GetAlgo((*_father), _subShape);
743 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
744 SetAlgoState(HYP_OK);
745 if (SMESH_Hypothesis::IsStatusFatal( ret ))
746 _meshDS->RemoveHypothesis(_subShape, anHyp);
747 else if (!_father->IsUsedHypothesis( anHyp, this ))
749 _meshDS->RemoveHypothesis(_subShape, anHyp);
750 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
754 case ADD_ALGO: { //already existing algo : on father ?
755 algo = gen->GetAlgo((*_father), _subShape);
757 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
758 SetAlgoState(HYP_OK);
759 else if ( algo->IsStatusFatal( aux_ret )) {
760 _meshDS->RemoveHypothesis(_subShape, anHyp);
764 SetAlgoState(MISSING_HYP);
769 case REMOVE_ALGO: { // perhaps a father algo applies ?
770 algo = gen->GetAlgo((*_father), _subShape);
771 if (algo == NULL) // no more algo applying on subShape...
773 SetAlgoState(NO_ALGO);
777 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
778 SetAlgoState(HYP_OK);
780 SetAlgoState(MISSING_HYP);
784 case ADD_FATHER_HYP: {
785 algo = gen->GetAlgo((*_father), _subShape);
787 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
788 SetAlgoState(HYP_OK);
790 SetAlgoState(MISSING_HYP);
793 case ADD_FATHER_ALGO: { // new father algo
794 algo = gen->GetAlgo((*_father), _subShape);
796 if ( algo == anHyp ) {
797 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
798 SetAlgoState(HYP_OK);
800 SetAlgoState(MISSING_HYP);
804 case REMOVE_FATHER_HYP: // nothing to do
806 case REMOVE_FATHER_ALGO: {
807 algo = gen->GetAlgo((*_father), _subShape);
808 if (algo == NULL) // no more applying algo on father
810 SetAlgoState(NO_ALGO);
814 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
815 SetAlgoState(HYP_OK);
817 SetAlgoState(MISSING_HYP);
827 // ----------------------------------------------------------------------
833 algo = gen->GetAlgo((*_father), _subShape);
835 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
837 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
838 // ret should be fatal: anHyp was not added
839 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
841 else if (!_father->IsUsedHypothesis( anHyp, this ))
842 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
844 if (SMESH_Hypothesis::IsStatusFatal( ret ))
846 MESSAGE("do not add extra hypothesis");
847 _meshDS->RemoveHypothesis(_subShape, anHyp);
855 case ADD_ALGO: { //already existing algo : on father ?
856 algo = gen->GetAlgo((*_father), _subShape);
857 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
858 // check if algo changes
860 f.Init( SMESH_HypoFilter::IsAlgo() );
861 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
862 f.AndNot( SMESH_HypoFilter::Is( algo ));
863 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
865 string(algo->GetName()) != string(prevAlgo->GetName()) )
869 SetAlgoState(MISSING_HYP);
873 algo = gen->GetAlgo((*_father), _subShape);
875 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
876 SetAlgoState(HYP_OK);
878 SetAlgoState(MISSING_HYP);
882 case REMOVE_ALGO: { // perhaps a father algo applies ?
883 algo = gen->GetAlgo((*_father), _subShape);
884 if (algo == NULL) // no more algo applying on subShape...
886 SetAlgoState(NO_ALGO);
890 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
891 // check if algo remains
892 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
896 SetAlgoState(MISSING_HYP);
900 case ADD_FATHER_HYP: { // new father hypothesis ?
901 algo = gen->GetAlgo((*_father), _subShape);
903 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
905 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
909 SetAlgoState(MISSING_HYP);
912 case ADD_FATHER_ALGO: {
913 algo = gen->GetAlgo((*_father), _subShape);
914 if ( algo == anHyp ) { // a new algo on father
915 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
916 // check if algo changes
918 f.Init( SMESH_HypoFilter::IsAlgo() );
919 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
920 f.AndNot( SMESH_HypoFilter::Is( algo ));
921 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
923 string(algo->GetName()) != string(prevAlgo->GetName()) )
927 SetAlgoState(MISSING_HYP);
931 case REMOVE_FATHER_HYP: {
932 algo = gen->GetAlgo((*_father), _subShape);
934 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
935 // is there the same local hyp or maybe a new father algo applied?
936 if ( !GetSimilarAttached( _subShape, anHyp ) )
940 SetAlgoState(MISSING_HYP);
943 case REMOVE_FATHER_ALGO: {
944 algo = gen->GetAlgo((*_father), _subShape);
945 if (algo == NULL) // no more applying algo on father
947 SetAlgoState(NO_ALGO);
951 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
952 // check if algo changes
953 if ( string(algo->GetName()) != string( anHyp->GetName()) )
957 SetAlgoState(MISSING_HYP);
967 // ----------------------------------------------------------------------
974 if ( _algoState != oldAlgoState )
976 if (_algoState == HYP_OK )
977 algo->SetEventListener( this );
978 if ( oldAlgoState == HYP_OK )
979 DeleteOwnListeners();
981 NotifyListenersOnEvent( event, ALGO_EVENT, anHyp );
983 if (_algoState != oldAlgoState || modifiedHyp)
984 ComputeStateEngine(MODIF_ALGO_STATE);
990 //=======================================================================
991 //function : IsConform
992 //purpose : check if a conform mesh will be produced by the Algo
993 //=======================================================================
995 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
997 // MESSAGE( "SMESH_subMesh::IsConform" );
999 if ( !theAlgo ) return false;
1001 // check only algo that doesn't NeedDescretBoundary(): because mesh made
1002 // on a sub-shape will be ignored by theAlgo
1003 if ( theAlgo->NeedDescretBoundary() )
1006 SMESH_Gen* gen =_father->GetGen();
1008 // only local algo is to be checked
1009 if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1012 // check algo attached to adjacent shapes
1014 // loop on one level down sub-meshes
1015 TopoDS_Iterator itsub( _subShape );
1016 for (; itsub.More(); itsub.Next())
1018 // loop on adjacent subShapes
1019 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1020 for (; it.More(); it.Next())
1022 const TopoDS_Shape& adjacent = it.Value();
1023 if ( _subShape.IsSame( adjacent )) continue;
1024 if ( adjacent.ShapeType() != _subShape.ShapeType())
1027 // check algo attached to smAdjacent
1028 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1030 //algo != theAlgo &&
1031 !algo->NeedDescretBoundary() /*&&
1032 !gen->IsGlobalHypothesis( algo, *_father )*/)
1033 return false; // NOT CONFORM MESH WILL BE PRODUCED
1040 //=============================================================================
1044 //=============================================================================
1046 void SMESH_subMesh::SetAlgoState(int state)
1051 //=============================================================================
1055 //=============================================================================
1056 SMESH_Hypothesis::Hypothesis_Status
1057 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1058 SMESH_Hypothesis * anHyp)
1060 //MESSAGE("SMESH_subMesh::SubMeshesAlgoStateEngine");
1061 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1062 //EAP: a wire (dim==1) should notify edges (dim==1)
1063 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1064 if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1066 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1068 map < int, SMESH_subMesh * >::const_iterator itsub;
1069 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1071 SMESH_subMesh *sm = (*itsub).second;
1072 SMESH_Hypothesis::Hypothesis_Status ret2 =
1073 sm->AlgoStateEngine(event, anHyp);
1081 //=============================================================================
1085 //=============================================================================
1087 void SMESH_subMesh::CleanDependsOn()
1089 //MESSAGE("SMESH_subMesh::CleanDependsOn");
1091 const map < int, SMESH_subMesh * >&dependson = DependsOn();
1092 map < int, SMESH_subMesh * >::const_iterator its;
1093 for (its = dependson.begin(); its != dependson.end(); its++)
1095 SMESH_subMesh *sm = (*its).second;
1096 sm->ComputeStateEngine(CLEAN);
1100 //=============================================================================
1104 //=============================================================================
1106 void SMESH_subMesh::DumpAlgoState(bool isMain)
1108 int dim = SMESH_Gen::GetShapeDim(_subShape);
1109 // if (dim < 1) return;
1112 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1114 map < int, SMESH_subMesh * >::const_iterator itsub;
1115 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1117 SMESH_subMesh *sm = (*itsub).second;
1118 sm->DumpAlgoState(false);
1121 int type = _subShape.ShapeType();
1122 MESSAGE("dim = " << dim << " type of shape " << type);
1126 MESSAGE(" AlgoState = NO_ALGO");
1129 MESSAGE(" AlgoState = MISSING_HYP");
1132 MESSAGE(" AlgoState = HYP_OK");
1135 switch (_computeState)
1138 MESSAGE(" ComputeState = NOT_READY");
1140 case READY_TO_COMPUTE:
1141 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1144 MESSAGE(" ComputeState = COMPUTE_OK");
1146 case FAILED_TO_COMPUTE:
1147 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1152 //================================================================================
1154 * \brief Remove nodes and elements bound to submesh
1155 * \param subMesh - submesh containing nodes and elements
1157 //================================================================================
1159 static void cleanSubMesh( SMESH_subMesh * subMesh )
1162 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1163 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1164 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1165 while (ite->more()) {
1166 const SMDS_MeshElement * elt = ite->next();
1167 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1168 //meshDS->RemoveElement(elt);
1169 meshDS->RemoveFreeElement(elt, subMeshDS);
1172 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1173 while (itn->more()) {
1174 const SMDS_MeshNode * node = itn->next();
1175 //MESSAGE( " RM node: "<<node->GetID());
1176 //meshDS->RemoveNode(node);
1177 meshDS->RemoveFreeNode(node, subMeshDS);
1183 //=============================================================================
1187 //=============================================================================
1189 bool SMESH_subMesh::ComputeStateEngine(int event)
1191 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1192 //SCRUTE(_computeState);
1195 int dim = SMESH_Gen::GetShapeDim(_subShape);
1199 if ( IsMeshComputed() )
1200 _computeState = COMPUTE_OK;
1202 _computeState = READY_TO_COMPUTE;
1205 SMESH_Gen *gen = _father->GetGen();
1206 SMESH_Algo *algo = 0;
1208 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1209 algo_state oldAlgoState = (algo_state) GetAlgoState();
1211 switch (_computeState)
1214 // ----------------------------------------------------------------------
1220 case MODIF_ALGO_STATE:
1221 algo = gen->GetAlgo((*_father), _subShape);
1222 if (algo && !algo->NeedDescretBoundary())
1223 CleanDependsOn(); // clean sub-meshes with event CLEAN
1226 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1228 _computeState = READY_TO_COMPUTE;
1230 if ( _computeState == READY_TO_COMPUTE )
1231 SetAlgoState(HYP_OK);
1233 SetAlgoState(MISSING_HYP);
1235 case COMPUTE: // nothing to do
1239 RemoveSubMeshElementsAndNodes();
1241 case SUBMESH_COMPUTED: // nothing to do
1243 case SUBMESH_RESTORED:
1244 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1246 case MESH_ENTITY_REMOVED:
1248 case CHECK_COMPUTE_STATE:
1249 if ( IsMeshComputed() )
1250 _computeState = COMPUTE_OK;
1258 // ----------------------------------------------------------------------
1260 case READY_TO_COMPUTE:
1264 case MODIF_ALGO_STATE:
1265 algo = gen->GetAlgo((*_father), _subShape);
1266 if (algo && !algo->NeedDescretBoundary())
1267 CleanDependsOn(); // clean sub-meshes with event CLEAN
1268 _computeState = NOT_READY;
1271 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1273 SetAlgoState(HYP_OK); // it might be KO if BAD_PARAM_VALUE
1274 _computeState = READY_TO_COMPUTE;
1277 SetAlgoState(MISSING_HYP);
1282 algo = gen->GetAlgo((*_father), _subShape);
1284 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1287 MESSAGE("***** verify compute state *****");
1288 _computeState = NOT_READY;
1289 SetAlgoState(MISSING_HYP);
1292 // check submeshes needed
1293 if (algo->NeedDescretBoundary())
1294 ret = SubMeshesComputed();
1297 MESSAGE("Some SubMeshes not computed");
1298 _computeState = FAILED_TO_COMPUTE;
1303 RemoveSubMeshElementsAndNodes();
1306 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1309 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput())
1310 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1312 ret = algo->Compute((*_father), _subShape);
1314 catch (Standard_Failure) {
1315 MESSAGE( "Exception in algo->Compute() ");
1321 MESSAGE("problem in algo execution: failed to compute");
1322 // release ALGO from responsibilty of partially built mesh
1323 RemoveSubMeshElementsAndNodes();
1324 _computeState = FAILED_TO_COMPUTE;
1325 if (!algo->NeedDescretBoundary())
1326 UpdateSubMeshState( FAILED_TO_COMPUTE );
1329 // Show vertices location of a failed shape
1330 cout << algo->GetName() << " failed on shape with the following vertices:" << endl;
1331 TopTools_IndexedMapOfShape vMap;
1332 TopExp::MapShapes( _subShape, TopAbs_VERTEX, vMap );
1333 for ( int iv = 1; iv <= vMap.Extent(); ++iv ) {
1334 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( vMap( iv ) )));
1335 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1342 _computeState = COMPUTE_OK;
1343 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1344 if (!algo->NeedDescretBoundary())
1345 UpdateSubMeshState( COMPUTE_OK );
1351 RemoveSubMeshElementsAndNodes();
1352 _computeState = NOT_READY;
1353 algo = gen->GetAlgo((*_father), _subShape);
1356 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1358 _computeState = READY_TO_COMPUTE;
1360 SetAlgoState(MISSING_HYP);
1363 case SUBMESH_COMPUTED: // nothing to do
1365 case SUBMESH_RESTORED:
1366 // check if a mesh is already computed that may
1367 // happen after retrieval from a file
1368 ComputeStateEngine( CHECK_COMPUTE_STATE );
1369 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1371 case MESH_ENTITY_REMOVED:
1373 case CHECK_COMPUTE_STATE:
1374 if ( IsMeshComputed() )
1375 _computeState = COMPUTE_OK;
1383 // ----------------------------------------------------------------------
1389 case MODIF_ALGO_STATE:
1390 ComputeStateEngine( CLEAN );
1391 algo = gen->GetAlgo((*_father), _subShape);
1392 if (algo && !algo->NeedDescretBoundary())
1393 CleanDependsOn(); // clean sub-meshes with event CLEAN
1395 case COMPUTE: // nothing to do
1398 CleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1399 RemoveSubMeshElementsAndNodes();
1400 _computeState = NOT_READY;
1401 algo = gen->GetAlgo((*_father), _subShape);
1404 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1406 _computeState = READY_TO_COMPUTE;
1408 SetAlgoState(MISSING_HYP);
1411 case SUBMESH_COMPUTED: // nothing to do
1413 case SUBMESH_RESTORED:
1414 ComputeStateEngine( CHECK_COMPUTE_STATE );
1415 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1417 case MESH_ENTITY_REMOVED:
1418 UpdateDependantsState( CHECK_COMPUTE_STATE );
1419 ComputeStateEngine( CHECK_COMPUTE_STATE );
1420 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1422 case CHECK_COMPUTE_STATE:
1423 if ( !IsMeshComputed() )
1424 if (_algoState == HYP_OK)
1425 _computeState = READY_TO_COMPUTE;
1427 _computeState = NOT_READY;
1435 // ----------------------------------------------------------------------
1437 case FAILED_TO_COMPUTE:
1441 if (_algoState == HYP_OK)
1442 _computeState = READY_TO_COMPUTE;
1444 _computeState = NOT_READY;
1446 case MODIF_ALGO_STATE:
1447 if (_algoState == HYP_OK)
1448 _computeState = READY_TO_COMPUTE;
1450 _computeState = NOT_READY;
1452 case COMPUTE: // nothing to do
1455 CleanDependants(); // submeshes dependent on me should be cleaned as well
1456 RemoveSubMeshElementsAndNodes();
1457 if (_algoState == HYP_OK)
1458 _computeState = READY_TO_COMPUTE;
1460 _computeState = NOT_READY;
1462 case SUBMESH_COMPUTED: // allow retry compute
1463 if (_algoState == HYP_OK)
1464 _computeState = READY_TO_COMPUTE;
1466 _computeState = NOT_READY;
1468 case SUBMESH_RESTORED:
1469 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1471 case MESH_ENTITY_REMOVED:
1473 case CHECK_COMPUTE_STATE:
1474 if ( IsMeshComputed() )
1475 _computeState = COMPUTE_OK;
1477 if (_algoState == HYP_OK)
1478 _computeState = READY_TO_COMPUTE;
1480 _computeState = NOT_READY;
1488 // ----------------------------------------------------------------------
1494 if ( _algoState != oldAlgoState || event == MODIF_HYP )
1496 if ( oldAlgoState == HYP_OK )
1497 DeleteOwnListeners();
1498 if (_algoState == HYP_OK && algo )
1499 algo->SetEventListener( this );
1501 NotifyListenersOnEvent( event, COMPUTE_EVENT );
1503 //SCRUTE(_computeState);
1507 //=======================================================================
1508 //function : ApplyToCollection
1509 //purpose : Apply theAlgo to all subshapes in theCollection
1510 //=======================================================================
1512 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1513 const TopoDS_Shape& theCollection)
1515 MESSAGE("SMESH_subMesh::ApplyToCollection");
1516 ASSERT ( !theAlgo->NeedDescretBoundary() );
1521 ret = theAlgo->Compute( *_father, theCollection );
1523 // set _computeState of subshapes
1524 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1525 for ( ; anExplorer.More(); anExplorer.Next() )
1527 const TopoDS_Shape& aSubShape = anExplorer.Current();
1528 SMESH_subMesh* subMesh = _father->GetSubMeshContaining( aSubShape );
1533 subMesh->_computeState = COMPUTE_OK;
1534 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1535 subMesh->UpdateSubMeshState( COMPUTE_OK );
1539 subMesh->_computeState = FAILED_TO_COMPUTE;
1547 //=======================================================================
1548 //function : UpdateSubMeshState
1550 //=======================================================================
1552 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1554 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1555 map<int, SMESH_subMesh*>::const_iterator itsub;
1556 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1558 SMESH_subMesh* sm = (*itsub).second;
1559 sm->_computeState = theState;
1563 //=======================================================================
1564 //function : ComputeSubMeshStateEngine
1566 //=======================================================================
1568 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1570 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1571 map<int, SMESH_subMesh*>::const_iterator itsub;
1572 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1574 SMESH_subMesh* sm = (*itsub).second;
1575 sm->ComputeStateEngine(event);
1579 //=======================================================================
1580 //function : UpdateDependantsState
1582 //=======================================================================
1584 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1586 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1587 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1588 for (; it.More(); it.Next())
1590 const TopoDS_Shape& ancestor = it.Value();
1591 SMESH_subMesh *aSubMesh =
1592 _father->GetSubMeshContaining(ancestor);
1594 aSubMesh->ComputeStateEngine( theEvent );
1598 //=============================================================================
1602 //=============================================================================
1604 void SMESH_subMesh::CleanDependants()
1606 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
1608 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1609 for (; it.More(); it.Next())
1611 const TopoDS_Shape& ancestor = it.Value();
1612 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
1613 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
1614 // will erase mesh on other shapes in a compound
1615 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
1616 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1618 aSubMesh->ComputeStateEngine(CLEAN);
1624 //=============================================================================
1628 //=============================================================================
1630 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1632 //SCRUTE(_subShape.ShapeType());
1634 cleanSubMesh( this );
1636 // algo may bind a submesh not to _subShape, eg 3D algo
1637 // sets nodes on SHELL while _subShape may be SOLID
1639 int dim = SMESH_Gen::GetShapeDim( _subShape );
1640 int type = _subShape.ShapeType() + 1;
1641 for ( ; type <= TopAbs_EDGE; type++) {
1642 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1644 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1645 for ( ; exp.More(); exp.Next() )
1646 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
1653 //=======================================================================
1654 //function : IsMeshComputed
1655 //purpose : check if _subMeshDS contains mesh elements
1656 //=======================================================================
1658 bool SMESH_subMesh::IsMeshComputed() const
1660 // algo may bind a submesh not to _subShape, eg 3D algo
1661 // sets nodes on SHELL while _subShape may be SOLID
1663 int dim = SMESH_Gen::GetShapeDim( _subShape );
1664 int type = _subShape.ShapeType();
1665 for ( ; type <= TopAbs_VERTEX; type++) {
1666 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1668 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1669 for ( ; exp.More(); exp.Next() )
1671 SMESHDS_SubMesh * smDS = _meshDS->MeshElements( exp.Current() );
1672 if ( smDS && ( smDS->NbElements() || smDS->NbNodes()))
1684 //=======================================================================
1685 //function : GetCollection
1686 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1687 // meshed at once along with _subShape
1688 //=======================================================================
1690 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1692 MESSAGE("SMESH_subMesh::GetCollection");
1693 ASSERT (!theAlgo->NeedDescretBoundary());
1695 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1697 if ( mainShape.IsSame( _subShape ))
1700 const bool ignoreAuxiliaryHyps = false;
1701 list<const SMESHDS_Hypothesis*> aUsedHyp =
1702 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
1704 // put in a compound all shapes with the same hypothesis assigned
1705 // and a good ComputState
1707 TopoDS_Compound aCompound;
1708 BRep_Builder aBuilder;
1709 aBuilder.MakeCompound( aCompound );
1711 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1712 for ( ; anExplorer.More(); anExplorer.Next() )
1714 const TopoDS_Shape& S = anExplorer.Current();
1715 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1716 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1718 if (subMesh->GetComputeState() == READY_TO_COMPUTE &&
1719 anAlgo == theAlgo &&
1720 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp)
1722 aBuilder.Add( aCompound, S );
1729 //=======================================================================
1730 //function : GetSimilarAttached
1731 //purpose : return a hypothesis attached to theShape.
1732 // If theHyp is provided, similar but not same hypotheses
1733 // is returned; else only applicable ones having theHypType
1735 //=======================================================================
1737 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1738 const SMESH_Hypothesis * theHyp,
1739 const int theHypType)
1741 SMESH_HypoFilter hypoKind;
1742 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
1744 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
1745 hypoKind.AndNot( hypoKind.Is( theHyp ));
1746 if ( theHyp->IsAuxiliary() )
1747 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
1749 hypoKind.AndNot( hypoKind.IsAuxiliary());
1752 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
1755 return _father->GetHypothesis( theShape, hypoKind, false );
1758 //=======================================================================
1759 //function : CheckConcurentHypothesis
1760 //purpose : check if there are several applicable hypothesis attached to
1762 //=======================================================================
1764 SMESH_Hypothesis::Hypothesis_Status
1765 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1767 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1769 // is there local hypothesis on me?
1770 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1771 return SMESH_Hypothesis::HYP_OK;
1774 TopoDS_Shape aPrevWithHyp;
1775 const SMESH_Hypothesis* aPrevHyp = 0;
1776 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1777 for (; it.More(); it.Next())
1779 const TopoDS_Shape& ancestor = it.Value();
1780 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1783 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1785 aPrevWithHyp = ancestor;
1788 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1789 return SMESH_Hypothesis::HYP_CONCURENT;
1791 return SMESH_Hypothesis::HYP_OK;
1794 return SMESH_Hypothesis::HYP_OK;
1797 //================================================================================
1799 * \brief Sets an event listener and its data to a submesh
1800 * \param listener - the listener to store
1801 * \param data - the listener data to store
1802 * \param where - the submesh to store the listener and it's data
1803 * \param deleteListener - if true then the listener will be deleted as
1804 * it is removed from where submesh
1806 * It remembers the submesh where it puts the listener in order to delete
1807 * them when HYP_OK algo_state is lost
1808 * After being set, event listener is notified on each event of where submesh.
1810 //================================================================================
1812 void SMESH_subMesh::SetEventListener(EventListener* listener,
1813 EventListenerData* data,
1814 SMESH_subMesh* where)
1816 if ( listener && where ) {
1817 where->SetEventListener( listener, data );
1818 myOwnListeners.push_back( make_pair( where, listener ));
1822 //================================================================================
1824 * \brief Sets an event listener and its data to a submesh
1825 * \param listener - the listener to store
1826 * \param data - the listener data to store
1828 * After being set, event listener is notified on each event of a submesh.
1830 //================================================================================
1832 void SMESH_subMesh::SetEventListener(EventListener* listener, EventListenerData* data)
1834 myEventListeners.insert( make_pair( listener, data ));
1837 //================================================================================
1839 * \brief Return an event listener data
1840 * \param listener - the listener whose data is
1841 * \retval EventListenerData* - found data, maybe NULL
1843 //================================================================================
1845 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
1847 map< EventListener*, EventListenerData* >::const_iterator l_d =
1848 myEventListeners.find( listener );
1849 if ( l_d != myEventListeners.end() )
1854 //================================================================================
1856 * \brief Notify stored event listeners on the occured event
1857 * \param event - algo_event or compute_event itself
1858 * \param eventType - algo_event or compute_event
1859 * \param subMesh - the submesh where the event occures
1860 * \param data - listener data stored in the subMesh
1861 * \param hyp - hypothesis, if eventType is algo_event
1863 //================================================================================
1865 void SMESH_subMesh::NotifyListenersOnEvent( const int event,
1866 const event_type eventType,
1867 SMESH_Hypothesis* hyp)
1869 map< EventListener*, EventListenerData* >::iterator l_d = myEventListeners.begin();
1870 for ( ; l_d != myEventListeners.end(); ++l_d )
1871 l_d->first->ProcessEvent( event, eventType, this, l_d->second, hyp );
1874 //================================================================================
1876 * \brief Unregister the listener and delete listener's data
1877 * \param listener - the event listener
1879 //================================================================================
1881 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
1883 map< EventListener*, EventListenerData* >::iterator l_d =
1884 myEventListeners.find( listener );
1885 if ( l_d != myEventListeners.end() ) {
1886 if ( l_d->first->IsDeletable() ) delete l_d->first;
1887 if ( l_d->second->IsDeletable() ) delete l_d->second;
1888 myEventListeners.erase( l_d );
1892 //================================================================================
1894 * \brief Delete event listeners depending on algo of this submesh
1896 //================================================================================
1898 void SMESH_subMesh::DeleteOwnListeners()
1900 list< pair< SMESH_subMesh*, EventListener* > >::iterator sm_l;
1901 for ( sm_l = myOwnListeners.begin(); sm_l != myOwnListeners.end(); ++sm_l)
1902 sm_l->first->DeleteEventListener( sm_l->second );
1903 myOwnListeners.clear();
1906 //================================================================================
1908 * \brief Do something on a certain event
1909 * \param event - algo_event or compute_event itself
1910 * \param eventType - algo_event or compute_event
1911 * \param subMesh - the submesh where the event occures
1912 * \param data - listener data stored in the subMesh
1913 * \param hyp - hypothesis, if eventType is algo_event
1915 * The base implementation translates CLEAN event to the subMesh
1916 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
1917 * successful COMPUTE event.
1919 //================================================================================
1921 void SMESH_subMeshEventListener::ProcessEvent(const int event,
1922 const int eventType,
1923 SMESH_subMesh* subMesh,
1924 EventListenerData* data,
1925 SMESH_Hypothesis* /*hyp*/)
1927 if ( data && !data->mySubMeshes.empty() &&
1928 eventType == SMESH_subMesh::COMPUTE_EVENT)
1930 ASSERT( data->mySubMeshes.front() != subMesh );
1932 case SMESH_subMesh::CLEAN:
1933 data->mySubMeshes.front()->ComputeStateEngine( event );
1935 case SMESH_subMesh::COMPUTE:
1936 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
1937 data->mySubMeshes.front()->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );