// referenceTransitionModelItem is used when a connector is re-linked.
        void CreateTransition(ConnectionPoint sourceConnPoint, ConnectionPoint destConnPoint, ModelItem referenceTransitionModelItem, bool isSourceMoved)
        {
            Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor.");

            WorkflowViewElement srcDesigner = sourceConnPoint.ParentDesigner as WorkflowViewElement;
            WorkflowViewElement destDesigner = destConnPoint.ParentDesigner as WorkflowViewElement;
            Debug.Assert(srcDesigner is StateDesigner && destDesigner is StateDesigner, "The source and destination designers should both be StateDesigner");

            ModelItem srcModelItem = srcDesigner.ModelItem;
            ModelItem destModelItem = destDesigner.ModelItem;
            ModelItem transitionModelItem = null;

            // We are moving the connector.
            if (referenceTransitionModelItem != null && referenceTransitionModelItem.ItemType == typeof(Transition))
            {
                transitionModelItem = referenceTransitionModelItem;
                // We are moving the start of the connector. We only preserve the trigger if it is not shared.
                if(isSourceMoved)
                {
                    Transition referenceTransition = referenceTransitionModelItem.GetCurrentValue() as Transition;
                    ModelItem stateModelItem = GetParentStateModelItemForTransition(referenceTransitionModelItem);
                    State state = stateModelItem.GetCurrentValue() as State;
                    bool isTriggerShared = false;
                    foreach (Transition transition in state.Transitions)
                    {
                        if (transition != referenceTransition && transition.Trigger == referenceTransition.Trigger)
                        {
                            isTriggerShared = true;
                            break;
                        }
                    }
                    if (isTriggerShared)
                    {
                        transitionModelItem.Properties[TransitionDesigner.TriggerPropertyName].SetValue(null);
                    }
                }
                transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destModelItem);
                srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem);
            }
            // We are creating a new connector. 
            else
            {
                Transition newTransition = new Transition() { DisplayName = string.Empty };
                newTransition.To = destModelItem.GetCurrentValue() as State;
                // Assign the shared trigger.
                if (sourceConnPoint.AttachedConnectors.Count > 0)
                {
                    Connector connector = sourceConnPoint.AttachedConnectors[0];
                    Transition existingTransition = StateContainerEditor.GetConnectorModelItem(connector).GetCurrentValue() as Transition;
                    newTransition.Trigger = existingTransition.Trigger;
                }
                transitionModelItem = srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(newTransition);
            }
            if (transitionModelItem != null)
            {
                PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnPoint, destConnPoint));
                this.StoreConnectorLocationViewState(transitionModelItem, connectorViewState, true);
            }
        }
 static void DrawConnectionPoint(ConnectionPoint connPoint, Point actualLocation, Brush renderBrush, Pen renderPen, DrawingContext drawingContext)
 {
     // actualLocation is the point on the Edge with respect to the coordinate system defined by the top left corner of the adorned element
     // We will need this transparent rectangle to make sure OnMouseOver event can be triggered, for hit test.
     drawingContext.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0),
         new Rect(actualLocation + connPoint.HitTestOffset, connPoint.HitTestSize));
     drawingContext.DrawRectangle(renderBrush, renderPen,
         new Rect(actualLocation + connPoint.DrawingOffset, connPoint.DrawingSize));
 }
        // referenceConnector is used when we are re-linking the connector.
        internal ConnectorCreationResult CreateConnectorGesture(ConnectionPoint sourceConnectionPoint, ConnectionPoint destConnectionPoint, Connector referenceConnector, bool isConnectorStartMoved)
        {
            Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor.");
            Debug.Assert(sourceConnectionPoint != null, "sourceConnectionPoint is null.");
            Debug.Assert(destConnectionPoint != null, "destConnectionPoint is null.");
            ConnectorCreationResult result = ConnectorCreationResult.OtherFailure;
            if (destConnectionPoint.PointType != ConnectionPointType.Outgoing && sourceConnectionPoint.PointType != ConnectionPointType.Incoming)
            {
                if (sourceConnectionPoint.ParentDesigner is StateDesigner)
                {
                    bool sameDestination = false;
                    ModelItem refTransitionModelItem = null;
                    if(referenceConnector != null)
                    {
                        refTransitionModelItem = StateContainerEditor.GetConnectorModelItem(referenceConnector);
                        ModelItem destStateModelItem = ((StateDesigner)destConnectionPoint.ParentDesigner).ModelItem;
                        if (refTransitionModelItem != null && refTransitionModelItem.Properties[TransitionDesigner.ToPropertyName].Value == destStateModelItem)
                        {
                            sameDestination = true;
                        }
                    }

                    // We do not allow transitions to composite states unless we don't change the transition destination 
                    // (e.g., we are moving the start of a connector).
                    if (!sameDestination && !((StateDesigner)destConnectionPoint.ParentDesigner).IsSimpleState())
                    {
                        result = ConnectorCreationResult.CannotCreateTransitionToCompositeState;
                    }
                    // We do not allow transitions from an ancestor to its descendant
                    else if (StateContainerEditor.IsDescendantStateOf(((StateDesigner)destConnectionPoint.ParentDesigner).ModelItem, ((StateDesigner)sourceConnectionPoint.ParentDesigner).ModelItem))
                    {
                        result = ConnectorCreationResult.CannotCreateTransitionFromAncestorToDescendant;
                    }
                    else
                    {
                        using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.CreateTransition))
                        {
                            if (refTransitionModelItem != null)
                            {
                                this.CreateTransition(sourceConnectionPoint, destConnectionPoint, refTransitionModelItem, isConnectorStartMoved);
                            }
                            else
                            {
                                this.CreateTransition(sourceConnectionPoint, destConnectionPoint, null, false);
                            }
                            result = ConnectorCreationResult.Success;
                            es.Complete();
                        }
                    }
                }
                else if (sourceConnectionPoint.ParentDesigner is InitialNode)
                {
                    StateDesigner destDesigner = (StateDesigner)destConnectionPoint.ParentDesigner;
                    // We only allow simple states to be set as the initial state
                    if (!destDesigner.IsSimpleState())
                    {
                        result = ConnectorCreationResult.CannotSetCompositeStateAsInitialState;
                    }
                    else if (destDesigner.IsFinalState())
                    {
                        result = ConnectorCreationResult.CannotSetFinalStateAsInitialState;
                    }
                    else
                    {
                        ModelItem destModelItem = destDesigner.ModelItem;
                        using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.SetInitialState))
                        {
                            this.StateMachineModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(destModelItem);
                            PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnectionPoint, destConnectionPoint));
                            this.StoreConnectorLocationViewState(this.StateMachineModelItem, connectorViewState, true);
                            result = ConnectorCreationResult.Success;
                            es.Complete();
                        }
                    }
                }
            }
            return result;
        }
