Ejemplo n.º 1
0
            internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e)
            {
                if (e.ChangedButton != MouseButton.Left)
                {
                    return(false); // We only handle left mouse button for now.
                }
                if (this.currentState == State.WindowSelection)
                {
                    SetCurrentState(State.None);
                    return(true); // Mouse event handled.
                }
                else if (this.currentState == State.NodeReposition)
                {
                    Point mouseCursor = e.GetPosition(sender as IInputElement);
                    var   operation   = DynCmd.DragSelectionCommand.Operation.EndDrag;
                    var   command     = new DynCmd.DragSelectionCommand(mouseCursor.AsDynamoType(), operation);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                    SetCurrentState(State.None); // Dragging operation ended.
                }
                else if (this.currentState == State.DragSetup)
                {
                    SetCurrentState(State.None);
                }
                else if (this.currentState == State.PanMode)
                {
                    // Change cursor back to Pan
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }
                else if (this.currentState == State.OrbitMode)
                {
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }

                return(false); // Mouse event not handled.
            }
Ejemplo n.º 2
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return(false); // Mouse event not handled.
            }
Ejemplo n.º 3
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active 
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever 
                    // it touches the selection box as opposed to only select 
                    // it when it is entirely within the selection box) when 
                    // mouse moves in the opposite direction (i.e. the current 
                    // mouse position is smaller than the point mouse-down 
                    // happened).
                    // 
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return false;
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return true;
                    }

                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());
                }

                return false; // Mouse event not handled.
            }
Ejemplo n.º 4
0
            internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e)
            {
                if (e.ChangedButton != MouseButton.Left)
                    return false; // We only handle left mouse button for now.

                if (this.currentState == State.WindowSelection)
                {
                    SetCurrentState(State.None);
                    return true; // Mouse event handled.
                }
                else if (this.currentState == State.NodeReposition)
                {
                    Point mouseCursor = e.GetPosition(sender as IInputElement);
                    var operation = DynCmd.DragSelectionCommand.Operation.EndDrag;
                    var command = new DynCmd.DragSelectionCommand(mouseCursor.AsDynamoType(), operation);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                    SetCurrentState(State.None); // Dragging operation ended.
                }
                else if (this.currentState == State.DragSetup)
                    SetCurrentState(State.None);
                else if (this.currentState == State.PanMode)
                {
                    // Change cursor back to Pan
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }
                else if (this.currentState == State.OrbitMode)
                {
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }

                return false; // Mouse event not handled.
            }
Ejemplo n.º 5
0
            internal bool HandleMouseMove(object sender, Point mouseCursor)
            {
                if (this.currentState == State.Connection)
                {
                    // If we are currently connecting and there is an active
                    // connector, redraw it to match the new mouse coordinates.
                    owningWorkspace.UpdateActiveConnector(mouseCursor);
                }
                else if (this.currentState == State.WindowSelection)
                {
                    // When the mouse is held down, reposition the drag selection box.
                    double x      = Math.Min(mouseDownPos.X, mouseCursor.X);
                    double y      = Math.Min(mouseDownPos.Y, mouseCursor.Y);
                    double width  = Math.Abs(mouseDownPos.X - mouseCursor.X);
                    double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y);

                    // We perform cross selection (i.e. select a node whenever
                    // it touches the selection box as opposed to only select
                    // it when it is entirely within the selection box) when
                    // mouse moves in the opposite direction (i.e. the current
                    // mouse position is smaller than the point mouse-down
                    // happened).
                    //
                    bool isCrossSelection = mouseCursor.X < mouseDownPos.X;

                    SelectionBoxUpdateArgs args = null;
                    args = new SelectionBoxUpdateArgs(x, y, width, height);
                    args.SetSelectionMode(isCrossSelection);
                    this.owningWorkspace.RequestSelectionBoxUpdate(this, args);

                    var rect = new Dynamo.Utilities.Rect2D(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                }
                else if (this.currentState == State.DragSetup)
                {
                    // There are something in the selection, but none is ILocatable.
                    if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable)))
                    {
                        SetCurrentState(State.None);
                        return(false);
                    }

                    if (Keyboard.Modifiers != ModifierKeys.Control)
                    {
                        // Record and begin the drag operation for selected nodes.
                        var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                        var command   = new DynCmd.DragSelectionCommand(
                            mouseCursor.AsDynamoType(),
                            operation);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        SetCurrentState(State.NodeReposition);
                        return(true);
                    }
                }
                else if (this.currentState == State.NodeReposition)
                {
                    // Update the dragged nodes (note: this isn't recorded).
                    owningWorkspace.UpdateDraggedSelection(mouseCursor.AsDynamoType());

                    var draggedGroups = DynamoSelection.Instance.Selection.OfType <AnnotationModel>();

                    // Here we check if the mouse cursor is inside any Annotation groups
                    var dropGroups = owningWorkspace.Annotations
                                     .Where(x =>
                                            !draggedGroups.Select(a => a.GUID).Contains(x.AnnotationModel.GUID) &&
                                            x.IsExpanded &&
                                            x.AnnotationModel.Rect.Contains(mouseCursor.X, mouseCursor.Y));

                    // In scenarios where there are nested groups, the above will return both
                    // the nested group and the parent group, as the mouse coursor will be inside
                    // both of there rects. In these cases we want to get group that is nested
                    // inside the parent group.
                    var dropGroup = dropGroups
                                    .FirstOrDefault(x => !x.AnnotationModel.HasNestedGroups) ?? dropGroups.FirstOrDefault();


                    // If the dropGroup is null or any of the selected items is already in the dropGroup,
                    // we disable the drop border by setting NodeHoveringState to false
                    var draggedModels = DynamoSelection.Instance.Selection
                                        .OfType <ModelBase>()
                                        .Except(draggedGroups.SelectMany(x => x.Nodes));

                    if (dropGroup is null ||
                        draggedModels
                        .Any(x => owningWorkspace.Model.Annotations.ContainsModel(x)))
                    {
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);
                    }

                    // If we are dragging groups over a group that is already nested
                    // we return as we cant have more than one nested layer
                    else if (draggedGroups.Any() &&
                             owningWorkspace.Model.Annotations.ContainsModel(dropGroup.AnnotationModel) ||
                             draggedGroups.Any(x => x.HasNestedGroups))
                    {
                        return(false); // Mouse event not handled.
                    }

                    // If the dropGroups NodeHoveringState is set to false
                    // we need to set it to true for the drop border to be displayed.
                    else if (!dropGroup.NodeHoveringState)
                    {
                        // make sure there are no other group
                        // set to NodeHoveringState before setting
                        // the current group.
                        // If we dont do this there are scenarios where
                        // two groups are very close and a node is dragged
                        // quickly between the two where the hovering state
                        // is not reset.
                        owningWorkspace.Annotations
                        .Where(x => x.NodeHoveringState)
                        .ToList()
                        .ForEach(x => x.NodeHoveringState = false);

                        // If the dropGroup belongs to another group
                        // we need to check if the parent group is collapsed
                        // if it is we dont want to be able to add new
                        // models to the drop group.
                        var parentGroup = owningWorkspace.Annotations
                                          .Where(x => x.AnnotationModel.ContainsModel(dropGroup.AnnotationModel))
                                          .FirstOrDefault();
                        if (parentGroup != null && !parentGroup.IsExpanded)
                        {
                            return(false);
                        }

                        dropGroup.NodeHoveringState = true;
                    }
                }
Ejemplo n.º 6
0
            internal bool HandleMouseRelease(object sender, MouseButtonEventArgs e)
            {
                if (e.ChangedButton != MouseButton.Left)
                {
                    return(false); // We only handle left mouse button for now.
                }
                if (this.currentState == State.WindowSelection)
                {
                    SetCurrentState(State.None);
                    return(true); // Mouse event handled.
                }
                else if (this.currentState == State.NodeReposition)
                {
                    Point mouseCursor = e.GetPosition(sender as IInputElement);
                    var   operation   = DynCmd.DragSelectionCommand.Operation.EndDrag;
                    var   command     = new DynCmd.DragSelectionCommand(mouseCursor.AsDynamoType(), operation);

                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                    // When mouse is released get any group with NodeHoveringState
                    // set to true (this should only ever be one),
                    // and add all ModelBase items in selection to that group
                    var dropGroup = owningWorkspace.Annotations
                                    .Where(x => x.NodeHoveringState)
                                    .FirstOrDefault();

                    if (dropGroup != null)
                    {
                        // If groups are being dragged store them here
                        var dragedGroups = DynamoSelection.Instance.Selection
                                           .OfType <AnnotationModel>()
                                           .ToList();

                        // We do not want to add dragged groups content twice
                        // so we filter it out here.
                        var modelsToAdd = DynamoSelection.Instance.Selection
                                          .OfType <ModelBase>()
                                          .Except(dragedGroups.SelectMany(x => x.Nodes))
                                          .ToList();

                        // AddModelsToGroupModelCommand adds models to the selected group
                        // therefor we add the dropGroup to the selection before calling
                        // the command.
                        DynamoSelection.Instance.Selection.AddUnique(dropGroup.AnnotationModel);

                        // If the dropgroup has nested groups they will be marked as
                        // IsSelected when adding the dropgroup to the selection.
                        // We need to unselect all nested groups before we try and add
                        // the dragged node this group, if we dont do this we might
                        // add the node to the wrong group.
                        if (dropGroup.AnnotationModel.HasNestedGroups)
                        {
                            dropGroup.Nodes
                            .OfType <AnnotationModel>()
                            .ToList()
                            .ForEach(x => x.Deselect());
                        }

                        foreach (var item in modelsToAdd)
                        {
                            if (item == dropGroup.AnnotationModel)
                            {
                                continue;
                            }

                            // If the item is a group and the hovered group
                            // is not a nested group, we add it to the dropGroup
                            if (item is AnnotationModel &&
                                !owningWorkspace.Model.Annotations.ContainsModel(dropGroup.AnnotationModel))
                            {
                                owningWorkspace.DynamoViewModel.AddGroupToGroupModelCommand.Execute(dropGroup.AnnotationModel.GUID);
                                continue;
                            }

                            owningWorkspace.DynamoViewModel.AddModelsToGroupModelCommand.Execute(null);
                        }
                        dropGroup.NodeHoveringState = false;
                        dropGroup.SelectAll();
                    }

                    SetCurrentState(State.None); // Dragging operation ended.
                }
                else if (this.currentState == State.DragSetup)
                {
                    SetCurrentState(State.None);
                }
                else if (this.currentState == State.PanMode)
                {
                    // Change cursor back to Pan
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }
                else if (this.currentState == State.OrbitMode)
                {
                    var c = CursorLibrary.GetCursor(CursorSet.HandPan);
                    owningWorkspace.CurrentCursor = c;
                }

                return(false); // Mouse event not handled.
            }