private List <ILayoutAction> CreateLayoutActions(LayoutVertexToPointMap newVertexCenters) { var layoutActions = new List <ILayoutAction>(); layoutActions.AddRange(CreateLayoutActionsForMovedDiagramNodes(newVertexCenters)); layoutActions.AddRange(CreateLayoutActionsForRerouteAllPaths(newVertexCenters)); return(layoutActions); }
public IncrementalLayoutEngine() { _diagramNodeToLayoutVertexMap = new Map <IDiagramNode, DiagramNodeLayoutVertex>(); _diagramConnectorToLayoutPathMap = new Map <IDiagramConnector, LayoutPath>(); _layoutPathToPreviousRouteMap = new Map <LayoutPath, Route>(); _previousVertexCenters = new LayoutVertexToPointMap(); _relativeLayoutCalculator = new RelativeLayoutCalculator(); _diagramActionDispatcherVisitor = new DiagramActionDispatcherVisitor(this); }
public IncrementalLayoutCalculator(ILayoutPriorityProvider layoutPriorityProvider) { _layoutPriorityProvider = layoutPriorityProvider ?? throw new ArgumentNullException(nameof(layoutPriorityProvider)); _diagramNodeToLayoutVertexMap = new Map <IDiagramNode, DiagramNodeLayoutVertex>(new DiagramNodeIdEqualityComparer()); _diagramConnectorToLayoutPathMap = new Map <IDiagramConnector, LayoutPath>(new DiagramConnectorIdEqualityComparer()); _layoutPathToPreviousRouteMap = new Map <LayoutPath, Route>(); _previousVertexCenters = new LayoutVertexToPointMap(); _relativeLayoutCalculator = new RelativeLayoutCalculator(); _diagramActionDispatcherVisitor = new DiagramActionDispatcherVisitor(this); }
private void SaveCurrentLayoutPaths(LayoutVertexToPointMap newVertexCenters) { _layoutPathToPreviousRouteMap.Clear(); foreach (var layoutPath in RelativeLayout.LayeredLayoutGraph.Edges) { var currentRoute = GetRoutePoints(layoutPath, newVertexCenters); _layoutPathToPreviousRouteMap.Set(layoutPath, currentRoute); } }
private IEnumerable <ILayoutAction> CreateLayoutActionsForRerouteAllPaths(LayoutVertexToPointMap newVertexCenters) { foreach (var layoutPath in RelativeLayout.LayeredLayoutGraph.Edges) { _layoutPathToPreviousRouteMap.TryGet(layoutPath, out var oldRoute, valueForMissingKey: Route.Empty); var newRoute = GetRoutePoints(layoutPath, newVertexCenters); if (newRoute.IsDefined && newRoute != oldRoute) { yield return(new ReroutePathLayoutAction(layoutPath, oldRoute, newRoute)); } } }
private IEnumerable <ILayoutAction> CreateLayoutActionsForMovedDiagramNodes(LayoutVertexToPointMap newVertexCenters) { foreach (var diagramNodeLayoutVertex in RelativeLayout.LayeredLayoutGraph.Vertices) { var oldCenter = GetVertexCenterOrUndefined(_previousVertexCenters, diagramNodeLayoutVertex); var newCenter = GetVertexCenterOrUndefined(newVertexCenters, diagramNodeLayoutVertex); if (newCenter.IsDefined && newCenter != oldCenter) { yield return(new MoveDiagramNodeLayoutAction(diagramNodeLayoutVertex, oldCenter, newCenter)); } } }
private static Route GetRoutePoints(LayoutPath layoutPath, LayoutVertexToPointMap vertexCenters) { var sourceRect = vertexCenters.GetRect(layoutPath.PathSource); var targetRect = vertexCenters.GetRect(layoutPath.PathTarget); var routePoints = new Route.Builder { sourceRect.Center, layoutPath.InterimVertices.Select(vertexCenters.Get), targetRect.Center }.ToRoute(); return(routePoints.AttachToSourceRectAndTargetRect(sourceRect, targetRect)); }
private static Point2D GetVertexCenterOrUndefined(LayoutVertexToPointMap vertexCenters, LayoutVertexBase vertex) { vertexCenters.TryGet(vertex, out var center, valueForMissingKey: Point2D.Undefined); return(center); }
private void SaveCurrentPositions(LayoutVertexToPointMap newVertexCenters) { _previousVertexCenters = newVertexCenters; SaveCurrentLayoutPaths(newVertexCenters); }
private static Point2D GetVertexCenterOrUndefined(LayoutVertexToPointMap vertexCenters, LayoutVertexBase vertex) { return(vertexCenters.Contains(vertex) ? vertexCenters.Get(vertex) : Point2D.Undefined); }