Hi,
Yes, there is an easier way – just subscribe to the NodeTransformChanging event of the document’s event sink service. In the event handler you can use the following code:
private void EventSinkService_NodeTransformChanging(NNodeTransformCancelEventArgs args)
{
NShape shape = args.Node as NShape;
if(shape == null)
return;
// Get the rect bounds in device coordinates
NMatrix2DF newTransform = args.NewTransform;
newTransform.Multiply(shape.ParentSceneTransform);
NRectangleF rect = newTransform.TransformBounds(shape.ModelBounds);
rect = view.SceneToDevice.TransformRect(rect);
// Get the nodes under the rect
NNodeList nodes = view.HitTestDocument(rect, NFilters.Shape2D);
if (nodes.Count != 1)
return;
// Get the hit shape
NShape hitShape = (NShape)nodes[0];
// The moved shape is the hit shape, so do nothing
if (hitShape == shape)
return;
// Create a line connecting the 2 shapes
NDrawingDocument doc = (NDrawingDocument)shape.Document;
NLineShape line = new NLineShape();
doc.ActiveLayer.AddChild(line);
line.FromShape = shape;
line.ToShape = hitShape;
// Cancel the movement of the shape
args.Cancel = true;
}
Best Regards,
Nevron Support Team