internal static void DragEdge(Point delta, GeomEdge e, EdgeRestoreData edgeRestoreData,
                                      Set <GeometryObject> objectsMarkedToDrag)
        {
            Site site = null;

            if (objectsMarkedToDrag.Contains(e.Source))
            {
                if (!objectsMarkedToDrag.Contains(e.Target))
                {
                    site = e.UnderlyingPolyline.HeadSite;
                }
            }
            else
            {
                site = e.UnderlyingPolyline.LastSite;
            }

            if (site == null)
            {
                TranslateEdge(e, delta, edgeRestoreData);
            }
            else
            {
                DragEdgeWithSite(delta, e, site);
            }
        }
Example #2
0
        public static GeometryGraph CopyGraph(GeometryGraph graph)
        {
            if (graph == null) return null;
            var copy = new GeometryGraph();

            Dictionary<Node,Node> nodeCopy=new Dictionary<Node, Node>(graph.Nodes.Count);

            foreach (Node node in graph.Nodes) {
                var c = new Node();
                copy.Nodes.Add(c);
                nodeCopy[node] = c;
                c.BoundaryCurve = node.BoundaryCurve.Clone();
            }

            foreach (Edge edge in graph.Edges) {
                var source = edge.Source;
                var target = edge.Target;
                var copySource = nodeCopy[source];
                var copyTarget = nodeCopy[target];
                Edge edgeCopy=new Edge(copySource,copyTarget);
                copy.Edges.Add(edgeCopy);
                StraightLineEdges.RouteEdge(edgeCopy,0);
            }

            return copy;
        }
Example #3
0
        public static GeometryGraph CopyGraph(GeometryGraph graph)
        {
            if (graph == null)
            {
                return(null);
            }
            var copy = new GeometryGraph();

            Dictionary <Node, Node> nodeCopy = new Dictionary <Node, Node>(graph.Nodes.Count);

            foreach (Node node in graph.Nodes)
            {
                var c = new Node();
                copy.Nodes.Add(c);
                nodeCopy[node]  = c;
                c.BoundaryCurve = node.BoundaryCurve.Clone();
            }

            foreach (Edge edge in graph.Edges)
            {
                var  source     = edge.Source;
                var  target     = edge.Target;
                var  copySource = nodeCopy[source];
                var  copyTarget = nodeCopy[target];
                Edge edgeCopy   = new Edge(copySource, copyTarget);
                copy.Edges.Add(edgeCopy);
                StraightLineEdges.RouteEdge(edgeCopy, 0);
            }

            return(copy);
        }
        static Dictionary <GeomEdge, double> GetMiddleAnglesOfMultiedge(List <GeomEdge> multiedge, GeomNode node)
        {
            var      ret       = new Dictionary <GeomEdge, double>();
            GeomEdge firstEdge = multiedge[0];

            Point a = node.Center;
            Point b = Middle(firstEdge.Curve);

            ret[firstEdge] = 0;

            for (int i = 1; i < multiedge.Count; i++)
            {
                GeomEdge edge  = multiedge[i];
                Point    c     = Middle(edge.Curve);
                double   angle = Point.Angle(b, a, c);
                if (angle > Math.PI)
                {
                    angle = angle - Math.PI * 2;
                }

                ret[edge] = angle;
            }

            return(ret);
        }
        ///// <summary>
        ///// Creates a curve by using the underlying polyline
        ///// </summary>
        ///// <param name="underlyingPoly"></param>
        ///// <returns></returns>
        //        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline")]
        //        static public Curve CreateCurveFromEdgeUnderlyingPolyline(UnderlyingPolyline underlyingPoly) {
        //            Curve curve = new Curve();
        //            Site a = underlyingPoly.HeadSite;//the corner start
        //            Site b; //the corner origin
        //            Site c;//the corner other end

        //            while (SmoothedPolyline.FindCorner(a, out b, out c)) {
        //                CubicBezierSegment seg = SmoothedPolyline.CreateBezierSeg(b.bezierSegmentShrinkCoefficient, a, b, c);
        //                if (curve.Segments.Count == 0) {
        //                    if (!ApproximateComparer.Close(a.Point, seg.Start))
        //                        Curve.AddLineSeg(curve, a.Point, seg.Start);
        //                    } else if (!ApproximateComparer.Close(curve.End, seg.Start))
        //                    Routing.ContinueWithLineSeg(curve, seg.Start);
        //                curve.AddSegment(seg);
        //                a = b;
        //            }

        //            System.Diagnostics.Debug.Assert(a.Next.Next == null);

        //            if (curve.Segments.Count == 0) {
        //                if (!ApproximateComparer.Close(a.Point, a.Next.Point)) {
        //                    Curve.AddLineSeg(curve, a.Point, a.Next.Point);
        //                } else {
        //                    double w=5;
        //                    curve.Segments.Add(new CubicBezierSegment(a.Point, a.Point+new Point(w,w),a.Point+new Point(-w,w), b.Point));
        //                }
        //            } else if (!ApproximateComparer.Close(curve.End, a.Next.Point))
        //                Routing.ContinueWithLineSeg(curve, a.Next.Point);

        //            return curve;
        //        }

        static void TranslateEdge(GeomEdge e, Point delta, EdgeRestoreData edgeRestoreData)
        {
            if (edgeRestoreData.Curve != null)
            {
                e.Curve = edgeRestoreData.Curve.Clone();
                e.Curve.Translate(delta);
            }
            if (e.UnderlyingPolyline != null)
            {
                for (Site s = e.UnderlyingPolyline.HeadSite, s0 = edgeRestoreData.UnderlyingPolyline.HeadSite;
                     s != null;
                     s = s.Next, s0 = s0.Next)
                {
                    s.Point = s0.Point + delta;
                }
            }
            if (e.EdgeGeometry.SourceArrowhead != null)
            {
                e.EdgeGeometry.SourceArrowhead.TipPosition = edgeRestoreData.ArrowheadAtSourcePosition + delta;
            }
            if (e.EdgeGeometry.TargetArrowhead != null)
            {
                e.EdgeGeometry.TargetArrowhead.TipPosition = edgeRestoreData.ArrowheadAtTargetPosition + delta;
            }
            if (e.Label != null)
            {
                e.Label.Center = edgeRestoreData.LabelCenter + delta;
            }
        }
        static void CalculateMiddleOffsetsForMultiedge(List <GeomEdge> multiedge, GeomNode node,
                                                       Dictionary <GeomEdge, double> offsetsInsideOfMultiedge,
                                                       double nodeSeparation)
        {
            Dictionary <GeomEdge, double> middleAngles = GetMiddleAnglesOfMultiedge(multiedge, node);
            var angles = new double[middleAngles.Count];
            var edges  = new GeomEdge[middleAngles.Count];
            int i      = 0;

            foreach (var v in middleAngles)
            {
                angles[i] = v.Value;
                edges[i]  = v.Key;
                i++;
            }
            Array.Sort(angles, edges);

            double separation = nodeSeparation * 6;

            int    k    = edges.Length / 2;
            bool   even = k * 2 == edges.Length;
            double off;

            if (even)
            {
                off = -separation / 2;
                for (int j = k - 1; j >= 0; j--)
                {
                    GeomEdge edge = edges[j];
                    offsetsInsideOfMultiedge[edge] = off;
                    off -= separation + (edge.Label != null ? edge.Label.Width : 0);
                }

                off = separation / 2;
                for (int j = k; j < edges.Length; j++)
                {
                    GeomEdge edge = edges[j];
                    offsetsInsideOfMultiedge[edge] = off;
                    off += separation + (edge.Label != null ? edge.Label.Width : 0);
                }
            }
            else
            {
                off = 0;
                for (int j = k; j >= 0; j--)
                {
                    GeomEdge edge = edges[j];
                    offsetsInsideOfMultiedge[edge] = off;
                    off -= separation + (edge.Label != null ? edge.Label.Width : 0);
                }
                off = separation;
                for (int j = k + 1; j < edges.Length; j++)
                {
                    GeomEdge edge = edges[j];
                    offsetsInsideOfMultiedge[edge] = off;
                    off += separation + (edge.Label != null ? edge.Label.Width : 0);
                }
            }
        }
