Ejemplo n.º 1
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());
        }
 public void OnEndEditing(Point point, bool commitChanges)
 {
     if (this.activeEditPoint != null)
     {
         this.Invalidate();
         if (commitChanges)
         {
             this.UpdateEditPoints(point);
             EditPoint activeEditPoint = this.activeEditPoint;
             this.activeEditPoint = null;
             this.UpdateEditPoints(point);
             bool flag = false;
             if (activeEditPoint.Type == EditPoint.EditPointTypes.ConnectionEditPoint)
             {
                 ConnectionManager        service            = this.GetService(typeof(ConnectionManager)) as ConnectionManager;
                 FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(activeEditPoint.EditedConnectionPoint.AssociatedDesigner);
                 if (((service != null) && (service.SnappedConnectionPoint != null)) && (connectorContainer != null))
                 {
                     ConnectionPoint source = this.editedConnector.Source;
                     ConnectionPoint target = this.editedConnector.Target;
                     if (target.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         target = service.SnappedConnectionPoint;
                     }
                     else if (source.Equals(activeEditPoint.EditedConnectionPoint))
                     {
                         source = service.SnappedConnectionPoint;
                     }
                     if ((connectorContainer == ConnectionManager.GetConnectorContainer(target.AssociatedDesigner)) && connectorContainer.CanConnectContainedDesigners(source, target))
                     {
                         this.editedConnector.Source = source;
                         this.editedConnector.Target = target;
                         if (this.editedConnector.ParentDesigner == null)
                         {
                             this.editedConnector = connectorContainer.AddConnector(source, target);
                             WorkflowDesignerLoader loader = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                             if (loader != null)
                             {
                                 loader.SetModified(true);
                             }
                         }
                         connectorContainer.OnContainedDesignersConnected(source, target);
                     }
                     flag = true;
                 }
             }
             else
             {
                 flag = true;
             }
             if (flag)
             {
                 this.editedConnector.SetConnectorSegments(this.GetPointsFromEditPoints(this.editPoints));
                 if (this.editedConnector.ParentDesigner != null)
                 {
                     this.editedConnector.ParentDesigner.OnConnectorChanged(new ConnectorEventArgs(this.editedConnector));
                     WorkflowDesignerLoader loader2 = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                     if (loader2 != null)
                     {
                         loader2.SetModified(true);
                     }
                 }
             }
             this.PerformLayout();
         }
         this.Invalidate();
     }
 }
Ejemplo n.º 3
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());
        }