+ typedef SMESH_Algo::Features AlgoData;
+
+ TopoDS_Shape assignedToShape;
+ SMESH_Algo* algo =
+ (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape );
+
+ if ( algo &&
+ aShape.ShapeType() == TopAbs_FACE &&
+ !aShape.IsSame( assignedToShape ) &&
+ SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
+ {
+ // Issue 0021559. If there is another 2D algo with different types of output
+ // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
+ // have different types of input elements, we choose a most appropriate 2D algo.
+
+ // try to find a concurrent 2D algo
+ filter.AndNot( filter.Is( algo ));
+ TopoDS_Shape assignedToShape2;
+ SMESH_Algo* algo2 =
+ (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape2 );
+ if ( algo2 && // algo found
+ !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) && // algo is local
+ ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
+ SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
+ aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ), // no forced order
+ aMesh.GetSubMesh( assignedToShape )))
+ {
+ // get algos on the adjacent SOLIDs
+ filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
+ vector< SMESH_Algo* > algos3D;
+ PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
+ TopAbs_SOLID );
+ while ( const TopoDS_Shape* solid = solidIt->next() )
+ if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
+ {
+ algos3D.push_back( algo3D );
+ filter.AndNot( filter.HasName( algo3D->GetName() ));
+ }
+ // check compatibility of algos
+ if ( algos3D.size() > 1 )
+ {
+ const AlgoData& algoData = algo->SMESH_Algo::GetFeatures();
+ const AlgoData& algoData2 = algo2->SMESH_Algo::GetFeatures();
+ const AlgoData& algoData3d0 = algos3D[0]->SMESH_Algo::GetFeatures();
+ const AlgoData& algoData3d1 = algos3D[1]->SMESH_Algo::GetFeatures();
+ if (( algoData2.IsCompatible( algoData3d0 ) &&
+ algoData2.IsCompatible( algoData3d1 ))
+ &&
+ !(algoData.IsCompatible( algoData3d0 ) &&
+ algoData.IsCompatible( algoData3d1 )))
+ algo = algo2;
+ }
+ }
+ }
+
+ if ( assignedTo && algo )
+ * assignedTo = assignedToShape;
+
+ return algo;