1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_subMesh.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_subMesh.hxx"
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_HypoFilter.hxx"
33 #include "SMESH_Hypothesis.hxx"
34 #include "SMESH_Mesh.hxx"
35 #include "SMESH_MesherHelper.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Comment.hxx"
38 #include "SMDS_SetIterator.hxx"
39 #include "SMDSAbs_ElementType.hxx"
41 #include <Basics_OCCTVersion.hxx>
43 #include "utilities.h"
45 #include "Basics_Utils.hxx"
47 #include <BRep_Builder.hxx>
48 #include <BRep_Tool.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopoDS_Compound.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopoDS_Iterator.hxx>
58 #include <Standard_OutOfMemory.hxx>
59 #include <Standard_ErrorHandler.hxx>
65 //=============================================================================
67 * \brief Allocate some memory at construction and release it at destruction.
68 * Is used to be able to continue working after mesh generation breaks due to
71 //=============================================================================
76 MemoryReserve(): myBuf( new char[1024*1024*2] ){}
77 ~MemoryReserve() { delete [] myBuf; }
80 //=============================================================================
82 * default constructor:
84 //=============================================================================
86 SMESH_subMesh::SMESH_subMesh(int Id,
88 SMESHDS_Mesh * meshDS,
89 const TopoDS_Shape & aSubShape)
91 _subShape = aSubShape;
92 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
95 _dependenceAnalysed = _alwaysComputed = false;
97 if (_subShape.ShapeType() == TopAbs_VERTEX)
100 _computeState = READY_TO_COMPUTE;
104 _algoState = NO_ALGO;
105 _computeState = NOT_READY;
107 _computeCost = 0; // how costly is to compute this sub-mesh
110 //=============================================================================
114 //=============================================================================
116 SMESH_subMesh::~SMESH_subMesh()
118 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
120 deleteOwnListeners();
123 //=============================================================================
127 //=============================================================================
129 int SMESH_subMesh::GetId() const
131 //MESSAGE("SMESH_subMesh::GetId");
135 //=============================================================================
139 //=============================================================================
141 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
143 // submesh appears in DS only when a mesher set nodes and elements on a shape
144 return _subMeshDS ? _subMeshDS : _subMeshDS = _father->GetMeshDS()->MeshElements(_subShape); // may be null
147 //=============================================================================
151 //=============================================================================
153 const SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS() const
155 return ((SMESH_subMesh*) this )->GetSubMeshDS();
158 //=============================================================================
162 //=============================================================================
164 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
166 if ( !GetSubMeshDS() ) {
167 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
168 meshDS->NewSubMesh( meshDS->ShapeToIndex( _subShape ) );
170 return GetSubMeshDS();
173 //=============================================================================
177 //=============================================================================
179 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
181 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(true,false);
182 while ( smIt->more() ) {
183 SMESH_subMesh *sm = smIt->next();
184 if ( sm->GetComputeState() == READY_TO_COMPUTE )
187 return 0; // nothing to compute
190 //================================================================================
192 * \brief Returns a current algorithm
194 //================================================================================
196 SMESH_Algo* SMESH_subMesh::GetAlgo() const
199 ((SMESH_subMesh*)this)->_algo = _father->GetGen()->GetAlgo(*_father, _subShape);
203 //================================================================================
205 * \brief Allow algo->Compute() if a sub-shape of lower dim is meshed but
206 * none mesh entity is bound to it (PAL13615, 2nd part)
208 //================================================================================
210 void SMESH_subMesh::SetIsAlwaysComputed(bool isAlCo)
212 _alwaysComputed = isAlCo;
213 if ( _alwaysComputed )
214 _computeState = COMPUTE_OK;
216 ComputeStateEngine( CHECK_COMPUTE_STATE );
219 //=======================================================================
221 * \brief Return true if no mesh entities is bound to the submesh
223 //=======================================================================
225 bool SMESH_subMesh::IsEmpty() const
227 if (SMESHDS_SubMesh * subMeshDS = ((SMESH_subMesh*)this)->GetSubMeshDS())
228 return (!subMeshDS->NbElements() && !subMeshDS->NbNodes());
232 //=======================================================================
233 //function : IsMeshComputed
234 //purpose : check if _subMeshDS contains mesh elements
235 //=======================================================================
237 bool SMESH_subMesh::IsMeshComputed() const
239 if ( _alwaysComputed )
241 // algo may bind a submesh not to _subShape, eg 3D algo
242 // sets nodes on SHELL while _subShape may be SOLID
244 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
245 int dim = SMESH_Gen::GetShapeDim( _subShape );
246 int type = _subShape.ShapeType();
247 for ( ; type <= TopAbs_VERTEX; type++) {
248 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
250 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
251 for ( ; exp.More(); exp.Next() )
253 if ( SMESHDS_SubMesh * smDS = meshDS->MeshElements( exp.Current() ))
255 bool computed = (dim > 0) ? smDS->NbElements() : smDS->NbNodes();
268 //=============================================================================
270 * Return true if all sub-meshes have been meshed
272 //=============================================================================
274 bool SMESH_subMesh::SubMeshesComputed(bool * isFailedToCompute/*=0*/) const
276 int myDim = SMESH_Gen::GetShapeDim( _subShape );
277 int dimToCheck = myDim - 1;
278 bool subMeshesComputed = true;
279 if ( isFailedToCompute ) *isFailedToCompute = false;
280 // check subMeshes with upper dimension => reverse iteration
281 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
282 while ( smIt->more() )
284 SMESH_subMesh *sm = smIt->next();
285 if ( sm->_alwaysComputed )
287 const TopoDS_Shape & ss = sm->GetSubShape();
289 // MSV 07.04.2006: restrict checking to myDim-1 only. Ex., there is no sense
290 // in checking of existence of edges if the algo needs only faces. Moreover,
291 // degenerated edges may have no submesh, as after computing NETGEN_2D.
292 if ( !_algo || _algo->NeedDiscreteBoundary() ) {
293 int dim = SMESH_Gen::GetShapeDim( ss );
294 if (dim < dimToCheck)
295 break; // the rest subMeshes are all of less dimension
297 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
298 bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
299 (ds && ( dimToCheck ? ds->NbElements() : ds->NbNodes() )));
302 subMeshesComputed = false;
303 if ( isFailedToCompute && !(*isFailedToCompute) )
304 *isFailedToCompute = ( sm->GetComputeState() == FAILED_TO_COMPUTE );
306 // int type = ss.ShapeType();
310 // case TopAbs_COMPOUND:
312 // MESSAGE("The not computed sub mesh is a COMPOUND");
315 // case TopAbs_COMPSOLID:
317 // MESSAGE("The not computed sub mesh is a COMPSOLID");
320 // case TopAbs_SHELL:
322 // MESSAGE("The not computed sub mesh is a SHEL");
327 // MESSAGE("The not computed sub mesh is a WIRE");
330 // case TopAbs_SOLID:
332 // MESSAGE("The not computed sub mesh is a SOLID");
337 // MESSAGE("The not computed sub mesh is a FACE");
342 // MESSAGE("The not computed sub mesh is a EDGE");
347 // MESSAGE("The not computed sub mesh is of unknown type");
352 if ( !isFailedToCompute )
356 return subMeshesComputed;
359 //================================================================================
361 * \brief Return cost of computing this sub-mesh. The cost depends on the shape type
362 * and number of sub-meshes this one DependsOn().
363 * \return int - the computation cost in abstract units.
365 //================================================================================
367 int SMESH_subMesh::GetComputeCost() const
372 switch ( _subShape.ShapeType() ) {
374 case TopAbs_SHELL: computeCost = 1000; break;
375 case TopAbs_FACE: computeCost = 100; break;
376 case TopAbs_EDGE: computeCost = 10; break;
377 default: computeCost = 1;
379 SMESH_subMeshIteratorPtr childIt = getDependsOnIterator(/*includeSelf=*/false);
380 while ( childIt->more() )
381 computeCost += childIt->next()->GetComputeCost();
383 ((SMESH_subMesh*)this)->_computeCost = computeCost;
388 //=============================================================================
392 //=============================================================================
394 // bool SMESH_subMesh::SubMeshesReady()
396 // bool subMeshesReady = true;
397 // SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
398 // while ( smIt->more() ) {
399 // SMESH_subMesh *sm = smIt->next();
400 // bool computeOk = (sm->GetComputeState() == COMPUTE_OK ||
401 // sm->GetComputeState() == READY_TO_COMPUTE);
404 // subMeshesReady = false;
405 // SCRUTE(sm->GetId());
409 // return subMeshesReady;
412 //=============================================================================
414 * Construct dependence on first level subMeshes. complex shapes (compsolid,
415 * shell, wire) are not analysed the same way as simple shapes (solid, face,
417 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
418 * with possible multiples occurences. Multiples occurences corresponds to
419 * internal frontiers within shapes of the collection and must not be keeped.
420 * See FinalizeDependence.
422 //=============================================================================
424 const map < int, SMESH_subMesh * >& SMESH_subMesh::DependsOn()
426 if (_dependenceAnalysed)
429 //MESSAGE("SMESH_subMesh::DependsOn");
431 int type = _subShape.ShapeType();
435 case TopAbs_COMPOUND:
437 //MESSAGE("compound");
438 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();exp.Next())
440 insertDependence(exp.Current());
442 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More(); exp.Next())
444 if ( BRep_Tool::IsClosed(exp.Current() ))
445 insertDependence(exp.Current()); //only shell not in solid
447 for (TopExp_Explorer expF(exp.Current(), TopAbs_FACE); expF.More();expF.Next())
448 insertDependence(expF.Current()); // issue 0020959: HEXA_3D fails on shell
451 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();exp.Next())
453 insertDependence(exp.Current());
455 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();exp.Next())
457 insertDependence(exp.Current());
459 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX, TopAbs_EDGE); exp.More();exp.Next())
461 insertDependence(exp.Current());
465 case TopAbs_COMPSOLID:
467 //MESSAGE("compsolid");
468 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More(); exp.Next())
470 insertDependence(exp.Current());
477 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More(); exp.Next())
479 insertDependence(exp.Current());
486 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More(); exp.Next())
488 insertDependence(exp.Current());
495 if(_father->HasShapeToMesh()) {
496 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();exp.Next())
498 insertDependence(exp.Current());
506 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();exp.Next())
508 insertDependence(exp.Current());
515 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More(); exp.Next())
517 insertDependence(exp.Current());
530 _dependenceAnalysed = true;
534 //=============================================================================
536 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
538 //=============================================================================
540 void SMESH_subMesh::insertDependence(const TopoDS_Shape aSubShape)
542 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
543 int type = aSubShape.ShapeType();
544 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
545 int cle = aSubMesh->GetId();
546 cle += 10000000 * ordType; // sort map by ordType then index
547 if ( _mapDepend.find( cle ) == _mapDepend.end())
549 _mapDepend[cle] = aSubMesh;
550 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
551 _mapDepend.insert( subMap.begin(), subMap.end() );
555 //=============================================================================
559 //=============================================================================
561 const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
563 //MESSAGE("SMESH_subMesh::GetSubShape");
568 //=======================================================================
569 //function : CanAddHypothesis
570 //purpose : return true if theHypothesis can be attached to me:
571 // its dimention is checked
572 //=======================================================================
574 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
576 int aHypDim = theHypothesis->GetDim();
577 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
578 // issue 21106. Forbid 3D mesh on the SHELL
579 // if (aHypDim == 3 && aShapeDim == 3) {
580 // // check case of open shell
581 // //if (_subShape.ShapeType() == TopAbs_SHELL && !_subShape.Closed())
582 // if (_subShape.ShapeType() == TopAbs_SHELL && !BRep_Tool::IsClosed(_subShape))
585 if ( aHypDim <= aShapeDim )
591 //=======================================================================
592 //function : IsApplicableHypotesis
594 //=======================================================================
596 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
597 const TopAbs_ShapeEnum theShapeType)
599 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
602 if ( theHypothesis->GetShapeType() & (1<< theShapeType))
603 // issue 21106. Forbid 3D mesh on the SHELL
604 return !( theHypothesis->GetDim() == 3 && theShapeType == TopAbs_SHELL );
610 switch ( theShapeType ) {
615 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
618 // Special case for algorithms, building 2D mesh on a whole shell.
619 // Before this fix there was a problem after restoring from study,
620 // because in that case algorithm is assigned before hypothesis
621 // (on shell in problem case) and hypothesis is checked on faces
622 // (because it is 2D), where we have NO_ALGO state.
623 // Now 2D hypothesis is also applicable to shells.
624 return (theHypothesis->GetDim() == 2 || theHypothesis->GetDim() == 3);
627 // case TopAbs_COMPSOLID:
628 // case TopAbs_COMPOUND:
634 //=============================================================================
638 //=============================================================================
640 SMESH_Hypothesis::Hypothesis_Status
641 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
643 // **** les retour des evenement shape sont significatifs
644 // (add ou remove fait ou non)
645 // le retour des evenement father n'indiquent pas que add ou remove fait
647 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
649 SMESHDS_Mesh* meshDS =_father->GetMeshDS();
650 SMESH_Algo* algo = 0;
653 if (_subShape.ShapeType() == TopAbs_VERTEX )
655 if ( anHyp->GetDim() != 0) {
656 if (event == ADD_HYP || event == ADD_ALGO)
657 return SMESH_Hypothesis::HYP_BAD_DIM;
659 return SMESH_Hypothesis::HYP_OK;
662 else if ( _algoState == HYP_OK ) {
663 // update default _algoState
664 if ( event != REMOVE_FATHER_ALGO )
666 _algoState = NO_ALGO;
669 _algoState = MISSING_HYP;
670 if ( event == REMOVE_FATHER_HYP ||
671 algo->CheckHypothesis(*_father,_subShape, aux_ret))
678 int oldAlgoState = _algoState;
679 bool modifiedHyp = (event == MODIF_HYP); // if set to true, force event MODIF_ALGO_STATE
680 SMESH_Algo* algoRequiringCleaning = 0;
682 bool isApplicableHyp = IsApplicableHypotesis( anHyp );
684 if (event == ADD_ALGO || event == ADD_FATHER_ALGO)
686 // -------------------------------------------
687 // check if a shape needed by algo is present
688 // -------------------------------------------
689 algo = static_cast< SMESH_Algo* >( anHyp );
690 if ( !_father->HasShapeToMesh() && algo->NeedShape() )
691 return SMESH_Hypothesis::HYP_NEED_SHAPE;
692 // ----------------------
693 // check mesh conformity
694 // ----------------------
695 if (isApplicableHyp && !_father->IsNotConformAllowed() && !IsConform( algo ))
696 return SMESH_Hypothesis::HYP_NOTCONFORM;
698 // check if all-dimensional algo is hidden by other local one
699 if ( event == ADD_ALGO ) {
700 SMESH_HypoFilter filter( SMESH_HypoFilter::HasType( algo->GetType() ));
701 filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+1 ));
702 filter.Or( SMESH_HypoFilter::HasType( algo->GetType()+2 ));
703 if ( SMESH_Algo * curAlgo = (SMESH_Algo*)_father->GetHypothesis(_subShape, filter, true ))
704 if ( !curAlgo->NeedDiscreteBoundary() )
705 algoRequiringCleaning = curAlgo;
709 // ----------------------------------
710 // add a hypothesis to DS if possible
711 // ----------------------------------
712 if (event == ADD_HYP || event == ADD_ALGO)
714 if ( ! CanAddHypothesis( anHyp )) // check dimension
715 return SMESH_Hypothesis::HYP_BAD_DIM;
717 if ( /*!anHyp->IsAuxiliary() &&*/ getSimilarAttached( _subShape, anHyp ) )
718 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
720 if ( !meshDS->AddHypothesis(_subShape, anHyp))
721 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
724 // --------------------------
725 // remove a hypothesis from DS
726 // --------------------------
727 if (event == REMOVE_HYP || event == REMOVE_ALGO)
729 if (!meshDS->RemoveHypothesis(_subShape, anHyp))
730 return SMESH_Hypothesis::HYP_OK; // nothing changes
732 if (event == REMOVE_ALGO)
734 algo = dynamic_cast<SMESH_Algo*> (anHyp);
735 if (!algo->NeedDiscreteBoundary())
736 algoRequiringCleaning = algo;
740 // ------------------
741 // analyse algo state
742 // ------------------
743 if (!isApplicableHyp)
744 return ret; // not applicable hypotheses do not change algo state
749 // ----------------------------------------------------------------------
758 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
759 setAlgoState(HYP_OK);
760 else if ( algo->IsStatusFatal( aux_ret )) {
761 meshDS->RemoveHypothesis(_subShape, anHyp);
765 setAlgoState(MISSING_HYP);
772 case ADD_FATHER_ALGO: { // Algo just added in father
775 if ( algo == anHyp ) {
776 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
777 setAlgoState(HYP_OK);
779 setAlgoState(MISSING_HYP);
783 case REMOVE_FATHER_HYP:
785 case REMOVE_FATHER_ALGO: {
789 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
790 setAlgoState(HYP_OK);
792 setAlgoState(MISSING_HYP);
796 case MODIF_HYP: break;
803 // ----------------------------------------------------------------------
811 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
812 setAlgoState(HYP_OK);
813 if (SMESH_Hypothesis::IsStatusFatal( ret ))
814 meshDS->RemoveHypothesis(_subShape, anHyp);
815 else if (!_father->IsUsedHypothesis( anHyp, this ))
817 meshDS->RemoveHypothesis(_subShape, anHyp);
818 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
822 case ADD_ALGO: { //already existing algo : on father ?
825 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
826 setAlgoState(HYP_OK);
827 else if ( algo->IsStatusFatal( aux_ret )) {
828 meshDS->RemoveHypothesis(_subShape, anHyp);
832 setAlgoState(MISSING_HYP);
837 case REMOVE_ALGO: { // perhaps a father algo applies ?
839 if (algo == NULL) // no more algo applying on sub-shape...
841 setAlgoState(NO_ALGO);
845 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
846 setAlgoState(HYP_OK);
848 setAlgoState(MISSING_HYP);
852 case MODIF_HYP: // assigned hypothesis value may become good
853 case ADD_FATHER_HYP: {
856 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
857 setAlgoState(HYP_OK);
859 setAlgoState(MISSING_HYP);
862 case ADD_FATHER_ALGO: { // new father algo
865 if ( algo == anHyp ) {
866 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
867 setAlgoState(HYP_OK);
869 setAlgoState(MISSING_HYP);
873 case REMOVE_FATHER_HYP: // nothing to do
875 case REMOVE_FATHER_ALGO: {
877 if (algo == NULL) // no more applying algo on father
879 setAlgoState(NO_ALGO);
883 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
884 setAlgoState(HYP_OK);
886 setAlgoState(MISSING_HYP);
896 // ----------------------------------------------------------------------
904 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
906 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
907 // ret should be fatal: anHyp was not added
908 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
910 else if (!_father->IsUsedHypothesis( anHyp, this ))
911 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
913 if (SMESH_Hypothesis::IsStatusFatal( ret ))
915 MESSAGE("do not add extra hypothesis");
916 meshDS->RemoveHypothesis(_subShape, anHyp);
924 case ADD_ALGO: { //already existing algo : on father ?
926 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
927 // check if algo changes
929 f.Init( SMESH_HypoFilter::IsAlgo() );
930 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
931 f.AndNot( SMESH_HypoFilter::Is( algo ));
932 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
934 string(algo->GetName()) != string(prevAlgo->GetName()) )
938 setAlgoState(MISSING_HYP);
944 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
945 setAlgoState(HYP_OK);
947 setAlgoState(MISSING_HYP);
951 case REMOVE_ALGO: { // perhaps a father algo applies ?
953 if (algo == NULL) // no more algo applying on sub-shape...
955 setAlgoState(NO_ALGO);
959 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
960 // check if algo remains
961 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
965 setAlgoState(MISSING_HYP);
969 case MODIF_HYP: // hypothesis value may become bad
970 case ADD_FATHER_HYP: { // new father hypothesis ?
973 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
975 if (_father->IsUsedHypothesis( anHyp, this )) // new Hyp
979 setAlgoState(MISSING_HYP);
982 case ADD_FATHER_ALGO: {
984 if ( algo == anHyp ) { // a new algo on father
985 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
986 // check if algo changes
988 f.Init( SMESH_HypoFilter::IsAlgo() );
989 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
990 f.AndNot( SMESH_HypoFilter::Is( algo ));
991 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
993 string(algo->GetName()) != string(prevAlgo->GetName()) )
997 setAlgoState(MISSING_HYP);
1001 case REMOVE_FATHER_HYP: {
1004 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1005 // is there the same local hyp or maybe a new father algo applied?
1006 if ( !getSimilarAttached( _subShape, anHyp ) )
1010 setAlgoState(MISSING_HYP);
1013 case REMOVE_FATHER_ALGO: {
1014 // IPAL21346. Edges not removed when Netgen 1d-2d is removed from a SOLID.
1015 // CLEAN was not called at event REMOVE_ALGO because the algo is not applicable to SOLID.
1016 algo = dynamic_cast<SMESH_Algo*> (anHyp);
1017 if (!algo->NeedDiscreteBoundary())
1018 algoRequiringCleaning = algo;
1020 if (algo == NULL) // no more applying algo on father
1022 setAlgoState(NO_ALGO);
1026 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
1027 // check if algo changes
1028 if ( string(algo->GetName()) != string( anHyp->GetName()) )
1032 setAlgoState(MISSING_HYP);
1042 // ----------------------------------------------------------------------
1049 // detect algorithm hiding
1051 if ( ret == SMESH_Hypothesis::HYP_OK &&
1052 ( event == ADD_ALGO || event == ADD_FATHER_ALGO ) &&
1053 algo->GetName() == anHyp->GetName() )
1056 SMESH_Gen* gen = _father->GetGen();
1057 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1058 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && it.More()); it.Next() ) {
1059 if ( SMESH_Algo* upperAlgo = gen->GetAlgo( *_father, it.Value() ))
1060 if ( !upperAlgo->NeedDiscreteBoundary() && !upperAlgo->SupportSubmeshes())
1061 ret = SMESH_Hypothesis::HYP_HIDDEN_ALGO;
1064 if ( ret == SMESH_Hypothesis::HYP_OK &&
1065 !algo->NeedDiscreteBoundary() &&
1066 !algo->SupportSubmeshes()) {
1067 TopoDS_Shape algoAssignedTo, otherAssignedTo;
1068 gen->GetAlgo( *_father, _subShape, &algoAssignedTo );
1069 map<int, SMESH_subMesh*>::reverse_iterator i_sm = _mapDepend.rbegin();
1070 for ( ; ( ret == SMESH_Hypothesis::HYP_OK && i_sm != _mapDepend.rend()) ; ++i_sm )
1071 if ( gen->GetAlgo( *_father, i_sm->second->_subShape, &otherAssignedTo ) &&
1072 SMESH_MesherHelper::IsSubShape( /*sub=*/otherAssignedTo, /*main=*/algoAssignedTo ))
1073 ret = SMESH_Hypothesis::HYP_HIDING_ALGO;
1077 bool stateChange = ( _algoState != oldAlgoState );
1079 if ( stateChange && _algoState == HYP_OK ) // hyp becomes OK
1080 algo->SetEventListener( this );
1082 if ( event == REMOVE_ALGO || event == REMOVE_FATHER_ALGO )
1085 notifyListenersOnEvent( event, ALGO_EVENT, anHyp );
1087 if ( stateChange && oldAlgoState == HYP_OK ) { // hyp becomes KO
1088 deleteOwnListeners();
1089 SetIsAlwaysComputed( false );
1090 if (_subShape.ShapeType() == TopAbs_VERTEX ) {
1091 // restore default states
1092 _algoState = HYP_OK;
1093 _computeState = READY_TO_COMPUTE;
1097 if ( algoRequiringCleaning ) {
1098 // added or removed algo is all-dimensional
1099 ComputeStateEngine( CLEAN );
1100 cleanDependsOn( algoRequiringCleaning );
1101 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1104 if (stateChange || modifiedHyp)
1105 ComputeStateEngine(MODIF_ALGO_STATE);
1110 //=======================================================================
1111 //function : IsConform
1112 //purpose : check if a conform mesh will be produced by the Algo
1113 //=======================================================================
1115 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
1117 // MESSAGE( "SMESH_subMesh::IsConform" );
1118 if ( !theAlgo ) return false;
1120 // Suppose that theAlgo is applicable to _subShape, do not check it here
1121 //if ( !IsApplicableHypotesis( theAlgo )) return false;
1123 // check only algo that doesn't NeedDiscreteBoundary(): because mesh made
1124 // on a sub-shape will be ignored by theAlgo
1125 if ( theAlgo->NeedDiscreteBoundary() ||
1126 !theAlgo->OnlyUnaryInput() ) // all adjacent shapes will be meshed by this algo?
1129 SMESH_Gen* gen =_father->GetGen();
1131 // only local algo is to be checked
1132 //if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
1133 if ( _subShape.ShapeType() == _father->GetMeshDS()->ShapeToMesh().ShapeType() )
1136 // check algo attached to adjacent shapes
1138 // loop on one level down sub-meshes
1139 TopoDS_Iterator itsub( _subShape );
1140 for (; itsub.More(); itsub.Next())
1142 // loop on adjacent subShapes
1143 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
1144 for (; it.More(); it.Next())
1146 const TopoDS_Shape& adjacent = it.Value();
1147 if ( _subShape.IsSame( adjacent )) continue;
1148 if ( adjacent.ShapeType() != _subShape.ShapeType())
1151 // check algo attached to smAdjacent
1152 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
1154 !algo->NeedDiscreteBoundary() &&
1155 algo->OnlyUnaryInput())
1156 return false; // NOT CONFORM MESH WILL BE PRODUCED
1163 //=============================================================================
1167 //=============================================================================
1169 void SMESH_subMesh::setAlgoState(algo_state state)
1174 //=============================================================================
1178 //=============================================================================
1179 SMESH_Hypothesis::Hypothesis_Status
1180 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
1181 SMESH_Hypothesis * anHyp)
1183 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1184 //EAP: a wire (dim==1) should notify edges (dim==1)
1185 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1186 //if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1188 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1189 while ( smIt->more() ) {
1190 SMESH_Hypothesis::Hypothesis_Status ret2 =
1191 smIt->next()->AlgoStateEngine(event, anHyp);
1199 //================================================================================
1201 * \brief Remove elements from sub-meshes.
1202 * \param algoRequiringCleaning - an all-dimensional algorithm whose presence
1203 * causes the cleaning.
1205 //================================================================================
1207 void SMESH_subMesh::cleanDependsOn( SMESH_Algo* algoRequiringCleaning/*=0*/ )
1209 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,
1210 /*complexShapeFirst=*/true);
1211 if ( _father->NbNodes() == 0 )
1213 while ( smIt->more() )
1214 smIt->next()->ComputeStateEngine(CHECK_COMPUTE_STATE);
1216 else if ( !algoRequiringCleaning || !algoRequiringCleaning->SupportSubmeshes() )
1218 while ( smIt->more() )
1219 smIt->next()->ComputeStateEngine(CLEAN);
1221 else if ( algoRequiringCleaning && algoRequiringCleaning->SupportSubmeshes() )
1223 SMESHDS_Mesh* meshDS = _father->GetMeshDS();
1225 // find sub-meshes to keep elements on
1226 set< SMESH_subMesh* > smToKeep;
1227 TopAbs_ShapeEnum prevShapeType = TopAbs_SHAPE;
1228 bool toKeepPrevShapeType = false;
1229 while ( smIt->more() )
1231 SMESH_subMesh* sm = smIt->next();
1232 sm->ComputeStateEngine(CHECK_COMPUTE_STATE);
1233 if ( !sm->IsEmpty() )
1235 const bool sameShapeType = ( prevShapeType == sm->GetSubShape().ShapeType() );
1236 bool keepSubMeshes = ( sameShapeType && toKeepPrevShapeType );
1237 if ( !sameShapeType )
1239 // check if the algo allows presence of global algos of dimension the algo
1240 // can generate it-self
1241 int shapeDim = SMESH_Gen::GetShapeDim( sm->GetSubShape() );
1242 keepSubMeshes = algoRequiringCleaning->NeedLowerHyps( shapeDim );
1243 prevShapeType = sm->GetSubShape().ShapeType();
1244 toKeepPrevShapeType = keepSubMeshes;
1246 if ( !keepSubMeshes )
1248 // look for an algo assigned to sm
1249 bool algoFound = false;
1250 const list<const SMESHDS_Hypothesis*>& hyps = meshDS->GetHypothesis( sm->_subShape );
1251 list<const SMESHDS_Hypothesis*>::const_iterator h = hyps.begin();
1252 for ( ; ( !algoFound && h != hyps.end() ); ++h )
1253 algoFound = ((*h)->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
1254 keepSubMeshes = algoFound;
1256 // remember all sub-meshes of sm
1257 if ( keepSubMeshes )
1259 SMESH_subMeshIteratorPtr smIt2 = getDependsOnIterator(false,true);
1260 while ( smIt2->more() )
1261 smToKeep.insert( smIt2->next() );
1266 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,true);
1267 while ( smIt->more() )
1269 SMESH_subMesh* sm = smIt->next();
1270 if ( !smToKeep.count( sm ))
1271 sm->ComputeStateEngine(CLEAN);
1276 //=============================================================================
1280 //=============================================================================
1282 void SMESH_subMesh::DumpAlgoState(bool isMain)
1284 // if (dim < 1) return;
1287 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1289 map < int, SMESH_subMesh * >::const_iterator itsub;
1290 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1292 SMESH_subMesh *sm = (*itsub).second;
1293 sm->DumpAlgoState(false);
1296 //int type = _subShape.ShapeType();
1297 MESSAGE("dim = " << SMESH_Gen::GetShapeDim(_subShape) <<
1298 " type of shape " << _subShape.ShapeType());
1302 MESSAGE(" AlgoState = NO_ALGO");
1305 MESSAGE(" AlgoState = MISSING_HYP");
1308 MESSAGE(" AlgoState = HYP_OK");
1311 switch (_computeState)
1314 MESSAGE(" ComputeState = NOT_READY");
1316 case READY_TO_COMPUTE:
1317 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1320 MESSAGE(" ComputeState = COMPUTE_OK");
1322 case FAILED_TO_COMPUTE:
1323 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1328 //================================================================================
1330 * \brief Remove nodes and elements bound to submesh
1331 * \param subMesh - submesh containing nodes and elements
1333 //================================================================================
1335 static void cleanSubMesh( SMESH_subMesh * subMesh )
1338 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS()) {
1339 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1340 SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1341 while (ite->more()) {
1342 const SMDS_MeshElement * elt = ite->next();
1343 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1344 //meshDS->RemoveElement(elt);
1345 meshDS->RemoveFreeElement(elt, subMeshDS);
1348 SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1349 while (itn->more()) {
1350 const SMDS_MeshNode * node = itn->next();
1351 //MESSAGE( " RM node: "<<node->GetID());
1352 if ( node->NbInverseElements() == 0 )
1353 meshDS->RemoveFreeNode(node, subMeshDS);
1354 else // for StdMeshers_CompositeSegment_1D: node in one submesh, edge in another
1355 meshDS->RemoveNode(node);
1361 //=============================================================================
1365 //=============================================================================
1367 bool SMESH_subMesh::ComputeStateEngine(int event)
1370 case MODIF_ALGO_STATE:
1372 case COMPUTE_SUBMESH:
1373 //case COMPUTE_CANCELED:
1375 //case SUBMESH_COMPUTED:
1376 //case SUBMESH_RESTORED:
1377 //case SUBMESH_LOADED:
1378 //case MESH_ENTITY_REMOVED:
1379 //case CHECK_COMPUTE_STATE:
1380 _computeError.reset(); break;
1384 if ( event == CLEAN )
1385 _alwaysComputed = false; // Unset 'true' set by MergeNodes() (issue 0022182)
1387 if (_subShape.ShapeType() == TopAbs_VERTEX)
1389 _computeState = READY_TO_COMPUTE;
1390 SMESHDS_SubMesh* smDS = GetSubMeshDS();
1391 if ( smDS && smDS->NbNodes() )
1393 if ( event == CLEAN ) {
1395 cleanSubMesh( this );
1398 _computeState = COMPUTE_OK;
1400 else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
1401 && !_alwaysComputed )
1403 const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
1404 gp_Pnt P = BRep_Tool::Pnt(V);
1405 if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
1406 _father->GetMeshDS()->SetNodeOnVertex(n,_Id);
1407 _computeState = COMPUTE_OK;
1410 if ( event == MODIF_ALGO_STATE )
1414 SMESH_Gen *gen = _father->GetGen();
1415 SMESH_Algo *algo = 0;
1417 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1418 //algo_state oldAlgoState = (algo_state) GetAlgoState();
1420 switch (_computeState)
1423 // ----------------------------------------------------------------------
1428 case MODIF_ALGO_STATE:
1430 if (algo && !algo->NeedDiscreteBoundary())
1431 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1432 if ( _algoState == HYP_OK )
1433 _computeState = READY_TO_COMPUTE;
1435 case COMPUTE: // nothing to do
1436 case COMPUTE_SUBMESH:
1438 case COMPUTE_CANCELED: // nothing to do
1442 removeSubMeshElementsAndNodes();
1444 case SUBMESH_COMPUTED: // nothing to do
1446 case SUBMESH_RESTORED:
1447 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1449 case MESH_ENTITY_REMOVED:
1451 case SUBMESH_LOADED:
1452 loadDependentMeshes();
1453 ComputeSubMeshStateEngine( SUBMESH_LOADED );
1455 case CHECK_COMPUTE_STATE:
1456 if ( IsMeshComputed() )
1457 _computeState = COMPUTE_OK;
1465 // ----------------------------------------------------------------------
1467 case READY_TO_COMPUTE:
1470 case MODIF_ALGO_STATE:
1471 _computeState = NOT_READY;
1475 if (!algo->NeedDiscreteBoundary())
1476 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1477 if ( _algoState == HYP_OK )
1478 _computeState = READY_TO_COMPUTE;
1482 case COMPUTE_SUBMESH:
1486 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1489 MESSAGE("***** verify compute state *****");
1490 _computeState = NOT_READY;
1491 setAlgoState(MISSING_HYP);
1494 TopoDS_Shape shape = _subShape;
1495 int computeCost = GetComputeCost();
1496 // check submeshes needed
1497 if (_father->HasShapeToMesh() ) {
1498 bool subComputed = false, subFailed = false;
1499 if (!algo->OnlyUnaryInput()) {
1500 if ( event == COMPUTE /*&&
1501 ( algo->NeedDiscreteBoundary() || algo->SupportSubmeshes() )*/)
1502 shape = getCollection( gen, algo, subComputed, subFailed, computeCost);
1504 subComputed = SubMeshesComputed( & subFailed );
1507 subComputed = SubMeshesComputed();
1509 ret = ( algo->NeedDiscreteBoundary() ? subComputed :
1510 algo->SupportSubmeshes() ? !subFailed :
1511 ( !subComputed || _father->IsNotConformAllowed() ));
1514 _computeState = FAILED_TO_COMPUTE;
1515 if ( !algo->NeedDiscreteBoundary() && !subFailed )
1517 SMESH_ComputeError::New(COMPERR_BAD_INPUT_MESH,
1518 "Unexpected computed submesh",algo);
1524 //cleanDependants(); for "UseExisting_*D" algos
1525 //removeSubMeshElementsAndNodes();
1526 loadDependentMeshes();
1528 _computeState = FAILED_TO_COMPUTE;
1529 _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
1531 #if OCC_VERSION_LARGE > 0x06010000
1534 algo->InitComputeError();
1535 algo->GetComputeCost() = computeCost;
1537 MemoryReserve aMemoryReserve;
1538 SMDS_Mesh::CheckMemory();
1539 Kernel_Utils::Localizer loc;
1540 if ( !_father->HasShapeToMesh() ) // no shape
1542 SMESH_MesherHelper helper( *_father );
1543 helper.SetSubShape( shape );
1544 helper.SetElementsOnShape( true );
1545 ret = algo->Compute(*_father, &helper );
1549 ret = algo->Compute((*_father), shape);
1551 if ( !_computeError || (/* !ret && */_computeError->IsOK() ) ) // algo can set _computeError of submesh
1552 _computeError = algo->GetComputeError();
1554 catch ( ::SMESH_ComputeError& comperr ) {
1555 cout << " SMESH_ComputeError caught" << endl;
1556 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1557 *_computeError = comperr;
1559 catch ( std::bad_alloc& exc ) {
1560 MESSAGE("std::bad_alloc thrown inside algo->Compute()");
1561 if ( _computeError ) {
1562 _computeError->myName = COMPERR_MEMORY_PB;
1563 //_computeError->myComment = exc.what();
1565 cleanSubMesh( this );
1568 catch ( Standard_OutOfMemory& exc ) {
1569 MESSAGE("Standard_OutOfMemory thrown inside algo->Compute()");
1570 if ( _computeError ) {
1571 _computeError->myName = COMPERR_MEMORY_PB;
1572 //_computeError->myComment = exc.what();
1574 cleanSubMesh( this );
1575 throw std::bad_alloc();
1577 catch (Standard_Failure& ex) {
1578 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1579 _computeError->myName = COMPERR_OCC_EXCEPTION;
1580 _computeError->myComment += ex.DynamicType()->Name();
1581 if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) {
1582 _computeError->myComment += ": ";
1583 _computeError->myComment += ex.GetMessageString();
1586 catch ( SALOME_Exception& S_ex ) {
1587 const int skipSalomeShift = 7; /* to skip "Salome " of
1588 "Salome Exception" prefix returned
1589 by SALOME_Exception::what() */
1590 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1591 _computeError->myName = COMPERR_SLM_EXCEPTION;
1592 _computeError->myComment = S_ex.what() + skipSalomeShift;
1594 catch ( std::exception& exc ) {
1595 if ( !_computeError ) _computeError = SMESH_ComputeError::New();
1596 _computeError->myName = COMPERR_STD_EXCEPTION;
1597 _computeError->myComment = exc.what();
1600 if ( _computeError )
1601 _computeError->myName = COMPERR_EXCEPTION;
1605 // check if an error reported on any sub-shape
1606 bool isComputeErrorSet = !checkComputeError( algo, ret, shape );
1607 if ( isComputeErrorSet )
1609 // check if anything was built
1610 TopExp_Explorer subS(shape, _subShape.ShapeType());
1613 for (; ret && subS.More(); subS.Next())
1614 ret = _father->GetSubMesh( subS.Current() )->IsMeshComputed();
1616 // Set _computeError
1617 if (!ret && !isComputeErrorSet)
1619 for (subS.ReInit(); subS.More(); subS.Next())
1621 SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
1622 if ( !sm->IsMeshComputed() )
1624 if ( !sm->_computeError )
1625 sm->_computeError = SMESH_ComputeError::New();
1626 if ( sm->_computeError->IsOK() )
1627 sm->_computeError->myName = COMPERR_ALGO_FAILED;
1628 sm->_computeState = FAILED_TO_COMPUTE;
1629 sm->_computeError->myAlgo = algo;
1633 if (ret && _computeError && _computeError->myName != COMPERR_WARNING )
1635 _computeError.reset();
1638 // send event SUBMESH_COMPUTED
1640 if ( !algo->NeedDiscreteBoundary() )
1641 // send SUBMESH_COMPUTED to dependants of all sub-meshes of shape
1642 for (subS.ReInit(); subS.More(); subS.Next())
1644 SMESH_subMesh* sm = _father->GetSubMesh( subS.Current() );
1645 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(false,false);
1646 while ( smIt->more() ) {
1648 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1649 sm->updateDependantsState( SUBMESH_COMPUTED );
1655 updateDependantsState( SUBMESH_COMPUTED );
1659 case COMPUTE_CANCELED: // nothing to do
1663 removeSubMeshElementsAndNodes();
1664 _computeState = NOT_READY;
1668 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1670 _computeState = READY_TO_COMPUTE;
1672 setAlgoState(MISSING_HYP);
1675 case SUBMESH_COMPUTED: // nothing to do
1677 case SUBMESH_RESTORED:
1678 // check if a mesh is already computed that may
1679 // happen after retrieval from a file
1680 ComputeStateEngine( CHECK_COMPUTE_STATE );
1681 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1683 if (algo) algo->SubmeshRestored( this );
1685 case MESH_ENTITY_REMOVED:
1687 case SUBMESH_LOADED:
1688 loadDependentMeshes();
1689 ComputeSubMeshStateEngine( SUBMESH_LOADED );
1691 case CHECK_COMPUTE_STATE:
1692 if ( IsMeshComputed() )
1693 _computeState = COMPUTE_OK;
1701 // ----------------------------------------------------------------------
1706 case MODIF_ALGO_STATE:
1707 ComputeStateEngine( CLEAN );
1709 if (algo && !algo->NeedDiscreteBoundary())
1710 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1712 case COMPUTE: // nothing to do
1714 case COMPUTE_CANCELED: // nothing to do
1717 cleanDependants(); // clean sub-meshes, dependant on this one, with event CLEAN
1718 removeSubMeshElementsAndNodes();
1719 _computeState = NOT_READY;
1720 if ( _algoState == HYP_OK )
1721 _computeState = READY_TO_COMPUTE;
1723 case SUBMESH_COMPUTED: // nothing to do
1725 case SUBMESH_RESTORED:
1726 ComputeStateEngine( CHECK_COMPUTE_STATE );
1727 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1729 if (algo) algo->SubmeshRestored( this );
1731 case MESH_ENTITY_REMOVED:
1732 updateDependantsState ( CHECK_COMPUTE_STATE );
1733 ComputeStateEngine ( CHECK_COMPUTE_STATE );
1734 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1736 case CHECK_COMPUTE_STATE:
1737 if ( !IsMeshComputed() ) {
1738 if (_algoState == HYP_OK)
1739 _computeState = READY_TO_COMPUTE;
1741 _computeState = NOT_READY;
1744 case SUBMESH_LOADED:
1745 // already treated event, thanks to which _computeState == COMPUTE_OK
1753 // ----------------------------------------------------------------------
1755 case FAILED_TO_COMPUTE:
1758 case MODIF_ALGO_STATE:
1760 ComputeStateEngine( CLEAN );
1762 if (algo && !algo->NeedDiscreteBoundary())
1763 cleanDependsOn( algo ); // clean sub-meshes with event CLEAN
1764 if (_algoState == HYP_OK)
1765 _computeState = READY_TO_COMPUTE;
1767 _computeState = NOT_READY;
1769 case COMPUTE: // nothing to do
1770 case COMPUTE_SUBMESH:
1772 case COMPUTE_CANCELED:
1775 algo->CancelCompute();
1779 cleanDependants(); // submeshes dependent on me should be cleaned as well
1780 removeSubMeshElementsAndNodes();
1782 case SUBMESH_COMPUTED: // allow retry compute
1783 if (_algoState == HYP_OK)
1784 _computeState = READY_TO_COMPUTE;
1786 _computeState = NOT_READY;
1788 case SUBMESH_RESTORED:
1789 ComputeSubMeshStateEngine( SUBMESH_RESTORED );
1791 case MESH_ENTITY_REMOVED:
1793 case CHECK_COMPUTE_STATE:
1794 if ( IsMeshComputed() )
1795 _computeState = COMPUTE_OK;
1797 if (_algoState == HYP_OK)
1798 _computeState = READY_TO_COMPUTE;
1800 _computeState = NOT_READY;
1802 // case SUBMESH_LOADED:
1810 // ----------------------------------------------------------------------
1816 notifyListenersOnEvent( event, COMPUTE_EVENT );
1822 //=============================================================================
1826 //=============================================================================
1828 bool SMESH_subMesh::Evaluate(MapShapeNbElems& aResMap)
1830 _computeError.reset();
1834 if (_subShape.ShapeType() == TopAbs_VERTEX) {
1835 vector<int> aVec(SMDSEntity_Last,0);
1836 aVec[SMDSEntity_Node] = 1;
1837 aResMap.insert(make_pair(this,aVec));
1841 //SMESH_Gen *gen = _father->GetGen();
1842 SMESH_Algo *algo = 0;
1843 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1846 if(algo && !aResMap.count(this) )
1848 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1849 if (!ret) return false;
1851 if (_father->HasShapeToMesh() && algo->NeedDiscreteBoundary())
1853 // check submeshes needed
1854 bool subMeshEvaluated = true;
1855 int dimToCheck = SMESH_Gen::GetShapeDim( _subShape ) - 1;
1856 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,/*complexShapeFirst=*/true);
1857 while ( smIt->more() && subMeshEvaluated )
1859 SMESH_subMesh* sm = smIt->next();
1860 int dim = SMESH_Gen::GetShapeDim( sm->GetSubShape() );
1861 if (dim < dimToCheck) break; // the rest subMeshes are all of less dimension
1862 const vector<int> & nbs = aResMap[ sm ];
1863 subMeshEvaluated = (std::accumulate( nbs.begin(), nbs.end(), 0 ) > 0 );
1865 if ( !subMeshEvaluated )
1868 _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
1869 ret = algo->Evaluate((*_father), _subShape, aResMap);
1871 aResMap.insert( make_pair( this,vector<int>(0)));
1878 //=======================================================================
1880 * \brief Update compute_state by _computeError and send proper events to
1881 * dependent submeshes
1882 * \retval bool - true if _computeError is NOT set
1884 //=======================================================================
1886 bool SMESH_subMesh::checkComputeError(SMESH_Algo* theAlgo,
1887 const bool theComputeOK,
1888 const TopoDS_Shape& theShape)
1890 bool noErrors = true;
1892 if ( !theShape.IsNull() )
1894 // Check state of submeshes
1895 if ( !theAlgo->NeedDiscreteBoundary())
1897 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1898 while ( smIt->more() )
1899 if ( !smIt->next()->checkComputeError( theAlgo, theComputeOK ))
1903 // Check state of neighbours
1904 if ( !theAlgo->OnlyUnaryInput() &&
1905 theShape.ShapeType() == TopAbs_COMPOUND &&
1906 !theShape.IsSame( _subShape ))
1908 for (TopoDS_Iterator subIt( theShape ); subIt.More(); subIt.Next()) {
1909 SMESH_subMesh* sm = _father->GetSubMesh( subIt.Value() );
1911 if ( !sm->checkComputeError( theAlgo, theComputeOK, sm->GetSubShape() ))
1913 updateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1920 // Set my _computeState
1922 if ( !_computeError || _computeError->IsOK() )
1924 // no error description is set to this sub-mesh, check if any mesh is computed
1925 _computeState = IsMeshComputed() ? COMPUTE_OK : FAILED_TO_COMPUTE;
1926 if ( _computeState != COMPUTE_OK )
1928 if ( _subShape.ShapeType() == TopAbs_EDGE &&
1929 BRep_Tool::Degenerated( TopoDS::Edge( _subShape )) )
1930 _computeState = COMPUTE_OK;
1931 else if ( theComputeOK )
1932 _computeError = SMESH_ComputeError::New(COMPERR_NO_MESH_ON_SHAPE,"",theAlgo);
1936 if ( _computeError && !_computeError->IsOK() )
1938 if ( !_computeError->myAlgo )
1939 _computeError->myAlgo = theAlgo;
1943 text << theAlgo->GetName() << " failed on sub-shape #" << _Id << " with error ";
1944 if (_computeError->IsCommon() )
1945 text << _computeError->CommonName();
1947 text << _computeError->myName;
1948 if ( _computeError->myComment.size() > 0 )
1949 text << " \"" << _computeError->myComment << "\"";
1953 _computeState = _computeError->IsKO() ? FAILED_TO_COMPUTE : COMPUTE_OK;
1961 //=======================================================================
1962 //function : updateSubMeshState
1964 //=======================================================================
1966 void SMESH_subMesh::updateSubMeshState(const compute_state theState)
1968 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(false,false);
1969 while ( smIt->more() )
1970 smIt->next()->_computeState = theState;
1973 //=======================================================================
1974 //function : ComputeSubMeshStateEngine
1976 //=======================================================================
1978 void SMESH_subMesh::ComputeSubMeshStateEngine(int event, const bool includeSelf)
1980 SMESH_subMeshIteratorPtr smIt = getDependsOnIterator(includeSelf,false);
1981 while ( smIt->more() )
1982 smIt->next()->ComputeStateEngine(event);
1985 //=======================================================================
1986 //function : updateDependantsState
1988 //=======================================================================
1990 void SMESH_subMesh::updateDependantsState(const compute_event theEvent)
1992 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1993 for (; it.More(); it.Next())
1995 const TopoDS_Shape& ancestor = it.Value();
1996 if ( SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor))
1997 aSubMesh->ComputeStateEngine( theEvent );
2001 //=============================================================================
2005 //=============================================================================
2007 void SMESH_subMesh::cleanDependants()
2009 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
2011 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
2012 for (; it.More(); it.Next())
2014 const TopoDS_Shape& ancestor = it.Value();
2015 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
2016 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
2017 // will erase mesh on other shapes in a compound
2018 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
2019 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
2021 !aSubMesh->IsEmpty() ) // prevent infinite CLEAN via event lesteners
2022 aSubMesh->ComputeStateEngine(CLEAN);
2028 //=============================================================================
2032 //=============================================================================
2034 void SMESH_subMesh::removeSubMeshElementsAndNodes()
2036 cleanSubMesh( this );
2038 // algo may bind a submesh not to _subShape, eg 3D algo
2039 // sets nodes on SHELL while _subShape may be SOLID
2041 int dim = SMESH_Gen::GetShapeDim( _subShape );
2042 int type = _subShape.ShapeType() + 1;
2043 for ( ; type <= TopAbs_EDGE; type++) {
2044 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
2046 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
2047 for ( ; exp.More(); exp.Next() )
2048 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
2055 //=======================================================================
2056 //function : getCollection
2057 //purpose : return a shape containing all sub-shapes of the MainShape that can be
2058 // meshed at once along with _subShape
2059 //=======================================================================
2061 TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * theGen,
2062 SMESH_Algo* theAlgo,
2063 bool & theSubComputed,
2064 bool & theSubFailed,
2065 int & theComputeCost)
2067 theSubComputed = SubMeshesComputed( & theSubFailed );
2069 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
2071 if ( mainShape.IsSame( _subShape ))
2074 const bool ignoreAuxiliaryHyps = false;
2075 list<const SMESHDS_Hypothesis*> aUsedHyp =
2076 theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
2078 // put in a compound all shapes with the same hypothesis assigned
2079 // and a good ComputState
2081 TopoDS_Compound aCompound;
2082 BRep_Builder aBuilder;
2083 aBuilder.MakeCompound( aCompound );
2087 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
2088 for ( ; anExplorer.More(); anExplorer.Next() )
2090 const TopoDS_Shape& S = anExplorer.Current();
2091 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
2092 if ( subMesh->GetComputeState() != NOT_READY )
2093 theComputeCost += subMesh->GetComputeCost();
2094 if ( subMesh == this )
2096 aBuilder.Add( aCompound, S );
2098 else if ( subMesh->GetComputeState() == READY_TO_COMPUTE )
2100 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
2101 if (strcmp( anAlgo->GetName(), theAlgo->GetName()) == 0 && // same algo
2102 anAlgo->GetUsedHypothesis( *_father, S, ignoreAuxiliaryHyps ) == aUsedHyp) // same hyps
2103 aBuilder.Add( aCompound, S );
2104 if ( !subMesh->SubMeshesComputed() )
2105 theSubComputed = false;
2107 if ( !theAlgo->NeedDiscreteBoundary() )
2109 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(/*includeSelf=*/false);
2110 while ( smIt->more() )
2112 SMESH_subMesh* sm = smIt->next();
2113 if ( sm->GetComputeState() != NOT_READY &&
2115 theComputeCost += sm->GetComputeCost();
2123 //=======================================================================
2124 //function : getSimilarAttached
2125 //purpose : return a hypothesis attached to theShape.
2126 // If theHyp is provided, similar but not same hypotheses
2127 // is returned; else only applicable ones having theHypType
2129 //=======================================================================
2131 const SMESH_Hypothesis* SMESH_subMesh::getSimilarAttached(const TopoDS_Shape& theShape,
2132 const SMESH_Hypothesis * theHyp,
2133 const int theHypType)
2135 SMESH_HypoFilter hypoKind;
2136 hypoKind.Init( hypoKind.HasType( theHyp ? theHyp->GetType() : theHypType ));
2138 hypoKind.And ( hypoKind.HasDim( theHyp->GetDim() ));
2139 hypoKind.AndNot( hypoKind.Is( theHyp ));
2140 if ( theHyp->IsAuxiliary() )
2141 hypoKind.And( hypoKind.HasName( theHyp->GetName() ));
2143 hypoKind.AndNot( hypoKind.IsAuxiliary());
2146 hypoKind.And( hypoKind.IsApplicableTo( theShape ));
2149 return _father->GetHypothesis( theShape, hypoKind, false );
2152 //=======================================================================
2153 //function : CheckConcurentHypothesis
2154 //purpose : check if there are several applicable hypothesis attached to
2156 //=======================================================================
2158 SMESH_Hypothesis::Hypothesis_Status
2159 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
2161 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
2163 // is there local hypothesis on me?
2164 if ( getSimilarAttached( _subShape, 0, theHypType ) )
2165 return SMESH_Hypothesis::HYP_OK;
2168 TopoDS_Shape aPrevWithHyp;
2169 const SMESH_Hypothesis* aPrevHyp = 0;
2170 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
2171 for (; it.More(); it.Next())
2173 const TopoDS_Shape& ancestor = it.Value();
2174 const SMESH_Hypothesis* hyp = getSimilarAttached( ancestor, 0, theHypType );
2177 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
2179 aPrevWithHyp = ancestor;
2182 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
2183 return SMESH_Hypothesis::HYP_CONCURENT;
2185 return SMESH_Hypothesis::HYP_OK;
2188 return SMESH_Hypothesis::HYP_OK;
2191 //================================================================================
2193 * \brief Constructor of OwnListenerData
2195 //================================================================================
2197 SMESH_subMesh::OwnListenerData::OwnListenerData( SMESH_subMesh* sm, EventListener* el):
2199 myMeshID( sm ? sm->GetFather()->GetId() : -1 ),
2200 mySubMeshID( sm ? sm->GetId() : -1 ),
2205 //================================================================================
2207 * \brief Sets an event listener and its data to a submesh
2208 * \param listener - the listener to store
2209 * \param data - the listener data to store
2210 * \param where - the submesh to store the listener and it's data
2212 * It remembers the submesh where it puts the listener in order to delete
2213 * them when HYP_OK algo_state is lost
2214 * After being set, event listener is notified on each event of where submesh.
2216 //================================================================================
2218 void SMESH_subMesh::SetEventListener(EventListener* listener,
2219 EventListenerData* data,
2220 SMESH_subMesh* where)
2222 if ( listener && where ) {
2223 where->setEventListener( listener, data );
2224 _ownListeners.push_back( OwnListenerData( where, listener ));
2228 //================================================================================
2230 * \brief Sets an event listener and its data to a submesh
2231 * \param listener - the listener to store
2232 * \param data - the listener data to store
2234 * After being set, event listener is notified on each event of a submesh.
2236 //================================================================================
2238 void SMESH_subMesh::setEventListener(EventListener* listener,
2239 EventListenerData* data)
2241 map< EventListener*, EventListenerData* >::iterator l_d =
2242 _eventListeners.find( listener );
2243 if ( l_d != _eventListeners.end() ) {
2244 EventListenerData* curData = l_d->second;
2245 if ( curData && curData != data && curData->IsDeletable() )
2251 for ( l_d = _eventListeners.begin(); l_d != _eventListeners.end(); ++l_d )
2252 if ( listener->GetName() == l_d->first->GetName() )
2254 EventListenerData* curData = l_d->second;
2255 if ( curData && curData != data && curData->IsDeletable() )
2257 if ( l_d->first->IsDeletable() )
2259 _eventListeners.erase( l_d );
2262 _eventListeners.insert( make_pair( listener, data ));
2266 //================================================================================
2268 * \brief Return an event listener data
2269 * \param listener - the listener whose data is
2270 * \retval EventListenerData* - found data, maybe NULL
2272 //================================================================================
2274 EventListenerData* SMESH_subMesh::GetEventListenerData(EventListener* listener) const
2276 map< EventListener*, EventListenerData* >::const_iterator l_d =
2277 _eventListeners.find( listener );
2278 if ( l_d != _eventListeners.end() )
2283 //================================================================================
2285 * \brief Return an event listener data
2286 * \param listenerName - the listener name
2287 * \retval EventListenerData* - found data, maybe NULL
2289 //================================================================================
2291 EventListenerData* SMESH_subMesh::GetEventListenerData(const string& listenerName) const
2293 map< EventListener*, EventListenerData* >::const_iterator l_d = _eventListeners.begin();
2294 for ( ; l_d != _eventListeners.end(); ++l_d )
2295 if ( listenerName == l_d->first->GetName() )
2300 //================================================================================
2302 * \brief Notify stored event listeners on the occured event
2303 * \param event - algo_event or compute_event itself
2304 * \param eventType - algo_event or compute_event
2305 * \param hyp - hypothesis, if eventType is algo_event
2307 //================================================================================
2309 void SMESH_subMesh::notifyListenersOnEvent( const int event,
2310 const event_type eventType,
2311 SMESH_Hypothesis* hyp)
2313 list< pair< EventListener*, EventListenerData* > > eventListeners( _eventListeners.begin(),
2314 _eventListeners.end());
2315 list< pair< EventListener*, EventListenerData* > >::iterator l_d = eventListeners.begin();
2316 for ( ; l_d != eventListeners.end(); ++l_d )
2318 std::pair< EventListener*, EventListenerData* > li_da = *l_d;
2319 if ( !_eventListeners.count( li_da.first )) continue;
2321 if ( li_da.first->myBusySM.insert( this ).second )
2323 const bool isDeletable = li_da.first->IsDeletable();
2325 li_da.first->ProcessEvent( event, eventType, this, li_da.second, hyp );
2327 if ( !isDeletable || _eventListeners.count( li_da.first ))
2328 li_da.first->myBusySM.erase( this ); // a listener is hopefully not dead
2333 //================================================================================
2335 * \brief Unregister the listener and delete listener's data
2336 * \param listener - the event listener
2338 //================================================================================
2340 void SMESH_subMesh::DeleteEventListener(EventListener* listener)
2342 map< EventListener*, EventListenerData* >::iterator l_d =
2343 _eventListeners.find( listener );
2344 if ( l_d != _eventListeners.end() && l_d->first )
2346 if ( l_d->second && l_d->second->IsDeletable() )
2350 l_d->first->myBusySM.erase( this );
2351 if ( l_d->first->IsDeletable() )
2353 l_d->first->BeforeDelete( this, l_d->second );
2356 _eventListeners.erase( l_d );
2360 //================================================================================
2362 * \brief Delete event listeners depending on algo of this submesh
2364 //================================================================================
2366 void SMESH_subMesh::deleteOwnListeners()
2368 list< OwnListenerData >::iterator d;
2369 for ( d = _ownListeners.begin(); d != _ownListeners.end(); ++d )
2371 if ( !_father->MeshExists( d->myMeshID ))
2373 if ( _father->GetId() == d->myMeshID && !_father->GetSubMeshContaining( d->mySubMeshID ))
2375 d->mySubMesh->DeleteEventListener( d->myListener );
2377 _ownListeners.clear();
2380 //=======================================================================
2381 //function : loadDependentMeshes
2382 //purpose : loads dependent meshes on SUBMESH_LOADED event
2383 //=======================================================================
2385 void SMESH_subMesh::loadDependentMeshes()
2387 list< OwnListenerData >::iterator d;
2388 for ( d = _ownListeners.begin(); d != _ownListeners.end(); ++d )
2389 if ( _father != d->mySubMesh->_father )
2390 d->mySubMesh->_father->Load();
2392 // map< EventListener*, EventListenerData* >::iterator l_d = _eventListeners.begin();
2393 // for ( ; l_d != _eventListeners.end(); ++l_d )
2394 // if ( l_d->second )
2396 // const list<SMESH_subMesh*>& smList = l_d->second->mySubMeshes;
2397 // list<SMESH_subMesh*>::const_iterator sm = smList.begin();
2398 // for ( ; sm != smList.end(); ++sm )
2399 // if ( _father != (*sm)->_father )
2400 // (*sm)->_father->Load();
2404 //================================================================================
2406 * \brief Do something on a certain event
2407 * \param event - algo_event or compute_event itself
2408 * \param eventType - algo_event or compute_event
2409 * \param subMesh - the submesh where the event occures
2410 * \param data - listener data stored in the subMesh
2411 * \param hyp - hypothesis, if eventType is algo_event
2413 * The base implementation translates CLEAN event to the subMesh
2414 * stored in listener data. Also it sends SUBMESH_COMPUTED event in case of
2415 * successful COMPUTE event.
2417 //================================================================================
2419 void SMESH_subMeshEventListener::ProcessEvent(const int event,
2420 const int eventType,
2421 SMESH_subMesh* subMesh,
2422 EventListenerData* data,
2423 const SMESH_Hypothesis* /*hyp*/)
2425 if ( data && !data->mySubMeshes.empty() &&
2426 eventType == SMESH_subMesh::COMPUTE_EVENT)
2428 ASSERT( data->mySubMeshes.front() != subMesh );
2429 list<SMESH_subMesh*>::iterator smIt = data->mySubMeshes.begin();
2430 list<SMESH_subMesh*>::iterator smEnd = data->mySubMeshes.end();
2432 case SMESH_subMesh::CLEAN:
2433 for ( ; smIt != smEnd; ++ smIt)
2434 (*smIt)->ComputeStateEngine( event );
2436 case SMESH_subMesh::COMPUTE:
2437 case SMESH_subMesh::COMPUTE_SUBMESH:
2438 if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
2439 for ( ; smIt != smEnd; ++ smIt)
2440 (*smIt)->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
2449 //================================================================================
2451 * \brief Iterator over submeshes and optionally prepended or appended one
2453 //================================================================================
2455 struct _Iterator : public SMDS_Iterator<SMESH_subMesh*>
2457 _Iterator(SMDS_Iterator<SMESH_subMesh*>* subIt,
2458 SMESH_subMesh* prepend,
2459 SMESH_subMesh* append): myIt(subIt),myAppend(append)
2461 myCur = prepend ? prepend : myIt->more() ? myIt->next() : append;
2462 if ( myCur == append ) append = 0;
2464 /// Return true if and only if there are other object in this iterator
2469 /// Return the current object and step to the next one
2470 virtual SMESH_subMesh* next()
2472 SMESH_subMesh* res = myCur;
2473 if ( myIt->more() ) { myCur = myIt->next(); }
2474 else { myCur = myAppend; myAppend = 0; }
2481 SMESH_subMesh *myAppend, *myCur;
2482 SMDS_Iterator<SMESH_subMesh*> *myIt;
2486 //================================================================================
2488 * \brief Return iterator on the submeshes this one depends on
2489 * \param includeSelf - this submesh to be returned also
2490 * \param reverse - if true, complex shape submeshes go first
2492 //================================================================================
2494 SMESH_subMeshIteratorPtr SMESH_subMesh::getDependsOnIterator(const bool includeSelf,
2495 const bool reverse) const
2497 SMESH_subMesh *me = (SMESH_subMesh*) this;
2498 SMESH_subMesh *prepend=0, *append=0;
2499 if ( includeSelf ) {
2500 if ( reverse ) prepend = me;
2503 typedef map < int, SMESH_subMesh * > TMap;
2506 return SMESH_subMeshIteratorPtr
2507 ( new _Iterator( new SMDS_mapReverseIterator<TMap>( me->DependsOn() ), prepend, append ));
2510 return SMESH_subMeshIteratorPtr
2511 ( new _Iterator( new SMDS_mapIterator<TMap>( me->DependsOn() ), prepend, append ));
2515 //================================================================================
2517 * \brief Find common submeshes (based on shared sub-shapes with other
2518 * \param theOther submesh to check
2519 * \param theSetOfCommon set of common submesh
2521 //================================================================================
2523 bool SMESH_subMesh::FindIntersection(const SMESH_subMesh* theOther,
2524 std::set<const SMESH_subMesh*>& theSetOfCommon ) const
2526 int oldNb = theSetOfCommon.size();
2527 // check main submeshes
2528 const map <int, SMESH_subMesh*>::const_iterator otherEnd = theOther->_mapDepend.end();
2529 if ( theOther->_mapDepend.find(this->GetId()) != otherEnd )
2530 theSetOfCommon.insert( this );
2531 if ( _mapDepend.find(theOther->GetId()) != _mapDepend.end() )
2532 theSetOfCommon.insert( theOther );
2533 // check common submeshes
2534 map <int, SMESH_subMesh*>::const_iterator mapIt = _mapDepend.begin();
2535 for( ; mapIt != _mapDepend.end(); mapIt++ )
2536 if ( theOther->_mapDepend.find((*mapIt).first) != otherEnd )
2537 theSetOfCommon.insert( (*mapIt).second );
2538 return oldNb < theSetOfCommon.size();