Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Event handler issues in case of attached nodes (Read 3405 times)
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Event handler issues in case of attached nodes
May 26th, 2009 at 4:28pm
Print Post  
Hi Stoyan,

I have sent a new sample to you at your email-id (support@mindfusion.eu).Please have a look into that.

Our objectives are:-

1). To perform operation over the node like DoubleClicked,MouseLeftButtonUp,LinkDoubleClicked etc.
2). To show + button while mouse enters in the node and remove this button on mouse leave.

Problem:-

1). When we perform any diagram event over the node (like DoubleClicked, MouseLeftButtonUp, LinkDoubleClicked) we get source node from e.Node. We want to perform all the operations over the mainNode only not over its attached nodes. for exa- If I clicked on the Node(it also may click on its Attached Node, which is inside this main node),I want to get that node as mainNode only i.e attached node should be there but all the operation should be performed only for main nodes.

2). MouseEnter and MouseLeave both are calling inside a node (condition: when mouse enters from one attached nodes to another). I want Mouse enter should be called only when mouse enters to the main node and mouse leave should be called only when mouse leave from main node.

These two issues are very critical for us. We have tried to solve these but not got that much success. Please give solution of these as soon as possible.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event handler issues in case of attached nodes
Reply #1 - May 27th, 2009 at 12:27pm
Print Post  
1. You could use the following pattern:

Code
Select All
void diagram_NodeDoubleClicked(object sender, NodeEventArgs e)
{
	if (e.Node.MasterGroup != null)
	{
		DiagramNode mainNode = e.Node.MasterGroup.MainItem as DiagramNode;
		if (mainNode != null)
		{
			diagram_NodeDoubleClicked(null, new NodeEventArgs(mainNode));
		}
	}
	else
	{
		ShapeNode node = e.Node as ShapeNode;
		if (node != null)
			MessageBox.Show(node.Text);
	}
}
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event handler issues in case of attached nodes
Reply #2 - May 27th, 2009 at 2:58pm
Print Post  
2. That's easier to implement using MouseMove. The MouseEnter and Leave events are raised by WPF at a lower level for all kinds of UI elements, including selection handles, and gets harder to track. You can find a sample MouseMove handler below.

Code
Select All
void OnDiagramMouseMove(object sender, MouseEventArgs e)
{
	Point mousePt = e.GetPosition(diagram.DocumentPlane);
	DiagramItem item = diagram.GetItemAt(mousePt, true);
	if (item != null)
	{
		ShapeNode node = item as ShapeNode;
		if (node != null && node.SubordinateGroup != null && node != mainNode)
		{
			if (mainNode != null)
				MouseLeave(mainNode);
			MouseEnter(node);
			mainNode = node;
		}
	}
	else if (mainNode != null)
	{
		MouseLeave(mainNode);
		mainNode = null;
	}
}

private void MouseEnter(DiagramNode node)
{
	Debug.Write("\nin: " + inCount.ToString());
	inCount++;
}

private int inCount = 0;
private int outCount = 0;
private ShapeNode mainNode;

private void MouseLeave(DiagramNode node)
{
	Debug.Write("\nout: " + outCount.ToString());
	outCount++;
}
 



This code assumes the attched nodes are Locked, so that GetItemAt does not return them.
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Event handler issues in case of attached nodes
Reply #3 - May 28th, 2009 at 1:08pm
Print Post  
Hi Stoyan,
Its not working.MouseEnter and MouseLeave are calling continously in a node.Please suggest some alternative way.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event handler issues in case of attached nodes
Reply #4 - May 29th, 2009 at 6:36am
Print Post  
I suppose this could happen if you replaced the enter/leave methods above with your own implementation that do not update the mainNode field. The code below moves the mainNode assignments out of the handler methods. Also if your attached nodes are not locked, replace the GetItemsAt call with the GetMasterNodeAt method shown below:

Code
Select All
private DiagramNode GetMasterNodeAt(Point pt)
{
	DiagramNodeCollection dnc = diagram.GetNodesAt(pt);

	foreach (DiagramNode node in dnc)
	{
		if (node.SubordinateGroup != null)
			return node;
	}

	return null;
}

void OnDiagramMouseMove(object sender, MouseEventArgs e)
{
	Point mousePt = e.GetPosition(diagram.DocumentPlane);
	DiagramNode item = GetMasterNodeAt(mousePt);

	if (item != null)
	{
		ShapeNode node = item as ShapeNode;
		if (node != null && node != mainNode)
		{
			if (mainNode != null)
				MouseLeave(mainNode);
			MouseEnter(node);
			mainNode = node;
		}
	}
	else if (mainNode != null)
	{
		MouseLeave(mainNode);
		mainNode = null;
	}
}

private void MouseEnter(DiagramNode node)
{
	Console.WriteLine("in");
}

private void MouseLeave(DiagramNode node)
{
	Console.WriteLine("out");
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint