Hi. very thank you.
I have some problem.
http://cfile29.uf.tistory.com/original/144732154B80B7043EE77F private void OverlapLinkCreated(object sender, LinkEventArgs e)
{
DiagramLink link = e.Link;
DiagramLinkCollection links = GetCommonLinks(link.Origin, link.Destination);
PointF firstPoint = link.ControlPoints[0];
PointF lastPoint = link.ControlPoints[link.ControlPoints.Count - 1];
ShapeNode origin = link.Origin as ShapeNode;
ShapeNode destination = link.Destination as ShapeNode;
PointF originIntersectionPoint = origin.GetIntersection(firstPoint, lastPoint);
if (originIntersectionPoint.Y <= link.Origin.Bounds.Top ||
originIntersectionPoint.Y >= link.Origin.Bounds.Bottom)
DistributeHorizontally(links, origin, firstPoint.Y);
else
DistributeVertically(links, origin, firstPoint.X);
PointF destinationIntersectionPoint = link.Destination.GetIntersection(firstPoint, lastPoint);
if (destinationIntersectionPoint.Y <= link.Destination.Bounds.Top ||
destinationIntersectionPoint.Y >= link.Destination.Bounds.Bottom)
DistributeHorizontally(links, destination, lastPoint.Y);
else
DistributeVertically(links, destination, lastPoint.X);
}
private void DistributeHorizontally(DiagramLinkCollection links, ShapeNode node, float y)
{
float d = node.Bounds.Width / (links.Count + 1);
int x = 1;
foreach (DiagramLink link in links)
{
int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
PointF endPointF = node.GetIntersection(link.ControlPoints[0], link.ControlPoints[link.ControlPoints.Count - 1]);
endPointF.X = node.Bounds.Left + (d * x);
endPointF.Y = y;
link.ControlPoints[index] = endPointF;
link.UpdateFromPoints(true, false);
x++;
}
}
private void DistributeVertically(DiagramLinkCollection links, ShapeNode node, float x)
{
float d = node.Bounds.Height / (links.Count + 1);
int y = 1;
foreach (DiagramLink link in links)
{
int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
PointF endPointF = node.GetIntersection(link.ControlPoints[0], link.ControlPoints[link.ControlPoints.Count - 1]);
endPointF.X = x;
endPointF.Y = node.Bounds.Top + (d * y);
link.ControlPoints[index] = endPointF;
link.UpdateFromPoints(true, false);
y++;
}
}
problem 1. I called node.GetIntersection() function. but why overlap?
problem 2. How can I improve code ?