Move node to current mouse postion

Hi,

I am trying to draw a line using the mouse, in order to do so I am using a go:Node with a canvas as its contents and then using the LastMousePointInModel method to determine where in the model the mouse currently is and setting the start / end points of a line within the canvas.

This works fine most of the time when the node is within the current view port of the diagram.

It also works if the diagram has been zoomed and the node is outside the view port.

The process falls down when the diagram has been zoomed and panned and the node is outside the current view port.

To try and resolve this I have tried,

Point currentPos = diagram.LastMousePointInModel;

Node.Move(currentPos, False);

This sets the Node.Location but does not set the position, leaving it outside the view port and the line I am trying to draw does not appear.

I have also tried setting the Node.Position directly, but again this does not move the position (but does set the location).

If the node is in the current view or the diagram has only been zoomed, both of the above methods work.

Is there a way to move a node into the viewport (without changing the viewport). Or is there a better way to draw a line on the diagram using model coordinates. The line is used to define a scale on the diagram so must be in model coordinates.

Thanks,
Kevin Shaw

Would the sample discussed in freehand drawing tools help?

Thanks for the reply, but that example is too complex for what I need. I only need a single line for scaling purposes. In the code I am using, I simply redraw the end point of a single line based on the current mouse position until the mouse is clicked again.

The problem that I am seeing is that if a node is outside of the viewport it is not displayed and therefore any content that the node may contain which is still within the viewport is not displayed.

I was looking either for a method to move the existing node (which is always in the diagram, just hidden when not being used) into the viewport or to force the node to display even when it is outside the viewport I think would also work.

If the only way in which you can envisage this working is to add additional nodes at run time as appears to be the case in the example, then I will investigate this route.

Note: The application I am writing is WPF rather than silverlight if that has an impact.

I think what is in the sample is pretty similar to what you are doing.

I suspect your problem is that you aren’t normalizing the start point and the end point such that the minimum coordinate values, for both X and Y, are zero. And that your Node.Location should then be the desired point in model coordinates.

The sample code does exactly this normalization and re-positioning of the Node.