Example #4
0
 public static void SetSourceConnectionPoint(DependencyObject obj, ConnectionPoint connectionPoint)
 {
     obj.SetValue(FreeFormPanel.SourceConnectionPointProperty, connectionPoint);
 }
Example #5
0
        static public Point GetLocationRelativeToOutmostPanel(ConnectionPoint connectionPoint)
        {
            FreeFormPanel parentPanel = StateContainerEditor.GetVisualAncestor <FreeFormPanel>(connectionPoint.ParentDesigner);

            return(parentPanel.GetLocationRelativeToOutmostPanel(connectionPoint.Location));
        }
Example #6
0
 public static void SetSourceConnectionPoint(DependencyObject obj, ConnectionPoint connectionPoint)
 {
     obj.SetValue(FreeFormPanel.SourceConnectionPointProperty, connectionPoint);
 }
Example #7
0
 static public Point GetLocationRelativeToOutmostPanel(ConnectionPoint connectionPoint)
 {
     FreeFormPanel parentPanel = StateContainerEditor.GetVisualAncestor<FreeFormPanel>(connectionPoint.ParentDesigner);
     return parentPanel.GetLocationRelativeToOutmostPanel(connectionPoint.Location);
 }
        void UpdateStateMachineOnConnectorMoved(ConnectionPoint knownConnectionPoint, Point newPoint, Connector movedConnector, bool isConnectorStartMoved)
        {
            HitTestResult hitTestResult = VisualTreeHelper.HitTest(this.panel, newPoint);
            if (hitTestResult == null)
            {
                return;
            }

            UIElement newViewElement = null;
            ConnectionPoint newConnectionPoint = null;

            //The case where the Connector is dropped on a ConnectionPoint.
            if (this.lastConnectionPointMouseUpElement != null)
            {
                newConnectionPoint = StateContainerEditor.ConnectionPointHitTest(this.lastConnectionPointMouseUpElement, newPoint);
                if (newConnectionPoint != null)
                {
                    newViewElement = this.lastConnectionPointMouseUpElement;
                }
                this.lastConnectionPointMouseUpElement = null;
            }

            //The case where the link is dropped on a shape.
            if (newViewElement == null)
            {
                newViewElement = StateContainerEditor.GetVisualAncestor<WorkflowViewElement>(hitTestResult.VisualHit);
            }

            if (newViewElement != null)
            {
                if (this.panel.IsAncestorOf(newViewElement))
                {
                    using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.MoveLink))
                    {
                        // Remove the old connector ModelItem
                        this.DeleteConnectorModelItem(movedConnector);
                        // Create new connector
                        ConnectorCreationResult result = ConnectorCreationResult.OtherFailure;
                        if (!isConnectorStartMoved)
                        {
                            if (newConnectionPoint == null)
                            {
                                result = CreateConnectorGesture(knownConnectionPoint, newViewElement, movedConnector, false);
                            }
                            else
                            {
                                result = CreateConnectorGesture(knownConnectionPoint, newConnectionPoint, movedConnector, false);
                            }
                        }
                        else
                        {
                            // Don't allow moving the start of the initial node connector to a state
                            if (!(newViewElement is StateDesigner && StateContainerEditor.IsConnectorFromInitialNode(movedConnector)))
                            {
                                if (newConnectionPoint == null)
                                {
                                    result = CreateConnectorGesture(newViewElement, knownConnectionPoint, movedConnector, true);
                                }
                                else
                                {
                                    result = CreateConnectorGesture(newConnectionPoint, knownConnectionPoint, movedConnector, true);
                                }
                            }
                        }

                        if (result == ConnectorCreationResult.Success)
                        {
                            es.Complete();
                        }
                        else
                        {
                            StateContainerEditor.ReportConnectorCreationError(result);
                            es.Revert();
                        }
                    }
                }
            }
        }
 void OnConnectionPointMouseDown(object sender, MouseButtonEventArgs e)
 {
     UIElement srcElement = ((Adorner)sender).AdornedElement as UIElement;
     this.activeSrcConnectionPoint = ConnectionPointHitTest(srcElement, e.GetPosition(this.panel));
     e.Handled = true;
 }
 void OnConnectorStartDotMouseDown(object sender, MouseButtonEventArgs e)
 {
     DependencyObject startDot = (DependencyObject)sender;
     Connector connector = StateContainerEditor.GetVisualAncestor<Connector>(startDot);
     this.activeSrcConnectionPoint = FreeFormPanel.GetSourceConnectionPoint(connector);
     e.Handled = true;
 }
 void OnConnectorStartDotMouseUp(object sender, MouseButtonEventArgs e)
 {
     this.activeSrcConnectionPoint = null;
     RemoveAdorner(this.panel, typeof(ConnectorCreationAdorner));
 }
 //widthFraction and heightFraction determine the location of the ConnectionPoint on the UIElement.
 ConnectionPoint CreateConnectionPoint(UIElement element, double widthFraction, double heightFraction, EdgeLocation location, ConnectionPointType type)
 {
     ConnectionPoint connectionPoint = new ConnectionPoint();
     connectionPoint.EdgeLocation = location;
     connectionPoint.PointType = type;
     connectionPoint.ParentDesigner = element;
     BindingOperations.SetBinding(connectionPoint, ConnectionPoint.LocationProperty, GetConnectionPointBinding(element as FrameworkElement, widthFraction, heightFraction));
     return connectionPoint;
 }
 Connector CreateConnector(ConnectionPoint srcConnPoint, ConnectionPoint destConnPoint, PointCollection points, ModelItem connectorModelItem)
 {
     Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor.");
     Connector connector = new Connector();
     connector.FocusVisualStyle = null;
     connector.Focusable = true;
     DesignerView.SetCommandMenuMode(connector, CommandMenuMode.NoCommandMenu);
     if (connectorModelItem != null && connectorModelItem.ItemType == typeof(Transition))
     {
         SetConnectorLabel(connector, connectorModelItem);
         SetConnectorStartDotToolTip(connector.startDotGrid, connectorModelItem);
         connector.IsTransition = true;
         connector.ToolTip = SR.EditTransitionTooltip;
         connector.startDotGrid.MouseDown += new MouseButtonEventHandler(OnConnectorStartDotMouseDown);
         connector.startDotGrid.MouseUp += new MouseButtonEventHandler(OnConnectorStartDotMouseUp);
     }
     connector.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(OnConnectorGotKeyboardFocus);
     connector.RequestBringIntoView += new RequestBringIntoViewEventHandler(OnConnectorRequestBringIntoView);
     connector.GotFocus += new RoutedEventHandler(OnConnectorGotFocus);
     connector.LostFocus += new RoutedEventHandler(OnConnectorLostFocus);
     connector.MouseDoubleClick += new MouseButtonEventHandler(OnConnectorMouseDoubleClick);
     connector.MouseDown += new MouseButtonEventHandler(OnConnectorMouseDown);
     connector.KeyDown += new KeyEventHandler(OnConnectorKeyDown);
     connector.ContextMenuOpening += new ContextMenuEventHandler(OnConnectorContextMenuOpening);
     SetConnectorSrcDestConnectionPoints(connector, srcConnPoint, destConnPoint);
     StateContainerEditor.SetConnectorModelItem(connector, connectorModelItem);
     connector.Unloaded += new RoutedEventHandler(OnConnectorUnloaded);
     connector.Points = points;
     return connector;
 }
 void OnStateContainerGridPreviewMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (!this.IsOutmostStateContainerEditor())
     {
         return;
     }
     UIElement destElement = StateContainerEditor.GetVisualAncestor<WorkflowViewElement>(e.OriginalSource as DependencyObject);
     if (destElement != null && destElement is StateDesigner)
     {
         if (this.activeSrcConnectionPoint != null)
         {
             ConnectorCreationResult result = CreateConnectorGesture(this.activeSrcConnectionPoint, destElement, null, false);
             if (result != ConnectorCreationResult.Success)
             {
                 StateContainerEditor.ReportConnectorCreationError(result);
             }
         }
         RemoveAdorner(destElement, typeof(ConnectionPointsAdorner));
     }
     if (this.activeSrcConnectionPoint != null)
     {
         this.activeSrcConnectionPoint = null;
         RemoveAdorner(this.panel, typeof(ConnectorCreationAdorner));
     }
 }
 void OnStateContainerGridMouseLeave(object sender, MouseEventArgs e)
 {
     if (!this.IsOutmostStateContainerEditor())
     {
         return;
     }
     bool endLinkCreation = !IsVisualHit(sender as UIElement, sender as UIElement, e.GetPosition(sender as IInputElement));
     if (endLinkCreation)
     {
         RemoveAdorner(this.panel, typeof(ConnectorCreationAdorner));
         this.activeSrcConnectionPoint = null;
     }
 }
 internal ConnectorCreationResult CreateConnectorGesture(UIElement source, ConnectionPoint destConnectionPoint, Connector referenceConnector, bool isConnectorStartMoved)
 {
     ConnectionPoint sourceConnectionPoint = GetClosestSrcConnectionPoint(source, destConnectionPoint);
     if (sourceConnectionPoint != null)
     {
         return CreateConnectorGesture(sourceConnectionPoint, destConnectionPoint, referenceConnector, isConnectorStartMoved);
     }
     return ConnectorCreationResult.OtherFailure;
 }
Example #17
0
 static public List<Point> GetEdgeRelativeToOutmostPanel(ConnectionPoint connectionPoint)
 {
     FreeFormPanel parentPanel = StateContainerEditor.GetVisualAncestor<FreeFormPanel>(connectionPoint.ParentDesigner);
     List<Point> edge = new List<Point>();
     foreach (Point point in connectionPoint.Edge)
     {
         edge.Add(parentPanel.GetLocationRelativeToOutmostPanel(point));
     }
     return edge;
 }
 void OnConnectionPointMouseUp(object sender, MouseButtonEventArgs e)
 {
     UIElement dest = ((Adorner)sender).AdornedElement as UIElement;
     if (this.activeSrcConnectionPoint != null)
     {
         ConnectionPoint destConnectionPoint = ConnectionPointHitTest(dest, e.GetPosition(this.panel));
         if (destConnectionPoint != null && !this.activeSrcConnectionPoint.Equals(destConnectionPoint))
         {
             ConnectorCreationResult result = CreateConnectorGesture(this.activeSrcConnectionPoint, destConnectionPoint, null, false);
             if (result != ConnectorCreationResult.Success)
             {
                 StateContainerEditor.ReportConnectorCreationError(result);
             }
         }
         this.activeSrcConnectionPoint = null;
         RemoveAdorner(this.panel, typeof(ConnectorCreationAdorner));
     }
     else
     {
         //This will cause the FreeFormPanel to handle the event and is useful while moving a connector end point.
         this.lastConnectionPointMouseUpElement = dest;
         dest.RaiseEvent(e);
     }
     RemoveAdorner(dest, typeof(ConnectionPointsAdorner));
 }