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 || event == ADD_FATHER_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 // NOTE: it is possible to re-implement Propagation using EventListener
570 if (event == ADD_HYP) {
571 bool isPropagationOk = true;
572 bool isPropagationHyp = ( strcmp( "Propagation", anHyp->GetName() ) == 0 );
574 if ( isPropagationHyp ) {
575 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
576 TopTools_MapOfShape aMap;
577 for (; exp.More(); exp.Next()) {
578 if (aMap.Add(exp.Current())) {
579 if (!_father->BuildPropagationChain(exp.Current())) {
580 isPropagationOk = false;
585 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
586 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
587 TopTools_MapOfShape aMap;
588 for (; exp.More(); exp.Next()) {
589 if (aMap.Add(exp.Current())) {
590 TopoDS_Shape aMainEdge;
591 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
592 isPropagationOk = _father->RebuildPropagationChains();
593 } else if (_father->IsPropagationHypothesis(exp.Current())) {
594 isPropagationOk = _father->BuildPropagationChain(exp.Current());
602 if ( isPropagationOk ) {
603 if ( isPropagationHyp )
604 return ret; // nothing more to do for "Propagation" hypothesis
606 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
607 ret = SMESH_Hypothesis::HYP_CONCURENT;
609 } // Serve Propagation of 1D hypothesis
612 // --------------------------
613 // remove a hypothesis from DS
614 // --------------------------
615 if (event == REMOVE_HYP || event == REMOVE_ALGO)
617 if (!_meshDS->RemoveHypothesis(_subShape, anHyp))
618 return SMESH_Hypothesis::HYP_OK; // nothing changes
620 // Serve Propagation of 1D hypothesis
621 // NOTE: it is possible to re-implement Propagation using EventListener
622 if (event == REMOVE_HYP)
624 bool isPropagationOk = true;
625 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
626 bool isPropagationHyp = propagFilter.IsOk( anHyp, _subShape );
628 if ( isPropagationHyp )
630 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
631 TopTools_MapOfShape aMap;
632 for (; exp.More(); exp.Next()) {
633 if (aMap.Add(exp.Current()) &&
634 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
635 // no more Propagation on the current edge
636 if (!_father->RemovePropagationChain(exp.Current())) {
637 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
641 // rebuild propagation chains, because removing one
642 // chain can resolve concurention, existing before
643 isPropagationOk = _father->RebuildPropagationChains();
645 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
647 isPropagationOk = _father->RebuildPropagationChains();
650 if ( isPropagationOk ) {
651 if ( isPropagationHyp )
652 return ret; // nothing more to do for "Propagation" hypothesis
654 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
655 ret = SMESH_Hypothesis::HYP_CONCURENT;
657 } // Serve Propagation of 1D hypothesis
658 else // event == REMOVE_ALGO
660 algo = dynamic_cast<SMESH_Algo*> (anHyp);
661 if (!algo->NeedDescretBoundary())
663 // clean all mesh in the tree of the current submesh;
664 // we must perform it now because later
665 // we will have no information about the type of the removed algo
667 ComputeStateEngine( CLEAN );
673 // ------------------
674 // analyse algo state
675 // ------------------
676 if (!IsApplicableHypotesis( anHyp ))
677 return ret; // not applicable hypotheses do not change algo state
682 // ----------------------------------------------------------------------
689 algo = gen->GetAlgo((*_father), _subShape);
691 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
692 SetAlgoState(HYP_OK);
693 else if ( algo->IsStatusFatal( aux_ret )) {
694 _meshDS->RemoveHypothesis(_subShape, anHyp);
698 SetAlgoState(MISSING_HYP);
707 case ADD_FATHER_ALGO: { // Algo just added in father
708 algo = gen->GetAlgo((*_father), _subShape);
710 if ( algo == anHyp ) {
711 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
712 SetAlgoState(HYP_OK);
714 SetAlgoState(MISSING_HYP);
718 case REMOVE_FATHER_HYP:
720 case REMOVE_FATHER_ALGO: {
721 algo = gen->GetAlgo((*_father), _subShape);
724 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
725 SetAlgoState(HYP_OK);
727 SetAlgoState(MISSING_HYP);
737 // ----------------------------------------------------------------------
743 algo = gen->GetAlgo((*_father), _subShape);
745 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
746 SetAlgoState(HYP_OK);
747 if (SMESH_Hypothesis::IsStatusFatal( ret ))
748 _meshDS->RemoveHypothesis(_subShape, anHyp);
749 else if (!_father->IsUsedHypothesis( anHyp, this ))
751 _meshDS->RemoveHypothesis(_subShape, anHyp);
752 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
756 case ADD_ALGO: { //already existing algo : on father ?
757 algo = gen->GetAlgo((*_father), _subShape);
759 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
760 SetAlgoState(HYP_OK);
761 else if ( algo->IsStatusFatal( aux_ret )) {
762 _meshDS->RemoveHypothesis(_subShape, anHyp);
766 SetAlgoState(MISSING_HYP);
771 case REMOVE_ALGO: { // perhaps a father algo applies ?
772 algo = gen->GetAlgo((*_father), _subShape);
773 if (algo == NULL) // no more algo applying on subShape...
775 SetAlgoState(NO_ALGO);
779 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
780 SetAlgoState(HYP_OK);
782 SetAlgoState(MISSING_HYP);
786 case ADD_FATHER_HYP: {
787 algo = gen->GetAlgo((*_father), _subShape);
789 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
790 SetAlgoState(HYP_OK);
792 SetAlgoState(MISSING_HYP);
795 case ADD_FATHER_ALGO: { // new father algo
796 algo = gen->GetAlgo((*_father), _subShape);
798 if ( algo == anHyp ) {
799 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
800 SetAlgoState(HYP_OK);
802 SetAlgoState(MISSING_HYP);
806 case REMOVE_FATHER_HYP: // nothing to do
808 case REMOVE_FATHER_ALGO: {
809 algo = gen->GetAlgo((*_father), _subShape);
810 if (algo == NULL) // no more applying algo on father
812 SetAlgoState(NO_ALGO);
816 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
817 SetAlgoState(HYP_OK);
819 SetAlgoState(MISSING_HYP);
829 // ----------------------------------------------------------------------
835 algo = gen->GetAlgo((*_father), _subShape);
837 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
839 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
840 // ret should be fatal: anHyp was not added
841 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
843 else if (!_father->IsUsedHypothesis( anHyp, this ))
844 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
846 if (SMESH_Hypothesis::IsStatusFatal( ret ))
848 MESSAGE("do not add extra hypothesis");
849 _meshDS->RemoveHypothesis(_subShape, anHyp);
857 case ADD_ALGO: { //already existing algo : on father ?
858 algo = gen->GetAlgo((*_father), _subShape);
859 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
860 // check if algo changes
862 f.Init( SMESH_HypoFilter::IsAlgo() );
863 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
864 f.AndNot( SMESH_HypoFilter::Is( algo ));
865 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
867 string(algo->GetName()) != string(prevAlgo->GetName()) )
871 SetAlgoState(MISSING_HYP);
875 algo = gen->GetAlgo((*_father), _subShape);
877 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
878 SetAlgoState(HYP_OK);
880 SetAlgoState(MISSING_HYP);
884 case REMOVE_ALGO: { // perhaps a father algo applies ?
885 algo = gen->GetAlgo((*_father), _subShape);
886 if (algo == NULL) // no more algo applying on subShape...
888 SetAlgoState(NO_ALGO);
892 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
893 // check if algo remains
894 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
898 SetAlgoState(MISSING_HYP);
902 case ADD_FATHER_HYP: { // new father hypothesis ?
903 algo = gen->GetAlgo((*_father), _subShape);
905 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
907 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
911 SetAlgoState(MISSING_HYP);
914 case ADD_FATHER_ALGO: {
915 algo = gen->GetAlgo((*_father), _subShape);
916 if ( algo == anHyp ) { // a new algo on father
917 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
918 // check if algo changes
920 f.Init( SMESH_HypoFilter::IsAlgo() );
921 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
922 f.AndNot( SMESH_HypoFilter::Is( algo ));
923 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
925 string(algo->GetName()) != string(prevAlgo->GetName()) )
929 SetAlgoState(MISSING_HYP);
933 case REMOVE_FATHER_HYP: {
934 algo = gen->GetAlgo((*_father), _subShape);
936 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
937 // is there the same local hyp or maybe a new father algo applied?
938 if ( !GetSimilarAttached( _subShape, anHyp ) )
942 SetAlgoState(MISSING_HYP);
945 case REMOVE_FATHER_ALGO: {
946 algo = gen->GetAlgo((*_father), _subShape);
947 if (algo == NULL) // no more applying algo on father
949 SetAlgoState(NO_ALGO);
953 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
954 // check if algo changes
955 if ( string(algo->GetName()) != string( anHyp->GetName()) )
959 SetAlgoState(MISSING_HYP);
969 // ----------------------------------------------------------------------
976 // detect algorithm hidding
978 if ( ret == SMESH_Hypothesis::HYP_OK &&
979 ( event == ADD_ALGO || event == ADD_FATHER_ALGO ) &&
980 algo->GetName() == anHyp->GetName() )
983 SMESH_Gen* gen = _father->GetGen();
984 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
985 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && it.More()); it.Next() ) {
986 if ( SMESH_Algo* upperAlgo = gen->GetAlgo( *_father, it.Value() ))
987 if ( !upperAlgo->NeedDescretBoundary() )
988 ret = SMESH_Hypothesis::HYP_HIDDEN_ALGO;
991 if ( ret == SMESH_Hypothesis::HYP_OK && !algo->NeedDescretBoundary() ) {
992 map<int, SMESH_subMesh*>::reverse_iterator i_sm = _mapDepend.rbegin();
993 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && i_sm != _mapDepend.rend()) ; ++i_sm )
994 if ( gen->GetAlgo( *_father, i_sm->second->_subShape ))
995 ret = SMESH_Hypothesis::HYP_HIDING_ALGO;
999 if ( _algoState != oldAlgoState )
1001 if (_algoState == HYP_OK )
1002 algo->SetEventListener( this );
1003 if ( oldAlgoState == HYP_OK )
1004 DeleteOwnListeners();
1006 NotifyListenersOnEvent( event, ALGO_EVENT, anHyp );
1008 if (_algoState != oldAlgoState || modifiedHyp)
1009 ComputeStateEngine(MODIF_ALGO_STATE);
1015 //=======================================================================
1016 //function : IsConform
1017 //purpose : check if a conform mesh will be produced by the Algo
1018 //=======================================================================
1020 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
1022 // MESSAGE( "SMESH_subMesh::IsConform" );
1023 if ( !theAlgo ) return false;
1025 // Suppose that theAlgo is applicable to _subShape, do not check it here
1026 //if ( !IsApplicableHypotesis( theAlgo )) return false;
1028 // check only algo that doesn't NeedDescretBoundary(): because mesh made
1029 // on a sub-shape will be ignored by theAlgo
1030 if ( theAlgo->NeedDescretBoundary() ||
1031 !theAlgo->OnlyUnaryInput() ) // all adjacent shapes will be meshed by this algo?
1034 SMESH_Gen* gen =_father->GetGen();
1036 // only local algo is to be checked
1037 //if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1038 if ( _subShape.ShapeType() == _father->GetMeshDS()->ShapeToMesh().ShapeType() )
1041 // check algo attached to adjacent shapes
1043 // loop on one level down sub-meshes
1044 TopoDS_Iterator itsub( _subShape );
1045 for (; itsub.More(); itsub.Next())
1047 // loop on adjacent subShapes
1048 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1049 for (; it.More(); it.Next())
1051 const TopoDS_Shape& adjacent = it.Value();
1052 if ( _subShape.IsSame( adjacent )) continue;
1053 if ( adjacent.ShapeType() != _subShape.ShapeType())
1056 // check algo attached to smAdjacent
1057 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1059 !algo->NeedDescretBoundary() &&
1060 algo->OnlyUnaryInput())
1061 return false; // NOT CONFORM MESH WILL BE PRODUCED
1068 //=============================================================================
1072 //=============================================================================
1074 void SMESH_subMesh::SetAlgoState(int state)
1079 //=============================================================================
1083 //=============================================================================
1084 SMESH_Hypothesis::Hypothesis_Status
1085 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1086 SMESH_Hypothesis * anHyp)
1088 //MESSAGE("SMESH_subMesh::SubMeshesAlgoStateEngine");
1089 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1090 //EAP: a wire (dim==1) should notify edges (dim==1)
1091 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1092 if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1094 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1096 map < int, SMESH_subMesh * >::const_iterator itsub;
1097 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1099 SMESH_subMesh *sm = (*itsub).second;
1100 SMESH_Hypothesis::Hypothesis_Status ret2 =
1101 sm->AlgoStateEngine(event, anHyp);
1109 //=============================================================================
1113 //=============================================================================
1115 void SMESH_subMesh::CleanDependsOn()
1117 //MESSAGE("SMESH_subMesh::CleanDependsOn");
1119 const map < int, SMESH_subMesh * >&dependson = DependsOn();
1120 map < int, SMESH_subMesh * >::const_iterator its;
1121 for (its = dependson.begin(); its != dependson.end(); its++)
1123 SMESH_subMesh *sm = (*its).second;
1124 sm->ComputeStateEngine(CLEAN);
1128 //=============================================================================
1132 //=============================================================================
1134 void SMESH_subMesh::DumpAlgoState(bool isMain)
1136 int dim = SMESH_Gen::GetShapeDim(_subShape);
1137 // if (dim < 1) return;
1140 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1142 map < int, SMESH_subMesh * >::const_iterator itsub;
1143 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1145 SMESH_subMesh *sm = (*itsub).second;
1146 sm->DumpAlgoState(false);
1149 int type = _subShape.ShapeType();
1150 MESSAGE("dim = " << dim << " type of shape " << type);
1154 MESSAGE(" AlgoState = NO_ALGO");
1157 MESSAGE(" AlgoState = MISSING_HYP");
1160 MESSAGE(" AlgoState = HYP_OK");
1163 switch (_computeState)
1166 MESSAGE(" ComputeState = NOT_READY");
1168 case READY_TO_COMPUTE:
1169 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1172 MESSAGE(" ComputeState = COMPUTE_OK");
1174 case FAILED_TO_COMPUTE:
1175 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1180 //================================================================================
1182 * \brief Remove nodes and elements bound to submesh
1183 * \param subMesh - submesh containing nodes and elements
1185 //================================================================================
1187 static void cleanSubMesh( SMESH_subMesh * subMesh )
1190 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1191 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1192 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1193 while (ite->more()) {
1194 const SMDS_MeshElement * elt = ite->next();
1195 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1196 //meshDS->RemoveElement(elt);
1197 meshDS->RemoveFreeElement(elt, subMeshDS);
1200 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1201 while (itn->more()) {
1202 const SMDS_MeshNode * node = itn->next();
1203 //MESSAGE( " RM node: "<<node->GetID());
1204 //meshDS->RemoveNode(node);
1205 meshDS->RemoveFreeNode(node, subMeshDS);
1211 //=============================================================================
1215 //=============================================================================
1217 bool SMESH_subMesh::ComputeStateEngine(int event)
1219 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1220 //SCRUTE(_computeState);
1223 int dim = SMESH_Gen::GetShapeDim(_subShape);
1227 if ( IsMeshComputed() )
1228 _computeState = COMPUTE_OK;
1230 _computeState = READY_TO_COMPUTE;
1233 SMESH_Gen *gen = _father->GetGen();
1234 SMESH_Algo *algo = 0;
1236 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1237 algo_state oldAlgoState = (algo_state) GetAlgoState();
1239 switch (_computeState)
1242 // ----------------------------------------------------------------------
1248 case MODIF_ALGO_STATE:
1249 algo = gen->GetAlgo((*_father), _subShape);
1250 if (algo && !algo->NeedDescretBoundary())
1251 CleanDependsOn(); // clean sub-meshes with event CLEAN
1254 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1256 _computeState = READY_TO_COMPUTE;
1258 if ( _computeState == READY_TO_COMPUTE )
1259 SetAlgoState(HYP_OK);
1261 SetAlgoState(MISSING_HYP);
1263 case COMPUTE: // nothing to do
1267 RemoveSubMeshElementsAndNodes();
1269 case SUBMESH_COMPUTED: // nothing to do
1271 case SUBMESH_RESTORED:
1272 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1274 case MESH_ENTITY_REMOVED:
1276 case CHECK_COMPUTE_STATE:
1277 if ( IsMeshComputed() )
1278 _computeState = COMPUTE_OK;
1286 // ----------------------------------------------------------------------
1288 case READY_TO_COMPUTE:
1292 case MODIF_ALGO_STATE:
1293 algo = gen->GetAlgo((*_father), _subShape);
1294 if (algo && !algo->NeedDescretBoundary())
1295 CleanDependsOn(); // clean sub-meshes with event CLEAN
1296 _computeState = NOT_READY;
1299 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1301 SetAlgoState(HYP_OK); // it might be KO if BAD_PARAM_VALUE
1302 _computeState = READY_TO_COMPUTE;
1305 SetAlgoState(MISSING_HYP);
1310 algo = gen->GetAlgo((*_father), _subShape);
1312 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1315 MESSAGE("***** verify compute state *****");
1316 _computeState = NOT_READY;
1317 SetAlgoState(MISSING_HYP);
1320 // check submeshes needed
1321 if (algo->NeedDescretBoundary())
1322 ret = SubMeshesComputed();
1325 MESSAGE("Some SubMeshes not computed");
1326 _computeState = FAILED_TO_COMPUTE;
1331 RemoveSubMeshElementsAndNodes();
1334 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1337 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput())
1338 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1340 ret = algo->Compute((*_father), _subShape);
1342 catch (Standard_Failure) {
1343 MESSAGE( "Exception in algo->Compute() ");
1349 MESSAGE("problem in algo execution: failed to compute");
1350 // release ALGO from responsibilty of partially built mesh
1351 RemoveSubMeshElementsAndNodes();
1352 _computeState = FAILED_TO_COMPUTE;
1353 if (!algo->NeedDescretBoundary())
1354 UpdateSubMeshState( FAILED_TO_COMPUTE );
1357 // Show vertices location of a failed shape
1358 cout << algo->GetName() << " failed on shape with the following vertices:" << endl;
1359 TopTools_IndexedMapOfShape vMap;
1360 TopExp::MapShapes( _subShape, TopAbs_VERTEX, vMap );
1361 for ( int iv = 1; iv <= vMap.Extent(); ++iv ) {
1362 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( vMap( iv ) )));
1363 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1370 _computeState = COMPUTE_OK;
1371 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1372 if (!algo->NeedDescretBoundary())
1373 UpdateSubMeshState( COMPUTE_OK );
1379 RemoveSubMeshElementsAndNodes();
1380 _computeState = NOT_READY;
1381 algo = gen->GetAlgo((*_father), _subShape);
1384 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1386 _computeState = READY_TO_COMPUTE;
1388 SetAlgoState(MISSING_HYP);
1391 case SUBMESH_COMPUTED: // nothing to do
1393 case SUBMESH_RESTORED:
1394 // check if a mesh is already computed that may
1395 // happen after retrieval from a file
1396 ComputeStateEngine( CHECK_COMPUTE_STATE );
1397 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1399 case MESH_ENTITY_REMOVED:
1401 case CHECK_COMPUTE_STATE:
1402 if ( IsMeshComputed() )
1403 _computeState = COMPUTE_OK;
1411 // ----------------------------------------------------------------------
1417 case MODIF_ALGO_STATE:
1418 ComputeStateEngine( CLEAN );
1419 algo = gen->GetAlgo((*_father), _subShape);
1420 if (algo && !algo->NeedDescretBoundary())
1421 CleanDependsOn(); // clean sub-meshes with event CLEAN
1423 case COMPUTE: // nothing to do
1426 CleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1427 RemoveSubMeshElementsAndNodes();
1428 _computeState = NOT_READY;
1429 algo = gen->GetAlgo((*_father), _subShape);
1432 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1434 _computeState = READY_TO_COMPUTE;
1436 SetAlgoState(MISSING_HYP);
1439 case SUBMESH_COMPUTED: // nothing to do
1441 case SUBMESH_RESTORED:
1442 ComputeStateEngine( CHECK_COMPUTE_STATE );
1443 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1445 case MESH_ENTITY_REMOVED:
1446 UpdateDependantsState( CHECK_COMPUTE_STATE );
1447 ComputeStateEngine( CHECK_COMPUTE_STATE );
1448 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1450 case CHECK_COMPUTE_STATE:
1451 if ( !IsMeshComputed() )
1452 if (_algoState == HYP_OK)
1453 _computeState = READY_TO_COMPUTE;
1455 _computeState = NOT_READY;
1463 // ----------------------------------------------------------------------
1465 case FAILED_TO_COMPUTE:
1469 if (_algoState == HYP_OK)
1470 _computeState = READY_TO_COMPUTE;
1472 _computeState = NOT_READY;
1474 case MODIF_ALGO_STATE:
1475 if (_algoState == HYP_OK)
1476 _computeState = READY_TO_COMPUTE;
1478 _computeState = NOT_READY;
1480 case COMPUTE: // nothing to do
1483 CleanDependants(); // submeshes dependent on me should be cleaned as well
1484 RemoveSubMeshElementsAndNodes();
1485 if (_algoState == HYP_OK)
1486 _computeState = READY_TO_COMPUTE;
1488 _computeState = NOT_READY;
1490 case SUBMESH_COMPUTED: // allow retry compute
1491 if (_algoState == HYP_OK)
1492 _computeState = READY_TO_COMPUTE;
1494 _computeState = NOT_READY;
1496 case SUBMESH_RESTORED:
1497 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1499 case MESH_ENTITY_REMOVED:
1501 case CHECK_COMPUTE_STATE:
1502 if ( IsMeshComputed() )
1503 _computeState = COMPUTE_OK;
1505 if (_algoState == HYP_OK)
1506 _computeState = READY_TO_COMPUTE;
1508 _computeState = NOT_READY;
1516 // ----------------------------------------------------------------------
1522 if ( _algoState != oldAlgoState || event == MODIF_HYP )
1524 if ( oldAlgoState == HYP_OK )
1525 DeleteOwnListeners();
1526 if (_algoState == HYP_OK && algo )
1527 algo->SetEventListener( this );
1529 NotifyListenersOnEvent( event, COMPUTE_EVENT );
1531 //SCRUTE(_computeState);
1535 //=======================================================================
1536 //function : ApplyToCollection
1537 //purpose : Apply theAlgo to all subshapes in theCollection
1538 //=======================================================================
1540 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1541 const TopoDS_Shape& theCollection)
1543 MESSAGE("SMESH_subMesh::ApplyToCollection");
1544 ASSERT ( !theAlgo->NeedDescretBoundary() );
1549 ret = theAlgo->Compute( *_father, theCollection );
1551 // set _computeState of subshapes
1552 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1553 for ( ; anExplorer.More(); anExplorer.Next() )
1555 const TopoDS_Shape& aSubShape = anExplorer.Current();
1556 SMESH_subMesh* subMesh = _father->GetSubMeshContaining( aSubShape );
1561 subMesh->_computeState = COMPUTE_OK;
1562 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1563 subMesh->UpdateSubMeshState( COMPUTE_OK );
1567 subMesh->_computeState = FAILED_TO_COMPUTE;
1575 //=======================================================================
1576 //function : UpdateSubMeshState
1578 //=======================================================================
1580 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1582 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1583 map<int, SMESH_subMesh*>::const_iterator itsub;
1584 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1586 SMESH_subMesh* sm = (*itsub).second;
1587 sm->_computeState = theState;
1591 //=======================================================================
1592 //function : ComputeSubMeshStateEngine
1594 //=======================================================================
1596 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1598 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1599 map<int, SMESH_subMesh*>::const_iterator itsub;
1600 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1602 SMESH_subMesh* sm = (*itsub).second;
1603 sm->ComputeStateEngine(event);
1607 //=======================================================================
1608 //function : UpdateDependantsState
1610 //=======================================================================
1612 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1614 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1615 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1616 for (; it.More(); it.Next())
1618 const TopoDS_Shape& ancestor = it.Value();
1619 SMESH_subMesh *aSubMesh =
1620 _father->GetSubMeshContaining(ancestor);
1622 aSubMesh->ComputeStateEngine( theEvent );
1626 //=============================================================================
1630 //=============================================================================
1632 void SMESH_subMesh::CleanDependants()
1634 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
1636 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1637 for (; it.More(); it.Next())
1639 const TopoDS_Shape& ancestor = it.Value();
1640 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
1641 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
1642 // will erase mesh on other shapes in a compound
1643 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
1644 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1646 aSubMesh->ComputeStateEngine(CLEAN);
1652 //=============================================================================
1656 //=============================================================================
1658 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1660 //SCRUTE(_subShape.ShapeType());
1662 cleanSubMesh( this );
1664 // algo may bind a submesh not to _subShape, eg 3D algo
1665 // sets nodes on SHELL while _subShape may be SOLID
1667 int dim = SMESH_Gen::GetShapeDim( _subShape );
1668 int type = _subShape.ShapeType() + 1;
1669 for ( ; type <= TopAbs_EDGE; type++) {
1670 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1672 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1673 for ( ; exp.More(); exp.Next() )
1674 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
1681 //=======================================================================
1682 //function : IsMeshComputed
1683 //purpose : check if _subMeshDS contains mesh elements
1684 //=======================================================================
1686 bool SMESH_subMesh::IsMeshComputed() const
1688 // algo may bind a submesh not to _subShape, eg 3D algo
1689 // sets nodes on SHELL while _subShape may be SOLID
1691 int dim = SMESH_Gen::GetShapeDim( _subShape );
1692 int type = _subShape.ShapeType();
1693 for ( ; type <= TopAbs_VERTEX; type++) {
1694 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1696 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1697 for ( ; exp.More(); exp.Next() )
1699 SMESHDS_SubMesh * smDS = _meshDS->MeshElements( exp.Current() );
1700 if ( smDS && ( smDS->NbElements() || smDS->NbNodes()))
1712 //=======================================================================
1713 //function : GetCollection
1714 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1715 // meshed at once along with _subShape
1716 //=======================================================================
1718 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1720 MESSAGE("SMESH_subMesh::GetCollection");
1721 ASSERT (!theAlgo->NeedDescretBoundary());
1723 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1725 if ( mainShape.IsSame( _subShape ))
1728 const bool ignoreAuxiliaryHyps = false;
1729 list<const SMESHDS_Hypothesis*> aUsedHyp =
1730 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
1732 // put in a compound all shapes with the same hypothesis assigned
1733 // and a good ComputState
1735 TopoDS_Compound aCompound;
1736 BRep_Builder aBuilder;
1737 aBuilder.MakeCompound( aCompound );
1739 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1740 for ( ; anExplorer.More(); anExplorer.Next() )
1742 const TopoDS_Shape& S = anExplorer.Current();
1743 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1744 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1746 if (subMesh->GetComputeState() == READY_TO_COMPUTE &&
1747 anAlgo == theAlgo &&
1748 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp)
1750 aBuilder.Add( aCompound, S );
1757 //=======================================================================
1758 //function : GetSimilarAttached
1759 //purpose : return a hypothesis attached to theShape.
1760 // If theHyp is provided, similar but not same hypotheses
1761 // is returned; else only applicable ones having theHypType
1763 //=======================================================================
1765 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1766 const SMESH_Hypothesis * theHyp,
1767 const int theHypType)
1769 SMESH_HypoFilter hypoKind;
1770 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
1772 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
1773 hypoKind.AndNot( hypoKind.Is( theHyp ));
1774 if ( theHyp->IsAuxiliary() )
1775 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
1777 hypoKind.AndNot( hypoKind.IsAuxiliary());
1780 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
1783 return _father->GetHypothesis( theShape, hypoKind, false );
1786 //=======================================================================
1787 //function : CheckConcurentHypothesis
1788 //purpose : check if there are several applicable hypothesis attached to
1790 //=======================================================================
1792 SMESH_Hypothesis::Hypothesis_Status
1793 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1795 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1797 // is there local hypothesis on me?
1798 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1799 return SMESH_Hypothesis::HYP_OK;
1802 TopoDS_Shape aPrevWithHyp;
1803 const SMESH_Hypothesis* aPrevHyp = 0;
1804 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1805 for (; it.More(); it.Next())
1807 const TopoDS_Shape& ancestor = it.Value();
1808 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1811 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1813 aPrevWithHyp = ancestor;
1816 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1817 return SMESH_Hypothesis::HYP_CONCURENT;
1819 return SMESH_Hypothesis::HYP_OK;
1822 return SMESH_Hypothesis::HYP_OK;
1825 //================================================================================
1827 * \brief Sets an event listener and its data to a submesh
1828 * \param listener - the listener to store
1829 * \param data - the listener data to store
1830 * \param where - the submesh to store the listener and it's data
1831 * \param deleteListener - if true then the listener will be deleted as
1832 * it is removed from where submesh
1834 * It remembers the submesh where it puts the listener in order to delete
1835 * them when HYP_OK algo_state is lost
1836 * After being set, event listener is notified on each event of where submesh.
1838 //================================================================================
1840 void SMESH_subMesh::SetEventListener(EventListener* listener,
1841 EventListenerData* data,
1842 SMESH_subMesh* where)
1844 if ( listener && where ) {
1845 where->SetEventListener( listener, data );
1846 myOwnListeners.push_back( make_pair( where, listener ));
1850 //================================================================================
1852 * \brief Sets an event listener and its data to a submesh
1853 * \param listener - the listener to store
1854 * \param data - the listener data to store
1856 * After being set, event listener is notified on each event of a submesh.
1858 //================================================================================
1860 void SMESH_subMesh::SetEventListener(EventListener* listener, EventListenerData* data)
1862 myEventListeners.insert( make_pair( listener, data ));
1865 //================================================================================
1867 * \brief Return an event listener data
1868 * \param listener - the listener whose data is
1869 * \retval EventListenerData* - found data, maybe NULL
1871 //================================================================================
1873 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
1875 map< EventListener*, EventListenerData* >::const_iterator l_d =
1876 myEventListeners.find( listener );
1877 if ( l_d != myEventListeners.end() )
1882 //================================================================================
1884 * \brief Notify stored event listeners on the occured event
1885 * \param event - algo_event or compute_event itself
1886 * \param eventType - algo_event or compute_event
1887 * \param subMesh - the submesh where the event occures
1888 * \param data - listener data stored in the subMesh
1889 * \param hyp - hypothesis, if eventType is algo_event
1891 //================================================================================
1893 void SMESH_subMesh::NotifyListenersOnEvent( const int event,
1894 const event_type eventType,
1895 SMESH_Hypothesis* hyp)
1897 map< EventListener*, EventListenerData* >::iterator l_d = myEventListeners.begin();
1898 for ( ; l_d != myEventListeners.end(); ++l_d )
1899 l_d->first->ProcessEvent( event, eventType, this, l_d->second, hyp );
1902 //================================================================================
1904 * \brief Unregister the listener and delete listener's data
1905 * \param listener - the event listener
1907 //================================================================================
1909 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
1911 map< EventListener*, EventListenerData* >::iterator l_d =
1912 myEventListeners.find( listener );
1913 if ( l_d != myEventListeners.end() ) {
1914 if ( l_d->first->IsDeletable() ) delete l_d->first;
1915 if ( l_d->second->IsDeletable() ) delete l_d->second;
1916 myEventListeners.erase( l_d );
1920 //================================================================================
1922 * \brief Delete event listeners depending on algo of this submesh
1924 //================================================================================
1926 void SMESH_subMesh::DeleteOwnListeners()
1928 list< pair< SMESH_subMesh*, EventListener* > >::iterator sm_l;
1929 for ( sm_l = myOwnListeners.begin(); sm_l != myOwnListeners.end(); ++sm_l)
1930 sm_l->first->DeleteEventListener( sm_l->second );
1931 myOwnListeners.clear();
1934 //================================================================================
1936 * \brief Do something on a certain event
1937 * \param event - algo_event or compute_event itself
1938 * \param eventType - algo_event or compute_event
1939 * \param subMesh - the submesh where the event occures
1940 * \param data - listener data stored in the subMesh
1941 * \param hyp - hypothesis, if eventType is algo_event
1943 * The base implementation translates CLEAN event to the subMesh
1944 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
1945 * successful COMPUTE event.
1947 //================================================================================
1949 void SMESH_subMeshEventListener::ProcessEvent(const int event,
1950 const int eventType,
1951 SMESH_subMesh* subMesh,
1952 EventListenerData* data,
1953 SMESH_Hypothesis* /*hyp*/)
1955 if ( data && !data->mySubMeshes.empty() &&
1956 eventType == SMESH_subMesh::COMPUTE_EVENT)
1958 ASSERT( data->mySubMeshes.front() != subMesh );
1960 case SMESH_subMesh::CLEAN:
1961 data->mySubMeshes.front()->ComputeStateEngine( event );
1963 case SMESH_subMesh::COMPUTE:
1964 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
1965 data->mySubMeshes.front()->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );