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>
51 #include <BRep_Tool.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
56 #include <Standard_Failure.hxx>
57 #include <Standard_ErrorHandler.hxx>
59 //=============================================================================
61 * default constructor:
63 //=============================================================================
65 SMESH_subMesh::SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
66 const TopoDS_Shape & aSubShape)
68 _subShape = aSubShape;
70 _subMeshDS = meshDS->MeshElements(_subShape); // may be null ...
73 _dependenceAnalysed = false;
75 if (_subShape.ShapeType() == TopAbs_VERTEX)
78 _computeState = READY_TO_COMPUTE;
83 _computeState = NOT_READY;
87 //=============================================================================
91 //=============================================================================
93 SMESH_subMesh::~SMESH_subMesh()
95 MESSAGE("SMESH_subMesh::~SMESH_subMesh");
99 //=============================================================================
103 //=============================================================================
105 int SMESH_subMesh::GetId() const
107 //MESSAGE("SMESH_subMesh::GetId");
111 //=============================================================================
115 //=============================================================================
117 SMESHDS_SubMesh * SMESH_subMesh::GetSubMeshDS()
119 // submesh appears in DS only when a mesher set nodes and elements on it
120 if (_subMeshDS==NULL)
122 _subMeshDS = _meshDS->MeshElements(_subShape); // may be null ...
123 // if (_subMeshDS==NULL)
125 // MESSAGE("problem... subMesh still empty");
131 //=============================================================================
135 //=============================================================================
137 SMESHDS_SubMesh* SMESH_subMesh::CreateSubMeshDS()
139 if ( !GetSubMeshDS() )
140 _meshDS->NewSubMesh( _meshDS->ShapeToIndex( _subShape ) );
142 return GetSubMeshDS();
145 //=============================================================================
149 //=============================================================================
151 SMESH_subMesh *SMESH_subMesh::GetFirstToCompute()
153 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
154 SMESH_subMesh *firstToCompute = 0;
156 map < int, SMESH_subMesh * >::const_iterator itsub;
157 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
159 SMESH_subMesh *sm = (*itsub).second;
160 bool readyToCompute = (sm->GetComputeState() == READY_TO_COMPUTE);
169 return firstToCompute; // a subMesh of this
171 if (_computeState == READY_TO_COMPUTE)
175 return 0; // nothing to compute
178 //=============================================================================
182 //=============================================================================
184 bool SMESH_subMesh::SubMeshesComputed()
186 //MESSAGE("SMESH_subMesh::SubMeshesComputed");
187 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
189 bool subMeshesComputed = true;
190 map < int, SMESH_subMesh * >::const_iterator itsub;
191 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
193 SMESH_subMesh *sm = (*itsub).second;
194 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
196 // There are some tricks with compute states, e.g. Penta_3D leaves
197 // one face with READY_TO_COMPUTE state in order to be able to
198 // recompute 3D when a locale triangle hypo changes (see PAL7428).
199 // So we check if mesh is really present
200 //bool computeOk = (sm->GetComputeState() == COMPUTE_OK);
201 bool computeOk = ( ds && ( ds->GetNodes()->more() || ds->GetElements()->more() ));
204 const TopoDS_Shape & ss = sm->GetSubShape();
205 int type = ss.ShapeType();
207 subMeshesComputed = false;
211 case TopAbs_COMPOUND:
213 MESSAGE("The not computed sub mesh is a COMPOUND");
216 case TopAbs_COMPSOLID:
218 MESSAGE("The not computed sub mesh is a COMPSOLID");
223 MESSAGE("The not computed sub mesh is a SHEL");
228 MESSAGE("The not computed sub mesh is a WIRE");
233 MESSAGE("The not computed sub mesh is a SOLID");
238 MESSAGE("The not computed sub mesh is a FACE");
243 MESSAGE("The not computed sub mesh is a EDGE");
248 MESSAGE("The not computed sub mesh is of unknown type");
256 return subMeshesComputed;
259 //=============================================================================
263 //=============================================================================
265 bool SMESH_subMesh::SubMeshesReady()
267 MESSAGE("SMESH_subMesh::SubMeshesReady");
268 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
270 bool subMeshesReady = true;
271 map < int, SMESH_subMesh * >::const_iterator itsub;
272 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
274 SMESH_subMesh *sm = (*itsub).second;
275 bool computeOk = ((sm->GetComputeState() == COMPUTE_OK)
276 || (sm->GetComputeState() == READY_TO_COMPUTE));
279 subMeshesReady = false;
284 return subMeshesReady;
287 //=============================================================================
289 * Construct dependence on first level subMeshes. complex shapes (compsolid,
290 * shell, wire) are not analysed the same way as simple shapes (solid, face,
292 * For collection shapes (compsolid, shell, wire) prepare a list of submeshes
293 * with possible multiples occurences. Multiples occurences corresponds to
294 * internal frontiers within shapes of the collection and must not be keeped.
295 * See FinalizeDependence.
297 //=============================================================================
299 const map < int, SMESH_subMesh * >&SMESH_subMesh::DependsOn()
301 if (_dependenceAnalysed)
304 //MESSAGE("SMESH_subMesh::DependsOn");
306 int type = _subShape.ShapeType();
310 case TopAbs_COMPOUND:
312 //MESSAGE("compound");
313 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
316 InsertDependence(exp.Current());
318 for (TopExp_Explorer exp(_subShape, TopAbs_SHELL, TopAbs_SOLID); exp.More();
321 InsertDependence(exp.Current()); //only shell not in solid
323 for (TopExp_Explorer exp(_subShape, TopAbs_FACE, TopAbs_SHELL); exp.More();
326 InsertDependence(exp.Current());
328 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE, TopAbs_FACE); exp.More();
331 InsertDependence(exp.Current());
335 case TopAbs_COMPSOLID:
337 //MESSAGE("compsolid");
338 for (TopExp_Explorer exp(_subShape, TopAbs_SOLID); exp.More();
341 InsertDependence(exp.Current());
348 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
351 InsertDependence(exp.Current());
358 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
361 InsertDependence(exp.Current());
368 for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
371 InsertDependence(exp.Current());
378 for (TopExp_Explorer exp(_subShape, TopAbs_EDGE); exp.More();
381 InsertDependence(exp.Current());
388 for (TopExp_Explorer exp(_subShape, TopAbs_VERTEX); exp.More();
391 InsertDependence(exp.Current());
404 _dependenceAnalysed = true;
408 //=============================================================================
410 * For simple Shapes (solid, face, edge): add subMesh into dependence list.
412 //=============================================================================
414 void SMESH_subMesh::InsertDependence(const TopoDS_Shape aSubShape)
416 //MESSAGE("SMESH_subMesh::InsertDependence");
417 SMESH_subMesh *aSubMesh = _father->GetSubMesh(aSubShape);
418 int type = aSubShape.ShapeType();
419 int ordType = 9 - type; // 2 = Vertex, 8 = CompSolid
420 int cle = aSubMesh->GetId();
421 cle += 10000000 * ordType; // sort map by ordType then index
422 if ( _mapDepend.find( cle ) == _mapDepend.end())
424 _mapDepend[cle] = aSubMesh;
425 const map < int, SMESH_subMesh * > & subMap = aSubMesh->DependsOn();
426 _mapDepend.insert( subMap.begin(), subMap.end() );
430 //=============================================================================
434 //=============================================================================
436 const TopoDS_Shape & SMESH_subMesh::GetSubShape()
438 //MESSAGE("SMESH_subMesh::GetSubShape");
443 //=======================================================================
444 //function : CanAddHypothesis
445 //purpose : return true if theHypothesis can be attached to me:
446 // its dimention is checked
447 //=======================================================================
449 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
451 int aHypDim = theHypothesis->GetDim();
452 int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
453 if ( aHypDim <= aShapeDim )
455 // if ( aHypDim < aShapeDim )
456 // return ( _father->IsMainShape( _subShape ));
461 //=======================================================================
462 //function : IsApplicableHypotesis
464 //=======================================================================
466 bool SMESH_subMesh::IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
467 const TopAbs_ShapeEnum theShapeType)
469 if ( theHypothesis->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
471 return ( theHypothesis->GetShapeType() & (1<< theShapeType));
474 switch ( theShapeType ) {
479 return SMESH_Gen::GetShapeDim( theShapeType ) == theHypothesis->GetDim();
481 // case TopAbs_COMPSOLID:
482 // case TopAbs_COMPOUND:
488 //=============================================================================
492 //=============================================================================
494 SMESH_Hypothesis::Hypothesis_Status
495 SMESH_subMesh::AlgoStateEngine(int event, SMESH_Hypothesis * anHyp)
497 // MESSAGE("SMESH_subMesh::AlgoStateEngine");
498 //SCRUTE(_algoState);
501 // **** les retour des evenement shape sont significatifs
502 // (add ou remove fait ou non)
503 // le retour des evenement father n'indiquent pas que add ou remove fait
505 SMESH_Hypothesis::Hypothesis_Status aux_ret, ret = SMESH_Hypothesis::HYP_OK;
507 int dim = SMESH_Gen::GetShapeDim(_subShape);
512 if (event == ADD_HYP || event == ADD_ALGO)
513 return SMESH_Hypothesis::HYP_BAD_DIM; // do not allow to assign any hyp
515 return SMESH_Hypothesis::HYP_OK;
518 SMESH_Gen* gen =_father->GetGen();
520 int oldAlgoState = _algoState;
521 bool modifiedHyp = false; // if set to true, force event MODIF_ALGO_STATE
522 // in ComputeStateEngine
524 // ----------------------
525 // check mesh conformity
526 // ----------------------
527 if (event == ADD_ALGO)
529 if (IsApplicableHypotesis( anHyp ) &&
530 !_father->IsNotConformAllowed() &&
531 !IsConform( static_cast< SMESH_Algo* >( anHyp )))
532 return SMESH_Hypothesis::HYP_NOTCONFORM;
535 // ----------------------------------
536 // add a hypothesis to DS if possible
537 // ----------------------------------
538 if (event == ADD_HYP || event == ADD_ALGO)
540 if ( ! CanAddHypothesis( anHyp ))
541 return SMESH_Hypothesis::HYP_BAD_DIM;
543 if ( GetSimilarAttached( _subShape, anHyp ) )
544 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
546 if ( !_meshDS->AddHypothesis(_subShape, anHyp))
547 return SMESH_Hypothesis::HYP_ALREADY_EXIST;
549 // Serve Propagation of 1D hypothesis
550 if (event == ADD_HYP) {
551 bool isPropagationOk = true;
552 string hypName = anHyp->GetName();
554 if (hypName == "Propagation") {
555 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
556 TopTools_MapOfShape aMap;
557 for (; exp.More(); exp.Next()) {
558 if (aMap.Add(exp.Current())) {
559 if (!_father->BuildPropagationChain(exp.Current())) {
560 isPropagationOk = false;
565 else if (anHyp->GetDim() == 1) { // Only 1D hypothesis can be propagated
566 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
567 TopTools_MapOfShape aMap;
568 for (; exp.More(); exp.Next()) {
569 if (aMap.Add(exp.Current())) {
570 TopoDS_Shape aMainEdge;
571 if (_father->IsPropagatedHypothesis(exp.Current(), aMainEdge)) {
572 isPropagationOk = _father->RebuildPropagationChains();
573 } else if (_father->IsPropagationHypothesis(exp.Current())) {
574 isPropagationOk = _father->BuildPropagationChain(exp.Current());
582 if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) {
583 ret = SMESH_Hypothesis::HYP_CONCURENT;
585 } // Serve Propagation of 1D hypothesis
588 // --------------------------
589 // remove a hypothesis from DS
590 // --------------------------
591 if (event == REMOVE_HYP || event == REMOVE_ALGO)
593 if (!_meshDS->RemoveHypothesis(_subShape, anHyp))
594 return SMESH_Hypothesis::HYP_OK; // nothing changes
596 // Serve Propagation of 1D hypothesis
597 if (event == REMOVE_HYP)
599 bool isPropagationOk = true;
600 SMESH_HypoFilter propagFilter( SMESH_HypoFilter::HasName( "Propagation" ));
601 if ( propagFilter.IsOk( anHyp, _subShape ))
603 TopExp_Explorer exp (_subShape, TopAbs_EDGE);
604 TopTools_MapOfShape aMap;
605 for (; exp.More(); exp.Next()) {
606 if (aMap.Add(exp.Current()) &&
607 !_father->GetHypothesis( exp.Current(), propagFilter, true )) {
608 // no more Propagation on the current edge
609 if (!_father->RemovePropagationChain(exp.Current())) {
610 return SMESH_Hypothesis::HYP_UNKNOWN_FATAL;
614 // rebuild propagation chains, because removing one
615 // chain can resolve concurention, existing before
616 isPropagationOk = _father->RebuildPropagationChains();
618 else if (anHyp->GetDim() == 1) // Only 1D hypothesis can be propagated
620 isPropagationOk = _father->RebuildPropagationChains();
623 if (!isPropagationOk && ret < SMESH_Hypothesis::HYP_CONCURENT) {
624 ret = SMESH_Hypothesis::HYP_CONCURENT;
626 } // Serve Propagation of 1D hypothesis
629 // ------------------
630 // analyse algo state
631 // ------------------
632 if (!IsApplicableHypotesis( anHyp ))
633 return ret; // not applicable hypotheses do not change algo state
638 // ----------------------------------------------------------------------
645 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
647 if (algo->CheckHypothesis((*_father),_subShape, aux_ret))
648 SetAlgoState(HYP_OK);
650 SetAlgoState(MISSING_HYP);
659 case ADD_FATHER_ALGO: { // Algo just added in father
660 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
662 if ( algo == anHyp ) {
663 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret))
664 SetAlgoState(HYP_OK);
666 SetAlgoState(MISSING_HYP);
670 case REMOVE_FATHER_HYP:
672 case REMOVE_FATHER_ALGO: {
673 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
676 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
677 SetAlgoState(HYP_OK);
679 SetAlgoState(MISSING_HYP);
689 // ----------------------------------------------------------------------
695 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
697 if ( algo->CheckHypothesis((*_father),_subShape, ret ))
698 SetAlgoState(HYP_OK);
699 if (SMESH_Hypothesis::IsStatusFatal( ret ))
700 _meshDS->RemoveHypothesis(_subShape, anHyp);
701 else if (!_father->IsUsedHypothesis( anHyp, _subShape ))
703 _meshDS->RemoveHypothesis(_subShape, anHyp);
704 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
708 case ADD_ALGO: { //already existing algo : on father ?
709 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
711 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))// ignore hyp status
712 SetAlgoState(HYP_OK);
714 SetAlgoState(MISSING_HYP);
719 case REMOVE_ALGO: { // perhaps a father algo applies ?
720 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
721 if (algo == NULL) // no more algo applying on subShape...
723 SetAlgoState(NO_ALGO);
727 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
728 SetAlgoState(HYP_OK);
730 SetAlgoState(MISSING_HYP);
734 case ADD_FATHER_HYP: {
735 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
737 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
738 SetAlgoState(HYP_OK);
740 SetAlgoState(MISSING_HYP);
743 case ADD_FATHER_ALGO: { // new father algo
744 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
746 if ( algo == anHyp ) {
747 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
748 SetAlgoState(HYP_OK);
750 SetAlgoState(MISSING_HYP);
754 case REMOVE_FATHER_HYP: // nothing to do
756 case REMOVE_FATHER_ALGO: {
757 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
758 if (algo == NULL) // no more applying algo on father
760 SetAlgoState(NO_ALGO);
764 if ( algo->CheckHypothesis((*_father),_subShape , aux_ret ))
765 SetAlgoState(HYP_OK);
767 SetAlgoState(MISSING_HYP);
777 // ----------------------------------------------------------------------
783 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
785 if (!algo->CheckHypothesis((*_father),_subShape, ret ))
787 if ( !SMESH_Hypothesis::IsStatusFatal( ret ))
788 // ret should be fatal: anHyp was not added
789 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
791 else if (!_father->IsUsedHypothesis( anHyp, _subShape ))
792 ret = SMESH_Hypothesis::HYP_INCOMPATIBLE;
794 if (SMESH_Hypothesis::IsStatusFatal( ret ))
796 MESSAGE("do not add extra hypothesis");
797 _meshDS->RemoveHypothesis(_subShape, anHyp);
805 case ADD_ALGO: { //already existing algo : on father ?
806 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
807 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
808 // check if algo changes
810 f.Init( SMESH_HypoFilter::IsAlgo() );
811 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
812 f.AndNot( SMESH_HypoFilter::Is( algo ));
813 const SMESH_Hypothesis * prevAlgo = _father->GetHypothesis( _subShape, f, true );
815 string(algo->GetName()) != string(prevAlgo->GetName()) )
819 SetAlgoState(MISSING_HYP);
823 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
825 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
826 SetAlgoState(HYP_OK);
828 SetAlgoState(MISSING_HYP);
832 case REMOVE_ALGO: { // perhaps a father algo applies ?
833 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
834 if (algo == NULL) // no more algo applying on subShape...
836 SetAlgoState(NO_ALGO);
840 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
841 // check if algo remains
842 if ( anHyp != algo && strcmp( anHyp->GetName(), algo->GetName()) )
846 SetAlgoState(MISSING_HYP);
850 case ADD_FATHER_HYP: { // new father hypothesis ?
851 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
853 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret ))
855 if (_father->IsUsedHypothesis( anHyp, _subShape )) // new Hyp
859 SetAlgoState(MISSING_HYP);
862 case ADD_FATHER_ALGO: {
863 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
864 if ( algo == anHyp ) { // a new algo on father
865 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
866 // check if algo changes
868 f.Init( SMESH_HypoFilter::IsAlgo() );
869 f.And( SMESH_HypoFilter::IsApplicableTo( _subShape ));
870 f.AndNot( SMESH_HypoFilter::Is( algo ));
871 const SMESH_Hypothesis* prevAlgo = _father->GetHypothesis( _subShape, f, true );
873 string(algo->GetName()) != string(prevAlgo->GetName()) )
877 SetAlgoState(MISSING_HYP);
881 case REMOVE_FATHER_HYP: {
882 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
884 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
885 // is there the same local hyp or maybe a new father algo applied?
886 if ( !GetSimilarAttached( _subShape, anHyp ) )
890 SetAlgoState(MISSING_HYP);
893 case REMOVE_FATHER_ALGO: {
894 SMESH_Algo* algo = gen->GetAlgo((*_father), _subShape);
895 if (algo == NULL) // no more applying algo on father
897 SetAlgoState(NO_ALGO);
901 if ( algo->CheckHypothesis((*_father),_subShape, aux_ret )) {
902 // check if algo changes
903 if ( string(algo->GetName()) != string( anHyp->GetName()) )
907 SetAlgoState(MISSING_HYP);
917 // ----------------------------------------------------------------------
924 if ((_algoState != oldAlgoState) || modifiedHyp)
925 ComputeStateEngine(MODIF_ALGO_STATE);
931 //=======================================================================
932 //function : IsConform
933 //purpose : check if a conform mesh will be produced by the Algo
934 //=======================================================================
936 bool SMESH_subMesh::IsConform(const SMESH_Algo* theAlgo)
938 // MESSAGE( "SMESH_subMesh::IsConform" );
940 if ( !theAlgo ) return false;
942 // check only algo that doesn't NeedDescretBoundary(): because mesh made
943 // on a sub-shape will be ignored by theAlgo
944 if ( theAlgo->NeedDescretBoundary() )
947 SMESH_Gen* gen =_father->GetGen();
949 // only local algo is to be checked
950 if ( gen->IsGlobalHypothesis( theAlgo, *_father ))
953 // check algo attached to adjacent shapes
955 // loop on one level down sub-meshes
956 TopoDS_Iterator itsub( _subShape );
957 for (; itsub.More(); itsub.Next())
959 // loop on adjacent subShapes
960 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( itsub.Value() ));
961 for (; it.More(); it.Next())
963 const TopoDS_Shape& adjacent = it.Value();
964 if ( _subShape.IsSame( adjacent )) continue;
965 if ( adjacent.ShapeType() != _subShape.ShapeType())
968 // check algo attached to smAdjacent
969 SMESH_Algo * algo = gen->GetAlgo((*_father), adjacent);
972 !algo->NeedDescretBoundary() /*&&
973 !gen->IsGlobalHypothesis( algo, *_father )*/)
974 return false; // NOT CONFORM MESH WILL BE PRODUCED
981 //=============================================================================
985 //=============================================================================
987 void SMESH_subMesh::SetAlgoState(int state)
992 //=============================================================================
996 //=============================================================================
997 SMESH_Hypothesis::Hypothesis_Status
998 SMESH_subMesh::SubMeshesAlgoStateEngine(int event,
999 SMESH_Hypothesis * anHyp)
1001 //MESSAGE("SMESH_subMesh::SubMeshesAlgoStateEngine");
1002 SMESH_Hypothesis::Hypothesis_Status ret = SMESH_Hypothesis::HYP_OK;
1003 //EAP: a wire (dim==1) should notify edges (dim==1)
1004 //EAP: int dim = SMESH_Gen::GetShapeDim(_subShape);
1005 if (_subShape.ShapeType() < TopAbs_EDGE ) // wire,face etc
1007 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1009 map < int, SMESH_subMesh * >::const_iterator itsub;
1010 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1012 SMESH_subMesh *sm = (*itsub).second;
1013 SMESH_Hypothesis::Hypothesis_Status ret2 =
1014 sm->AlgoStateEngine(event, anHyp);
1022 //=============================================================================
1026 //=============================================================================
1028 void SMESH_subMesh::CleanDependsOn()
1030 //MESSAGE("SMESH_subMesh::CleanDependsOn");
1031 // **** parcourir les ancetres dans l'ordre de dépendance
1033 ComputeStateEngine(CLEAN);
1035 const map < int, SMESH_subMesh * >&dependson = DependsOn();
1036 map < int, SMESH_subMesh * >::const_iterator its;
1037 for (its = dependson.begin(); its != dependson.end(); its++)
1039 SMESH_subMesh *sm = (*its).second;
1040 sm->ComputeStateEngine(CLEAN);
1044 //=============================================================================
1048 //=============================================================================
1050 void SMESH_subMesh::DumpAlgoState(bool isMain)
1052 int dim = SMESH_Gen::GetShapeDim(_subShape);
1053 // if (dim < 1) return;
1056 const map < int, SMESH_subMesh * >&subMeshes = DependsOn();
1058 map < int, SMESH_subMesh * >::const_iterator itsub;
1059 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
1061 SMESH_subMesh *sm = (*itsub).second;
1062 sm->DumpAlgoState(false);
1065 int type = _subShape.ShapeType();
1066 MESSAGE("dim = " << dim << " type of shape " << type);
1070 MESSAGE(" AlgoState = NO_ALGO");
1073 MESSAGE(" AlgoState = MISSING_HYP");
1076 MESSAGE(" AlgoState = HYP_OK");
1079 switch (_computeState)
1082 MESSAGE(" ComputeState = NOT_READY");
1084 case READY_TO_COMPUTE:
1085 MESSAGE(" ComputeState = READY_TO_COMPUTE");
1088 MESSAGE(" ComputeState = COMPUTE_OK");
1090 case FAILED_TO_COMPUTE:
1091 MESSAGE(" ComputeState = FAILED_TO_COMPUTE");
1096 //================================================================================
1098 * \brief Remove nodes and elements bound to submesh
1099 * \param subMesh - submesh containing nodes and elements
1101 //================================================================================
1103 static void cleanSubMesh( SMESH_subMesh * subMesh )
1106 if (SMESHDS_SubMesh * subMeshDS = subMesh->GetSubMeshDS())
1108 SMESHDS_Mesh * meshDS = subMesh->GetFather()->GetMeshDS();
1109 SMDS_ElemIteratorPtr ite=subMeshDS->GetElements();
1112 const SMDS_MeshElement * elt = ite->next();
1113 //MESSAGE( " RM elt: "<<elt->GetID()<<" ( "<<elt->NbNodes()<<" )" );
1114 meshDS->RemoveElement(elt);
1117 SMDS_NodeIteratorPtr itn=subMeshDS->GetNodes();
1120 const SMDS_MeshNode * node = itn->next();
1121 //MESSAGE( " RM node: "<<node->GetID());
1122 meshDS->RemoveNode(node);
1127 //=============================================================================
1131 //=============================================================================
1133 bool SMESH_subMesh::ComputeStateEngine(int event)
1135 //MESSAGE("SMESH_subMesh::ComputeStateEngine");
1136 //SCRUTE(_computeState);
1139 int dim = SMESH_Gen::GetShapeDim(_subShape);
1143 if ( IsMeshComputed() )
1144 _computeState = COMPUTE_OK;
1146 _computeState = READY_TO_COMPUTE;
1149 SMESH_Gen *gen = _father->GetGen();
1150 SMESH_Algo *algo = 0;
1152 SMESH_Hypothesis::Hypothesis_Status hyp_status;
1154 switch (_computeState)
1157 // ----------------------------------------------------------------------
1162 case MODIF_HYP: // nothing to do
1164 case MODIF_ALGO_STATE:
1165 if (_algoState == HYP_OK)
1167 _computeState = READY_TO_COMPUTE;
1170 case COMPUTE: // nothing to do
1173 RemoveSubMeshElementsAndNodes();
1174 //break; submeshes dependent on me should be cleaned as well
1178 case SUBMESH_COMPUTED: // nothing to do
1180 case SUBMESH_RESTORED:
1181 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1183 case MESH_ENTITY_REMOVED:
1185 case CHECK_COMPUTE_STATE:
1186 if ( IsMeshComputed() )
1187 _computeState = COMPUTE_OK;
1195 // ----------------------------------------------------------------------
1197 case READY_TO_COMPUTE:
1200 case MODIF_HYP: // nothing to do
1202 case MODIF_ALGO_STATE:
1203 _computeState = NOT_READY;
1204 algo = gen->GetAlgo((*_father), _subShape);
1207 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1209 _computeState = READY_TO_COMPUTE;
1214 algo = gen->GetAlgo((*_father), _subShape);
1216 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1219 MESSAGE("***** verify compute state *****");
1220 _computeState = NOT_READY;
1223 // check submeshes needed
1224 if (algo->NeedDescretBoundary())
1225 ret = SubMeshesComputed();
1228 MESSAGE("Some SubMeshes not computed");
1229 _computeState = FAILED_TO_COMPUTE;
1234 RemoveSubMeshElementsAndNodes();
1236 if (!algo->NeedDescretBoundary() && !algo->OnlyUnaryInput())
1237 ret = ApplyToCollection( algo, GetCollection( gen, algo ) );
1239 ret = algo->Compute((*_father), _subShape);
1241 catch (Standard_Failure) {
1242 MESSAGE( "Exception in algo->Compute() ");
1247 MESSAGE("problem in algo execution: failed to compute");
1248 _computeState = FAILED_TO_COMPUTE;
1249 if (!algo->NeedDescretBoundary())
1250 UpdateSubMeshState( FAILED_TO_COMPUTE );
1253 // Show vertices location of a failed shape
1254 TopTools_IndexedMapOfShape vMap;
1255 TopExp::MapShapes( _subShape, TopAbs_VERTEX, vMap );
1256 for ( int iv = 1; iv <= vMap.Extent(); ++iv ) {
1257 gp_Pnt P( BRep_Tool::Pnt( TopoDS::Vertex( vMap( iv ) )));
1258 cout << P.X() << " " << P.Y() << " " << P.Z() << " " << endl;
1265 _computeState = COMPUTE_OK;
1266 UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
1267 if (!algo->NeedDescretBoundary())
1268 UpdateSubMeshState( COMPUTE_OK );
1273 RemoveSubMeshElementsAndNodes();
1274 _computeState = NOT_READY;
1275 algo = gen->GetAlgo((*_father), _subShape);
1278 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1280 _computeState = READY_TO_COMPUTE;
1282 //break; submeshes dependent on me should be cleaned as well
1286 case SUBMESH_COMPUTED: // nothing to do
1288 case SUBMESH_RESTORED:
1289 // check if a mesh is already computed that may
1290 // happen after retrieval from a file
1291 ComputeStateEngine( CHECK_COMPUTE_STATE );
1292 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1294 case MESH_ENTITY_REMOVED:
1296 case CHECK_COMPUTE_STATE:
1297 if ( IsMeshComputed() )
1298 _computeState = COMPUTE_OK;
1306 // ----------------------------------------------------------------------
1312 case MODIF_ALGO_STATE:
1313 ComputeStateEngine( CLEAN );
1314 algo = gen->GetAlgo((*_father), _subShape);
1315 if (algo && !algo->NeedDescretBoundary())
1316 CleanDependsOn(); // remove sub-mesh with event CLEANDEP
1318 case COMPUTE: // nothing to do
1321 RemoveSubMeshElementsAndNodes();
1322 _computeState = NOT_READY;
1323 algo = gen->GetAlgo((*_father), _subShape);
1326 ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
1328 _computeState = READY_TO_COMPUTE;
1330 // break; submeshes dependent on me should be cleaned as well
1332 CleanDependants(); // recursive recall with event CLEANDEP
1334 case SUBMESH_COMPUTED: // nothing to do
1336 case SUBMESH_RESTORED:
1337 ComputeStateEngine( CHECK_COMPUTE_STATE );
1338 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1340 case MESH_ENTITY_REMOVED:
1341 UpdateDependantsState( CHECK_COMPUTE_STATE );
1342 ComputeStateEngine( CHECK_COMPUTE_STATE );
1343 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1345 case CHECK_COMPUTE_STATE:
1346 if ( !IsMeshComputed() )
1347 if (_algoState == HYP_OK)
1348 _computeState = READY_TO_COMPUTE;
1350 _computeState = NOT_READY;
1358 // ----------------------------------------------------------------------
1360 case FAILED_TO_COMPUTE:
1364 if (_algoState == HYP_OK)
1365 _computeState = READY_TO_COMPUTE;
1367 _computeState = NOT_READY;
1369 case MODIF_ALGO_STATE:
1370 if (_algoState == HYP_OK)
1371 _computeState = READY_TO_COMPUTE;
1373 _computeState = NOT_READY;
1375 case COMPUTE: // nothing to do
1378 RemoveSubMeshElementsAndNodes();
1379 if (_algoState == HYP_OK)
1380 _computeState = READY_TO_COMPUTE;
1382 _computeState = NOT_READY;
1383 // break; submeshes dependent on me should be cleaned as well
1387 case SUBMESH_COMPUTED: // allow retry compute
1388 if (_algoState == HYP_OK)
1389 _computeState = READY_TO_COMPUTE;
1391 _computeState = NOT_READY;
1393 case SUBMESH_RESTORED:
1394 ComputeSubMeshStateEngine( CHECK_COMPUTE_STATE );
1396 case MESH_ENTITY_REMOVED:
1398 case CHECK_COMPUTE_STATE:
1399 if ( IsMeshComputed() )
1400 _computeState = COMPUTE_OK;
1402 if (_algoState == HYP_OK)
1403 _computeState = READY_TO_COMPUTE;
1405 _computeState = NOT_READY;
1413 // ----------------------------------------------------------------------
1419 //SCRUTE(_computeState);
1423 //=======================================================================
1424 //function : ApplyToCollection
1425 //purpose : Apply theAlgo to all subshapes in theCollection
1426 //=======================================================================
1428 bool SMESH_subMesh::ApplyToCollection (SMESH_Algo* theAlgo,
1429 const TopoDS_Shape& theCollection)
1431 MESSAGE("SMESH_subMesh::ApplyToCollection");
1432 ASSERT ( !theAlgo->NeedDescretBoundary() );
1437 ret = theAlgo->Compute( *_father, theCollection );
1439 // set _computeState of subshapes
1440 TopExp_Explorer anExplorer( theCollection, _subShape.ShapeType() );
1441 for ( ; anExplorer.More(); anExplorer.Next() )
1443 const TopoDS_Shape& aSubShape = anExplorer.Current();
1444 SMESH_subMesh* subMesh = _father->GetSubMeshContaining( aSubShape );
1449 subMesh->_computeState = COMPUTE_OK;
1450 subMesh->UpdateDependantsState( SUBMESH_COMPUTED );
1451 subMesh->UpdateSubMeshState( COMPUTE_OK );
1455 subMesh->_computeState = FAILED_TO_COMPUTE;
1463 //=======================================================================
1464 //function : UpdateSubMeshState
1466 //=======================================================================
1468 void SMESH_subMesh::UpdateSubMeshState(const compute_state theState)
1470 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1471 map<int, SMESH_subMesh*>::const_iterator itsub;
1472 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1474 SMESH_subMesh* sm = (*itsub).second;
1475 sm->_computeState = theState;
1479 //=======================================================================
1480 //function : ComputeSubMeshStateEngine
1482 //=======================================================================
1484 void SMESH_subMesh::ComputeSubMeshStateEngine(int event)
1486 const map<int, SMESH_subMesh*>& smMap = DependsOn();
1487 map<int, SMESH_subMesh*>::const_iterator itsub;
1488 for (itsub = smMap.begin(); itsub != smMap.end(); itsub++)
1490 SMESH_subMesh* sm = (*itsub).second;
1491 sm->ComputeStateEngine(event);
1495 //=======================================================================
1496 //function : UpdateDependantsState
1498 //=======================================================================
1500 void SMESH_subMesh::UpdateDependantsState(const compute_event theEvent)
1502 //MESSAGE("SMESH_subMesh::UpdateDependantsState");
1503 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1504 for (; it.More(); it.Next())
1506 const TopoDS_Shape& ancestor = it.Value();
1507 SMESH_subMesh *aSubMesh =
1508 _father->GetSubMeshContaining(ancestor);
1510 aSubMesh->ComputeStateEngine( theEvent );
1514 //=============================================================================
1518 //=============================================================================
1520 void SMESH_subMesh::CleanDependants()
1522 int dimToClean = SMESH_Gen::GetShapeDim( _subShape ) + 1;
1524 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1525 for (; it.More(); it.Next())
1527 const TopoDS_Shape& ancestor = it.Value();
1528 if ( SMESH_Gen::GetShapeDim( ancestor ) == dimToClean ) {
1529 // PAL8021. do not go upper than SOLID, else ComputeStateEngine(CLEAN)
1530 // will erase mesh on other shapes in a compound
1531 if ( ancestor.ShapeType() >= TopAbs_SOLID ) {
1532 SMESH_subMesh *aSubMesh = _father->GetSubMeshContaining(ancestor);
1534 aSubMesh->ComputeStateEngine(CLEAN);
1540 //=============================================================================
1544 //=============================================================================
1546 void SMESH_subMesh::RemoveSubMeshElementsAndNodes()
1548 //SCRUTE(_subShape.ShapeType());
1550 cleanSubMesh( this );
1552 // algo may bind a submesh not to _subShape, eg 3D algo
1553 // sets nodes on SHELL while _subShape may be SOLID
1555 int dim = SMESH_Gen::GetShapeDim( _subShape );
1556 int type = _subShape.ShapeType() + 1;
1557 for ( ; type <= TopAbs_EDGE; type++)
1558 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1560 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1561 for ( ; exp.More(); exp.Next() )
1562 cleanSubMesh( _father->GetSubMeshContaining( exp.Current() ));
1568 //=======================================================================
1569 //function : IsMeshComputed
1570 //purpose : check if _subMeshDS contains mesh elements
1571 //=======================================================================
1573 bool SMESH_subMesh::IsMeshComputed() const
1575 // algo may bind a submesh not to _subShape, eg 3D algo
1576 // sets nodes on SHELL while _subShape may be SOLID
1578 int dim = SMESH_Gen::GetShapeDim( _subShape );
1579 int type = _subShape.ShapeType();
1580 for ( ; type <= TopAbs_VERTEX; type++) {
1581 if ( dim == SMESH_Gen::GetShapeDim( (TopAbs_ShapeEnum) type ))
1583 TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
1584 for ( ; exp.More(); exp.Next() )
1586 SMESHDS_SubMesh * subMeshDS = _meshDS->MeshElements( exp.Current() );
1587 if ( subMeshDS != NULL &&
1588 (subMeshDS->GetElements()->more() || subMeshDS->GetNodes()->more())) {
1601 //=======================================================================
1602 //function : GetCollection
1603 //purpose : return a shape containing all sub-shapes of the MainShape that can be
1604 // meshed at once along with _subShape
1605 //=======================================================================
1607 TopoDS_Shape SMESH_subMesh::GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo)
1609 MESSAGE("SMESH_subMesh::GetCollection");
1610 ASSERT (!theAlgo->NeedDescretBoundary());
1612 TopoDS_Shape mainShape = _father->GetMeshDS()->ShapeToMesh();
1614 if ( mainShape.IsSame( _subShape ))
1617 list<const SMESHDS_Hypothesis*> aUsedHyp =
1618 theAlgo->GetUsedHypothesis( *_father, _subShape ); // copy
1620 // put in a compound all shapes with the same hypothesis assigned
1621 // and a good ComputState
1623 TopoDS_Compound aCompound;
1624 BRep_Builder aBuilder;
1625 aBuilder.MakeCompound( aCompound );
1627 TopExp_Explorer anExplorer( mainShape, _subShape.ShapeType() );
1628 for ( ; anExplorer.More(); anExplorer.Next() )
1630 const TopoDS_Shape& S = anExplorer.Current();
1631 SMESH_subMesh* subMesh = _father->GetSubMesh( S );
1632 SMESH_Algo* anAlgo = theGen->GetAlgo( *_father, S );
1634 if (subMesh->GetComputeState() == READY_TO_COMPUTE &&
1635 anAlgo == theAlgo &&
1636 anAlgo->GetUsedHypothesis( *_father, S ) == aUsedHyp)
1638 aBuilder.Add( aCompound, S );
1645 //=======================================================================
1646 //function : GetSimilarAttached
1647 //purpose : return nb of hypotheses attached to theShape.
1648 // If theHyp is provided, similar but not same hypotheses
1649 // are countered; else only applicable ones having theHypType
1651 //=======================================================================
1653 const SMESH_Hypothesis* SMESH_subMesh::GetSimilarAttached(const TopoDS_Shape& theShape,
1654 const SMESH_Hypothesis * theHyp,
1655 const int theHypType)
1657 SMESH_HypoFilter filter;
1658 filter.Init( SMESH_HypoFilter::HasType( theHyp ? theHyp->GetType() : theHypType ));
1660 filter.And( SMESH_HypoFilter::HasDim( theHyp->GetDim() ));
1661 filter.AndNot( SMESH_HypoFilter::Is( theHyp ));
1664 filter.And( SMESH_HypoFilter::IsApplicableTo( theShape ));
1666 return _father->GetHypothesis( theShape, filter, false );
1669 //=======================================================================
1670 //function : CheckConcurentHypothesis
1671 //purpose : check if there are several applicable hypothesis attached to
1673 //=======================================================================
1675 SMESH_Hypothesis::Hypothesis_Status
1676 SMESH_subMesh::CheckConcurentHypothesis (const int theHypType)
1678 MESSAGE ("SMESH_subMesh::CheckConcurentHypothesis");
1680 // is there local hypothesis on me?
1681 if ( GetSimilarAttached( _subShape, 0, theHypType ) )
1682 return SMESH_Hypothesis::HYP_OK;
1685 TopoDS_Shape aPrevWithHyp;
1686 const SMESH_Hypothesis* aPrevHyp = 0;
1687 TopTools_ListIteratorOfListOfShape it( _father->GetAncestors( _subShape ));
1688 for (; it.More(); it.Next())
1690 const TopoDS_Shape& ancestor = it.Value();
1691 const SMESH_Hypothesis* hyp = GetSimilarAttached( ancestor, 0, theHypType );
1694 if ( aPrevWithHyp.IsNull() || aPrevWithHyp.IsSame( ancestor ))
1696 aPrevWithHyp = ancestor;
1699 else if ( aPrevWithHyp.ShapeType() == ancestor.ShapeType() && aPrevHyp != hyp )
1700 return SMESH_Hypothesis::HYP_CONCURENT;
1702 return SMESH_Hypothesis::HYP_OK;
1705 return SMESH_Hypothesis::HYP_OK;