protected override void DimensionChanged() { var poolRect = Helper.GetRect(this); foreach (BaseElementViewModel baseElement in Document.BaseElements) { PoolElementViewModel poolElementViewModel = baseElement as PoolElementViewModel; if (poolElementViewModel != null) { var objectRect = Helper.GetRect(baseElement); if (poolRect.Contains(objectRect)) { if (poolElementViewModel.Pool != null) { continue; } AddElement(poolElementViewModel); poolElementViewModel.Pool = this; } } } }
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); }
public void AddElement(PoolElementViewModel poolElementViewModel) { _poolElement.Elements.Add(poolElementViewModel.BaseElement); _elements.Add(poolElementViewModel); }
public void RemoveElement(PoolElementViewModel poolElementViewModel) { _poolElement.Elements.Remove(poolElementViewModel.BaseElement); _elements.Remove(poolElementViewModel); }