I am wonderring if there is a property I can use to avoid nodes superimposing others?
Is it possible to avoid this situation?
Thancks in advance
I am wonderring if there is a property I can use to avoid nodes superimposing others?
Is it possible to avoid this situation?
Thancks in advance
Is “Epsilon” a Group? Did you specify a Group.Layout to arrange the nodes within the group? I assume you haven’t specified the node locations yourself via code or data-binding or manual positioning.
Epsilon is a group. And I didn’t specify a Group.Layout but my issu is the same for two Nodes. I am wondering if I can avoid Node overlaping?
For exemple, using a manual positioning, can I tell nodes not overlapping? I would like my diagram avoid nodes to overlap even if the user want to do it…
Oh – do you mean that you setup your screenshot by manually or programmatically placing the nodes to be overlapping each other? If so, that would explain it, because that isn’t the normal result of any of our layouts.
So your issue is not one of the behavior of any automatic layout. Instead it sounds like you want to restrict or fix-up any dragging behavior. This means customizing the DraggingTool.
What do you want to happen when the user drags a node to be partly or completely overlapping a stationary node, before a drop occurs? And if it is permitted, what do you want to happen when the drop occurs?
Yes, I put nodes like that manually.
I don’t want to allow the user to drop a nodes over an other one. But if the user drop a node over a group, I want the node to be part of this group.
Is there somewhere I can see how the DraggingTool works? :$
Thancks again for your help
Well, presumably you already know about setting Diagram.DraggingTool.DropOntoEnabled=true and about setting go:Part.DropOntoBehavior=“AddsToGroup” on your Group DataTemplate. This is demonstrated in some of the samples, such as Planogram.
Avoiding node overlaps is more complicated. You didn’t say what you want to have happen, so I guess you can decide in your customization of the DraggingTool.
One possibility is to cancel the drag-and-drop if the drop causes any node overlaps. You could implement that by overriding DraggingTool.DropOnto. (The DropOntoBehavior is changing the built-in behavior of that method already.) If you assume nodes are basically rectangular, you just need to see if any of the selected nodes have bounds that intersect with any stationary (non-selected) non-Group nodes. If there is, call DoCancel() to cancel the drag-and-drop.
The FlowGrammer sample demonstrates this, but with a different purpose – cancelling the drag-and-drop when the drop happens at a point in the background of the diagram, i.e. not onto a stationary object. Note though that such a determination in that sample is based on the mouse point, not on the bounds of all of the selected nodes that were dropped.
Alternatively you could adjust the positions of the dropped nodes that overlap stationary nodes. Again, you’ll need to figure out what policies you’ll want to implement.
You’ll also need to consider what should happen when the user drags one or more Groups. If you are following me so far, I think you can appreciate that there are a lot of different cases that can occur. You have to figure out what to do for each one.
Oh, I forgot to mention that when you want to find intersecting nodes, you should call the myDiagram.Panel.FindPartsIn method. The Local Expand sample demonstrates this, although for a different purpose. This will typically be faster than just iterating over the Diagram.Nodes collection, since you’ll only get nodes that intersect with the selection area, and you just need to check for nodes that they really do intersect with the selected nodes.
The Rect that you want to use can be the result of calling myDiagram.Panel.ComputeBounds(myDiagram.SelectedParts.OfType()). Remember to check that the Rect is not IsEmpty.
Thx, I am currently customing the dragging tool but I still have issues :)
I started to override the DropOnto and DragOver functions.
My DropOnto function issu is that I don’t know how I can forbid users to drop only on nodes and not on groups, I want to cancel only if it’s a node.
Moreover, because I overide the function, my nodes are no more add to the group…
I also have a question about DragOver. Is it possible to forbid the users to dragover nodes? I am trying to cancel if the drop is on an other node, but is it possible to “limit” the users drag? :$
The CustomDraggingTool in the Planogram sample demonstrates the selectivity that I think you are looking for.
It’s not possible to prevent the user from moving the mouse anywhere on the screen nor to prevent them from releasing the mouse button at any time during a drag. However it should be possible to customize where the selection may be dragged. And you already know it’s possible to cancel the drag-and-drop if a drop happens at a disallowed location – by calling DoCancel().
To customize where the selection is dragged, you can override the DraggingTool.ConsiderSnapTo and SnapTo methods. The standard implementation of SnapTo is what implements grid-snapping. The Planogram sample demonstrates overriding the ConsiderSnapTo method but not the SnapTo method.
If you find the ConsiderSnapTo and SnapTo methods too complicated, you can just override ComputeMove, which normally calls those methods and also respects the Node.MinLocation and MaxLocation properties.