Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Link route / control points (Read 9742 times)
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Link route / control points
Jun 6th, 2011 at 8:23am
Print Post  
Hi Stoyo,

We are having a side effect when creating links which we can not seem to get around.

In the diagram that the user creates it is possible for a link to have the same shapenode for its origin, as well as its destination node, just with different anchor points.

A link is programmatically created and given the location of the anchor points, as well as some control points.

In the following screenshot, the "swirly link" was created with the following control points:

1) Create the link:

DiagramLink Edge = new DiagramLink(DiagramView.Diagram, GetShapeByNodeId(WfEdge.SourceNodeId), GetShapeByNodeId(WfEdge.TargetNodeId));

In this case the GetShapeByNodeId returns the same shape for both origin and destination shapes.

2)
Edge.OriginAnchor is set to 3.
Edge.DestinationAnchor is set to 0.

3)
At this point there are already control points in the link, and since we want to specify our own we clear the collection.

Edge.ControlPoints.Clear();

4)
All 5 control points are added using the Edge.ControlPoints.Add(PointF); method, with the following coordinates:

[150-311]
[135-311]
[134-271]
[200-271]
[200-286]

5)
After altering the control points we call UpdateFromPoints();.

6)
To finalize, we set the Edge.SegmentCount to Edge.ControlPoints.Count() - 1.

After 6, the control points collection now has 13 items instead of 5. Also, as you can see in this screenshot..



.. the link is not connected to the specified anchor points. At least, visually, because the OriginAnchor and DestinationAnchor are still set to the correct values of 3 and 0 respectively.

What I would like to see, is this (edited image):



Basically all my links behave like I want to (including anchors and control points), only the links where the origin and destination shapenode is the same this issue is occuring.

How can we get to a result as shown in the second image?

Kind regards,
Bas

  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #1 - Jun 6th, 2011 at 8:43am
Print Post  
Short update:

If the control point adding logic is changed to:

Code
Select All
DiagramLink Edge = new DiagramLink(DiagramView.Diagram, GetShapeByNodeId(WfEdge.SourceNodeId), GetShapeByNodeId(WfEdge.TargetNodeId));

Edge.OriginAnchor = WfEdge.Style.SourceHandle;
Edge.DestinationAnchor = WfEdge.Style.DestinationHandle;


Edge.SegmentCount = Convert.ToInt16(WfEdge.Style.EdgePoints.Count - 1);

Edge.ControlPoints.Clear();


for (int n = 0; n < fEdge.Style.EdgePoints.Count; n++)
{
  PointF Point = new PointF(WfEdge.Style.EdgePoints[n].X, WfEdge.Style.EdgePoints[n].Y);

  Edge.ControlPoints.Add(Point);
}

Edge.UpdateFromPoints();

Edge.SegmentCount = Convert.ToInt16(WfEdge.Style.EdgePoints.Count - 1);
 




Then the amount of controlpoints in the collection is correct (5) and the SegmentCount is also correct (4).

However, the diagramview shows a big red X..


UPDATE:

I notice that in this case the control points collection is already changed to 13 items after the first call to set SegmentCount.

The funny thing here is, that in that collection the first and last items have the same coordinates. That strikes me as a bit odd considering the origin and destination anchors are different.



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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #2 - Jun 6th, 2011 at 9:37am
Print Post  
Hi Bas,

The Style of self-loop links is set to Bezier by default, and Bezier links have 4 control points for each segment. Try resetting the style to Polyline or Cascading before assigning new points. Also call UpdateFromPoints(false, true) to update the internal segment count instead of setting the SegmentCount property (which could reset the link shape again).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #3 - Jun 6th, 2011 at 9:53am
Print Post  
I modified my code to set the style of the link after the setting of the origin and destination anchors:

if (Edge.Origin == Edge.Destination)
Edge.Style = LinkStyle.Cascading;

However, after it sets the style to Cascading, the Edge.Style is still set to Brezier.

UPDATE:
The diagram.LinkStyle property was already set to PolyLine.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #4 - Jun 6th, 2011 at 10:34am
Print Post  
It seems you cannot set a reflexive link's Style to Cascading if the link currently has less than 3 segments. Try setting SegmentCount to 3 before changing Style.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #5 - Jun 6th, 2011 at 11:35am
Print Post  
Ok, so here the entire method as it is:

