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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_subMesh.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_Hypothesis.hxx"
34 #include "SMESH_Algo.hxx"
35 #include "SMESH_HypoFilter.hxx"
37 #include "utilities.h"
40 #include <BRep_Builder.hxx>
43 #include <TopoDS_Compound.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_ListOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
53 #include <BRep_Tool.hxx>
57 //=============================================================================
59 * default constructor:
61 //=============================================================================
63 SMESH_subMesh::SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
64 const TopoDS_Shape & aSubShape)
66 _subShape = aSubShape;
68 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
71 _dependenceAnalysed = false;
73 if (_subShape.ShapeType() == TopAbs_VERTEX)
76 _computeState = READY_TO_COMPUTE;
81 _computeState = NOT_READY;
85 //=============================================================================
89 //=============================================================================
91 SMESH_subMesh::~SMESH_subMesh()
93 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
97 //=============================================================================
101 //=============================================================================
103 int SMESH_subMesh::GetId() const
105 //MESSAGE("SMESH_subMesh::GetId");
109 //=============================================================================
113 //=============================================================================
115 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
117 //MESSAGE("SMESH_subMesh::GetSubMeshDS");
118 if (_subMeshDS==NULL)
120 //MESSAGE("subMesh pointer still null, trying to get it...");
121 _subMeshDS = _meshDS->MeshElements(_subShape); // may be null ...
122 if (_subMeshDS==NULL)
124 MESSAGE("problem... subMesh still empty");
126 //NRI throw SALOME_Exception(LOCALIZED(subMesh still empty));
132 //=============================================================================
136 //=============================================================================
138 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
140 if ( !GetSubMeshDS() )
141 _meshDS->NewSubMesh( _meshDS->ShapeToIndex( _subShape ) );
143 return GetSubMeshDS();
146 //=============================================================================
150 //=============================================================================
152 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
154 //MESSAGE("SMESH_subMesh::GetFirstToCompute");
155 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
156 SMESH_subMesh *firstToCompute = 0;
158 map < int, SMESH_subMesh * >::const_iterator itsub;
159 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
161 SMESH_subMesh *sm = (*itsub).second;
162 // SCRUTE(sm->GetId());
163 // SCRUTE(sm->GetComputeState());
164 bool readyToCompute = (sm->GetComputeState() == READY_TO_COMPUTE);
168 //SCRUTE(sm->GetId());
174 return firstToCompute; // a subMesh of this
176 if (_computeState == READY_TO_COMPUTE)
180 return 0; // nothing to compute
183 //=============================================================================
187 //=============================================================================
189 bool SMESH_subMesh::SubMeshesComputed()
191 //MESSAGE("SMESH_subMesh::SubMeshesComputed");
192 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
194 bool subMeshesComputed = true;
195 map < int, SMESH_subMesh * >::const_iterator itsub;
196 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
198 SMESH_subMesh *sm = (*itsub).second;
200 const TopoDS_Shape & ss = sm->GetSubShape();
201 int type = ss.ShapeType();
202 bool computeOk = (sm->GetComputeState() == COMPUTE_OK);
205 subMeshesComputed = false;
209 case TopAbs_COMPOUND:
211 MESSAGE("The not computed sub mesh is a COMPOUND");
214 case TopAbs_COMPSOLID:
216 MESSAGE("The not computed sub mesh is a COMPSOLID");
221 MESSAGE("The not computed sub mesh is a SHEL");
226 MESSAGE("The not computed sub mesh is a WIRE");
231 MESSAGE("The not computed sub mesh is a SOLID");
236 MESSAGE("The not computed sub mesh is a FACE");
241 MESSAGE("The not computed sub mesh is a EDGE");
246 MESSAGE("The not computed sub mesh is of unknown type");
254 return subMeshesComputed;
257 //=============================================================================
261 //=============================================================================
263 bool SMESH_subMesh::SubMeshesReady()
265 MESSAGE("SMESH_subMesh::SubMeshesReady");
266 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
268 bool subMeshesReady = true;
269 map < int, SMESH_subMesh * >::const_iterator itsub;
270 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
272 SMESH_subMesh *sm = (*itsub).second;
273 bool computeOk = ((sm->GetComputeState() == COMPUTE_OK)
274 || (sm->GetComputeState() == READY_TO_COMPUTE));
277 subMeshesReady = false;
282 return subMeshesReady;
285 //=============================================================================
287 * Construct dependence on first level subMeshes. complex shapes (compsolid,
288 * shell, wire) are not analysed the same way as simple shapes (solid, face,
290 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
291 * with possible multiples occurences. Multiples occurences corresponds to
292 * internal frontiers within shapes of the collection and must not be keeped.
293 * See FinalizeDependence.
295 //=============================================================================
297 const map < int, SMESH_subMesh * >&SMESH_subMesh::DependsOn()
299 if (_dependenceAnalysed)
302 //MESSAGE("SMESH_subMesh::DependsOn");
304 int type = _subShape.ShapeType();
308 case TopAbs_COMPOUND:
310 //MESSAGE("compound");
311 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
314 InsertDependence(exp.Current());
316 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More();
319 InsertDependence(exp.Current()); //only shell not in solid
321 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();
324 InsertDependence(exp.Current());
326 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();
329 InsertDependence(exp.Current());
333 case TopAbs_COMPSOLID:
335 //MESSAGE("compsolid");
336 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
339 InsertDependence(exp.Current());
346 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
349 InsertDependence(exp.Current());
356 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
359 InsertDependence(exp.Current());
366 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
369 InsertDependence(exp.Current());
376 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
379 InsertDependence(exp.Current());
386 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More();
389 InsertDependence(exp.Current());
402 _dependenceAnalysed = true;
406 //=============================================================================
408 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
410 //=============================================================================
412 void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape)
414 //MESSAGE("SMESH_subMesh::InsertDependence");
415 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
416 int type = aSubShape.ShapeType();
417 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
418 int cle = aSubMesh->GetId();
419 cle += 10000000 * ordType; // sort map by ordType then index
420 if (_mapDepend.find(cle) == _mapDepend.end())
422 _mapDepend[cle] = aSubMesh;
423 const map < int, SMESH_subMesh * >&subMap = aSubMesh->DependsOn();
424 map < int, SMESH_subMesh * >::const_iterator im;
425 for (im = subMap.begin(); im != subMap.end(); im++)
427 int clesub = (*im).first;
428 SMESH_subMesh *sm = (*im).second;
429 if (_mapDepend.find(clesub) == _mapDepend.end())
430 _mapDepend[clesub] = sm;
436 //=============================================================================
440 //=============================================================================
442 const TopoDS_Shape & SMESH_subMesh::GetSubShape()
444 //MESSAGE("SMESH_subMesh::GetSubShape");
449 //=======================================================================
450 //function : CanAddHypothesis
451 //purpose : return true if theHypothesis can be attached to me:
452 // its dimention is checked
453 //=======================================================================
455 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
457 int aHypDim = theHypothesis->GetDim();
458 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
459 if ( aHypDim <= aShapeDim )
461 // if ( aHypDim < aShapeDim )
462 // return ( _father->IsMainShape( _subShape ));
467 //=======================================================================
468 //function : IsApplicableHypotesis
470 //=======================================================================
472 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
473 const TopAbs_ShapeEnum theShapeType)
475 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
477 return ( theHypothesis->GetShapeType() & (1<< theShapeType));
481 switch ( theShapeType ) {
482 case TopAbs_EDGE: aShapeDim = 1; break;
483 case TopAbs_FACE: aShapeDim = 2; break;
484 case TopAbs_SHELL:aShapeDim = 3; break;
485 case TopAbs_SOLID:aShapeDim = 3; break;
486 // case TopAbs_VERTEX:
488 // case TopAbs_COMPSOLID:
489 // case TopAbs_COMPOUND:
490 default: return false;
493 return ( theHypothesis->GetDim() == aShapeDim );
496 //=============================================================================
500 //=============================================================================
502 SMESH_Hypothesis::Hypothesis_Status
503 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
505 // MESSAGE("SMESH_subMesh::AlgoStateEngine");
506 //SCRUTE(_algoState);
509 // **** les retour des evenement shape sont significatifs
510 // (add ou remove fait ou non)
511 // le retour des evenement father n'indiquent pas que add ou remove fait
513 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
515 int dim = SMESH_Gen::GetShapeDim(_subShape);
520 if (event == ADD_HYP || event == ADD_ALGO)
521 return SMESH_Hypothesis::HYP_BAD_DIM; // do not allow to assign any hyp
523 return SMESH_Hypothesis::HYP_OK;
526 SMESH_Gen* gen =_father->GetGen();
528 int oldAlgoState = _algoState;
529 bool modifiedHyp = false; // if set to true, force event MODIF_ALGO_STATE
530 // in ComputeStateEngine
532 // ----------------------
533 // check mesh conformity
534 // ----------------------
535 if (event == ADD_ALGO)
537 if (IsApplicableHypotesis( anHyp ) &&
538 !_father->IsNotConformAllowed() &&
539 !IsConform( static_cast< SMESH_Algo* >( anHyp )))
540 return SMESH_Hypothesis::HYP_NOTCONFORM;
543 // ----------------------------------
544 // add a hypothesis to DS if possible
545 // ----------------------------------
546 if (event == ADD_HYP || event == ADD_ALGO)
548 if ( ! CanAddHypothesis( anHyp ))
549 return SMESH_Hypothesis::HYP_BAD_DIM;
551 if ( GetSimilarAttached( _subShape, anHyp ) )
552 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
554 if ( !_meshDS->AddHypothesis(_subShape, anHyp))
555 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
557 // Serve Propagation of 1D hypothesis
558 if (event == ADD_HYP) {
559 bool isPropagationOk = true;
560 string hypName = anHyp->GetName();
562 if (hypName == "Propagation") {
563 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
564 TopTools_MapOfShape aMap;
565 for (; exp.More(); exp.Next()) {
566 if (aMap.Add(exp.Current())) {
567 if (!_father->BuildPropagationChain(exp.Current())) {
568 isPropagationOk = false;
573 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
574 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
575 TopTools_MapOfShape aMap;
576 for (; exp.More(); exp.Next()) {
577 if (aMap.Add(exp.Current())) {
578 TopoDS_Shape aMainEdge;
579 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
580 isPropagationOk = _father->RebuildPropagationChains();
581 } else if (_father->IsPropagationHypothesis(exp.Current())) {
582 isPropagationOk = _father->BuildPropagationChain(exp.Current());
590 if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) {
591 ret = SMESH_Hypothesis::HYP_CONCURENT;
593 } // Serve Propagation of 1D hypothesis
596 // --------------------------
597 // remove a hypothesis from DS
598 // --------------------------
599 if (event == REMOVE_HYP || event == REMOVE_ALGO)
601 if (!_meshDS->RemoveHypothesis(_subShape, anHyp))
602 return SMESH_Hypothesis::HYP_OK; // nothing changes
604 // Serve Propagation of 1D hypothesis
605 if (event == REMOVE_HYP)
607 bool isPropagationOk = true;
608 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
609 if ( propagFilter.IsOk( anHyp, _subShape ))
611 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
612 TopTools_MapOfShape aMap;
613 for (; exp.More(); exp.Next()) {
614 if (aMap.Add(exp.Current()) &&
615 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
616 // no more Propagation on the current edge
617 if (!_father->RemovePropagationChain(exp.Current())) {
618 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
622 // rebuild propagation chains, because removing one
623 // chain can resolve concurention, existing before
624 isPropagationOk = _father->RebuildPropagationChains();
626 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
628 isPropagationOk = _father->RebuildPropagationChains();
631 if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) {
632 ret = SMESH_Hypothesis::HYP_CONCURENT;
634 } // Serve Propagation of 1D hypothesis
637 // ------------------
638 // analyse algo state
639 // ------------------
640 if (!IsApplicableHypotesis( anHyp ))
641 return ret; // not applicable hypotheses do not change algo state
646 // ----------------------------------------------------------------------
653 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
655 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
656 SetAlgoState(HYP_OK);
658 SetAlgoState(MISSING_HYP);
667 case ADD_FATHER_ALGO: { // Algo just added in father
668 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
670 if ( algo == anHyp ) {
671 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
672 SetAlgoState(HYP_OK);
674 SetAlgoState(MISSING_HYP);
678 case REMOVE_FATHER_HYP:
680 case REMOVE_FATHER_ALGO: {
681 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
684 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
685 SetAlgoState(HYP_OK);
687 SetAlgoState(MISSING_HYP);
697 // ----------------------------------------------------------------------
703 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
705 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
706 SetAlgoState(HYP_OK);
707 if (SMESH_Hypothesis::IsStatusFatal( ret ))
708 _meshDS->RemoveHypothesis(_subShape, anHyp);
709 else if (!_father->IsUsedHypothesis( anHyp, _subShape ))
711 _meshDS->RemoveHypothesis(_subShape, anHyp);
712 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
716 case ADD_ALGO: { //already existing algo : on father ?
717 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
719 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
720 SetAlgoState(HYP_OK);
722 SetAlgoState(MISSING_HYP);
727 case REMOVE_ALGO: { // perhaps a father algo applies ?
728 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
729 if (algo == NULL) // no more algo applying on subShape...
731 SetAlgoState(NO_ALGO);
735 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
736 SetAlgoState(HYP_OK);
738 SetAlgoState(MISSING_HYP);
742 case ADD_FATHER_HYP: {
743 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
745 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
746 SetAlgoState(HYP_OK);
748 SetAlgoState(MISSING_HYP);
751 case ADD_FATHER_ALGO: { // new father algo
752 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
754 if ( algo == anHyp ) {
755 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
756 SetAlgoState(HYP_OK);
758 SetAlgoState(MISSING_HYP);
762 case REMOVE_FATHER_HYP: // nothing to do
764 case REMOVE_FATHER_ALGO: {
765 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
766 if (algo == NULL) // no more applying algo on father
768 SetAlgoState(NO_ALGO);
772 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
773 SetAlgoState(HYP_OK);
775 SetAlgoState(MISSING_HYP);
785 // ----------------------------------------------------------------------
791 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
793 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
795 //two applying algo on the same shape not allowed
796 _meshDS->RemoveHypothesis(_subShape, anHyp);
797 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
798 // ret should be fatal: anHyp was not added
799 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
801 else if (SMESH_Hypothesis::IsStatusFatal( ret ))
803 _meshDS->RemoveHypothesis(_subShape, anHyp);
805 else if (!_father->IsUsedHypothesis( anHyp, _subShape ))
807 _meshDS->RemoveHypothesis(_subShape, anHyp);
808 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
816 case ADD_ALGO: { //already existing algo : on father ?
817 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
818 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
819 SetAlgoState(HYP_OK);
821 SetAlgoState(MISSING_HYP);
826 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
828 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
829 SetAlgoState(HYP_OK);
831 SetAlgoState(MISSING_HYP);
835 case REMOVE_ALGO: { // perhaps a father algo applies ?
836 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
837 if (algo == NULL) // no more algo applying on subShape...
839 SetAlgoState(NO_ALGO);
843 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
844 SetAlgoState(HYP_OK);
846 SetAlgoState(MISSING_HYP);
847 // check if same algo remains
848 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
853 case ADD_FATHER_HYP: { // new father hypothesis ?
854 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
856 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
858 SetAlgoState(HYP_OK);
859 if (_father->IsUsedHypothesis( anHyp, _subShape )) // new Hyp
863 SetAlgoState(MISSING_HYP);
866 case ADD_FATHER_ALGO: { // a new algo on father
867 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
868 if ( algo == anHyp ) {
869 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
870 SetAlgoState(HYP_OK);
872 SetAlgoState(MISSING_HYP);
877 case REMOVE_FATHER_HYP: {
878 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
880 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
881 SetAlgoState(HYP_OK);
883 SetAlgoState(MISSING_HYP);
884 // is there the same local hyp or maybe a new father algo applied?
885 if ( !GetSimilarAttached( _subShape, anHyp ) )
889 case REMOVE_FATHER_ALGO: {
890 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
891 if (algo == NULL) // no more applying algo on father
893 SetAlgoState(NO_ALGO);
897 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
898 SetAlgoState(HYP_OK);
900 SetAlgoState(MISSING_HYP);
901 // is there the same local algo or maybe a new father algo applied?
902 if ( !GetSimilarAttached( _subShape, anHyp ))
913 // ----------------------------------------------------------------------
920 if ((_algoState != oldAlgoState) || modifiedHyp)
921 ComputeStateEngine(MODIF_ALGO_STATE);
927 //=======================================================================
928 //function : IsConform
929 //purpose : check if a conform mesh will be produced by the Algo
930 //=======================================================================
932 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
934 // MESSAGE( "SMESH_subMesh::IsConform" );
936 if ( !theAlgo ) return false;
938 // check only algo that doesn't NeedDescretBoundary(): because mesh made
939 // on a sub-shape will be ignored by theAlgo
940 if ( theAlgo->NeedDescretBoundary() )
943 SMESH_Gen* gen =_father->GetGen();
945 // only local algo is to be checked
946 if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
949 // check algo attached to adjacent shapes
951 // loop on one level down sub-meshes
952 TopoDS_Iterator itsub( _subShape );
953 for (; itsub.More(); itsub.Next())
955 // loop on adjacent subShapes
956 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
957 for (; it.More(); it.Next())
959 const TopoDS_Shape& adjacent = it.Value();
960 if ( _subShape.IsSame( adjacent )) continue;
961 if ( adjacent.ShapeType() != _subShape.ShapeType())
964 // check algo attached to smAdjacent
965 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
968 !algo->NeedDescretBoundary() /*&&
969 !gen->IsGlobalHypothesis( algo, *_father )*/)
970 return false; // NOT CONFORM MESH WILL BE PRODUCED
977 //=============================================================================
981 //=============================================================================
983 void SMESH_subMesh::SetAlgoState(int state)
985 // if (state != _oldAlgoState)
986 // int retc = ComputeStateEngine(MODIF_ALGO_STATE);
990 //=============================================================================
994 //=============================================================================
995 SMESH_Hypothesis::Hypothesis_Status
996 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
997 SMESH_Hypothesis * anHyp)
999 //MESSAGE("SMESH_subMesh::SubMeshesAlgoStateEngine");
1000 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1001 //EAP: a wire (dim==1) should notify edges (dim==1)
1002 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1003 if (/*EAP:dim > 1*/ _subShape.ShapeType() < TopAbs_EDGE )
1005 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1007 map < int, SMESH_subMesh * >::const_iterator itsub;
1008 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1010 SMESH_subMesh *sm = (*itsub).second;
1011 SMESH_Hypothesis::Hypothesis_Status ret2 =
1012 sm->AlgoStateEngine(event, anHyp);
1020 //=============================================================================
1024 //=============================================================================
1026 void SMESH_subMesh::CleanDependsOn()
1028 MESSAGE("SMESH_subMesh::CleanDependsOn");
1029 // **** parcourir les ancetres dans l'ordre de dépendance
1031 ComputeStateEngine(CLEAN);
1033 const map < int, SMESH_subMesh * >&dependson = DependsOn();
1034 map < int, SMESH_subMesh * >::const_iterator its;
1035 for (its = dependson.begin(); its != dependson.end(); its++)
1037 SMESH_subMesh *sm = (*its).second;
1038 // SCRUTE((*its).first);
1039 sm->ComputeStateEngine(CLEAN);
1043 //=============================================================================
1047 //=============================================================================
1049 void SMESH_subMesh::DumpAlgoState(bool isMain)
1051 int dim = SMESH_Gen::GetShapeDim(_subShape);
1052 // if (dim < 1) return;
1055 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1057 map < int, SMESH_subMesh * >::const_iterator itsub;
1058 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1060 SMESH_subMesh *sm = (*itsub).second;
1061 sm->DumpAlgoState(false);
1064 int type = _subShape.ShapeType();
1065 MESSAGE("dim = " << dim << " type of shape " << type);
1069 MESSAGE(" AlgoState = NO_ALGO");
1072 MESSAGE(" AlgoState = MISSING_HYP");
1075 MESSAGE(" AlgoState = HYP_OK");
1078 switch (_computeState)
1081 MESSAGE(" ComputeState = NOT_READY");
1083 case READY_TO_COMPUTE:
1084 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1087 MESSAGE(" ComputeState = COMPUTE_OK");
1089 case FAILED_TO_COMPUTE:
1090 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1095 //=============================================================================
1099 //=============================================================================
1101 bool SMESH_subMesh::ComputeStateEngine(int event)
1103 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1104 //SCRUTE(_computeState);
1107 int dim = SMESH_Gen::GetShapeDim(_subShape);
1111 if ( IsMeshComputed() )
1112 _computeState = COMPUTE_OK;
1114 _computeState = READY_TO_COMPUTE;
1117 SMESH_Gen *gen = _father->GetGen();
1118 SMESH_Algo *algo = 0;
1120 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1122 switch (_computeState)
1125 // ----------------------------------------------------------------------
1130 case MODIF_HYP: // nothing to do
1132 case MODIF_ALGO_STATE:
1133 if (_algoState == HYP_OK)
1135 _computeState = READY_TO_COMPUTE;
1138 case COMPUTE: // nothing to do
1141 RemoveSubMeshElementsAndNodes();
1146 case SUBMESH_COMPUTED: // nothing to do
1148 case SUBMESH_RESTORED:
1149 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1151 case MESH_ENTITY_REMOVED:
1153 case CHECK_COMPUTE_STATE:
1154 if ( IsMeshComputed() )
1155 _computeState = COMPUTE_OK;
1163 // ----------------------------------------------------------------------
1165 case READY_TO_COMPUTE:
1168 case MODIF_HYP: // nothing to do
1170 case MODIF_ALGO_STATE:
1171 _computeState = NOT_READY;
1172 algo = gen->GetAlgo((*_father), _subShape);
1175 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1177 _computeState = READY_TO_COMPUTE;
1182 algo = gen->GetAlgo((*_father), _subShape);
1184 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1187 MESSAGE("***** verify compute state *****");
1188 _computeState = NOT_READY;
1191 // check submeshes needed
1192 if (algo->NeedDescretBoundary())
1193 ret = SubMeshesComputed();
1196 MESSAGE("Some SubMeshes not computed");
1197 _computeState = FAILED_TO_COMPUTE;
1200 RemoveSubMeshElementsAndNodes();
1202 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput())
1203 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1205 ret = algo->Compute((*_father), _subShape);
1209 MESSAGE("problem in algo execution: failed to compute");
1210 _computeState = FAILED_TO_COMPUTE;
1211 if (!algo->NeedDescretBoundary())
1212 UpdateSubMeshState( FAILED_TO_COMPUTE );
1215 // Show vertices location of a failed shape
1216 TopExp_Explorer exp( _subShape, TopAbs_VERTEX);
1217 for ( ; exp.More(); exp.Next() ) {
1218 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( exp.Current() )));
1219 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1226 _computeState = COMPUTE_OK;
1227 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1228 if (!algo->NeedDescretBoundary())
1229 UpdateSubMeshState( COMPUTE_OK );
1234 RemoveSubMeshElementsAndNodes();
1235 _computeState = NOT_READY;
1236 algo = gen->GetAlgo((*_father), _subShape);
1239 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1241 _computeState = READY_TO_COMPUTE;
1247 case SUBMESH_COMPUTED: // nothing to do
1249 case SUBMESH_RESTORED:
1250 // check if a mesh is already computed that may
1251 // happen after retrieval from a file
1252 ComputeStateEngine( CHECK_COMPUTE_STATE );
1253 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1255 case MESH_ENTITY_REMOVED:
1257 case CHECK_COMPUTE_STATE:
1258 if ( IsMeshComputed() )
1259 _computeState = COMPUTE_OK;
1267 // ----------------------------------------------------------------------
1273 CleanDependants(); // recursive recall with event CLEANDEP
1274 algo = gen->GetAlgo((*_father), _subShape);
1275 if (algo && !algo->NeedDescretBoundary())
1276 CleanDependsOn(); // remove sub-mesh with event CLEANDEP
1278 case MODIF_ALGO_STATE:
1279 CleanDependants(); // recursive recall with event CLEANDEP
1280 algo = gen->GetAlgo((*_father), _subShape);
1281 if (algo && !algo->NeedDescretBoundary())
1282 CleanDependsOn(); // remove sub-mesh with event CLEANDEP
1284 case COMPUTE: // nothing to do
1287 RemoveSubMeshElementsAndNodes();
1288 _computeState = NOT_READY;
1289 algo = gen->GetAlgo((*_father), _subShape);
1292 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1294 _computeState = READY_TO_COMPUTE;
1298 CleanDependants(); // recursive recall with event CLEANDEP
1300 case SUBMESH_COMPUTED: // nothing to do
1302 case SUBMESH_RESTORED:
1303 ComputeStateEngine( CHECK_COMPUTE_STATE );
1304 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1306 case MESH_ENTITY_REMOVED:
1307 UpdateDependantsState( CHECK_COMPUTE_STATE );
1308 ComputeStateEngine( CHECK_COMPUTE_STATE );
1309 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1311 case CHECK_COMPUTE_STATE:
1312 if ( !IsMeshComputed() )
1313 if (_algoState == HYP_OK)
1314 _computeState = READY_TO_COMPUTE;
1316 _computeState = NOT_READY;
1324 // ----------------------------------------------------------------------
1326 case FAILED_TO_COMPUTE:
1330 if (_algoState == HYP_OK)
1331 _computeState = READY_TO_COMPUTE;
1333 _computeState = NOT_READY;
1335 case MODIF_ALGO_STATE:
1336 if (_algoState == HYP_OK)
1337 _computeState = READY_TO_COMPUTE;
1339 _computeState = NOT_READY;
1341 case COMPUTE: // nothing to do
1344 RemoveSubMeshElementsAndNodes();
1345 if (_algoState == HYP_OK)
1346 _computeState = READY_TO_COMPUTE;
1348 _computeState = NOT_READY;
1353 case SUBMESH_COMPUTED: // allow retry compute
1354 if (_algoState == HYP_OK)
1355 _computeState = READY_TO_COMPUTE;
1357 _computeState = NOT_READY;
1359 case SUBMESH_RESTORED:
1360 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1362 case MESH_ENTITY_REMOVED:
1364 case CHECK_COMPUTE_STATE:
1365 if ( IsMeshComputed() )
1366 _computeState = COMPUTE_OK;
1368 if (_algoState == HYP_OK)
1369 _computeState = READY_TO_COMPUTE;
1371 _computeState = NOT_READY;
1379 // ----------------------------------------------------------------------
1385 //SCRUTE(_computeState);
1389 //=======================================================================
1390 //function : ApplyToCollection
1391 //purpose : Apply theAlgo to all subshapes in theCollection
1392 //=======================================================================
1394 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1395 const TopoDS_Shape& theCollection)
1397 MESSAGE("SMESH_subMesh::ApplyToCollection");
1398 ASSERT ( !theAlgo->NeedDescretBoundary() );
1403 ret = theAlgo->Compute( *_father, theCollection );
1405 // set _computeState of subshapes
1406 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1407 for ( ; anExplorer.More(); anExplorer.Next() )
1409 const TopoDS_Shape& aSubShape = anExplorer.Current();
1410 SMESH_subMesh* subMesh = _father->GetSubMeshContaining( aSubShape );
1415 subMesh->_computeState = COMPUTE_OK;
1416 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1417 subMesh->UpdateSubMeshState( COMPUTE_OK );
1421 subMesh->_computeState = FAILED_TO_COMPUTE;
1429 //=======================================================================
1430 //function : UpdateSubMeshState
1432 //=======================================================================
1434 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1436 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1437 map<int, SMESH_subMesh*>::const_iterator itsub;
1438 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1440 SMESH_subMesh* sm = (*itsub).second;
1441 sm->_computeState = theState;
1445 //=======================================================================
1446 //function : ComputeSubMeshStateEngine
1448 //=======================================================================
1450 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1452 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1453 map<int, SMESH_subMesh*>::const_iterator itsub;
1454 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1456 SMESH_subMesh* sm = (*itsub).second;
1457 sm->ComputeStateEngine(event);
1461 //=======================================================================
1462 //function : UpdateDependantsState
1464 //=======================================================================
1466 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1468 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1469 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1470 for (; it.More(); it.Next())
1472 const TopoDS_Shape& ancestor = it.Value();
1473 SMESH_subMesh *aSubMesh =
1474 _father->GetSubMeshContaining(ancestor);
1476 aSubMesh->ComputeStateEngine( theEvent );
1480 //=============================================================================
1484 //=============================================================================
1486 void SMESH_subMesh::CleanDependants()
1488 //MESSAGE("SMESH_subMesh::CleanDependants: shape type " << _subShape.ShapeType() );
1490 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1491 for (; it.More(); it.Next())
1493 const TopoDS_Shape& ancestor = it.Value();
1494 //MESSAGE("ancestor shape type " << ancestor.ShapeType() );
1495 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1497 aSubMesh->ComputeStateEngine(CLEANDEP);
1499 ComputeStateEngine(CLEAN);
1503 //=============================================================================
1507 //=============================================================================
1509 static void removeSubMesh( SMESHDS_Mesh * meshDS, const TopoDS_Shape& subShape)
1511 SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(subShape);
1512 if (subMeshDS!=NULL)
1514 SMDS_ElemIteratorPtr ite=subMeshDS->GetElements();
1517 const SMDS_MeshElement * elt = ite->next();
1518 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1519 meshDS->RemoveElement(elt);
1522 SMDS_NodeIteratorPtr itn=subMeshDS->GetNodes();
1525 const SMDS_MeshNode * node = itn->next();
1526 //MESSAGE( " RM node: "<<node->GetID());
1527 meshDS->RemoveNode(node);
1532 //=============================================================================
1536 //=============================================================================
1538 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1540 //SCRUTE(_subShape.ShapeType());
1542 removeSubMesh( _meshDS, _subShape );
1544 // algo may bind a submesh not to _subShape, eg 3D algo
1545 // sets nodes on SHELL while _subShape may be SOLID
1547 int dim = SMESH_Gen::GetShapeDim( _subShape );
1548 int type = _subShape.ShapeType() + 1;
1549 for ( ; type <= TopAbs_EDGE; type++)
1550 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1552 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1553 for ( ; exp.More(); exp.Next() )
1554 removeSubMesh( _meshDS, exp.Current() );
1560 //=======================================================================
1561 //function : IsMeshComputed
1562 //purpose : check if _subMeshDS contains mesh elements
1563 //=======================================================================
1565 bool SMESH_subMesh::IsMeshComputed() const
1567 // algo may bind a submesh not to _subShape, eg 3D algo
1568 // sets nodes on SHELL while _subShape may be SOLID
1570 int dim = SMESH_Gen::GetShapeDim( _subShape );
1571 int type = _subShape.ShapeType();
1572 for ( ; type <= TopAbs_VERTEX; type++) {
1573 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1575 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1576 for ( ; exp.More(); exp.Next() )
1578 SMESHDS_SubMesh * subMeshDS = _meshDS->MeshElements( exp.Current() );
1579 if ( subMeshDS != NULL &&
1580 (subMeshDS->GetElements()->more() || subMeshDS->GetNodes()->more())) {
1593 //=======================================================================
1594 //function : GetCollection
1595 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1596 // meshed at once along with _subShape
1597 //=======================================================================
1599 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1601 MESSAGE("SMESH_subMesh::GetCollection");
1602 ASSERT (!theAlgo->NeedDescretBoundary());
1604 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1606 if ( mainShape.IsSame( _subShape ))
1609 list<const SMESHDS_Hypothesis*> aUsedHyp =
1610 theAlgo->GetUsedHypothesis( *_father, _subShape ); // copy
1612 // put in a compound all shapes with the same hypothesis assigned
1613 // and a good ComputState
1615 TopoDS_Compound aCompound;
1616 BRep_Builder aBuilder;
1617 aBuilder.MakeCompound( aCompound );
1619 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1620 for ( ; anExplorer.More(); anExplorer.Next() )
1622 const TopoDS_Shape& S = anExplorer.Current();
1623 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1624 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1626 if (subMesh->GetComputeState() == READY_TO_COMPUTE &&
1627 anAlgo == theAlgo &&
1628 anAlgo->GetUsedHypothesis( *_father, S ) == aUsedHyp)
1630 aBuilder.Add( aCompound, S );
1637 //=======================================================================
1638 //function : GetSimilarAttached
1639 //purpose : return nb of hypotheses attached to theShape.
1640 // If theHyp is provided, similar but not same hypotheses
1641 // are countered; else only applicable ones having theHypType
1643 //=======================================================================
1645 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1646 const SMESH_Hypothesis * theHyp,
1647 const int theHypType)
1649 SMESH_HypoFilter filter;
1650 filter.Init( SMESH_HypoFilter::HasType( theHyp ? theHyp->GetType() : theHypType ));
1652 filter.And( SMESH_HypoFilter::HasDim( theHyp->GetDim() ));
1653 filter.AndNot( SMESH_HypoFilter::Is( theHyp ));
1656 filter.And( SMESH_HypoFilter::IsApplicableTo( theShape ));
1658 return _father->GetHypothesis( theShape, filter, false );
1661 //=======================================================================
1662 //function : CheckConcurentHypothesis
1663 //purpose : check if there are several applicable hypothesis attached to
1665 //=======================================================================
1667 SMESH_Hypothesis::Hypothesis_Status
1668 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1670 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1672 // is there local hypothesis on me?
1673 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1674 return SMESH_Hypothesis::HYP_OK;
1677 TopoDS_Shape aPrevWithHyp;
1678 const SMESH_Hypothesis* aPrevHyp = 0;
1679 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1680 for (; it.More(); it.Next())
1682 const TopoDS_Shape& ancestor = it.Value();
1683 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1686 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1688 aPrevWithHyp = ancestor;
1691 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1692 return SMESH_Hypothesis::HYP_CONCURENT;
1694 return SMESH_Hypothesis::HYP_OK;
1697 return SMESH_Hypothesis::HYP_OK;