+//=======================================================================
+//function : findExistingNodes
+//purpose : fills nodes vector with nodes existing on a given shape (IMP 22368)
+// Returns true if all nodes for all points on S are found
+//=======================================================================
+
+bool SMESH_Pattern::findExistingNodes( SMESH_Mesh* mesh,
+ const TopoDS_Shape& S,
+ const std::list< TPoint* > & points,
+ vector< const SMDS_MeshNode* > & nodesVector)
+{
+ if ( S.IsNull() || points.empty() )
+ return false;
+
+ SMESHDS_Mesh* aMeshDS = mesh->GetMeshDS();
+
+ switch ( S.ShapeType() )
+ {
+ case TopAbs_VERTEX:
+ {
+ int pIndex = points.back() - &myPoints[0];
+ if ( !nodesVector[ pIndex ] )
+ nodesVector[ pIndex ] = SMESH_Algo::VertexNode( TopoDS::Vertex( S ), aMeshDS );
+ return nodesVector[ pIndex ];
+ }
+ case TopAbs_EDGE:
+ {
+ const TopoDS_Edge& edge = TopoDS::Edge( S );
+ map< double, const SMDS_MeshNode* > paramsOfNodes;
+ if ( !SMESH_Algo::GetSortedNodesOnEdge( aMeshDS, edge,
+ /*ignoreMediumNodes=*/false,
+ paramsOfNodes )
+ || paramsOfNodes.size() < 3 )
+ break;
+ // points on VERTEXes are included with wrong myU
+ list< TPoint* >::const_reverse_iterator pItR = ++points.rbegin();
+ list< TPoint* >::const_iterator pItF = ++points.begin();
+ const bool isForward = ( (*pItF)->myU < (*pItR)->myU );
+ map< double, const SMDS_MeshNode* >::iterator u2n = ++paramsOfNodes.begin();
+ map< double, const SMDS_MeshNode* >::iterator u2nEnd = --paramsOfNodes.end();
+ TPoint* p;
+ if ( paramsOfNodes.size() == points.size() )
+ {
+ for ( ; u2n != u2nEnd; ++u2n )
+ {
+ p = ( isForward ? *pItF : *pItR );
+ int pIndex = p - &myPoints[0];
+ if ( !nodesVector [ pIndex ] )
+ nodesVector [ pIndex ] = u2n->second;
+ ++pItF;
+ ++pItR;
+ }
+ return true;
+ }
+ else
+ {
+ const double tolFact = 0.05;
+ while ( u2n != u2nEnd && pItF != points.end() )
+ {
+ const double u = u2n->first;
+ const SMDS_MeshNode* n = u2n->second;
+ const double tol = ( (++u2n)->first - u ) * tolFact;
+ do
+ {
+ p = ( isForward ? *pItF : *pItR );
+ if ( Abs( u - p->myU ) < tol )
+ {
+ int pIndex = p - &myPoints[0];
+ if ( !nodesVector [ pIndex ] )
+ nodesVector [ pIndex ] = n;
+ ++pItF;
+ ++pItR;
+ break;
+ }
+ }
+ while ( p->myU < u && ( ++pItF, ++pItR != points.rend() ));
+ }
+ }
+ break;
+ } // case TopAbs_EDGE:
+
+ default:;
+ } // switch ( S.ShapeType() )
+
+ return false;
+}
+