Skip to content

Commit

Permalink
Merge branch 'release/v4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhq-boiler committed Sep 29, 2021
2 parents be954f6 + 108f28d commit 1aab16c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
18 changes: 15 additions & 3 deletions boilersGraphics/Models/LayerTreeViewItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,21 @@ public IObservable<Unit> LayerItemsChangedAsObservable()

public IObservable<Unit> SelectedLayerItemsChangedAsObservable()
{
return Children.ObserveElementObservableProperty(x => (x as LayerItem).Item.Value.IsSelected)
.ToUnit()
.Merge(Children.CollectionChangedAsObservable().Where(x => x.Action == NotifyCollectionChangedAction.Remove || x.Action == NotifyCollectionChangedAction.Reset).ToUnit());
var ox1 = Children
.ObserveElementObservableProperty(x => (x as LayerItem).Item.Value.IsSelected)
.ToUnit()
.Merge(Children.CollectionChangedAsObservable().Where(x => x.Action == NotifyCollectionChangedAction.Remove || x.Action == NotifyCollectionChangedAction.Reset).ToUnit());

var ox2 = Children.CollectionChangedAsObservable()
.Select(_ => Children.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.OfType<LayerItem>()
.Select(x => x.Item.Value)
.OfType<ConnectorBaseViewModel>()
.SelectMany(x => new[] { x.SnapPoint0VM.Value, x.SnapPoint1VM.Value })
.Select(x => x.IsSelected.ToUnit())
.Merge())
.Switch();
return ox1.Merge(ox2);
}

public void AddItem(MainWindowViewModel mainWindowViewModel, DiagramViewModel diagramViewModel, SelectableDesignerItemViewModelBase item)
Expand Down
55 changes: 27 additions & 28 deletions boilersGraphics/ViewModels/DiagramViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,34 +343,33 @@ public DiagramViewModel(MainWindowViewModel mainWindowViewModel, int width, int
})
.AddTo(_CompositeDisposable);

SelectedItems = Layers.CollectionChangedAsObservable()
.Select(_ => Layers.Select(x => x.SelectedLayerItemsChangedAsObservable()).Merge()
.Merge(Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.OfType<ConnectorBaseViewModel>()
.SelectMany(x => new List<SnapPointViewModel>() { x.SnapPoint0VM.Value, x.SnapPoint1VM.Value })
.ToObservableCollection()
.ObserveElementProperty(x => x.IsSelected.Value)
.ToUnit()))
.Switch()
.Select(_ => Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.Except(Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.OfType<ConnectorBaseViewModel>())
.Union(Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.OfType<ConnectorBaseViewModel>()
.SelectMany(x => new List<SnapPointViewModel>() { x.SnapPoint0VM.Value, x.SnapPoint1VM.Value })
)
.Where(z => z.IsSelected.Value == true)
.OrderBy(z => z.SelectedOrder.Value)
.ToArray())
.ToReadOnlyReactivePropertySlim(Array.Empty<SelectableDesignerItemViewModelBase>());
SelectedItems = Layers
.CollectionChangedAsObservable()
.Select(_ =>
Layers
.Select(x => x.SelectedLayerItemsChangedAsObservable())
.Merge()
)
.Switch()
.Do(x => Debug.WriteLine("SelectedItems updated"))
.Select(_ => Layers
.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x is LayerItem)
.Select(y => (y as LayerItem).Item.Value)
.Except(Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.OfType<ConnectorBaseViewModel>())
.Union(Layers.SelectRecursive<LayerTreeViewItemBase, LayerTreeViewItemBase>(x => x.Children)
.Where(x => x.GetType() == typeof(LayerItem))
.Select(y => (y as LayerItem).Item.Value)
.OfType<ConnectorBaseViewModel>()
.SelectMany(x => new[] { x.SnapPoint0VM.Value, x.SnapPoint1VM.Value }.Where(y => y.IsSelected.Value))
)
.Where(z => z.IsSelected.Value == true)
.OrderBy(z => z.SelectedOrder.Value)
.ToArray()
).ToReadOnlyReactivePropertySlim(Array.Empty<SelectableDesignerItemViewModelBase>());

SelectedItems.Subscribe(selectedItems =>
{
Expand Down

0 comments on commit 1aab16c

Please sign in to comment.