Example #7
0
        private void DrawEdge(Edge e, Pen pen, Graphics graphics) {
            graphics.DrawPath(pen, CreateGraphicsPath(e.Curve));

            if (e.EdgeGeometry != null && e.EdgeGeometry.SourceArrowhead != null)
                DrawArrow(e, pen, graphics, e.Curve.Start, e.EdgeGeometry.SourceArrowhead.TipPosition);
            if (e.EdgeGeometry != null && e.EdgeGeometry.TargetArrowhead != null)
                DrawArrow(e, pen, graphics, e.Curve.End, e.EdgeGeometry.TargetArrowhead.TipPosition);
        }
Example #8
0
        internal void CreateEdge()
        {
            if (Model == null)
            {
                return;
            }

            if (this.Source.Label == null || this.Target.Label == null)
            {
                return;
            }

            Dictionary <string, Entity> entitiesLookup = Model.DisplayedSubmodel.Entities.ToDictionary(x => x.Label, y => y);

            if ((entitiesLookup.ContainsKey(Source.Label) || entitiesLookup.ContainsKey(Target.Label)) == false)
            {
                return;
            }

            if (drawingEdge != null)
            {
                DeleteDrawingEdge(false);
            }

            if (Model.Graph != null)
            {
                drawingEdge       = Model.Graph.AddEdge(Source.Label, Target.Label);
                drawingEdge.Attr  = CreateEdgeAttr();
                drawingEdge.Label = CreateLabel(drawingEdge, Model.ShowRelationshipLabels ? Type : "");

                LayoutEdge coreEdge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
                CreateEdgeCurve(drawingEdge, coreEdge);

                Model.GeometryGraph.Edges.Add(coreEdge);
                drawingEdge.GeometryEdge = coreEdge;
                drawingEdge.UserData     = this;
            }
            else
            {
                if (IsAddedOnViewGraph)
                {
                    IsAddedOnViewGraph = false;
                    return;
                }

                DrawingNode source = Model.GraphEditor.Graph.FindNode(Source.Label);
                DrawingNode target = Model.GraphEditor.Graph.FindNode(Target.Label);

                if (target != null)
                {
                    drawingEdge = Model.GraphEditor.Viewer.AddEdge(source, target, false);

                    drawingEdge.Attr     = CreateEdgeAttr();
                    drawingEdge.UserData = this;
                }
                RenameEdge();
            }
        }
Example #9
0
        void ModifyEdgeByScale(Point delta, GeomEdge edge)
        {
            //StraightLineEdges.CreateSimpleEdgeCurveWithUnderlyingPolyline(edge);
            var sn = edge.Source.UserData as Drawing.Node;
            var tn = edge.Target.UserData as Drawing.Node;

            //var gg = graph.UserData as Graph;
            //var vsn = Viewer.GetIViewerObject(sn);
            //var vtn = Viewer.GetIViewerObject(tn);
            Drawing.Node oN = null, tN = null;
            if (Viewer.GetIViewerObject(sn).MarkedForDragging)
            {
                tN = sn;
                oN = tn;
            }
            else
            {
                tN = tn;
                oN = sn;
            }
            Point  o = oN.Pos, t = tN.Pos, t_ = t - delta;
            double scale = (t - o).Length / (t_ - o).Length;
            //double angle = Point.Angle(t, o, t_)*180/Math.PI;
            double angle = Point.Angle(t, o, t_);

            System.Windows.Media.Matrix mm = System.Windows.Media.Matrix.Identity;
            //mm.ScaleAt(scale, scale, o.X, o.Y);
            mm.RotateAt(angle, o.X, o.Y);
            //PlaneTransformation mt = new PlaneTransformation(mm.M11,mm.M12,mm.OffsetX,mm.M21,mm.M22,mm.OffsetY);
            var scaleMatrix       = new PlaneTransformation(scale, 0, 0, 0, scale, 0);
            var translateToOrigin = new PlaneTransformation(1, 0, -o.X, 0, 1, -o.Y);
            var translateToNode   = new PlaneTransformation(1, 0, o.X, 0, 1, o.Y);
            var rotateMatrix      = PlaneTransformation.Rotation(-angle);
            var matrix            = translateToNode * scaleMatrix * rotateMatrix * translateToOrigin;

            if (edge.UnderlyingPolyline != null)
            {
                var ul = edge.UnderlyingPolyline;
                if (tN == sn)
                {
                    ul.HeadSite.Point = t;
                }
                else
                {
                    ul.LastSite.Point = t;
                }
                for (Site s = ul.HeadSite.Next; s != ul.LastSite; s = s.Next)
                {
                    s.Point = matrix * s.Point;
                }
                edge.Curve = ul.CreateCurve();
                Arrowheads.TrimSplineAndCalculateArrowheads(edge, edge.Curve, true, false);
            }

            //edge.Curve = edge.Curve.Transform(matrix);

            //var angle= Point.Angle(graph.)
        }
        /// <summary>
        ///     preparing for an edge corner dragging
        /// </summary>
        /// <param name="geometryEdge"></param>
        /// <param name="site"></param>
        /// <returns></returns>
        public UndoRedoAction PrepareForEdgeCornerDragging(GeomEdge geometryEdge, Site site)
        {
            EditedEdge = geometryEdge;
            UndoRedoAction edgeDragUndoRedoAction = CreateEdgeEditUndoRedoAction();

//            var edgeRestoreDate = (EdgeRestoreData) edgeDragUndoRedoAction.GetRestoreData(geometryEdge);
//            edgeRestoreDate.Site = site;
            return(InsertToListAndSetTheBoxBefore(edgeDragUndoRedoAction));
        }
Example #11
0
        static Edge NewEdge(GeometryGraph g, int i, int j)
        {
            var e = new Edge(g.Nodes[i], g.Nodes[j])
            {
                LineWidth = 0.01
            };

            return(e);
        }
 /// <summary>
 ///     deletes the polyline corner
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="site"></param>
 /// <param name="userData">an object to be stored in the unde action</param>
 public void DeleteSite(GeomEdge edge, Site site, IViewerObject userData)
 {
     EditedEdge = edge;
     PrepareForPolylineCornerRemoval(userData, site);
     site.Previous.Next = site.Next; //removing the site from the list
     site.Next.Previous = site.Previous;
     //just to recalc everything in a correct way
     DragEdgeWithSite(new Point(0, 0), edge,
                      site.Previous);
 }
