Example #1
1
        static void ProcessLinks(Dictionary<DrawingObject, IViewerObjectX> vObjectsMapping, Graph g, Dictionary<string, Subgraph> subgraphTable, Microsoft.Msagl.Drawing.Graph drawingGraph)
        {
            foreach (GraphLink gl in g.Links) {
                var sourceId = gl.Source.Id.LiteralValue;
                var targetId = gl.Target.Id.LiteralValue;

                Subgraph sourceSubgraph;
                Node source = !subgraphTable.TryGetValue(sourceId, out sourceSubgraph) ? drawingGraph.FindNode(sourceId) : sourceSubgraph;

                Subgraph targetSubgraph;
                Node target = !subgraphTable.TryGetValue(targetId, out targetSubgraph) ? drawingGraph.FindNode(targetId) : targetSubgraph;

                foreach (GraphCategory gc in gl.Categories) {
                    string c = gc.ToString().Replace("CodeSchema_", "");
                    if (c == "Contains") {
                        if (targetSubgraph != null)
                            sourceSubgraph.AddSubgraph(targetSubgraph);
                        else
                            sourceSubgraph.AddNode(target);
                    } else {
                        Edge edge = new Edge(source, target, ConnectionToGraph.Connected);

                        edge.Label = new Label(c);
                        XEdge xEdge = new XEdge(edge, c);
                        vObjectsMapping[edge] = xEdge;
                    }
                }
            }
        }
        void CreateEdge(DrawingEdge edge)
        {
            if (drawingObjectsToIViewerObjects.ContainsKey(edge))
            {
                return;
            }

            XEdge xEdge;

            if (vObjectsMapping.ContainsKey(edge))
            {
                xEdge = (XEdge)vObjectsMapping[edge];
            }
            else
            {
                xEdge = new XEdge(edge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;


            if (edge.Source == edge.Target)
            {
                ((XNode)drawingObjectsToIViewerObjects[edge.SourceNode]).selfEdges.Add(xEdge);
            }
            else
            {
                ((XNode)drawingObjectsToIViewerObjects[edge.SourceNode]).outEdges.Add(xEdge);
                ((XNode)drawingObjectsToIViewerObjects[edge.TargetNode]).inEdges.Add(xEdge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;

            FrameworkElement _visuals = xEdge.VisualObject;

            if (_visuals != null)
            {
                graphObjectsToFrameworkElements[edge] = _visuals;
                if (_visuals.Parent == null)
                {
                    graphCanvas.Children.Add(_visuals);
                }
            }
            graphCanvas.Children.Add(xEdge.Path);
        }
        void CreateEdge(DrawingEdge edge)
        {
            if (drawingObjectsToIViewerObjects.ContainsKey(edge)) return;

            XEdge xEdge;
            if (vObjectsMapping.ContainsKey(edge))
            {
                xEdge = (XEdge)vObjectsMapping[edge];
            }
            else
            {
                xEdge = new XEdge(edge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;

            if (edge.Source == edge.Target)
                ((XNode) drawingObjectsToIViewerObjects[edge.SourceNode]).selfEdges.Add(xEdge);
            else {
                ((XNode) drawingObjectsToIViewerObjects[edge.SourceNode]).outEdges.Add(xEdge);
                ((XNode) drawingObjectsToIViewerObjects[edge.TargetNode]).inEdges.Add(xEdge);
            }
            drawingObjectsToIViewerObjects[edge] = xEdge;

            FrameworkElement _visuals = xEdge.VisualObject;
            if (_visuals != null)
            {
                graphObjectsToFrameworkElements[edge] = _visuals;
                if (_visuals.Parent == null)
                    graphCanvas.Children.Add(_visuals);
            }
            graphCanvas.Children.Add(xEdge.Path);
        }