コード例 #1
0
        /// <summary>
        /// Do a one setup of the ports
        /// </summary>
        private void SetupInitialPortViewModels()
        {
            foreach (var item in nodeLogic.InPorts)
            {
                PortViewModel inportViewModel = SubscribePortEvents(item);
                InPorts.Add(inportViewModel);
            }

            foreach (var item in nodeLogic.OutPorts)
            {
                PortViewModel outportViewModel = SubscribePortEvents(item);
                OutPorts.Add(outportViewModel);
            }
        }
コード例 #2
0
            internal bool HandlePortClicked(PortViewModel portViewModel)
            {
                // We only entertain port clicking when the current state is idle,
                // or when it is already having a connector being established.
                if (currentState != State.None && (currentState != State.Connection))
                {
                    return(false);
                }

                var portModel = portViewModel.PortModel;

                var workspaceViewModel = owningWorkspace.DynamoViewModel.CurrentSpaceViewModel;

                if (this.currentState != State.Connection) // Not in a connection attempt...
                {
                    Guid nodeId    = portModel.Owner.GUID;
                    int  portIndex = portModel.Index;

                    var mode    = DynamoModel.MakeConnectionCommand.Mode.Begin;
                    var command = new DynamoModel.MakeConnectionCommand(nodeId, portIndex, portModel.PortType, mode);
                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                    if (null != owningWorkspace.activeConnector)
                    {
                        this.currentState              = State.Connection;
                        owningWorkspace.CurrentCursor  = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                        owningWorkspace.IsCursorForced = false;
                    }
                }
                else  // Attempt to complete the connection
                {
                    // Check if connection is valid
                    if (owningWorkspace.CheckActiveConnectorCompatibility(portViewModel))
                    {
                        Guid nodeId    = portModel.Owner.GUID;
                        int  portIndex = portModel.Index;

                        var mode    = DynamoModel.MakeConnectionCommand.Mode.End;
                        var command = new DynamoModel.MakeConnectionCommand(nodeId,
                                                                            portIndex, portModel.PortType, mode);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                        owningWorkspace.CurrentCursor  = null;
                        owningWorkspace.IsCursorForced = false;
                        this.currentState = State.None;
                    }
                }

                return(true);
            }
コード例 #3
0
            internal bool HandlePortClicked(PortViewModel portViewModel)
            {
                // We only entertain port clicking when the current state is idle,
                // or when it is already having a connector being established.
                if (currentState != State.None && (currentState != State.Connection))
                {
                    return(false);
                }

                PortModel          portModel          = portViewModel.PortModel;
                DynamoViewModel    dynamoViewModel    = dynSettings.Controller.DynamoViewModel;
                WorkspaceViewModel workspaceViewModel = dynamoViewModel.CurrentSpaceViewModel;

                if (this.currentState != State.Connection) // Not in a connection attempt...
                {
                    PortType portType  = PortType.INPUT;
                    Guid     nodeId    = portModel.Owner.GUID;
                    int      portIndex = portModel.Owner.GetPortIndex(portModel, out portType);

                    dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand(
                                                       nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.Begin));

                    if (owningWorkspace.IsConnecting)
                    {
                        this.currentState = State.Connection;
                    }
                }
                else  // Attempt to complete the connection
                {
                    PortType portType  = PortType.INPUT;
                    Guid     nodeId    = portModel.Owner.GUID;
                    int      portIndex = portModel.Owner.GetPortIndex(portModel, out portType);

                    dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand(
                                                       nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.End));

                    this.currentState = State.None;
                }

                return(true);
            }
コード例 #4
0
ファイル: WorkspaceView.xaml.cs プロジェクト: nmeek/Dynamo
        private void OnMouseRelease(object sender, MouseButtonEventArgs e)
        {
            if (e == null) return; // in certain bizarre cases, e can be null

            this.snappedPort = null;

            var wvm = (DataContext as WorkspaceViewModel);
            if (wvm == null) return;
            wvm.HandleMouseRelease(workBench, e);
        }
コード例 #5
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            this.snappedPort = null;

            bool mouseMessageHandled = false;

            // If we are currently connecting and there is an active 
            // connector, redraw it to match the new mouse coordinates.
            if (ViewModel.IsSnapping)
            {
                if (ViewModel.portViewModel != null)
                {
                    if (ViewModel.CheckActiveConnectorCompatibility(ViewModel.portViewModel))
                    {
                        mouseMessageHandled = true;
                        ViewModel.HandleMouseMove(workBench, ViewModel.portViewModel.Center);
                    }
                }
                else
                    ViewModel.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
            }

            if (ViewModel.IsInIdleState)
            {
                // Find the dependency object directly under the mouse 
                // cursor, then see if it represents a port. If it does,
                // then determine its type, we would like to show the 
                // "ArcRemoving" cursor when the mouse is over an out port.
                Point mouse = e.GetPosition((UIElement)sender);
                var dependencyObject = ElementUnderMouseCursor(mouse);
                PortViewModel pvm = PortFromHitTestResult(dependencyObject);

                if (null != pvm && (pvm.PortType == PortType.Input))
                    this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                else
                    this.Cursor = null;
            }

            // If selection is going to be dragged and ctrl is pressed.
            if (ViewModel.IsDragging && Keyboard.Modifiers == ModifierKeys.Control)
            {
                var currentMousePosition = e.GetPosition(null);

                // Set initialMousePosition here, so that we can use it in OnDragOver.
                initialMousePosition = e.GetPosition(WorkspaceElements);

                // Check that current mouse position is far enough from start position.
                var canDrag =
                    (Math.Abs(currentMousePosition.X - startMousePosition.X) >
                     SystemParameters.MinimumHorizontalDragDistance) &&
                    (Math.Abs(currentMousePosition.Y - startMousePosition.Y) >
                     SystemParameters.MinimumVerticalDragDistance) &&
                    e.OriginalSource is DragCanvas;

                if (canDrag)
                {
                    DragAndDrop(e.GetPosition(WorkspaceElements));
                    mouseMessageHandled = true;
                }
            }

            if (!mouseMessageHandled)
            {
                ViewModel.HandleMouseMove(workBench, e);
            }
        }
コード例 #6
0
        private void OnMouseRelease(object sender, MouseButtonEventArgs e)
        {
            if (e == null) return; // in certain bizarre cases, e can be null

            snappedPort = null;
            if (ViewModel == null) return;

            // check IsInIdleState and IsPanning before finishing an action with HandleMouseRelease
            var returnToSearch = (ViewModel.IsInIdleState || ViewModel.IsPanning) 
                && e.ChangedButton == MouseButton.Right && Keyboard.Modifiers == ModifierKeys.Control;

            ViewModel.HandleMouseRelease(workBench, e);
            if (returnToSearch)
            {
                ViewModel.DynamoViewModel.SearchViewModel.OnRequestFocusSearch();
                // do not open context menu in this case
                e.Handled = true;
            }
        }
コード例 #7
0
        private void OnMouseRelease(object sender, MouseButtonEventArgs e)
        {
            if (e == null) return; // in certain bizarre cases, e can be null

            snappedPort = null;
            if (ViewModel == null) return;

            // check IsInIdleState and IsPanning before finishing an action with HandleMouseRelease
            var returnToSearch = (ViewModel.IsInIdleState || ViewModel.IsPanning)
                && e.ChangedButton == MouseButton.Right && Keyboard.Modifiers == ModifierKeys.Control;

            ViewModel.HandleMouseRelease(workBench, e);
            ContextMenuPopup.IsOpen = false;
            if (returnToSearch)
            {
                ViewModel.DynamoViewModel.SearchViewModel.OnRequestFocusSearch();
            }
            else if (e.ChangedButton == MouseButton.Right && e.OriginalSource == zoomBorder)
            {
                // open if workspace is right-clicked itself 
                // (not node, note, not buttons from viewControlPanel such as zoom, pan and so on)
                ContextMenuPopup.IsOpen = true;
            }
        }
コード例 #8
0
            internal bool HandlePortClicked(PortViewModel portViewModel)
            {
                // We only entertain port clicking when the current state is idle,
                // or when it is already having a connector being established.
                if (currentState != State.None && (currentState != State.Connection))
                {
                    return(false);
                }

                var portModel = portViewModel.PortModel;

                var workspaceViewModel = owningWorkspace.DynamoViewModel.CurrentSpaceViewModel;

                if (this.currentState != State.Connection) // Not in a connection attempt...
                {
                    if (Keyboard.Modifiers == ModifierKeys.Alt &&
                        portViewModel.NodeAutoCompleteCommand.CanExecute(portViewModel))
                    {
                        portViewModel.NodeAutoCompleteCommand.Execute(portViewModel);
                        this.currentState              = State.Connection;
                        owningWorkspace.CurrentCursor  = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                        owningWorkspace.IsCursorForced = false;
                        Timestamp = DateTime.Now;
                        return(true);
                    }

                    Guid nodeId    = portModel.Owner.GUID;
                    int  portIndex = portModel.Index;

                    var mode = DynamoModel.MakeConnectionCommand.Mode.Begin;
                    if (Keyboard.Modifiers == ModifierKeys.Shift) //if shift key is down, handle multiple wire reconnections
                    {
                        multipleConnections = true;
                        mode = DynamoModel.MakeConnectionCommand.Mode.BeginShiftReconnections;
                    }
                    else if (Keyboard.Modifiers == ModifierKeys.Control)
                    {
                        // If the control key is held down, check if there is a need to duplicate connections
                        mode = DynamoModel.MakeConnectionCommand.Mode.BeginDuplicateConnection;
                    }

                    var command = new DynamoModel.MakeConnectionCommand(nodeId, portIndex, portModel.PortType, mode);
                    owningWorkspace.DynamoViewModel.ExecuteCommand(command);

                    if (null != owningWorkspace.FirstActiveConnector)
                    {
                        this.currentState              = State.Connection;
                        owningWorkspace.CurrentCursor  = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                        owningWorkspace.IsCursorForced = false;
                    }
                }
                else  // Attempt to complete the connection
                {
                    // Check if connection is valid
                    if (owningWorkspace.CheckActiveConnectorCompatibility(portViewModel))
                    {
                        Guid nodeId    = portModel.Owner.GUID;
                        int  portIndex = portModel.Index;

                        var mode = DynamoModel.MakeConnectionCommand.Mode.End;
                        this.currentState             = State.None;
                        owningWorkspace.CurrentCursor = null;

                        if (multipleConnections)
                        {
                            mode = DynamoModel.MakeConnectionCommand.Mode.EndShiftReconnections;
                        }
                        else if (Keyboard.Modifiers == ModifierKeys.Control) // If the control key is held down
                        {
                            mode = DynamoModel.MakeConnectionCommand.Mode.BeginCreateConnections;
                            this.currentState             = State.Connection;                             // Start a new connection
                            owningWorkspace.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); // Reassign the cursor
                        }
                        var command = new DynamoModel.MakeConnectionCommand(nodeId,
                                                                            portIndex, portModel.PortType, mode);
                        owningWorkspace.DynamoViewModel.ExecuteCommand(command);
                        multipleConnections            = false;
                        owningWorkspace.IsCursorForced = false;
                    }
                }

                return(true);
            }
コード例 #9
0
ファイル: NodeViewModel.cs プロジェクト: mikeyforrest/Dynamo
 /// <summary>
 /// Unsubscribe port events.
 /// </summary>
 /// <param name="item">The PortViewModel.</param>
 /// <returns></returns>
 private PortViewModel UnSubscribePortEvents(PortViewModel item)
 {
     item.MouseEnter -= OnRectangleMouseEnter;
     item.MouseLeave -= OnRectangleMouseLeave;
     item.MouseLeftButtonDown -= OnMouseLeftButtonDown;
     return item;
 }
コード例 #10
0
ファイル: WorkspaceViewModel.cs プロジェクト: jimb000/Dynamo
        /// <summary>
        /// Handles the port snapping on Mouse Enter.
        /// </summary>
        /// <param name="portViewModel">The port view model.</param>
        /// <param name="eventType">Type of the event.</param>
        private void nodeViewModel_SnapInputEvent(PortViewModel portViewModel)
        {
            switch (portViewModel.EventType)
            {
                case PortEventType.MouseEnter:                    
                    IsSnapping = this.CheckActiveConnectorCompatibility(portViewModel);
                    this.portViewModel = portViewModel;
                    break;
                case PortEventType.MouseLeave:
                    IsSnapping = this.CheckActiveConnectorCompatibility(portViewModel, false);
                    this.portViewModel = portViewModel;
                    break;
                case PortEventType.MouseLeftButtonDown:
                    //If the connector is not active, then the state is changed to None. otherwise, the connector state is connection and 
                    //is not deleted from the view.
                    this.portViewModel = portViewModel;
                    if (this.CheckActiveConnectorCompatibility(portViewModel))
                    {
                        this.HandlePortClicked(portViewModel);
                    }
                    else
                    {
                        this.CancelActiveState();

                    }
                    break;
                default:
                    IsSnapping = this.CheckActiveConnectorCompatibility(portViewModel);
                    this.portViewModel = portViewModel;
                    break;

            }
            
        }
コード例 #11
0
ファイル: StateMachine.cs プロジェクト: algobasket/Dynamo
            internal bool HandlePortClicked(PortViewModel portViewModel)
            {
                // We only entertain port clicking when the current state is idle, 
                // or when it is already having a connector being established.
                if (currentState != State.None && (currentState != State.Connection))
                    return false;

                PortModel portModel = portViewModel.PortModel;
                DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel;
                WorkspaceViewModel workspaceViewModel = dynamoViewModel.CurrentSpaceViewModel;

                if (this.currentState != State.Connection) // Not in a connection attempt...
                {
                    PortType portType = PortType.INPUT;
                    Guid nodeId = portModel.Owner.GUID;
                    int portIndex = portModel.Owner.GetPortIndexAndType(portModel, out portType);

                    dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand(
                        nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.Begin));

                    if (null != owningWorkspace.activeConnector)
                    {
                        this.currentState = State.Connection;
                        owningWorkspace.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                        owningWorkspace.IsCursorForced = false;
                    }
                }
                else  // Attempt to complete the connection
                {
                    // Check if connection is valid
                    if (owningWorkspace.CheckActiveConnectorCompatibility(portViewModel))
                    {
                        PortType portType = PortType.INPUT;
                        Guid nodeId = portModel.Owner.GUID;
                        int portIndex = portModel.Owner.GetPortIndexAndType(portModel, out portType);

                        dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand(
                            nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.End));

                        owningWorkspace.CurrentCursor = null;
                        owningWorkspace.IsCursorForced = false;
                        this.currentState = State.None;
                    }
                }

                return true;
            }
コード例 #12
0
ファイル: StateMachine.cs プロジェクト: algobasket/Dynamo
 internal bool HandlePortClicked(PortViewModel portViewModel)
 {
     return stateMachine.HandlePortClicked(portViewModel);
 }
コード例 #13
0
ファイル: StateMachine.cs プロジェクト: algobasket/Dynamo
        internal bool CheckActiveConnectorCompatibility(PortViewModel portVM)
        {
            // Check if required ports exist
            if (this.activeConnector == null || portVM == null)
                return false;

            PortModel srcPortM = this.activeConnector.ActiveStartPort;
            PortModel desPortM = portVM.PortModel;

            // No self connection
            // No start to start or end or end connection
            if (srcPortM.Owner != desPortM.Owner && srcPortM.PortType != desPortM.PortType)
            {
                // Change cursor to show compatible port connection
                CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcAdding);
                return true;
            }
            else
            {
                // Change cursor to show not compatible
                CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                return false;
            }
        }
コード例 #14
0
ファイル: StateMachine.cs プロジェクト: sm6srw/Dynamo
        internal bool CheckActiveConnectorCompatibility(PortViewModel portVM,bool isSnapping = true)
        {
            // Check if required ports exist
            if (this.activeConnector == null || portVM == null)
                return false;
            //By default the ports will be in snapping mode. But if the connection is not completed,
            //then on mouse leave, the cursor should be pointed as arcselect instead of arcadd.             
            if (!isSnapping)
            {
                CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                return false;
            }

            PortModel srcPortM = this.activeConnector.ActiveStartPort;
            PortModel desPortM = portVM.PortModel;

            // No self connection
            // No start to start or end or end connection
            if (srcPortM.Owner != desPortM.Owner && srcPortM.PortType != desPortM.PortType)
            {
                // Change cursor to show compatible port connection
                CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcAdding);
                return true;
            }
            else
            {
                // Change cursor to show not compatible
                CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                return false;
            }
        }
コード例 #15
0
ファイル: WorkspaceView.xaml.cs プロジェクト: nmeek/Dynamo
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            this.snappedPort = null;

            bool mouseMessageHandled = false;
            WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel);
            
            // If we are currently connecting and there is an active 
            // connector, redraw it to match the new mouse coordinates.
            if (wvm.IsSnapping)
            {              
                if (wvm.portViewModel != null)
                {
                    if (wvm.CheckActiveConnectorCompatibility(wvm.portViewModel))
                    {
                        mouseMessageHandled = true;
                        wvm.HandleMouseMove(workBench, wvm.portViewModel.Center);
                    }
                }
                else
                    wvm.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
            }

            if (wvm.IsInIdleState)
            {
                // Find the dependency object directly under the mouse 
                // cursor, then see if it represents a port. If it does,
                // then determine its type, we would like to show the 
                // "ArcRemoving" cursor when the mouse is over an out port.
                Point mouse = e.GetPosition((UIElement)sender);
                var dependencyObject = ElementUnderMouseCursor(mouse);
                PortViewModel pvm = PortFromHitTestResult(dependencyObject);

                if (null != pvm && (pvm.PortType == PortType.Input))
                    this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                else
                    this.Cursor = null;
            }

            if (false == mouseMessageHandled)
                wvm.HandleMouseMove(workBench, e);
        }
コード例 #16
0
ファイル: NodeViewModel.cs プロジェクト: mikeyforrest/Dynamo
 /// <summary>
 /// Registers the port events.
 /// </summary>
 /// <param name="item">PortModel.</param>
 /// <returns></returns>
 private PortViewModel SubscribePortEvents(PortModel item)
 {
     PortViewModel portViewModel = new PortViewModel(this, item);            
     portViewModel.MouseEnter += OnRectangleMouseEnter;
     portViewModel.MouseLeave += OnRectangleMouseLeave;
     portViewModel.MouseLeftButtonDown += OnMouseLeftButtonDown;
     return portViewModel;
 }
コード例 #17
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            this.snappedPort = null;

            bool mouseMessageHandled = false;
            WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel);
            var currentState = wvm.CurrentState;

            switch (wvm.CurrentState)
            {
                // If we are currently connecting and there is an active
                // connector, redraw it to match the new mouse coordinates.
                case WorkspaceViewModel.StateMachine.State.Connection:
                {
                    Point mouse = e.GetPosition((UIElement)sender);
                    this.snappedPort = GetSnappedPort(mouse);

                    // Check for nearby port to snap
                    if (this.snappedPort != null)
                    {
                        // Nearby port must be compatible for connection
                        if (wvm.CheckActiveConnectorCompatibility(this.snappedPort))
                        {
                            mouseMessageHandled = true;
                            wvm.HandleMouseMove(this.WorkBench, this.snappedPort.Center);
                        }
                        else
                            this.snappedPort = null; // remove non-compatible port
                    }
                    else
                        wvm.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);

                    break;
                }

                case WorkspaceViewModel.StateMachine.State.None:
                {
                    // Find the dependency object directly under the mouse
                    // cursor, then see if it represents a port. If it does,
                    // then determine its type, we would like to show the
                    // "ArcRemoving" cursor when the mouse is over an out port.
                    Point mouse = e.GetPosition((UIElement)sender);
                    var dependencyObject = ElementUnderMouseCursor(mouse);
                    PortViewModel pvm = PortFromHitTestResult(dependencyObject);

                    if (null != pvm && (pvm.PortType == PortType.INPUT))
                        this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
                    else
                        this.Cursor = null;

                    break;
                }
            }

            if (false == mouseMessageHandled)
                wvm.HandleMouseMove(this.WorkBench, e);
        }
コード例 #18
0
ファイル: StateMachine.cs プロジェクト: jimmplan/Dynamo
 internal bool HandlePortClicked(PortViewModel portViewModel)
 {
     return(stateMachine.HandlePortClicked(portViewModel));
 }
コード例 #19
0
 private void OnMouseRelease(object sender, MouseButtonEventArgs e)
 {
     this.snappedPort = null;
     WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel);
     wvm.HandleMouseRelease(this.WorkBench, e);
 }