Example #13
0
        public void AddEdge(IViewerEdge edge, bool registerForUndo)
        {
            //if (registerForUndo) drawingLayoutEditor.RegisterEdgeAdditionForUndo(edge);

            var  drawingEdge = edge.Edge;
            Edge geomEdge    = drawingEdge.GeometryEdge;

            drawingGraph.AddPrecalculatedEdge(drawingEdge);
            drawingGraph.GeometryGraph.Edges.Add(geomEdge);
        }
 static void AddEdgesBetweenColumns(string[] col0, string[] col1, GeometryGraph graph)
 {
     foreach (var id in col0)
     {
         Edge edge = new Edge(graph.FindNodeByUserData(id), graph.FindNodeByUserData(col1[r.Next(col1.Length)]));
         edge.EdgeGeometry.TargetArrowhead = null;
         graph.Edges.Add(edge);
         edge = new Edge(graph.FindNodeByUserData(id), graph.FindNodeByUserData(col1[r.Next(col1.Length)]));
         graph.Edges.Add(edge);
     }
 }
        static void CreateCurveOnChangedPolyline(GeomEdge e)
        {
            Curve curve = e.UnderlyingPolyline.CreateCurve();

            if (
                !Arrowheads.TrimSplineAndCalculateArrowheads(e.EdgeGeometry, e.Source.BoundaryCurve,
                                                             e.Target.BoundaryCurve, curve, false, false))
            {
                Arrowheads.CreateBigEnoughSpline(e);
            }
        }
        /// <summary>
        ///     insert a polyline corner
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="point">the point to insert the corner</param>
        /// <param name="siteBeforeInsertion"></param>
        /// <param name="affectedEntity">an object to be stored in the undo action</param>
        public void InsertSite(GeomEdge edge, Point point, Site siteBeforeInsertion, IViewerObject affectedEntity)
        {
            EditedEdge = edge;
            //creating the new site
            Site first  = siteBeforeInsertion;
            Site second = first.Next;
            var  s      = new Site(first, point, second);

            PrepareForPolylineCornerInsertion(affectedEntity, s);

            //just to recalc everything in a correct way
            DragEdgeWithSite(new Point(0, 0), edge, s);
        }
        private void DrawEdge(Edge e, Pen pen, Graphics graphics)
        {
            graphics.DrawPath(pen, CreateGraphicsPath(e.Curve));

            if (e.EdgeGeometry != null && e.EdgeGeometry.SourceArrowhead != null)
            {
                DrawArrow(e, pen, graphics, e.Curve.Start, e.EdgeGeometry.SourceArrowhead.TipPosition);
            }
            if (e.EdgeGeometry != null && e.EdgeGeometry.TargetArrowhead != null)
            {
                DrawArrow(e, pen, graphics, e.Curve.End, e.EdgeGeometry.TargetArrowhead.TipPosition);
            }
        }
        /// <summary>
        ///     gets the enumerator pointing to the polyline corner before the point
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static Site GetPreviousSite(GeomEdge edge, Point point)
        {
            Site prevSite = edge.UnderlyingPolyline.HeadSite;
            Site nextSite = prevSite.Next;

            do
            {
                if (BetweenSites(prevSite, nextSite, point))
                {
                    return(prevSite);
                }
                prevSite = nextSite;
                nextSite = nextSite.Next;
            } while (nextSite != null);
            return(null);
        }
Example #19
0
        void CreateEdgeCurve(DrawingEdge de, LayoutEdge le)
        {
            var a = de.SourceNode.GeometryNode.Center;
            var b = de.TargetNode.GeometryNode.Center;

            Site start, end, mids;

            if (Source.Label == Target.Label)
            {
                start = new Site(a);
                end   = new Site(b);
                var mid1 = de.SourceNode.GeometryNode.Center;
                mid1.X += (de.SourceNode.GeometryNode.BoundingBox.Width / 3 * 2);
                var mid2 = mid1;
                mid1.Y -= de.SourceNode.GeometryNode.BoundingBox.Height / 2;
                mid2.Y += de.SourceNode.GeometryNode.BoundingBox.Height / 2;
                Site mid1s = new Site(mid1);
                Site mid2s = new Site(mid2);
                start.Next     = mid1s;
                mid1s.Previous = start;
                mid1s.Next     = mid2s;
                mid2s.Previous = mid1s;
                mid2s.Next     = end;
                end.Previous   = mid2s;
            }
            else
            {
                start         = new Site(a);
                end           = new Site(b);
                mids          = new Site(a * 0.5 + b * 0.5);
                start.Next    = mids;
                mids.Previous = start;
                mids.Next     = end;
                end.Previous  = mids;
            }

            SmoothedPolyline polyline = new SmoothedPolyline(start);

            le.UnderlyingPolyline = polyline;
            le.Curve = polyline.CreateCurve();

            if (Arrowheads.TrimSplineAndCalculateArrowheads(le, le.Curve, true, true) == false)
            {
                Arrowheads.CreateBigEnoughSpline(le);
            }
        }
 /// <summary>
 /// Verifies that the edge's label is near the edge.
 /// </summary>
 private static void VerifyLabelIsNearEdges(Edge edge)
 {
     Label label = edge.Label;
     if (label != null)
     {
         Rectangle labelBox = label.BoundingBox;
         Point[] edgePoints = edge.GetPoints();
         Point[] labelPoints = new[] { labelBox.Center, labelBox.LeftTop, labelBox.LeftBottom, labelBox.RightBottom, labelBox.RightTop };
         
         if (!edgePoints.Any(p => labelBox.Contains(p)))
         {
             // If the edge doesn't intersect the label, check that the label is at least nearby.
             // 10 was chosen as the distance tolerance since it is fairly small and passes on pretty much every diagram I tested.
             double closestDistance = GetClosestDistance(edgePoints, labelPoints);
             Assert.IsTrue(closestDistance < 10, "The label was placed greater than 10 units from the edge.");
         }
     }
 }
        private void DrawArrow(Edge e, Pen pen, Graphics graphics, P start, P end)
        {
            PointF[] points;
            float    arrowAngle = 30;

            P dir = end - start;
            P h   = dir;

            dir /= dir.Length;

            P s = new P(-dir.Y, dir.X);

            s *= h.Length * ((float)Math.Tan(arrowAngle * 0.5f * (Math.PI / 180.0)));

            points = new PointF[] { MsaglPointToDrawingPoint(start + s), MsaglPointToDrawingPoint(end), MsaglPointToDrawingPoint(start - s) };

            graphics.FillPolygon(pen.Brush, points);
        }
Example #22
0
        static void TestFD()
        {
            GeometryGraph graph = CreateGeometryGraphForFD();
            //LayoutAlgorithmSettings.ShowGraph(graph);
            var settings = new FastIncrementalLayoutSettings {
                AvoidOverlaps         = true,
                ApplyForces           = false,
                RungeKuttaIntegration = true
            };

            var ir = new InitialLayout(graph, settings);

            ir.Run();
            RouteEdges(graph, settings);
            //LayoutAlgorithmSettings.ShowGraph(graph);
            //  AddNodeFd(graph);

            var n = new Node(CurveFactory.CreateDiamond(200, 200, new Point(350, 230)));
            var e = new Edge(n, graph.Nodes[42]);

            graph.Edges.Add(e);
            e = new Edge(n, graph.Nodes[6]);
            graph.Edges.Add(e);
            e = new Edge(n, graph.Nodes[12]);
            graph.Edges.Add(e);

            graph.Nodes.Add(n);
            graph.RootCluster.AddChild(n);
            settings.algorithm = new FastIncrementalLayout(graph, settings, settings.MaxConstraintLevel, f => settings);
            settings.Unconverge();
            settings.CreateLock(n, new Rectangle(200, 400, 500, 100));
            do
            {
                settings.IncrementalRun(graph);
            } while (!settings.Converged);

            RouteEdges(graph, settings);
#if TEST_MSAGL
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
            Environment.Exit(0);
        }
        private static void AddEdge(Microsoft.Msagl.Drawing.Node a, Microsoft.Msagl.Drawing.Node b, Graph graph)
        {
            var de = new Microsoft.Msagl.Drawing.Edge(a, b, ConnectionToGraph.Connected);

            de.Attr.LineWidth = Math.Max(1, (int)(a.Width / 10));
            de.Attr.Color     = new Microsoft.Msagl.Drawing.Color(200, 100, 100, 100);
            var   ge    = new Edge(a.GeometryNode, b.GeometryNode);
            Point start = a.GeometryNode.Center;
            Point end   = b.GeometryNode.Center;
            Point d     = (end - start) / 4;
            Point b1    = start + d;
            Point b2    = b1 + d;
            Point b3    = b2 + d;

            ge.EdgeGeometry.Curve           = new CubicBezierSegment(start, b1, b2, b3);
            ge.EdgeGeometry.TargetArrowhead = new Arrowhead()
            {
                TipPosition = end
            };
            de.GeometryEdge = ge;
            ge.UserData     = de;
        }
        internal EdgeRestoreData(Edge edge) {
            if (edge.UnderlyingPolyline == null) {
                var asCurve = (edge.Curve as Curve) ?? new Curve(new List<ICurve> {edge.Curve});
                edge.UnderlyingPolyline =
                    SmoothedPolyline.FromPoints(
                        new[] {edge.Source.Center}.Concat(Polyline.PolylineFromCurve(asCurve)).
                            Concat(new[] {edge.Target.Center}));
            }
            UnderlyingPolyline = edge.UnderlyingPolyline.Clone();

            Curve = edge.Curve.Clone();
            if (edge.EdgeGeometry.SourceArrowhead != null)
                ArrowheadAtSourcePosition = edge.EdgeGeometry.SourceArrowhead.TipPosition;
            if (edge.EdgeGeometry.TargetArrowhead != null)
                ArrowheadAtTargetPosition = edge.EdgeGeometry.TargetArrowhead.TipPosition;
            if (edge.Label != null && edge.UnderlyingPolyline != null) {
                labelCenter = edge.Label.Center;
                Curve untrimmedCurve = edge.UnderlyingPolyline.CreateCurve();
                LabelAttachmentParameter = untrimmedCurve.ClosestParameter(labelCenter);
                LabelOffsetFromTheAttachmentPoint = labelCenter - untrimmedCurve[LabelAttachmentParameter];
            }
        }
Example #25
0
        IEnumerable <RectangleNode <object> > EdgeRectNodes(GeomEdge edge)
        {
            const int parts = 64; //divide each edge into 64 segments
            var       curve = edge.Curve;
            double    delta = (curve.ParEnd - curve.ParStart) / parts;
            Point     p0    = curve.Start;

            for (int i = 1; i <= parts; i++)
            {
                yield return(new RectangleNode <object>(edge, new Rectangle(p0, p0 = curve[curve.ParStart + i * delta])));
            }

            if (edge.ArrowheadAtSource)
            {
                yield return(new RectangleNode <object>(edge, new Rectangle(edge.EdgeGeometry.SourceArrowhead.TipPosition, curve.Start)));
            }

            if (edge.ArrowheadAtTarget)
            {
                yield return(new RectangleNode <object>(edge, new Rectangle(edge.EdgeGeometry.TargetArrowhead.TipPosition, curve.End)));
            }
        }
Example #26
0
        private string DotGeomString(Microsoft.Msagl.Core.Layout.Edge geometryEdge)
        {
            var edgeGeom = geometryEdge.EdgeGeometry;

            if (edgeGeom == null)
            {
                return("");
            }

            CubicBezierSegment b = edgeGeom.Curve as CubicBezierSegment;

            if (b == null)
            {
                return("");
            }

            string ret = "";

            if (edgeGeom.SourceArrowhead != null)
            {
                ret += string.Format("s,{0},{1} ", edgeGeom.SourceArrowhead.TipPosition.X, edgeGeom.SourceArrowhead.TipPosition.Y);
            }

            if (edgeGeom.TargetArrowhead != null)
            {
                ret += string.Format("e,{0},{1} ", edgeGeom.TargetArrowhead.TipPosition.X, edgeGeom.TargetArrowhead.TipPosition.Y);
            }

            for (int i = 0; i < 4; i++)
            {
                ret += string.Format("{0},{1} ", b.B(i).X, b.B(i).Y);
            }


            return("pos=" + Utils.Quote(ret));
        }
Example #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="drawingEdge"></param>
        /// <returns></returns>
        public static Microsoft.Msagl.Core.Layout.Edge CreateGeometryEdgeFromDrawingEdge(Edge drawingEdge)
        {
            var sourceNode = drawingEdge.SourceNode.GeometryNode;
            var targetNode = drawingEdge.TargetNode.GeometryNode;
            var msaglEdge  = new Microsoft.Msagl.Core.Layout.Edge(sourceNode, targetNode);

            drawingEdge.GeometryEdge = msaglEdge;
            msaglEdge.SourcePort     = drawingEdge.SourcePort;
            msaglEdge.TargetPort     = drawingEdge.TargetPort;

            if (drawingEdge.Label != null)
            {
                // && graph.LayoutAlgorithmSettings is SugiyamaLayoutSettings &&
                //                   graph.LayoutAlgorithmSettings.routingMode == false){
                msaglEdge.Label = drawingEdge.Label.GeometryLabel;
                msaglEdge.Label.GeometryParent = msaglEdge;
            }
            msaglEdge.Weight     = drawingEdge.Attr.Weight;
            msaglEdge.Length     = drawingEdge.Attr.Length;
            msaglEdge.Separation = drawingEdge.Attr.Separation;
            if (drawingEdge.Attr.ArrowAtSource)
            {
                msaglEdge.EdgeGeometry.SourceArrowhead = new Arrowhead {
                    Length = drawingEdge.Attr.ArrowheadLength
                };
            }
            if (drawingEdge.Attr.ArrowAtTarget)
            {
                msaglEdge.EdgeGeometry.TargetArrowhead = new Arrowhead {
                    Length = drawingEdge.Attr.ArrowheadLength
                };
            }
            msaglEdge.UserData  = drawingEdge;
            msaglEdge.LineWidth = drawingEdge.Attr.LineWidth;
            return(msaglEdge);
        }
 static void FixPortAtTarget(Shape shape, Port port, Edge e) {
     if (e.TargetPort == null)
         e.TargetPort = port;
     else 
         shape.Ports.Insert(e.TargetPort);
 }
 /// <summary>
 ///     deletes the polyline corner
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="site"></param>
 /// <param name="userData">an object to be stored in the unde action</param>
 public void DeleteSite(GeomEdge edge, Site site, IViewerObject userData) {
     EditedEdge = edge;
     PrepareForPolylineCornerRemoval(userData, site);
     site.Previous.Next = site.Next; //removing the site from the list
     site.Next.Previous = site.Previous;
     //just to recalc everything in a correct way
     DragEdgeWithSite(new Point(0, 0), edge,
         site.Previous);
 }
