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);
        }
Example #2
0
        private DesignerEdges GetSizingEdge(ActivityDesigner designer, Point point)
        {
            DesignerEdges none          = DesignerEdges.None;
            Size          selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
            Rectangle     bounds        = designer.Bounds;

            Point[] line = new Point[] { new Point(bounds.Left, bounds.Top), new Point(bounds.Left, bounds.Bottom) };
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, line)) <= (selectionSize.Width + 1))
            {
                none |= DesignerEdges.Left;
            }
            Point[] pointArray2 = new Point[] { new Point(bounds.Left, bounds.Top), new Point(bounds.Right, bounds.Top) };
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, pointArray2)) <= (selectionSize.Height + 1))
            {
                none |= DesignerEdges.Top;
            }
            Point[] pointArray3 = new Point[] { new Point(bounds.Right, bounds.Top), new Point(bounds.Right, bounds.Bottom) };
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, pointArray3)) <= (selectionSize.Width + 1))
            {
                none |= DesignerEdges.Right;
            }
            Point[] pointArray4 = new Point[] { new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom) };
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, pointArray4)) <= (selectionSize.Height + 1))
            {
                none |= DesignerEdges.Bottom;
            }
            return(none);
        }
 private void UpdateTransparency(Point point)
 {
     for (int i = 0; i < this.actions.Count; i++)
     {
         float num2 = 0f;
         if (!point.IsEmpty)
         {
             Rectangle actionBounds = this.GetActionBounds(i);
             if (actionBounds.Contains(point) || (this.draggedActionIndex == i))
             {
                 num2 = 1f;
             }
             else
             {
                 Rectangle viewPortRectangle = base.ParentView.ViewPortRectangle;
                 double    num3 = DesignerGeometryHelper.DistanceFromPointToRectangle(point, actionBounds);
                 if ((num3 > (viewPortRectangle.Width / 3)) || (num3 > (viewPortRectangle.Height / 3)))
                 {
                     num2 = 0.3f;
                 }
                 else
                 {
                     num2 = 1f;
                 }
             }
         }
         this.actions[i].Transparency = num2;
     }
 }
        private void UpdateTransparency(Point point)
        {
            for (int i = 0; i < this.actions.Count; i++)
            {
                float transparency = 0;
                if (!point.IsEmpty)
                {
                    Rectangle actionBounds = GetActionBounds(i);
                    if (actionBounds.Contains(point) || this.draggedActionIndex == i)
                    {
                        transparency = 1.0f;
                    }
                    else
                    {
                        Rectangle rectangle = ParentView.ViewPortRectangle;
                        double    distance  = DesignerGeometryHelper.DistanceFromPointToRectangle(point, actionBounds);
                        if (distance > rectangle.Width / 3 || distance > rectangle.Height / 3)
                        {
                            transparency = 0.3f;
                        }
                        else
                        {
                            //Uncomment the following code for fluctuating transparency
                            //1.0f - ((float)Convert.ToInt32(distance)) / Math.Max(ParentView.ViewPortSize.Width, ParentView.ViewPortSize.Height);
                            transparency = 1.0f;
                        }
                    }
                }

                this.actions[i].Transparency = transparency;
            }
        }
        private DesignerEdges GetSizingEdge(ActivityDesigner designer, Point point)
        {
            DesignerEdges sizingEdge = DesignerEdges.None;

            Size      selectionSize  = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
            Rectangle designerBounds = designer.Bounds;

            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, new Point[] { new Point(designerBounds.Left, designerBounds.Top), new Point(designerBounds.Left, designerBounds.Bottom) })) <= selectionSize.Width + 1)
            {
                sizingEdge |= DesignerEdges.Left;
            }
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, new Point[] { new Point(designerBounds.Left, designerBounds.Top), new Point(designerBounds.Right, designerBounds.Top) })) <= selectionSize.Height + 1)
            {
                sizingEdge |= DesignerEdges.Top;
            }
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, new Point[] { new Point(designerBounds.Right, designerBounds.Top), new Point(designerBounds.Right, designerBounds.Bottom) })) <= selectionSize.Width + 1)
            {
                sizingEdge |= DesignerEdges.Right;
            }
            if (Math.Floor(DesignerGeometryHelper.DistanceFromPointToLineSegment(point, new Point[] { new Point(designerBounds.Left, designerBounds.Bottom), new Point(designerBounds.Right, designerBounds.Bottom) })) <= selectionSize.Height + 1)
            {
                sizingEdge |= DesignerEdges.Bottom;
            }

            return(sizingEdge);
        }
Example #6
0
        private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
        {
            snappedConnectionPoint = null;
            List <ConnectionPoint>   list = new List <ConnectionPoint>();
            FreeformActivityDesigner connectorContainer = GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);

            if (connectorContainer != null)
            {
                FreeformActivityDesigner designer2 = activityDesigner as FreeformActivityDesigner;
                List <ActivityDesigner>  list2     = new List <ActivityDesigner> {
                    activityDesigner
                };
                if (designer2 != null)
                {
                    list2.AddRange(designer2.ContainedDesigners);
                }
                double num = 20.0;
                foreach (ActivityDesigner designer3 in list2)
                {
                    if (GetConnectorContainer(designer3) == connectorContainer)
                    {
                        bool flag = false;
                        List <ConnectionPoint> collection = new List <ConnectionPoint>();
                        foreach (ConnectionPoint point in designer3.GetConnectionPoints(DesignerEdges.All))
                        {
                            if (!point.Equals(activeConnectionPoint) && connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, point))
                            {
                                collection.Add(point);
                                double num2 = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, point.Bounds);
                                if (num2 <= 20.0)
                                {
                                    flag = true;
                                    if (num2 < num)
                                    {
                                        snappedConnectionPoint = point;
                                        num = num2;
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            list.AddRange(collection);
                        }
                    }
                }
                if (snappedConnectionPoint != null)
                {
                    foreach (ConnectionPoint point2 in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
                    {
                        if (!list.Contains(point2))
                        {
                            list.Add(point2);
                        }
                    }
                }
            }
            return(list.ToArray());
        }
        private void Invalidate()
        {
            WorkflowView service = this.GetService(typeof(WorkflowView)) as WorkflowView;

            if (service != null)
            {
                Rectangle logicalRectangle = DesignerGeometryHelper.RectangleFromLineSegments(this.GetPointsFromEditPoints(this.editPoints).ToArray());
                logicalRectangle.Inflate(1, 1);
                service.InvalidateLogicalRectangle(logicalRectangle);
            }
        }
        public virtual bool HitTest(Point point)
        {
            Size selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
            ReadOnlyCollection <Point> connectorSegments = this.ConnectorSegments;

            for (int i = 1; i < connectorSegments.Count; i++)
            {
                Point[] line = new Point[] { connectorSegments[i - 1], connectorSegments[i] };
                if (DesignerGeometryHelper.PointOnLineSegment(point, line, selectionSize))
                {
                    return(true);
                }
            }
            return(false);
        }
 private void AddEditPoints(EditPoint.EditPointTypes editPointType)
 {
     if (editPointType == EditPoint.EditPointTypes.ConnectionEditPoint)
     {
         if ((this.editPoints.Count == 0) || !this.editPoints[0].EditedConnectionPoint.Equals(this.Source))
         {
             this.editPoints.Insert(0, new EditPoint(this, this.Source));
         }
         if ((this.editPoints.Count < 2) || !this.editPoints[this.editPoints.Count - 1].EditedConnectionPoint.Equals(this.Target))
         {
             this.editPoints.Add(new EditPoint(this, this.Target));
         }
     }
     else if (editPointType == EditPoint.EditPointTypes.MidSegmentEditPoint)
     {
         int num = this.Source.Bounds.Width * 4;
         for (int i = 0; i < (this.editPoints.Count - 1); i++)
         {
             if ((this.editPoints[i].Type != EditPoint.EditPointTypes.MidSegmentEditPoint) && (this.editPoints[i + 1].Type != EditPoint.EditPointTypes.MidSegmentEditPoint))
             {
                 Point[] segments = new Point[] { this.editPoints[i].Location, this.editPoints[i + 1].Location };
                 if (DesignerGeometryHelper.DistanceOfLineSegments(segments) > num)
                 {
                     Point point = DesignerGeometryHelper.MidPointOfLineSegment(this.editPoints[i].Location, this.editPoints[i + 1].Location);
                     this.editPoints.Insert(i + 1, new EditPoint(this, EditPoint.EditPointTypes.MidSegmentEditPoint, point));
                 }
             }
         }
     }
     else if ((editPointType == EditPoint.EditPointTypes.MultiSegmentEditPoint) && (this.editPoints.Count == 2))
     {
         List <Point> list = new List <Point>(this.editedConnector.ConnectorSegments);
         if ((list.Count > 0) && (list[0] == this.Source.Location))
         {
             list.RemoveAt(0);
         }
         if ((list.Count > 0) && (list[list.Count - 1] == this.Target.Location))
         {
             list.RemoveAt(list.Count - 1);
         }
         List <EditPoint> list2 = new List <EditPoint>();
         for (int j = 0; j < list.Count; j++)
         {
             list2.Add(new EditPoint(this, EditPoint.EditPointTypes.MultiSegmentEditPoint, list[j]));
         }
         this.editPoints.InsertRange(this.editPoints.Count - 1, list2.ToArray());
     }
 }
 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));
             }
         }
     }
 }
        private static IList <Point> GetDesignerEscapeCover(ActivityDesigner designer, ICollection <object> escapeLocations)
        {
            Rectangle bounds = designer.Bounds;
            Dictionary <DesignerEdges, List <Point> > dictionary = new Dictionary <DesignerEdges, List <Point> >();

            foreach (object obj2 in escapeLocations)
            {
                DesignerEdges none  = DesignerEdges.None;
                Point         empty = Point.Empty;
                if (obj2 is ConnectionPoint)
                {
                    none  = ((ConnectionPoint)obj2).ConnectionEdge;
                    empty = ((ConnectionPoint)obj2).Location;
                }
                else if (obj2 is Point)
                {
                    empty = (Point)obj2;
                    none  = DesignerGeometryHelper.ClosestEdgeToPoint((Point)obj2, bounds, DesignerEdges.All);
                }
                if (none != DesignerEdges.None)
                {
                    List <Point> list = null;
                    if (!dictionary.ContainsKey(none))
                    {
                        list = new List <Point>();
                        dictionary.Add(none, list);
                    }
                    else
                    {
                        list = dictionary[none];
                    }
                    list.Add(empty);
                }
            }
            Size margin = WorkflowTheme.CurrentTheme.AmbientTheme.Margin;

            bounds.Inflate(margin);
            Dictionary <DesignerEdges, Point[]> dictionary2 = new Dictionary <DesignerEdges, Point[]>();

            Point[] pointArray2 = new Point[] { new Point(bounds.Left, bounds.Top), new Point(bounds.Left, bounds.Bottom) };
            dictionary2.Add(DesignerEdges.Left, pointArray2);
            Point[] pointArray3 = new Point[] { new Point(bounds.Left, bounds.Top), new Point(bounds.Right, bounds.Top) };
            dictionary2.Add(DesignerEdges.Top, pointArray3);
            Point[] pointArray4 = new Point[] { new Point(bounds.Right, bounds.Top), new Point(bounds.Right, bounds.Bottom) };
            dictionary2.Add(DesignerEdges.Right, pointArray4);
            Point[] pointArray5 = new Point[] { new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom) };
            dictionary2.Add(DesignerEdges.Bottom, pointArray5);
            List <Point> list2 = new List <Point>();

            foreach (DesignerEdges edges2 in dictionary2.Keys)
            {
                if (dictionary.ContainsKey(edges2))
                {
                    Point[]      pointArray = dictionary2[edges2];
                    List <Point> list3      = dictionary[edges2];
                    List <Point> list4      = new List <Point>();
                    switch (edges2)
                    {
                    case DesignerEdges.Left:
                        list4.Add(new Point(pointArray[0].X, pointArray[0].Y));
                        for (int j = 0; j < list3.Count; j++)
                        {
                            Point point2 = list3[j];
                            if (((point2.X > pointArray[0].X) && (point2.Y > pointArray[0].Y)) && (point2.Y < pointArray[1].Y))
                            {
                                list4.Add(new Point(pointArray[0].X, point2.Y - 1));
                                list4.Add(new Point(point2.X + 1, point2.Y - 1));
                                list4.Add(new Point(point2.X + 1, point2.Y + 1));
                                list4.Add(new Point(pointArray[0].X, point2.Y + 1));
                            }
                        }
                        list4.Add(new Point(pointArray[0].X, pointArray[1].Y));
                        break;

                    case DesignerEdges.Right:
                        list4.Add(new Point(pointArray[0].X, pointArray[0].Y));
                        for (int k = 0; k < list3.Count; k++)
                        {
                            Point point3 = list3[k];
                            if (((point3.X < pointArray[0].X) && (point3.Y > pointArray[0].Y)) && (point3.Y < pointArray[1].Y))
                            {
                                list4.Add(new Point(pointArray[0].X, point3.Y - 1));
                                list4.Add(new Point(point3.X - 1, point3.Y - 1));
                                list4.Add(new Point(point3.X - 1, point3.Y + 1));
                                list4.Add(new Point(pointArray[0].X, point3.Y + 1));
                            }
                        }
                        list4.Add(new Point(pointArray[0].X, pointArray[1].Y));
                        break;

                    case DesignerEdges.Top:
                        list4.Add(new Point(pointArray[0].X, pointArray[0].Y));
                        for (int m = 0; m < list3.Count; m++)
                        {
                            Point point4 = list3[m];
                            if (((point4.Y > pointArray[0].Y) && (point4.X > pointArray[0].X)) && (point4.X < pointArray[1].X))
                            {
                                list4.Add(new Point(point4.X - 1, pointArray[0].Y));
                                list4.Add(new Point(point4.X - 1, point4.Y + 1));
                                list4.Add(new Point(point4.X + 1, point4.Y + 1));
                                list4.Add(new Point(point4.X + 1, pointArray[0].Y));
                            }
                        }
                        list4.Add(new Point(pointArray[1].X, pointArray[0].Y));
                        break;

                    case DesignerEdges.Bottom:
                        list4.Add(new Point(pointArray[0].X, pointArray[0].Y));
                        for (int n = 0; n < list3.Count; n++)
                        {
                            Point point5 = list3[n];
                            if (((point5.Y < pointArray[0].Y) && (point5.X > pointArray[0].X)) && (point5.X < pointArray[1].X))
                            {
                                list4.Add(new Point(point5.X - 1, pointArray[0].Y));
                                list4.Add(new Point(point5.X - 1, point5.Y - 1));
                                list4.Add(new Point(point5.X + 1, point5.Y - 1));
                                list4.Add(new Point(point5.X + 1, pointArray[0].Y));
                            }
                        }
                        list4.Add(new Point(pointArray[1].X, pointArray[0].Y));
                        break;
                    }
                    for (int i = 1; i < list4.Count; i++)
                    {
                        list2.Add(list4[i - 1]);
                        list2.Add(list4[i]);
                    }
                    continue;
                }
                list2.AddRange(dictionary2[edges2]);
            }
            return(list2.AsReadOnly());
        }
