Esempio n. 1
0
 /// <inheritdoc/>
 public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.Type == InteractionType.MouseMoved)
     {
         SetEnd(interaction.MousePosition.X, interaction.MousePosition.Y);
     }
 }
Esempio n. 2
0
 /// <inheritdoc/>
 public override bool ShouldStartInteraction(DiagramInteractionEventArguments interaction)
 {
     return(interaction.Type == InteractionType.LeftMouseDown &&
            interaction.IsCtrlKeyPressed &&
            !interaction.IsShiftKeyPressed &&
            !interaction.IsAltKeyPressed);
 }
Esempio n. 3
0
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var selectedNodes = interaction.Diagram.Nodes.Where(n => n.IsSelected).ToList();

            selectedNodes.ForEach(n => n.IsSelected = false);
            if (interaction.Key == Key.C)
            {
                _copiedNodes = selectedNodes.Select(s => s.Model.Copy()).OfType <NodeModel>().ToList();
            }
            else
            {
                if (_copiedNodes == null)
                {
                    return;
                }
                var firstCopiedNodeX       = _copiedNodes.FirstOrDefault()?.X ?? 0;
                var firstCopiedNodeY       = _copiedNodes.FirstOrDefault()?.Y ?? 0;
                var nodesToInsertToDiagram = new List <Node>();
                foreach (var copiedNode in _copiedNodes)
                {
                    var node = _nodeProvider.CreateNodeFromModel((NodeModel)copiedNode.Copy());
                    node.IsSelected = true;
                    var diagramMousePoint = interaction.Diagram.GetDiagramPointFromViewPoint(interaction.MousePosition);
                    node.X         -= firstCopiedNodeX - diagramMousePoint.X;
                    node.Y         -= firstCopiedNodeY - diagramMousePoint.Y;
                    node.IsSelected = true;
                    nodesToInsertToDiagram.Add(node);
                    interaction.Diagram.AddNode(node);
                }
                _transactor.Transact(new UndoCommand(new MapCommand(new UnwireAndDeleteNodeCommand(interaction.Diagram))), nodesToInsertToDiagram);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Handles input from the diagram.
 /// </summary>
 /// <param name="type">The information about the interation that occured.</param>
 /// <param name="diagram">The diagram that the interaction occured on.</param>
 public void HandleDiagramInput(DiagramInteractionEventArguments interaction, Diagram diagram)
 {
     interaction.Diagram = diagram;
     PutViewModelMouseIsOverInInteraction(interaction);
     PutKeyStatesInInteraction(interaction);
     SendInteractionToInteractors(interaction);
 }
 /// <inheritdoc/>
 public override void StopInteraction(DiagramInteractionEventArguments interaction)
 {
     if (ContextTerminal != null)
     {
         ContextTerminal.HighlightVisible = false;
     }
 }
 /// <inheritdoc/>
 public override void StartInteraction(DiagramInteractionEventArguments interaction)
 {
     _reachedMinimunMouseDeltaToStartPanning = false;
     StartMouseLocation = interaction.MousePosition;
     StartPanX          = interaction.Diagram.PanX;
     StartPanY          = interaction.Diagram.PanY;
 }
Esempio n. 7
0
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            if (interaction.Type == InteractionType.LeftMouseDown)
            {
                ProcessMouseDownInteraction(interaction);
            }
            else if (interaction.Type == InteractionType.LeftMouseUp)
            {
                ProcessMouseUpInteraction(interaction);
            }

            if (interaction.ViewModelUnderMouse is Node pluginNode)
            {
                if (!pluginNode.IsSelected)
                {
                    if (!interaction.IsCtrlKeyPressed)
                    {
                        interaction.Diagram.UnselectNodes();
                    }

                    interaction.Diagram.UnselectTerminals();
                    pluginNode.IsSelected = true;
                }
            }
        }
Esempio n. 8
0
 /// <inheritdoc/>
 public override bool ShouldStartInteraction(DiagramInteractionEventArguments interaction)
 {
     return(interaction.Type == InteractionType.KeyDown &&
            !interaction.IsAltKeyPressed &&
            !interaction.IsShiftKeyPressed &&
            interaction.IsCtrlKeyPressed &&
            (interaction.Key == Key.C || interaction.Key == Key.V));
 }
Esempio n. 9
0
 /// <inheritdoc/>
 public override bool ShouldStopInteraction(DiagramInteractionEventArguments interaction)
 {
     return(interaction.Type == InteractionType.RightMouseDown ||
            (interaction.Type == InteractionType.LeftMouseDown &&
             interaction.ViewModelUnderMouse is Terminal terminal &&
             (terminal != _wiringTerminal || _leftMouseDownCount == 2)) ||
            (interaction.Type == InteractionType.LeftMouseDown && interaction.ViewModelUnderMouse is Wire));
 }