Example #30
0
 static void foo(Edge p0) {
     p0.Weight *= 2;
     p0.LineWidth *= 2;
     p0.Weight *= 2;
     p0.LineWidth *= 2;
     p0.Weight *= 2;
     p0.LineWidth *= 2;
     p0.Weight *= 2;
     if (p0.EdgeGeometry != null)
         p0.EdgeGeometry.LineWidth /= 2;
     p0.LineWidth *= 2;
 }
Example #31
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="editedEdgePar"></param>
 public EdgeDragUndoRedoAction(GeomEdge editedEdgePar) : base((GeometryGraph)editedEdgePar.GeometryParent)
 {
     editedEdge = editedEdgePar;
 }
 /// <summary>
 /// </summary>
 /// <param name="delta">delta of the drag</param>
 /// <param name="e">the modified edge</param>
 /// <param name="site"></param>
 internal static void DragEdgeWithSite(Point delta, GeomEdge e, Site site)
 {
     e.RaiseLayoutChangeEvent(delta);
     site.Point += delta;
     CreateCurveOnChangedPolyline(e);
 }
Example #33
0
        static IEnumerable<Edge> CreateEdgesForGroupRouting(IEnumerable<Cluster> clusters) {
            var c = GetClusterById(clusters, "c");
            var f = GetClusterById(clusters, "f");
            var a = c.Clusters.Single(s => s.UserData.Equals("a"));
            var b = c.Clusters.Single(s => s.UserData.Equals("b"));
            var d = f.Clusters.Single(s => s.UserData.Equals("d"));
            var e = f.Clusters.Single(s => s.UserData.Equals("e"));
            var h = GetClusterById(clusters, "h");
            var g = GetClusterById(clusters, "g");
            var l = GetClusterById(clusters, "l");
            var k = GetClusterById(clusters, "k");
            var ports = new Dictionary<Cluster, Set<Port>>();
            AddPortToShape(k, ports, new CurvePort(k.BoundaryCurve, 0.4*(k.BoundaryCurve.ParEnd + k.BoundaryCurve.ParStart)));
            AddPortToShape(l, ports);
            AddPortToShape(a, ports);
            AddPortToShape(b, ports);
            AddPortToShape(d, ports);
            AddPortToShape(e, ports);
            AddPortToShape(h, ports);
            AddPortToShape(g, ports);
            var hSecondPort = new CurvePort(h.BoundaryCurve, 0.1);

            ports[h].Insert(hSecondPort);
            var hFreePort = new FloatingPort(null, new Point(-129, -55));
            var kFreePort = new FloatingPort(null, new Point(137, -51));
            ports[h].Insert(hFreePort);
            ports[k].Insert(kFreePort);

            var fFreePort = new FloatingPort(null, new Point(3, 3));
            var kFreePort0 = new FloatingPort(null, new Point(106, 8));
            AddPortToShape(f,ports, fFreePort);
            AddPortToShape(k, ports, kFreePort0);

            AddPortToShape(c,ports,new CurvePort(c.BoundaryCurve, 0));
            AddPortToShape(f, ports,new FloatingPort(f.BoundaryCurve, f.BoundingBox.Center));
            var freePort0 = new FloatingPort(null, new Point(72, -1.3));

            var halfFreeEdge = new EdgeGeometry(freePort0, ports[a].First());
            var freePort1 = new FloatingPort(null, new Point(-122, 110));
            var freeEdge = new EdgeGeometry(freePort0, freePort1);
            var ab = new EdgeGeometry(ports[a].First(), ports[b].First());
            var abE = new Edge(a, b) {EdgeGeometry = ab};
            var ae = new EdgeGeometry(ports[a].First(), ports[e].First());
            var aeE = new Edge(a, e) {EdgeGeometry = ae};
            var de = new EdgeGeometry(ports[d].First(), ports[e].First());
            var deE = new Edge(d, e) {EdgeGeometry = de};
            var ad = new EdgeGeometry(ports[a].First(), ports[d].First());
            var adE = new Edge(a, d) {EdgeGeometry = ad};
            var he = new EdgeGeometry(ports[h].First(), ports[e].First());
            var heE = new Edge(h, e) {EdgeGeometry = he};
            var gd = new EdgeGeometry(ports[g].First(), ports[d].First());
            var gdE = new Edge(g, d) {EdgeGeometry = gd};
            var lg = new EdgeGeometry(ports[l].First(), ports[g].First());
            var lgE = new Edge(l, g) {EdgeGeometry = lg};
            var le = new EdgeGeometry(ports[l].First(), ports[e].First());
            var leE = new Edge(l, e) {EdgeGeometry = le};
            var ca = new EdgeGeometry(ports[c].First(), ports[a].First());
            var caE = new Edge(c, a) {EdgeGeometry = ca};
            var cd = new EdgeGeometry(ports[c].First(), ports[d].First());
            var cdE = new Edge(c, d) {EdgeGeometry = cd};
            var hl = new EdgeGeometry(hSecondPort, ports[l].First());
            var hlE = new Edge(h, l) {EdgeGeometry = hl};
            var lh = new EdgeGeometry(ports[l].First(), hSecondPort);
            var lhE = new Edge(l, h) {EdgeGeometry = lh};
            var ha = new EdgeGeometry(hSecondPort, ports[a].First());
            var haE = new Edge(h, a) {EdgeGeometry = ha};
            var hk = new EdgeGeometry(hSecondPort, ports[k].First());
            var hkE = new Edge(h, k) {EdgeGeometry = hk};

            var hk0 = new EdgeGeometry(hFreePort, kFreePort);
            var hk0E = new Edge(h, k) {EdgeGeometry = hk0};

            var fk = new EdgeGeometry(fFreePort, kFreePort0);
            var fkE = new Edge(f, k) {EdgeGeometry = fk};

            var hThirdPort = new CurvePort(h.BoundaryCurve, 0.5);
            var halfFreeInside = new EdgeGeometry(ports[b].First(), freePort1);
            //var halfFreeInside = new Edge(b, d) { EdgeGeometry = ad };

            ports[h].Insert(hThirdPort);
            var lSecondPort = new CurvePort(l.BoundaryCurve, 0);
            ports[l].Insert(lSecondPort);
            var hThirdLSecond = new EdgeGeometry(hThirdPort, lSecondPort);
            var hThirdLSecondE = new Edge(h, l) {EdgeGeometry = hThirdLSecond};
            //            return new[] {
            //                             /*halfFreeInside, freeEdge,*/ halfFreeEdge, lh
            //                         };
            return new[] {
                             lhE, abE, aeE, deE, adE, heE, gdE, lgE, leE, cdE, hlE,
                             hThirdLSecondE, caE, haE, hkE, hk0E, fkE
                         };
        }
 /// <summary>
 /// Removes an in-edge from the node's edge list (this won't remove the edge from the graph).
 /// </summary>
 /// <param name="edge">The edge to be removed</param>
 public void RemoveInEdge(Edge edge)
 {
     inEdges.Remove(edge);
 }
        internal static ICurve CreateBaseSegmentForDraggingEdgeWithSource(Point delta, GeomEdge edge,
                                                                          EdgeRestoreData edgeRestoreData,
                                                                          Dictionary <GeomEdge, double> offsets)
        {
            double offset;
            ICurve seg;
            Point  a = edgeRestoreData.UnderlyingPolyline.HeadSite.Point + delta;
            Point  b = edgeRestoreData.UnderlyingPolyline.LastSite.Point;

            if (offsets.TryGetValue(edge, out offset) && offset != 0)
            {
                Point ab      = b - a;
                Point abOrtog = ab.Normalize().Rotate(Math.PI / 2) * offset;
                seg = CreateBaseSegOnSourceTargetAndOrth(ref a, ref b, ref abOrtog);
                //        SugiyamaLayoutSettings.Show(seg, edge.Curve, edge.Source.BoundaryCurve);
            }
            else
            {
                seg = new LineSegment(a, b);
            }

            return(seg);
        }
 /// <summary>
 /// Removes an out-edge from the node's edge list (this won't remove the edge from the graph).
 /// </summary>
 /// <param name="edge">The edge to be removed</param>
 public void RemoveOutEdge(Edge edge)
 {
     outEdges.Remove(edge);
 }
 private static void InsertEdgePortsToShapes(Dictionary<Node, Shape> nodesToShapes, Edge edge) {
     nodesToShapes[edge.Target].Ports.Insert(edge.TargetPort);
     nodesToShapes[edge.Source].Ports.Insert(edge.SourcePort);
 }
Example #38
0
        public DEdge AddEdgeBetweenNodes(DNode source, DNode target)
        {
            if (!IsContainedSub(source))
                throw new InvalidOperationException("The edge source node must be in the graph or in one of its nested graphs.");
            if (!IsContainedSub(target))
                throw new InvalidOperationException("The edge target node must be in the graph or in one of its nested graphs.");
            if (source.ParentGraph == this && target.ParentGraph == this)
            {
                DEdge dEdge = new DEdge(source, target, new DrawingEdge(source.Node, target.Node, ConnectionToGraph.Disconnected), ConnectionToGraph.Disconnected);
                GeometryEdge gEdge = new GeometryEdge(source.GeometryNode, target.GeometryNode) { GeometryParent = Graph.GeometryGraph };
                dEdge.GeometryEdge = gEdge;
                dEdge.ArrowheadAtTarget = ArrowStyle.Normal;

                AddEdge(dEdge, false);

                return dEdge;
            }
            else
                return AddCrossEdge(source, target);
        }
 /// <summary>
 /// Removes a self-edge from the node's edge list (this won't remove the edge from the graph).
 /// </summary>
 /// <param name="edge">The edge to be removed</param>
 public void RemoveSelfEdge(Edge edge)
 {
     selfEdges.Remove(edge);
 }
 public FiEdge(Edge mEdge) {
     this.mEdge = mEdge;
     source = (FiNode) mEdge.Source.AlgorithmData;
     target = (FiNode) mEdge.Target.AlgorithmData;
 }
Example #41
0
        public void RouteSelectedEdges(int separation)
        {
            double nodeSeparation = Graph.LayoutAlgorithmSettings.NodeSeparation;
            double nodePadding = nodeSeparation / 3;
            double loosePadding = SplineRouter.ComputeLooseSplinePadding(nodeSeparation, nodePadding);
            BundlingSettings bundlingSettings = new BundlingSettings() { EdgeSeparation = separation, CreateUnderlyingPolyline = true };
            EdgeRoutingSettings settings = new EdgeRoutingSettings() { BundlingSettings = bundlingSettings, EdgeRoutingMode = EdgeRoutingMode };
            if (settings.EdgeRoutingMode == EdgeRoutingMode.SugiyamaSplines)
                settings.EdgeRoutingMode = EdgeRoutingMode.Spline;

            if (Nodes().Any(n => n.MarkedForDragging))
            {
                Dictionary<DNode, GeometryNode> nodesThisToAux = new Dictionary<DNode, GeometryNode>();
                Dictionary<DEdge, GeometryEdge> edgesThisToAux = new Dictionary<DEdge, GeometryEdge>();
                GeometryGraph ggAux = new GeometryGraph();
                foreach (DNode node in Nodes())
                {
                    var n = new GeometryNode()
                    {
                        BoundaryCurve = node.GeometryNode.BoundaryCurve,
                        GeometryParent = ggAux,
                        Padding = node.GeometryNode.Padding,
                    };
                    ggAux.Nodes.Add(n);
                    nodesThisToAux[node] = n;
                }

                foreach (DNode node in Nodes().Where(n => n.MarkedForDragging))
                {
                    foreach (DEdge edge in node.Edges)
                    {
                        if (!edgesThisToAux.ContainsKey(edge))
                        {
                            var e = new GeometryEdge(nodesThisToAux[edge.Source], nodesThisToAux[edge.Target]);
                            if (edge.Source == edge.Target)
                                nodesThisToAux[edge.Source].AddSelfEdge(e);
                            else
                            {
                                nodesThisToAux[edge.Source].AddOutEdge(e);
                                nodesThisToAux[edge.Target].AddInEdge(e);
                            }
                            ggAux.Edges.Add(e);
                            edgesThisToAux[edge] = e;
                        }
                    }

                    /*ggAux.Nodes.Add(node.GeometryNode);
                    if (node.MarkedForDragging)
                    {
                        foreach (DEdge edge in node.Edges)
                        {
                            if (!ggAux.Nodes.Contains(edge.Source.GeometryNode))
                                ggAux.Nodes.Add(edge.Source.GeometryNode);
                            if (!ggAux.Nodes.Contains(edge.Target.GeometryNode))
                                ggAux.Nodes.Add(edge.Target.GeometryNode);
                            if (!ggAux.Edges.Contains(edge.GeometryEdge))
                                ggAux.Edges.Add(edge.GeometryEdge);
                        }
                    }*/
                }

                DoEdgeRouting(ggAux, settings, nodeSeparation);

                //BundledEdgeRouter.RouteEdgesInMetroMapStyle(ggAux, Math.PI / 6.0, nodePadding, loosePadding, settings);
                /*var router = new SplineRouter(ggAux, settings);
                router.Run(CancelToken);
                VerifyPolylines();*/
                foreach (var kv in edgesThisToAux)
                    kv.Key.GeometryEdge.EdgeGeometry = kv.Value.EdgeGeometry;
            }
            else
            {
                DoEdgeRouting(Graph.GeometryGraph, settings, nodeSeparation);
                //BundledEdgeRouter.RouteEdgesInMetroMapStyle(Graph.GeometryGraph, Math.PI / 6.0, nodePadding, loosePadding, settings);
                /*var router = new SplineRouter(Graph.GeometryGraph, settings);
                router.Run(CancelToken);
                VerifyPolylines();*/
            }

            //Invalidate();
        }
 public void AddSelfEdge(Edge e){
     selfEdges.Insert(e);
 }
 static void DragEdgeAsStraightLine(Point delta, GeomEdge edge)
 {
     StraightLineEdges.CreateSimpleEdgeCurveWithUnderlyingPolyline(edge);
 }
 public void AddOutEdge(Edge e){
     outEdges.Insert(e);
 }
Example #45
0
 static Edge NewEdge(GeometryGraph g, int i, int j) {
     var e= new Edge(g.Nodes[i],g.Nodes[j]) {LineWidth = 0.01};
     return e;
 }
 /// <summary>
 /// Constructor. At the moment of the constructor call the site should not be inserted yet
 /// </summary>
 /// <param name="edgeToEdit"></param>
 public SiteInsertUndoAction(GeomEdge edgeToEdit)
     : base((GeometryGraph)edgeToEdit.GeometryParent) {
     this.editedEdge = edgeToEdit;
     this.AddRestoreData(editedEdge, RestoreHelper.GetRestoreData(editedEdge));
 }
Example #47
0
        static void TestFD() {
            GeometryGraph graph = CreateGeometryGraphForFD();
            //LayoutAlgorithmSettings.ShowGraph(graph);
            var settings = new FastIncrementalLayoutSettings {
                                                                 AvoidOverlaps = true,
                                                                 ApplyForces = false,
                                                                 RungeKuttaIntegration = true
                                                             };

            var ir = new InitialLayout(graph, settings);
            ir.Run();
            RouteEdges(graph, settings);
            //LayoutAlgorithmSettings.ShowGraph(graph);
          //  AddNodeFd(graph);

            var n = new Node(CurveFactory.CreateDiamond(200, 200, new Point(350, 230)));
            var e = new Edge(n, graph.Nodes[42]);
            graph.Edges.Add(e);
            e = new Edge(n, graph.Nodes[6]);
            graph.Edges.Add(e);
            e = new Edge(n, graph.Nodes[12]);
            graph.Edges.Add(e);

            graph.Nodes.Add(n);
            graph.RootCluster.AddChild(n);
            settings.algorithm=new FastIncrementalLayout(graph, settings, settings.MaxConstraintLevel, f=>settings);
            settings.Unconverge();
            settings.CreateLock(n, new Rectangle(200, 400, 500, 100));
            do {
                settings.IncrementalRun(graph);
            } while (!settings.Converged);

            RouteEdges(graph, settings);
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif
            Environment.Exit(0);
        }
Example #48
0
 /// <summary>
 /// Constructor. At the moment of the constructor call the site should not be inserted yet
 /// </summary>
 /// <param name="edgePar"></param>
 public SiteRemoveUndoAction(GeomEdge edgePar)
     : base((GeometryGraph)edgePar.GeometryParent)
 {
     this.editedEdge = edgePar;
     this.AddRestoreData(editedEdge, RestoreHelper.GetRestoreData(editedEdge));
 }
Example #49
0
                public static void TreeWithConstraints() {
            var graph = new GeometryGraph();

            var closed = new Node(CreateEllipse(), "clos");
            var line = new Node(CreateEllipse(), "line");
            var bezier = new Node(CreateEllipse(), "bezi");
            var arc = new Node(CreateEllipse(), "arc");
            var rectangle = new Node(CreateEllipse(), "rect");
            var ellipse = new Node(CreateEllipse(), "elli");
            var polygon = new Node(CreateEllipse(), "poly");
            var shapes = new Node(CreateEllipse(), "shap");
            var open = new Node(CreateEllipse(), "open");
            graph.Nodes.Add(closed);
            graph.Nodes.Add(line);
            graph.Nodes.Add(bezier);
            graph.Nodes.Add(arc);
            graph.Nodes.Add(rectangle);
            graph.Nodes.Add(ellipse);
            graph.Nodes.Add(polygon);
            graph.Nodes.Add(shapes);
            graph.Nodes.Add(open);

            var so = new Edge(shapes, open);
            var sc = new Edge(shapes, closed);
            var ol = new Edge(open, line);
            var ob = new Edge(open, bezier);
            var oa = new Edge(open, arc);
            var cr = new Edge(closed, rectangle);
            var ce = new Edge(closed, ellipse);
            var cp = new Edge(closed, polygon);
            graph.Edges.Add(so);
            graph.Edges.Add(sc);
            graph.Edges.Add(ol);
            graph.Edges.Add(ob);
            graph.Edges.Add(oa);
            graph.Edges.Add(cr);
            graph.Edges.Add(ce);
            graph.Edges.Add(cp);

            var settings = new SugiyamaLayoutSettings();
            settings.AddUpDownVerticalConstraint(closed, ellipse);
            settings.AddUpDownVerticalConstraint(open, bezier);
            settings.AddUpDownConstraint(closed, open);
            settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);

            settings.AddUpDownConstraint(closed, open);
            //settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);

            //To verify 444585, just turn on this following commented line
            settings.AddLeftRightConstraint(ellipse, rectangle);
            settings.AddLeftRightConstraint(ellipse, bezier);

            var layeredLayout = new LayeredLayout(graph, settings);
            layeredLayout.Run();
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif

            Debug.Assert(Math.Abs(closed.Center.X - ellipse.Center.X) < 0.01);
            Debug.Assert(Math.Abs(open.Center.X - bezier.Center.X) < 0.01);

            foreach (Node n0 in graph.Nodes) {
                foreach (Node n1 in graph.Nodes) {
                    if (n0 == n1) {
                        continue;
                    }
                    Debug.Assert(!n0.BoundingBox.Intersects(n1.BoundingBox));
                }
            }

            ValidateUpDownVerticalConstraint(closed, ellipse);
            ValidateUpDownVerticalConstraint(open, bezier);
            ValidateUpDownConstraint(closed, open);
            ValidateNeighborConstraint(graph, polygon, open);
            ValidateLeftRightConstraint(closed, open);

            //To verify 444585, also turn on this following commented line
            ValidateLeftRightConstraint(ellipse, rectangle);
            ValidateLeftRightConstraint(ellipse, bezier);
        }
 public void AddInEdge(Edge e){
     inEdges.Insert(e);
 }
