- // const TopoDS_Shape& theMainEdge = theMainSubMesh->GetSubShape();
-// if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
-
-// SMESH_Mesh* mesh = theMainSubMesh->GetFather();
-
-// EventListenerData* chainData = new PropagationMgrData(HAS_PROPAG_HYP);
-// theMainSubMesh->SetEventListener( getListener(), chainData, theMainSubMesh );
-
-// // Edges submeshes, on which the 1D hypothesis will be propagated from <theMainEdge>
-// list<SMESH_subMesh*> & chain = chainData->mySubMeshes;
-
-// // List of edges, added to chain on the previous cycle pass
-// TopTools_ListOfShape listPrevEdges;
-// listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
-
-// // 4____3____2____3____4____5
-// // | | | | | | Number in the each knot of
-// // | | | | | | grid indicates cycle pass,
-// // 3____2____1____2____3____4 on which corresponding edge
-// // | | | | | | (perpendicular to the plane
-// // | | | | | | of view) will be found.
-// // 2____1____0____1____2____3
-// // | | | | | |
-// // | | | | | |
-// // 3____2____1____2____3____4
-
-// // Collect all edges pass by pass
-// while (listPrevEdges.Extent() > 0) {
-// // List of edges, added to chain on this cycle pass
-// TopTools_ListOfShape listCurEdges;
-
-// // Find the next portion of edges
-// TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
-// for (; itE.More(); itE.Next()) {
-// TopoDS_Shape anE = itE.Value();
-
-// // Iterate on faces, having edge <anE>
-// TopTools_ListIteratorOfListOfShape itA (mesh->GetAncestors(anE));
-// for (; itA.More(); itA.Next()) {
-// TopoDS_Shape aW = itA.Value();
-
-// // There are objects of different type among the ancestors of edge
-// if (aW.ShapeType() == TopAbs_WIRE) {
-// TopoDS_Shape anOppE;
-
-// BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
-// Standard_Integer nb = 1, found = 0;
-// TopTools_Array1OfShape anEdges (1,4);
-// for (; aWE.More(); aWE.Next(), nb++) {
-// if (nb > 4) {
-// found = 0;
-// break;
-// }
-// anEdges(nb) = aWE.Current();
-// if (!_mapAncestors.Contains(anEdges(nb))) {
-// MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
-// break;
-// }
-// if (anEdges(nb).IsSame(anE)) found = nb;
-// }
-
-// if (nb == 5 && found > 0) {
-// // Quadrangle face found, get an opposite edge
-// Standard_Integer opp = ( found + 2 ) % 4;
-// anOppE = anEdges(opp);
-
-// // add anOppE to aChain if ...
-// PropagationMgrData* data = getData( *mesh, anOppE );
-// if ( !data || data->State() == WAIT_PROPAG_HYP ) { // ... anOppE is not in any chain
-// if ( !isLocal1DHypothesis( *mesh, anOppE )) { // ... no other 1d hyp on anOppE
-// // Add found edge to the chain oriented so that to
-// // have it co-directed with a forward MainEdge
-// TopAbs_Orientation ori = anE.Orientation();
-// if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
-// ori = TopAbs::Reverse( ori );
-// anOppE.Orientation( ori );
-// aChain.Add(anOppE);
-// listCurEdges.Append(anOppE);
-// }
-// else {
-// // Collision!
-// MESSAGE("Error: Collision between propagated hypotheses");
-// CleanMeshOnPropagationChain(theMainEdge);
-// aChain.Clear();
-// return ( aMainHyp == isLocal1DHypothesis(aMainEdgeForOppEdge) );
-// }
-// }
-// }
-// } // if (nb == 5 && found > 0)
-// } // if (aF.ShapeType() == TopAbs_WIRE)
-// } // for (; itF.More(); itF.Next())
-// } // for (; itE.More(); itE.Next())
-
-// listPrevEdges = listCurEdges;
-// } // while (listPrevEdges.Extent() > 0)
-
-// CleanMeshOnPropagationChain(theMainEdge);
+ DBGMSG( "buildPropagationChain from " << theMainSubMesh->GetId() );
+ const TopoDS_Shape& theMainEdge = theMainSubMesh->GetSubShape();
+ if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
+
+ SMESH_Mesh* mesh = theMainSubMesh->GetFather();
+
+ PropagationMgrData* chainData = getData( theMainSubMesh );
+ chainData->SetState( HAS_PROPAG_HYP );
+
+ // Edge submeshes, to which the 1D hypothesis will be propagated from theMainEdge
+ list<SMESH_subMesh*> & chain = chainData->mySubMeshes;
+ chain.clear();
+ chain.push_back( theMainSubMesh );
+
+ TopTools_MapOfShape checkedShapes;
+ checkedShapes.Add( theMainEdge );
+
+ list<SMESH_subMesh*>::iterator smIt = chain.begin();
+ for ( ; smIt != chain.end(); ++smIt )
+ {
+ const TopoDS_Edge& anE = TopoDS::Edge( (*smIt)->GetSubShape() );
+ PropagationMgrData* data = findData( *smIt );
+ if ( !data ) continue;
+
+ // Iterate on faces, having edge <anE>
+ TopTools_ListIteratorOfListOfShape itA (mesh->GetAncestors(anE));
+ for (; itA.More(); itA.Next())
+ {
+ // there are objects of different type among the ancestors of edge
+ if ( itA.Value().ShapeType() != TopAbs_WIRE || !checkedShapes.Add( itA.Value() ))
+ continue;
+
+ // Get ordered edges and find index of anE in a sequence
+ BRepTools_WireExplorer aWE (TopoDS::Wire(itA.Value()));
+ vector<TopoDS_Edge> edges;
+ edges.reserve(4);
+ int edgeIndex = 0;
+ for (; aWE.More(); aWE.Next()) {
+ TopoDS_Edge edge = aWE.Current();
+ edge.Orientation( aWE.Orientation() );
+ if ( edge.IsSame( anE ))
+ edgeIndex = edges.size();
+ edges.push_back( edge );
+ }
+
+ // Find an edge opposite to anE
+ TopoDS_Edge anOppE;
+ if ( edges.size() < 4 ) {
+ continue; // too few edges
+ }
+ else if ( edges.size() == 4 ) {
+ int oppIndex = edgeIndex + 2;
+ if ( oppIndex > 3 ) oppIndex -= 4;
+ anOppE = edges[ oppIndex ];
+ }
+ else {
+ // count nb sides
+ TopoDS_Edge prevEdge = anE;
+ int nbSide = 0, eIndex = edgeIndex + 1;
+ for ( int i = 0; i < edges.size(); ++i, ++eIndex )
+ {
+ if ( eIndex == edges.size() )
+ eIndex = 0;
+ if ( !SMESH_Algo::IsContinuous( prevEdge, edges[ eIndex ])) {
+ nbSide++;
+ }
+ else {
+ // check that anE is not a part of a composite side
+ if ( anE.IsSame( prevEdge ) || anE.IsSame( edges[ eIndex ])) {
+ anOppE.Nullify(); break;
+ }
+ }
+ if ( nbSide == 2 ) { // opposite side
+ if ( !anOppE.IsNull() ) {
+ // composite opposite side -> stop propagation
+ anOppE.Nullify(); break;
+ }
+ anOppE = edges[ eIndex ];
+ }
+ if ( nbSide == 5 ) {
+ anOppE.Nullify(); break; // too many sides
+ }
+ prevEdge = edges[ eIndex ];
+ }
+ if ( anOppE.IsNull() )
+ continue;
+ if ( nbSide != 4 ) {
+ DBGMSG( nbSide << " sides in wire #" << mesh->GetMeshDS()->ShapeToIndex( itA.Value() ) << " - SKIP" );
+ continue;
+ }
+ }
+ if ( anOppE.IsNull() || !checkedShapes.Add( anOppE ))
+ continue;
+ SMESH_subMesh* oppSM = mesh->GetSubMesh( anOppE );
+ PropagationMgrData* oppData = getData( oppSM );
+
+ // Add anOppE to aChain if ...
+ if ( oppData->State() == WAIT_PROPAG_HYP ) // ... anOppE is not in any chain
+ {
+ oppData->SetSource( theMainSubMesh );
+ if ( !getLocal1DHyp( *mesh, anOppE )) // ... no 1d hyp on anOppE
+ {
+ oppData->myForward = data->myForward;
+ if ( edges[ edgeIndex ].Orientation() == anOppE.Orientation() )
+ oppData->myForward = !oppData->myForward;
+ chain.push_back( oppSM );
+ oppSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
+ oppData->SetState( IN_CHAIN );
+ DBGMSG( "set IN_CHAIN on " << oppSM->GetId() );
+ }
+ else {
+ oppData->SetState( LAST_IN_CHAIN );
+ DBGMSG( "set LAST_IN_CHAIN on " << oppSM->GetId() );
+ }
+ }
+ else if ( oppData->State() == LAST_IN_CHAIN ) // anOppE breaks other chain
+ {
+ DBGMSG( "encounters LAST_IN_CHAIN on " << oppSM->GetId() );
+ oppData->AddSource( theMainSubMesh );
+ }
+ } // loop on face ancestors
+ } // loop on the chain
+
+ // theMainSubMesh must not be in a chain
+ chain.pop_front();
+