Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Dragging of Node from one group to another (Read 9321 times)
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Dragging of Node from one group to another
Apr 23rd, 2009 at 12:19pm
Print Post  
Hi Stoyan,

I have created two groups of nodes.Now I want to Drag  one node from first group and want to drop it in second group.How can I do this ?

Thanks,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #1 - Apr 23rd, 2009 at 1:00pm
Print Post  
Handle NodeModified. Check if e.Node.MasterGroup.MainNode.Bounds.Contains(e.Node.Bounds). If it doesn't, call e.Node.Detach. Call GetNodesAt(e.MousePosition), look for a group node in the returned list, and attach e.Node to it if one is found.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #2 - Apr 23rd, 2009 at 2:37pm
Print Post  
I am not getting your answer. Sad
e.Node.MasterGroup.MainNode.Bounds.Contains does not exits.

Could you please send some detail information?
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #3 - Apr 24th, 2009 at 7:36am
Print Post  
Hi Stoyan,

I also want to know about this.Let me clear first,what is the scenerio.

I have created a group of Nodes which is also a ShapeNode type Node and it has some childNode(ShapeNode) attached.
I have 2 groupNode of this kind.
Now I want to drag a child node from group1 and drop it into group2.

In NodeModified,I have not found e.Node.MasterGroup.MainNode.Bounds.Contains.

Any pointer in this regard?

Thanks,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #4 - Apr 24th, 2009 at 8:38am
Print Post  
Try with e.Node.MasterGroup.MainItem.
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #5 - Apr 24th, 2009 at 11:36am
Print Post  
Can you please send a code example so that I can correct my mistake.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #6 - Apr 26th, 2009 at 10:21am
Print Post  
if (!e.Node.MasterGroup.MainItem.Bounds.Contains(e.Node.Bounds))
{
     e.Node.Detach();
     // call GetNodesAt and check if there's another group node under the mouse position
}

I hope that  helps,
Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #7 - Apr 27th, 2009 at 10:01am
Print Post  
Hi,

In my sample project I have

1. Some shape Nodes
2. Some Groups of ShapeNodes (This group node is also a ShapeNode that has some child shape node attached with it).
3. Have more than 3 groups of this kind.

Requirement:-

1. Want to detach a node from one group and drop that into another group.
2. If a node is not belongs to any group then also I want the same drag and drop functionality.

Problem:-

1. "e.Node.MasterGroup.MainItem.Bounds" main item doesn’t have Bounds property.
2. How can I identify the destination of the node, whether it is that group node or not.
3. I want to drop a node into a group only. If a user tries to drop node in diagram or any place other then group it should roll back.

Thanks in advance,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #8 - Apr 27th, 2009 at 1:25pm
Print Post  
It should look like this:

Code
Select All
private void OnNodeModified(object sender, NodeEventArgs e)
{
	var container = e.Node.MasterGroup.MainItem as DiagramNode;
	if (container != null && !container.Bounds.Contains(e.Node.Bounds))
		e.Node.Detach();

	var nodes = diagram.GetNodesAt(e.MousePosition);
	foreach (DiagramNode node in nodes)
		if (node.MasterGroup != null)// it's a container
		{
			e.Node.AttachTo(node, AttachToNode.TopLeft);
			break;
		}
}
 


  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #9 - Apr 28th, 2009 at 12:28pm
Print Post  
Thanks stoyan,it is helpful.

Now I am able to Drag and Drop Node from one group to another.
I have applied some conditions in DragDrop operation.If these conditions gets true than only node should drop into another group, else node should return back to its previous position.

Now I want know,How Node can move to its previous position if the condition gets false?

Thanks,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #10 - Apr 29th, 2009 at 9:36am
Print Post  
Hi,

You could handle the NodeModifying validation event and check for this condition there. If it does not hold, set e.Cancel = true.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #11 - May 12th, 2009 at 6:44am
Print Post  
First of all, Thanks for the reply its working Smiley

Now I facing a different issue.Scenerio is like this.

I am selecting multiple nodes from one group and drop them into another group but in this operation I am getting 0 node count in that drop mouse position.Code is working fine for 1 node but I am unable to get mousePosition when select multiple nodes.

The code is like this.

Code
Select All
if (sourceNode.MasterGroup.MainItem != null)
				{
				    DiagramNode sourceMasterNode = sourceNode.MasterGroup.MainItem as DiagramNode;
				    if (sourceMasterNode != null && !sourceMasterNode.Bounds.Contains(sourceNode.Bounds))
				    {
					  DiagramNodeCollection nodes = diagram.GetNodesAt(e.MousePosition);

					  if (nodes.Count == 1)
						sourceNode.Detach();
					  else
					  {......................}
					  }
					  } 



please suggest something.

Thanks,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #12 - May 12th, 2009 at 7:35am
Print Post  
Are you doing that in the SelectionMoved handler?
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Dragging of Node from one group to another
Reply #13 - May 12th, 2009 at 8:17am
Print Post  
No,I have done this in NodeModified event.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dragging of Node from one group to another
Reply #14 - May 12th, 2009 at 10:18am
Print Post  
The mouse position is not specified for NodeModified when dragging multiple nodes. Try getting it through the GetPosition method of the System.Windows.Input.Mouse class, and convert it to diagram coordinates using ClientToDoc method.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint