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_subMeshEventListener.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "SMESH_Algo.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_MesherHelper.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>
63 //=============================================================================
65 * default constructor:
67 //=============================================================================
69 SMESH_subMesh::SMESH_subMesh(int Id,
71 SMESHDS_Mesh * meshDS,
72 const TopoDS_Shape & aSubShape)
74 _subShape = aSubShape;
76 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
79 _dependenceAnalysed = _alwaysComputed = false;
81 if (_subShape.ShapeType() == TopAbs_VERTEX)
84 _computeState = READY_TO_COMPUTE;
89 _computeState = NOT_READY;
93 //=============================================================================
97 //=============================================================================
99 SMESH_subMesh::~SMESH_subMesh()
101 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
103 DeleteOwnListeners();
106 //=============================================================================
110 //=============================================================================
112 int SMESH_subMesh::GetId() const
114 //MESSAGE("SMESH_subMesh::GetId");
118 //=============================================================================
122 //=============================================================================
124 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
126 // submesh appears in DS only when a mesher set nodes and elements on a shape
127 return _subMeshDS ? _subMeshDS : _subMeshDS = _meshDS->MeshElements(_subShape); // may be null
130 //=============================================================================
134 //=============================================================================
136 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
138 if ( !GetSubMeshDS() )
139 _meshDS->NewSubMesh( _meshDS->ShapeToIndex( _subShape ) );
141 return GetSubMeshDS();
144 //=============================================================================
148 //=============================================================================
150 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
152 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
153 SMESH_subMesh *firstToCompute = 0;
155 map < int, SMESH_subMesh * >::const_iterator itsub;
156 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
158 SMESH_subMesh *sm = (*itsub).second;
159 bool readyToCompute = (sm->GetComputeState() == READY_TO_COMPUTE);
168 return firstToCompute; // a subMesh of this
170 if (_computeState == READY_TO_COMPUTE)
174 return 0; // nothing to compute
177 //================================================================================
179 * \brief Allow algo->Compute() if a subshape of lower dim is meshed but
180 * none mesh entity is bound to it (PAL13615, 2nd part)
182 //================================================================================
184 void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
186 _alwaysComputed = isAlCo;
187 if ( _alwaysComputed )
188 _computeState = COMPUTE_OK;
190 ComputeStateEngine( CHECK_COMPUTE_STATE );
193 //=======================================================================
194 //function : IsMeshComputed
195 //purpose : check if _subMeshDS contains mesh elements
196 //=======================================================================
198 bool SMESH_subMesh::IsMeshComputed() const
200 if ( _alwaysComputed )
202 // algo may bind a submesh not to _subShape, eg 3D algo
203 // sets nodes on SHELL while _subShape may be SOLID
205 int dim = SMESH_Gen::GetShapeDim( _subShape );
206 int type = _subShape.ShapeType();
207 for ( ; type <= TopAbs_VERTEX; type++) {
208 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
210 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
211 for ( ; exp.More(); exp.Next() )
213 SMESHDS_SubMesh * smDS = _meshDS->MeshElements( exp.Current() );
214 if ( smDS && ( smDS->NbElements() || smDS->NbNodes()))
225 //=============================================================================
229 //=============================================================================
231 bool SMESH_subMesh::SubMeshesComputed()
233 //MESSAGE("SMESH_subMesh::SubMeshesComputed");
234 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
236 int myDim = SMESH_Gen::GetShapeDim( _subShape );
237 int dimToCheck = myDim - 1;
238 bool subMeshesComputed = true;
239 // check subMeshes with upper dimension => reverse iteration
240 map < int, SMESH_subMesh * >::const_reverse_iterator itsub;
241 for (itsub = subMeshes.rbegin(); itsub != subMeshes.rend(); itsub++)
243 SMESH_subMesh *sm = (*itsub).second;
244 if ( sm->_alwaysComputed )
246 const TopoDS_Shape & ss = sm->GetSubShape();
247 // MSV 07.04.2006: restrict checking to myDim-1 only. Ex., there is no sense
248 // in checking of existence of edges if the algo needs only faces. Moreover,
249 // degenerated edges may have no submesh, as after computing NETGEN_2D.
250 int dim = SMESH_Gen::GetShapeDim( ss );
251 if (dim < dimToCheck)
252 break; // the rest subMeshes are all of less dimension
253 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
254 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
255 (ds && ( ds->NbNodes() || ds->NbElements() )));
258 int type = ss.ShapeType();
260 subMeshesComputed = false;
264 case TopAbs_COMPOUND:
266 MESSAGE("The not computed sub mesh is a COMPOUND");
269 case TopAbs_COMPSOLID:
271 MESSAGE("The not computed sub mesh is a COMPSOLID");
276 MESSAGE("The not computed sub mesh is a SHEL");
281 MESSAGE("The not computed sub mesh is a WIRE");
286 MESSAGE("The not computed sub mesh is a SOLID");
291 MESSAGE("The not computed sub mesh is a FACE");
296 MESSAGE("The not computed sub mesh is a EDGE");
301 MESSAGE("The not computed sub mesh is of unknown type");
309 return subMeshesComputed;
312 //=============================================================================
316 //=============================================================================
318 bool SMESH_subMesh::SubMeshesReady()
320 MESSAGE("SMESH_subMesh::SubMeshesReady");
321 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
323 bool subMeshesReady = true;
324 map < int, SMESH_subMesh * >::const_iterator itsub;
325 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
327 SMESH_subMesh *sm = (*itsub).second;
328 bool computeOk = ((sm->GetComputeState() == COMPUTE_OK)
329 || (sm->GetComputeState() == READY_TO_COMPUTE));
332 subMeshesReady = false;
337 return subMeshesReady;
340 //=============================================================================
342 * Construct dependence on first level subMeshes. complex shapes (compsolid,
343 * shell, wire) are not analysed the same way as simple shapes (solid, face,
345 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
346 * with possible multiples occurences. Multiples occurences corresponds to
347 * internal frontiers within shapes of the collection and must not be keeped.
348 * See FinalizeDependence.
350 //=============================================================================
352 const map < int, SMESH_subMesh * >&SMESH_subMesh::DependsOn()
354 if (_dependenceAnalysed)
357 //MESSAGE("SMESH_subMesh::DependsOn");
359 int type = _subShape.ShapeType();
363 case TopAbs_COMPOUND:
365 //MESSAGE("compound");
366 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
369 InsertDependence(exp.Current());
371 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More();
374 InsertDependence(exp.Current()); //only shell not in solid
376 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();
379 InsertDependence(exp.Current());
381 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();
384 InsertDependence(exp.Current());
388 case TopAbs_COMPSOLID:
390 //MESSAGE("compsolid");
391 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
394 InsertDependence(exp.Current());
401 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
404 InsertDependence(exp.Current());
411 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
414 InsertDependence(exp.Current());
421 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
424 InsertDependence(exp.Current());
431 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
434 InsertDependence(exp.Current());
441 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More();
444 InsertDependence(exp.Current());
457 _dependenceAnalysed = true;
461 //=============================================================================
463 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
465 //=============================================================================
467 void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape)
469 //MESSAGE("SMESH_subMesh::InsertDependence");
470 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
471 int type = aSubShape.ShapeType();
472 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
473 int cle = aSubMesh->GetId();
474 cle += 10000000 * ordType; // sort map by ordType then index
475 if ( _mapDepend.find( cle ) == _mapDepend.end())
477 _mapDepend[cle] = aSubMesh;
478 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
479 _mapDepend.insert( subMap.begin(), subMap.end() );
483 //=============================================================================
487 //=============================================================================
489 const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
491 //MESSAGE("SMESH_subMesh::GetSubShape");
496 //=======================================================================
497 //function : CanAddHypothesis
498 //purpose : return true if theHypothesis can be attached to me:
499 // its dimention is checked
500 //=======================================================================
502 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
504 int aHypDim = theHypothesis->GetDim();
505 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
506 if ( aHypDim <= aShapeDim )
508 // if ( aHypDim < aShapeDim )
509 // return ( _father->IsMainShape( _subShape ));
514 //=======================================================================
515 //function : IsApplicableHypotesis
517 //=======================================================================
519 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
520 const TopAbs_ShapeEnum theShapeType)
522 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
524 return ( theHypothesis->GetShapeType() & (1<< theShapeType));
527 switch ( theShapeType ) {
532 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
535 // Special case for algorithms, building 2D mesh on a whole shell.
536 // Before this fix there was a problem after restoring from study,
537 // because in that case algorithm is assigned before hypothesis
538 // (on shell in problem case) and hypothesis is checked on faces
539 // (because it is 2D), where we have NO_ALGO state.
540 // Now 2D hypothesis is also applicable to shells.
541 return (theHypothesis->GetDim() == 2 || theHypothesis->GetDim() == 3);
544 // case TopAbs_COMPSOLID:
545 // case TopAbs_COMPOUND:
551 //=============================================================================
555 //=============================================================================
557 SMESH_Hypothesis::Hypothesis_Status
558 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
560 // MESSAGE("SMESH_subMesh::AlgoStateEngine");
561 //SCRUTE(_algoState);
564 // **** les retour des evenement shape sont significatifs
565 // (add ou remove fait ou non)
566 // le retour des evenement father n'indiquent pas que add ou remove fait
568 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
570 SMESH_Gen* gen =_father->GetGen();
571 SMESH_Algo* algo = 0;
573 if (_subShape.ShapeType() == TopAbs_VERTEX )
575 if ( anHyp->GetDim() != 0) {
576 if (event == ADD_HYP || event == ADD_ALGO)
577 return SMESH_Hypothesis::HYP_BAD_DIM;
579 return SMESH_Hypothesis::HYP_OK;
582 else if ( _algoState == HYP_OK ) { // update default _algoState
583 _algoState = NO_ALGO;
584 algo = gen->GetAlgo(*_father, _subShape);
586 _algoState = MISSING_HYP;
587 if ( algo->CheckHypothesis(*_father,_subShape, aux_ret))
593 int oldAlgoState = _algoState;
594 bool modifiedHyp = (event == MODIF_HYP); // if set to true, force event MODIF_ALGO_STATE
596 bool isApplicableHyp = IsApplicableHypotesis( anHyp );
598 if (event == ADD_ALGO || event == ADD_FATHER_ALGO)
600 // -------------------------------------------
601 // check if a shape needed by algo is present
602 // -------------------------------------------
603 algo = static_cast< SMESH_Algo* >( anHyp );
604 if ( !_father->HasShapeToMesh() && algo->NeedShape() )
605 return SMESH_Hypothesis::HYP_BAD_GEOMETRY;
606 // ----------------------
607 // check mesh conformity
608 // ----------------------
609 if (isApplicableHyp && !_father->IsNotConformAllowed() && !IsConform( algo ))
610 return SMESH_Hypothesis::HYP_NOTCONFORM;
613 // ----------------------------------
614 // add a hypothesis to DS if possible
615 // ----------------------------------
616 if (event == ADD_HYP || event == ADD_ALGO)
618 if ( ! CanAddHypothesis( anHyp )) // check dimension
619 return SMESH_Hypothesis::HYP_BAD_DIM;
621 if ( /*!anHyp->IsAuxiliary() &&*/ GetSimilarAttached( _subShape, anHyp ) )
622 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
624 if ( !_meshDS->AddHypothesis(_subShape, anHyp))
625 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
627 // Serve Propagation of 1D hypothesis
628 // NOTE: it is possible to re-implement Propagation using EventListener
629 if (event == ADD_HYP) {
630 bool isPropagationOk = true;
631 bool isPropagationHyp = ( strcmp( "Propagation", anHyp->GetName() ) == 0 );
633 if ( isPropagationHyp ) {
634 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
635 TopTools_MapOfShape aMap;
636 for (; exp.More(); exp.Next()) {
637 if (aMap.Add(exp.Current())) {
638 if (!_father->BuildPropagationChain(exp.Current())) {
639 isPropagationOk = false;
644 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
645 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
646 TopTools_MapOfShape aMap;
647 for (; exp.More(); exp.Next()) {
648 if (aMap.Add(exp.Current())) {
649 TopoDS_Shape aMainEdge;
650 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
651 isPropagationOk = _father->RebuildPropagationChains();
652 } else if (_father->IsPropagationHypothesis(exp.Current())) {
653 isPropagationOk = _father->BuildPropagationChain(exp.Current());
661 if ( isPropagationOk ) {
662 if ( isPropagationHyp )
663 return ret; // nothing more to do for "Propagation" hypothesis
665 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
666 ret = SMESH_Hypothesis::HYP_CONCURENT;
668 } // Serve Propagation of 1D hypothesis
671 // --------------------------
672 // remove a hypothesis from DS
673 // --------------------------
674 if (event == REMOVE_HYP || event == REMOVE_ALGO)
676 if (!_meshDS->RemoveHypothesis(_subShape, anHyp))
677 return SMESH_Hypothesis::HYP_OK; // nothing changes
679 // Serve Propagation of 1D hypothesis
680 // NOTE: it is possible to re-implement Propagation using EventListener
681 if (event == REMOVE_HYP)
683 bool isPropagationOk = true;
684 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
685 bool isPropagationHyp = propagFilter.IsOk( anHyp, _subShape );
687 if ( isPropagationHyp )
689 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
690 TopTools_MapOfShape aMap;
691 for (; exp.More(); exp.Next()) {
692 if (aMap.Add(exp.Current()) &&
693 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
694 // no more Propagation on the current edge
695 if (!_father->RemovePropagationChain(exp.Current())) {
696 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
700 // rebuild propagation chains, because removing one
701 // chain can resolve concurention, existing before
702 isPropagationOk = _father->RebuildPropagationChains();
704 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
706 isPropagationOk = _father->RebuildPropagationChains();
709 if ( isPropagationOk ) {
710 if ( isPropagationHyp )
711 return ret; // nothing more to do for "Propagation" hypothesis
713 else if ( ret < SMESH_Hypothesis::HYP_CONCURENT) {
714 ret = SMESH_Hypothesis::HYP_CONCURENT;
716 } // Serve Propagation of 1D hypothesis
717 else // event == REMOVE_ALGO
719 algo = dynamic_cast<SMESH_Algo*> (anHyp);
720 if (!algo->NeedDescretBoundary())
722 // clean all mesh in the tree of the current submesh;
723 // we must perform it now because later
724 // we will have no information about the type of the removed algo
726 ComputeStateEngine( CLEAN );
732 // ------------------
733 // analyse algo state
734 // ------------------
735 if (!isApplicableHyp)
736 return ret; // not applicable hypotheses do not change algo state
741 // ----------------------------------------------------------------------
748 algo = gen->GetAlgo((*_father), _subShape);
750 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
751 SetAlgoState(HYP_OK);
752 else if ( algo->IsStatusFatal( aux_ret )) {
753 _meshDS->RemoveHypothesis(_subShape, anHyp);
757 SetAlgoState(MISSING_HYP);
764 case ADD_FATHER_ALGO: { // Algo just added in father
765 algo = gen->GetAlgo((*_father), _subShape);
767 if ( algo == anHyp ) {
768 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
769 SetAlgoState(HYP_OK);
771 SetAlgoState(MISSING_HYP);
775 case REMOVE_FATHER_HYP:
777 case REMOVE_FATHER_ALGO: {
778 algo = gen->GetAlgo((*_father), _subShape);
781 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
782 SetAlgoState(HYP_OK);
784 SetAlgoState(MISSING_HYP);
788 case MODIF_HYP: break;
795 // ----------------------------------------------------------------------
801 algo = gen->GetAlgo((*_father), _subShape);
803 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
804 SetAlgoState(HYP_OK);
805 if (SMESH_Hypothesis::IsStatusFatal( ret ))
806 _meshDS->RemoveHypothesis(_subShape, anHyp);
807 else if (!_father->IsUsedHypothesis( anHyp, this ))
809 _meshDS->RemoveHypothesis(_subShape, anHyp);
810 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
814 case ADD_ALGO: { //already existing algo : on father ?
815 algo = gen->GetAlgo((*_father), _subShape);
817 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
818 SetAlgoState(HYP_OK);
819 else if ( algo->IsStatusFatal( aux_ret )) {
820 _meshDS->RemoveHypothesis(_subShape, anHyp);
824 SetAlgoState(MISSING_HYP);
829 case REMOVE_ALGO: { // perhaps a father algo applies ?
830 algo = gen->GetAlgo((*_father), _subShape);
831 if (algo == NULL) // no more algo applying on subShape...
833 SetAlgoState(NO_ALGO);
837 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
838 SetAlgoState(HYP_OK);
840 SetAlgoState(MISSING_HYP);
844 case MODIF_HYP: // assigned hypothesis value may become good
845 case ADD_FATHER_HYP: {
846 algo = gen->GetAlgo((*_father), _subShape);
848 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
849 SetAlgoState(HYP_OK);
851 SetAlgoState(MISSING_HYP);
854 case ADD_FATHER_ALGO: { // new father algo
855 algo = gen->GetAlgo((*_father), _subShape);
857 if ( algo == anHyp ) {
858 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
859 SetAlgoState(HYP_OK);
861 SetAlgoState(MISSING_HYP);
865 case REMOVE_FATHER_HYP: // nothing to do
867 case REMOVE_FATHER_ALGO: {
868 algo = gen->GetAlgo((*_father), _subShape);
869 if (algo == NULL) // no more applying algo on father
871 SetAlgoState(NO_ALGO);
875 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
876 SetAlgoState(HYP_OK);
878 SetAlgoState(MISSING_HYP);
888 // ----------------------------------------------------------------------
894 algo = gen->GetAlgo((*_father), _subShape);
896 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
898 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
899 // ret should be fatal: anHyp was not added
900 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
902 else if (!_father->IsUsedHypothesis( anHyp, this ))
903 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
905 if (SMESH_Hypothesis::IsStatusFatal( ret ))
907 MESSAGE("do not add extra hypothesis");
908 _meshDS->RemoveHypothesis(_subShape, anHyp);
916 case ADD_ALGO: { //already existing algo : on father ?
917 algo = gen->GetAlgo((*_father), _subShape);
918 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
919 // check if algo changes
921 f.Init( SMESH_HypoFilter::IsAlgo() );
922 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
923 f.AndNot( SMESH_HypoFilter::Is( algo ));
924 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
926 string(algo->GetName()) != string(prevAlgo->GetName()) )
930 SetAlgoState(MISSING_HYP);
934 algo = gen->GetAlgo((*_father), _subShape);
936 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
937 SetAlgoState(HYP_OK);
939 SetAlgoState(MISSING_HYP);
943 case REMOVE_ALGO: { // perhaps a father algo applies ?
944 algo = gen->GetAlgo((*_father), _subShape);
945 if (algo == NULL) // no more algo applying on subShape...
947 SetAlgoState(NO_ALGO);
951 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
952 // check if algo remains
953 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
957 SetAlgoState(MISSING_HYP);
961 case MODIF_HYP: // hypothesis value may become bad
962 case ADD_FATHER_HYP: { // new father hypothesis ?
963 algo = gen->GetAlgo((*_father), _subShape);
965 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
967 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
971 SetAlgoState(MISSING_HYP);
974 case ADD_FATHER_ALGO: {
975 algo = gen->GetAlgo((*_father), _subShape);
976 if ( algo == anHyp ) { // a new algo on father
977 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
978 // check if algo changes
980 f.Init( SMESH_HypoFilter::IsAlgo() );
981 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
982 f.AndNot( SMESH_HypoFilter::Is( algo ));
983 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
985 string(algo->GetName()) != string(prevAlgo->GetName()) )
989 SetAlgoState(MISSING_HYP);
993 case REMOVE_FATHER_HYP: {
994 algo = gen->GetAlgo((*_father), _subShape);
996 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
997 // is there the same local hyp or maybe a new father algo applied?
998 if ( !GetSimilarAttached( _subShape, anHyp ) )
1002 SetAlgoState(MISSING_HYP);
1005 case REMOVE_FATHER_ALGO: {
1006 algo = gen->GetAlgo((*_father), _subShape);
1007 if (algo == NULL) // no more applying algo on father
1009 SetAlgoState(NO_ALGO);
1013 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1014 // check if algo changes
1015 if ( string(algo->GetName()) != string( anHyp->GetName()) )
1019 SetAlgoState(MISSING_HYP);
1029 // ----------------------------------------------------------------------
1036 // detect algorithm hiding
1038 if ( ret == SMESH_Hypothesis::HYP_OK &&
1039 ( event == ADD_ALGO || event == ADD_FATHER_ALGO ) &&
1040 algo->GetName() == anHyp->GetName() )
1043 SMESH_Gen* gen = _father->GetGen();
1044 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1045 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && it.More()); it.Next() ) {
1046 if ( SMESH_Algo* upperAlgo = gen->GetAlgo( *_father, it.Value() ))
1047 if ( !upperAlgo->NeedDescretBoundary() )
1048 ret = SMESH_Hypothesis::HYP_HIDDEN_ALGO;
1051 if ( ret == SMESH_Hypothesis::HYP_OK && !algo->NeedDescretBoundary() ) {
1052 map<int, SMESH_subMesh*>::reverse_iterator i_sm = _mapDepend.rbegin();
1053 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && i_sm != _mapDepend.rend()) ; ++i_sm )
1054 if ( gen->GetAlgo( *_father, i_sm->second->_subShape ))
1055 ret = SMESH_Hypothesis::HYP_HIDING_ALGO;
1059 bool stateChange = ( _algoState != oldAlgoState );
1061 if ( stateChange && _algoState == HYP_OK ) // hyp becomes OK
1062 algo->SetEventListener( this );
1064 NotifyListenersOnEvent( event, ALGO_EVENT, anHyp );
1066 if ( stateChange && oldAlgoState == HYP_OK ) { // hyp becomes KO
1067 DeleteOwnListeners();
1068 if (_subShape.ShapeType() == TopAbs_VERTEX ) {
1069 // restore default states
1070 _algoState = HYP_OK;
1071 _computeState = READY_TO_COMPUTE;
1075 if (stateChange || modifiedHyp)
1076 ComputeStateEngine(MODIF_ALGO_STATE);
1081 //=======================================================================
1082 //function : IsConform
1083 //purpose : check if a conform mesh will be produced by the Algo
1084 //=======================================================================
1086 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
1088 // MESSAGE( "SMESH_subMesh::IsConform" );
1089 if ( !theAlgo ) return false;
1091 // Suppose that theAlgo is applicable to _subShape, do not check it here
1092 //if ( !IsApplicableHypotesis( theAlgo )) return false;
1094 // check only algo that doesn't NeedDescretBoundary(): because mesh made
1095 // on a sub-shape will be ignored by theAlgo
1096 if ( theAlgo->NeedDescretBoundary() ||
1097 !theAlgo->OnlyUnaryInput() ) // all adjacent shapes will be meshed by this algo?
1100 SMESH_Gen* gen =_father->GetGen();
1102 // only local algo is to be checked
1103 //if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1104 if ( _subShape.ShapeType() == _father->GetMeshDS()->ShapeToMesh().ShapeType() )
1107 // check algo attached to adjacent shapes
1109 // loop on one level down sub-meshes
1110 TopoDS_Iterator itsub( _subShape );
1111 for (; itsub.More(); itsub.Next())
1113 // loop on adjacent subShapes
1114 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1115 for (; it.More(); it.Next())
1117 const TopoDS_Shape& adjacent = it.Value();
1118 if ( _subShape.IsSame( adjacent )) continue;
1119 if ( adjacent.ShapeType() != _subShape.ShapeType())
1122 // check algo attached to smAdjacent
1123 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1125 !algo->NeedDescretBoundary() &&
1126 algo->OnlyUnaryInput())
1127 return false; // NOT CONFORM MESH WILL BE PRODUCED
1134 //=============================================================================
1138 //=============================================================================
1140 void SMESH_subMesh::SetAlgoState(int state)
1145 //=============================================================================
1149 //=============================================================================
1150 SMESH_Hypothesis::Hypothesis_Status
1151 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1152 SMESH_Hypothesis * anHyp)
1154 //MESSAGE("SMESH_subMesh::SubMeshesAlgoStateEngine");
1155 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1156 //EAP: a wire (dim==1) should notify edges (dim==1)
1157 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1158 if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1160 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1162 map < int, SMESH_subMesh * >::const_iterator itsub;
1163 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1165 SMESH_subMesh *sm = (*itsub).second;
1166 SMESH_Hypothesis::Hypothesis_Status ret2 =
1167 sm->AlgoStateEngine(event, anHyp);
1175 //=============================================================================
1179 //=============================================================================
1181 void SMESH_subMesh::CleanDependsOn()
1183 //MESSAGE("SMESH_subMesh::CleanDependsOn");
1185 const map < int, SMESH_subMesh * >&dependson = DependsOn();
1186 map < int, SMESH_subMesh * >::const_iterator its;
1187 for (its = dependson.begin(); its != dependson.end(); its++)
1189 SMESH_subMesh *sm = (*its).second;
1190 sm->ComputeStateEngine(CLEAN);
1194 //=============================================================================
1198 //=============================================================================
1200 void SMESH_subMesh::DumpAlgoState(bool isMain)
1202 int dim = SMESH_Gen::GetShapeDim(_subShape);
1203 // if (dim < 1) return;
1206 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1208 map < int, SMESH_subMesh * >::const_iterator itsub;
1209 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1211 SMESH_subMesh *sm = (*itsub).second;
1212 sm->DumpAlgoState(false);
1215 int type = _subShape.ShapeType();
1216 MESSAGE("dim = " << dim << " type of shape " << type);
1220 MESSAGE(" AlgoState = NO_ALGO");
1223 MESSAGE(" AlgoState = MISSING_HYP");
1226 MESSAGE(" AlgoState = HYP_OK");
1229 switch (_computeState)
1232 MESSAGE(" ComputeState = NOT_READY");
1234 case READY_TO_COMPUTE:
1235 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1238 MESSAGE(" ComputeState = COMPUTE_OK");
1240 case FAILED_TO_COMPUTE:
1241 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1246 //================================================================================
1248 * \brief Remove nodes and elements bound to submesh
1249 * \param subMesh - submesh containing nodes and elements
1251 //================================================================================
1253 static void cleanSubMesh( SMESH_subMesh * subMesh )
1256 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1257 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1258 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1259 while (ite->more()) {
1260 const SMDS_MeshElement * elt = ite->next();
1261 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1262 //meshDS->RemoveElement(elt);
1263 meshDS->RemoveFreeElement(elt, subMeshDS);
1266 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1267 while (itn->more()) {
1268 const SMDS_MeshNode * node = itn->next();
1269 //MESSAGE( " RM node: "<<node->GetID());
1270 //meshDS->RemoveNode(node);
1271 meshDS->RemoveFreeNode(node, subMeshDS);
1277 //=============================================================================
1281 //=============================================================================
1283 bool SMESH_subMesh::ComputeStateEngine(int event)
1285 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1286 //SCRUTE(_computeState);
1289 if (_subShape.ShapeType() == TopAbs_VERTEX)
1291 if ( IsMeshComputed() )
1292 _computeState = COMPUTE_OK;
1294 _computeState = READY_TO_COMPUTE;
1295 if ( event == MODIF_ALGO_STATE )
1299 SMESH_Gen *gen = _father->GetGen();
1300 SMESH_Algo *algo = 0;
1302 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1303 //algo_state oldAlgoState = (algo_state) GetAlgoState();
1305 switch (_computeState)
1308 // ----------------------------------------------------------------------
1313 case MODIF_ALGO_STATE:
1314 algo = gen->GetAlgo((*_father), _subShape);
1315 if (algo && !algo->NeedDescretBoundary())
1316 CleanDependsOn(); // clean sub-meshes with event CLEAN
1317 if ( _algoState == HYP_OK )
1318 _computeState = READY_TO_COMPUTE;
1320 case COMPUTE: // nothing to do
1324 RemoveSubMeshElementsAndNodes();
1326 case SUBMESH_COMPUTED: // nothing to do
1328 case SUBMESH_RESTORED:
1329 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1331 case MESH_ENTITY_REMOVED:
1333 case CHECK_COMPUTE_STATE:
1334 if ( IsMeshComputed() )
1335 _computeState = COMPUTE_OK;
1343 // ----------------------------------------------------------------------
1345 case READY_TO_COMPUTE:
1348 case MODIF_ALGO_STATE:
1349 _computeState = NOT_READY;
1350 algo = gen->GetAlgo((*_father), _subShape);
1353 if (!algo->NeedDescretBoundary())
1354 CleanDependsOn(); // clean sub-meshes with event CLEAN
1355 if ( _algoState == HYP_OK )
1356 _computeState = READY_TO_COMPUTE;
1361 algo = gen->GetAlgo((*_father), _subShape);
1363 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1366 MESSAGE("***** verify compute state *****");
1367 _computeState = NOT_READY;
1368 SetAlgoState(MISSING_HYP);
1371 // check submeshes needed
1372 if (_father->HasShapeToMesh() && algo->NeedDescretBoundary())
1373 ret = SubMeshesComputed();
1376 MESSAGE("Some SubMeshes not computed");
1377 _computeState = FAILED_TO_COMPUTE;
1382 RemoveSubMeshElementsAndNodes();
1385 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1388 if ( !_father->HasShapeToMesh() ) // no shape
1390 SMESH_MesherHelper helper( *_father );
1391 helper.SetSubShape( _subShape );
1392 helper.SetElementsOnShape( true );
1393 ret = algo->Compute(*_father, &helper );
1396 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput())
1397 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1399 ret = algo->Compute((*_father), _subShape);
1402 catch (Standard_Failure) {
1403 MESSAGE( "Exception in algo->Compute() ");
1409 MESSAGE("problem in algo execution: failed to compute");
1410 // release ALGO from responsibilty of partially built mesh
1411 RemoveSubMeshElementsAndNodes();
1412 _computeState = FAILED_TO_COMPUTE;
1413 if (!algo->NeedDescretBoundary())
1414 UpdateSubMeshState( FAILED_TO_COMPUTE );
1417 // Show vertices location of a failed shape
1418 cout << algo->GetName() << " failed on shape with the following vertices:" << endl;
1419 TopTools_IndexedMapOfShape vMap;
1420 TopExp::MapShapes( _subShape, TopAbs_VERTEX, vMap );
1421 for ( int iv = 1; iv <= vMap.Extent(); ++iv ) {
1422 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( vMap( iv ) )));
1423 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1430 _computeState = COMPUTE_OK;
1431 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1432 if (!algo->NeedDescretBoundary())
1433 UpdateSubMeshState( COMPUTE_OK );
1439 RemoveSubMeshElementsAndNodes();
1440 _computeState = NOT_READY;
1441 algo = gen->GetAlgo((*_father), _subShape);
1444 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1446 _computeState = READY_TO_COMPUTE;
1448 SetAlgoState(MISSING_HYP);
1451 case SUBMESH_COMPUTED: // nothing to do
1453 case SUBMESH_RESTORED:
1454 // check if a mesh is already computed that may
1455 // happen after retrieval from a file
1456 ComputeStateEngine( CHECK_COMPUTE_STATE );
1457 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1458 algo = gen->GetAlgo(*_father, _subShape);
1459 if (algo) algo->SubmeshRestored( this );
1461 case MESH_ENTITY_REMOVED:
1463 case CHECK_COMPUTE_STATE:
1464 if ( IsMeshComputed() )
1465 _computeState = COMPUTE_OK;
1473 // ----------------------------------------------------------------------
1478 case MODIF_ALGO_STATE:
1479 ComputeStateEngine( CLEAN );
1480 algo = gen->GetAlgo((*_father), _subShape);
1481 if (algo && !algo->NeedDescretBoundary())
1482 CleanDependsOn(); // clean sub-meshes with event CLEAN
1484 case COMPUTE: // nothing to do
1487 CleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1488 RemoveSubMeshElementsAndNodes();
1489 _computeState = NOT_READY;
1490 if ( _algoState == HYP_OK )
1491 _computeState = READY_TO_COMPUTE;
1493 case SUBMESH_COMPUTED: // nothing to do
1495 case SUBMESH_RESTORED:
1496 ComputeStateEngine( CHECK_COMPUTE_STATE );
1497 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1498 algo = gen->GetAlgo(*_father, _subShape);
1499 if (algo) algo->SubmeshRestored( this );
1501 case MESH_ENTITY_REMOVED:
1502 UpdateDependantsState( CHECK_COMPUTE_STATE );
1503 ComputeStateEngine( CHECK_COMPUTE_STATE );
1504 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1506 case CHECK_COMPUTE_STATE:
1507 if ( !IsMeshComputed() )
1508 if (_algoState == HYP_OK)
1509 _computeState = READY_TO_COMPUTE;
1511 _computeState = NOT_READY;
1519 // ----------------------------------------------------------------------
1521 case FAILED_TO_COMPUTE:
1524 case MODIF_ALGO_STATE:
1525 if (_algoState == HYP_OK)
1526 _computeState = READY_TO_COMPUTE;
1528 _computeState = NOT_READY;
1530 case COMPUTE: // nothing to do
1533 CleanDependants(); // submeshes dependent on me should be cleaned as well
1534 RemoveSubMeshElementsAndNodes();
1535 if (_algoState == HYP_OK)
1536 _computeState = READY_TO_COMPUTE;
1538 _computeState = NOT_READY;
1540 case SUBMESH_COMPUTED: // allow retry compute
1541 if (_algoState == HYP_OK)
1542 _computeState = READY_TO_COMPUTE;
1544 _computeState = NOT_READY;
1546 case SUBMESH_RESTORED:
1547 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1549 case MESH_ENTITY_REMOVED:
1551 case CHECK_COMPUTE_STATE:
1552 if ( IsMeshComputed() )
1553 _computeState = COMPUTE_OK;
1555 if (_algoState == HYP_OK)
1556 _computeState = READY_TO_COMPUTE;
1558 _computeState = NOT_READY;
1566 // ----------------------------------------------------------------------
1572 NotifyListenersOnEvent( event, COMPUTE_EVENT );
1577 //=======================================================================
1578 //function : ApplyToCollection
1579 //purpose : Apply theAlgo to all subshapes in theCollection
1580 //=======================================================================
1582 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1583 const TopoDS_Shape& theCollection)
1585 MESSAGE("SMESH_subMesh::ApplyToCollection");
1586 ASSERT ( !theAlgo->NeedDescretBoundary() );
1591 ret = theAlgo->Compute( *_father, theCollection );
1593 // set _computeState of subshapes
1594 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1595 for ( ; anExplorer.More(); anExplorer.Next() )
1597 const TopoDS_Shape& aSubShape = anExplorer.Current();
1598 SMESH_subMesh* subMesh = _father->GetSubMeshContaining( aSubShape );
1603 subMesh->_computeState = COMPUTE_OK;
1604 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1605 subMesh->UpdateSubMeshState( COMPUTE_OK );
1609 subMesh->_computeState = FAILED_TO_COMPUTE;
1617 //=======================================================================
1618 //function : UpdateSubMeshState
1620 //=======================================================================
1622 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1624 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1625 map<int, SMESH_subMesh*>::const_iterator itsub;
1626 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1628 SMESH_subMesh* sm = (*itsub).second;
1629 sm->_computeState = theState;
1633 //=======================================================================
1634 //function : ComputeSubMeshStateEngine
1636 //=======================================================================
1638 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1640 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1641 map<int, SMESH_subMesh*>::const_iterator itsub;
1642 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1644 SMESH_subMesh* sm = (*itsub).second;
1645 sm->ComputeStateEngine(event);
1649 //=======================================================================
1650 //function : UpdateDependantsState
1652 //=======================================================================
1654 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1656 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1657 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1658 for (; it.More(); it.Next())
1660 const TopoDS_Shape& ancestor = it.Value();
1661 SMESH_subMesh *aSubMesh =
1662 _father->GetSubMeshContaining(ancestor);
1664 aSubMesh->ComputeStateEngine( theEvent );
1668 //=============================================================================
1672 //=============================================================================
1674 void SMESH_subMesh::CleanDependants()
1676 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
1678 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1679 for (; it.More(); it.Next())
1681 const TopoDS_Shape& ancestor = it.Value();
1682 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
1683 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
1684 // will erase mesh on other shapes in a compound
1685 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
1686 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1688 aSubMesh->ComputeStateEngine(CLEAN);
1694 //=============================================================================
1698 //=============================================================================
1700 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1702 //SCRUTE(_subShape.ShapeType());
1704 cleanSubMesh( this );
1706 // algo may bind a submesh not to _subShape, eg 3D algo
1707 // sets nodes on SHELL while _subShape may be SOLID
1709 int dim = SMESH_Gen::GetShapeDim( _subShape );
1710 int type = _subShape.ShapeType() + 1;
1711 for ( ; type <= TopAbs_EDGE; type++) {
1712 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1714 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1715 for ( ; exp.More(); exp.Next() )
1716 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
1723 //=======================================================================
1724 //function : GetCollection
1725 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1726 // meshed at once along with _subShape
1727 //=======================================================================
1729 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1731 MESSAGE("SMESH_subMesh::GetCollection");
1732 ASSERT (!theAlgo->NeedDescretBoundary());
1734 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1736 if ( mainShape.IsSame( _subShape ))
1739 const bool ignoreAuxiliaryHyps = false;
1740 list<const SMESHDS_Hypothesis*> aUsedHyp =
1741 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
1743 // put in a compound all shapes with the same hypothesis assigned
1744 // and a good ComputState
1746 TopoDS_Compound aCompound;
1747 BRep_Builder aBuilder;
1748 aBuilder.MakeCompound( aCompound );
1750 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1751 for ( ; anExplorer.More(); anExplorer.Next() )
1753 const TopoDS_Shape& S = anExplorer.Current();
1754 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1755 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1757 if (subMesh->GetComputeState() == READY_TO_COMPUTE &&
1758 anAlgo == theAlgo &&
1759 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp)
1761 aBuilder.Add( aCompound, S );
1768 //=======================================================================
1769 //function : GetSimilarAttached
1770 //purpose : return a hypothesis attached to theShape.
1771 // If theHyp is provided, similar but not same hypotheses
1772 // is returned; else only applicable ones having theHypType
1774 //=======================================================================
1776 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1777 const SMESH_Hypothesis * theHyp,
1778 const int theHypType)
1780 SMESH_HypoFilter hypoKind;
1781 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
1783 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
1784 hypoKind.AndNot( hypoKind.Is( theHyp ));
1785 if ( theHyp->IsAuxiliary() )
1786 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
1788 hypoKind.AndNot( hypoKind.IsAuxiliary());
1791 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
1794 return _father->GetHypothesis( theShape, hypoKind, false );
1797 //=======================================================================
1798 //function : CheckConcurentHypothesis
1799 //purpose : check if there are several applicable hypothesis attached to
1801 //=======================================================================
1803 SMESH_Hypothesis::Hypothesis_Status
1804 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1806 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1808 // is there local hypothesis on me?
1809 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1810 return SMESH_Hypothesis::HYP_OK;
1813 TopoDS_Shape aPrevWithHyp;
1814 const SMESH_Hypothesis* aPrevHyp = 0;
1815 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1816 for (; it.More(); it.Next())
1818 const TopoDS_Shape& ancestor = it.Value();
1819 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1822 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1824 aPrevWithHyp = ancestor;
1827 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1828 return SMESH_Hypothesis::HYP_CONCURENT;
1830 return SMESH_Hypothesis::HYP_OK;
1833 return SMESH_Hypothesis::HYP_OK;
1836 //================================================================================
1838 * \brief Sets an event listener and its data to a submesh
1839 * \param listener - the listener to store
1840 * \param data - the listener data to store
1841 * \param where - the submesh to store the listener and it's data
1842 * \param deleteListener - if true then the listener will be deleted as
1843 * it is removed from where submesh
1845 * It remembers the submesh where it puts the listener in order to delete
1846 * them when HYP_OK algo_state is lost
1847 * After being set, event listener is notified on each event of where submesh.
1849 //================================================================================
1851 void SMESH_subMesh::SetEventListener(EventListener* listener,
1852 EventListenerData* data,
1853 SMESH_subMesh* where)
1855 if ( listener && where ) {
1856 where->SetEventListener( listener, data );
1857 myOwnListeners.push_back( make_pair( where, listener ));
1861 //================================================================================
1863 * \brief Sets an event listener and its data to a submesh
1864 * \param listener - the listener to store
1865 * \param data - the listener data to store
1867 * After being set, event listener is notified on each event of a submesh.
1869 //================================================================================
1871 void SMESH_subMesh::SetEventListener(EventListener* listener, EventListenerData* data)
1873 map< EventListener*, EventListenerData* >::iterator l_d =
1874 myEventListeners.find( listener );
1875 if ( l_d != myEventListeners.end() ) {
1876 if ( l_d->second && l_d->second->IsDeletable() )
1881 myEventListeners.insert( make_pair( listener, data ));
1884 //================================================================================
1886 * \brief Return an event listener data
1887 * \param listener - the listener whose data is
1888 * \retval EventListenerData* - found data, maybe NULL
1890 //================================================================================
1892 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
1894 map< EventListener*, EventListenerData* >::const_iterator l_d =
1895 myEventListeners.find( listener );
1896 if ( l_d != myEventListeners.end() )
1901 //================================================================================
1903 * \brief Notify stored event listeners on the occured event
1904 * \param event - algo_event or compute_event itself
1905 * \param eventType - algo_event or compute_event
1906 * \param subMesh - the submesh where the event occures
1907 * \param data - listener data stored in the subMesh
1908 * \param hyp - hypothesis, if eventType is algo_event
1910 //================================================================================
1912 void SMESH_subMesh::NotifyListenersOnEvent( const int event,
1913 const event_type eventType,
1914 SMESH_Hypothesis* hyp)
1916 map< EventListener*, EventListenerData* >::iterator l_d = myEventListeners.begin();
1917 for ( ; l_d != myEventListeners.end(); ++l_d )
1918 l_d->first->ProcessEvent( event, eventType, this, l_d->second, hyp );
1921 //================================================================================
1923 * \brief Unregister the listener and delete listener's data
1924 * \param listener - the event listener
1926 //================================================================================
1928 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
1930 map< EventListener*, EventListenerData* >::iterator l_d =
1931 myEventListeners.find( listener );
1932 if ( l_d != myEventListeners.end() ) {
1933 if ( l_d->first && l_d->first->IsDeletable() ) delete l_d->first;
1934 if ( l_d->second && l_d->second->IsDeletable() ) delete l_d->second;
1935 myEventListeners.erase( l_d );
1939 //================================================================================
1941 * \brief Delete event listeners depending on algo of this submesh
1943 //================================================================================
1945 void SMESH_subMesh::DeleteOwnListeners()
1947 list< pair< SMESH_subMesh*, EventListener* > >::iterator sm_l;
1948 for ( sm_l = myOwnListeners.begin(); sm_l != myOwnListeners.end(); ++sm_l)
1949 sm_l->first->DeleteEventListener( sm_l->second );
1950 myOwnListeners.clear();
1953 //================================================================================
1955 * \brief Do something on a certain event
1956 * \param event - algo_event or compute_event itself
1957 * \param eventType - algo_event or compute_event
1958 * \param subMesh - the submesh where the event occures
1959 * \param data - listener data stored in the subMesh
1960 * \param hyp - hypothesis, if eventType is algo_event
1962 * The base implementation translates CLEAN event to the subMesh
1963 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
1964 * successful COMPUTE event.
1966 //================================================================================
1968 void SMESH_subMeshEventListener::ProcessEvent(const int event,
1969 const int eventType,
1970 SMESH_subMesh* subMesh,
1971 EventListenerData* data,
1972 SMESH_Hypothesis* /*hyp*/)
1974 if ( data && !data->mySubMeshes.empty() &&
1975 eventType == SMESH_subMesh::COMPUTE_EVENT)
1977 ASSERT( data->mySubMeshes.front() != subMesh );
1979 case SMESH_subMesh::CLEAN:
1980 data->mySubMeshes.front()->ComputeStateEngine( event );
1982 case SMESH_subMesh::COMPUTE:
1983 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
1984 data->mySubMeshes.front()->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );