Esempio n. 1
0
        public void TestSelectInRegionCommand()
        {
            Rect region = new Rect(
                randomizer.NextDouble() * 100,
                randomizer.NextDouble() * 100,
                randomizer.NextDouble() * 100,
                randomizer.NextDouble() * 100);

            bool isCrossSelection = randomizer.Next(2) == 0;

            var cmdOne = new DynCmd.SelectInRegionCommand(region, isCrossSelection);
            var cmdTwo = DuplicateAndCompare(cmdOne);

            Assert.AreEqual(cmdOne.Region.X, cmdTwo.Region.X, 0.000001);
            Assert.AreEqual(cmdOne.Region.Y, cmdTwo.Region.Y, 0.000001);
            Assert.AreEqual(cmdOne.Region.Width, cmdTwo.Region.Width, 0.000001);
            Assert.AreEqual(cmdOne.Region.Height, cmdTwo.Region.Height, 0.000001);
            Assert.AreEqual(cmdOne.IsCrossSelection, cmdTwo.IsCrossSelection);
        }
Esempio 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 Rect(x, y, width, height);

                    var             command         = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);
                    DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel;
                    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);
                    }

                    // Record and begin the drag operation for selected nodes.
                    var             operation       = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                    var             command         = new DynCmd.DragSelectionCommand(mouseCursor, operation);
                    DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel;
                    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);
                }

                return(false); // Mouse event not handled.
            }
Esempio 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 Rect(x, y, width, height);

                    var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection);
                    DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel;
                    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;
                    }

                    // Record and begin the drag operation for selected nodes.
                    var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag;
                    var command = new DynCmd.DragSelectionCommand(mouseCursor, operation);
                    DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel;
                    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);
                }

                return false; // Mouse event not handled.
            }