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
29 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Algo.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_HypoFilter.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "SMESH_subMeshEventListener.hxx"
38 #include "SMESH_Comment.hxx"
39 #include "SMDS_SetIterator.hxx"
41 #include "utilities.h"
44 #include <BRep_Builder.hxx>
45 #include <BRep_Tool.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TopTools_ListOfShape.hxx>
51 #include <TopTools_MapOfShape.hxx>
53 #include <TopoDS_Compound.hxx>
56 #include <Standard_Failure.hxx>
57 #include <Standard_ErrorHandler.hxx>
61 //=============================================================================
63 * default constructor:
65 //=============================================================================
67 SMESH_subMesh::SMESH_subMesh(int Id,
69 SMESHDS_Mesh * meshDS,
70 const TopoDS_Shape & aSubShape)
72 _subShape = aSubShape;
73 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
76 _dependenceAnalysed = _alwaysComputed = false;
78 if (_subShape.ShapeType() == TopAbs_VERTEX)
81 _computeState = READY_TO_COMPUTE;
86 _computeState = NOT_READY;
90 //=============================================================================
94 //=============================================================================
96 SMESH_subMesh::~SMESH_subMesh()
98 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
100 DeleteOwnListeners();
103 //=============================================================================
107 //=============================================================================
109 int SMESH_subMesh::GetId() const
111 //MESSAGE("SMESH_subMesh::GetId");
115 //=============================================================================
119 //=============================================================================
121 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
123 // submesh appears in DS only when a mesher set nodes and elements on a shape
124 return _subMeshDS ? _subMeshDS : _subMeshDS = _father->GetMeshDS()->MeshElements(_subShape); // may be null
127 //=============================================================================
131 //=============================================================================
133 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
135 if ( !GetSubMeshDS() ) {
136 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
137 meshDS->NewSubMesh( meshDS->ShapeToIndex( _subShape ) );
139 return GetSubMeshDS();
142 //=============================================================================
146 //=============================================================================
148 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
150 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(true,false);
151 while ( smIt->more() ) {
152 SMESH_subMesh *sm = smIt->next();
153 if ( sm->GetComputeState() == READY_TO_COMPUTE )
156 return 0; // nothing to compute
159 //================================================================================
161 * \brief Allow algo->Compute() if a subshape of lower dim is meshed but
162 * none mesh entity is bound to it (PAL13615, 2nd part)
164 //================================================================================
166 void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
168 _alwaysComputed = isAlCo;
169 if ( _alwaysComputed )
170 _computeState = COMPUTE_OK;
172 ComputeStateEngine( CHECK_COMPUTE_STATE );
175 //=======================================================================
176 //function : IsMeshComputed
177 //purpose : check if _subMeshDS contains mesh elements
178 //=======================================================================
180 bool SMESH_subMesh::IsMeshComputed() const
182 if ( _alwaysComputed )
184 // algo may bind a submesh not to _subShape, eg 3D algo
185 // sets nodes on SHELL while _subShape may be SOLID
187 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
188 int dim = SMESH_Gen::GetShapeDim( _subShape );
189 int type = _subShape.ShapeType();
190 for ( ; type <= TopAbs_VERTEX; type++) {
191 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
193 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
194 for ( ; exp.More(); exp.Next() )
196 if ( SMESHDS_SubMesh * smDS = meshDS->MeshElements( exp.Current() ))
198 bool computed = (dim > 0) ? smDS->NbElements() : smDS->NbNodes();
211 //=============================================================================
215 //=============================================================================
217 bool SMESH_subMesh::SubMeshesComputed()
219 int myDim = SMESH_Gen::GetShapeDim( _subShape );
220 int dimToCheck = myDim - 1;
221 bool subMeshesComputed = true;
222 // check subMeshes with upper dimension => reverse iteration
223 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
224 while ( smIt->more() )
226 SMESH_subMesh *sm = smIt->next();
227 if ( sm->_alwaysComputed )
229 const TopoDS_Shape & ss = sm->GetSubShape();
230 // MSV 07.04.2006: restrict checking to myDim-1 only. Ex., there is no sense
231 // in checking of existence of edges if the algo needs only faces. Moreover,
232 // degenerated edges may have no submesh, as after computing NETGEN_2D.
233 int dim = SMESH_Gen::GetShapeDim( ss );
234 if (dim < dimToCheck)
235 break; // the rest subMeshes are all of less dimension
236 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
237 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
238 (ds && ( ds->NbNodes() || ds->NbElements() )));
241 int type = ss.ShapeType();
243 subMeshesComputed = false;
247 case TopAbs_COMPOUND:
249 MESSAGE("The not computed sub mesh is a COMPOUND");
252 case TopAbs_COMPSOLID:
254 MESSAGE("The not computed sub mesh is a COMPSOLID");
259 MESSAGE("The not computed sub mesh is a SHEL");
264 MESSAGE("The not computed sub mesh is a WIRE");
269 MESSAGE("The not computed sub mesh is a SOLID");
274 MESSAGE("The not computed sub mesh is a FACE");
279 MESSAGE("The not computed sub mesh is a EDGE");
284 MESSAGE("The not computed sub mesh is of unknown type");
292 return subMeshesComputed;
295 //=============================================================================
299 //=============================================================================
301 bool SMESH_subMesh::SubMeshesReady()
303 bool subMeshesReady = true;
304 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
305 while ( smIt->more() ) {
306 SMESH_subMesh *sm = smIt->next();
307 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
308 sm->GetComputeState() == READY_TO_COMPUTE);
311 subMeshesReady = false;
316 return subMeshesReady;
319 //=============================================================================
321 * Construct dependence on first level subMeshes. complex shapes (compsolid,
322 * shell, wire) are not analysed the same way as simple shapes (solid, face,
324 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
325 * with possible multiples occurences. Multiples occurences corresponds to
326 * internal frontiers within shapes of the collection and must not be keeped.
327 * See FinalizeDependence.
329 //=============================================================================
331 const map < int, SMESH_subMesh * >& SMESH_subMesh::DependsOn()
333 if (_dependenceAnalysed)
336 //MESSAGE("SMESH_subMesh::DependsOn");
338 int type = _subShape.ShapeType();
342 case TopAbs_COMPOUND:
344 //MESSAGE("compound");
345 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
348 InsertDependence(exp.Current());
350 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More();
353 InsertDependence(exp.Current()); //only shell not in solid
355 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();
358 InsertDependence(exp.Current());
360 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();
363 InsertDependence(exp.Current());
367 case TopAbs_COMPSOLID:
369 //MESSAGE("compsolid");
370 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
373 InsertDependence(exp.Current());
380 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
383 InsertDependence(exp.Current());
390 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
393 InsertDependence(exp.Current());
400 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
403 InsertDependence(exp.Current());
410 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
413 InsertDependence(exp.Current());
420 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More();
423 InsertDependence(exp.Current());
436 _dependenceAnalysed = true;
440 //=============================================================================
442 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
444 //=============================================================================
446 void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape)
448 //MESSAGE("SMESH_subMesh::InsertDependence");
449 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
450 int type = aSubShape.ShapeType();
451 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
452 int cle = aSubMesh->GetId();
453 cle += 10000000 * ordType; // sort map by ordType then index
454 if ( _mapDepend.find( cle ) == _mapDepend.end())
456 _mapDepend[cle] = aSubMesh;
457 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
458 _mapDepend.insert( subMap.begin(), subMap.end() );
462 //=============================================================================
466 //=============================================================================
468 const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
470 //MESSAGE("SMESH_subMesh::GetSubShape");
475 //=======================================================================
476 //function : CanAddHypothesis
477 //purpose : return true if theHypothesis can be attached to me:
478 // its dimention is checked
479 //=======================================================================
481 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
483 int aHypDim = theHypothesis->GetDim();
484 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
485 if ( aHypDim <= aShapeDim )
487 // if ( aHypDim < aShapeDim )
488 // return ( _father->IsMainShape( _subShape ));
493 //=======================================================================
494 //function : IsApplicableHypotesis
496 //=======================================================================
498 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
499 const TopAbs_ShapeEnum theShapeType)
501 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
503 return ( theHypothesis->GetShapeType() & (1<< theShapeType));
506 switch ( theShapeType ) {
511 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
514 // Special case for algorithms, building 2D mesh on a whole shell.
515 // Before this fix there was a problem after restoring from study,
516 // because in that case algorithm is assigned before hypothesis
517 // (on shell in problem case) and hypothesis is checked on faces
518 // (because it is 2D), where we have NO_ALGO state.
519 // Now 2D hypothesis is also applicable to shells.
520 return (theHypothesis->GetDim() == 2 || theHypothesis->GetDim() == 3);
523 // case TopAbs_COMPSOLID:
524 // case TopAbs_COMPOUND:
530 //=============================================================================
534 //=============================================================================
536 SMESH_Hypothesis::Hypothesis_Status
537 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
539 // MESSAGE("SMESH_subMesh::AlgoStateEngine");
540 //SCRUTE(_algoState);
543 // **** les retour des evenement shape sont significatifs
544 // (add ou remove fait ou non)
545 // le retour des evenement father n'indiquent pas que add ou remove fait
547 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
549 SMESHDS_Mesh* meshDS =_father->GetMeshDS();
550 SMESH_Gen* gen =_father->GetGen();
551 SMESH_Algo* algo = 0;
553 if (_subShape.ShapeType() == TopAbs_VERTEX )
555 if ( anHyp->GetDim() != 0) {
556 if (event == ADD_HYP || event == ADD_ALGO)
557 return SMESH_Hypothesis::HYP_BAD_DIM;
559 return SMESH_Hypothesis::HYP_OK;
562 else if ( _algoState == HYP_OK ) { // update default _algoState
563 _algoState = NO_ALGO;
564 algo = gen->GetAlgo(*_father, _subShape);
566 _algoState = MISSING_HYP;
567 if ( algo->CheckHypothesis(*_father,_subShape, aux_ret))
573 int oldAlgoState = _algoState;
574 bool modifiedHyp = (event == MODIF_HYP); // if set to true, force event MODIF_ALGO_STATE
576 bool isApplicableHyp = IsApplicableHypotesis( anHyp );
578 if (event == ADD_ALGO || event == ADD_FATHER_ALGO)
580 // -------------------------------------------
581 // check if a shape needed by algo is present
582 // -------------------------------------------
583 algo = static_cast< SMESH_Algo* >( anHyp );
584 if ( !_father->HasShapeToMesh() && algo->NeedShape() )
585 return SMESH_Hypothesis::HYP_BAD_GEOMETRY;
586 // ----------------------
587 // check mesh conformity
588 // ----------------------
589 if (isApplicableHyp && !_father->IsNotConformAllowed() && !IsConform( algo ))
590 return SMESH_Hypothesis::HYP_NOTCONFORM;
593 // ----------------------------------
594 // add a hypothesis to DS if possible
595 // ----------------------------------
596 if (event == ADD_HYP || event == ADD_ALGO)
598 if ( ! CanAddHypothesis( anHyp )) // check dimension
599 return SMESH_Hypothesis::HYP_BAD_DIM;
601 if ( /*!anHyp->IsAuxiliary() &&*/ GetSimilarAttached( _subShape, anHyp ) )
602 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
604 if ( !meshDS->AddHypothesis(_subShape, anHyp))
605 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
607 // Serve Propagation of 1D hypothesis
608 // NOTE: it is possible to re-implement Propagation using EventListener
609 if (event == ADD_HYP) {
610 bool isPropagationOk = true;
611 bool isPropagationHyp = ( strcmp( "Propagation", anHyp->GetName() ) == 0 );
613 if ( isPropagationHyp ) {
614 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
615 TopTools_MapOfShape aMap;
616 for (; exp.More(); exp.Next()) {
617 if (aMap.Add(exp.Current())) {
618 if (!_father->BuildPropagationChain(exp.Current())) {
619 isPropagationOk = false;
624 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
625 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
626 TopTools_MapOfShape aMap;
627 for (; exp.More(); exp.Next()) {
628 if (aMap.Add(exp.Current())) {
629 TopoDS_Shape aMainEdge;
630 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
631 isPropagationOk = _father->RebuildPropagationChains();
632 } else if (_father->IsPropagationHypothesis(exp.Current())) {
633 isPropagationOk = _father->BuildPropagationChain(exp.Current());
641 if ( isPropagationOk ) {
642 if ( isPropagationHyp )
643 return ret; // nothing more to do for "Propagation" hypothesis
645 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
646 ret = SMESH_Hypothesis::HYP_CONCURENT;
648 } // Serve Propagation of 1D hypothesis
651 // --------------------------
652 // remove a hypothesis from DS
653 // --------------------------
654 if (event == REMOVE_HYP || event == REMOVE_ALGO)
656 if (!meshDS->RemoveHypothesis(_subShape, anHyp))
657 return SMESH_Hypothesis::HYP_OK; // nothing changes
659 // Serve Propagation of 1D hypothesis
660 // NOTE: it is possible to re-implement Propagation using EventListener
661 if (event == REMOVE_HYP)
663 bool isPropagationOk = true;
664 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
665 bool isPropagationHyp = propagFilter.IsOk( anHyp, _subShape );
667 if ( isPropagationHyp )
669 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
670 TopTools_MapOfShape aMap;
671 for (; exp.More(); exp.Next()) {
672 if (aMap.Add(exp.Current()) &&
673 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
674 // no more Propagation on the current edge
675 if (!_father->RemovePropagationChain(exp.Current())) {
676 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
680 // rebuild propagation chains, because removing one
681 // chain can resolve concurention, existing before
682 isPropagationOk = _father->RebuildPropagationChains();
684 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
686 isPropagationOk = _father->RebuildPropagationChains();
689 if ( isPropagationOk ) {
690 if ( isPropagationHyp )
691 return ret; // nothing more to do for "Propagation" hypothesis
693 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
694 ret = SMESH_Hypothesis::HYP_CONCURENT;
696 } // Serve Propagation of 1D hypothesis
697 else // event == REMOVE_ALGO
699 algo = dynamic_cast<SMESH_Algo*> (anHyp);
700 if (!algo->NeedDescretBoundary())
702 // clean all mesh in the tree of the current submesh;
703 // we must perform it now because later
704 // we will have no information about the type of the removed algo
706 ComputeStateEngine( CLEAN );
712 // ------------------
713 // analyse algo state
714 // ------------------
715 if (!isApplicableHyp)
716 return ret; // not applicable hypotheses do not change algo state
721 // ----------------------------------------------------------------------
728 algo = gen->GetAlgo((*_father), _subShape);
730 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
731 SetAlgoState(HYP_OK);
732 else if ( algo->IsStatusFatal( aux_ret )) {
733 meshDS->RemoveHypothesis(_subShape, anHyp);
737 SetAlgoState(MISSING_HYP);
744 case ADD_FATHER_ALGO: { // Algo just added in father
745 algo = gen->GetAlgo((*_father), _subShape);
747 if ( algo == anHyp ) {
748 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
749 SetAlgoState(HYP_OK);
751 SetAlgoState(MISSING_HYP);
755 case REMOVE_FATHER_HYP:
757 case REMOVE_FATHER_ALGO: {
758 algo = gen->GetAlgo((*_father), _subShape);
761 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
762 SetAlgoState(HYP_OK);
764 SetAlgoState(MISSING_HYP);
768 case MODIF_HYP: break;
775 // ----------------------------------------------------------------------
781 algo = gen->GetAlgo((*_father), _subShape);
783 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
784 SetAlgoState(HYP_OK);
785 if (SMESH_Hypothesis::IsStatusFatal( ret ))
786 meshDS->RemoveHypothesis(_subShape, anHyp);
787 else if (!_father->IsUsedHypothesis( anHyp, this ))
789 meshDS->RemoveHypothesis(_subShape, anHyp);
790 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
794 case ADD_ALGO: { //already existing algo : on father ?
795 algo = gen->GetAlgo((*_father), _subShape);
797 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
798 SetAlgoState(HYP_OK);
799 else if ( algo->IsStatusFatal( aux_ret )) {
800 meshDS->RemoveHypothesis(_subShape, anHyp);
804 SetAlgoState(MISSING_HYP);
809 case REMOVE_ALGO: { // perhaps a father algo applies ?
810 algo = gen->GetAlgo((*_father), _subShape);
811 if (algo == NULL) // no more algo applying on subShape...
813 SetAlgoState(NO_ALGO);
817 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
818 SetAlgoState(HYP_OK);
820 SetAlgoState(MISSING_HYP);
824 case MODIF_HYP: // assigned hypothesis value may become good
825 case ADD_FATHER_HYP: {
826 algo = gen->GetAlgo((*_father), _subShape);
828 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
829 SetAlgoState(HYP_OK);
831 SetAlgoState(MISSING_HYP);
834 case ADD_FATHER_ALGO: { // new father algo
835 algo = gen->GetAlgo((*_father), _subShape);
837 if ( algo == anHyp ) {
838 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
839 SetAlgoState(HYP_OK);
841 SetAlgoState(MISSING_HYP);
845 case REMOVE_FATHER_HYP: // nothing to do
847 case REMOVE_FATHER_ALGO: {
848 algo = gen->GetAlgo((*_father), _subShape);
849 if (algo == NULL) // no more applying algo on father
851 SetAlgoState(NO_ALGO);
855 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
856 SetAlgoState(HYP_OK);
858 SetAlgoState(MISSING_HYP);
868 // ----------------------------------------------------------------------
874 algo = gen->GetAlgo((*_father), _subShape);
876 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
878 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
879 // ret should be fatal: anHyp was not added
880 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
882 else if (!_father->IsUsedHypothesis( anHyp, this ))
883 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
885 if (SMESH_Hypothesis::IsStatusFatal( ret ))
887 MESSAGE("do not add extra hypothesis");
888 meshDS->RemoveHypothesis(_subShape, anHyp);
896 case ADD_ALGO: { //already existing algo : on father ?
897 algo = gen->GetAlgo((*_father), _subShape);
898 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
899 // check if algo changes
901 f.Init( SMESH_HypoFilter::IsAlgo() );
902 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
903 f.AndNot( SMESH_HypoFilter::Is( algo ));
904 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
906 string(algo->GetName()) != string(prevAlgo->GetName()) )
910 SetAlgoState(MISSING_HYP);
914 algo = gen->GetAlgo((*_father), _subShape);
916 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
917 SetAlgoState(HYP_OK);
919 SetAlgoState(MISSING_HYP);
923 case REMOVE_ALGO: { // perhaps a father algo applies ?
924 algo = gen->GetAlgo((*_father), _subShape);
925 if (algo == NULL) // no more algo applying on subShape...
927 SetAlgoState(NO_ALGO);
931 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
932 // check if algo remains
933 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
937 SetAlgoState(MISSING_HYP);
941 case MODIF_HYP: // hypothesis value may become bad
942 case ADD_FATHER_HYP: { // new father hypothesis ?
943 algo = gen->GetAlgo((*_father), _subShape);
945 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
947 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
951 SetAlgoState(MISSING_HYP);
954 case ADD_FATHER_ALGO: {
955 algo = gen->GetAlgo((*_father), _subShape);
956 if ( algo == anHyp ) { // a new algo on father
957 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
958 // check if algo changes
960 f.Init( SMESH_HypoFilter::IsAlgo() );
961 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
962 f.AndNot( SMESH_HypoFilter::Is( algo ));
963 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
965 string(algo->GetName()) != string(prevAlgo->GetName()) )
969 SetAlgoState(MISSING_HYP);
973 case REMOVE_FATHER_HYP: {
974 algo = gen->GetAlgo((*_father), _subShape);
976 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
977 // is there the same local hyp or maybe a new father algo applied?
978 if ( !GetSimilarAttached( _subShape, anHyp ) )
982 SetAlgoState(MISSING_HYP);
985 case REMOVE_FATHER_ALGO: {
986 algo = gen->GetAlgo((*_father), _subShape);
987 if (algo == NULL) // no more applying algo on father
989 SetAlgoState(NO_ALGO);
993 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
994 // check if algo changes
995 if ( string(algo->GetName()) != string( anHyp->GetName()) )
999 SetAlgoState(MISSING_HYP);
1009 // ----------------------------------------------------------------------
1016 // detect algorithm hiding
1018 if ( ret == SMESH_Hypothesis::HYP_OK &&
1019 ( event == ADD_ALGO || event == ADD_FATHER_ALGO ) &&
1020 algo->GetName() == anHyp->GetName() )
1023 SMESH_Gen* gen = _father->GetGen();
1024 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1025 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && it.More()); it.Next() ) {
1026 if ( SMESH_Algo* upperAlgo = gen->GetAlgo( *_father, it.Value() ))
1027 if ( !upperAlgo->NeedDescretBoundary() )
1028 ret = SMESH_Hypothesis::HYP_HIDDEN_ALGO;
1031 if ( ret == SMESH_Hypothesis::HYP_OK && !algo->NeedDescretBoundary() ) {
1032 map<int, SMESH_subMesh*>::reverse_iterator i_sm = _mapDepend.rbegin();
1033 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && i_sm != _mapDepend.rend()) ; ++i_sm )
1034 if ( gen->GetAlgo( *_father, i_sm->second->_subShape ))
1035 ret = SMESH_Hypothesis::HYP_HIDING_ALGO;
1039 bool stateChange = ( _algoState != oldAlgoState );
1041 if ( stateChange && _algoState == HYP_OK ) // hyp becomes OK
1042 algo->SetEventListener( this );
1044 NotifyListenersOnEvent( event, ALGO_EVENT, anHyp );
1046 if ( stateChange && oldAlgoState == HYP_OK ) { // hyp becomes KO
1047 DeleteOwnListeners();
1048 if (_subShape.ShapeType() == TopAbs_VERTEX ) {
1049 // restore default states
1050 _algoState = HYP_OK;
1051 _computeState = READY_TO_COMPUTE;
1055 if (stateChange || modifiedHyp)
1056 ComputeStateEngine(MODIF_ALGO_STATE);
1061 //=======================================================================
1062 //function : IsConform
1063 //purpose : check if a conform mesh will be produced by the Algo
1064 //=======================================================================
1066 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
1068 // MESSAGE( "SMESH_subMesh::IsConform" );
1069 if ( !theAlgo ) return false;
1071 // Suppose that theAlgo is applicable to _subShape, do not check it here
1072 //if ( !IsApplicableHypotesis( theAlgo )) return false;
1074 // check only algo that doesn't NeedDescretBoundary(): because mesh made
1075 // on a sub-shape will be ignored by theAlgo
1076 if ( theAlgo->NeedDescretBoundary() ||
1077 !theAlgo->OnlyUnaryInput() ) // all adjacent shapes will be meshed by this algo?
1080 SMESH_Gen* gen =_father->GetGen();
1082 // only local algo is to be checked
1083 //if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1084 if ( _subShape.ShapeType() == _father->GetMeshDS()->ShapeToMesh().ShapeType() )
1087 // check algo attached to adjacent shapes
1089 // loop on one level down sub-meshes
1090 TopoDS_Iterator itsub( _subShape );
1091 for (; itsub.More(); itsub.Next())
1093 // loop on adjacent subShapes
1094 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1095 for (; it.More(); it.Next())
1097 const TopoDS_Shape& adjacent = it.Value();
1098 if ( _subShape.IsSame( adjacent )) continue;
1099 if ( adjacent.ShapeType() != _subShape.ShapeType())
1102 // check algo attached to smAdjacent
1103 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1105 !algo->NeedDescretBoundary() &&
1106 algo->OnlyUnaryInput())
1107 return false; // NOT CONFORM MESH WILL BE PRODUCED
1114 //=============================================================================
1118 //=============================================================================
1120 void SMESH_subMesh::SetAlgoState(int state)
1125 //=============================================================================
1129 //=============================================================================
1130 SMESH_Hypothesis::Hypothesis_Status
1131 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1132 SMESH_Hypothesis * anHyp)
1134 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1135 //EAP: a wire (dim==1) should notify edges (dim==1)
1136 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1137 if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1139 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1140 while ( smIt->more() ) {
1141 SMESH_Hypothesis::Hypothesis_Status ret2 =
1142 smIt->next()->AlgoStateEngine(event, anHyp);
1150 //=============================================================================
1154 //=============================================================================
1156 void SMESH_subMesh::CleanDependsOn()
1158 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1159 while ( smIt->more() )
1160 smIt->next()->ComputeStateEngine(CLEAN);
1163 //=============================================================================
1167 //=============================================================================
1169 void SMESH_subMesh::DumpAlgoState(bool isMain)
1171 int dim = SMESH_Gen::GetShapeDim(_subShape);
1172 // if (dim < 1) return;
1175 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1177 map < int, SMESH_subMesh * >::const_iterator itsub;
1178 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1180 SMESH_subMesh *sm = (*itsub).second;
1181 sm->DumpAlgoState(false);
1184 int type = _subShape.ShapeType();
1185 MESSAGE("dim = " << dim << " type of shape " << type);
1189 MESSAGE(" AlgoState = NO_ALGO");
1192 MESSAGE(" AlgoState = MISSING_HYP");
1195 MESSAGE(" AlgoState = HYP_OK");
1198 switch (_computeState)
1201 MESSAGE(" ComputeState = NOT_READY");
1203 case READY_TO_COMPUTE:
1204 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1207 MESSAGE(" ComputeState = COMPUTE_OK");
1209 case FAILED_TO_COMPUTE:
1210 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1215 //================================================================================
1217 * \brief Remove nodes and elements bound to submesh
1218 * \param subMesh - submesh containing nodes and elements
1220 //================================================================================
1222 static void cleanSubMesh( SMESH_subMesh * subMesh )
1225 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1226 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1227 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1228 while (ite->more()) {
1229 const SMDS_MeshElement * elt = ite->next();
1230 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1231 //meshDS->RemoveElement(elt);
1232 meshDS->RemoveFreeElement(elt, subMeshDS);
1235 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1236 while (itn->more()) {
1237 const SMDS_MeshNode * node = itn->next();
1238 //MESSAGE( " RM node: "<<node->GetID());
1239 if ( node->NbInverseNodes() == 0 )
1240 meshDS->RemoveFreeNode(node, subMeshDS);
1241 else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another
1242 meshDS->RemoveNode(node);
1248 //=============================================================================
1252 //=============================================================================
1254 bool SMESH_subMesh::ComputeStateEngine(int event)
1256 _computeError.reset();
1258 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1259 //SCRUTE(_computeState);
1262 if (_subShape.ShapeType() == TopAbs_VERTEX)
1264 _computeState = READY_TO_COMPUTE;
1265 SMESHDS_SubMesh* smDS = GetSubMeshDS();
1266 if ( smDS && smDS->NbNodes() ) {
1267 _computeState = COMPUTE_OK;
1269 else if ( event == COMPUTE && !_alwaysComputed ) {
1270 const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
1271 gp_Pnt P = BRep_Tool::Pnt(V);
1272 if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
1273 _father->GetMeshDS()->SetNodeOnVertex(n,_Id);
1274 _computeState = COMPUTE_OK;
1277 if ( event == MODIF_ALGO_STATE )
1281 SMESH_Gen *gen = _father->GetGen();
1282 SMESH_Algo *algo = 0;
1284 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1285 //algo_state oldAlgoState = (algo_state) GetAlgoState();
1287 switch (_computeState)
1290 // ----------------------------------------------------------------------
1295 case MODIF_ALGO_STATE:
1296 algo = gen->GetAlgo((*_father), _subShape);
1297 if (algo && !algo->NeedDescretBoundary())
1298 CleanDependsOn(); // clean sub-meshes with event CLEAN
1299 if ( _algoState == HYP_OK )
1300 _computeState = READY_TO_COMPUTE;
1302 case COMPUTE: // nothing to do
1306 RemoveSubMeshElementsAndNodes();
1308 case SUBMESH_COMPUTED: // nothing to do
1310 case SUBMESH_RESTORED:
1311 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1313 case MESH_ENTITY_REMOVED:
1315 case CHECK_COMPUTE_STATE:
1316 if ( IsMeshComputed() )
1317 _computeState = COMPUTE_OK;
1325 // ----------------------------------------------------------------------
1327 case READY_TO_COMPUTE:
1330 case MODIF_ALGO_STATE:
1331 _computeState = NOT_READY;
1332 algo = gen->GetAlgo((*_father), _subShape);
1335 if (!algo->NeedDescretBoundary())
1336 CleanDependsOn(); // clean sub-meshes with event CLEAN
1337 if ( _algoState == HYP_OK )
1338 _computeState = READY_TO_COMPUTE;
1343 algo = gen->GetAlgo((*_father), _subShape);
1345 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1348 MESSAGE("***** verify compute state *****");
1349 _computeState = NOT_READY;
1350 SetAlgoState(MISSING_HYP);
1353 // check submeshes needed
1354 if (_father->HasShapeToMesh() ) {
1355 bool subComputed = SubMeshesComputed();
1356 ret = ( algo->NeedDescretBoundary() ? subComputed :
1357 ( !subComputed || _father->IsNotConformAllowed() ));
1359 _computeState = FAILED_TO_COMPUTE;
1360 if ( !algo->NeedDescretBoundary() )
1362 SMESH_ComputeError::New(COMPERR_BAD_INPUT_MESH,"Unexpected submesh",algo);
1368 RemoveSubMeshElementsAndNodes();
1370 _computeState = FAILED_TO_COMPUTE;
1371 _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
1373 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1376 algo->InitComputeError();
1377 if ( !_father->HasShapeToMesh() ) // no shape
1379 SMESH_MesherHelper helper( *_father );
1380 helper.SetSubShape( _subShape );
1381 helper.SetElementsOnShape( true );
1382 ret = algo->Compute(*_father, &helper );
1386 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput()) {
1387 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1391 ret = algo->Compute((*_father), _subShape);
1395 _computeError = algo->GetComputeError();
1397 catch (Standard_Failure& exc) {
1398 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1399 _computeError->myName = COMPERR_OCC_EXCEPTION;
1400 _computeError->myComment = exc.GetMessageString();
1402 catch ( SALOME_Exception& S_ex ) {
1403 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1404 _computeError->myName = COMPERR_SLM_EXCEPTION;
1405 _computeError->myComment = S_ex.what();
1407 catch ( std::bad_alloc& exc ) {
1408 if ( _computeError ) {
1409 _computeError->myName = COMPERR_MEMORY_PB;
1410 _computeError->myComment = exc.what();
1414 catch ( std::exception& exc ) {
1415 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1416 _computeError->myName = COMPERR_STD_EXCEPTION;
1417 _computeError->myComment = exc.what();
1420 if ( _computeError )
1421 _computeError->myName = COMPERR_EXCEPTION;
1425 if ( ret && _computeError && !_computeError->IsOK() ) {
1428 if (ret) { // check if anything was built
1429 ret = ( GetSubMeshDS() && ( GetSubMeshDS()->NbElements() || GetSubMeshDS()->NbNodes() ));
1433 // Set _computeError
1434 if ( !_computeError )
1435 _computeError = SMESH_ComputeError::New();
1436 if ( _computeError->IsOK() )
1437 _computeError->myName = COMPERR_ALGO_FAILED;
1441 _computeError.reset();
1442 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1444 if ( !algo->NeedDescretBoundary() )
1445 UpdateSubMeshState( ret ? COMPUTE_OK : FAILED_TO_COMPUTE );
1446 CheckComputeError( algo );
1451 RemoveSubMeshElementsAndNodes();
1452 _computeState = NOT_READY;
1453 algo = gen->GetAlgo((*_father), _subShape);
1456 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1458 _computeState = READY_TO_COMPUTE;
1460 SetAlgoState(MISSING_HYP);
1463 case SUBMESH_COMPUTED: // nothing to do
1465 case SUBMESH_RESTORED:
1466 // check if a mesh is already computed that may
1467 // happen after retrieval from a file
1468 ComputeStateEngine( CHECK_COMPUTE_STATE );
1469 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1470 algo = gen->GetAlgo(*_father, _subShape);
1471 if (algo) algo->SubmeshRestored( this );
1473 case MESH_ENTITY_REMOVED:
1475 case CHECK_COMPUTE_STATE:
1476 if ( IsMeshComputed() )
1477 _computeState = COMPUTE_OK;
1485 // ----------------------------------------------------------------------
1490 case MODIF_ALGO_STATE:
1491 ComputeStateEngine( CLEAN );
1492 algo = gen->GetAlgo((*_father), _subShape);
1493 if (algo && !algo->NeedDescretBoundary())
1494 CleanDependsOn(); // clean sub-meshes with event CLEAN
1496 case COMPUTE: // nothing to do
1499 CleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1500 RemoveSubMeshElementsAndNodes();
1501 _computeState = NOT_READY;
1502 if ( _algoState == HYP_OK )
1503 _computeState = READY_TO_COMPUTE;
1505 case SUBMESH_COMPUTED: // nothing to do
1507 case SUBMESH_RESTORED:
1508 ComputeStateEngine( CHECK_COMPUTE_STATE );
1509 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1510 algo = gen->GetAlgo(*_father, _subShape);
1511 if (algo) algo->SubmeshRestored( this );
1513 case MESH_ENTITY_REMOVED:
1514 UpdateDependantsState( CHECK_COMPUTE_STATE );
1515 ComputeStateEngine( CHECK_COMPUTE_STATE );
1516 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1518 case CHECK_COMPUTE_STATE:
1519 if ( !IsMeshComputed() )
1520 if (_algoState == HYP_OK)
1521 _computeState = READY_TO_COMPUTE;
1523 _computeState = NOT_READY;
1531 // ----------------------------------------------------------------------
1533 case FAILED_TO_COMPUTE:
1536 case MODIF_ALGO_STATE:
1537 if (_algoState == HYP_OK)
1538 _computeState = READY_TO_COMPUTE;
1540 _computeState = NOT_READY;
1542 case COMPUTE: // nothing to do
1545 CleanDependants(); // submeshes dependent on me should be cleaned as well
1546 RemoveSubMeshElementsAndNodes();
1548 case SUBMESH_COMPUTED: // allow retry compute
1549 if (_algoState == HYP_OK)
1550 _computeState = READY_TO_COMPUTE;
1552 _computeState = NOT_READY;
1554 case SUBMESH_RESTORED:
1555 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1557 case MESH_ENTITY_REMOVED:
1559 case CHECK_COMPUTE_STATE:
1560 if ( IsMeshComputed() )
1561 _computeState = COMPUTE_OK;
1563 if (_algoState == HYP_OK)
1564 _computeState = READY_TO_COMPUTE;
1566 _computeState = NOT_READY;
1574 // ----------------------------------------------------------------------
1580 NotifyListenersOnEvent( event, COMPUTE_EVENT );
1585 //=======================================================================
1587 * \brief Update compute_state by _computeError
1589 //=======================================================================
1591 bool SMESH_subMesh::CheckComputeError(SMESH_Algo* theAlgo)
1593 bool noErrors = ( !_computeError || _computeError->IsOK() );
1596 if ( !_computeError->myAlgo )
1597 _computeError->myAlgo = theAlgo;
1601 text << theAlgo->GetName() << " failed on subshape " << _Id << " with error ";
1602 if (_computeError->IsCommon() )
1603 text << _computeError->CommonName();
1605 text << _computeError->myName;
1606 if ( _computeError->myComment.size() > 0 )
1607 text << " \"" << _computeError->myComment << "\"";
1610 cout << text << endl;
1611 // Show vertices location of a failed shape
1612 cout << "Subshape vertices (first 10):" << endl;
1613 TopTools_IndexedMapOfShape vMap;
1614 TopExp::MapShapes( _subShape, TopAbs_VERTEX, vMap );
1615 for ( int iv = 1; iv <= vMap.Extent() && iv < 11; ++iv ) {
1616 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( vMap( iv ) )));
1617 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1622 _computeState = FAILED_TO_COMPUTE;
1626 _computeState = COMPUTE_OK;
1628 // Check state of submeshes
1629 if ( !theAlgo->NeedDescretBoundary() /*&& theAlgo->OnlyUnaryInput()*/ ) {
1630 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1631 while ( smIt->more() )
1632 if ( !smIt->next()->CheckComputeError( theAlgo ))
1638 //=======================================================================
1639 //function : ApplyToCollection
1640 //purpose : Apply theAlgo to all subshapes in theCollection
1641 //=======================================================================
1643 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1644 const TopoDS_Shape& theCollection)
1646 MESSAGE("SMESH_subMesh::ApplyToCollection");
1647 ASSERT ( !theAlgo->NeedDescretBoundary() );
1649 if ( _computeError )
1650 _computeError->myName = COMPERR_OK;
1652 bool ok = theAlgo->Compute( *_father, theCollection );
1654 // set _computeState of subshapes
1655 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1656 for ( ; anExplorer.More(); anExplorer.Next() )
1658 if ( SMESH_subMesh* subMesh = _father->GetSubMeshContaining( anExplorer.Current() ))
1660 bool localOK = subMesh->CheckComputeError( theAlgo );
1661 if ( !ok && localOK && !subMesh->IsMeshComputed() )
1663 subMesh->_computeError = theAlgo->GetComputeError();
1664 if ( subMesh->_computeError->IsOK() )
1665 _computeError = SMESH_ComputeError::New(COMPERR_ALGO_FAILED);
1666 localOK = CheckComputeError( theAlgo );
1669 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1670 subMesh->UpdateSubMeshState( localOK ? COMPUTE_OK : FAILED_TO_COMPUTE );
1678 //=======================================================================
1679 //function : UpdateSubMeshState
1681 //=======================================================================
1683 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1685 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1686 while ( smIt->more() )
1687 smIt->next()->_computeState = theState;
1690 //=======================================================================
1691 //function : ComputeSubMeshStateEngine
1693 //=======================================================================
1695 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1697 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1698 while ( smIt->more() )
1699 smIt->next()->ComputeStateEngine(event);
1702 //=======================================================================
1703 //function : UpdateDependantsState
1705 //=======================================================================
1707 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1709 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1710 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1711 for (; it.More(); it.Next())
1713 const TopoDS_Shape& ancestor = it.Value();
1714 SMESH_subMesh *aSubMesh =
1715 _father->GetSubMeshContaining(ancestor);
1717 aSubMesh->ComputeStateEngine( theEvent );
1721 //=============================================================================
1725 //=============================================================================
1727 void SMESH_subMesh::CleanDependants()
1729 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
1731 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1732 for (; it.More(); it.Next())
1734 const TopoDS_Shape& ancestor = it.Value();
1735 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
1736 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
1737 // will erase mesh on other shapes in a compound
1738 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
1739 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1741 aSubMesh->ComputeStateEngine(CLEAN);
1747 //=============================================================================
1751 //=============================================================================
1753 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1755 //SCRUTE(_subShape.ShapeType());
1757 cleanSubMesh( this );
1759 // algo may bind a submesh not to _subShape, eg 3D algo
1760 // sets nodes on SHELL while _subShape may be SOLID
1762 int dim = SMESH_Gen::GetShapeDim( _subShape );
1763 int type = _subShape.ShapeType() + 1;
1764 for ( ; type <= TopAbs_EDGE; type++) {
1765 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1767 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1768 for ( ; exp.More(); exp.Next() )
1769 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
1776 //=======================================================================
1777 //function : GetCollection
1778 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1779 // meshed at once along with _subShape
1780 //=======================================================================
1782 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1784 MESSAGE("SMESH_subMesh::GetCollection");
1785 ASSERT (!theAlgo->NeedDescretBoundary());
1787 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1789 if ( mainShape.IsSame( _subShape ))
1792 const bool ignoreAuxiliaryHyps = false;
1793 list<const SMESHDS_Hypothesis*> aUsedHyp =
1794 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
1796 // put in a compound all shapes with the same hypothesis assigned
1797 // and a good ComputState
1799 TopoDS_Compound aCompound;
1800 BRep_Builder aBuilder;
1801 aBuilder.MakeCompound( aCompound );
1803 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1804 for ( ; anExplorer.More(); anExplorer.Next() )
1806 const TopoDS_Shape& S = anExplorer.Current();
1807 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1808 if ( subMesh == this )
1810 aBuilder.Add( aCompound, S );
1812 else if ( subMesh->GetComputeState() == READY_TO_COMPUTE )
1814 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1815 if (anAlgo == theAlgo &&
1816 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp)
1817 aBuilder.Add( aCompound, S );
1824 //=======================================================================
1825 //function : GetSimilarAttached
1826 //purpose : return a hypothesis attached to theShape.
1827 // If theHyp is provided, similar but not same hypotheses
1828 // is returned; else only applicable ones having theHypType
1830 //=======================================================================
1832 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1833 const SMESH_Hypothesis * theHyp,
1834 const int theHypType)
1836 SMESH_HypoFilter hypoKind;
1837 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
1839 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
1840 hypoKind.AndNot( hypoKind.Is( theHyp ));
1841 if ( theHyp->IsAuxiliary() )
1842 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
1844 hypoKind.AndNot( hypoKind.IsAuxiliary());
1847 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
1850 return _father->GetHypothesis( theShape, hypoKind, false );
1853 //=======================================================================
1854 //function : CheckConcurentHypothesis
1855 //purpose : check if there are several applicable hypothesis attached to
1857 //=======================================================================
1859 SMESH_Hypothesis::Hypothesis_Status
1860 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1862 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1864 // is there local hypothesis on me?
1865 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1866 return SMESH_Hypothesis::HYP_OK;
1869 TopoDS_Shape aPrevWithHyp;
1870 const SMESH_Hypothesis* aPrevHyp = 0;
1871 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1872 for (; it.More(); it.Next())
1874 const TopoDS_Shape& ancestor = it.Value();
1875 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1878 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1880 aPrevWithHyp = ancestor;
1883 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1884 return SMESH_Hypothesis::HYP_CONCURENT;
1886 return SMESH_Hypothesis::HYP_OK;
1889 return SMESH_Hypothesis::HYP_OK;
1892 //================================================================================
1894 * \brief Sets an event listener and its data to a submesh
1895 * \param listener - the listener to store
1896 * \param data - the listener data to store
1897 * \param where - the submesh to store the listener and it's data
1898 * \param deleteListener - if true then the listener will be deleted as
1899 * it is removed from where submesh
1901 * It remembers the submesh where it puts the listener in order to delete
1902 * them when HYP_OK algo_state is lost
1903 * After being set, event listener is notified on each event of where submesh.
1905 //================================================================================
1907 void SMESH_subMesh::SetEventListener(EventListener* listener,
1908 EventListenerData* data,
1909 SMESH_subMesh* where)
1911 if ( listener && where ) {
1912 where->SetEventListener( listener, data );
1913 myOwnListeners.push_back( make_pair( where, listener ));
1917 //================================================================================
1919 * \brief Sets an event listener and its data to a submesh
1920 * \param listener - the listener to store
1921 * \param data - the listener data to store
1923 * After being set, event listener is notified on each event of a submesh.
1925 //================================================================================
1927 void SMESH_subMesh::SetEventListener(EventListener* listener, EventListenerData* data)
1929 map< EventListener*, EventListenerData* >::iterator l_d =
1930 myEventListeners.find( listener );
1931 if ( l_d != myEventListeners.end() ) {
1932 if ( l_d->second && l_d->second->IsDeletable() )
1937 myEventListeners.insert( make_pair( listener, data ));
1940 //================================================================================
1942 * \brief Return an event listener data
1943 * \param listener - the listener whose data is
1944 * \retval EventListenerData* - found data, maybe NULL
1946 //================================================================================
1948 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
1950 map< EventListener*, EventListenerData* >::const_iterator l_d =
1951 myEventListeners.find( listener );
1952 if ( l_d != myEventListeners.end() )
1957 //================================================================================
1959 * \brief Notify stored event listeners on the occured event
1960 * \param event - algo_event or compute_event itself
1961 * \param eventType - algo_event or compute_event
1962 * \param subMesh - the submesh where the event occures
1963 * \param data - listener data stored in the subMesh
1964 * \param hyp - hypothesis, if eventType is algo_event
1966 //================================================================================
1968 void SMESH_subMesh::NotifyListenersOnEvent( const int event,
1969 const event_type eventType,
1970 SMESH_Hypothesis* hyp)
1972 map< EventListener*, EventListenerData* >::iterator l_d = myEventListeners.begin();
1973 for ( ; l_d != myEventListeners.end(); ++l_d )
1974 l_d->first->ProcessEvent( event, eventType, this, l_d->second, hyp );
1977 //================================================================================
1979 * \brief Unregister the listener and delete listener's data
1980 * \param listener - the event listener
1982 //================================================================================
1984 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
1986 map< EventListener*, EventListenerData* >::iterator l_d =
1987 myEventListeners.find( listener );
1988 if ( l_d != myEventListeners.end() ) {
1989 if ( l_d->first && l_d->first->IsDeletable() ) delete l_d->first;
1990 if ( l_d->second && l_d->second->IsDeletable() ) delete l_d->second;
1991 myEventListeners.erase( l_d );
1995 //================================================================================
1997 * \brief Delete event listeners depending on algo of this submesh
1999 //================================================================================
2001 void SMESH_subMesh::DeleteOwnListeners()
2003 list< pair< SMESH_subMesh*, EventListener* > >::iterator sm_l;
2004 for ( sm_l = myOwnListeners.begin(); sm_l != myOwnListeners.end(); ++sm_l)
2005 sm_l->first->DeleteEventListener( sm_l->second );
2006 myOwnListeners.clear();
2009 //================================================================================
2011 * \brief Do something on a certain event
2012 * \param event - algo_event or compute_event itself
2013 * \param eventType - algo_event or compute_event
2014 * \param subMesh - the submesh where the event occures
2015 * \param data - listener data stored in the subMesh
2016 * \param hyp - hypothesis, if eventType is algo_event
2018 * The base implementation translates CLEAN event to the subMesh
2019 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
2020 * successful COMPUTE event.
2022 //================================================================================
2024 void SMESH_subMeshEventListener::ProcessEvent(const int event,
2025 const int eventType,
2026 SMESH_subMesh* subMesh,
2027 EventListenerData* data,
2028 const SMESH_Hypothesis* /*hyp*/)
2030 if ( data && !data->mySubMeshes.empty() &&
2031 eventType == SMESH_subMesh::COMPUTE_EVENT)
2033 ASSERT( data->mySubMeshes.front() != subMesh );
2035 case SMESH_subMesh::CLEAN:
2036 data->mySubMeshes.front()->ComputeStateEngine( event );
2038 case SMESH_subMesh::COMPUTE:
2039 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
2040 data->mySubMeshes.front()->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
2049 //================================================================================
2051 * \brief Iterator over submeshes and optionally prepended or appended one
2053 //================================================================================
2055 struct _Iterator : public SMDS_Iterator<SMESH_subMesh*>
2057 _Iterator(SMDS_Iterator<SMESH_subMesh*>* subIt,
2058 SMESH_subMesh* prepend,
2059 SMESH_subMesh* append): myIt(subIt),myAppend(append)
2061 myCur = prepend ? prepend : myIt->more() ? myIt->next() : 0;
2063 /// Return true if and only if there are other object in this iterator
2068 /// Return the current object and step to the next one
2069 virtual SMESH_subMesh* next()
2071 SMESH_subMesh* res = myCur;
2072 if ( myIt->more() ) { myCur = myIt->next(); }
2073 else { myCur = myAppend; myAppend = 0; }
2080 SMESH_subMesh *myAppend, *myCur;
2081 SMDS_Iterator<SMESH_subMesh*> *myIt;
2085 //================================================================================
2087 * \brief Return iterator on the submeshes this one depends on
2088 * \param includeSelf - this submesh to be returned also
2089 * \param reverse - if true, complex shape submeshes go first
2091 //================================================================================
2093 SMESH_subMeshIteratorPtr SMESH_subMesh::getDependsOnIterator(const bool includeSelf,
2096 SMESH_subMesh *prepend=0, *append=0;
2097 if ( includeSelf ) {
2098 if ( reverse ) prepend = this;
2101 typedef map < int, SMESH_subMesh * > TMap;
2104 return SMESH_subMeshIteratorPtr
2105 ( new _Iterator( new SMDS_mapReverseIterator<TMap>( DependsOn() ), prepend, append ));
2108 return SMESH_subMeshIteratorPtr
2109 ( new _Iterator( new SMDS_mapIterator<TMap>( DependsOn() ), prepend, append ));