Exemplo n.º 1
0
        /// <summary>
        /// Calculates the location of the handle considering the <see cref="GraphExtensions.GetLocation">port location</see>,
        /// <see cref="NodeStylePortStyleAdapter.RenderSize"/> and <see cref="Margins"/>.
        /// </summary>
        private PointD CalculateLocation()
        {
            var portLocation             = port.GetLocation();
            var handleX                  = portLocation.X;
            var handleY                  = portLocation.Y;
            var marginsInViewCoordinates = Margins / context.Zoom;

            if (position == HandlePositions.NorthWest || position == HandlePositions.West || position == HandlePositions.SouthWest)
            {
                handleX -= adapter.RenderSize.Width / 2 + marginsInViewCoordinates;
            }
            else if (position == HandlePositions.NorthEast || position == HandlePositions.East || position == HandlePositions.SouthEast)
            {
                handleX += adapter.RenderSize.Width / 2 + marginsInViewCoordinates;
            }
            if (position == HandlePositions.NorthWest || position == HandlePositions.North || position == HandlePositions.NorthEast)
            {
                handleY -= adapter.RenderSize.Height / 2 + marginsInViewCoordinates;
            }
            else if (position == HandlePositions.SouthWest || position == HandlePositions.South || position == HandlePositions.SouthEast)
            {
                handleY += adapter.RenderSize.Height / 2 + marginsInViewCoordinates;
            }
            return(new PointD(handleX, handleY));
        }
        protected override Ellipse UpdateVisual(IRenderContext context, Ellipse oldVisual, IPort port)
        {
            var portLocation = port.GetLocation();

            oldVisual.SetCanvasArrangeRect(new Rect(portLocation.X - renderSizeHalf, portLocation.Y - renderSizeHalf, renderSize, renderSize));
            return(oldVisual);
        }
            public void Paint(IRenderContext renderContext, Graphics graphics)
            {
                var color    = port.Tag is Color ? (Color)port.Tag : Color.White;
                var location = port.GetLocation();

                graphics.FillEllipse(new SolidBrush(color), (float)(location.X - renderSizeHalf), (float)(location.Y - renderSizeHalf), renderSize, renderSize);
                graphics.DrawEllipse(Pens.Gray, (float)(location.X - renderSizeHalf), (float)(location.Y - renderSizeHalf), renderSize, renderSize);
            }
Exemplo n.º 4
0
        /// <summary>
        /// Moves the visual to the correct location.
        /// </summary>
        protected override EllipseVisual UpdateVisual(IRenderContext context, EllipseVisual oldVisual, IPort port)
        {
            // arrange the old ellipse
            var transform = new Matrix();
            var topLeft   = port.GetLocation() + new PointD(Width * 0.5, Height * 0.5);

            transform.Translate((float)topLeft.X, (float)topLeft.Y);
            oldVisual.Transform = transform;
            return(oldVisual);
        }
        protected override Ellipse CreateVisual(IRenderContext context, IPort port)
        {
            var color   = port.Tag is Color ? (Color)port.Tag : Colors.White;
            var ellipse = new Ellipse {
                Fill = new SolidColorBrush(color), Stroke = Brushes.Gray, Width = renderSize, Height = renderSize
            };
            var portLocation = port.GetLocation();

            ellipse.SetCanvasArrangeRect(new Rect(portLocation.X - renderSizeHalf, portLocation.Y - renderSizeHalf, renderSize, renderSize));
            return(ellipse);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a simple EllipseVisual.
        /// </summary>
        protected override EllipseVisual CreateVisual(IRenderContext context, IPort port)
        {
            // create the ellipse
            var visual = new EllipseVisual(0, 0, Width, Height)
            {
                Pen = ellipsePen
            };

            // and arrange it
            var transform = new Matrix();
            var topLeft   = port.GetLocation() + new PointD(Width * 0.5, Height * 0.5);

            transform.Translate((float)topLeft.X, (float)topLeft.Y);
            visual.Transform = transform;
            return(visual);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Calculates the bounds of this port.
 /// </summary>
 /// <remarks>
 /// These are also used for arranging the visual, hit testing, visibility testing, and marquee box tests.
 /// </remarks>
 protected override RectD GetBounds(ICanvasContext context, IPort port)
 {
     return(RectD.FromCenter(port.GetLocation(), new SizeD(Width, Height)));
 }
Exemplo n.º 8
0
 /// <summary>
 ///   Adds a port candidate dependent on the color tag of the given node.
 /// </summary>
 /// <param name="node">
 ///   The node that the port belongs to (for convenience, it could also be retrieved directly from the
 ///   port).
 /// </param>
 /// <param name="port">The port to add the candidate for.</param>
 /// <returns></returns>
 /// <remarks>
 ///   <para>
 ///     If the node is blue, then the existing port instances will be reused for the port candidates. This has the effect
 ///     that a port can potentially have multiple edges connected to it.
 ///   </para>
 ///   <para>
 ///     If the node is not blue, then a new port will be created at the same location as the original port for the port
 ///     candidate. This means that there are potentially multiple ports at the same location and no edge shares a port with
 ///     another edge.
 ///   </para>
 /// </remarks>
 private IPortCandidate CreatePortCandidate(INode node, IPort port)
 {
     if (Colors.RoyalBlue.Equals(node.Tag))
     {
         // reuse the existing port - the edge will be connected to the very same port after reconnection
         return(new DefaultPortCandidate(port));
     }
     else
     {
         // don't reuse the existing ports, but create new ones at the same location
         return(new DefaultPortCandidate(node,
                                         FreeNodePortLocationModel.Instance.CreateParameter(node, port.GetLocation())));
     }
 }
        protected override RectD GetBounds(ICanvasContext context, IPort port)
        {
            var location = port.GetLocation();

            return(new RectD(location.X - 3, location.Y - 3, 6, 6));
        }
Exemplo n.º 10
0
        private static PortConstraint CreatePortConstraintFromSketch(IEdge e, bool source, bool strong)
        {
            //Get connection port and owner
            IPort port      = source ? e.SourcePort : e.TargetPort;
            INode portOwner = port.Owner as INode;

            if (portOwner != null)
            {
                //Einfachste Loesung:
                //Erzeugt einen strong PortConstraint genau an der port location
                //anschluesse in alle richtungen moeglich
                //        return PortConstraint.create(PortConstraint.ANY_SIDE, strong);
                //alternativ: z.B. Kantenpfad bestimmen und einen PortConstraint
                //erzeugen, dessen Richtung durch den Schnittpunkt zwischen Pfad und Knotenrand gegeben ist.
                //hier nur geradlinige Verbindung zwischen Bends
                PointD portLocation = port.GetLocation();
                PointD seg          = new PointD();
                var    bends        = e.Bends;
                if (bends.Count == 0)
                {
                    // no bends, instead take the endpoint
                    seg = source ? e.TargetPort.GetLocation() : e.SourcePort.GetLocation();
                }
                else
                {
                    IPoint p1 = bends[0].Location;
                    IPoint p2 = bends[bends.Count - 1].Location;
                    seg = source ? new PointD(p1) : new PointD(p2);
                }
                // Some offset for ports, which lie exactly on the border
                RectD enlarged = portOwner.Layout.ToRectD().GetEnlarged(5);

                var generalPath = new GeneralPath(2);
                generalPath.MoveTo(portLocation);
                generalPath.LineTo(seg);

                if (generalPath.FindLineIntersection(enlarged.TopLeft, enlarged.TopRight) < 1)
                {
                    //Erstes Segment verlaesst den Knoten auf der Nordseite
                    //Die tatsaechliche Position des Constraints ergibt sich aus dem Startpunkt der Kante, muss
                    //hier also nicht noch mal angegeben werden, dafuer aber, dass es sich wirklich um einen STRONG constraint
                    //handelt.
                    return(PortConstraint.Create(PortSide.North, strong));
                }
                if (generalPath.FindLineIntersection(enlarged.TopLeft, enlarged.BottomLeft) < 1)
                {
                    //first segment leaves at west...
                    return(PortConstraint.Create(PortSide.West, strong));
                }
                if (generalPath.FindLineIntersection(enlarged.TopRight, enlarged.BottomRight) < 1)
                {
                    //first segment leaves at east...
                    return(PortConstraint.Create(PortSide.East, strong));
                }
                if (generalPath.FindLineIntersection(enlarged.BottomLeft, enlarged.BottomRight) < 1)
                {
                    //first segment leaves at south...
                    return(PortConstraint.Create(PortSide.South, strong));
                }
                //keine intersection mit dem ersten segment, hier waehlen wir den einfachen Weg...
                return(PortConstraint.Create(PortSide.Any, strong));
            }
            return(null);
        }
Exemplo n.º 11
0
        protected override RectD GetBounds(ICanvasContext context, IPort port)
        {
            var location = port.GetLocation();

            return(new RectD(location.X - Width / 2, location.Y - Height / 2, Width, Height));
        }