示例#1
0
        private static void UpdateCoordinates(GraphAreaBase area, DependencyObject obj, double horizontalChange, double verticalChange, SnapModifierFunc xSnapModifier, SnapModifierFunc ySnapModifier)
        {
            if (double.IsNaN(GraphAreaBase.GetX(obj)))
            {
                GraphAreaBase.SetX(obj, 0, true);
            }
            if (double.IsNaN(GraphAreaBase.GetY(obj)))
            {
                GraphAreaBase.SetY(obj, 0, true);
            }

            //move the object
            var x = GetOriginalX(obj) + horizontalChange;

            if (xSnapModifier != null)
            {
                x = xSnapModifier(area, obj, x);
            }
            GraphAreaBase.SetX(obj, x, true);

            var y = GetOriginalY(obj) + verticalChange;

            if (ySnapModifier != null)
            {
                y = ySnapModifier(area, obj, y);
            }
            GraphAreaBase.SetY(obj, y, true);

            if (GetUpdateEdgesOnMove(obj))
            {
                UpdateVertexEdges(obj as VertexControl);
            }

            //Debug.WriteLine("({0:##0.00000}, {1:##0.00000})", x, y);
        }
        private static void UpdateCoordinates(DependencyObject obj, double horizontalChange, double verticalChange)
        {
            if (double.IsNaN(GraphAreaBase.GetX(obj)))
            {
                GraphAreaBase.SetX(obj, 0, true);
            }
            if (double.IsNaN(GraphAreaBase.GetY(obj)))
            {
                GraphAreaBase.SetY(obj, 0, true);
            }

            //move the object
            var x = GraphAreaBase.GetX(obj) + horizontalChange;

            GraphAreaBase.SetX(obj, x, true);
            var y = GraphAreaBase.GetY(obj) + verticalChange;

            GraphAreaBase.SetY(obj, y, true);
            if (GetUpdateEdgesOnMove(obj))
            {
                UpdateVertexEdges(obj as VertexControl);
            }
        }
示例#3
0
 public void SetPosition(double x, double y, bool alsoFinal = true)
 {
     GraphAreaBase.SetX(this, x, alsoFinal);
     GraphAreaBase.SetY(this, y, alsoFinal);
 }
示例#4
0
 /// <summary>
 /// Set attached coordinates X and Y
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="alsoFinal"></param>
 public void SetPosition(Point pt, bool alsoFinal = true)
 {
     GraphAreaBase.SetX(this, pt.X, alsoFinal);
     GraphAreaBase.SetY(this, pt.Y, alsoFinal);
 }
示例#5
0
        /// <summary>
        /// Automaticaly update edge label position
        /// </summary>
        public virtual void UpdatePosition()
        {
            if (double.IsNaN(DesiredSize.Width) || DesiredSize.Width == 0)
            {
                return;
            }

            if (EdgeControl == null)
            {
                return;
            }
            if (EdgeControl.Source == null || EdgeControl.Target == null)
            {
                Debug.WriteLine("EdgeLabelControl_LayoutUpdated() -> Got empty edgecontrol!");
                return;
            }
            //if hidden
            if (Visibility != Visibility.Visible)
            {
                return;
            }

            if (EdgeControl.IsSelfLooped)
            {
                var idesiredSize = DesiredSize;
                var pt           = EdgeControl.Source.GetCenterPosition();
                SetSelfLoopedSize(pt, idesiredSize);
                Arrange(LastKnownRectSize);
                return;
            }

            var p1 = EdgeControl.SourceConnectionPoint.GetValueOrDefault();
            var p2 = EdgeControl.TargetConnectionPoint.GetValueOrDefault();

            double edgeLength  = 0;
            var    routingInfo = EdgeControl.Edge as IRoutingInfo;

            if (routingInfo != null)
            {
                var routePoints = routingInfo.RoutingPoints == null ? null : routingInfo.RoutingPoints.ToWindows();

                if (routePoints == null || routePoints.Length == 0)
                {
                    // the edge is a single segment (p1,p2)
                    edgeLength = GetLabelDistance(MathHelper.GetDistanceBetweenPoints(p1, p2));
                }
                else
                {
                    // the edge has one or more segments
                    // compute the total length of all the segments
                    edgeLength = 0;
                    var rplen = routePoints.Length;
                    for (var i = 0; i <= rplen; ++i)
                    {
                        if (i == 0)
                        {
                            edgeLength += MathHelper.GetDistanceBetweenPoints(p1, routePoints[0]);
                        }
                        else if (i == rplen)
                        {
                            edgeLength += MathHelper.GetDistanceBetweenPoints(routePoints[rplen - 1], p2);
                        }
                        else
                        {
                            edgeLength += MathHelper.GetDistanceBetweenPoints(routePoints[i - 1], routePoints[i]);
                        }
                    }
                    // find the line segment where the half distance is located
                    edgeLength = GetLabelDistance(edgeLength);
                    var newp1 = p1;
                    var newp2 = p2;
                    for (var i = 0; i <= rplen; ++i)
                    {
                        double lengthOfSegment;
                        if (i == 0)
                        {
                            lengthOfSegment = MathHelper.GetDistanceBetweenPoints(newp1 = p1, newp2 = routePoints[0]);
                        }
                        else if (i == rplen)
                        {
                            lengthOfSegment = MathHelper.GetDistanceBetweenPoints(newp1 = routePoints[rplen - 1], newp2 = p2);
                        }
                        else
                        {
                            lengthOfSegment = MathHelper.GetDistanceBetweenPoints(newp1 = routePoints[i - 1], newp2 = routePoints[i]);
                        }
                        if (lengthOfSegment >= edgeLength)
                        {
                            break;
                        }
                        edgeLength -= lengthOfSegment;
                    }
                    // redefine our edge points
                    p1 = newp1;
                    p2 = newp2;
                }
            }
            // The label control should be laid out on a rectangle, in the middle of the edge
            var  angleBetweenPoints = MathHelper.GetAngleBetweenPoints(p1, p2);
            var  desiredSize        = DesiredSize;
            bool flipAxis           = p1.X > p2.X; // Flip axis if source is "after" target

            ApplyLabelHorizontalOffset(edgeLength, LabelHorizontalOffset);

            // Calculate the center point of the edge
            var centerPoint = new Point(p1.X + edgeLength * Math.Cos(angleBetweenPoints), p1.Y - edgeLength * Math.Sin(angleBetweenPoints));

            if (AlignToEdge)
            {
                // If we're aligning labels to the edges make sure add the label vertical offset
                var yEdgeOffset = LabelVerticalOffset;
                if (FlipOnRotation && flipAxis && !EdgeControl.IsParallel) // If we've flipped axis, move the offset to the other side of the edge
                {
                    yEdgeOffset = -yEdgeOffset;
                }

                // Adjust offset for rotation. Remember, the offset is perpendicular from the edge tangent.
                // Slap on 90 degrees to the angle between the points, to get the direction of the offset.
                centerPoint.Y -= yEdgeOffset * Math.Sin(angleBetweenPoints + Math.PI / 2);
                centerPoint.X += yEdgeOffset * Math.Cos(angleBetweenPoints + Math.PI / 2);

                // Angle is in degrees
                Angle = -angleBetweenPoints * 180 / Math.PI;
                if (flipAxis)
                {
                    Angle += 180; // Reorient the label so that it's always "pointing north"
                }
            }

            UpdateFinalPosition(centerPoint, desiredSize);

            #if METRO
            GraphAreaBase.SetX(this, LastKnownRectSize.X, true);
            GraphAreaBase.SetY(this, LastKnownRectSize.Y, true);
            #else
            Arrange(LastKnownRectSize);
            #endif
        }