Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to prevent resizing of nodes at specifc size (Read 2270 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
How to prevent resizing of nodes at specifc size
Apr 13th, 2010 at 1:08pm
Print Post  
Hi Stoyo

I have a container node and child nodes added in it.

By keepting constranins I cannot move child nodes outside the container node.

But at the same time, i need to prevent sizing of container node such that its child item should not be visible outside.

For that I am trying to do something in following event but not giving expected results ...

Code
Select All
void diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
if (e.Node is ContainerNode)
{
ContainerNode con = e.Node as ContainerNode;
Rect r = new Rect(0, 0, 0, 0);
bool first = true;
foreach (DiagramNode item in con.Children)
{
if (first)
r = item.Bounds;
else
r.Union(item.Bounds);
first = false;
}
Rect outerRect = e.Node.Bounds;

if (!((r.Left > outerRect.Left) && (r.Top > outerRect.Top) && (r.Width < outerRect.Width) && (r.Height < outerRect.Height)))
e.Cancel = true; //();// = true;
System.Console.Write("TesT");
}
}
 



With above code, the node gets resized to its previous state when mouse button was down ... I need to stop it resizing once above condition matches even mouse movement is there ...

I guess it needs to be done in behaviour.
Can you help me in it with some code snipet.

-Rajesh
  
Back to top
WWW  
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: How to prevent resizing of nodes at specifc si
Reply #1 - Apr 13th, 2010 at 2:16pm
Print Post  
Hi Stoyo

I am able to get where it needs to be fixed -
I have a dervied class and I updated its UpdateDrag function as below :
Code
Select All
protected override void UpdateDrag(InteractionState ist)
{
if (true)
{
int index = ist.AdjustmentHandle.Index;
if (index != 8)
{
ContainerNode con = this as ContainerNode;
Rect r = new Rect(0, 0, 0, 0);
bool first = true;
foreach (DiagramNode item in con.Children)
{
if (first)
r = item.Bounds;
else
r.Union(item.Bounds);
first = false;
}
Rect outerRect = this.Bounds;

if (((r.Left > outerRect.Left) && (r.Top > outerRect.Top) && (r.Width < outerRect.Width) && (r.Height < outerRect.Height)))
{
base.UpdateDrag(ist);
return;
}
}
else
{
base.UpdateDrag(ist);
return;
}
}
}
 



With this code, I am able to prevent the sizing from topleft adjusment handle when it encounter the first node.

The problem with this code is that, once it stopped resizing I cannot move the mouse again upside.

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prevent resizing of nodes at specifc si
Reply #2 - Apr 14th, 2010 at 11:46am
Print Post  
Hi Rajesh,

Try this:

Code
Select All
protected override void UpdateDrag(InteractionState ist)
{
	base.UpdateDrag(ist);

	var r = Bounds;
	foreach (DiagramNode node in Children)
		r.Union(node.Bounds);

	SetBounds(r, false);
} 



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


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: How to prevent resizing of nodes at specifc si
Reply #3 - Apr 16th, 2010 at 8:18am
Print Post  
Hi Stoyo

The sample work as expected with following additional behaviour -

For eq. Picking Top -left adjument handle, user tries to move the cursor downside and at one place it stops moving the top line since some inner node bounds matches with top position.

With this if user continues to move the mouse downside and reaches the bottom line of the node then it starts changing the height of the node.

Originally I am expecting only changing top,left position to change the size of node - later on results in changing the width/height of the node.

Any idea - to prevent this ?

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prevent resizing of nodes at specifc si
Reply #4 - Apr 16th, 2010 at 12:30pm
Print Post  
Hi Rajesh,

Add some checks for the AdjustmentHandle value of InteractionState and do not change the coordinates of the opposing side. E.g. if AdjustmentHandle is any of ResizeTop* values, keep r.Bottom to the node's original Bottom coordinate.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint