// 定位到特定节点 public override void FocusNode(Base.BaseNodeControl nodeControl) { if (nodeControl == null) { return; } var targetPos = RectCanvas.TranslatePoint(new Point(RectCanvas.ActualWidth * 0.5, RectCanvas.ActualHeight * 0.5), ViewBoxMain); var currentPos = nodeControl.TranslatePoint(new Point(nodeControl.GetWidth() * 0.5, nodeControl.GetHeight() * 0.5), ViewBoxMain); var left = Canvas.GetLeft(ViewBoxMain); var top = Canvas.GetTop(ViewBoxMain); mAnimTagLeft = left + targetPos.X - currentPos.X; mAnimTagTop = top + targetPos.Y - currentPos.Y; var transAnim = new DoubleAnimation(); transAnim.To = mAnimTagLeft; transAnim.Duration = TimeSpan.FromSeconds(0.15); transAnim.AccelerationRatio = 0.3; transAnim.DecelerationRatio = 0.3; transAnim.Completed += TransAnimX_Completed; ViewBoxMain.BeginAnimation(Canvas.LeftProperty, transAnim); transAnim = new DoubleAnimation(); transAnim.To = mAnimTagTop; transAnim.Duration = TimeSpan.FromSeconds(0.15); transAnim.AccelerationRatio = 0.3; transAnim.DecelerationRatio = 0.3; transAnim.Completed += TransAnimY_Completed; ViewBoxMain.BeginAnimation(Canvas.TopProperty, transAnim); }
public override void FocusNodes(Base.BaseNodeControl[] nodeControls) { if (nodeControls == null || nodeControls.Length <= 0) { return; } // 当前结点的包围大小(MainDrawCanvas上的坐标) var curLeft = double.MaxValue; var curTop = double.MaxValue; var curRight = double.MinValue; var curBottom = double.MinValue; foreach (var node in nodeControls) { var loc = node.GetLocation(); if (curLeft > loc.X) { curLeft = loc.X; } if (curTop > loc.Y) { curTop = loc.Y; } var right = loc.X + node.GetWidth(); if (curRight < right) { curRight = right; } var bottom = loc.Y + node.GetWidth(); if (curBottom < bottom) { curBottom = bottom; } } curLeft -= 50; curTop -= 50; curRight += 50; curBottom += 50; var tl = MainDrawCanvas.TranslatePoint(new Point(curLeft, curTop), ViewBoxMain); var rb = MainDrawCanvas.TranslatePoint(new Point(curRight, curBottom), ViewBoxMain); var tagVBMPt = new Point(tl.X + (rb.X - tl.X) * 0.5, tl.Y + (rb.Y - tl.Y) * 0.5); var viewStart = RectCanvas.TranslatePoint(new Point(0, 0), ViewBoxMain); var viewEnd = RectCanvas.TranslatePoint(new Point(RectCanvas.ActualWidth, RectCanvas.ActualHeight), ViewBoxMain); var curVBMPt = new Point(viewStart.X + (viewEnd.X - viewStart.X) * 0.5, viewStart.Y + (viewEnd.Y - viewStart.Y) * 0.5); //var scaleDeltaX = (viewEnd.X - viewStart.X) / (curRight - curLeft); //var scaleDeltaY = (viewEnd.Y - viewStart.Y) / (curBottom - curTop); var scaleDeltaX = (viewEnd.X - viewStart.X) / (rb.X - tl.X); var scaleDeltaY = (viewEnd.Y - viewStart.Y) / (rb.Y - tl.Y); var scaleDelta = Math.Min(scaleDeltaX, scaleDeltaY); var tagWidth = scaleDelta * ViewBoxMain.ActualWidth; var calScaleDelta = tagWidth / MainDrawCanvas.Width * 100; if (calScaleDelta < mScaleDeltaMin) { scaleDelta = mScaleDeltaMin / 100 * MainDrawCanvas.Width / ViewBoxMain.ActualWidth; } else if (calScaleDelta > mScaleDeltaMax) { scaleDelta = mScaleDeltaMax / 100 * MainDrawCanvas.Width / ViewBoxMain.ActualWidth; } mAnimTagLeft = Canvas.GetLeft(ViewBoxMain) + (curVBMPt.X - tagVBMPt.X); mAnimTagTop = Canvas.GetTop(ViewBoxMain) + (curVBMPt.Y - tagVBMPt.Y); var deltaX = tagVBMPt.X / ViewBoxMain.ActualWidth; var deltaY = tagVBMPt.Y / ViewBoxMain.ActualHeight; mAnimTagLeft -= (ViewBoxMain.ActualWidth * scaleDelta - ViewBoxMain.ActualWidth) * deltaX; mAnimTagTop -= (ViewBoxMain.ActualHeight * scaleDelta - ViewBoxMain.ActualHeight) * deltaY; if (double.IsNaN(mAnimTagLeft) || double.IsInfinity(mAnimTagLeft)) { return; } if (double.IsNaN(mAnimTagTop) || double.IsInfinity(mAnimTagTop)) { return; } var transAnim = new DoubleAnimation(); transAnim.To = mAnimTagLeft; transAnim.Duration = TimeSpan.FromSeconds(0.15); transAnim.AccelerationRatio = 0.3; transAnim.DecelerationRatio = 0.3; transAnim.Completed += TransAnimX_Completed; ViewBoxMain.BeginAnimation(Canvas.LeftProperty, transAnim); transAnim = new DoubleAnimation(); transAnim.To = mAnimTagTop; transAnim.Duration = TimeSpan.FromSeconds(0.15); transAnim.AccelerationRatio = 0.3; transAnim.DecelerationRatio = 0.3; transAnim.Completed += TransAnimY_Completed; ViewBoxMain.BeginAnimation(Canvas.TopProperty, transAnim); ViewBoxMain.Width = ViewBoxMain.ActualWidth; UpdateScaleInfoShow(); mAnimTagWidth = scaleDelta * ViewBoxMain.ActualWidth; if (double.IsNaN(mAnimTagWidth) || double.IsInfinity(mAnimTagWidth)) { return; } //ViewBoxMain.Width = mAnimTagWidth; var anim = new DoubleAnimation(); anim.To = mAnimTagWidth; anim.Duration = TimeSpan.FromSeconds(0.15); anim.AccelerationRatio = 0.3; anim.DecelerationRatio = 0.3; anim.Completed += ScaleAnim_Completed; ViewBoxMain.BeginAnimation(Viewbox.WidthProperty, anim); }