public LaneViewModel(int index, PoolViewModel poolViewModel) { Index = index; Lane = new LaneElement() { Height = 150 }; BaseElement = Lane; DeleteCommand = new RelayCommand(x => Delete()); _pool = poolViewModel; }
protected override void DimensionChanged() { var objectRect = Helper.GetRect(this); var currentPool = Pool; if (Pool != null) { var poolRect = Helper.GetRect(Pool); if (poolRect.Contains(objectRect)) { return; } else { currentPool.RemoveElement(this); Pool = null; } } //Check if is inside new pool foreach (BaseElementViewModel baseElement in Document.BaseElements) { PoolViewModel pool = baseElement as PoolViewModel; if (pool != null) { var poolRect = Helper.GetRect(pool); if (poolRect.Contains(objectRect)) { if (currentPool != null) { currentPool.RemoveElement(this); } pool.AddElement(this); Pool = pool; break; } } } }
public LaneViewModel(int index, PoolViewModel poolViewModel, LaneElement lane) : this(index, poolViewModel) { Lane = lane; BaseElement = lane; }
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); }