Esempio n. 10
0
 /// <inheritdoc/>
 public override void StartInteraction(DiagramInteractionEventArguments interaction)
 {
     PreviousMouseLocation            = interaction.MousePosition;
     _resizingNodes                   = interaction.Diagram.Nodes.Where(n => n.IsSelected).ToArray();
     _undoResizeCommand               = new ResizeNodesToCurrentSizeCommand(_resizingNodes);
     _undoPositionAdjustmentCommand   = new MoveNodesToCurrentPositionCommand(_resizingNodes);
     interaction.Diagram.ShowSnapGrid = true;
 }
Esempio n. 11
0
 /// <inheritdoc/>
 public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.ViewModelUnderMouse is Wire wire)
     {
         var deleteWireCommand = new DeleteWireCommand(interaction.Diagram);
         _transactor.Transact(deleteWireCommand, wire.WireModel);
     }
 }
Esempio n. 12
0
        private void SendInteractionToActiveInteractions(DiagramInteractionEventArguments interaction)
        {
            var activeInteractors = ActiveDiagramInteractors.ToArray();

            foreach (var activeInteractor in activeInteractors)
            {
                activeInteractor.ProcessInteraction(interaction);
            }
        }
Esempio n. 13
0
 /// <inheritdoc/>
 public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.Type == InteractionType.MouseMoved)
     {
         MoveInsertingNode(interaction.Diagram, interaction.MousePosition);
         interaction.Diagram.UpdateDiagramBoundingBox();
         InsertingNodeViewModel.Visible = true;
     }
 }
Esempio n. 14
0
 /// <inheritdoc/>
 public override void StartInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.Type == InteractionType.LeftMouseDown && interaction.ViewModelUnderMouse is Terminal terminal)
     {
         _wiringTerminal = terminal;
         StartWiringFromTerminal(interaction.Diagram, terminal);
         _leftMouseDownCount = 0;
     }
 }
Esempio n. 15
0
        private void StopActiveInteractionsThatShouldStop(DiagramInteractionEventArguments interaction)
        {
            var activeInteractors = ActiveDiagramInteractors.ToArray();

            foreach (var activeInteractor in activeInteractors)
            {
                TryStoppingInteraction(interaction, activeInteractor);
            }
        }
Esempio n. 16
0
 /// <inheritdoc/>
 public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.Type == InteractionType.MouseMoved)
     {
         var diagram       = interaction.Diagram;
         var mousePosition = interaction.MousePosition;
         ProcessMouseMoved(diagram, mousePosition);
     }
 }
Esempio n. 17
0
 /// <inheritdoc/>
 public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.Type == InteractionType.MouseMoved)
     {
         var diagram       = interaction.Diagram;
         var mousePosition = interaction.MousePosition;
         ProcessMouseMoved(diagram, mousePosition);
         diagram.ShowSnapGrid = !interaction.IsCtrlKeyPressed;
     }
 }
Esempio n. 18
0
 /// <inheritdoc/>
 public override void StartInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.ViewModelUnderMouse is Node node)
     {
         var nodeCopy = _nodeProvider.CreateNodeFromName(node.GetType().FullName);
         node.SetAdorner(null);
         _helpDialog = new HelpDialog(nodeCopy);
         _dialogHost.OpenDialog(_helpDialog);
     }
 }
Esempio n. 19
0
 private void SendInteractionToInteractors(DiagramInteractionEventArguments interaction)
 {
     if (!ActiveDiagramInteractors.Any())
     {
         StartAndProcessInteractionsThatShouldStart(interaction);
     }
     else
     {
         SendInteractionToActiveInteractions(interaction);
         StopActiveInteractionsThatShouldStop(interaction);
     }
 }
Esempio n. 20
0
        private static void PutViewModelMouseIsOverInInteraction(DiagramInteractionEventArguments interaction)
        {
            var elementMouseIsOver = Mouse.DirectlyOver as FrameworkElement;

            if (!(elementMouseIsOver?.DataContext is Screen viewModelMouseIsOver))
            {
                var contentPresenter = elementMouseIsOver?.DataContext as ContentPresenter;
                viewModelMouseIsOver = contentPresenter?.DataContext as Screen;
            }

            interaction.ViewModelUnderMouse = viewModelMouseIsOver;
        }
Esempio n. 21
0
        private bool TryStoppingInteraction(DiagramInteractionEventArguments interaction, DiagramInteractor activeInteractor)
        {
            var didInteractionStop = activeInteractor.ShouldStopInteraction(interaction);

            if (didInteractionStop)
            {
                ActiveDiagramInteractors.Remove(activeInteractor);
                ActiveDiagramInteractorNames.Remove(activeInteractor.GetType().Name);
                activeInteractor.StopInteraction(interaction);
            }

            return(didInteractionStop);
        }
        /// <inheritdoc/>
        public override void StartInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram       = interaction.Diagram;
            var mousePosition = interaction.MousePosition;

            RiftStartDiagramPoint = diagram.GetDiagramPointFromViewPoint(mousePosition);
            Mode             = RiftMode.None;
            X                = mousePosition.X;
            Y                = mousePosition.Y;
            RiftWidth        = 0;
            RiftHeight       = 0;
            _undoRiftCommand = new MoveNodesToCurrentPositionCommand(_nodesBeingRifted);
        }
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram           = interaction.Diagram;
            var mousePosition     = interaction.MousePosition;
            var diagramMousePoint = diagram.GetDiagramPointFromViewPoint(mousePosition);
            var riftDeltaX        = diagramMousePoint.X - RiftStartDiagramPoint.X;
            var riftDeltaY        = diagramMousePoint.Y - RiftStartDiagramPoint.Y;

            if (interaction.Type == InteractionType.MouseMoved)
            {
                ProcessMouseMoved(diagram, mousePosition, riftDeltaX, riftDeltaY);
            }
        }
Esempio n. 24
0
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram       = interaction.Diagram;
            var selectedNodes = diagram.Nodes.Where(n => n.IsSelected).ToArray();
            var unwireAndRemoveAllNodesCommand = new MapCommand(new UnwireAndDeleteNodeCommand(diagram));

            _transactor.Transact(unwireAndRemoveAllNodesCommand, selectedNodes);

            if (!diagram.Nodes.Any())
            {
                diagram.ResetPanAndZoom();
            }
        }
        public override void StopInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram     = interaction.Diagram;
            var left        = diagram.GetDiagramPointFromViewPointX(X);
            var top         = diagram.GetDiagramPointFromViewPointY(Y);
            var right       = diagram.GetDiagramPointFromViewPointX(X + Width);
            var bottom      = diagram.GetDiagramPointFromViewPointY(Y + Height);
            var nodesToWire = diagram.Nodes.Where(node =>
                                                  node.X > left && node.X + node.Width <right &&
                                                                                        node.Y> top && node.Y + node.Height < bottom).ToList();
            var autoWirer = new NodeAutoWirer();

            autoWirer.AutoWireNodes(diagram, nodesToWire);
        }
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram = interaction.Diagram;

            if (interaction.Type == InteractionType.MouseMoved)
            {
                var mousePosition = interaction.MousePosition;
                ProcessMouseMoved(diagram, mousePosition);
            }
            else if (interaction.Type == InteractionType.LeftMouseUp && !_reachedMinimunMouseDeltaToStartPanning)
            {
                ProcessMouseMouseUpAfterNotPanning(diagram);
            }
        }
Esempio n. 27
0
 /// <inheritdoc/>
 public override bool ShouldStartInteraction(DiagramInteractionEventArguments interaction)
 {
     if (interaction.ViewModelUnderMouse is Node node &&
         !interaction.IsCtrlKeyPressed)
     {
         var mouseX  = interaction.MousePosition.X;
         var mouseY  = interaction.MousePosition.Y;
         var diagram = interaction.Diagram;
         if (IsMouseOverNodeBorder(node, mouseX, mouseY, diagram))
         {
             Mouse.SetCursor(Cursors.SizeAll);
             return(interaction.Type == InteractionType.LeftMouseDown);
         }
     }
Esempio n. 28
0
        /// <inheritdoc/>
        public override void StopInteraction(DiagramInteractionEventArguments interaction)
        {
            var type              = interaction.Type;
            var diagram           = interaction.Diagram;
            var elementUnderMouse = interaction.ViewModelUnderMouse;

            if (type == InteractionType.RightMouseDown || elementUnderMouse is Wire)
            {
                CancelWireInsertion(interaction.Diagram);
            }
            else if (type == InteractionType.LeftMouseDown && elementUnderMouse is Terminal terminal)
            {
                WireToTerminal(diagram, terminal);
            }
        }
Esempio n. 29
0
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram           = interaction?.Diagram ?? throw new ArgumentNullException(nameof(interaction));
            var mousePosition     = interaction.MousePosition;
            var elementUnderMouse = interaction.ViewModelUnderMouse;

            if (interaction.Type == InteractionType.MouseMoved)
            {
                ProcessMouseMove(diagram, mousePosition, elementUnderMouse);
            }
            else if (interaction.Type == InteractionType.LeftMouseDown)
            {
                ProcessLeftMouseDown(diagram, elementUnderMouse);
            }
        }
        /// <inheritdoc/>
        public override void ProcessInteraction(DiagramInteractionEventArguments interaction)
        {
            var diagram       = interaction.Diagram;
            var mousePosition = interaction.MousePosition;
            var diagramStart  = diagram.GetDiagramPointFromViewPoint(mousePosition);

            var zoom    = interaction.MouseWheelDelta > 0 ? 1.0 + ZoomAmount : 1.0 - ZoomAmount;
            var newZoom = diagram.Zoom * zoom;

            SetZoom(diagram, newZoom);

            var diagramEnd = diagram.GetDiagramPointFromViewPoint(mousePosition);

            diagram.PanX -= diagramStart.X - diagramEnd.X;
            diagram.PanY -= diagramStart.Y - diagramEnd.Y;
        }