Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic OnContainerChildRemoving event (Read 4665 times)
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
OnContainerChildRemoving event
Apr 30th, 2013 at 7:18am
Print Post  
Hi,

I wanted to prevent a shape not to move out of the container node. I don't want that shape to get adedd to a child container also.

So what i am thinking is to do the logic in onContainerChildRemoving event and do a setCancel. Since Mindfusion is not exposing this event, what is the ideal way to achieve this. I dont want to handle this in OnModifyingEvent.

I want to do soemthing similar to the below scenario.

http://mindfusion.eu/Forum/YaBB.pl?num=1367226820

Is there any method i can override inorder to achive this.

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildRemoving event
Reply #1 - Apr 30th, 2013 at 6:01pm
Print Post  
Hi,

You can override the container.remove method the same way as the add one:

Code
Select All
var originalRemove = ContainerNode.prototype.remove;
ContainerNode.prototype.remove = function (node, raiseEvent)
{
	// filtering code
	// ...

	originalRemove.apply(this, [node, raiseEvent]);
}; 



There's nothing wrong in cancelling the operation from modifying event, that will also show a stop cursor:

Code
Select All
var node = args.getNode();
var ctrBounds = node.container.getBounds();
var childBounds = node.getBounds();
if (!ctrBounds.contains(childBounds) &&
	!ctrBounds.intersectsWith(childBounds))
{
	args.setCancel(true);
} 



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


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildRemoving event
Reply #2 - May 8th, 2013 at 6:19am
Print Post  
Hi Stoyan,

The below code is not working in the below 2 scenarios.

var node = args.getNode();
var ctrBounds = node.container.getBounds();
var childBounds = node.getBounds();
if (!ctrBounds.contains(childBounds) &&
     !ctrBounds.intersectsWith(childBounds))
{
     args.setCancel(true);
}


1. I am having a container node. Another container node is inside that. Here in this case i am able to drop shapes form parent container to child container

2. One container node is overlapping with another container node. Here i am able to drop shapes in the overlapped region

How can i fix these 2 also?

Thanks
Kiran B
« Last Edit: May 9th, 2013 at 4:03pm by Kiran B »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildRemoving event
Reply #3 - May 9th, 2013 at 6:08am
Print Post  
What code exactly is not working?
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildRemoving event
Reply #4 - May 9th, 2013 at 6:08am
Print Post  
Hi Stoyan,

Is There any update for this?

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildRemoving event
Reply #5 - May 9th, 2013 at 10:21am
Print Post  
What exactly is the "code below" that's not working?
  
Back to top
 
IP Logged
 
Kiran B
Full Member
***
Offline


I Love MindFusion!

Posts: 102
Joined: Apr 19th, 2013
Re: OnContainerChildRemoving event
Reply #6 - May 9th, 2013 at 12:36pm
Print Post  
Sorry Stoyan,

This is the code i am using. Same code you have given

var node = args.getNode();
var ctrBounds = node.container.getBounds();
var childBounds = node.getBounds();
if (!ctrBounds.contains(childBounds) &&
     !ctrBounds.intersectsWith(childBounds))
{
     args.setCancel(true);
}

Thanks
Kiran B
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnContainerChildRemoving event
Reply #7 - May 9th, 2013 at 4:45pm
Print Post  
Try this version instead:

Code
Select All
function onNodeModifying(sender, args)
{
	var node = args.getNode();
	if (node.container)
	{
		var ctrBounds = node.container.getBounds();
		var childBounds = node.getBounds();
		if (!ctrBounds.contains(childBounds) &&
			!ctrBounds.intersectsWith(childBounds))
		{
			args.setCancel(true);
			return;
		}

		var nodes = sender.getNodesAt(args.getMousePosition());
		for (var i = nodes.length - 1; i >= 0; i--)
		{
			var test = nodes[i];
			if (test == node)
				continue;
			else if (test == node.container)
				return;
			else if (ContainerNode.isInstanceOfType(test))
			{
				args.setCancel(true);
				return;
			}
		}
	}
} 



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