/// <summary> /// Adjusts the end points position to an optimal position /// (when their <see cref="DragThumb.Placement"/> is set /// to <see cref="EPlacementKind.ParentAutoPos"/>). /// </summary> public bool AdjustEndPoints() { #if SILVERLIGHT if (StartNode != null && !sourceMeasureValid) { sourceMeasureValid = StartNode.GetBounds().Width != 0; } if (EndNode != null && !targetMeasureValid) { targetMeasureValid = EndNode.GetBounds().Width != 0; } #endif // StartNode and EndNode now can be null to allow disconnected connector points if (StartNode != null && !StartNode.IsMeasureValid) { return(false); } if (EndNode != null && !EndNode.IsMeasureValid) { return(false); } if (StartPoint == null || EndPoint == null || !targetMeasureValid || !sourceMeasureValid) { return(false); } #region set source junctionEnd position double angle = StartNode != null ? StartNode.BoundsAngle : 0; if (StartPoint.Placement == EPlacementKind.AbsoluteSubCanvas) { Point snappedStart = StartNode.GetBounds().Normalize().SnapPointToRectangle(StartPoint.Position); if (snappedStart != StartPoint.Position) { StartPoint.SetPreferedPosition(snappedStart); } } if (AutoPosModeOnly && StartPoint.Placement != EPlacementKind.ParentAutoPos) { StartPoint.Placement = EPlacementKind.ParentAutoPos; } // Condition removed to allow disconnected connector points //if (StartNode.IsMeasureValid /*&& (viewHelperPointsCollection == null || Points.Count == viewHelperPointsCollection.Count)*/ // /*&& (StartPoint.Placement == EPlacementKind.ParentAutoPos || viewHelperPointsCollection == null || viewHelperPointsCollection.PointsInvalid)*/) { Rect r1 = GeometryHelper.GetFirstElementBounds(this); Rect r2 = GeometryHelper.GetFirstButOneElementBounds(this); Point p1 = GeometryHelper.RectangleRectangleCenterIntersection(r1, r2, true, angle); if (StartPoint.Placement != EPlacementKind.ParentAutoPos && StartPoint.Position.AlmostEqual(p1) && !((IDraggable)StartPoint).DragThumb.IsDragged) { StartPoint.Placement = EPlacementKind.ParentAutoPos; } if (StartPoint.Placement == EPlacementKind.ParentAutoPos) { // simplified to this.. StartPoint.SetPreferedPosition(p1); } //if (viewHelperPointsCollection == null) //{ // StartPoint.SetPreferedPosition(p1); //} //else if (!viewHelperPointsCollection.First().AlmostEqual(p1)) //{ // if (viewHelperPointsCollection.PointsInvalid) // { // viewHelperPointsCollection[0].Set(p1); // StartPoint.SetPreferedPosition(p1); // viewHelperPointsCollection.PointsInvalid = false; // } // else // { // if (!sourceMeasureValid) // { // if (p1 != StartPoint.Position) // { // if (!AutoPosModeOnly) // { // StartPoint.Placement = EPlacementKind.AbsoluteSubCanvas; // Point snapped = r1.Normalize().SnapPointToRectangle(StartPoint.Position); // if (snapped != StartPoint.Position) // StartPoint.SetPreferedPosition(snapped); // } // } // } // else // { // viewHelperPointsCollection[0].Set(p1); // StartPoint.SetPreferedPosition(p1); // } // } //} //else //{ // StartPoint.SetPreferedPosition(p1); // StartPoint.Placement = EPlacementKind.ParentAutoPos; //} sourceMeasureValid = true; } #endregion #region set end junctionEnd position if (EndPoint.Placement == EPlacementKind.AbsoluteSubCanvas) { Point snappedEnd = EndNode.GetBounds().Normalize().SnapPointToRectangle(EndPoint.Position); if (snappedEnd != EndPoint.Position) { EndPoint.SetPreferedPosition(snappedEnd); } } angle = EndNode != null ? EndNode.BoundsAngle : 0; if (AutoPosModeOnly && EndPoint.Placement != EPlacementKind.ParentAutoPos) { EndPoint.Placement = EPlacementKind.ParentAutoPos; } // Condition removed to allow disconnected connector points //if (EndNode.IsMeasureValid /*&& (viewHelperPointsCollection == null || Points.Count == viewHelperPointsCollection.Count)*/ // /*&& (EndPoint.Placement == EPlacementKind.ParentAutoPos || viewHelperPointsCollection == null || viewHelperPointsCollection.PointsInvalid)*/) { Rect r1 = GeometryHelper.GetLastElementBounds(this); Rect r2 = GeometryHelper.GetLastButOneElementBounds(this); Point p2 = GeometryHelper.RectangleRectangleCenterIntersection(r1, r2, true, angle); if (EndPoint.Placement != EPlacementKind.ParentAutoPos && EndPoint.Position.AlmostEqual(p2) && !((IDraggable)EndPoint).DragThumb.IsDragged) { EndPoint.Placement = EPlacementKind.ParentAutoPos; } if (EndPoint.Placement == EPlacementKind.ParentAutoPos) { // simplified to this.. EndPoint.SetPreferedPosition(p2); } //if (viewHelperPointsCollection == null) //{ // EndPoint.SetPreferedPosition(p2); //} //else if (!viewHelperPointsCollection.Last().AlmostEqual(p2)) //{ // if (viewHelperPointsCollection.PointsInvalid) // { // viewHelperPointsCollection.Last().Set(p2); // EndPoint.SetPreferedPosition(p2); // viewHelperPointsCollection.PointsInvalid = false; // } // else // { // if (!targetMeasureValid) // { // if (p2 != EndPoint.Position) // { // EndPoint.Placement = EPlacementKind.AbsoluteSubCanvas; // Point snapped = r1.Normalize().SnapPointToRectangle(EndPoint.Position); // if (snapped != EndPoint.Position) // EndPoint.SetPreferedPosition(snapped); // } // } // else // { // viewHelperPointsCollection.Last().Set(p2); // EndPoint.SetPreferedPosition(p2); // } // } //} //else //{ // EndPoint.SetPreferedPosition(p2); // EndPoint.Placement = EPlacementKind.ParentAutoPos; //} targetMeasureValid = true; } #endregion return(true); }