public PostsynapticViewModel(IAvatarViewer host, string tag, Node <Neuron, int> node, SourceCache <Neuron, int> cache, NeuronViewModelBase parent = null, INeuronApplicationService neuronApplicationService = null, INeuronQueryService neuronQueryService = null, ITerminalApplicationService terminalApplicationService = null, IExtendedSelectionService selectionService = null) : base(host, node, cache, parent, neuronApplicationService, neuronQueryService, terminalApplicationService, selectionService) { this.Tag = tag; }
private void UpdateFromViewer(IAvatarViewer av) { this.AvatarUrl = av.AvatarUrl; this.RegionId = av.RegionId; this.RegionName = av.RegionName; this.Target = av.Target; }
protected NeuronViewModelBase(IAvatarViewer host, Node <Neuron, int> node, SourceCache <Neuron, int> cache, NeuronViewModelBase parent = null, INeuronApplicationService neuronApplicationService = null, INeuronQueryService neuronQueryService = null, ITerminalApplicationService terminalApplicationService = null, IExtendedSelectionService selectionService = null, IExtendedSelectionService highlightService = null, IStatusService statusService = null, IDialogService dialogService = null) { this.host = host; this.Id = node.Key; this.Parent = parent; this.SetNeuron(node.Item); this.ReloadCommand = ReactiveCommand.Create(async() => await this.OnReload(cache)); this.ReloadExpandCommand = ReactiveCommand.Create(async() => { await this.OnReload(cache); this.IsExpanded = true; }); this.AddPostsynapticCommand = ReactiveCommand.Create <object>(async(parameter) => await this.OnAddPostsynaptic(cache, parameter)); this.AddPresynapticCommand = ReactiveCommand.Create <object>(async(parameter) => await this.OnAddPresynaptic(cache, parameter)); this.DeleteCommand = ReactiveCommand.Create <object>(async(parameter) => await this.OnDeleteClicked(cache, parameter)); this.neuronApplicationService = neuronApplicationService ?? Locator.Current.GetService <INeuronApplicationService>(); this.neuronQueryService = neuronQueryService ?? Locator.Current.GetService <INeuronQueryService>(); this.terminalApplicationService = terminalApplicationService ?? Locator.Current.GetService <ITerminalApplicationService>(); this.selectionService = selectionService ?? Locator.Current.GetService <IExtendedSelectionService>(SelectionContract.Select.ToString()); this.highlightService = highlightService ?? Locator.Current.GetService <IExtendedSelectionService>(SelectionContract.Highlight.ToString()); this.statusService = statusService ?? Locator.Current.GetService <IStatusService>(); this.dialogService = dialogService ?? Locator.Current.GetService <IDialogService>(); var childrenLoader = new Lazy <IDisposable>(() => node.Children.Connect() .Transform(e => e.Item.Type == RelativeType.Postsynaptic ? (NeuronViewModelBase)(new PostsynapticViewModel(this.host, e.Item.Tag, e, cache, this)) : (NeuronViewModelBase)(new PresynapticViewModel(this.host, e.Item.Tag, e, cache, this))) .Bind(out this.children) .DisposeMany() .Subscribe() ); var shouldExpand = node.IsRoot ? Observable.Return(true) : Parent.Value.WhenValueChanged(t => t.IsExpanded); var expander = shouldExpand .Where(isExpanded => isExpanded) .Take(1) .Subscribe(_ => { var x = childrenLoader.Value; }); var childrenCount = node.Children.CountChanged .Select(count => { if (count == 0) { return("0 Synapses"); } else { return($"{node.Children.Items.Count(n => n.Item.Type == RelativeType.Postsynaptic)} Postsynaptic; " + $"{node.Children.Items.Count(n => n.Item.Type == RelativeType.Presynaptic)} Presynaptic"); } }) .Subscribe(text => this.ChildrenCountText = text); var changeTag = this.WhenPropertyChanged(p => p.Tag, false) .Subscribe(async(x) => await this.OnNeuronTagChanged(cache, x)); var selector = this.WhenPropertyChanged(p => p.IsSelected) .Where(p => p.Value) .Subscribe(x => { this.selectionService.SetSelectedComponents(new object[] { x.Sender }); this.host.Target = NeuronViewModelBase.ConvertNeuronViewModelToEditorNeuron((NeuronViewModelBase)x.Sender); }); var highlighter = this.highlightService.WhenPropertyChanged(a => a.SelectedComponents) .Subscribe(p => { if (p.Sender.SelectedComponents != null) { var selection = p.Sender.SelectedComponents.OfType <object>().ToArray(); if (selection.Count() > 0 && selection[0] is string) { if (selection.Count() < 2) { this.IsHighlighted = this.NeuronId == p.Sender.PrimarySelection.ToString(); } else { this.IsHighlighted = this.NeuronId == p.Sender.PrimarySelection.ToString() && this.TerminalId == selection[1].ToString(); } } } } ); this.cleanUp = Disposable.Create(() => { expander.Dispose(); childrenCount.Dispose(); if (childrenLoader.IsValueCreated) { childrenLoader.Value.Dispose(); } changeTag.Dispose(); selector.Dispose(); highlighter.Dispose(); }); }