Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Finding a shape in server-side javaapplet event (Read 6186 times)
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Finding a shape in server-side javaapplet event
Oct 11th, 2012 at 4:24am
Print Post  
Hi,

I'm trying to find a particular shape I drew on the diagramView.

I cant seem to figure out how to use the findnode to find it when it was created on the fly by user.

What I eventually want to do is somehow (not figured out yet), see if this shape drawn resides in the bounds on stage 2 rectangle.

Note I am using javaApplet server side events.
« Last Edit: Oct 11th, 2012 at 8:10am by saad »  

Capture_012.PNG ( 11 KB | 118 Downloads )
Capture_012.PNG
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Finding a shape in client-side javaapplet event
Reply #1 - Oct 11th, 2012 at 7:13am
Print Post  
Hi,

You can detect a newly drawn shape using the NodeCreatedScript client-side event. To determine over which lane the new node has been drawn, you could check the area of intersection of the new node with lane nodes and select the one with largest area. E.g. assuming your lane nodes are locked:

Code
Select All
function onNodeCreated(sender, args)
{
	var applet = <%= diagramView.AppletElement %>;
	var diagram = applet.getDiagram();

	var laneUnderNewNode = null;
	var maxArea = 0;

	for (var i = 0; i < diagram.getNodes().size(); i++)
	{
		var node = diagram.getNodes().get(i);

		if (node.getLocked())	// this is a lane
		{
			var intr = args.getNode().getBounds().createIntersection(node.getBounds());
			var area = intr.getWidth() * intr.getHeight();
			if (area > maxArea)
			{
				maxArea = area;
				laneUnderNewNode = node;
			}
		}
	}

	if (laneUnderNewNode)
	{
		// process new node drawn over this lane
	}
} 



If your lanes are the same height and start from 0, you could find the lane index by simply dividing the node's center Y coordinate by lane height instead of iterating and checking for intersections.

If you need to that on the server side after post-back, the last drawn node should be also last in the diagram.Nodes collection, so you should be able to find it at the count - 1 index:

var newNode = diagram.Nodes[diagram.Nodes.Count - 1];

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


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Finding a shape in server-side javaapplet event
Reply #2 - Oct 11th, 2012 at 8:11am
Print Post  
I edited the question, I meant server-side, not client side.
Apologies for that.

If you'd see my solution to firing server-side events in javaapplet (which BTW I'd like to know is the right way or not) since I'm calling a button's event no arguments are passed as normally would when you trigger an event.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Finding a shape in server-side javaapplet event
Reply #3 - Oct 11th, 2012 at 11:36am
Print Post  
On the server side you can use very much the same APIs:

Code
Select All
foreach (DiagramNode node in diagram.Nodes)
{
    if (node.Locked)
    {
        var intr = RectangleF.Intersect(node.Bounds, newNode.Bounds);
        var area = intr.Width * intr.Height;
        if (area > maxArea)
        ....
} 



or if all lanes have the same height:

int laneIndex = (int)newNode.GetCenter().Y / (int)laneHeight;

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


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Finding a shape in server-side javaapplet event
Reply #4 - Oct 11th, 2012 at 2:40pm
Print Post  
Hi,

Thanks for that.

I did it like this
Code
Select All
 foreach (ShapeNode node in diagramView.Diagram.Nodes)
        {
            if (node.Text == "Start")
            {
                // assigning node matching to variable
                startNode = node;


            }
        } 



Now you see what I'm doing here, to identify the node I am using its text property.

For a new or currently created node, I shall see if the text is null.

As you probably noticed, this is not ideal.

The reason is that because of the method of executing server-side events, no arguments are passed giving me the current node that normally I would be able to access with "e.node".

Ideally I would want this:
Code
Select All
protected void diagramView_NodeClicked(object sender, NodeEventArgs e) 



But as I showed in another thread of mine, I am using a button.

So I'm forced to write a function in c# on lines of:

Code
Select All
protected void LocationClicked(object sender, EventArgs e) 



I mean really I would still like to know if my method of executing server-side event is the right and most efficient way or do you have like a tutorial on how to execute server-side events in javaApplet mode?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Finding a shape in server-side javaapplet event
Reply #5 - Oct 12th, 2012 at 6:40am
Print Post  
Using the PostBack event method from the other thread, you can pass the node's index within diagram.Nodes along with the event name as a parameter for the RaisePostBackEvent method. That will let you identify which node has been clicked or created.

E.g. when calling the postback script, set the argument to "NodeCreated," + diagram.getNodes().indexOf(args.getNode()). When processing RaisePostBackEvent, call eventArgument.Split(","), parse the second substring as integer index and use diagram.Nodes[index] to access the node.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint