using System; using System.Collections.Generic; using System.Linq; using Microsoft.Msagl.Core; using Microsoft.Msagl.Core.DataStructures; using Microsoft.Msagl.Core.Geometry; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Core.GraphAlgorithms; using Microsoft.Msagl.Core.Layout; using Microsoft.Msagl.Core.ProjectionSolver; using Microsoft.Msagl.Routing; namespace Microsoft.Msagl.Layout.Layered { internal class TwoLayerFlatEdgeRouter : AlgorithmBase { readonly int[] bottomLayer; InteractiveEdgeRouter interactiveEdgeRouter; double[] labelCenters; Dictionary labelsToLabelObstacles = new Dictionary(); IntPair[] pairArray; readonly Routing routing; readonly int[] topLayer; private SugiyamaLayoutSettings settings; internal TwoLayerFlatEdgeRouter(SugiyamaLayoutSettings settings, Routing routing, int[] bottomLayer, int[] topLayer) { this.settings = settings; this.topLayer = topLayer; this.bottomLayer = bottomLayer; this.routing = routing; InitLabelsInfo(); } Database Database { get { return routing.Database; } } int[] Layering { get { return routing.LayerArrays.Y; } } BasicGraph IntGraph { get { return routing.IntGraph; } } LayerArrays LayerArrays { get { return routing.LayerArrays; } } double PaddingForEdges { get { return settings.LayerSeparation / 8; } } void InitLabelsInfo() { pairArray = new Set(from v in bottomLayer where v < IntGraph.NodeCount from edge in IntGraph.OutEdges(v) where edge.Source != edge.Target where Layering[edge.Target] == Layering[edge.Source] select new IntPair(edge.Source, edge.Target)).ToArray(); labelCenters = new double[pairArray.Length]; int i = 0; foreach (IntPair p in pairArray) { int leftNode, rightNode; if (LayerArrays.X[p.First] < LayerArrays.X[p.Second]) { leftNode = p.First; rightNode = p.Second; } else { leftNode = p.Second; rightNode = p.First; } labelCenters[i++] = (Database.Anchors[leftNode].Right + Database.Anchors[rightNode].Left)/2; //labelCenters contains ideal position for nodes at the moment } InitLabelsToLabelObstacles(); } void InitLabelsToLabelObstacles() { labelsToLabelObstacles = new Dictionary(); IEnumerable