public static Point[] Route(IServiceProvider serviceProvider, object source, object target, ICollection <Rectangle> userDefinedRoutingObstacles) { List <Rectangle> list; List <Point> list2; List <Point> list3; GetRoutingObstacles(serviceProvider, source, target, out list, out list2, out list3); if (userDefinedRoutingObstacles != null) { list.AddRange(userDefinedRoutingObstacles); } ActivityDesigner safeRootDesigner = ActivityDesigner.GetSafeRootDesigner(serviceProvider); AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; Point begin = (source is ConnectionPoint) ? ((ConnectionPoint)source).Location : ((Point)source); Point end = (target is ConnectionPoint) ? ((ConnectionPoint)target).Location : ((Point)target); Point[] segments = ConnectorRouter.Route(begin, end, new Size(2 * ambientTheme.Margin.Width, 2 * ambientTheme.Margin.Height), safeRootDesigner.Bounds, list.ToArray(), list2.ToArray(), list3.ToArray()); if (!AreAllSegmentsVerticalOrHorizontal(segments)) { segments = ConnectorRouter.Route(begin, end, ambientTheme.Margin, safeRootDesigner.Bounds, new Rectangle[0], list2.ToArray(), new Point[0]); } if (!AreAllSegmentsVerticalOrHorizontal(segments)) { Point point3 = (DesignerGeometryHelper.SlopeOfLineSegment(begin, end) < 1f) ? new Point(end.X, begin.Y) : new Point(begin.X, end.Y); segments = new Point[] { begin, point3, end }; } return(segments); }
private void UpdateEditPoints(Point newPoint) { if (((this.editPoints.Count >= 2) && (this.editPoints[0].Type == EditPoint.EditPointTypes.ConnectionEditPoint)) && (this.editPoints[this.editPoints.Count - 1].Type == EditPoint.EditPointTypes.ConnectionEditPoint)) { this.RemoveEditPoints(EditPoint.EditPointTypes.MidSegmentEditPoint); if (this.activeEditPoint != null) { int index = this.editPoints.IndexOf(this.activeEditPoint); EditPoint point = (index > 0) ? this.editPoints[index - 1] : null; EditPoint point2 = (index < (this.editPoints.Count - 1)) ? this.editPoints[index + 1] : null; if ((point != null) && (point.Type == EditPoint.EditPointTypes.ConnectionEditPoint)) { Orientation orientation = (Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, this.activeEditPoint.Location)) < 1f) ? Orientation.Horizontal : Orientation.Vertical; int num3 = Convert.ToInt32(DesignerGeometryHelper.DistanceBetweenPoints(point.Location, (point2 != null) ? point2.Location : this.activeEditPoint.Location)) / 4; if (orientation == Orientation.Horizontal) { num3 *= (point.Location.X < this.activeEditPoint.Location.X) ? 1 : -1; } else { num3 *= (point.Location.Y < this.activeEditPoint.Location.X) ? 1 : -1; } index = this.editPoints.IndexOf(this.activeEditPoint); Point point3 = (orientation == Orientation.Horizontal) ? new Point(point.Location.X + num3, point.Location.Y) : new Point(point.Location.X, point.Location.Y + num3); point = new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, point3); this.editPoints.InsertRange(index, new EditPoint[] { new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, point3), point }); } if ((point2 != null) && (point2.Type == EditPoint.EditPointTypes.ConnectionEditPoint)) { Orientation orientation2 = (Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(this.activeEditPoint.Location, point2.Location)) < 1f) ? Orientation.Horizontal : Orientation.Vertical; int num5 = Convert.ToInt32(DesignerGeometryHelper.DistanceBetweenPoints((point != null) ? point.Location : this.activeEditPoint.Location, point2.Location)) / 4; if (orientation2 == Orientation.Horizontal) { num5 *= (this.activeEditPoint.Location.X < point2.Location.X) ? -1 : 1; } else { num5 *= (this.activeEditPoint.Location.Y < point2.Location.Y) ? -1 : 1; } index = this.editPoints.IndexOf(this.activeEditPoint); Point point4 = (orientation2 == Orientation.Horizontal) ? new Point(point2.Location.X + num5, point2.Location.Y) : new Point(point2.Location.X, point2.Location.Y + num5); point2 = new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, point4); this.editPoints.InsertRange(index + 1, new EditPoint[] { point2, new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, point4) }); } if (this.activeEditPoint.Type == EditPoint.EditPointTypes.ConnectionEditPoint) { this.activeEditPoint.Location = newPoint; this.RemoveEditPoints(EditPoint.EditPointTypes.MultiSegmentEditPoint); object source = null; object target = null; if (this.activeEditPoint.EditedConnectionPoint.Equals(this.Target)) { target = newPoint; source = this.Source; } else { source = newPoint; target = this.Target; } int num6 = (this.editPoints.Count == 2) ? 1 : 0; List <EditPoint> list = new List <EditPoint>(); Point[] pointArray = ActivityDesignerConnectorRouter.Route(this.serviceProvider, source, target, this.editedConnector.ExcludedRoutingRectangles); for (int i = num6; i < (pointArray.Length - num6); i++) { list.Add(new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, pointArray[i])); } this.editPoints.InsertRange(1, list.ToArray()); } else if (this.activeEditPoint.Type == EditPoint.EditPointTypes.MultiSegmentEditPoint) { if (((point != null) && (point.Type != EditPoint.EditPointTypes.ConnectionEditPoint)) && ((point2 != null) && (point2.Type != EditPoint.EditPointTypes.ConnectionEditPoint))) { Orientation orientation3 = (Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, this.activeEditPoint.Location)) < 1f) ? Orientation.Horizontal : Orientation.Vertical; point.Location = (orientation3 == Orientation.Horizontal) ? new Point(point.Location.X, newPoint.Y) : new Point(newPoint.X, point.Location.Y); orientation3 = (Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(this.activeEditPoint.Location, point2.Location)) < 1f) ? Orientation.Horizontal : Orientation.Vertical; point2.Location = (orientation3 == Orientation.Horizontal) ? new Point(point2.Location.X, newPoint.Y) : new Point(newPoint.X, point2.Location.Y); this.activeEditPoint.Location = newPoint; } } else if ((((this.activeEditPoint.Type == EditPoint.EditPointTypes.MidSegmentEditPoint) && (point != null)) && ((point.Type != EditPoint.EditPointTypes.ConnectionEditPoint) && (point2 != null))) && (point2.Type != EditPoint.EditPointTypes.ConnectionEditPoint)) { if (((Math.Abs(DesignerGeometryHelper.SlopeOfLineSegment(point.Location, point2.Location)) < 1f) ? 0 : 1) == 0) { point.Location = new Point(point.Location.X, newPoint.Y); point2.Location = new Point(point2.Location.X, newPoint.Y); this.activeEditPoint.Location = new Point(this.activeEditPoint.Location.X, newPoint.Y); } else { point.Location = new Point(newPoint.X, point.Location.Y); point2.Location = new Point(newPoint.X, point2.Location.Y); this.activeEditPoint.Location = new Point(newPoint.X, this.activeEditPoint.Location.Y); } } } this.RemoveCoincidingEditPoints(); this.AddEditPoints(EditPoint.EditPointTypes.MidSegmentEditPoint); this.ValidateEditPoints(); } }
private void RemoveCoincidingEditPoints() { if (((this.editPoints.Count >= 2) && (this.editPoints[0].Type == EditPoint.EditPointTypes.ConnectionEditPoint)) && ((this.editPoints[this.editPoints.Count - 1].Type == EditPoint.EditPointTypes.ConnectionEditPoint) && ((this.activeEditPoint == null) || (this.activeEditPoint.Type != EditPoint.EditPointTypes.ConnectionEditPoint)))) { this.RemoveEditPoints(EditPoint.EditPointTypes.MidSegmentEditPoint); List <EditPoint> list = new List <EditPoint>(); for (int i = 0; i < this.editPoints.Count; i++) { if ((((this.editPoints[i].Type != EditPoint.EditPointTypes.MultiSegmentEditPoint) || (this.editPoints[i] == this.activeEditPoint)) || ((i > 0) && (this.editPoints[i - 1].Type == EditPoint.EditPointTypes.MidSegmentEditPoint))) || ((i < (this.editPoints.Count - 1)) && (this.editPoints[i + 1].Type == EditPoint.EditPointTypes.MidSegmentEditPoint))) { list.Add(this.editPoints[i]); } } for (int j = 1; j < (this.editPoints.Count - 1); j++) { EditPoint point = this.editPoints[j - 1]; EditPoint item = this.editPoints[j]; EditPoint point3 = this.editPoints[j + 1]; if (!list.Contains(item)) { Point[] segments = new Point[] { point.Location, item.Location }; double num3 = DesignerGeometryHelper.DistanceOfLineSegments(segments); if (((num3 < item.Bounds.Width) || (num3 < item.Bounds.Height)) && (point3.Type == EditPoint.EditPointTypes.MultiSegmentEditPoint)) { float num4 = DesignerGeometryHelper.SlopeOfLineSegment(item.Location, point3.Location); point3.Location = (num4 < 1f) ? new Point(point3.Location.X, point.Location.Y) : new Point(point.Location.X, point3.Location.Y); this.editPoints.Remove(item); j--; } else { Point[] pointArray2 = new Point[] { item.Location, point3.Location }; num3 = DesignerGeometryHelper.DistanceOfLineSegments(pointArray2); if (((num3 < item.Bounds.Width) || (num3 < item.Bounds.Height)) && (point.Type == EditPoint.EditPointTypes.MultiSegmentEditPoint)) { float num5 = DesignerGeometryHelper.SlopeOfLineSegment(point.Location, item.Location); point.Location = (num5 < 1f) ? new Point(point.Location.X, point3.Location.Y) : new Point(point3.Location.X, point.Location.Y); this.editPoints.Remove(item); j--; } } } } for (int k = 1; k < (this.editPoints.Count - 1); k++) { EditPoint point4 = this.editPoints[k]; EditPoint point5 = this.editPoints[k - 1]; EditPoint point6 = this.editPoints[k + 1]; if (!list.Contains(point4)) { float num7 = DesignerGeometryHelper.SlopeOfLineSegment(point5.Location, point4.Location); float num8 = DesignerGeometryHelper.SlopeOfLineSegment(point4.Location, point6.Location); if (Math.Abs(num7) == Math.Abs(num8)) { this.editPoints.Remove(point4); k--; } } } for (int m = 0; m < (this.editPoints.Count - 1); m++) { EditPoint point7 = this.editPoints[m]; EditPoint point8 = this.editPoints[m + 1]; float num10 = DesignerGeometryHelper.SlopeOfLineSegment(point7.Location, point8.Location); if ((num10 != 0f) && (num10 != float.MaxValue)) { Point point9 = (num10 < 1f) ? new Point(point8.Location.X, point7.Location.Y) : new Point(point7.Location.X, point8.Location.Y); this.editPoints.Insert(m + 1, new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, point9)); } } } }