microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 308 forks source link

ObjectUnderMouseCursor is IViewerNode (not null) when there are no nodes left #305

Closed MVoloshin closed 2 years ago

MVoloshin commented 2 years ago

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).

MVoloshin commented 2 years ago

@levnach please, take a look at this issue when you have time

levnach commented 2 years ago

Will try tomorrow.

levnach commented 2 years ago

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.

MVoloshin commented 2 years ago

Thank you very much!