Ejemplo n.º 1
0
 private KosmographViewerEdge CreateEdgeForLgCase(LgLayoutSettings lgSettings, DrawingEdge edge)
 {
     return((KosmographViewerEdge)(drawingObjectsToIViewerObjects[edge] = new KosmographViewerEdge(edge, lgSettings)
     {
         PathStrokeThicknessFunc = () => GetBorderPathThickness() * edge.Attr.LineWidth
     }));
 }
Ejemplo n.º 2
0
        private KosmographViewerEdge CreateEdge(DrawingEdge edge, LgLayoutSettings lgSettings)
        {
            lock (this.syncRoot)
            {
                if (drawingObjectsToIViewerObjects.ContainsKey(edge))
                {
                    return((KosmographViewerEdge)drawingObjectsToIViewerObjects[edge]);
                }
                if (lgSettings != null)
                {
                    return(CreateEdgeForLgCase(lgSettings, edge));
                }

                FrameworkElement labelTextBox;
                drawingObjectsToFrameworkElements.TryGetValue(edge, out labelTextBox);
                var vEdge = new KosmographViewerEdge(edge, labelTextBox);

                var zIndex = ZIndexOfEdge(edge);
                drawingObjectsToIViewerObjects[edge] = vEdge;

                if (edge.Label != null)
                {
                    SetVEdgeLabel(edge, vEdge, zIndex);
                }

                Panel.SetZIndex(vEdge.EdgePath, zIndex);
                GraphCanvas.Children.Add(vEdge.EdgePath);
                SetVEdgeArrowheads(vEdge, zIndex);

                return(vEdge);
            }
        }
 bool GetLgSettings(out LgLayoutSettings settings)
 {
     settings = null;
     if (_graphViewer == null)
     {
         return(false);
     }
     if (_graphViewer.Graph == null)
     {
         return(false);
     }
     if (_graphViewer.Graph.LayoutAlgorithmSettings == null)
     {
         return(false);
     }
     settings = _graphViewer.Graph.LayoutAlgorithmSettings as LgLayoutSettings;
     return(settings != null);
 }
 void PushDataFromLayoutGraphToFrameworkElements()
 {
     CreateBackgroundRectangleForEventCaptures();
     if (LargeGraphBrowsing)
     {
         LgLayoutSettings lgSettings = (LgLayoutSettings)drawingGraph.LayoutAlgorithmSettings;
         CreateBackgroundRectangle(lgSettings.OGraph);
         foreach (Node geomNode in lgSettings.OGraph.Nodes)
         {
             CreateNode((DrawingNode)geomNode.UserData);
         }
     }
     else
     {
         CreateBackgroundRectangle(drawingGraph.GeometryGraph);
         CreateNodes();
         CreateEdges();
     }
 }
        void ProcessGraph()
        {
            try {
                selectedObject = null;
                if (drawingGraph == null)
                {
                    return;
                }

                graphCanvas.Visibility = Visibility.Hidden; // hide canvas while we lay it out asynchronously.
                ClearGraphViewer();

                // Make nodes and edges

                if (LargeGraphBrowsing)
                {
                    LayoutEditingEnabled = false;
                    var lgsettings = new LgLayoutSettings(
                        () => new Rectangle(0, 0, graphCanvas.RenderSize.Width, graphCanvas.RenderSize.Height),
                        () => Transform, DpiX, DpiY, () => 0.1 * DpiX / CurrentScale /*0.1 inch*/);
                    drawingGraph.LayoutAlgorithmSettings = lgsettings;
                    lgsettings.ViewerChangeTransformAndInvalidateGraph += OGraphChanged;
                }
                if (NeedToCalculateLayout)
                {
                    drawingGraph.CreateGeometryGraph(); //forcing the layout recalculation
                    geometryGraphUnderLayout = drawingGraph.GeometryGraph;
                }

                PushGeometryIntoLayoutGraph();
                graphCanvas.RaiseEvent(new RoutedEventArgs(LayoutStartEvent));
                LayoutHelpers.CalculateLayout(geometryGraphUnderLayout, drawingGraph.LayoutAlgorithmSettings);

                TransferLayoutDataToWpf();
            }
            catch
            (Exception e) {
                MessageBox.Show(e.ToString());
            }
        }
Ejemplo n.º 6
0
        internal GraphmapsNode(Node node, LgNodeInfo lgNodeInfo, FrameworkElement frameworkElementOfNodeForLabelOfLabel,
                               Func <Edge, GraphmapsEdge> funcFromDrawingEdgeToVEdge, Func <double> pathStrokeThicknessFunc, LgLayoutSettings lgSettings)
        {
            this.lgSettings         = lgSettings;
            PathStrokeThicknessFunc = pathStrokeThicknessFunc;
            LgNodeInfo = lgNodeInfo;
            Node       = node;
            FrameworkElementOfNodeForLabel = frameworkElementOfNodeForLabelOfLabel;

            this.funcFromDrawingEdgeToVEdge = funcFromDrawingEdgeToVEdge;

            CreateNodeBoundaryPath();
            if (FrameworkElementOfNodeForLabel != null)
            {
                FrameworkElementOfNodeForLabel.Tag = this; //get a backpointer to the VNode
                Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center, 1);
                Panel.SetZIndex(FrameworkElementOfNodeForLabel, Panel.GetZIndex(BoundaryPath) + 1);
            }
            SetupSubgraphDrawing();
            Node.GeometryNode.BeforeLayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent;
            Node.Attr.VisualsChanged += (a, b) => Invalidate();
        }
 bool GetLgSettingsAndActiveLevel(out LgLayoutSettings settings, out int iLevel)
 {
     settings = _graphViewer.Graph.LayoutAlgorithmSettings as LgLayoutSettings;
     iLevel   = 0;
     return(settings != null && iLevel >= 0);
 }
Ejemplo n.º 8
0
        public static void MsaglShortcutShortEdges(Tiling g, Dictionary <int, Node> idToNodes,
                                                   LgLayoutSettings _lgLayoutSettings)
        {
            int unit = (int)_lgLayoutSettings.NodeSeparation;

            int shortcutcount = 1;
            int iteration     = 10;

            //Console.WriteLine();
            //Console.WriteLine("Minimize the number of railes for quick interaction? (Y/N)");
            //string input = Console.ReadLine();
            if (_lgLayoutSettings.hugeGraph)
            {
                iteration = 1;
                unit     *= 5;
            }

            while (shortcutcount > 0 && iteration > 0)
            {
                iteration--;
                //for all vertices that are not real vertices
                for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
                {
                    //current vertex is w
                    Vertex w = g.VList[index];

                    //for each neighbor of w
                    for (int k = 0; k < g.DegList[w.Id]; k++)
                    {
                        Vertex neighbor = g.VList[g.EList[w.Id, k].NodeId];

                        //if neighbor is a real vertex then continue
                        if (neighbor.Id < g.N)
                        {
                            continue;
                        }

                        //else check whether the edge is short
                        double l = g.GetEucledianDist(w.Id, neighbor.Id);

                        //if the length is short engough then short-cut
                        if (l < unit)
                        {
                            //shortcut this edge
                            //take all the neighbors of the 'neighbor' into the modification list
                            List <int> modificationList = new List <int>();
                            for (int j = 0; j < g.DegList[neighbor.Id]; j++)
                            {
                                int id = g.EList[neighbor.Id, j].NodeId;

                                if (id != w.Id)
                                {
                                    modificationList.Add(id);
                                }
                            }
                            //check whether it is safe to modify the graph
                            bool safetomodify = true;
                            if (g.DegList[w.Id] + modificationList.Count >= g.maxDeg)
                            {
                                continue;
                            }
                            foreach (var x in modificationList)
                            {
                                if (g.DegList[x] + 1 >= g.maxDeg)
                                {
                                    safetomodify = false;
                                }
                            }

                            foreach (var x in modificationList)
                            {
                                if (g.Crossings(w.Id, x))
                                {
                                    safetomodify = false;
                                }
                            }

                            if (!safetomodify)
                            {
                                continue;
                            }

                            //add edges between w and the neighbor's neighbor
                            foreach (var x in modificationList)
                            {
                                g.AddEdge(w.Id, x);
                            }

                            g.RemoveEdge(w.Id, neighbor.Id);
                            shortcutcount++;
                        }
                    }
                }
                unit *= 2;
            }
            Console.WriteLine("Shortcut made for " + shortcutcount + " edges");
        }
