static void ProcessSugiamaLayout(GeometryGraph geometryGraph, SugiyamaLayoutSettings sugiyamaLayoutSettings, CancelToken cancelToken) {
            PlaneTransformation originalTransform;
            var transformIsNotIdentity = HandleTransformIsNotIdentity(geometryGraph, sugiyamaLayoutSettings, out originalTransform);

            if (geometryGraph.RootCluster.Clusters.Any()) {
                PrepareGraphForInitialLayoutByCluster(geometryGraph, sugiyamaLayoutSettings);
                var initialBc = new InitialLayoutByCluster(geometryGraph, a => sugiyamaLayoutSettings);
                initialBc.Run(cancelToken);
                //route the rest of the edges, those between the clusters
                RouteAndLabelEdges(geometryGraph, sugiyamaLayoutSettings,
                    geometryGraph.Edges.Where(e => e.Curve == null).ToArray());
            }
            else
                geometryGraph.AlgorithmData = SugiyamaLayoutSettings.CalculateLayout(geometryGraph,
                    sugiyamaLayoutSettings, cancelToken);

            if (transformIsNotIdentity)
                sugiyamaLayoutSettings.Transformation = originalTransform;

            PostRunTransform(geometryGraph, sugiyamaLayoutSettings);
        }
        /// <summary>
        /// Calculates the graph layout
        /// </summary>
        /// <exception cref="CancelException">Thrown when the layout is canceled.</exception>
#else
        /// <summary>
        /// Calculates the graph layout
        /// </summary>
        /// <exception cref="System.OperationCanceledException">Thrown when the layout is canceled.</exception>
#endif
        public static void CalculateLayout(GeometryGraph geometryGraph, LayoutAlgorithmSettings settings, CancelToken cancelToken) {
            Console.WriteLine("starting CalculateLayout");
            if (settings is RankingLayoutSettings) {
                var rankingLayoutSettings = settings as RankingLayoutSettings;
                var rankingLayout = new RankingLayout(rankingLayoutSettings, geometryGraph);
                rankingLayout.Run(cancelToken);
                RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges);
            }
            else if (settings is MdsLayoutSettings) {
                var mdsLayoutSettings = settings as MdsLayoutSettings;
                var mdsLayout = new MdsGraphLayout(mdsLayoutSettings, geometryGraph);
                mdsLayout.Run(cancelToken);
                if (settings.EdgeRoutingSettings.EdgeRoutingMode != EdgeRoutingMode.None)
                    RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges);
            }
            else if (settings is FastIncrementalLayoutSettings) {
                var incrementalSettings = settings as FastIncrementalLayoutSettings;
                incrementalSettings.AvoidOverlaps = true;
                var initialLayout = new InitialLayout(geometryGraph, incrementalSettings);
                initialLayout.Run(cancelToken);
                if (settings.EdgeRoutingSettings.EdgeRoutingMode != EdgeRoutingMode.None)
                    RouteAndLabelEdges(geometryGraph, settings, geometryGraph.Edges);
                //incrementalSettings.IncrementalRun(geometryGraph);
            }
            else {
                var sugiyamaLayoutSettings = settings as SugiyamaLayoutSettings;
                if (sugiyamaLayoutSettings != null)
                    ProcessSugiamaLayout(geometryGraph, sugiyamaLayoutSettings, cancelToken);
                else {
                    Debug.Assert(settings is LgLayoutSettings);
                    LayoutLargeGraphWithLayers(geometryGraph, settings, cancelToken);
                }
            }
        }
 /// <summary>
 /// Set the cancel token.  Returns the old cancel token, in case you need to revert at some stage.
 /// </summary>
 /// <param name="cancelToken">new cancel token</param>
 /// <returns>old cancel token</returns>
 public CancelToken SetCancelToken(CancelToken cancelToken)
 {
     this.cancelToken = cancelToken;
     this.ThrowIfCanceled();
     CancelToken oldCancelToken = threadStaticCancelToken;
     threadStaticCancelToken = cancelToken;
     return oldCancelToken;
 }
        internal static void RouteEdges(GeometryGraph component, LayoutAlgorithmSettings settings, CancelToken cancelToken)
        {
            EdgeRoutingMode mode = settings.EdgeRoutingSettings.EdgeRoutingMode;

            // Use straight line routing on very large graphs otherwise it is too slow 
            if (component.Nodes.Count >= 2000)
            {
                mode = EdgeRoutingMode.StraightLine;
            }

            switch (mode)
            {
                case EdgeRoutingMode.Spline:
                    var splineRouter = new SplineRouter(
                        component,
                        settings.EdgeRoutingSettings.Padding,
                        settings.NodeSeparation, settings.EdgeRoutingSettings.ConeAngle, null);
                    splineRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.SplineBundling:
                    splineRouter = new SplineRouter(
                        component,
                        settings.EdgeRoutingSettings.Padding,
                        settings.NodeSeparation / 20, settings.EdgeRoutingSettings.ConeAngle,
                      new BundlingSettings());
                    splineRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.Rectilinear:
                    double edgePadding = settings.EdgeRoutingSettings.Padding;
                    double cornerRadius = settings.EdgeRoutingSettings.CornerRadius;
                    var rectilinearEdgeRouter = new RectilinearEdgeRouter(component, edgePadding, cornerRadius,
                                                                          true);
                    rectilinearEdgeRouter.Run(cancelToken);
                    break;
                case EdgeRoutingMode.StraightLine:
                    var router = new StraightLineEdges(component.Edges,
                                                       settings.EdgeRoutingSettings.Padding);
                    router.Run(cancelToken);
                    break;
            }
        }
