From d11a3ef2fd2d57acc897fabbbb3f0a28bbf28ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Mon, 2 Aug 2021 22:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=80=E9=97=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIStudio.Wpf.SFC/SFCService.cs | 12 ------- AIStudio.Wpf.SFC/ViewModels/SFCNode.xaml | 33 +++++++++++++++++-- .../ViewModels/Simulate_SolenoidViewModel.cs | 23 ++++++++++++- .../ViewModels/BindableBase.cs | 13 ++++++++ 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/AIStudio.Wpf.SFC/SFCService.cs b/AIStudio.Wpf.SFC/SFCService.cs index 647c42a..848370b 100644 --- a/AIStudio.Wpf.SFC/SFCService.cs +++ b/AIStudio.Wpf.SFC/SFCService.cs @@ -86,18 +86,6 @@ namespace AIStudio.Wpf.SFC if (startbtn != null && startbtn.LinkPoint.Value == 0)//停止 { ResetStatus(viewModel); - - //关闭所有阀门 - foreach (var node in SFCNodes[viewModel].OfType()) - { - if (node.DILinkPoint != null) - { - node.DILinkPoint.Value = 0; - } - } - - //真实情况不会改变容器液位,只是为了模拟重新启动时候为了低液位处理的 - //tank.LinkPoint.Value = 0; } else//启动 { diff --git a/AIStudio.Wpf.SFC/ViewModels/SFCNode.xaml b/AIStudio.Wpf.SFC/ViewModels/SFCNode.xaml index a7aa60b..5a9abc3 100644 --- a/AIStudio.Wpf.SFC/ViewModels/SFCNode.xaml +++ b/AIStudio.Wpf.SFC/ViewModels/SFCNode.xaml @@ -79,6 +79,34 @@ + + - - + + + diff --git a/AIStudio.Wpf.SFC/ViewModels/Simulate_SolenoidViewModel.cs b/AIStudio.Wpf.SFC/ViewModels/Simulate_SolenoidViewModel.cs index dfc4d78..201db84 100644 --- a/AIStudio.Wpf.SFC/ViewModels/Simulate_SolenoidViewModel.cs +++ b/AIStudio.Wpf.SFC/ViewModels/Simulate_SolenoidViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Reactive.Linq; using System.Text; using Util.DiagramDesigner; @@ -8,6 +9,7 @@ namespace AIStudio.Wpf.SFC.ViewModels { public class Simulate_SolenoidViewModel : SFCNode { + private IDisposable diChangedSubscription; public Simulate_SolenoidViewModel() : base(SFCNodeKinds.Simulate_Solenoid) { ItemWidth = 32; @@ -21,6 +23,17 @@ namespace AIStudio.Wpf.SFC.ViewModels { } + protected override void Init() + { + base.Init(); + if (diChangedSubscription != null) + { + diChangedSubscription.Dispose(); + } + Random random = new Random(); + diChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == "Value").Throttle(TimeSpan.FromSeconds(random.Next(1,10))).Subscribe(OnValueChanged);//Sample + } + private bool _showText; public override bool ShowText { @@ -64,11 +77,19 @@ namespace AIStudio.Wpf.SFC.ViewModels { if (DOLinkPoint != null) { - DOLinkPoint.Value = DILinkPoint.Value; + Value = DILinkPoint.Value; } } } + private void OnValueChanged(string propertyName) + { + if (DOLinkPoint != null) + { + DOLinkPoint.Value = Value; + } + } + /// /// 反馈 /// diff --git a/Util.DiagramDesigner/ViewModels/BindableBase.cs b/Util.DiagramDesigner/ViewModels/BindableBase.cs index 09c0a06..174223e 100644 --- a/Util.DiagramDesigner/ViewModels/BindableBase.cs +++ b/Util.DiagramDesigner/ViewModels/BindableBase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Reactive.Linq; using System.Runtime.CompilerServices; using System.Text; @@ -130,6 +131,18 @@ namespace Util.DiagramDesigner { PropertyChanged?.Invoke(this, args); } + + public IObservable WhenPropertyChanged + { + get + { + return Observable + .FromEventPattern( + h => this.PropertyChanged += h, + h => this.PropertyChanged -= h) + .Select(x => x.EventArgs.PropertyName); + } + } } public class ValuePropertyChangedEventArgs : PropertyChangedEventArgs