Exemplo n.º 1
0
        void RouteEdgeWithLabel(IntEdge intEdge, Label label)
        {
            //we allow here for the edge to cross its own label
            Node             sourceNode    = routing.IntGraph.Nodes[intEdge.Source];
            Node             targetNode    = routing.IntGraph.Nodes[intEdge.Target];
            var              sourcePort    = new FloatingPort(sourceNode.BoundaryCurve, sourceNode.Center);
            var              targetPort    = new FloatingPort(targetNode.BoundaryCurve, targetNode.Center);
            ICurve           labelObstacle = labelsToLabelObstacles[label];
            var              labelPort     = new FloatingPort(labelObstacle, label.Center);
            SmoothedPolyline poly0;

            interactiveEdgeRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(sourcePort, labelPort, true, out poly0);
            SmoothedPolyline poly1;

            interactiveEdgeRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(labelPort, targetPort, true, out poly1);
            Site site = poly1.HeadSite.Next;

            Site lastSite = poly0.LastSite;

            lastSite.Next = site;
            site.Previous = lastSite;
            var eg = intEdge.Edge.EdgeGeometry;

            eg.SetSmoothedPolylineAndCurve(poly0);
            Arrowheads.TrimSplineAndCalculateArrowheads(eg, intEdge.Edge.Source.BoundaryCurve,
                                                        intEdge.Edge.Target.BoundaryCurve, eg.Curve, false,
                                                        settings.EdgeRoutingSettings.KeepOriginalSpline);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="cornerFitRadius"></param>
        public static void CreateSimpleEdgeCurveWithGivenFitRadius(Edge edge, double cornerFitRadius)
        {
            ValidateArg.IsNotNull(edge, "edge");
            var a = edge.Source.Center;
            var b = edge.Target.Center;

            if (edge.Source == edge.Target)
            {
                var dx = edge.Source.BoundaryCurve.BoundingBox.Width / 2;
                var dy = edge.Source.BoundingBox.Height / 4;
                edge.UnderlyingPolyline = CreateUnderlyingPolylineForSelfEdge(a, dx, dy);
                for (var site = edge.UnderlyingPolyline.HeadSite.Next; site.Next != null; site = site.Next)
                {
                    CalculateCoefficiensUnderSite(site, cornerFitRadius);
                }
                edge.Curve = edge.UnderlyingPolyline.CreateCurve();
            }
            else
            {
                edge.UnderlyingPolyline = SmoothedPolyline.FromPoints(new[] { a, b });
                edge.Curve = edge.UnderlyingPolyline.CreateCurve();
            }

            if (!Arrowheads.TrimSplineAndCalculateArrowheads(edge.EdgeGeometry, edge.Source.BoundaryCurve, edge.Target.BoundaryCurve, edge.Curve,
                                                             true))
            {
                Arrowheads.CreateBigEnoughSpline(edge);
            }
        }
        /// <summary>
        /// populate the geometry including curve and arrowhead positioning for the given edge using simple
        /// straight line routing style.  Self edges will be drawn as a loop, padding is used to control the
        /// size of the loop.
        /// </summary>
        /// <param name="edge">edge to route</param>
        /// <param name="padding">controls size of loop</param>
        public static void RouteEdge(Edge edge, double padding)
        {
            ValidateArg.IsNotNull(edge, "edge");

            var eg = edge.EdgeGeometry;

            if (eg.SourcePort == null)
            {
#if SHARPKIT // Lambdas bind differently in JS
                eg.SourcePort = ((Func <Edge, RelativeFloatingPort>)(ed => new RelativeFloatingPort(() => ed.Source.BoundaryCurve,
                                                                                                    () => ed.Source.Center)))(edge);
#else
                eg.SourcePort = new RelativeFloatingPort(() => edge.Source.BoundaryCurve, () => edge.Source.Center);
#endif
            }

            if (eg.TargetPort == null)
            {
#if SHARPKIT // Lambdas bind differently in JS
                eg.TargetPort = ((Func <Edge, RelativeFloatingPort>)(ed => new RelativeFloatingPort(() => ed.Target.BoundaryCurve,
                                                                                                    () => ed.Target.Center)))(edge);
#else
                eg.TargetPort = new RelativeFloatingPort(() => edge.Target.BoundaryCurve, () => edge.Target.Center);
#endif
            }

            if (!ContainmentLoop(eg, padding))
            {
                eg.Curve = GetEdgeLine(edge);
            }

            Arrowheads.TrimSplineAndCalculateArrowheads(eg, eg.SourcePort.Curve,
                                                        eg.TargetPort.Curve, edge.Curve, false, false);
        }
Exemplo n.º 4
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.)
        }
Exemplo n.º 5
0
 void FixArrowheads()
 {
     foreach (var edge in geometryGraph.Edges)
     {
         Arrowheads.TrimSplineAndCalculateArrowheads(edge.EdgeGeometry,
                                                     edge.Source.BoundaryCurve,
                                                     edge.Target.BoundaryCurve,
                                                     edge.Curve, false, this.bundlingSettings.KeepOriginalSpline);
     }
 }
Exemplo n.º 6
0
 void FixArrowheads()
 {
     foreach (var edge in geometryGraph.Edges)
     {
         Arrowheads.TrimSplineAndCalculateArrowheads(edge.EdgeGeometry,
                                                     edge.Source.BoundaryCurve,
                                                     edge.Target.BoundaryCurve,
                                                     edge.Curve, false);
     }
 }
        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);
            }
        }
Exemplo n.º 8
0
        void CreateSplineForNonSelfEdge(PolyIntEdge es, bool optimizeShortEdges) {
            this.ProgressStep();

            if (es.LayerEdges != null) {
                DrawSplineBySmothingThePolyline(es, optimizeShortEdges);
                if (!es.IsVirtualEdge)
                {
                    es.UpdateEdgeLabelPosition(Database.Anchors);
                    Arrowheads.TrimSplineAndCalculateArrowheads(es.Edge.EdgeGeometry, es.Edge.Source.BoundaryCurve,
                                                                     es.Edge.Target.BoundaryCurve, es.Curve, true);
                }
            }
        }
Exemplo n.º 9
0
        static void DrawEdgeWithPort(Edge edge, InteractiveEdgeRouter portRouter, double par0, double par1)
        {
            var port0 = new CurvePort(edge.Source.BoundaryCurve, par0);
            var port1 = new CurvePort(edge.Target.BoundaryCurve, par1);

            SmoothedPolyline sp;
            var spline = portRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(port0, port1, true, out sp);

            Arrowheads.TrimSplineAndCalculateArrowheads(edge.EdgeGeometry,
                                                        edge.Source.BoundaryCurve,
                                                        edge.Target.BoundaryCurve,
                                                        spline, true);
        }
Exemplo n.º 10
0
        void CreateSelfSplines()
        {
            foreach (var kv in Database.Multiedges)
            {
                this.ProgressStep();

                IntPair ip = kv.Key;
                if (ip.x == ip.y) {
                    Anchor anchor = Database.Anchors[ip.x];
                    double offset = anchor.LeftAnchor;
                    foreach (PolyIntEdge intEdge in kv.Value) {
                        ProgressStep();

                        double dx = settings.NodeSeparation + settings.MinNodeWidth + offset;
                        double dy = anchor.BottomAnchor / 2;
                        Point p0 = anchor.Origin;
                        Point p1 = p0 + new Point(0, dy);
                        Point p2 = p0 + new Point(dx, dy);
                        Point p3 = p0 + new Point(dx, -dy);
                        Point p4 = p0 + new Point(0, -dy);

                        var s = new Site(p0);
                        var polyline = new SmoothedPolyline(s);
                        s = new Site(s, p1);
                        s = new Site(s, p2);
                        s = new Site(s, p3);
                        s = new Site(s, p4);
                        new Site(s, p0);

                        Curve c;
                        intEdge.Curve = c = polyline.CreateCurve();
                        intEdge.Edge.UnderlyingPolyline = polyline;
                        offset = dx;
                        if (intEdge.Edge.Label != null) {
                            offset += intEdge.Edge.Label.Width;
                            Point center =
                                intEdge.Edge.Label.Center =
                                new Point(c[(c.ParStart + c.ParEnd) / 2].X + intEdge.LabelWidth / 2, anchor.Y);
                            var del = new Point(intEdge.Edge.Label.Width / 2, intEdge.Edge.Label.Height / 2);

                            var box = new Rectangle(center + del, center - del);
                            intEdge.Edge.Label.BoundingBox = box;
                        }
                        Arrowheads.TrimSplineAndCalculateArrowheads(intEdge.Edge.EdgeGeometry,
                                                               intEdge.Edge.Source.BoundaryCurve,
                                                               intEdge.Edge.Target.BoundaryCurve, c, false, 
                                                               settings.EdgeRoutingSettings.KeepOriginalSpline);
                    }
                }
            }
        }
        void RouteEdgeWithNoLabel(PolyIntEdge intEdge)
        {
            Node             sourceNode = routing.IntGraph.Nodes[intEdge.Source];
            Node             targetNode = routing.IntGraph.Nodes[intEdge.Target];
            var              sourcePort = new FloatingPort(sourceNode.BoundaryCurve, sourceNode.Center);
            var              targetPort = new FloatingPort(targetNode.BoundaryCurve, targetNode.Center);
            var              eg         = intEdge.Edge.EdgeGeometry;
            SmoothedPolyline sp;

            eg.Curve = interactiveEdgeRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(sourcePort, targetPort, true, out sp);
            Arrowheads.TrimSplineAndCalculateArrowheads(eg, intEdge.Edge.Source.BoundaryCurve,
                                                        intEdge.Edge.Target.BoundaryCurve, eg.Curve, false);
            intEdge.Edge.EdgeGeometry = eg;
        }
 static void RouteClusterParentInEdges(List<Edge> inParentEdges, EdgeRoutingSettings edgeRoutingSettings, Cluster cluster,
     double padding) {
     foreach (var e in cluster.InEdges.Where(e => IsDescendant(e.Source, cluster))) {
         double ePadding = Math.Max(padding, 1.5 * ArrowlengthAtTarget(e));
         var hookPort = e.TargetPort as HookUpAnywhereFromInsidePort;
         if (hookPort == null)
             e.TargetPort = hookPort = new HookUpAnywhereFromInsidePort(() => cluster.BoundaryCurve);
         hookPort.HookSize = ePadding;
         e.Curve = StraightLineEdges.CreateLoop(e.Source.BoundingBox, cluster.BoundingBox, ePadding, false);
         Arrowheads.TrimSplineAndCalculateArrowheads(e, e.Curve, false,
             edgeRoutingSettings.KeepOriginalSpline);
         inParentEdges.Add(e);
     }
 }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
        Geometry DefiningSourceArrowHead()
        {
            if (Edge.GeometryEdge.EdgeGeometry.SourceArrowhead == null)
            {
                Edge.GeometryEdge.EdgeGeometry.SourceArrowhead = new Arrowhead {
                    Length = Edge.Attr.ArrowheadLength
                };
                var curve = Edge.GeometryEdge.UnderlyingPolyline.CreateCurve();
                Arrowheads.TrimSplineAndCalculateArrowheads(Edge.GeometryEdge, curve, true, false);
            }
            var streamGeometry = new StreamGeometry();

            using (StreamGeometryContext context = streamGeometry.Open()) {
                AddArrow(context, Edge.GeometryEdge.Curve.Start, Edge.GeometryEdge.EdgeGeometry.SourceArrowhead.TipPosition, PathStrokeThickness, Edge.Attr.ArrowheadAtSource);
                return(streamGeometry);
            }
        }
        /// <summary>
        /// creates an edge curve based only on the source and target geometry
        /// </summary>
        /// <param name="edge"></param>
        public static void CreateSimpleEdgeCurveWithUnderlyingPolyline(Edge edge)
        {
            ValidateArg.IsNotNull(edge, "edge");
            var a = edge.Source.Center;
            var b = edge.Target.Center;

            if (edge.Source == edge.Target)
            {
                var dx = 2.0 / 3 * edge.Source.BoundaryCurve.BoundingBox.Width;
                var dy = edge.Source.BoundingBox.Height / 4;
                edge.UnderlyingPolyline = CreateUnderlyingPolylineForSelfEdge(a, dx, dy);
                edge.Curve = edge.UnderlyingPolyline.CreateCurve();
            }
            else
            {
                edge.UnderlyingPolyline = SmoothedPolyline.FromPoints(new[] { a, b });
                edge.Curve = edge.UnderlyingPolyline.CreateCurve();
            }
            Arrowheads.TrimSplineAndCalculateArrowheads(edge.EdgeGeometry,
                                                        edge.Source.BoundaryCurve,
                                                        edge.Target.BoundaryCurve,
                                                        edge.Curve, false, false);
        }
Exemplo n.º 16
0
 private static void CalculateArrowheads(EdgeGeometry edgeGeom)
 {
     Arrowheads.TrimSplineAndCalculateArrowheads(edgeGeom, edgeGeom.SourcePort.Curve, edgeGeom.TargetPort.Curve, edgeGeom.Curve, true, false);
 }