Exemple #5
0
        public void Run(CancelToken cancelToken)
        {
            this.progressRatio  = 0;
            this.localStepCount = 0;

            CancelToken oldCancelToken = this.SetCancelToken(cancelToken);

            try
            {
                this.ProgressSteps(0); // Initial progress

                this.RunInternal();

                if (!this.IsCanceled)
                {
                    this.ProgressComplete();
                }
            }
            finally
            {
                threadStaticCancelToken = oldCancelToken;
            }
        }
        public void Run(CancelToken cancelToken)
        {
            this.progressRatio = 0;
            this.localStepCount = 0;

            CancelToken oldCancelToken = this.SetCancelToken(cancelToken);

            try
            {
                this.ProgressSteps(0); // Initial progress

                this.RunInternal();
                
                if (!this.IsCanceled)
                {
                    this.ProgressComplete();
                }
            }
            finally
            {
                threadStaticCancelToken = oldCancelToken;
            }
        }
 /// <summary>
 /// balances the layers by moving vertices with
 /// the same number of input-output edges to feasible layers with fiewer nodes  /// </summary>
 /// <param name="dag">the layered graph</param>
 /// <param name="layering">the layering to change</param>
 /// <param name="nodeCount">shows how many nodes are represented be a node</param>
 /// <param name="cancelObj"></param>
 static internal void Balance(Graph dag, int[] layering, int[] nodeCount, CancelToken cancelObj) {
     Balancing b = new Balancing(dag, layering, nodeCount);
     b.Run(cancelObj);
 }
 static public void ComputeNodeLabelsOfLargeGraphWithLayers(GeometryGraph geometryGraph, LayoutAlgorithmSettings settings, List<double> noldeLabelRatios, CancelToken cancelToken) {
     var largeGraphLayoutSettings = (LgLayoutSettings)settings;
     var largeGraphLayout = largeGraphLayoutSettings.Interactor;
     largeGraphLayout.InitNodeLabelWidthToHeightRatios(noldeLabelRatios);
     largeGraphLayout.LabelingOfOneRun();
 }
 /// <summary>
 /// calculates all data necessery for large graph browsing
 /// </summary>
 /// <param name="geometryGraph"></param>
 /// <param name="settings"></param>
 /// <param name="cancelToken"></param>
 static public void LayoutLargeGraphWithLayers(GeometryGraph geometryGraph, LayoutAlgorithmSettings settings, CancelToken cancelToken) {
     var largeGraphLayoutSettings = (LgLayoutSettings) settings;
     var largeGraphLayout = new LgInteractor(geometryGraph, largeGraphLayoutSettings, cancelToken);
     largeGraphLayoutSettings.Interactor = largeGraphLayout;
     largeGraphLayout.Run();
 }
 internal NetworkSimplexForGeneralGraph(BasicGraph<Node, IntEdge> graph, CancelToken cancelObject) {
     this.graph = graph;
     this.Cancel = cancelObject;
 }
        void ProcessGraphUnderLock() {
            try {
                if (LayoutStarted != null)
                    LayoutStarted(null, null);

                CancelToken = new CancelToken();

                if (_drawingGraph == null) return;

                HideCanvas();
                ClearGraphViewer();
                CreateFrameworkElementsForLabelsOnly();
                if (NeedToCalculateLayout) {
                    _drawingGraph.CreateGeometryGraph(); //forcing the layout recalculation
                    if (_graphCanvas.Dispatcher.CheckAccess())
                        PopulateGeometryOfGeometryGraph();
                    else
                        _graphCanvas.Dispatcher.Invoke(PopulateGeometryOfGeometryGraph);
                }

                geometryGraphUnderLayout = _drawingGraph.GeometryGraph;
                if (RunLayoutAsync)
                    SetUpBackgrounWorkerAndRunAsync();
                else
                    RunLayoutInUIThread();
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
        }
        internal static void OrderLayers(ProperLayeredGraph graph,
                                         LayerArrays layerArrays,
                                         int startOfVirtualNodes,
                                         bool balanceVirtualAndOriginalNodes, 
                                         SugiyamaLayoutSettings settings, CancelToken cancelToken) {
            bool hasCrossWeight = false;
            foreach (LayerEdge le in graph.Edges)
                if (le.CrossingWeight != 1) {
                    hasCrossWeight = true;
                    break;
                }

            var o = new Ordering(graph, true, layerArrays, startOfVirtualNodes, balanceVirtualAndOriginalNodes, hasCrossWeight, settings);
            o.Run(cancelToken);
        }
		/// <summary>
		/// 
		/// </summary>
		public void IncrementalRun(CancelToken cancelToken, GeometryGraph graph, Func<Cluster, LayoutAlgorithmSettings> clusterSettings)
        {
            if (cancelToken != null)
            {
                cancelToken.ThrowIfCanceled();
            }
            SetupIncrementalRun(graph, clusterSettings);
            algorithm.Run(cancelToken);
            graph.UpdateBoundingBox();
        }
 internal static void PlaceLabels(GeometryGraph component, CancelToken cancelToken)
 {
     List<Label> labelList = component.Edges.SelectMany(e => e.Labels).ToList();
     var labelPlacer = new EdgeLabelPlacement(component, labelList);
     labelPlacer.Run(cancelToken);
 }
        void ProcessGraphUnderLock() {
            try {
                if (LayoutStarted != null)
                    LayoutStarted(null, null);

                CancelToken = new CancelToken();

                if (_drawingGraph == null) return;
                HideCanvas();
                Clear();
                /*  if (!LargeGraphBrowsing)
                      CreateFrameworkElementsForLabelsOnly(); */
                LayoutEditingEnabled = false;
                var lgsettings = new LgLayoutSettings(
                    GetCanvasRenderViewport,
                    () => Transform, DpiX, DpiY, () => ArrowheadLength) {
                        NeedToLayout = NeedToCalculateLayout,
                        MaxNumberOfNodesPerTile = DefaultLargeLayoutSettings.MaxNumberOfNodesPerTile,
                        MaxNumberOfRailsPerTile = DefaultLargeLayoutSettings.MaxNumberOfRailsPerTile,
                        RailColors = DefaultLargeLayoutSettings.RailColors,
                        SelectionColors = DefaultLargeLayoutSettings.SelectionColors,
                        IncreaseNodeQuota = DefaultLargeLayoutSettings.IncreaseNodeQuota,
                        ExitAfterInit = DefaultLargeLayoutSettings.ExitAfterInit,
                        SimplifyRoutes = DefaultLargeLayoutSettings.SimplifyRoutes,
                        NodeLabelHeightInInches = DefaultLargeLayoutSettings.NodeLabelHeightInInches,
                        ClientViewportMappedToGraph = ()=>GetVisibleRectangleInGraph()
                    };

                _drawingGraph.LayoutAlgorithmSettings = lgsettings;
                //lgsettings.ViewModel = ViewModel;
                lgsettings.ViewerChangeTransformAndInvalidateGraph +=
                    OGraphChanged;
                if (NeedToCalculateLayout)
                {
                    _drawingGraph.CreateGeometryGraph(); //forcing the layout recalculation
                    if (_graphCanvas.Dispatcher.CheckAccess())
                        PopulateGeometryOfGeometryGraph();
                    else
                        _graphCanvas.Dispatcher.Invoke(PopulateGeometryOfGeometryGraph);
                }
                else
                {
                    if (_graphCanvas.Dispatcher.CheckAccess())
                        SetLabelWidthToHeightRatiosOfGeometryGraph();
                    else
                        _graphCanvas.Dispatcher.Invoke(SetLabelWidthToHeightRatiosOfGeometryGraph);
                }

                geometryGraphUnderLayout = _drawingGraph.GeometryGraph;
                if (RunLayoutAsync)
                    SetUpBackgrounWorkerAndRunAsync();
                else
                    RunLayoutInUIThread();
            }
            catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
        }
        internal static LayeredLayoutEngine CalculateLayout(GeometryGraph msaglGraph, SugiyamaLayoutSettings settings, CancelToken cancelToken) {
            var engine = new LayeredLayoutEngine(msaglGraph, settings);
#if USE_PHYLOTREE
           PhyloTree phyloTree = msaglGraph as PhyloTree;
            if (phyloTree != null) {
                var pc=new PhyloTreeLayoutCalclulation(phyloTree, settings, engine.IntGraph, engine.Database);
                pc.Run();
            } else
#endif
                engine.Run(cancelToken);
            return engine;
        }
        void RouteGraphEdgesAsSplines() {
            var geomGraph = gViewer.Graph.GeometryGraph;
            var layoutSettings = gViewer.Graph.LayoutAlgorithmSettings;
            EdgeRoutingSettings routingSettings = layoutSettings.EdgeRoutingSettings;
            if (routingSettings.EdgeRoutingMode == EdgeRoutingMode.StraightLine)
                RouteStraightLines();
            else
                if (routingSettings.EdgeRoutingMode == EdgeRoutingMode.Spline) {
                    var coneAngle = routingSettings.ConeAngle;
                    var padding = layoutSettings.NodeSeparation * gViewer.TightOffsetForRouting * 2;
                    this.currentCancelToken = new CancelToken();
                    var router = new SplineRouter(geomGraph, padding, 0.65 * padding, coneAngle, null);
                    router.Run(this.currentCancelToken);
                } else if (routingSettings.EdgeRoutingMode == EdgeRoutingMode.SplineBundling) {
                    var coneAngle = routingSettings.ConeAngle;
                    var padding = layoutSettings.NodeSeparation / 3;
                    var loosePadding = SplineRouter.ComputeLooseSplinePadding(layoutSettings.NodeSeparation, padding);
                    if(layoutSettings.EdgeRoutingSettings.BundlingSettings==null)
                        layoutSettings.EdgeRoutingSettings.BundlingSettings=new BundlingSettings();
                    var br = new SplineRouter(geomGraph, padding, loosePadding, coneAngle, layoutSettings.EdgeRoutingSettings.BundlingSettings);
                    br.Run();
                } else {
                    MessageBox.Show(String.Format("Mode {0} is not supported with this settings",
                                                  routingSettings.EdgeRoutingMode));
                    return;
                }

            new EdgeLabelPlacement(geomGraph).Run();
           
            InvalidateEdges();
        }