Example #13
0
        private static ConnectionPoint[] GetSnappableConnectionPoints(Point currentPoint, ConnectionPoint sourceConnectionPoint, ConnectionPoint activeConnectionPoint, ActivityDesigner activityDesigner, out ConnectionPoint snappedConnectionPoint)
        {
            //If the activity designer is composite activity designer then we will go through its children else we will go through its connection points
            snappedConnectionPoint = null;

            List <ConnectionPoint> snappableConnectionPoints = new List <ConnectionPoint>();

            FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeConnectionPoint.AssociatedDesigner);

            if (connectorContainer != null)
            {
                FreeformActivityDesigner freeFormDesigner = activityDesigner as FreeformActivityDesigner;
                List <ActivityDesigner>  designersToCheck = new List <ActivityDesigner>();
                designersToCheck.Add(activityDesigner);
                if (freeFormDesigner != null)
                {
                    designersToCheck.AddRange(freeFormDesigner.ContainedDesigners);
                }

                double minimumDistance = ConnectionManager.SnapHighlightDistance;
                foreach (ActivityDesigner designer in designersToCheck)
                {
                    if (ConnectionManager.GetConnectorContainer(designer) == connectorContainer)
                    {
                        bool addValidSnapPoints = false;
                        List <ConnectionPoint> validSnapPoints = new List <ConnectionPoint>();

                        ReadOnlyCollection <ConnectionPoint> snapPoints = designer.GetConnectionPoints(DesignerEdges.All);
                        foreach (ConnectionPoint snapPoint in snapPoints)
                        {
                            if (!snapPoint.Equals(activeConnectionPoint) &&
                                connectorContainer.CanConnectContainedDesigners(sourceConnectionPoint, snapPoint))
                            {
                                validSnapPoints.Add(snapPoint);

                                double distanceToDesigner = DesignerGeometryHelper.DistanceFromPointToRectangle(currentPoint, snapPoint.Bounds);
                                if (distanceToDesigner <= ConnectionManager.SnapHighlightDistance)
                                {
                                    addValidSnapPoints = true;
                                    if (distanceToDesigner < minimumDistance)
                                    {
                                        snappedConnectionPoint = snapPoint;
                                        minimumDistance        = distanceToDesigner;
                                    }
                                }
                            }
                        }

                        if (addValidSnapPoints)
                        {
                            snappableConnectionPoints.AddRange(validSnapPoints);
                        }
                    }
                }

                if (snappedConnectionPoint != null)
                {
                    foreach (ConnectionPoint connectionPoint in snappedConnectionPoint.AssociatedDesigner.GetConnectionPoints(DesignerEdges.All))
                    {
                        if (!snappableConnectionPoints.Contains(connectionPoint))
                        {
                            snappableConnectionPoints.Add(connectionPoint);
                        }
                    }
                }
            }

            return(snappableConnectionPoints.ToArray());
        }