mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
阀门优化
This commit is contained in:
@@ -86,18 +86,6 @@ namespace AIStudio.Wpf.SFC
|
||||
if (startbtn != null && startbtn.LinkPoint.Value == 0)//停止
|
||||
{
|
||||
ResetStatus(viewModel);
|
||||
|
||||
//关闭所有阀门
|
||||
foreach (var node in SFCNodes[viewModel].OfType<Simulate_SolenoidViewModel>())
|
||||
{
|
||||
if (node.DILinkPoint != null)
|
||||
{
|
||||
node.DILinkPoint.Value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//真实情况不会改变容器液位,只是为了模拟重新启动时候为了低液位处理的
|
||||
//tank.LinkPoint.Value = 0;
|
||||
}
|
||||
else//启动
|
||||
{
|
||||
|
||||
@@ -79,6 +79,34 @@
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="{x:Type ToggleButton}" x:Key="SolenoidControlToggleButtonStyle">
|
||||
<Setter Property="Background" Value="Red"/>
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Grid x:Name="Grid" Margin="{TemplateBinding Padding}">
|
||||
<Ellipse x:Name="path" Fill="Red" Stroke="Black" Stretch="Uniform"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource GrayBrush8}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Fluent.Ribbon.Brushes.HighlightBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Fill" TargetName="path" Value="Green" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value="0.6" TargetName="Grid"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type ToggleButton}" x:Key="SolenoidToggleButtonStyle">
|
||||
<Setter Property="Background" Value="Red"/>
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
@@ -139,8 +167,9 @@
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="SolenoidStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid Margin="0,5">
|
||||
<ToggleButton Style="{StaticResource SolenoidToggleButtonStyle}" IsChecked="{Binding DOLinkPoint.Value, Converter={StaticResource IntToBoolConverter}}"/>
|
||||
<Grid Margin="0,5">
|
||||
<ToggleButton Style="{StaticResource SolenoidToggleButtonStyle}" IsChecked="{Binding DOLinkPoint.Value, Converter={StaticResource IntToBoolConverter}}" IsHitTestVisible="False" />
|
||||
<ToggleButton Style="{StaticResource SolenoidControlToggleButtonStyle}" IsChecked="{Binding DILinkPoint.Value, Converter={StaticResource IntToBoolConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16"/>
|
||||
<TextBlock Text="{Binding Text}" RenderTransformOrigin="0.5,1" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="2">
|
||||
<TextBlock.RenderTransform>
|
||||
<TranslateTransform Y="16"/>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反馈
|
||||
/// </summary>
|
||||
|
||||
@@ -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<string> WhenPropertyChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
return Observable
|
||||
.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
|
||||
h => this.PropertyChanged += h,
|
||||
h => this.PropertyChanged -= h)
|
||||
.Select(x => x.EventArgs.PropertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ValuePropertyChangedEventArgs : PropertyChangedEventArgs
|
||||
|
||||
Reference in New Issue
Block a user