+//================================================================================
+/*!
+ * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
+ * move the node closest to the point to point's location and return ID of the node
+ */
+//================================================================================
+
+CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
+ CORBA::Double y,
+ CORBA::Double z,
+ CORBA::Long theNodeID)
+{
+ // We keep myNodeSearcher until any mesh modification:
+ // 1) initData() deletes myNodeSearcher at any edition,
+ // 2) TNodeSearcherDeleter - at any mesh compute event
+
+ initData();
+
+ int nodeID = theNodeID;
+ const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
+ if ( !node )
+ {
+ if ( !myNodeSearcher ) {
+ ::SMESH_MeshEditor anEditor( myMesh );
+ myNodeSearcher = anEditor.GetNodeSearcher();
+ static TNodeSearcherDeleter deleter;
+ deleter.Set( myMesh );
+ }
+ gp_Pnt p( x,y,z );
+ node = myNodeSearcher->FindClosestTo( p );
+ }
+ if ( node ) {
+ nodeID = node->GetID();
+ if ( myPreviewMode ) // make preview data
+ {
+ // in a preview mesh, make edges linked to a node
+ TPreviewMesh tmpMesh;
+ TIDSortedElemSet linkedNodes;
+ ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
+ TIDSortedElemSet::iterator nIt = linkedNodes.begin();
+ for ( ; nIt != linkedNodes.end(); ++nIt )
+ {
+ SMDS_MeshEdge edge( node, cast2Node( *nIt ));
+ tmpMesh.Copy( &edge );
+ }
+ // move copied node
+ node = tmpMesh.GetMeshDS()->FindNode( nodeID );
+ if ( node )
+ tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
+ // fill preview data
+ ::SMESH_MeshEditor anEditor( & tmpMesh );
+ StoreResult( anEditor );
+ }
+ else
+ {
+ GetMeshDS()->MoveNode(node, x, y, z);
+ }
+ }
+
+ if ( !myPreviewMode ) {
+ // Update Python script
+ TPythonDump() << "nodeID = " << this
+ << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
+ }
+
+ return nodeID;
+}
+