Code
Select All
	  private DiagramLink CreateWorkflowEdge(WorkflowEdge WfEdge)
	  {
		try
		{
		    DiagramLink Edge = new DiagramLink(DiagramView.Diagram, GetShapeByNodeId(WfEdge.SourceNodeId), GetShapeByNodeId(WfEdge.TargetNodeId));

		    Edge.OriginAnchor = WfEdge.Style.SourceHandle;
		    Edge.DestinationAnchor = WfEdge.Style.DestinationHandle;

		    Edge.ControlPoints.Clear();

		    for (int n = 0; n < WfEdge.Style.EdgePoints.Count; n++)
		    {
			  PointF Point = new PointF(WfEdge.Style.EdgePoints[n].X, WfEdge.Style.EdgePoints[n].Y);
			  Edge.ControlPoints.Add(Point);
		    }

		    Edge.SegmentCount = Convert.ToInt16(Edge.ControlPoints.Count - 1);

		    if (Edge.Origin == Edge.Destination)
			  Edge.Style = LinkStyle.Cascading;

		    Edge.UpdateFromPoints(false, true);

		    Edge.Tag = WfEdge;

		    return Edge;
		}
		catch (Exception E)
		{
		    throw new Exception("WorkflowManager.CreateWorkflowEdge: " + E.Message);
		}
	  }
 



If I use a Cascaded style, I am basically back to where I was in my first image (first post).

Setting it to Polyline does the following:



I just don't understand why the link doesnt follow the coordinates of the control points, and respects the origin and destination anchors on the same shapenode.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #6 - Jun 6th, 2011 at 12:14pm
Print Post  
Setting Style or SegmentCount resets the link to some default shape for its current state. That image shows the default for cascading self-loop link. You will have to set Style before changing the ControlPoints coordinates.
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #7 - Jun 7th, 2011 at 4:46am
Print Post  
That did the trick!

Perhaps its a good idea to specify in the documentation that there is a minimum segment count limit for the different link styles.

Thanks again,
Bas
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #8 - Jun 7th, 2011 at 4:51am
Print Post  
I noticed now that I am able to programmatically create reflexive links, but the user can not. This "denied" icon appears when you try to connect to an anchor of the same node.

I have diagram.AllowSelfLoops set to true. This is not enough?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #9 - Jun 7th, 2011 at 6:43am
Print Post  
AllowSelfLoops should let the user draw such links. Are you handling the LinkCreating or ValidateAnchorPoint events by any chance? Setting e.Cancel = true from the handlers will prevent drawing the link too.
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #10 - Jun 7th, 2011 at 9:27am
Print Post  
No..

Only the:

LinkClicked
LinkCreated
LinkDeleting
LinkModified

..events. And the same for nodes.

  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #11 - Jun 7th, 2011 at 10:01am
Print Post  
I can reproduce this behavior with a new test application, just dropping a Diagram and DiagramView on the form, and run it.

If you draw a node, you will not be able to create a reflexive link, even with the AllowSelfLoops set to true (which it is by default).
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #12 - Jun 7th, 2011 at 11:20am
Print Post  
It works for me when all properties have default values. Could you email your test app to support@mindfusion.eu?
  
Back to top
 
IP Logged
 
Bass
YaBB Newbies
*
Offline



Posts: 31
Joined: Aug 27th, 2010
Re: Link route / control points
Reply #13 - Jun 7th, 2011 at 12:20pm
Print Post  
Sent it.

It also includes a screenshot of what I am trying to do (attach link from anchor point 3 to achor point 2 of the same node).

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link route / control points
Reply #14 - Jun 7th, 2011 at 12:42pm
Print Post  
I am not sure if we are discussing the same thing. Here is the test project compiled, it lets me draw a node and after it a reflexive link (which the control converts automatically to Bezier to draw as a loop above the node) -
https://mindfusion.eu/_temp/winapp2_Debug.zip

Are you saying that on your system it shows the stop mouse cursor while drawing a link over the node, and does not create the link at all when you release the mouse at an interior point of the node? Also with all default settings the nodes do not have any specific anchor points defined, and I am not sure what the screenshot is supposed to show - there's no mouse cursor visible on it either.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint