ObjectUnderMouseCursor is IViewerNode (not null) when there are no nodes left
MVoloshin opened this issue · 4 comments
Hello! Please, look att EdgeDirectionTest sample and replace MouseDown listener code as follows.
private void viewer_MouseDown(object sender, MsaglMouseEventArgs e)
{
if(e.RightButtonIsPressed)
{
IViewerObject ob = gv.ObjectUnderMouseCursor;
if (ob == null) {
Microsoft.Msagl.Core.Geometry.Point p = gv.ScreenToSource(e.X, e.Y);
Node n = new Node((gv.Graph.NodeCount + 1).ToString());
IViewerNode iwn = gv.CreateIViewerNode(n, p, true);
gv.AddNode(iwn, true);
}
else if(ob is IViewerNode) {
IViewerNode existingNode = ob as IViewerNode;
gv.RemoveNode(existingNode, true);
}
}
}
Then remove existing nodes from GViewer one by one using right mouse button (by clicking it on nodes). When there are no nodes left try to create a new node pressing the same right mouse button in free space. In such conditions a new node won't appear as ObjectUnderMouseCursor is IViewerNode for some reason (and it does not matter where you make a click).
Will try tomorrow.
I think I fixed it. I noticed that Form1.cs sometimes created new nodes with the existing ID. That was causing additional confusing behavior. I introduced method Form1.FindNewId() to avoid it.
Thank you very much!