mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-12 12:16:37 +08:00
保存SFC数据到xml,json完成,
This commit is contained in:
@@ -5,10 +5,6 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MathParser.org-mXparser" Version="4.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
91
AIStudio.Wpf.SFC/Models/SFCNodeDesignerItem.cs
Normal file
91
AIStudio.Wpf.SFC/Models/SFCNodeDesignerItem.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using AIStudio.Wpf.SFC.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Xml.Serialization;
|
||||
using Util.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.Models
|
||||
{
|
||||
public class SFCNodeDesignerItem : DesignerItemBase
|
||||
{
|
||||
public SFCNodeDesignerItem()
|
||||
{
|
||||
|
||||
}
|
||||
public SFCNodeDesignerItem(SFCNode item) : base(item)
|
||||
{
|
||||
this.Connectors = new List<ConnectorItem>();
|
||||
foreach (var fullyCreatedConnectorInfo in item.Connectors)
|
||||
{
|
||||
ConnectorItem connector = new ConnectorItem()
|
||||
{
|
||||
XRatio = fullyCreatedConnectorInfo.XRatio,
|
||||
YRatio = fullyCreatedConnectorInfo.YRatio,
|
||||
ConnectorWidth = fullyCreatedConnectorInfo.ConnectorWidth,
|
||||
ConnectorHeight = fullyCreatedConnectorInfo.ConnectorHeight,
|
||||
Orientation = fullyCreatedConnectorInfo.Orientation,
|
||||
IsInnerPoint = fullyCreatedConnectorInfo.IsInnerPoint,
|
||||
ValueTypePoint = fullyCreatedConnectorInfo.ValueTypePoint,
|
||||
ConnectorValue = fullyCreatedConnectorInfo.ConnectorValue
|
||||
};
|
||||
this.Connectors.Add(connector);
|
||||
}
|
||||
Kind = item.Kind;
|
||||
Expression = item.Expression;
|
||||
|
||||
if (item is SFCActionNode actionNode)
|
||||
{
|
||||
LinkPoints = new List<LinkPoint> { actionNode.LinkPoint };
|
||||
}
|
||||
else if (item is SFCConditionNode sFCConditionNode)
|
||||
{
|
||||
LinkPoints = new List<LinkPoint>(sFCConditionNode.LinkPoint);
|
||||
}
|
||||
else if (item is Simulate_SolenoidViewModel simulate_SolenoidViewModel)
|
||||
{
|
||||
LinkPoints = new List<LinkPoint> { simulate_SolenoidViewModel.DILinkPoint, simulate_SolenoidViewModel.DOLinkPoint };
|
||||
}
|
||||
else if (item is Simulate_StartViewModel simulate_StartViewModel)
|
||||
{
|
||||
LinkPoints = new List<LinkPoint> { simulate_StartViewModel.LinkPoint };
|
||||
}
|
||||
else if (item is Simulate_TankViewModel simulate_TankViewModel)
|
||||
{
|
||||
LinkPoints = new List<LinkPoint> { simulate_TankViewModel.LinkPoint };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[XmlArray]
|
||||
public List<ConnectorItem> Connectors { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public SFCNodeKinds Kind { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public string Expression { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public List<LinkPoint> LinkPoints { get; set; } = new List<LinkPoint>();
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlElement("LinkPoint")]
|
||||
public string XmlLinkPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return SFCService.SerializeLinkPoint(LinkPoints);
|
||||
}
|
||||
set
|
||||
{
|
||||
LinkPoints = SFCService.DeserializeLinkPoint(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,18 @@ namespace AIStudio.Wpf.SFC
|
||||
{
|
||||
LinkPoint = new List<LinkPoint>();
|
||||
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "S0", Despcription = "启动按钮", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K1_DI", Despcription = "阀门1输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K2_DI", Despcription = "阀门2输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K3_DI", Despcription = "阀门3输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K4_DI", Despcription = "阀门4输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K1_DO", Despcription = "阀门1反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K2_DO", Despcription = "阀门2反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K3_DO", Despcription = "阀门3反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "K4_DO", Despcription = "阀门4反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "T1", Despcription = "容器1液位", Value = 100, });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "T2", Despcription = "容器2液位", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.NewGuid(), Name = "T3", Despcription = "容器3液位", Value = 20 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("9943AC3B-5E19-4AF4-8CB0-26998FC31545"), Name = "S0", Despcription = "启动按钮", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("F60007E3-913B-43C4-B80B-9624B4BD95AC"), Name = "K1_DI", Despcription = "阀门1输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("8B2CBA04-A9C8-4FF0-BE95-27546292FB90"), Name = "K2_DI", Despcription = "阀门2输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("F213B720-ADC2-41C9-82B7-D77B56B99CB7"), Name = "K3_DI", Despcription = "阀门3输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("48BB7F62-A476-4A68-9DB4-5BD4201C1C26"), Name = "K4_DI", Despcription = "阀门4输入", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("5E52ACA8-8DB4-4D39-A3BF-73EE3A551253"), Name = "K1_DO", Despcription = "阀门1反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("5B8C53FF-A4CA-40BA-9F36-5C228D9D0C5A"), Name = "K2_DO", Despcription = "阀门2反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("29496600-74CF-4AB0-88D1-4C5BFAD4C405"), Name = "K3_DO", Despcription = "阀门3反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("15733895-96E5-4F90-9BC2-3C7FF0A2B048"), Name = "K4_DO", Despcription = "阀门4反馈", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("BD593101-C759-4077-A3F2-F86AA2FC6DF8"), Name = "T1", Despcription = "容器1液位", Value = 100, });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("2BCBD2C9-9BCE-4F10-B115-088DEE1F4E08"), Name = "T2", Despcription = "容器2液位", Value = 0 });
|
||||
LinkPoint.Add(new LinkPoint { Id = Guid.Parse("DBD10A3C-7E2E-4DAE-9CB0-A2132DC469DF"), Name = "T3", Despcription = "容器3液位", Value = 20 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +165,7 @@ namespace AIStudio.Wpf.SFC
|
||||
SetStatus(next, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,5 +192,27 @@ namespace AIStudio.Wpf.SFC
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string SerializeLinkPoint(List<LinkPoint> points)
|
||||
{
|
||||
return string.Join(",", points.Select(p => p.Id));
|
||||
}
|
||||
|
||||
public static List<LinkPoint> DeserializeLinkPoint(string point)
|
||||
{
|
||||
List<LinkPoint> links = new List<LinkPoint>();
|
||||
string[] pieces = point.Split(new char[] { ',' });
|
||||
foreach (var piece in pieces)
|
||||
{
|
||||
links.Add(LinkPoint.FirstOrDefault(p => p.Id.ToString() == piece));
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
public static void DisposeData(IDiagramViewModel viewModel)
|
||||
{
|
||||
SFCNodes.Remove(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,6 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
private LinkPoint _linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
|
||||
@@ -42,32 +42,6 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _para;
|
||||
public string Para
|
||||
{
|
||||
get
|
||||
{
|
||||
return _para;
|
||||
}
|
||||
set
|
||||
{
|
||||
_para = value;
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<LinkPoint> _linkPoint = new ObservableCollection<LinkPoint>();
|
||||
public ObservableCollection<LinkPoint> LinkPoint
|
||||
{
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using AIStudio.Wpf.BaseDiagram;
|
||||
using AIStudio.Wpf.BaseDiagram.Services;
|
||||
using AIStudio.Wpf.SFC.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using Util.DiagramDesigner;
|
||||
@@ -18,7 +20,7 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
ColorViewModel.FillColor.Color = Colors.Blue;
|
||||
Kind = kind;
|
||||
ItemWidth = 80;
|
||||
ItemHeight = 40;
|
||||
ItemHeight = 40;
|
||||
}
|
||||
|
||||
public SFCNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
@@ -37,12 +39,60 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
base.Init();
|
||||
|
||||
visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
SFCNodeDesignerItem designer = designerbase as SFCNodeDesignerItem;
|
||||
this.Kind = designer.Kind;
|
||||
this.Expression = designer.Expression;
|
||||
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this, connector.Orientation, true);
|
||||
fullyCreatedConnectorInfo.XRatio = connector.XRatio;
|
||||
fullyCreatedConnectorInfo.YRatio = connector.YRatio;
|
||||
fullyCreatedConnectorInfo.ConnectorWidth = connector.ConnectorWidth;
|
||||
fullyCreatedConnectorInfo.ConnectorHeight = connector.ConnectorHeight;
|
||||
fullyCreatedConnectorInfo.Orientation = connector.Orientation;
|
||||
fullyCreatedConnectorInfo.IsInnerPoint = connector.IsInnerPoint;
|
||||
fullyCreatedConnectorInfo.ValueTypePoint = connector.ValueTypePoint;
|
||||
fullyCreatedConnectorInfo.ConnectorValue = connector.ConnectorValue;
|
||||
|
||||
if (fullyCreatedConnectorInfo.Orientation == ConnectorOrientation.Left)
|
||||
{
|
||||
Input.Add(Input.Count, fullyCreatedConnectorInfo);
|
||||
}
|
||||
else if (fullyCreatedConnectorInfo.Orientation == ConnectorOrientation.Right)
|
||||
{
|
||||
Output.Add(Output.Count, fullyCreatedConnectorInfo);
|
||||
}
|
||||
AddConnector(fullyCreatedConnectorInfo);
|
||||
}
|
||||
|
||||
if (this is SFCActionNode actionNode)
|
||||
{
|
||||
actionNode.LinkPoint = designer.LinkPoints.FirstOrDefault();
|
||||
}
|
||||
else if (this is SFCConditionNode sFCConditionNode)
|
||||
{
|
||||
sFCConditionNode.LinkPoint = new System.Collections.ObjectModel.ObservableCollection<LinkPoint>(designer.LinkPoints);
|
||||
}
|
||||
else if (this is Simulate_SolenoidViewModel simulate_SolenoidViewModel)
|
||||
{
|
||||
simulate_SolenoidViewModel.DILinkPoint = designer.LinkPoints.FirstOrDefault();
|
||||
simulate_SolenoidViewModel.DOLinkPoint = designer.LinkPoints.LastOrDefault();
|
||||
}
|
||||
else if (this is Simulate_StartViewModel simulate_StartViewModel)
|
||||
{
|
||||
simulate_StartViewModel.LinkPoint = designer.LinkPoints.FirstOrDefault();
|
||||
}
|
||||
else if (this is Simulate_TankViewModel simulate_TankViewModel)
|
||||
{
|
||||
simulate_TankViewModel.LinkPoint = designer.LinkPoints.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void InitConnector()
|
||||
@@ -136,6 +186,20 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
#region 暂不保存
|
||||
private int _status;
|
||||
|
||||
public int Status
|
||||
@@ -149,5 +213,6 @@ namespace AIStudio.Wpf.SFC.ViewModels
|
||||
|
||||
public List<SFCNode> NextNode { get; set; } = new List<SFCNode>();
|
||||
public List<SFCNode> PreNode { get; set; } = new List<SFCNode>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user