示例#1
0
 public void NotifyConnectors(Type connectorType, ConnectorViewModel connector, BaseElementViewModel source)
 {
     if (_currentConnetor == null)
     {
         source.HideOtherConnectors(connector);
         foreach (BaseElementViewModel baseElement in BaseElements)
         {
             if (source != baseElement && baseElement.IsTypeApplicable(connectorType))
             {
                 baseElement.IsConnectorVisible = true;
             }
         }
         _currentConnetor = connector;
     }
     else
     {
         _drawingConnectionViewModel.IsVisible = false;
         foreach (BaseElementViewModel baseElement in BaseElements)
         {
             baseElement.ShowAllConnectors();
         }
         ElementsConnectionViewModel connection = new ElementsConnectionViewModel(this, _currentConnetor, connector);
         this.BaseElements.Add(connection);
         _currentConnetor = null;
     }
 }
示例#2
0
        public void SetConnection(ElementsConnectionViewModel connection)
        {
            connection.ElementDeleted += Connection_ElementDeleted;
            GenericAddedAction <BaseElementViewModel> addedAction = new GenericAddedAction <BaseElementViewModel>(Document, connection);
            var addedActionArgs = new ActionPerformedEventArgs(addedAction);

            ActionPerformed?.Invoke(this, addedActionArgs);
            _activeConnections.Add(connection);
        }
示例#3
0
        private void Connection_ElementDeleted(object sender, EventArgs e)
        {
            ElementsConnectionViewModel senderConnectionViewModel = sender as ElementsConnectionViewModel;

            if (senderConnectionViewModel != null)
            {
                senderConnectionViewModel.ElementDeleted -= Connection_ElementDeleted;
                RemoveConnection(senderConnectionViewModel);
            }
        }
示例#4
0
 public void AfterInsert()
 {
     foreach (var item in Document.BaseElements)
     {
         ElementsConnectionViewModel connectionViewModel = item as ElementsConnectionViewModel;
         if (connectionViewModel != null && (connectionViewModel.From == this || connectionViewModel.To == this))
         {
             _activeConnections.Add(connectionViewModel);
         }
     }
 }
示例#5
0
        public void EndDrawConnectionLine(Point position)
        {
            if (_currentConnetor != null)
            {
                BaseElementViewModel source = _currentConnetor.Parent;
                _drawingConnectionViewModel.IsVisible = false;
                List <BaseElementViewModel> tempList = new List <BaseElementViewModel>(BaseElements);
                foreach (BaseElementViewModel baseElement in tempList)
                {
                    if (baseElement.BaseElement == null)
                    {
                        continue;
                    }
                    if (source != baseElement && baseElement.IsTypeApplicable(baseElement.BaseElement.GetType()))
                    {
                        Rect elementRect             = Helper.GetRect(baseElement, 10);
                        Rect pointRect               = new Rect(position, new Size(1, 1));
                        ConnectorViewModel connector = null;
                        bool connectionAdded         = false;

                        foreach (ConnectorViewModel baseElementConnector in baseElement.Connectors)
                        {
                            Rect connectorRect = baseElementConnector.GetRectWithMargin(0);
                            if (connectorRect.IntersectsWith(pointRect))
                            {
                                connector = baseElementConnector;
                                break;
                            }
                            else if (baseElementConnector.Placemement == _drawingConnectionViewModel.EndPlacemement && elementRect.IntersectsWith(pointRect))
                            {
                                connector = baseElementConnector;
                            }
                        }
                        if (connector != null)
                        {
                            ElementsConnectionViewModel connection = new ElementsConnectionViewModel(this, _currentConnetor, connector);
                            this.BaseElements.Add(connection);
                            break;
                        }
                    }
                    baseElement.ShowAllConnectors();
                }
            }
            _currentConnetor = null;
        }
示例#6
0
 private void RemoveConnection(ElementsConnectionViewModel connection)
 {
     _activeConnections.Remove(connection);
 }
示例#7
0
        public void Fill()
        {
            //TODO: Refactor
            PoolElement mainPoolElement = DocumentViewModel.Document.MainPoolElement;

            foreach (IBaseElement baseElement in mainPoolElement.Elements)
            {
                VisualElement        visualElement = baseElement as VisualElement;
                BaseElementViewModel baseViewModel = BaseElementViewModel.GetViewModel(visualElement, DocumentViewModel);
                _viewModelDictionary.Add(visualElement.Guid, baseViewModel);
                _viewModels.Add(baseViewModel);
            }
            foreach (ConnectionElement connection in mainPoolElement.Connections)
            {
                BaseElementViewModel start = null;
                BaseElementViewModel end   = null;
                if (_viewModelDictionary.TryGetValue(connection.SourceElement.Guid, out start) &&
                    _viewModelDictionary.TryGetValue(connection.TargetElement.Guid, out end))
                {
                    Point startPoint = new Point();
                    Point endPoint   = new Point();
                    if (connection.Points.Count >= 2)
                    {
                        startPoint = connection.Points[0];
                        endPoint   = connection.Points.Last();
                    }

                    ElementsConnectionViewModel connectionViewModel = new ElementsConnectionViewModel(
                        DocumentViewModel, connection, start, end, startPoint, endPoint);
                    _viewModels.Add(connectionViewModel);
                }
            }
            foreach (PoolElement poolElement in DocumentViewModel.Document.Pools)
            {
                PoolViewModel poolViewModel = new PoolViewModel(DocumentViewModel, poolElement);
                _poolViewModelsDictionary.Add(poolElement.Guid, poolViewModel);
                _viewModels.Add(poolViewModel);
                foreach (IBaseElement baseElement in poolElement.Elements)
                {
                    VisualElement        visualElement        = baseElement as VisualElement;
                    BaseElementViewModel baseViewModel        = BaseElementViewModel.GetViewModel(visualElement, DocumentViewModel);
                    PoolElementViewModel poolElementViewModel = baseViewModel as PoolElementViewModel;
                    poolElementViewModel.Pool = poolViewModel;
                    poolViewModel.Elements.Add(poolElementViewModel);
                    _viewModelDictionary.Add(visualElement.Guid, baseViewModel);
                    _viewModels.Add(baseViewModel);
                }
                foreach (ConnectionElement connection in poolElement.Connections)
                {
                    BaseElementViewModel start = null;
                    BaseElementViewModel end   = null;
                    if (_viewModelDictionary.TryGetValue(connection.SourceElement.Guid, out start) &&
                        _viewModelDictionary.TryGetValue(connection.TargetElement.Guid, out end))
                    {
                        Point startPoint = new Point();
                        Point endPoint   = new Point();
                        if (connection.Points.Count >= 2)
                        {
                            startPoint = connection.Points[0];
                            endPoint   = connection.Points.Last();
                        }

                        ElementsConnectionViewModel connectionViewModel = new ElementsConnectionViewModel(
                            DocumentViewModel, connection, start, end, startPoint, endPoint);
                        _viewModels.Add(connectionViewModel);
                    }
                }
            }
            DocumentViewModel.BaseElements = new ObservableCollection <BaseElementViewModel>(_viewModels);
        }