Example #51
0
        static void TestConstraints() {
            var gg = new GeometryGraph();

            var node1 = new Node {GeometryParent = gg};
            node1.BoundaryCurve =CurveFactory.CreateEllipse(20.0,10.0,new Point(0.0, 0.0));
            gg.Nodes.Add(node1);

            var node2 = new Node {GeometryParent = gg};
            node2.BoundaryCurve =
                CurveFactory.CreateEllipse(20.0,10.0,new Point(0.0, 0.0));
            gg.Nodes.Add(node2);

            var edge = new Edge(node1,node2) {GeometryParent = gg};
            gg.Edges.Add(edge);
            edge.Label = new Label {GeometryParent = edge,
                //need to set the label dimensions, otherwise the assertion is thrown
                Width = 10, Height = 10
            };
            //node1.AddOutEdge(edge); //the edges have been already added to the nodes in gg.Edges.Add(edge)
            //node2.AddInEdge(edge);

            var settings = new SugiyamaLayoutSettings();
            settings.AddSameLayerNeighbors(node1, node2);
            var layoutAlgorithm = new
                LayeredLayout(gg, settings);
            layoutAlgorithm.Run();
#if TEST_MSAGL
            LayoutAlgorithmSettings.ShowGraph(gg);
#endif
            Environment.Exit(0);
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="editedEdgePar"></param>
 public EdgeDragUndoRedoAction(GeomEdge editedEdgePar):base((GeometryGraph)editedEdgePar.GeometryParent) {
     editedEdge = editedEdgePar;         
 }
 static void FixPortAtSource(Shape shape, Port port, Edge e) {
     if (e.SourcePort == null)
         e.SourcePort = port;
     else
         shape.Ports.Insert(e.SourcePort);
 }
Example #54
0
        static void TestGraphWithConstraints() {
            var graph = new GeometryGraph();

            var closed = new Node(CreateEllipse(), "closed");
            var line = new Node(CreateEllipse(), "line");
            var bezier = new Node(CreateEllipse(), "bezier");
            var arc = new Node(CreateEllipse(), "arc");
            var rectangle = new Node(CreateEllipse(), "rectangle");
            var ellipse = new Node(CreateEllipse(), "ellipse");
            var polygon = new Node(CreateEllipse(), "polygon");
            var shapes = new Node(CreateEllipse(), "shapes");
            var open = new Node(CreateEllipse(), "open");
            graph.Nodes.Add(closed);
            graph.Nodes.Add(line);
            graph.Nodes.Add(bezier);
            graph.Nodes.Add(arc);
            graph.Nodes.Add(rectangle);
            graph.Nodes.Add(ellipse);
            graph.Nodes.Add(polygon);
            graph.Nodes.Add(shapes);
            graph.Nodes.Add(open);

            var so = new Edge(shapes, open);
            var sc = new Edge(shapes, closed);
            var ol = new Edge(open, line);
            var ob = new Edge(open, bezier);
            var oa = new Edge(open, arc);
            var cr = new Edge(closed, rectangle);
            var ce = new Edge(closed, ellipse);
            var cp = new Edge(closed, polygon);
            graph.Edges.Add(so);
            graph.Edges.Add(sc);
            graph.Edges.Add(ol);
            graph.Edges.Add(ob);
            graph.Edges.Add(oa);
            graph.Edges.Add(cr);
            graph.Edges.Add(ce);
            graph.Edges.Add(cp);

            var settings = new SugiyamaLayoutSettings();
            settings.AddUpDownVerticalConstraint(closed, ellipse);
            settings.AddUpDownVerticalConstraint(open, bezier);
            settings.AddUpDownConstraint(closed, open);
            settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);
            settings.AddLeftRightConstraint(open, closed);

            ////To verify 444585, just turn on this following commented line
            settings.AddLeftRightConstraint(ellipse, rectangle);
            settings.AddLeftRightConstraint(ellipse, bezier);

            var layeredLayout = new LayeredLayout(graph, settings);
            layeredLayout.Run();
#if DEBUG
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
Example #55
0
        static void TestPaddingForEdge(GeometryGraph geomGraph, Edge edge) {
            const int steps = 100;
            var edgeCurve = edge.Curve;
            var step = (edgeCurve.ParEnd - edgeCurve.ParStart)/steps;
            for(var par=edgeCurve.ParStart; par<edgeCurve.ParEnd; par= par+step) {
                var curvePoint = edgeCurve[par];
                foreach (var node in geomGraph.Nodes.Where(node => node == edge.Source && node == edge.Target)) {
                    var nb = node.BoundaryCurve;

                    var p = nb.ClosestParameter(curvePoint);
                    var nodePoint = nb[p];
#if DEBUG
                    if ((nodePoint - curvePoint).Length < 0.99)
                        LayoutAlgorithmSettings.Show(new LineSegment(nodePoint, curvePoint), nb, edgeCurve);
#endif
                }
            }
        }
 static void CalculateAttachedSegmentEnd(GeomLabel label, GeomEdge edge)
 {
     label.AttachmentSegmentEnd = edge.Curve[edge.Curve.ClosestParameter(label.Center)];
 }
Example #57
0
 private void RouteEdge(GeometryEdge geometryEdge)
 {
     var router = new RouterBetweenTwoNodes(Graph.GeometryGraph, Graph.Attr.NodeSeparation * tightOffsetForRouting,
                                            Graph.Attr.NodeSeparation * looseOffsetForRouting,
                                            Graph.Attr.NodeSeparation * offsetForRelaxingInRouting);
     try
     {
         router.RouteEdge(geometryEdge, true);
     }
     catch (Exception)
     {
     }
 }
Example #58
0
 private static void TransformUnderlyingPolyline(GeometryGraph geometryGraph, GeometryEdge e, PlaneTransformation transformation)
 {
     if (e.UnderlyingPolyline != null)
     {
         for (Microsoft.Msagl.Core.Geometry.Site s = e.UnderlyingPolyline.HeadSite; s != null; s = s.Next)
         {
             s.Point = transformation * s.Point;
         }
     }
 }
Example #59
0
        static void TestGraphWithConstraints()
        {
            var graph = new GeometryGraph();

            var closed    = new Node(CreateEllipse(), "closed");
            var line      = new Node(CreateEllipse(), "line");
            var bezier    = new Node(CreateEllipse(), "bezier");
            var arc       = new Node(CreateEllipse(), "arc");
            var rectangle = new Node(CreateEllipse(), "rectangle");
            var ellipse   = new Node(CreateEllipse(), "ellipse");
            var polygon   = new Node(CreateEllipse(), "polygon");
            var shapes    = new Node(CreateEllipse(), "shapes");
            var open      = new Node(CreateEllipse(), "open");

            graph.Nodes.Add(closed);
            graph.Nodes.Add(line);
            graph.Nodes.Add(bezier);
            graph.Nodes.Add(arc);
            graph.Nodes.Add(rectangle);
            graph.Nodes.Add(ellipse);
            graph.Nodes.Add(polygon);
            graph.Nodes.Add(shapes);
            graph.Nodes.Add(open);

            var so = new Edge(shapes, open);
            var sc = new Edge(shapes, closed);
            var ol = new Edge(open, line);
            var ob = new Edge(open, bezier);
            var oa = new Edge(open, arc);
            var cr = new Edge(closed, rectangle);
            var ce = new Edge(closed, ellipse);
            var cp = new Edge(closed, polygon);

            graph.Edges.Add(so);
            graph.Edges.Add(sc);
            graph.Edges.Add(ol);
            graph.Edges.Add(ob);
            graph.Edges.Add(oa);
            graph.Edges.Add(cr);
            graph.Edges.Add(ce);
            graph.Edges.Add(cp);

            var settings = new SugiyamaLayoutSettings();

            settings.AddUpDownVerticalConstraint(closed, ellipse);
            settings.AddUpDownVerticalConstraint(open, bezier);
            settings.AddUpDownConstraint(closed, open);
            settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);
            settings.AddLeftRightConstraint(open, closed);

            ////To verify 444585, just turn on this following commented line
            settings.AddLeftRightConstraint(ellipse, rectangle);
            settings.AddLeftRightConstraint(ellipse, bezier);

            var layeredLayout = new LayeredLayout(graph, settings);

            layeredLayout.Run();
#if TEST_MSAGL
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
Example #60
0
        private DEdge AddCrossEdge(DNode source, DNode target)
        {
            DEdge dEdge = new DEdge(source, target, new DrawingEdge(source.Node, target.Node, ConnectionToGraph.Disconnected), ConnectionToGraph.Disconnected);
            GeometryEdge gEdge = new GeometryEdge(source.GeometryNode, target.GeometryNode) { GeometryParent = Graph.GeometryGraph };
            dEdge.GeometryEdge = gEdge;
            dEdge.ArrowheadAtTarget = ArrowStyle.Normal;

            m_CrossEdges.Add(dEdge);

            return dEdge;

            /*DEdge ret;
            var s = VisualTreeHelper.GetRoot(this);
            var ss = VisualTreeHelper.GetRoot(source);
            var ts = VisualTreeHelper.GetRoot(target);
            if (s != ss || s != ts || ss != ts)
                ret = new DEdge(source, target, null, ConnectionToGraph.Disconnected);
            else
                ret = NestedGraphHelper.DrawCrossEdge(this, source, target);
            m_CrossEdges.Add(ret);
            return ret;*/
        }