Hi,
I've made some progress and seem to have it working.
Here's my code at this point:
protected void SortRoutedLinksTaskLeft(Diagram diagram)
{
foreach (ShapeNode node in diagram.Nodes)
{
// Only care about task shapes
if (node.Shape != Shapes.RoundRect)
continue; // stops processing here, and gets the next node in the collection
// sort incoming links by polar positions (angles) of link origin
// nodes around the clicked node
PointF center = node.GetCenter();
List<DiagramLink> links = LeftInLinks(node);
if (links.Count > 1)
{
links.Sort((l1, l2) =>
{
DiagramNode o1 = l1.Origin;
DiagramNode o2 = l2.Origin;
PointF c1 = o1.GetCenter();
PointF c2 = o2.GetCenter();
float a1 = 0, a2 = 0, r = 0;
MindFusion.Geometry.Geometry2D.Convert.CartesianToPolar(
center, c1, ref a1, ref r);
MindFusion.Geometry.Geometry2D.Convert.CartesianToPolar(
center, c2, ref a2, ref r);
if (a1 < 0)
a1 += 360;
if (a2 < 0)
a2 += 360;
return a1.CompareTo(a2);
});
// distribute the sorted links along the node's left side
float dy = node.Bounds.Height / (links.Count + 1);
float y = node.Bounds.Top + dy;
foreach (DiagramLink link in links)
{
Int32 EndPoint = link.ControlPoints.Count - 1;
link.ControlPoints[EndPoint] = new PointF(node.Bounds.Left, y);
link.UpdateFromPoints();
y += dy;
}
}
}
}
protected List<DiagramLink> LeftInLinks(DiagramNode node)
{
List<DiagramLink> links = new List<DiagramLink>();
foreach (DiagramLink link in node.IncomingLinks)
{
if (link.DestinationAnchor < 5)
links.Add(link);
}
return links;
}
Rather than placing this code in the DrawNode event handler, I call this method after I've created all the shapes and the links between them.
After calling the above code, I then perform the diagram.RouteAllLinks().
I now need to apply this same logic to links exiting the right and bottom of my task shapes.
I think I'm good for now.
Many thanks for the code - I would have never thought of taking this approach.
Jim