Пример #1
0
        public CanvasPoint BeginLinkage(PinViewModel pinViewModel)
        {
            _currentUnfinishedLink = new LinkViewModel(pinViewModel, null, ControlTypesResolver);
            _linkViewModels.Add(_currentUnfinishedLink);

            return(_currentUnfinishedLink.EndPoint);
        }
Пример #2
0
        public CanvasPoint BeginLinkage(PinViewModel pinViewModel)
        {
            _currentUnfinishedLink = new LinkViewModel(pinViewModel, null, ControlTypesResolver);
            _linkViewModels.Add(_currentUnfinishedLink);

            return _currentUnfinishedLink.EndPoint;
        }
Пример #3
0
        public CanvasPoint BeginRelinkage(PinViewModel pinViewModel)
        {
            _currentUnfinishedLink = _linkViewModels.First(model => model.TargetPinViewModel == pinViewModel);
            _currentUnfinishedLink.TargetPinViewModel = null;
            var canvasPoint = new CanvasPoint();

            _currentUnfinishedLink.EndPoint = canvasPoint;
            return(canvasPoint);
        }
Пример #4
0
        public void EndLinkage(PinViewModel pinViewModel)
        {
            if (_currentUnfinishedLink != null)
            {
                var success = false;
                if (_currentUnfinishedLink.TargetPinViewModel == null)
                {
                    // Can't link to nowhere
                    if (pinViewModel != null)
                    {
                        // Can't link input<->input
                        if (pinViewModel.Pin.Direction == PinDirection.Input)
                        {
                            // Can't link node to itself
                            if (pinViewModel.NodeViewModel != _currentUnfinishedLink.SourcePinViewModel.NodeViewModel)
                            {
                                // Hurray! Successfully linked!

                                // Cleanup previous loosers
                                foreach (var linkViewModel in _linkViewModels.Where(model => model.TargetPinViewModel == pinViewModel).ToArray())
                                {
                                    Node.Unlink(linkViewModel.TargetPinViewModel.NodeViewModel.Node, linkViewModel.TargetPinViewModel.Pin);
                                    _linkViewModels.Remove(linkViewModel);
                                }

                                _currentUnfinishedLink.TargetPinViewModel = pinViewModel;
                                Node.Link(
                                    _currentUnfinishedLink.SourcePinViewModel.NodeViewModel.Node,
                                    _currentUnfinishedLink.SourcePinViewModel.Pin,
                                    pinViewModel.NodeViewModel.Node,
                                    pinViewModel.Pin);

                                pinViewModel.NodeViewModel.Node.Pulse();
                                success = true;
                            }
                        }
                    }
                }

                if (!success)
                {
                    _linkViewModels.Remove(_currentUnfinishedLink);
                }

                _currentUnfinishedLink = null;
            }
        }
Пример #5
0
 public LinkViewModel(PinViewModel sourcePinViewModel, PinViewModel targetPinViewModel, IControlTypesResolver controlTypesResolver)
 {
     SourcePinViewModel = sourcePinViewModel;
     TargetPinViewModel = targetPinViewModel;
     ControlTypesResolver = controlTypesResolver;
 }
Пример #6
0
 private void OnPreviewPinMouseUp(PinViewModel pinViewModel, MouseButtonEventArgs e)
 {
     ViewModel.EndLinkage(pinViewModel);
 }
Пример #7
0
 private void OnPreviewPinMouseDown(PinViewModel pinViewModel, MouseButtonEventArgs e)
 {
     if (pinViewModel.Pin.Direction != PinDirection.Input)
     {
         _endLinkPoint = ViewModel.BeginLinkage(pinViewModel);
         CaptureMouse();
     }
     else
     {
         _endLinkPoint = ViewModel.BeginRelinkage(pinViewModel);
         CaptureMouse();
     }
 }
Пример #8
0
 public LinkViewModel(PinViewModel sourcePinViewModel, PinViewModel targetPinViewModel, IControlTypesResolver controlTypesResolver)
 {
     SourcePinViewModel   = sourcePinViewModel;
     TargetPinViewModel   = targetPinViewModel;
     ControlTypesResolver = controlTypesResolver;
 }
Пример #9
0
 public CanvasPoint BeginRelinkage(PinViewModel pinViewModel)
 {
     _currentUnfinishedLink = _linkViewModels.First(model => model.TargetPinViewModel == pinViewModel);
     _currentUnfinishedLink.TargetPinViewModel = null;
     var canvasPoint = new CanvasPoint();
     _currentUnfinishedLink.EndPoint = canvasPoint;
     return canvasPoint;
 }
Пример #10
0
        public void EndLinkage(PinViewModel pinViewModel)
        {
            if (_currentUnfinishedLink != null)
            {
                var success = false;
                if (_currentUnfinishedLink.TargetPinViewModel == null)
                {
                    // Can't link to nowhere
                    if (pinViewModel != null)
                    {
                        // Can't link input<->input
                        if (pinViewModel.Pin.Direction == PinDirection.Input)
                        {
                            // Can't link node to itself
                            if (pinViewModel.NodeViewModel != _currentUnfinishedLink.SourcePinViewModel.NodeViewModel)
                            {
                                // Hurray! Successfully linked!

                                // Cleanup previous loosers
                                foreach (var linkViewModel in _linkViewModels.Where(model => model.TargetPinViewModel == pinViewModel).ToArray())
                                {
                                    Node.Unlink(linkViewModel.TargetPinViewModel.NodeViewModel.Node, linkViewModel.TargetPinViewModel.Pin);
                                    _linkViewModels.Remove(linkViewModel);
                                }

                                _currentUnfinishedLink.TargetPinViewModel = pinViewModel;
                                Node.Link(
                                    _currentUnfinishedLink.SourcePinViewModel.NodeViewModel.Node,
                                    _currentUnfinishedLink.SourcePinViewModel.Pin,
                                    pinViewModel.NodeViewModel.Node,
                                    pinViewModel.Pin);

                                pinViewModel.NodeViewModel.Node.Pulse();
                                success = true;
                            }
                        }
                    }
                }

                if (!success)
                {
                    _linkViewModels.Remove(_currentUnfinishedLink);
                }

                _currentUnfinishedLink = null;
            }
        }