Ejemplo n.º 9
0
        public static void MsaglMoveToMedian(Tiling g, Dictionary <int, Node> idToNodes, LgLayoutSettings _lgLayoutSettings)
        {
            //foreach point first produce the crossing candidates.
            g.buildCrossingCandidates();


            //now proceess the movement
            int[,] listNeighbors = new int[20, 3];
            double[] d = new double[10];
            int      a = 0, b = 0;

            Core.Geometry.Point[] p    = new Core.Geometry.Point[10];
            bool localRefinementsFound = true;
            int  iteration             = 10;
            //int offset = iteration * 2;
            int unit = (int)_lgLayoutSettings.NodeSeparation / 2;

            if (_lgLayoutSettings.hugeGraph)
            {
                iteration = 3;
                unit      = (int)_lgLayoutSettings.NodeSeparation;
            }

            while (localRefinementsFound && iteration > 0)
            {
                iteration--;
                localRefinementsFound = false;


                for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
                {
                    Vertex w = g.VList[index];

                    int numNeighbors = 0;

                    for (int k = 0; k < g.DegList[w.Id]; k++)
                    {
                        numNeighbors++;
                        listNeighbors[numNeighbors, 1] = g.EList[w.Id, k].NodeId;
                        listNeighbors[numNeighbors, 2] = k;
                    }

                    if (numNeighbors <= 1)
                    {
                        continue;
                    }

                    for (int counter = 1; counter <= 9; counter++)
                    {
                        d[counter] = 0;

                        if (counter == 1)
                        {
                            a = unit; b = unit;
                        }
                        if (counter == 2)
                        {
                            a = 0; b = unit;
                        }
                        if (counter == 3)
                        {
                            a = -unit; b = unit;
                        }
                        if (counter == 4)
                        {
                            a = -unit; b = 0;
                        }
                        if (counter == 5)
                        {
                            a = -unit; b = -unit;
                        }
                        if (counter == 6)
                        {
                            a = 0; b = -unit;
                        }
                        if (counter == 7)
                        {
                            a = unit; b = -unit;
                        }
                        if (counter == 8)
                        {
                            a = unit; b = 0;
                        }
                        if (counter == 9)
                        {
                            a = 0; b = 0;
                        }


                        for (int k = 1; k <= numNeighbors; k++)
                        {
                            double length = Math.Sqrt((w.XLoc + a - g.VList[listNeighbors[k, 1]].XLoc) *
                                                      (w.XLoc + a - g.VList[listNeighbors[k, 1]].XLoc)
                                                      +
                                                      (w.YLoc + b - g.VList[listNeighbors[k, 1]].YLoc) *
                                                      (w.YLoc + b - g.VList[listNeighbors[k, 1]].YLoc)
                                                      );
                            if (length < 1)
                            {
                                length = 1000;
                            }

                            d[counter] += length;
                        }


                        p[counter] = new Core.Geometry.Point(a, b);
                    }
                    Array.Sort(d, p);

                    for (int counter = 1; counter <= 9; counter++)
                    {
                        var mincostA = (int)p[counter].X;
                        var mincostB = (int)p[counter].Y;

                        if (!(mincostA == 0 && mincostB == 0))
                        {
                            w.XLoc += mincostA;
                            w.YLoc += mincostB;
                            if (g.GetNodeExceptTheGivenNode(w, w.XLoc, w.YLoc, 5) >= 0 ||
                                g.MsaglGoodResolution(w, listNeighbors, numNeighbors, 5) == false ||
                                g.noCrossingsHeuristics(w, index) == false
                                )
                            {
                                w.XLoc -= mincostA;
                                w.YLoc -= mincostB;
                            }
                            else
                            {
                                //Console.Write(".");
                                localRefinementsFound = true;
                                break;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Done");
        }
Ejemplo n.º 10
0
 public VEdge(MEdge edge, LgLayoutSettings lgSettings)
 {
     Edge          = edge;
     EdgeAttrClone = edge.Attr.Clone();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VEdge"/> class.
 /// </summary>
 /// <param name="edge">Underlying edge.</param>
 /// <param name="layoutSettings">Layout settings.</param>
 public VEdge(Edge edge, LgLayoutSettings layoutSettings)
 {
     this.Edge          = edge;
     this.EdgeAttrClone = edge.Attr.Clone();
 }
Ejemplo n.º 12
0
 public GraphmapsEdge(Edge edge, LgLayoutSettings lgSettings)
 {
     Edge            = edge;
     EdgeAttrClone   = edge.Attr.Clone();
     this.lgSettings = lgSettings;
 }
Ejemplo n.º 13
0
 public KosmographViewerEdge(DrawingEdge edge, LgLayoutSettings lgSettings)
 {
     Edge = edge;
 }