1 // Copyright (C) 2007-2012 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 : idl implementation based on 'SMESH' unit's calsses
24 // File : StdMeshers_ProjectionUtils.cxx
25 // Created : Fri Oct 27 10:24:28 2006
26 // Author : Edward AGAPOV (eap)
28 #include "StdMeshers_ProjectionUtils.hxx"
30 #include "StdMeshers_ProjectionSource1D.hxx"
31 #include "StdMeshers_ProjectionSource2D.hxx"
32 #include "StdMeshers_ProjectionSource3D.hxx"
34 #include "SMESH_Algo.hxx"
35 #include "SMESH_Block.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Hypothesis.hxx"
38 #include "SMESH_Mesh.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "SMESH_subMeshEventListener.hxx"
42 #include "SMDS_EdgePosition.hxx"
44 #include "utilities.h"
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRepTools.hxx>
48 #include <BRepTools_WireExplorer.hxx>
49 #include <BRep_Builder.hxx>
50 #include <BRep_Tool.hxx>
51 #include <Bnd_Box.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_Array1OfShape.hxx>
56 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
57 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
58 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <TopTools_ListIteratorOfListOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
63 #include <TopoDS_Compound.hxx>
64 #include <TopoDS_Shape.hxx>
74 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
75 #define CONT_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); continue; }
76 #define SHOW_SHAPE(v,msg) \
78 // if ( (v).IsNull() ) cout << msg << " NULL SHAPE" << endl; \
79 // else if ((v).ShapeType() == TopAbs_VERTEX) {\
80 // gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( (v) ));\
81 // cout<<msg<<" "<<shapeIndex((v))<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;} \
83 // cout << msg << " "; TopAbs::Print((v).ShapeType(),cout) <<" "<<shapeIndex((v))<<endl;}\
85 #define SHOW_LIST(msg,l) \
87 // cout << msg << " ";\
88 // list< TopoDS_Edge >::const_iterator e = l.begin();\
89 // for ( int i = 0; e != l.end(); ++e, ++i ) {\
90 // cout << i << "V (" << TopExp::FirstVertex( *e, true ).TShape().operator->() << ") "\
91 // << i << "E (" << e->TShape().operator->() << "); "; }\
95 #define HERE StdMeshers_ProjectionUtils
99 static SMESHDS_Mesh* theMeshDS[2] = { 0, 0 }; // used to debug only
100 long shapeIndex(const TopoDS_Shape& S)
102 if ( theMeshDS[0] && theMeshDS[1] )
103 return max(theMeshDS[0]->ShapeToIndex(S), theMeshDS[1]->ShapeToIndex(S) );
104 return long(S.TShape().operator->());
107 //================================================================================
109 * \brief Write shape for debug purposes
111 //================================================================================
113 bool _StoreBadShape(const TopoDS_Shape& shape)
116 const char* type[] ={"COMPOUND","COMPSOLID","SOLID","SHELL","FACE","WIRE","EDGE","VERTEX"};
117 BRepTools::Write( shape, SMESH_Comment("/tmp/") << type[shape.ShapeType()] << "_"
118 << shape.TShape().operator->() << ".brep");
123 //================================================================================
125 * \brief Reverse order of edges in a list and their orientation
126 * \param edges - list of edges to reverse
127 * \param nbEdges - number of edges to reverse
129 //================================================================================
131 void Reverse( list< TopoDS_Edge > & edges, const int nbEdges, const int firstEdge=0)
133 SHOW_LIST("BEFORE REVERSE", edges);
135 list< TopoDS_Edge >::iterator eIt = edges.begin();
136 std::advance( eIt, firstEdge );
137 list< TopoDS_Edge >::iterator eBackIt = eIt;
138 for ( int i = 0; i < nbEdges; ++i, ++eBackIt )
139 eBackIt->Reverse(); // reverse edge
142 while ( eIt != eBackIt )
144 std::swap( *eIt, *eBackIt );
145 SHOW_LIST("# AFTER SWAP", edges)
146 if ( (++eIt) != eBackIt )
149 SHOW_LIST("ATFER REVERSE", edges)
152 //================================================================================
154 * \brief Check if propagation is possible
155 * \param theMesh1 - source mesh
156 * \param theMesh2 - target mesh
157 * \retval bool - true if possible
159 //================================================================================
161 bool IsPropagationPossible( SMESH_Mesh* theMesh1, SMESH_Mesh* theMesh2 )
163 if ( theMesh1 != theMesh2 ) {
164 TopoDS_Shape mainShape1 = theMesh1->GetMeshDS()->ShapeToMesh();
165 TopoDS_Shape mainShape2 = theMesh2->GetMeshDS()->ShapeToMesh();
166 return mainShape1.IsSame( mainShape2 );
171 //================================================================================
173 * \brief Fix up association of edges in faces by possible propagation
174 * \param nbEdges - nb of edges in an outer wire
175 * \param edges1 - edges of one face
176 * \param edges2 - matching edges of another face
177 * \param theMesh1 - mesh 1
178 * \param theMesh2 - mesh 2
179 * \retval bool - true if association was fixed
181 //================================================================================
183 bool FixAssocByPropagation( const int nbEdges,
184 list< TopoDS_Edge > & edges1,
185 list< TopoDS_Edge > & edges2,
186 SMESH_Mesh* theMesh1,
187 SMESH_Mesh* theMesh2)
189 if ( nbEdges == 2 && IsPropagationPossible( theMesh1, theMesh2 ) )
191 list< TopoDS_Edge >::iterator eIt2 = ++edges2.begin(); // 2nd edge of the 2nd face
192 TopoDS_Edge edge2 = HERE::GetPropagationEdge( theMesh1, *eIt2, edges1.front() ).second;
193 if ( !edge2.IsNull() ) { // propagation found for the second edge
194 Reverse( edges2, nbEdges );
201 //================================================================================
203 * \brief Look for a group containing a target shape and similar to a source group
204 * \param tgtShape - target edge or face
205 * \param tgtMesh1 - target mesh
206 * \param srcGroup - source group
207 * \retval TopoDS_Shape - found target group
209 //================================================================================
211 TopoDS_Shape FindGroupContaining(const TopoDS_Shape& tgtShape,
212 const SMESH_Mesh* tgtMesh1,
213 const TopoDS_Shape& srcGroup)
215 list<SMESH_subMesh*> subMeshes = tgtMesh1->GetGroupSubMeshesContaining(tgtShape);
216 list<SMESH_subMesh*>::iterator sm = subMeshes.begin();
217 int type, last = TopAbs_SHAPE;
218 StdMeshers_ProjectionUtils util;
219 for ( ; sm != subMeshes.end(); ++sm ) {
220 const TopoDS_Shape & group = (*sm)->GetSubShape();
221 // check if group is similar to srcGroup
222 for ( type = srcGroup.ShapeType(); type < last; ++type)
223 if ( util.Count( srcGroup, (TopAbs_ShapeEnum)type, 0) !=
224 util.Count( group, (TopAbs_ShapeEnum)type, 0))
229 return TopoDS_Shape();
232 //================================================================================
234 * \brief Find association of groups at top and bottom of prism
236 //================================================================================
238 bool AssocGroupsByPropagation(const TopoDS_Shape& theGroup1,
239 const TopoDS_Shape& theGroup2,
241 HERE::TShapeShapeMap& theMap)
243 // If groups are on top and bottom of prism then we can associate
244 // them using "vertical" (or "side") edges and faces of prism since
245 // they connect corresponding vertices and edges of groups.
247 TopTools_IndexedMapOfShape subshapes1, subshapes2;
248 TopExp::MapShapes( theGroup1, subshapes1 );
249 TopExp::MapShapes( theGroup2, subshapes2 );
250 TopTools_ListIteratorOfListOfShape ancestIt;
252 // Iterate on vertices of group1 to find corresponding vertices in group2
253 // and associate adjacent edges and faces
255 TopTools_MapOfShape verticShapes;
256 TopExp_Explorer vExp1( theGroup1, TopAbs_VERTEX );
257 for ( ; vExp1.More(); vExp1.Next() )
259 const TopoDS_Vertex& v1 = TopoDS::Vertex( vExp1.Current() );
260 if ( theMap.IsBound( v1 )) continue; // already processed
262 // Find "vertical" edge ending in v1 and whose other vertex belongs to group2
263 TopoDS_Shape verticEdge, v2;
264 ancestIt.Initialize( theMesh.GetAncestors( v1 ));
265 for ( ; verticEdge.IsNull() && ancestIt.More(); ancestIt.Next() )
267 if ( ancestIt.Value().ShapeType() != TopAbs_EDGE ) continue;
268 v2 = HERE::GetNextVertex( TopoDS::Edge( ancestIt.Value() ), v1 );
269 if ( subshapes2.Contains( v2 ))
270 verticEdge = ancestIt.Value();
272 if ( verticEdge.IsNull() )
275 HERE::InsertAssociation( v1, v2, theMap);
277 // Associate edges by vertical faces sharing the found vertical edge
278 ancestIt.Initialize( theMesh.GetAncestors( verticEdge ) );
279 for ( ; ancestIt.More(); ancestIt.Next() )
281 if ( ancestIt.Value().ShapeType() != TopAbs_FACE ) continue;
282 if ( !verticShapes.Add( ancestIt.Value() )) continue;
283 const TopoDS_Face& face = TopoDS::Face( ancestIt.Value() );
285 // get edges of the face
286 TopoDS_Edge edgeGr1, edgeGr2, verticEdge2;
287 list< TopoDS_Edge > edges; list< int > nbEdgesInWire;
288 SMESH_Block::GetOrderedEdges( face, v1, edges, nbEdgesInWire);
289 if ( nbEdgesInWire.front() != 4 )
290 return _StoreBadShape( face );
291 list< TopoDS_Edge >::iterator edge = edges.begin();
292 if ( verticEdge.IsSame( *edge )) {
294 verticEdge2 = *(++edge);
298 verticEdge2 = *(edge++);
302 HERE::InsertAssociation( edgeGr1, edgeGr2.Reversed(), theMap);
307 TopoDS_Iterator gr1It( theGroup1 );
308 if ( gr1It.Value().ShapeType() == TopAbs_FACE )
310 // find a boundary edge of group1 to start from
311 TopoDS_Shape bndEdge = HERE::GetBoundaryEdge( theGroup1, theMesh );
312 if ( bndEdge.IsNull() )
315 list< TopoDS_Shape > edges(1, bndEdge);
316 list< TopoDS_Shape >::iterator edge1 = edges.begin();
317 for ( ; edge1 != edges.end(); ++edge1 )
319 // there must be one or zero not associated faces between ancestors of edge
320 // belonging to theGroup1
322 ancestIt.Initialize( theMesh.GetAncestors( *edge1 ) );
323 for ( ; ancestIt.More() && face1.IsNull(); ancestIt.Next() ) {
324 if ( ancestIt.Value().ShapeType() == TopAbs_FACE &&
325 !theMap.IsBound( ancestIt.Value() ) &&
326 subshapes1.Contains( ancestIt.Value() ))
327 face1 = ancestIt.Value();
329 // add edges of face1 to start searching for adjacent faces from
330 for ( TopExp_Explorer e(face1, TopAbs_EDGE); e.More(); e.Next())
331 if ( !edge1->IsSame( e.Current() ))
332 edges.push_back( e.Current() );
334 if ( !face1.IsNull() ) {
335 // find the corresponding face of theGroup2
336 TopoDS_Shape edge2 = theMap( *edge1 );
338 ancestIt.Initialize( theMesh.GetAncestors( edge2 ) );
339 for ( ; ancestIt.More() && face2.IsNull(); ancestIt.Next() ) {
340 if ( ancestIt.Value().ShapeType() == TopAbs_FACE &&
341 !theMap.IsBound( ancestIt.Value(), /*is2nd=*/true ) &&
342 subshapes2.Contains( ancestIt.Value() ))
343 face2 = ancestIt.Value();
345 if ( face2.IsNull() )
348 HERE::InsertAssociation( face1, face2, theMap);
355 //================================================================================
357 * \brief Return true if uv position of the vIndex-th vertex of edge on face is close
360 //================================================================================
362 bool sameVertexUV( const TopoDS_Edge& edge,
363 const TopoDS_Face& face,
366 const double& tol2d )
369 TopExp::Vertices( edge, VV[0], VV[1], true);
370 gp_Pnt2d v1UV = BRep_Tool::Parameters( VV[vIndex], face);
371 double dist2d = v1UV.Distance( uv );
372 return dist2d < tol2d;
375 //================================================================================
377 * \brief Returns an EDGE suitable for search of initial vertex association
379 //================================================================================
381 bool getOuterEdges( const TopoDS_Shape shape,
383 std::list< TopoDS_Edge >& allBndEdges )
385 if ( shape.ShapeType() == TopAbs_COMPOUND )
387 TopoDS_Iterator it( shape );
388 if ( it.More() && it.Value().ShapeType() == TopAbs_FACE ) // group of FACEs
390 // look for a boundary EDGE of a group
391 StdMeshers_ProjectionUtils::GetBoundaryEdge( shape, mesh, &allBndEdges );
392 if ( !allBndEdges.empty() )
396 TopExp_Explorer expF( shape, TopAbs_FACE ), expE;
398 for ( ; expF.More(); expF.Next() ) {
400 StdMeshers_ProjectionUtils::OuterShape( TopoDS::Face( expF.Current() ), TopAbs_WIRE );
401 for ( expE.Init( wire, TopAbs_EDGE ); expE.More(); expE.Next() )
402 if ( !SMESH_MesherHelper::IsClosedEdge( TopoDS::Edge( expE.Current() )))
403 allBndEdges.push_back( TopoDS::Edge( expE.Current() ));
406 else if ( shape.ShapeType() != TopAbs_EDGE) { // no faces
407 for ( expE.Init( shape, TopAbs_EDGE ); expE.More(); expE.Next() )
408 if ( !SMESH_MesherHelper::IsClosedEdge( TopoDS::Edge( expE.Current() )))
409 allBndEdges.push_back( TopoDS::Edge( expE.Current() ));
411 else if ( shape.ShapeType() == TopAbs_EDGE ) {
412 if ( !SMESH_MesherHelper::IsClosedEdge( TopoDS::Edge( shape )))
413 allBndEdges.push_back( TopoDS::Edge( shape ));
415 return !allBndEdges.empty();
420 //=======================================================================
422 * \brief Looks for association of all sub-shapes of two shapes
423 * \param theShape1 - target shape
424 * \param theMesh1 - mesh built on shape 1
425 * \param theShape2 - source shape
426 * \param theMesh2 - mesh built on shape 2
427 * \param theAssociation - association map to be filled that may
428 * contain association of one or two pairs of vertices
429 * \retval bool - true if association found
431 //=======================================================================
433 bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& theShape1,
434 SMESH_Mesh* theMesh1,
435 const TopoDS_Shape& theShape2,
436 SMESH_Mesh* theMesh2,
437 TShapeShapeMap & theMap)
439 // Structure of this long function is following
440 // 1) Group->group projection: theShape1 is a group member,
441 // theShape2 is a group. We find a group theShape1 is in and recall self.
442 // 2) Accosiate same shapes with different location (partners).
443 // 3) If vertex association is given, perform accosiation according to shape type:
444 // switch ( ShapeType ) {
448 // 4) else try to accosiate in different ways:
449 // a) accosiate shapes by propagation and other simple cases
450 // switch ( ShapeType ) {
454 // b) find association of a couple of vertices and recall self.
457 theMeshDS[0] = theMesh1->GetMeshDS(); // debug
458 theMeshDS[1] = theMesh2->GetMeshDS();
460 // =================================================================================
461 // 1) Is it the case of associating a group member -> another group? (PAL16202, 16203)
462 // =================================================================================
463 if ( theShape1.ShapeType() != theShape2.ShapeType() ) {
464 TopoDS_Shape group1, group2;
465 if ( theShape1.ShapeType() == TopAbs_COMPOUND ) {
467 group2 = FindGroupContaining( theShape2, theMesh2, group1 );
469 else if ( theShape2.ShapeType() == TopAbs_COMPOUND ) {
471 group1 = FindGroupContaining( theShape1, theMesh1, group2 );
473 if ( group1.IsNull() || group2.IsNull() )
474 RETURN_BAD_RESULT("Different shape types");
475 // Associate compounds
476 return FindSubShapeAssociation(group1, theMesh1, group2, theMesh2, theMap );
482 bool partner = theShape1.IsPartner( theShape2 );
483 TopTools_DataMapIteratorOfDataMapOfShapeShape vvIt( theMap._map1to2 );
484 for ( ; partner && vvIt.More(); vvIt.Next() )
485 partner = vvIt.Key().IsPartner( vvIt.Value() );
487 if ( partner ) // Same shape with different location
489 // recursively associate all sub-shapes of theShape1 and theShape2
490 typedef list< pair< TopoDS_Shape, TopoDS_Shape > > TShapePairsList;
491 TShapePairsList shapesQueue( 1, make_pair( theShape1, theShape2 ));
492 TShapePairsList::iterator s1_s2 = shapesQueue.begin();
493 for ( ; s1_s2 != shapesQueue.end(); ++s1_s2 )
495 InsertAssociation( s1_s2->first, s1_s2->second, theMap );
496 TopoDS_Iterator s1It( s1_s2->first), s2It( s1_s2->second );
497 for ( ; s1It.More(); s1It.Next(), s2It.Next() )
498 shapesQueue.push_back( make_pair( s1It.Value(), s2It.Value() ));
503 if ( !theMap.IsEmpty() )
505 //======================================================================
506 // 3) HAS initial vertex association
507 //======================================================================
508 switch ( theShape1.ShapeType() ) {
509 // ----------------------------------------------------------------------
510 case TopAbs_EDGE: { // TopAbs_EDGE
511 // ----------------------------------------------------------------------
512 if ( theMap.Extent() != 2 )
513 RETURN_BAD_RESULT("Wrong map extent " << theMap.Extent() );
514 TopoDS_Edge edge1 = TopoDS::Edge( theShape1 );
515 TopoDS_Edge edge2 = TopoDS::Edge( theShape2 );
516 if ( edge1.Orientation() >= TopAbs_INTERNAL ) edge1.Orientation( TopAbs_FORWARD );
517 if ( edge2.Orientation() >= TopAbs_INTERNAL ) edge2.Orientation( TopAbs_FORWARD );
518 TopoDS_Vertex VV1[2], VV2[2];
519 TopExp::Vertices( edge1, VV1[0], VV1[1] );
520 TopExp::Vertices( edge2, VV2[0], VV2[1] );
522 if ( theMap.IsBound( VV1[ i1 ] )) i1 = 1;
523 if ( theMap.IsBound( VV2[ i2 ] )) i2 = 1;
524 InsertAssociation( VV1[ i1 ], VV2[ i2 ], theMap );
525 InsertAssociation( theShape1, theShape2, theMap );
528 // ----------------------------------------------------------------------
529 case TopAbs_FACE: { // TopAbs_FACE
530 // ----------------------------------------------------------------------
531 TopoDS_Face face1 = TopoDS::Face( theShape1 );
532 TopoDS_Face face2 = TopoDS::Face( theShape2 );
533 if ( face1.Orientation() >= TopAbs_INTERNAL ) face1.Orientation( TopAbs_FORWARD );
534 if ( face2.Orientation() >= TopAbs_INTERNAL ) face2.Orientation( TopAbs_FORWARD );
536 TopoDS_Vertex VV1[2], VV2[2];
537 // find a not closed edge of face1 both vertices of which are associated
539 TopExp_Explorer exp ( face1, TopAbs_EDGE );
540 for ( ; VV2[ 1 ].IsNull() && exp.More(); exp.Next(), ++nbEdges ) {
541 TopExp::Vertices( TopoDS::Edge( exp.Current() ), VV1[0], VV1[1] );
542 if ( theMap.IsBound( VV1[0] ) ) {
543 VV2[ 0 ] = TopoDS::Vertex( theMap( VV1[0] ));
544 if ( theMap.IsBound( VV1[1] ) && !VV1[0].IsSame( VV1[1] ))
545 VV2[ 1 ] = TopoDS::Vertex( theMap( VV1[1] ));
548 if ( VV2[ 1 ].IsNull() ) { // 2 bound vertices not found
550 RETURN_BAD_RESULT("2 bound vertices not found" );
555 list< TopoDS_Edge > edges1, edges2;
556 int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2 );
557 if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
558 FixAssocByPropagation( nbE, edges1, edges2, theMesh1, theMesh2 );
560 list< TopoDS_Edge >::iterator eIt1 = edges1.begin();
561 list< TopoDS_Edge >::iterator eIt2 = edges2.begin();
562 for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
564 InsertAssociation( *eIt1, *eIt2, theMap );
565 VV1[0] = TopExp::FirstVertex( *eIt1, true );
566 VV2[0] = TopExp::FirstVertex( *eIt2, true );
567 InsertAssociation( VV1[0], VV2[0], theMap );
569 InsertAssociation( theShape1, theShape2, theMap );
572 // ----------------------------------------------------------------------
573 case TopAbs_SHELL: // TopAbs_SHELL, TopAbs_SOLID
575 // ----------------------------------------------------------------------
576 TopoDS_Vertex VV1[2], VV2[2];
577 // try to find a not closed edge of shape1 both vertices of which are associated
579 TopExp_Explorer exp ( theShape1, TopAbs_EDGE );
580 for ( ; VV2[ 1 ].IsNull() && exp.More(); exp.Next() ) {
581 edge1 = TopoDS::Edge( exp.Current() );
582 if ( edge1.Orientation() >= TopAbs_INTERNAL ) edge1.Orientation( TopAbs_FORWARD );
583 TopExp::Vertices( edge1 , VV1[0], VV1[1] );
584 if ( theMap.IsBound( VV1[0] )) {
585 VV2[ 0 ] = TopoDS::Vertex( theMap( VV1[0] ));
586 if ( theMap.IsBound( VV1[1] ) && !VV1[0].IsSame( VV1[1] ))
587 VV2[ 1 ] = TopoDS::Vertex( theMap( VV1[1] ));
590 if ( VV2[ 1 ].IsNull() ) // 2 bound vertices not found
591 RETURN_BAD_RESULT("2 bound vertices not found" );
592 // get an edge2 of theShape2 corresponding to edge1
593 TopoDS_Edge edge2 = GetEdgeByVertices( theMesh2, VV2[ 0 ], VV2[ 1 ]);
594 if ( edge2.IsNull() )
595 RETURN_BAD_RESULT("GetEdgeByVertices() failed");
597 // build map of edge to faces if shapes are not sub-shapes of main ones
598 bool isSubOfMain = false;
599 if ( SMESHDS_SubMesh * sm = theMesh1->GetMeshDS()->MeshElements( theShape1 ))
600 isSubOfMain = !sm->IsComplexSubmesh();
602 isSubOfMain = theMesh1->GetMeshDS()->ShapeToIndex( theShape1 );
603 TAncestorMap e2f1, e2f2;
604 const TAncestorMap& edgeToFace1 = isSubOfMain ? theMesh1->GetAncestorMap() : e2f1;
605 const TAncestorMap& edgeToFace2 = isSubOfMain ? theMesh2->GetAncestorMap() : e2f2;
607 TopExp::MapShapesAndAncestors( theShape1, TopAbs_EDGE, TopAbs_FACE, e2f1 );
608 TopExp::MapShapesAndAncestors( theShape2, TopAbs_EDGE, TopAbs_FACE, e2f2 );
609 if ( !edgeToFace1.Contains( edge1 ))
610 RETURN_BAD_RESULT("edge1 does not belong to theShape1");
611 if ( !edgeToFace2.Contains( edge2 ))
612 RETURN_BAD_RESULT("edge2 does not belong to theShape2");
615 // Look for 2 corresponing faces:
619 // get a face sharing edge1 (F1)
621 TopTools_ListIteratorOfListOfShape ancestIt1( edgeToFace1.FindFromKey( edge1 ));
622 for ( ; F1.IsNull() && ancestIt1.More(); ancestIt1.Next() )
623 if ( ancestIt1.Value().ShapeType() == TopAbs_FACE )
624 F1 = ancestIt1.Value().Oriented( TopAbs_FORWARD );
626 RETURN_BAD_RESULT(" Face1 not found");
628 // get 2 faces sharing edge2 (one of them is F2)
629 TopTools_ListIteratorOfListOfShape ancestIt2( edgeToFace2.FindFromKey( edge2 ));
630 for ( int i = 0; FF2[1].IsNull() && ancestIt2.More(); ancestIt2.Next() )
631 if ( ancestIt2.Value().ShapeType() == TopAbs_FACE )
632 FF2[ i++ ] = ancestIt2.Value().Oriented( TopAbs_FORWARD );
634 // get oriented edge1 and edge2 from F1 and FF2[0]
635 for ( exp.Init( F1, TopAbs_EDGE ); exp.More(); exp.Next() )
636 if ( edge1.IsSame( exp.Current() )) {
637 edge1 = TopoDS::Edge( exp.Current() );
640 for ( exp.Init( FF2[ 0 ], TopAbs_EDGE ); exp.More(); exp.Next() )
641 if ( edge2.IsSame( exp.Current() )) {
642 edge2 = TopoDS::Edge( exp.Current() );
646 // compare first vertices of edge1 and edge2
647 TopExp::Vertices( edge1, VV1[0], VV1[1], true );
648 TopExp::Vertices( edge2, VV2[0], VV2[1], true );
649 F2 = FF2[ 0 ]; // (F2 !)
650 if ( !VV1[ 0 ].IsSame( theMap( VV2[ 0 ], /*is2=*/true))) {
652 if ( FF2[ 1 ].IsNull() )
658 TopTools_MapOfShape boundEdges;
660 // association of face sub-shapes and neighbour faces
661 list< pair < TopoDS_Face, TopoDS_Edge > > FE1, FE2;
662 list< pair < TopoDS_Face, TopoDS_Edge > >::iterator fe1, fe2;
663 FE1.push_back( make_pair( TopoDS::Face( F1 ), edge1 ));
664 FE2.push_back( make_pair( TopoDS::Face( F2 ), edge2 ));
665 for ( fe1 = FE1.begin(), fe2 = FE2.begin(); fe1 != FE1.end(); ++fe1, ++fe2 )
667 const TopoDS_Face& face1 = fe1->first;
668 if ( theMap.IsBound( face1 ) ) continue;
669 const TopoDS_Face& face2 = fe2->first;
672 TopExp::Vertices( edge1, VV1[0], VV1[1], true );
673 TopExp::Vertices( edge2, VV2[0], VV2[1], true );
674 list< TopoDS_Edge > edges1, edges2;
675 int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2 );
676 if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
677 InsertAssociation( face1, face2, theMap ); // assoc faces
678 MESSAGE("Assoc FACE " << theMesh1->GetMeshDS()->ShapeToIndex( face1 )<<
679 " to " << theMesh2->GetMeshDS()->ShapeToIndex( face2 ));
680 if ( nbE == 2 && (edge1.IsSame( edges1.front())) != (edge2.IsSame( edges2.front())))
682 Reverse( edges2, nbE );
684 list< TopoDS_Edge >::iterator eIt1 = edges1.begin();
685 list< TopoDS_Edge >::iterator eIt2 = edges2.begin();
686 for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
688 if ( !boundEdges.Add( *eIt1 )) continue; // already associated
689 InsertAssociation( *eIt1, *eIt2, theMap ); // assoc edges
690 MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( *eIt1 )<<
691 " to " << theMesh2->GetMeshDS()->ShapeToIndex( *eIt2 ));
692 VV1[0] = TopExp::FirstVertex( *eIt1, true );
693 VV2[0] = TopExp::FirstVertex( *eIt2, true );
694 InsertAssociation( VV1[0], VV2[0], theMap ); // assoc vertices
695 MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[0] )<<
696 " to " << theMesh2->GetMeshDS()->ShapeToIndex( VV2[0] ));
698 // add adjacent faces to process
699 TopoDS_Face nextFace1 = GetNextFace( edgeToFace1, *eIt1, face1 );
700 TopoDS_Face nextFace2 = GetNextFace( edgeToFace2, *eIt2, face2 );
701 if ( !nextFace1.IsNull() && !nextFace2.IsNull() ) {
702 FE1.push_back( make_pair( nextFace1, *eIt1 ));
703 FE2.push_back( make_pair( nextFace2, *eIt2 ));
707 InsertAssociation( theShape1, theShape2, theMap );
710 // ----------------------------------------------------------------------
711 case TopAbs_COMPOUND: { // GROUP
712 // ----------------------------------------------------------------------
713 // Maybe groups contain only one member
714 TopoDS_Iterator it1( theShape1 ), it2( theShape2 );
715 TopAbs_ShapeEnum memberType = it1.Value().ShapeType();
716 int nbMembers = Count( theShape1, memberType, true );
717 if ( nbMembers == 0 ) return true;
718 if ( nbMembers == 1 ) {
719 return FindSubShapeAssociation( it1.Value(), theMesh1, it2.Value(), theMesh2, theMap );
721 // Try to make shells of faces
723 BRep_Builder builder;
724 TopoDS_Shell shell1, shell2;
725 builder.MakeShell(shell1); builder.MakeShell(shell2);
726 if ( memberType == TopAbs_FACE ) {
727 // just add faces of groups to shells
728 for (; it1.More(); it1.Next(), it2.Next() )
729 builder.Add( shell1, it1.Value() ), builder.Add( shell2, it2.Value() );
731 else if ( memberType == TopAbs_EDGE ) {
732 // Try to add faces sharing more than one edge of a group or
733 // sharing all its vertices with the group
734 TopTools_IndexedMapOfShape groupVertices[2];
735 TopExp::MapShapes( theShape1, TopAbs_VERTEX, groupVertices[0]);
736 TopExp::MapShapes( theShape2, TopAbs_VERTEX, groupVertices[1]);
738 TopTools_MapOfShape groupEdges[2], addedFaces[2];
739 bool hasInitAssoc = (!theMap.IsEmpty()), initAssocOK = !hasInitAssoc;
740 for (; it1.More(); it1.Next(), it2.Next() ) {
741 groupEdges[0].Add( it1.Value() );
742 groupEdges[1].Add( it2.Value() );
743 if ( !initAssocOK ) {
744 // for shell association there must be an edge with both vertices bound
745 TopoDS_Vertex v1, v2;
746 TopExp::Vertices( TopoDS::Edge( it1.Value().Oriented(TopAbs_FORWARD)), v1, v2 );
747 initAssocOK = ( theMap.IsBound( v1 ) && theMap.IsBound( v2 ));
750 for (int is2ndGroup = 0; initAssocOK && is2ndGroup < 2; ++is2ndGroup) {
751 const TopoDS_Shape& group = is2ndGroup ? theShape2: theShape1;
752 SMESH_Mesh* mesh = is2ndGroup ? theMesh2 : theMesh1;
753 TopoDS_Shell& shell = is2ndGroup ? shell2 : shell1;
754 for ( TopoDS_Iterator it( group ); it.More(); it.Next() ) {
755 const TopoDS_Edge& edge = TopoDS::Edge( it.Value() );
757 for ( int iF = 0; iF < 2; ++iF ) { // loop on 2 faces sharing edge
758 face = GetNextFace(mesh->GetAncestorMap(), edge, face);
759 if ( !face.IsNull() ) {
760 int nbGroupEdges = 0;
761 for ( TopExp_Explorer f( face, TopAbs_EDGE ); f.More(); f.Next())
762 if ( groupEdges[ is2ndGroup ].Contains( f.Current() ))
763 if ( ++nbGroupEdges > 1 )
765 bool add = (nbGroupEdges > 1 || Count( face, TopAbs_EDGE, true ) == 1 );
768 for ( TopExp_Explorer v( face, TopAbs_VERTEX ); add && v.More(); v.Next())
769 add = groupVertices[ is2ndGroup ].Contains( v.Current() );
771 if ( add && addedFaces[ is2ndGroup ].Add( face ))
772 builder.Add( shell, face );
778 RETURN_BAD_RESULT("Unexpected group type");
782 int nbFaces1 = Count( shell1, TopAbs_FACE, 0 );
783 int nbFaces2 = Count( shell2, TopAbs_FACE, 0 );
784 if ( nbFaces1 != nbFaces2 )
785 RETURN_BAD_RESULT("Different nb of faces found for shells");
786 if ( nbFaces1 > 0 ) {
788 if ( nbFaces1 == 1 ) {
789 TopoDS_Shape F1 = TopoDS_Iterator( shell1 ).Value();
790 TopoDS_Shape F2 = TopoDS_Iterator( shell2 ).Value();
791 ok = FindSubShapeAssociation( F1, theMesh1, F2, theMesh2, theMap );
794 ok = FindSubShapeAssociation(shell1, theMesh1, shell2, theMesh2, theMap );
796 // Check if all members are mapped
798 TopTools_MapOfShape boundMembers[2];
800 for ( mIt.Initialize( theShape1 ); mIt.More(); mIt.Next())
801 if ( theMap.IsBound( mIt.Value() )) {
802 boundMembers[0].Add( mIt.Value() );
803 boundMembers[1].Add( theMap( mIt.Value() ));
805 if ( boundMembers[0].Extent() != nbMembers ) {
806 // make compounds of not bound members
807 TopoDS_Compound comp[2];
808 for ( int is2ndGroup = 0; is2ndGroup < 2; ++is2ndGroup ) {
809 builder.MakeCompound( comp[is2ndGroup] );
810 for ( mIt.Initialize( is2ndGroup ? theShape2:theShape1 ); mIt.More(); mIt.Next())
811 if ( ! boundMembers[ is2ndGroup ].Contains( mIt.Value() ))
812 builder.Add( comp[ is2ndGroup ], mIt.Value() );
814 // check if theMap contains initial association for the comp's
815 bool hasInitialAssoc = false;
816 if ( memberType == TopAbs_EDGE ) {
817 for ( TopExp_Explorer v( comp[0], TopAbs_VERTEX ); v.More(); v.Next())
818 if ( theMap.IsBound( v.Current() )) {
819 hasInitialAssoc = true;
823 if ( hasInitialAssoc == bool( !theMap.IsEmpty() ))
824 ok = FindSubShapeAssociation( comp[0], theMesh1, comp[1], theMesh2, theMap );
826 TShapeShapeMap tmpMap;
827 ok = FindSubShapeAssociation( comp[0], theMesh1, comp[1], theMesh2, tmpMap );
829 TopTools_DataMapIteratorOfDataMapOfShapeShape mapIt( tmpMap._map1to2 );
830 for ( ; mapIt.More(); mapIt.Next() )
831 theMap.Bind( mapIt.Key(), mapIt.Value());
838 // Each edge of an edge group is shared by own faces
839 // ------------------------------------------------------------------
841 // map vertices to edges sharing them, avoid doubling edges in lists
842 TopTools_DataMapOfShapeListOfShape v2e[2];
843 for (int isFirst = 0; isFirst < 2; ++isFirst ) {
844 const TopoDS_Shape& group = isFirst ? theShape1 : theShape2;
845 TopTools_DataMapOfShapeListOfShape& veMap = v2e[ isFirst ? 0 : 1 ];
846 TopTools_MapOfShape addedEdges;
847 for ( TopExp_Explorer e( group, TopAbs_EDGE ); e.More(); e.Next() ) {
848 const TopoDS_Shape& edge = e.Current();
849 if ( addedEdges.Add( edge )) {
850 for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next()) {
851 const TopoDS_Shape& vertex = v.Current();
852 if ( !veMap.IsBound( vertex )) {
853 TopTools_ListOfShape l;
854 veMap.Bind( vertex, l );
856 veMap( vertex ).Append( edge );
861 while ( !v2e[0].IsEmpty() )
863 // find a bound vertex
865 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape v2eIt( v2e[0] );
866 for ( ; v2eIt.More(); v2eIt.Next())
867 if ( theMap.IsBound( v2eIt.Key() )) {
868 V[0] = TopoDS::Vertex( v2eIt.Key() );
869 V[1] = TopoDS::Vertex( theMap( V[0] ));
873 RETURN_BAD_RESULT("No more bound vertices");
875 while ( !V[0].IsNull() && v2e[0].IsBound( V[0] )) {
876 TopTools_ListOfShape& edges0 = v2e[0]( V[0] );
877 TopTools_ListOfShape& edges1 = v2e[1]( V[1] );
878 int nbE0 = edges0.Extent(), nbE1 = edges1.Extent();
880 RETURN_BAD_RESULT("Different nb of edges: "<< nbE0 << " != " << nbE1);
884 TopoDS_Edge e0 = TopoDS::Edge( edges0.First() );
885 TopoDS_Edge e1 = TopoDS::Edge( edges1.First() );
886 v2e[0].UnBind( V[0] );
887 v2e[1].UnBind( V[1] );
888 InsertAssociation( e0, e1, theMap );
889 MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0 )<<
890 " to " << theMesh2->GetMeshDS()->ShapeToIndex( e1 ));
891 V[0] = GetNextVertex( e0, V[0] );
892 V[1] = GetNextVertex( e1, V[1] );
893 if ( !V[0].IsNull() ) {
894 InsertAssociation( V[0], V[1], theMap );
895 MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( V[0] )<<
896 " to " << theMesh2->GetMeshDS()->ShapeToIndex( V[1] ));
899 else if ( nbE0 == 2 )
901 // one of edges must have both ends bound
902 TopoDS_Vertex v0e0 = GetNextVertex( TopoDS::Edge( edges0.First() ), V[0] );
903 TopoDS_Vertex v1e0 = GetNextVertex( TopoDS::Edge( edges0.Last() ), V[0] );
904 TopoDS_Vertex v0e1 = GetNextVertex( TopoDS::Edge( edges1.First() ), V[1] );
905 TopoDS_Vertex v1e1 = GetNextVertex( TopoDS::Edge( edges1.Last() ), V[1] );
906 TopoDS_Shape e0b, e1b, e0n, e1n, v1b; // bound and not-bound
907 TopoDS_Vertex v0n, v1n;
908 if ( theMap.IsBound( v0e0 )) {
909 v0n = v1e0; e0b = edges0.First(); e0n = edges0.Last(); v1b = theMap( v0e0 );
910 } else if ( theMap.IsBound( v1e0 )) {
911 v0n = v0e0; e0n = edges0.First(); e0b = edges0.Last(); v1b = theMap( v1e0 );
913 RETURN_BAD_RESULT("None of vertices bound");
915 if ( v1b.IsSame( v1e1 )) {
916 v1n = v0e1; e1n = edges1.First(); e1b = edges1.Last();
918 v1n = v1e1; e1b = edges1.First(); e1n = edges1.Last();
920 InsertAssociation( e0b, e1b, theMap );
921 InsertAssociation( e0n, e1n, theMap );
922 InsertAssociation( v0n, v1n, theMap );
923 MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0b )<<
924 " to " << theMesh2->GetMeshDS()->ShapeToIndex( e1b ));
925 MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0n )<<
926 " to " << theMesh2->GetMeshDS()->ShapeToIndex( e1n ));
927 MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( v0n )<<
928 " to " << theMesh2->GetMeshDS()->ShapeToIndex( v1n ));
929 v2e[0].UnBind( V[0] );
930 v2e[1].UnBind( V[1] );
935 RETURN_BAD_RESULT("Not implemented");
938 } //while ( !v2e[0].IsEmpty() )
943 RETURN_BAD_RESULT("Unexpected shape type");
945 } // end switch by shape type
946 } // end case of available initial vertex association
948 //======================================================================
949 // 4) NO INITIAL VERTEX ASSOCIATION
950 //======================================================================
952 switch ( theShape1.ShapeType() ) {
955 // ----------------------------------------------------------------------
956 TopoDS_Edge edge1 = TopoDS::Edge( theShape1 );
957 TopoDS_Edge edge2 = TopoDS::Edge( theShape2 );
958 if ( IsPropagationPossible( theMesh1, theMesh2 ))
960 TopoDS_Edge prpEdge = GetPropagationEdge( theMesh1, edge2, edge1 ).second;
961 if ( !prpEdge.IsNull() )
963 TopoDS_Vertex VV1[2], VV2[2];
964 TopExp::Vertices( edge1, VV1[0], VV1[1], true );
965 TopExp::Vertices( prpEdge, VV2[0], VV2[1], true );
966 InsertAssociation( VV1[ 0 ], VV2[ 0 ], theMap );
967 InsertAssociation( VV1[ 1 ], VV2[ 1 ], theMap );
968 if ( VV1[0].IsSame( VV1[1] ) || // one of edges is closed
969 VV2[0].IsSame( VV2[1] ) )
971 InsertAssociation( edge1, prpEdge, theMap ); // insert with a proper orientation
973 InsertAssociation( theShape1, theShape2, theMap );
977 if ( SMESH_MesherHelper::IsClosedEdge( edge1 ) &&
978 SMESH_MesherHelper::IsClosedEdge( edge2 ))
980 // TODO: find out a proper orientation (is it possible?)
981 InsertAssociation( edge1, edge2, theMap ); // insert with a proper orientation
982 InsertAssociation( TopExp::FirstVertex(edge1), TopExp::FirstVertex(edge2),
984 InsertAssociation( theShape1, theShape2, theMap );
987 break; // try by vertex closeness
991 // ----------------------------------------------------------------------
992 if ( IsPropagationPossible( theMesh1, theMesh2 )) // try by propagation in one mesh
994 TopoDS_Face face1 = TopoDS::Face(theShape1);
995 TopoDS_Face face2 = TopoDS::Face(theShape2);
996 if ( face1.Orientation() >= TopAbs_INTERNAL ) face1.Orientation( TopAbs_FORWARD );
997 if ( face2.Orientation() >= TopAbs_INTERNAL ) face2.Orientation( TopAbs_FORWARD );
998 TopoDS_Edge edge1, edge2;
999 // get outer edge of theShape1
1000 edge1 = TopoDS::Edge( OuterShape( face1, TopAbs_EDGE ));
1001 // find out if any edge of face2 is a propagation edge of outer edge1
1002 map<int,TopoDS_Edge> propag_edges; // use map to find the closest propagation edge
1003 for ( TopExp_Explorer exp( face2, TopAbs_EDGE ); exp.More(); exp.Next() ) {
1004 edge2 = TopoDS::Edge( exp.Current() );
1005 pair<int,TopoDS_Edge> step_edge = GetPropagationEdge( theMesh1, edge2, edge1 );
1006 if ( !step_edge.second.IsNull() ) { // propagation found
1007 propag_edges.insert( step_edge );
1008 if ( step_edge.first == 1 ) break; // most close found
1011 if ( !propag_edges.empty() ) // propagation found
1013 edge2 = propag_edges.begin()->second;
1014 TopoDS_Vertex VV1[2], VV2[2];
1015 TopExp::Vertices( edge1, VV1[0], VV1[1], true );
1016 TopExp::Vertices( edge2, VV2[0], VV2[1], true );
1017 list< TopoDS_Edge > edges1, edges2;
1018 int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2 );
1019 if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
1020 // take care of proper association of propagated edges
1021 bool same1 = edge1.IsSame( edges1.front() );
1022 bool same2 = edge2.IsSame( edges2.front() );
1023 if ( same1 != same2 )
1025 Reverse(edges2, nbE);
1026 if ( nbE != 2 ) // 2 degen edges of 4 (issue 0021144)
1027 edges2.splice( edges2.end(), edges2, edges2.begin());
1029 // store association
1030 list< TopoDS_Edge >::iterator eIt1 = edges1.begin();
1031 list< TopoDS_Edge >::iterator eIt2 = edges2.begin();
1032 for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
1034 InsertAssociation( *eIt1, *eIt2, theMap );
1035 VV1[0] = TopExp::FirstVertex( *eIt1, true );
1036 VV2[0] = TopExp::FirstVertex( *eIt2, true );
1037 InsertAssociation( VV1[0], VV2[0], theMap );
1039 InsertAssociation( theShape1, theShape2, theMap );
1043 break; // try by vertex closeness
1045 case TopAbs_COMPOUND: {
1046 // ----------------------------------------------------------------------
1047 if ( IsPropagationPossible( theMesh1, theMesh2 )) {
1049 // try to accosiate all using propagation
1050 if ( AssocGroupsByPropagation( theShape1, theShape2, *theMesh1, theMap ))
1053 // find a boundary edge of theShape1
1054 TopoDS_Edge E = GetBoundaryEdge( theShape1, *theMesh1 );
1056 break; // try by vertex closeness
1058 // find association for vertices of edge E
1059 TopoDS_Vertex VV1[2], VV2[2];
1060 for(TopExp_Explorer eexp(E, TopAbs_VERTEX); eexp.More(); eexp.Next()) {
1061 TopoDS_Vertex V1 = TopoDS::Vertex( eexp.Current() );
1062 // look for an edge ending in E whose one vertex is in theShape1
1063 // and the other, in theShape2
1064 const TopTools_ListOfShape& Ancestors = theMesh1->GetAncestors(V1);
1065 TopTools_ListIteratorOfListOfShape ita(Ancestors);
1066 for(; ita.More(); ita.Next()) {
1067 if( ita.Value().ShapeType() != TopAbs_EDGE ) continue;
1068 TopoDS_Edge edge = TopoDS::Edge(ita.Value());
1069 bool FromShape1 = false;
1070 for(TopExp_Explorer expe(theShape1, TopAbs_EDGE); expe.More(); expe.Next() ) {
1071 if(edge.IsSame(expe.Current())) {
1077 // is it an edge between theShape1 and theShape2?
1078 TopExp_Explorer expv(edge, TopAbs_VERTEX);
1079 TopoDS_Vertex V2 = TopoDS::Vertex( expv.Current() );
1082 V2 = TopoDS::Vertex( expv.Current() );
1084 bool FromShape2 = false;
1085 for ( expv.Init( theShape2, TopAbs_VERTEX ); expv.More(); expv.Next()) {
1086 if ( V2.IsSame( expv.Current() )) {
1092 if ( VV1[0].IsNull() )
1093 VV1[0] = V1, VV2[0] = V2;
1095 VV1[1] = V1, VV2[1] = V2;
1096 break; // from loop on ancestors of V1
1101 if ( !VV1[1].IsNull() ) {
1102 InsertAssociation( VV1[0], VV2[0], theMap );
1103 InsertAssociation( VV1[1], VV2[1], theMap );
1104 return FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap);
1107 break; // try by vertex closeness
1112 // 4.b) Find association by closeness of vertices
1113 // ----------------------------------------------
1115 TopTools_IndexedMapOfShape vMap1, vMap2;
1116 TopExp::MapShapes( theShape1, TopAbs_VERTEX, vMap1 );
1117 TopExp::MapShapes( theShape2, TopAbs_VERTEX, vMap2 );
1118 TopoDS_Vertex VV1[2], VV2[2];
1120 if ( vMap1.Extent() != vMap2.Extent() )
1121 RETURN_BAD_RESULT("Different nb of vertices");
1123 if ( vMap1.Extent() == 1 ) {
1124 InsertAssociation( vMap1(1), vMap2(1), theMap );
1125 if ( theShape1.ShapeType() == TopAbs_EDGE ) {
1126 InsertAssociation( theShape1, theShape2, theMap );
1129 return FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap);
1132 // Try to associate by common vertices of an edge
1133 for ( int i = 1; i <= vMap1.Extent(); ++i )
1135 const TopoDS_Shape& v1 = vMap1(i);
1136 if ( vMap2.Contains( v1 ))
1138 // find an egde sharing v1 and sharing at the same time another common vertex
1139 PShapeIteratorPtr edgeIt = SMESH_MesherHelper::GetAncestors( v1, *theMesh1, TopAbs_EDGE);
1140 bool edgeFound = false;
1141 while ( edgeIt->more() && !edgeFound )
1143 TopoDS_Edge edge = TopoDS::Edge( edgeIt->next()->Oriented(TopAbs_FORWARD));
1144 TopExp::Vertices(edge, VV1[0], VV1[1]);
1145 if ( !VV1[0].IsSame( VV1[1] ))
1146 edgeFound = ( vMap2.Contains( VV1[ v1.IsSame(VV1[0]) ? 1:0]));
1150 InsertAssociation( VV1[0], VV1[0], theMap );
1151 InsertAssociation( VV1[1], VV1[1], theMap );
1152 if (FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap ))
1158 // Find transformation to make the shapes be of similar size at same location
1161 for ( int i = 1; i <= vMap1.Extent(); ++i ) {
1162 box[ 0 ].Add( BRep_Tool::Pnt ( TopoDS::Vertex( vMap1( i ))));
1163 box[ 1 ].Add( BRep_Tool::Pnt ( TopoDS::Vertex( vMap2( i ))));
1166 gp_Pnt gc[2]; // box center
1167 double x0,y0,z0, x1,y1,z1;
1168 box[0].Get( x0,y0,z0, x1,y1,z1 );
1169 gc[0] = 0.5 * ( gp_XYZ( x0,y0,z0 ) + gp_XYZ( x1,y1,z1 ));
1170 box[1].Get( x0,y0,z0, x1,y1,z1 );
1171 gc[1] = 0.5 * ( gp_XYZ( x0,y0,z0 ) + gp_XYZ( x1,y1,z1 ));
1174 gp_Vec vec01( gc[0], gc[1] );
1175 double scale = sqrt( box[1].SquareExtent() / box[0].SquareExtent() );
1177 // Find 2 closest vertices
1179 // get 2 linked vertices of shape 1 not belonging to an inner wire of a face
1180 std::list< TopoDS_Edge > allBndEdges1;
1181 if ( !getOuterEdges( theShape1, *theMesh1, allBndEdges1 ))
1182 RETURN_BAD_RESULT("Edge not found");
1184 std::list< TopoDS_Edge >::iterator edge1 = allBndEdges1.begin();
1185 double minDist = std::numeric_limits<double>::max();
1186 for ( int nbChecked=0; edge1 != allBndEdges1.end() && nbChecked++ < 10; ++edge1 )
1188 TopExp::Vertices( TopoDS::Edge( edge1->Oriented(TopAbs_FORWARD)), VV1[0], VV1[1]);
1189 if ( VV1[0].IsSame( VV1[1] ))
1190 continue;//RETURN_BAD_RESULT("Only closed edges");
1192 // find vertices closest to 2 linked vertices of shape 1
1193 double dist2[2] = { 1e+100, 1e+100 };
1194 TopoDS_Vertex edge2VV[2];
1195 for ( int i1 = 0; i1 < 2; ++i1 )
1197 gp_Pnt p1 = BRep_Tool::Pnt( VV1[ i1 ]);
1198 p1.Scale( gc[0], scale );
1199 p1.Translate( vec01 );
1201 // select a closest vertex among all ones in vMap2
1202 for ( int i2 = 1; i2 <= vMap2.Extent(); ++i2 )
1204 TopoDS_Vertex V2 = TopoDS::Vertex( vMap2( i2 ));
1205 gp_Pnt p2 = BRep_Tool::Pnt ( V2 );
1206 double d2 = p1.SquareDistance( p2 );
1207 if ( d2 < dist2[ 0 ] && d2 < minDist ) {
1213 else if ( !edge2VV[0].IsNull() ) {
1214 // select a closest vertex among ends of edges meeting at edge2VV[0]
1215 PShapeIteratorPtr edgeIt = SMESH_MesherHelper::GetAncestors( edge2VV[0],
1216 *theMesh2, TopAbs_EDGE);
1217 while ( const TopoDS_Shape* edge2 = edgeIt->next() )
1218 for ( TopoDS_Iterator itV2( *edge2 ); itV2.More(); itV2.Next() )
1220 if ( itV2.Value().IsSame( edge2VV[ 0 ])) continue;
1221 if ( !vMap2.Contains( itV2.Value() )) continue;
1222 TopoDS_Vertex V2 = TopoDS::Vertex( itV2.Value() );
1223 gp_Pnt p2 = BRep_Tool::Pnt ( V2 );
1224 double d2 = p1.SquareDistance( p2 );
1225 if ( d2 < dist2[1] && d2 < minDist ) {
1232 if ( dist2[0] + dist2[1] < minDist ) {
1233 VV2[0] = edge2VV[0];
1234 VV2[1] = edge2VV[1];
1235 minDist = dist2[0] + dist2[1];
1236 if ( minDist < 1e-10 )
1241 InsertAssociation( VV1[ 0 ], VV2[ 0 ], theMap );
1242 InsertAssociation( VV1[ 1 ], VV2[ 1 ], theMap );
1243 MESSAGE("Initial assoc VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 0 ] )<<
1244 " to " << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 0 ] )<<
1245 "\nand VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 1 ] )<<
1246 " to " << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 1 ] ));
1247 if ( theShape1.ShapeType() == TopAbs_EDGE ) {
1248 InsertAssociation( theShape1, theShape2, theMap );
1252 return FindSubShapeAssociation( theShape1, theMesh1, theShape2, theMesh2, theMap );
1255 //================================================================================
1257 * \brief Find association of edges of faces
1258 * \param face1 - face 1
1259 * \param VV1 - vertices of face 1
1260 * \param face2 - face 2
1261 * \param VV2 - vertices of face 2 associated with ones of face 1
1262 * \param edges1 - out list of edges of face 1
1263 * \param edges2 - out list of edges of face 2
1264 * \retval int - nb of edges in an outer wire in a success case, else zero
1266 //================================================================================
1268 int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face& face1,
1269 TopoDS_Vertex VV1[2],
1270 const TopoDS_Face& face2,
1271 TopoDS_Vertex VV2[2],
1272 list< TopoDS_Edge > & edges1,
1273 list< TopoDS_Edge > & edges2)
1276 list< int > nbEInW1, nbEInW2;
1277 list< TopoDS_Edge >::iterator edgeIt;
1278 int i_ok_wire_algo = -1;
1279 for ( int outer_wire_algo = 0; outer_wire_algo < 2 && !OK; ++outer_wire_algo )
1284 if ( SMESH_Block::GetOrderedEdges( face1, VV1[0], edges1, nbEInW1, outer_wire_algo) !=
1285 SMESH_Block::GetOrderedEdges( face2, VV2[0], edges2, nbEInW2, outer_wire_algo) )
1286 CONT_BAD_RESULT("Different number of wires in faces ");
1288 if ( nbEInW1 != nbEInW2 && outer_wire_algo == 0 &&
1289 ( std::accumulate( nbEInW1.begin(), nbEInW1.end(), 0) !=
1290 std::accumulate( nbEInW2.begin(), nbEInW2.end(), 0)))
1291 RETURN_BAD_RESULT("Different number of edges in faces");
1293 if ( nbEInW1.front() != nbEInW2.front() )
1294 CONT_BAD_RESULT("Different number of edges in the outer wire: " <<
1295 nbEInW1.front() << " != " << nbEInW2.front());
1297 i_ok_wire_algo = outer_wire_algo;
1299 // Define if we need to reverse one of wires to make edges in lists match each other
1301 bool reverse = false;
1303 if ( !VV1[1].IsSame( TopExp::LastVertex( edges1.front(), true ))) {
1305 edgeIt = --edges1.end();
1306 // check if the second vertex belongs to the first or last edge in the wire
1307 if ( !VV1[1].IsSame( TopExp::FirstVertex( *edgeIt, true ))) {
1308 bool KO = true; // belongs to none
1309 if ( nbEInW1.size() > 1 ) { // several wires
1310 edgeIt = edges1.begin();
1311 std::advance( edgeIt, nbEInW1.front()-1 );
1312 KO = !VV1[1].IsSame( TopExp::FirstVertex( *edgeIt, true ));
1315 CONT_BAD_RESULT("GetOrderedEdges() failed");
1318 edgeIt = --edges2.end();
1319 if ( !VV2[1].IsSame( TopExp::LastVertex( edges2.front(), true ))) {
1321 // check if the second vertex belongs to the first or last edge in the wire
1322 if ( !VV2[1].IsSame( TopExp::FirstVertex( *edgeIt, true ))) {
1323 bool KO = true; // belongs to none
1324 if ( nbEInW2.size() > 1 ) { // several wires
1325 edgeIt = edges2.begin();
1326 std::advance( edgeIt, nbEInW2.front()-1 );
1327 KO = !VV2[1].IsSame( TopExp::FirstVertex( *edgeIt, true ));
1330 CONT_BAD_RESULT("GetOrderedEdges() failed");
1335 Reverse( edges2 , nbEInW2.front());
1336 if (( VV1[1].IsSame( TopExp::LastVertex( edges1.front(), true ))) !=
1337 ( VV2[1].IsSame( TopExp::LastVertex( edges2.front(), true ))))
1338 CONT_BAD_RESULT("GetOrderedEdges() failed");
1342 } // loop algos getting an outer wire
1344 // Try to orient all (if !OK) or only internal wires (issue 0020996) by UV similarity
1346 if (( !OK || nbEInW1.size() > 1 ) && i_ok_wire_algo > -1 )
1348 // Check that Vec(VV1[0],VV1[1]) in 2D on face1 is the same
1349 // as Vec(VV2[0],VV2[1]) on face2
1350 double vTol = BRep_Tool::Tolerance( VV1[0] );
1351 BRepAdaptor_Surface surface1( face1, false );
1353 surface1.UResolution( vTol ) + surface1.VResolution( vTol ); // let's be tolerant
1354 gp_Pnt2d v0f1UV = BRep_Tool::Parameters( VV1[0], face1 );
1355 gp_Pnt2d v0f2UV = BRep_Tool::Parameters( VV2[0], face2 );
1356 gp_Pnt2d v1f1UV = BRep_Tool::Parameters( VV1[1], face1 );
1357 gp_Pnt2d v1f2UV = BRep_Tool::Parameters( VV2[1], face2 );
1358 gp_Vec2d v01f1Vec( v0f1UV, v1f1UV );
1359 gp_Vec2d v01f2Vec( v0f2UV, v1f2UV );
1360 if ( Abs( v01f1Vec.X()-v01f2Vec.X()) < vTolUV &&
1361 Abs( v01f1Vec.Y()-v01f2Vec.Y()) < vTolUV )
1363 if ( !OK /*i_ok_wire_algo != 1*/ )
1367 SMESH_Block::GetOrderedEdges( face1, VV1[0], edges1, nbEInW1, i_ok_wire_algo);
1368 SMESH_Block::GetOrderedEdges( face2, VV2[0], edges2, nbEInW2, i_ok_wire_algo);
1370 gp_XY dUV = v0f2UV.XY() - v0f1UV.XY(); // UV shift between 2 faces
1372 // skip edges of the outer wire (if the outer wire is OK)
1373 list< int >::iterator nbE2, nbE1 = nbEInW1.begin();
1374 list< TopoDS_Edge >::iterator edge2Beg, edge1Beg = edges1.begin();
1375 if ( OK ) std::advance( edge1Beg, *nbE1++ );
1376 // reach an end of edges of a current wire1
1377 list< TopoDS_Edge >::iterator edge2End, edge1End;
1379 // find corresponding wires of face2
1380 for ( int iW1 = OK; nbE1 != nbEInW1.end(); ++nbE1, ++iW1 ) // loop on wires of face1
1382 // reach an end of edges of a current wire1
1383 edge1End = edge1Beg;
1384 std::advance( edge1End, *nbE1 );
1385 // UV on face1 to find on face2
1386 v0f1UV = BRep_Tool::Parameters( TopExp::FirstVertex(*edge1Beg,true), face1 );
1387 v1f1UV = BRep_Tool::Parameters( TopExp::LastVertex (*edge1Beg,true), face1 );
1388 v0f1UV.ChangeCoord() += dUV;
1389 v1f1UV.ChangeCoord() += dUV;
1391 // look through wires of face2
1392 edge2Beg = edges2.begin();
1393 nbE2 = nbEInW2.begin();
1394 if ( OK ) std::advance( edge2Beg, *nbE2++ );
1395 for ( int iW2 = OK; nbE2 != nbEInW2.end(); ++nbE2, ++iW2 ) // loop on wires of face2
1397 // reach an end of edges of a current wire2
1398 edge2End = edge2Beg;
1399 std::advance( edge2End, *nbE2 );
1400 if ( *nbE1 == *nbE2 && iW2 >= iW1 )
1402 // rotate edge2 untill coincidence with edge1 in 2D
1404 while ( i-- > 0 && !sameVertexUV( *edge2Beg, face2, 0, v0f1UV, vTolUV ))
1405 // move edge2Beg to place before edge2End
1406 edges2.splice( edge2End, edges2, edge2Beg++ );
1408 if ( sameVertexUV( *edge2Beg, face2, 0, v0f1UV, vTolUV ))
1410 if ( iW1 == 0 ) OK = true; // OK is for the first wire
1411 // reverse edges2 if needed
1412 if ( !sameVertexUV( *edge2Beg, face2, 1, v1f1UV, vTolUV ))
1413 Reverse( edges2 , *nbE2, std::distance( edges2.begin(),edge2Beg ));
1414 // put wire2 at a right place within edges2
1416 list< TopoDS_Edge >::iterator place2 = edges2.begin();
1417 std::advance( place2, std::distance( edges1.begin(), edge1Beg ));
1418 edges2.splice( place2, edges2, edge2Beg, edge2End );
1419 // move nbE2 as well
1420 list< int >::iterator placeNbE2 = nbEInW2.begin();
1421 std::advance( placeNbE2, iW1 );
1422 nbEInW2.splice( placeNbE2, nbEInW2, nbE2 );
1427 // prepare to the next wire loop
1428 edge2Beg = edge2End;
1430 edge1Beg = edge1End;
1435 const int nbEdges = nbEInW1.front();
1436 if ( OK && nbEdges == 2 )
1438 // if wires include 2 edges, it's impossible to associate them using
1439 // topological information only. Try to use length of edges for association.
1440 double l1[2], l2[2];
1441 edgeIt = edges1.begin();
1442 l1[0] = SMESH_Algo::EdgeLength( *edgeIt++ );
1443 l1[1] = SMESH_Algo::EdgeLength( *edgeIt++ );
1444 if ( Abs( l1[0] - l1[1] ) > 0.1 * Max( l1[0], l1[1] ) )
1446 edgeIt = edges2.begin();
1447 l2[0] = SMESH_Algo::EdgeLength( *edgeIt++ );
1448 l2[1] = SMESH_Algo::EdgeLength( *edgeIt++ );
1449 if (( l1[0] < l1[1] ) != ( l2[0] < l2[1] ))
1451 Reverse( edges2, nbEdges );
1456 return OK ? nbEInW1.front() : 0;
1459 //=======================================================================
1460 //function : InitVertexAssociation
1462 //=======================================================================
1464 void StdMeshers_ProjectionUtils::InitVertexAssociation( const SMESH_Hypothesis* theHyp,
1465 TShapeShapeMap & theAssociationMap)
1467 string hypName = theHyp->GetName();
1468 if ( hypName == "ProjectionSource1D" ) {
1469 const StdMeshers_ProjectionSource1D * hyp =
1470 static_cast<const StdMeshers_ProjectionSource1D*>( theHyp );
1471 if ( hyp->HasVertexAssociation() )
1472 InsertAssociation( hyp->GetTargetVertex(),hyp->GetSourceVertex(),theAssociationMap );
1474 else if ( hypName == "ProjectionSource2D" ) {
1475 const StdMeshers_ProjectionSource2D * hyp =
1476 static_cast<const StdMeshers_ProjectionSource2D*>( theHyp );
1477 if ( hyp->HasVertexAssociation() ) {
1478 InsertAssociation( hyp->GetTargetVertex(1),hyp->GetSourceVertex(1),theAssociationMap);
1479 InsertAssociation( hyp->GetTargetVertex(2),hyp->GetSourceVertex(2),theAssociationMap);
1482 else if ( hypName == "ProjectionSource3D" ) {
1483 const StdMeshers_ProjectionSource3D * hyp =
1484 static_cast<const StdMeshers_ProjectionSource3D*>( theHyp );
1485 if ( hyp->HasVertexAssociation() ) {
1486 InsertAssociation( hyp->GetTargetVertex(1),hyp->GetSourceVertex(1),theAssociationMap);
1487 InsertAssociation( hyp->GetTargetVertex(2),hyp->GetSourceVertex(2),theAssociationMap);
1492 //=======================================================================
1494 * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
1495 * \param theShape1 - target shape
1496 * \param theShape2 - source shape
1497 * \param theAssociationMap - association map
1498 * \retval bool - true if there was no association for these shapes before
1500 //=======================================================================
1502 bool StdMeshers_ProjectionUtils::InsertAssociation( const TopoDS_Shape& theShape1, // tgt
1503 const TopoDS_Shape& theShape2, // src
1504 TShapeShapeMap & theAssociationMap)
1506 if ( !theShape1.IsNull() && !theShape2.IsNull() ) {
1507 SHOW_SHAPE(theShape1,"Assoc ");
1508 SHOW_SHAPE(theShape2," to ");
1509 bool isNew = ( theAssociationMap.Bind( theShape1, theShape2 ));
1513 throw SALOME_Exception("StdMeshers_ProjectionUtils: attempt to associate NULL shape");
1518 //=======================================================================
1520 * \brief Finds an edge by its vertices in a main shape of the mesh
1521 * \param aMesh - the mesh
1522 * \param V1 - vertex 1
1523 * \param V2 - vertex 2
1524 * \retval TopoDS_Edge - found edge
1526 //=======================================================================
1528 TopoDS_Edge StdMeshers_ProjectionUtils::GetEdgeByVertices( SMESH_Mesh* theMesh,
1529 const TopoDS_Vertex& theV1,
1530 const TopoDS_Vertex& theV2)
1532 if ( theMesh && !theV1.IsNull() && !theV2.IsNull() )
1534 TopTools_ListIteratorOfListOfShape ancestorIt( theMesh->GetAncestors( theV1 ));
1535 for ( ; ancestorIt.More(); ancestorIt.Next() )
1536 if ( ancestorIt.Value().ShapeType() == TopAbs_EDGE )
1537 for ( TopExp_Explorer expV ( ancestorIt.Value(), TopAbs_VERTEX );
1540 if ( theV2.IsSame( expV.Current() ))
1541 return TopoDS::Edge( ancestorIt.Value() );
1543 return TopoDS_Edge();
1546 //================================================================================
1548 * \brief Return another face sharing an edge
1549 * \param edgeToFaces - data map of descendants to ancestors
1550 * \param edge - edge
1551 * \param face - face
1552 * \retval TopoDS_Face - found face
1554 //================================================================================
1556 TopoDS_Face StdMeshers_ProjectionUtils::GetNextFace( const TAncestorMap& edgeToFaces,
1557 const TopoDS_Edge& edge,
1558 const TopoDS_Face& face)
1560 // if ( !edge.IsNull() && !face.IsNull() && edgeToFaces.Contains( edge ))
1561 if ( !edge.IsNull() && edgeToFaces.Contains( edge )) // PAL16202
1563 TopTools_ListIteratorOfListOfShape ancestorIt( edgeToFaces.FindFromKey( edge ));
1564 for ( ; ancestorIt.More(); ancestorIt.Next() )
1565 if ( ancestorIt.Value().ShapeType() == TopAbs_FACE &&
1566 !face.IsSame( ancestorIt.Value() ))
1567 return TopoDS::Face( ancestorIt.Value() );
1569 return TopoDS_Face();
1572 //================================================================================
1574 * \brief Return other vertex of an edge
1576 //================================================================================
1578 TopoDS_Vertex StdMeshers_ProjectionUtils::GetNextVertex(const TopoDS_Edge& edge,
1579 const TopoDS_Vertex& vertex)
1581 TopoDS_Vertex vF,vL;
1582 TopExp::Vertices(edge,vF,vL);
1583 if ( vF.IsSame( vL ))
1584 return TopoDS_Vertex();
1585 return vertex.IsSame( vF ) ? vL : vF;
1588 //================================================================================
1590 * \brief Return a propagation edge
1591 * \param aMesh - mesh
1592 * \param theEdge - edge to find by propagation
1593 * \param fromEdge - start edge for propagation
1594 * \retval pair<int,TopoDS_Edge> - propagation step and found edge
1596 //================================================================================
1598 pair<int,TopoDS_Edge>
1599 StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh* aMesh,
1600 const TopoDS_Edge& theEdge,
1601 const TopoDS_Edge& fromEdge)
1603 TopTools_IndexedMapOfShape aChain;
1606 // List of edges, added to chain on the previous cycle pass
1607 TopTools_ListOfShape listPrevEdges;
1608 listPrevEdges.Append(fromEdge);
1610 // Collect all edges pass by pass
1611 while (listPrevEdges.Extent() > 0) {
1613 // List of edges, added to chain on this cycle pass
1614 TopTools_ListOfShape listCurEdges;
1616 // Find the next portion of edges
1617 TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1618 for (; itE.More(); itE.Next()) {
1619 TopoDS_Shape anE = itE.Value();
1621 // Iterate on faces, having edge <anE>
1622 TopTools_ListIteratorOfListOfShape itA (aMesh->GetAncestors(anE));
1623 for (; itA.More(); itA.Next()) {
1624 TopoDS_Shape aW = itA.Value();
1626 // There are objects of different type among the ancestors of edge
1627 if (aW.ShapeType() == TopAbs_WIRE) {
1628 TopoDS_Shape anOppE;
1630 BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1631 Standard_Integer nb = 1, found = 0;
1632 TopTools_Array1OfShape anEdges (1,4);
1633 for (; aWE.More(); aWE.Next(), nb++) {
1638 anEdges(nb) = aWE.Current();
1639 if (anEdges(nb).IsSame(anE)) found = nb;
1642 if (nb == 5 && found > 0) {
1643 // Quadrangle face found, get an opposite edge
1644 Standard_Integer opp = found + 2;
1645 if (opp > 4) opp -= 4;
1646 anOppE = anEdges(opp);
1648 // add anOppE to aChain if ...
1649 if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain
1650 // Add found edge to the chain oriented so that to
1651 // have it co-directed with a forward MainEdge
1652 TopAbs_Orientation ori = anE.Orientation();
1653 if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1654 ori = TopAbs::Reverse( ori );
1655 anOppE.Orientation( ori );
1656 if ( anOppE.IsSame( theEdge ))
1657 return make_pair( step, TopoDS::Edge( anOppE ));
1659 listCurEdges.Append(anOppE);
1661 } // if (nb == 5 && found > 0)
1662 } // if (aF.ShapeType() == TopAbs_WIRE)
1663 } // for (; itF.More(); itF.Next())
1664 } // for (; itE.More(); itE.Next())
1666 listPrevEdges = listCurEdges;
1667 } // while (listPrevEdges.Extent() > 0)
1669 return make_pair( INT_MAX, TopoDS_Edge());
1672 //================================================================================
1674 * \brief Find corresponding nodes on two faces
1675 * \param face1 - the first face
1676 * \param mesh1 - mesh containing elements on the first face
1677 * \param face2 - the second face
1678 * \param mesh2 - mesh containing elements on the second face
1679 * \param assocMap - map associating sub-shapes of the faces
1680 * \param node1To2Map - map containing found matching nodes
1681 * \retval bool - is a success
1683 //================================================================================
1685 bool StdMeshers_ProjectionUtils::
1686 FindMatchingNodesOnFaces( const TopoDS_Face& face1,
1688 const TopoDS_Face& face2,
1690 const TShapeShapeMap & assocMap,
1691 TNodeNodeMap & node1To2Map)
1693 SMESHDS_Mesh* meshDS1 = mesh1->GetMeshDS();
1694 SMESHDS_Mesh* meshDS2 = mesh2->GetMeshDS();
1696 SMESH_MesherHelper helper1( *mesh1 );
1697 SMESH_MesherHelper helper2( *mesh2 );
1699 // Get corresponding submeshes and roughly check match of meshes
1701 SMESHDS_SubMesh * SM2 = meshDS2->MeshElements( face2 );
1702 SMESHDS_SubMesh * SM1 = meshDS1->MeshElements( face1 );
1704 RETURN_BAD_RESULT("Empty submeshes");
1705 if ( SM2->NbNodes() != SM1->NbNodes() ||
1706 SM2->NbElements() != SM1->NbElements() )
1707 RETURN_BAD_RESULT("Different meshes on corresponding faces "
1708 << meshDS1->ShapeToIndex( face1 ) << " and "
1709 << meshDS2->ShapeToIndex( face2 ));
1710 if ( SM2->NbElements() == 0 )
1711 RETURN_BAD_RESULT("Empty submeshes");
1713 helper1.SetSubShape( face1 );
1714 helper2.SetSubShape( face2 );
1715 if ( helper1.HasSeam() != helper2.HasSeam() )
1716 RETURN_BAD_RESULT("Different faces' geometry");
1718 // Data to call SMESH_MeshEditor::FindMatchingNodes():
1720 // 1. Nodes of corresponding links:
1722 // get 2 matching edges, try to find not seam ones
1723 TopoDS_Edge edge1, edge2, seam1, seam2, anyEdge1, anyEdge2;
1724 TopExp_Explorer eE( OuterShape( face2, TopAbs_WIRE ), TopAbs_EDGE );
1727 TopoDS_Edge e2 = TopoDS::Edge( eE.Current() );
1730 if ( !assocMap.IsBound( e2, /*is2nd=*/true ))
1731 RETURN_BAD_RESULT("Association not found for edge " << meshDS2->ShapeToIndex( e2 ));
1732 TopoDS_Edge e1 = TopoDS::Edge( assocMap( e2, /*is2nd=*/true ));
1733 if ( !helper1.IsSubShape( e1, face1 ))
1734 RETURN_BAD_RESULT("Wrong association, edge " << meshDS1->ShapeToIndex( e1 ) <<
1735 " isn't a sub-shape of face " << meshDS1->ShapeToIndex( face1 ));
1736 // check that there are nodes on edges
1737 SMESHDS_SubMesh * eSM1 = meshDS1->MeshElements( e1 );
1738 SMESHDS_SubMesh * eSM2 = meshDS2->MeshElements( e2 );
1739 bool nodesOnEdges = ( eSM1 && eSM2 && eSM1->NbNodes() && eSM2->NbNodes() );
1740 // check that the nodes on edges belong to faces
1741 // (as NETGEN ignores nodes on the degenerated geom edge)
1742 bool nodesOfFaces = false;
1743 if ( nodesOnEdges ) {
1744 const SMDS_MeshNode* n1 = eSM1->GetNodes()->next();
1745 const SMDS_MeshNode* n2 = eSM2->GetNodes()->next();
1746 nodesOfFaces = ( n1->GetInverseElementIterator(SMDSAbs_Face)->more() &&
1747 n2->GetInverseElementIterator(SMDSAbs_Face)->more() );
1751 if ( helper2.IsRealSeam( e2 )) {
1752 seam1 = e1; seam2 = e2;
1755 edge1 = e1; edge2 = e2;
1759 anyEdge1 = e1; anyEdge2 = e2;
1761 } while ( edge2.IsNull() && eE.More() );
1763 if ( edge2.IsNull() ) {
1764 edge1 = seam1; edge2 = seam2;
1766 bool hasNodesOnEdge = (! edge2.IsNull() );
1767 if ( !hasNodesOnEdge ) {
1768 // 0020338 - nb segments == 1
1769 edge1 = anyEdge1; edge2 = anyEdge2;
1772 // get 2 matching vertices
1773 TopoDS_Vertex V2 = TopExp::FirstVertex( TopoDS::Edge( edge2 ));
1774 if ( !assocMap.IsBound( V2, /*is2nd=*/true ))
1775 RETURN_BAD_RESULT("Association not found for vertex " << meshDS2->ShapeToIndex( V2 ));
1776 TopoDS_Vertex V1 = TopoDS::Vertex( assocMap( V2, /*is2nd=*/true ));
1778 // nodes on vertices
1779 const SMDS_MeshNode* vNode1 = SMESH_Algo::VertexNode( V1, meshDS1 );
1780 const SMDS_MeshNode* vNode2 = SMESH_Algo::VertexNode( V2, meshDS2 );
1781 if ( !vNode1 ) RETURN_BAD_RESULT("No node on vertex #" << meshDS1->ShapeToIndex( V1 ));
1782 if ( !vNode2 ) RETURN_BAD_RESULT("No node on vertex #" << meshDS2->ShapeToIndex( V2 ));
1784 // nodes on edges linked with nodes on vertices
1785 const SMDS_MeshNode* nullNode = 0;
1786 vector< const SMDS_MeshNode*> eNode1( 2, nullNode );
1787 vector< const SMDS_MeshNode*> eNode2( 2, nullNode );
1788 if ( hasNodesOnEdge )
1790 int nbNodeToGet = 1;
1791 if ( helper1.IsClosedEdge( edge1 ) || helper2.IsClosedEdge( edge2 ) )
1793 for ( int is2 = 0; is2 < 2; ++is2 )
1795 TopoDS_Edge & edge = is2 ? edge2 : edge1;
1796 SMESHDS_Mesh * smDS = is2 ? meshDS2 : meshDS1;
1797 SMESHDS_SubMesh* edgeSM = smDS->MeshElements( edge );
1798 // nodes linked with ones on vertices
1799 const SMDS_MeshNode* vNode = is2 ? vNode2 : vNode1;
1800 vector< const SMDS_MeshNode*>& eNode = is2 ? eNode2 : eNode1;
1802 SMDS_ElemIteratorPtr vElem = vNode->GetInverseElementIterator(SMDSAbs_Edge);
1803 while ( vElem->more() && nbGotNode != nbNodeToGet ) {
1804 const SMDS_MeshElement* elem = vElem->next();
1805 if ( edgeSM->Contains( elem ))
1806 eNode[ nbGotNode++ ] =
1807 ( elem->GetNode(0) == vNode ) ? elem->GetNode(1) : elem->GetNode(0);
1809 if ( nbGotNode > 1 ) // sort found nodes by param on edge
1811 SMESH_MesherHelper* helper = is2 ? &helper2 : &helper1;
1812 double u0 = helper->GetNodeU( edge, eNode[ 0 ]);
1813 double u1 = helper->GetNodeU( edge, eNode[ 1 ]);
1814 if ( u0 > u1 ) std::swap( eNode[ 0 ], eNode[ 1 ]);
1816 if ( nbGotNode == 0 )
1817 RETURN_BAD_RESULT("Found no nodes on edge " << smDS->ShapeToIndex( edge ) <<
1818 " linked to " << vNode );
1821 else // 0020338 - nb segments == 1
1823 // get 2 other matching vertices
1824 V2 = TopExp::LastVertex( TopoDS::Edge( edge2 ));
1825 if ( !assocMap.IsBound( V2, /*is2nd=*/true ))
1826 RETURN_BAD_RESULT("Association not found for vertex " << meshDS2->ShapeToIndex( V2 ));
1827 V1 = TopoDS::Vertex( assocMap( V2, /*is2nd=*/true ));
1829 // nodes on vertices
1830 eNode1[0] = SMESH_Algo::VertexNode( V1, meshDS1 );
1831 eNode2[0] = SMESH_Algo::VertexNode( V2, meshDS2 );
1832 if ( !eNode1[0] ) RETURN_BAD_RESULT("No node on vertex #" << meshDS1->ShapeToIndex( V1 ));
1833 if ( !eNode2[0] ) RETURN_BAD_RESULT("No node on vertex #" << meshDS2->ShapeToIndex( V2 ));
1838 set<const SMDS_MeshElement*> Elems1, Elems2;
1839 for ( int is2 = 0; is2 < 2; ++is2 )
1841 set<const SMDS_MeshElement*> & elems = is2 ? Elems2 : Elems1;
1842 SMESHDS_SubMesh* sm = is2 ? SM2 : SM1;
1843 SMESH_MesherHelper* helper = is2 ? &helper2 : &helper1;
1844 const TopoDS_Face & face = is2 ? face2 : face1;
1845 SMDS_ElemIteratorPtr eIt = sm->GetElements();
1847 if ( !helper->IsRealSeam( is2 ? edge2 : edge1 ))
1849 while ( eIt->more() ) elems.insert( eIt->next() );
1853 // the only suitable edge is seam, i.e. it is a sphere.
1854 // FindMatchingNodes() will not know which way to go from any edge.
1855 // So we ignore all faces having nodes on edges or vertices except
1856 // one of faces sharing current start nodes
1858 // find a face to keep
1859 const SMDS_MeshElement* faceToKeep = 0;
1860 const SMDS_MeshNode* vNode = is2 ? vNode2 : vNode1;
1861 const SMDS_MeshNode* eNode = is2 ? eNode2[0] : eNode1[0];
1862 TIDSortedElemSet inSet, notInSet;
1864 const SMDS_MeshElement* f1 =
1865 SMESH_MeshEditor::FindFaceInSet( vNode, eNode, inSet, notInSet );
1866 if ( !f1 ) RETURN_BAD_RESULT("The first face on seam not found");
1867 notInSet.insert( f1 );
1869 const SMDS_MeshElement* f2 =
1870 SMESH_MeshEditor::FindFaceInSet( vNode, eNode, inSet, notInSet );
1871 if ( !f2 ) RETURN_BAD_RESULT("The second face on seam not found");
1873 // select a face with less UV of vNode
1874 const SMDS_MeshNode* notSeamNode[2] = {0, 0};
1875 for ( int iF = 0; iF < 2; ++iF ) {
1876 const SMDS_MeshElement* f = ( iF ? f2 : f1 );
1877 for ( int i = 0; !notSeamNode[ iF ] && i < f->NbNodes(); ++i ) {
1878 const SMDS_MeshNode* node = f->GetNode( i );
1879 if ( !helper->IsSeamShape( node->getshapeId() ))
1880 notSeamNode[ iF ] = node;
1883 gp_Pnt2d uv1 = helper->GetNodeUV( face, vNode, notSeamNode[0] );
1884 gp_Pnt2d uv2 = helper->GetNodeUV( face, vNode, notSeamNode[1] );
1885 if ( uv1.X() + uv1.Y() > uv2.X() + uv2.Y() )
1891 elems.insert( faceToKeep );
1892 while ( eIt->more() ) {
1893 const SMDS_MeshElement* f = eIt->next();
1894 int nbNodes = f->NbNodes();
1895 if ( f->IsQuadratic() )
1898 for ( int i = 0; !onBnd && i < nbNodes; ++i ) {
1899 const SMDS_MeshNode* node = f->GetNode( i );
1900 onBnd = ( node->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE);
1905 // add also faces adjacent to faceToKeep
1906 int nbNodes = faceToKeep->NbNodes();
1907 if ( faceToKeep->IsQuadratic() ) nbNodes /= 2;
1908 notInSet.insert( f1 );
1909 notInSet.insert( f2 );
1910 for ( int i = 0; i < nbNodes; ++i ) {
1911 const SMDS_MeshNode* n1 = faceToKeep->GetNode( i );
1912 const SMDS_MeshNode* n2 = faceToKeep->GetNode(( i+1 ) % nbNodes );
1913 f1 = SMESH_MeshEditor::FindFaceInSet( n1, n2, inSet, notInSet );
1917 } // case on a sphere
1918 } // loop on 2 faces
1920 // int quadFactor = (*Elems1.begin())->IsQuadratic() ? 2 : 1;
1922 node1To2Map.clear();
1923 int res = SMESH_MeshEditor::FindMatchingNodes( Elems1, Elems2,
1925 eNode1[0], eNode2[0],
1927 if ( res != SMESH_MeshEditor::SEW_OK )
1928 RETURN_BAD_RESULT("FindMatchingNodes() result " << res );
1930 // On a sphere, add matching nodes on the edge
1932 if ( helper1.IsRealSeam( edge1 ))
1934 // sort nodes on edges by param on edge
1935 map< double, const SMDS_MeshNode* > u2nodesMaps[2];
1936 for ( int is2 = 0; is2 < 2; ++is2 )
1938 TopoDS_Edge & edge = is2 ? edge2 : edge1;
1939 SMESHDS_Mesh * smDS = is2 ? meshDS2 : meshDS1;
1940 SMESHDS_SubMesh* edgeSM = smDS->MeshElements( edge );
1941 map< double, const SMDS_MeshNode* > & pos2nodes = u2nodesMaps[ is2 ];
1943 SMDS_NodeIteratorPtr nIt = edgeSM->GetNodes();
1944 while ( nIt->more() ) {
1945 const SMDS_MeshNode* node = nIt->next();
1946 const SMDS_EdgePosition* pos =
1947 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
1948 pos2nodes.insert( make_pair( pos->GetUParameter(), node ));
1950 if ( pos2nodes.size() != edgeSM->NbNodes() )
1951 RETURN_BAD_RESULT("Equal params of nodes on edge "
1952 << smDS->ShapeToIndex( edge ) << " of face " << is2 );
1954 if ( u2nodesMaps[0].size() != u2nodesMaps[1].size() )
1955 RETURN_BAD_RESULT("Different nb of new nodes on edges or wrong params");
1957 // compare edge orientation
1958 double u1 = helper1.GetNodeU( edge1, vNode1 );
1959 double u2 = helper2.GetNodeU( edge2, vNode2 );
1960 bool isFirst1 = ( u1 < u2nodesMaps[0].begin()->first );
1961 bool isFirst2 = ( u2 < u2nodesMaps[1].begin()->first );
1962 bool reverse ( isFirst1 != isFirst2 );
1964 // associate matching nodes
1965 map< double, const SMDS_MeshNode* >::iterator u_Node1, u_Node2, end1;
1966 map< double, const SMDS_MeshNode* >::reverse_iterator uR_Node2;
1967 u_Node1 = u2nodesMaps[0].begin();
1968 u_Node2 = u2nodesMaps[1].begin();
1969 uR_Node2 = u2nodesMaps[1].rbegin();
1970 end1 = u2nodesMaps[0].end();
1971 for ( ; u_Node1 != end1; ++u_Node1 ) {
1972 const SMDS_MeshNode* n1 = u_Node1->second;
1973 const SMDS_MeshNode* n2 = ( reverse ? (uR_Node2++)->second : (u_Node2++)->second );
1974 node1To2Map.insert( make_pair( n1, n2 ));
1977 // associate matching nodes on the last vertices
1978 V2 = TopExp::LastVertex( TopoDS::Edge( edge2 ));
1979 if ( !assocMap.IsBound( V2, /*is2nd=*/true ))
1980 RETURN_BAD_RESULT("Association not found for vertex " << meshDS2->ShapeToIndex( V2 ));
1981 V1 = TopoDS::Vertex( assocMap( V2, /*is2nd=*/true ));
1982 vNode1 = SMESH_Algo::VertexNode( V1, meshDS1 );
1983 vNode2 = SMESH_Algo::VertexNode( V2, meshDS2 );
1984 if ( !vNode1 ) RETURN_BAD_RESULT("No node on vertex #" << meshDS1->ShapeToIndex( V1 ));
1985 if ( !vNode2 ) RETURN_BAD_RESULT("No node on vertex #" << meshDS2->ShapeToIndex( V2 ));
1986 node1To2Map.insert( make_pair( vNode1, vNode2 ));
1989 // don't know why this condition is usually true :(
1990 // if ( node1To2Map.size() * quadFactor < SM1->NbNodes() )
1991 // MESSAGE("FindMatchingNodes() found too few node pairs starting from nodes ("
1992 // << vNode1->GetID() << " - " << eNode1[0]->GetID() << ") ("
1993 // << vNode2->GetID() << " - " << eNode2[0]->GetID() << "):"
1994 // << node1To2Map.size() * quadFactor << " < " << SM1->NbNodes());
1999 //================================================================================
2001 * \brief Return any sub-shape of a face belonging to the outer wire
2002 * \param face - the face
2003 * \param type - type of sub-shape to return
2004 * \retval TopoDS_Shape - the found sub-shape
2006 //================================================================================
2008 TopoDS_Shape StdMeshers_ProjectionUtils::OuterShape( const TopoDS_Face& face,
2009 TopAbs_ShapeEnum type)
2011 TopExp_Explorer exp( BRepTools::OuterWire( face ), type );
2013 return exp.Current();
2014 return TopoDS_Shape();
2017 //================================================================================
2019 * \brief Check that submesh is computed and try to compute it if is not
2020 * \param sm - submesh to compute
2021 * \param iterationNb - int used to stop infinite recursive call
2022 * \retval bool - true if computed
2024 //================================================================================
2026 bool StdMeshers_ProjectionUtils::MakeComputed(SMESH_subMesh * sm, const int iterationNb)
2028 if ( iterationNb > 10 )
2029 RETURN_BAD_RESULT("Infinite recursive projection");
2031 RETURN_BAD_RESULT("NULL submesh");
2032 if ( sm->IsMeshComputed() )
2035 SMESH_Mesh* mesh = sm->GetFather();
2036 SMESH_Gen* gen = mesh->GetGen();
2037 SMESH_Algo* algo = sm->GetAlgo();
2040 if ( sm->GetSubShape().ShapeType() != TopAbs_COMPOUND )
2041 RETURN_BAD_RESULT("No algo assigned to submesh " << sm->GetId());
2043 bool computed = true;
2044 for ( TopoDS_Iterator grMember( sm->GetSubShape() ); grMember.More(); grMember.Next())
2045 if ( SMESH_subMesh* grSub = mesh->GetSubMesh( grMember.Value() ))
2046 if ( !MakeComputed( grSub, iterationNb + 1 ))
2051 string algoType = algo->GetName();
2052 if ( algoType.substr(0, 11) != "Projection_")
2053 return gen->Compute( *mesh, sm->GetSubShape() );
2055 // try to compute source mesh
2057 const list <const SMESHDS_Hypothesis *> & hyps =
2058 algo->GetUsedHypothesis( *mesh, sm->GetSubShape() );
2060 TopoDS_Shape srcShape;
2061 SMESH_Mesh* srcMesh = 0;
2062 list <const SMESHDS_Hypothesis*>::const_iterator hIt = hyps.begin();
2063 for ( ; srcShape.IsNull() && hIt != hyps.end(); ++hIt ) {
2064 string hypName = (*hIt)->GetName();
2065 if ( hypName == "ProjectionSource1D" ) {
2066 const StdMeshers_ProjectionSource1D * hyp =
2067 static_cast<const StdMeshers_ProjectionSource1D*>( *hIt );
2068 srcShape = hyp->GetSourceEdge();
2069 srcMesh = hyp->GetSourceMesh();
2071 else if ( hypName == "ProjectionSource2D" ) {
2072 const StdMeshers_ProjectionSource2D * hyp =
2073 static_cast<const StdMeshers_ProjectionSource2D*>( *hIt );
2074 srcShape = hyp->GetSourceFace();
2075 srcMesh = hyp->GetSourceMesh();
2077 else if ( hypName == "ProjectionSource3D" ) {
2078 const StdMeshers_ProjectionSource3D * hyp =
2079 static_cast<const StdMeshers_ProjectionSource3D*>( *hIt );
2080 srcShape = hyp->GetSource3DShape();
2081 srcMesh = hyp->GetSourceMesh();
2084 if ( srcShape.IsNull() ) // no projection source defined
2085 return gen->Compute( *mesh, sm->GetSubShape() );
2087 if ( srcShape.IsSame( sm->GetSubShape() ))
2088 RETURN_BAD_RESULT("Projection from self");
2093 if ( MakeComputed( srcMesh->GetSubMesh( srcShape ), iterationNb + 1 ) &&
2094 gen->Compute( *mesh, sm->GetSubShape() ))
2095 return sm->IsMeshComputed();
2100 //================================================================================
2102 * \brief Count nb of sub-shapes
2103 * \param shape - the shape
2104 * \param type - the type of sub-shapes to count
2105 * \retval int - the calculated number
2107 //================================================================================
2109 int StdMeshers_ProjectionUtils::Count(const TopoDS_Shape& shape,
2110 const TopAbs_ShapeEnum type,
2111 const bool ignoreSame)
2114 TopTools_IndexedMapOfShape map;
2115 TopExp::MapShapes( shape, type, map );
2116 return map.Extent();
2120 for ( TopExp_Explorer exp( shape, type ); exp.More(); exp.Next() )
2126 //================================================================================
2128 * \brief Return a boundary EDGE of edgeContainer
2130 //================================================================================
2132 TopoDS_Edge StdMeshers_ProjectionUtils::GetBoundaryEdge(const TopoDS_Shape& edgeContainer,
2133 const SMESH_Mesh& mesh,
2134 std::list< TopoDS_Edge >* allBndEdges)
2136 TopTools_IndexedMapOfShape facesOfEdgeContainer, facesNearEdge;
2137 TopExp::MapShapes( edgeContainer, TopAbs_FACE, facesOfEdgeContainer );
2139 if ( !facesOfEdgeContainer.IsEmpty() )
2140 for ( TopExp_Explorer exp(edgeContainer, TopAbs_EDGE); exp.More(); exp.Next() )
2142 const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
2143 facesNearEdge.Clear();
2144 PShapeIteratorPtr faceIt = SMESH_MesherHelper::GetAncestors( edge, mesh, TopAbs_FACE );
2145 while ( const TopoDS_Shape* face = faceIt->next() )
2146 if ( facesOfEdgeContainer.Contains( *face ))
2147 if ( facesNearEdge.Add( *face ) && facesNearEdge.Extent() > 1 )
2149 if ( facesNearEdge.Extent() == 1 ) {
2151 allBndEdges->push_back( edge );
2157 return TopoDS_Edge();
2161 namespace { // Definition of event listeners
2163 SMESH_subMeshEventListener* GetSrcSubMeshListener();
2165 //================================================================================
2167 * \brief Listener that resets an event listener on source submesh when
2168 * "ProjectionSource*D" hypothesis is modified
2170 //================================================================================
2172 struct HypModifWaiter: SMESH_subMeshEventListener
2174 HypModifWaiter():SMESH_subMeshEventListener(false,// won't be deleted by submesh
2175 "StdMeshers_ProjectionUtils::HypModifWaiter") {}
2176 void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
2177 EventListenerData*, const SMESH_Hypothesis*)
2179 if ( event == SMESH_subMesh::MODIF_HYP &&
2180 eventType == SMESH_subMesh::ALGO_EVENT)
2182 // delete current source listener
2183 subMesh->DeleteEventListener( GetSrcSubMeshListener() );
2184 // let algo set a new one
2185 if ( SMESH_Algo* algo = subMesh->GetAlgo() )
2186 algo->SetEventListener( subMesh );
2190 //================================================================================
2192 * \brief return static HypModifWaiter
2194 //================================================================================
2196 SMESH_subMeshEventListener* GetHypModifWaiter() {
2197 static HypModifWaiter aHypModifWaiter;
2198 return &aHypModifWaiter;
2200 //================================================================================
2202 * \brief return static listener for source shape submeshes
2204 //================================================================================
2206 SMESH_subMeshEventListener* GetSrcSubMeshListener() {
2207 static SMESH_subMeshEventListener srcListener(false, // won't be deleted by submesh
2208 "StdMeshers_ProjectionUtils::SrcSubMeshListener");
2209 return &srcListener;
2213 //================================================================================
2215 * \brief Set event listeners to submesh with projection algo
2216 * \param subMesh - submesh with projection algo
2217 * \param srcShape - source shape
2218 * \param srcMesh - source mesh
2220 //================================================================================
2222 void StdMeshers_ProjectionUtils::SetEventListener(SMESH_subMesh* subMesh,
2223 TopoDS_Shape srcShape,
2224 SMESH_Mesh* srcMesh)
2226 // Set listener that resets an event listener on source submesh when
2227 // "ProjectionSource*D" hypothesis is modified since source shape can be changed
2228 subMesh->SetEventListener( GetHypModifWaiter(),0,subMesh);
2230 // Set an event listener to submesh of the source shape
2231 if ( !srcShape.IsNull() )
2234 srcMesh = subMesh->GetFather();
2236 SMESH_subMesh* srcShapeSM = srcMesh->GetSubMesh( srcShape );
2238 if ( srcShapeSM != subMesh ) {
2239 if ( srcShapeSM->GetSubMeshDS() &&
2240 srcShapeSM->GetSubMeshDS()->IsComplexSubmesh() )
2241 { // source shape is a group
2242 TopExp_Explorer it(srcShapeSM->GetSubShape(), // explore the group into sub-shapes...
2243 subMesh->GetSubShape().ShapeType()); // ...of target shape type
2244 for (; it.More(); it.Next())
2246 SMESH_subMesh* srcSM = srcMesh->GetSubMesh( it.Current() );
2247 if ( srcSM != subMesh )
2249 SMESH_subMeshEventListenerData* data =
2250 srcSM->GetEventListenerData(GetSrcSubMeshListener());
2252 data->mySubMeshes.push_back( subMesh );
2254 data = SMESH_subMeshEventListenerData::MakeData( subMesh );
2255 subMesh->SetEventListener ( GetSrcSubMeshListener(), data, srcSM );
2261 subMesh->SetEventListener( GetSrcSubMeshListener(),
2262 SMESH_subMeshEventListenerData::MakeData( subMesh ),