Пример #1
0
        private List <ILayoutAction> CreateLayoutActions(LayoutVertexToPointMap newVertexCenters)
        {
            var layoutActions = new List <ILayoutAction>();

            layoutActions.AddRange(CreateLayoutActionsForMovedDiagramNodes(newVertexCenters));
            layoutActions.AddRange(CreateLayoutActionsForRerouteAllPaths(newVertexCenters));
            return(layoutActions);
        }
Пример #2
0
 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);
 }
Пример #3
0
 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);
 }
Пример #4
0
        private void SaveCurrentLayoutPaths(LayoutVertexToPointMap newVertexCenters)
        {
            _layoutPathToPreviousRouteMap.Clear();

            foreach (var layoutPath in RelativeLayout.LayeredLayoutGraph.Edges)
            {
                var currentRoute = GetRoutePoints(layoutPath, newVertexCenters);
                _layoutPathToPreviousRouteMap.Set(layoutPath, currentRoute);
            }
        }
Пример #5
0
        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));
                }
            }
        }
Пример #6
0
        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));
                }
            }
        }
Пример #7
0
        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));
        }
Пример #8
0
 private static Point2D GetVertexCenterOrUndefined(LayoutVertexToPointMap vertexCenters, LayoutVertexBase vertex)
 {
     vertexCenters.TryGet(vertex, out var center, valueForMissingKey: Point2D.Undefined);
     return(center);
 }
Пример #9
0
 private void SaveCurrentPositions(LayoutVertexToPointMap newVertexCenters)
 {
     _previousVertexCenters = newVertexCenters;
     SaveCurrentLayoutPaths(newVertexCenters);
 }
Пример #10
0
 private static Point2D GetVertexCenterOrUndefined(LayoutVertexToPointMap vertexCenters, LayoutVertexBase vertex)
 {
     return(vertexCenters.Contains(vertex)
         ? vertexCenters.Get(vertex)
         : Point2D.Undefined);
 }