Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Stop avoiding overlapping Nodes on Canvas (Read 11047 times)
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Stop avoiding overlapping Nodes on Canvas
Reply #15 - Apr 7th, 2017 at 4:07am
Print Post  
oky this is working now when drag node already on canvas, but how to revoke the action in following scenarios

Scenario 1

I have NodeList on right panel, select an item from it and drag and drop on canvas, how to avoid if dropping node overlap with existing item



I tried following but it contains compile time errors


Code
Select All
        private void OnNodeCreated(object sender, NodeEventArgs e)
        {

            if (IsMovingNodeOverlap(e.Node, 2))
            {
                e.Cancel = true;
            }
            else
            {
                e.Cancel = false;
            }
        }
        public bool IsMovingNodeOverlap(DiagramNode modifiedNode, double minDist)
        {
            bool isCurrentNodeOverlap = false;

            var queue = new Queue<DiagramNode>();
            queue.Enqueue(modifiedNode);

            while (queue.Count > 0)
            {
                var node = queue.Dequeue();
                var nodeCenter = node.GetCenter();
                var overlaps = FindOverlaps(node, minDist);

                if (overlaps.Count > 0)
                {
                    isCurrentNodeOverlap = true;
                }
                else
                {
                    isCurrentNodeOverlap = false;
                }

            }

            return isCurrentNodeOverlap;
        } 



Scenario 2

Existing Node can rotate to overlap with another existing node

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3378
Joined: Oct 19th, 2005
Re: Stop avoiding overlapping Nodes on Canvas
Reply #16 - Apr 8th, 2017 at 12:13pm
Print Post  
You can set e.Cancel only from validation events, ones with names ending in "ing" like NodeCreating. However NodeCreating is raised only when you draw on the diagram canvas, and not when you drag and drop from the list view control. In latter case you can stop the operation from PreviewDragOver event handler like this -
Code
Select All
// in diagram xaml
PreviewDragOver="OnPreviewDragOver"

// in class file
void OnPreviewDragOver(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(typeof(DraggedNode)))
	{
		var data = (DraggedNode)e.Data.GetData(typeof(DraggedNode));
		var position = e.GetPosition(diagram.DocumentPlane);
		var node = (DiagramNode)data.Node.Clone(false);
		node.Bounds = new Rect(position, node.Bounds.Size);
		e.Effects = DragDropEffects.Copy;
		if (FindOverlaps(node, 0).Count > 0)
		{
			e.Effects = DragDropEffects.None;
			e.Handled = true;
		}
	}
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint