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; } }
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); }
private void Connection_ElementDeleted(object sender, EventArgs e) { ElementsConnectionViewModel senderConnectionViewModel = sender as ElementsConnectionViewModel; if (senderConnectionViewModel != null) { senderConnectionViewModel.ElementDeleted -= Connection_ElementDeleted; RemoveConnection(senderConnectionViewModel); } }
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); } } }
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; }
private void RemoveConnection(ElementsConnectionViewModel connection) { _activeConnections.Remove(connection); }
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); }