mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-20 08:26:36 +08:00
项目结构调整
This commit is contained in:
53
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCActionNode.cs
Normal file
53
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCActionNode.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCActionNode : SFCNode
|
||||
{
|
||||
public SFCActionNode() : base(SFCNodeKinds.Action)
|
||||
{
|
||||
FontViewModel.FontSize = 10;
|
||||
ItemWidth = 60;
|
||||
ItemHeight = 48;
|
||||
|
||||
ExecuteAddLeftInput(null);
|
||||
}
|
||||
|
||||
public SFCActionNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCActionNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private LinkPoint _linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
SFCActionNodeData data = new SFCActionNodeData(LinkPoint, Expression);
|
||||
if (visualiserService.ShowDialog(data) == true)
|
||||
{
|
||||
this.LinkPoint = data.LinkPoint;
|
||||
this.Expression = data.Expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCActionNodeData.cs
Normal file
60
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCActionNodeData.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// This is passed to the PopupWindow.xaml window, where a DataTemplate is used to provide the
|
||||
/// ContentControl with the look for this data. This class is also used to allow
|
||||
/// the popup to be cancelled without applying any changes to the calling ViewModel
|
||||
/// whos data will be updated if the PopupWindow.xaml window is closed successfully
|
||||
/// </summary>
|
||||
public class SFCActionNodeData : BindableBase
|
||||
{
|
||||
private string _title;
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _title, value);
|
||||
}
|
||||
}
|
||||
|
||||
public SFCActionNodeData(LinkPoint linkPoint, string expression)
|
||||
{
|
||||
Title = "输出动作";
|
||||
|
||||
LinkPoint = linkPoint;
|
||||
Expression = expression;
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
private LinkPoint _linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _linkPoint, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
56
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCCOBeginNode.cs
Normal file
56
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCCOBeginNode.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCCOBeginNode : SFCNode
|
||||
{
|
||||
public SFCCOBeginNode() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCCOBeginNode(IDiagramViewModel root) : base(root, SFCNodeKinds.COBegin)
|
||||
{
|
||||
ItemWidth = 280;
|
||||
ItemHeight = 10;
|
||||
|
||||
ExecuteAddTopInput(null);
|
||||
ExecuteAddBottomOutput(null);
|
||||
ExecuteAddBottomOutput(null);
|
||||
}
|
||||
|
||||
public SFCCOBeginNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public SFCCOBeginNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExecuteAddTopInput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);
|
||||
connector.YRatio = 0;
|
||||
connector.XRatio = (40 + Input.Count * 200) / ItemWidth;
|
||||
Input.Add(Input.Count, connector);
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public override void ExecuteAddBottomOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom, true);
|
||||
connector.YRatio = 1;
|
||||
connector.XRatio = (40 + Output.Count * 200) / ItemWidth;
|
||||
Output.Add(Output.Count, connector);
|
||||
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCCOEndNode.cs
Normal file
56
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCCOEndNode.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCCOEndNode : SFCNode
|
||||
{
|
||||
public SFCCOEndNode() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCCOEndNode(IDiagramViewModel root) : base(root, SFCNodeKinds.COEnd)
|
||||
{
|
||||
ItemWidth = 280;
|
||||
ItemHeight = 10;
|
||||
|
||||
ExecuteAddBottomOutput(null);
|
||||
ExecuteAddTopInput(null);
|
||||
ExecuteAddTopInput(null);
|
||||
}
|
||||
|
||||
public SFCCOEndNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public SFCCOEndNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExecuteAddTopInput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);
|
||||
connector.YRatio = 0;
|
||||
connector.XRatio = (40 + Input.Count * 200) / ItemWidth;
|
||||
Input.Add(Input.Count, connector);
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public override void ExecuteAddBottomOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom, true);
|
||||
connector.YRatio = 1;
|
||||
connector.XRatio = (40 + Output.Count * 200) / ItemWidth;
|
||||
Output.Add(Output.Count, connector);
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
72
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCConditionNode.cs
Normal file
72
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCConditionNode.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCConditionNode : SFCNode
|
||||
{
|
||||
public SFCConditionNode() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCConditionNode(IDiagramViewModel root) : base(root, SFCNodeKinds.Condition)
|
||||
{
|
||||
ColorViewModel.LineColor.Color = Colors.Black;
|
||||
ItemWidth = 30;
|
||||
ItemHeight = 30;
|
||||
|
||||
ExecuteAddTopInput(null);
|
||||
ExecuteAddBottomOutput(null);
|
||||
}
|
||||
|
||||
public SFCConditionNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public SFCConditionNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
CustomText = true;
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
}
|
||||
|
||||
private ObservableCollection<LinkPoint> _linkPoint = new ObservableCollection<LinkPoint>();
|
||||
public ObservableCollection<LinkPoint> LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
SFCConditionNodeData data = new SFCConditionNodeData(LinkPoint, Expression);
|
||||
if (visualiserService.ShowDialog(data) == true)
|
||||
{
|
||||
this.LinkPoint = new ObservableCollection<LinkPoint>(data.LinkPoint.Select(p => SFCService.LinkPoint.FirstOrDefault(q => q.Name == p.Name)));
|
||||
this.Expression = data.Expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// This is passed to the PopupWindow.xaml window, where a DataTemplate is used to provide the
|
||||
/// ContentControl with the look for this data. This class is also used to allow
|
||||
/// the popup to be cancelled without applying any changes to the calling ViewModel
|
||||
/// whos data will be updated if the PopupWindow.xaml window is closed successfully
|
||||
/// </summary>
|
||||
public class SFCConditionNodeData : BindableBase
|
||||
{
|
||||
private string _title;
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _title, value);
|
||||
}
|
||||
}
|
||||
public SFCConditionNodeData(IEnumerable<LinkPoint> linkPoint, string expression)
|
||||
{
|
||||
Title = "转移条件";
|
||||
LinkPoint = new ObservableCollection<LinkPoint>(linkPoint);
|
||||
Expression = expression;
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<LinkPoint> _linkPoint;
|
||||
public ObservableCollection<LinkPoint> LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _addCommand;
|
||||
public ICommand AddCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._addCommand ?? (this._addCommand = new SimpleCommand(para => { return true; }, para => this.AddExecuted(para)));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _deleteCommand;
|
||||
public ICommand DeleteCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._deleteCommand ?? (this._deleteCommand = new SimpleCommand(para => { return true; }, para => this.DeleteExecuted(para)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void AddExecuted(object para)
|
||||
{
|
||||
LinkPoint.Add(new SFC.LinkPoint());
|
||||
}
|
||||
|
||||
private void DeleteExecuted(object para)
|
||||
{
|
||||
LinkPoint.Remove(para as SFC.LinkPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
225
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCNode.cs
Normal file
225
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCNode.cs
Normal file
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.DiagramDesigner.Services;
|
||||
using AIStudio.Wpf.SFC.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCNode : DesignerItemViewModelBase
|
||||
{
|
||||
protected IUIVisualizerService visualiserService;
|
||||
|
||||
public SFCNode(SFCNodeKinds kind) : this(null, kind)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCNode(IDiagramViewModel root, SFCNodeKinds kind) : base(root)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Blue;
|
||||
Kind = kind;
|
||||
ItemWidth = 80;
|
||||
ItemHeight = 40;
|
||||
}
|
||||
|
||||
public SFCNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new SFCNodeDesignerItem(this);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
IsInnerConnector = true;
|
||||
ShowRotate = false;
|
||||
ShowArrow = false;
|
||||
ShowText = true;
|
||||
IsReadOnlyText = true;
|
||||
|
||||
base.Init(root, initNew);
|
||||
|
||||
visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
ClearConnectors();
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
if (designerbase is SFCNodeDesignerItem designer)
|
||||
{
|
||||
this.Kind = designer.Kind;
|
||||
this.Expression = designer.Expression;
|
||||
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this.Root, this, connector);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Input { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Output { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Action { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
|
||||
public virtual void ExecuteAddLeftInput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left, true);
|
||||
connector.XRatio = 0;
|
||||
Input.Add(Input.Count, connector);
|
||||
for (int i = 0; i < Input.Values.Count; i++)
|
||||
{
|
||||
Input[i].YRatio = (i + 1.0) / (Input.Values.Count + 1.0);
|
||||
}
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public virtual void ExecuteAddTopInput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);
|
||||
connector.YRatio = 0;
|
||||
Input.Add(Input.Count, connector);
|
||||
for (int i = 0; i < Input.Values.Count; i++)
|
||||
{
|
||||
Input[i].XRatio = (i + 1.0) / (Input.Values.Count + 1.0);
|
||||
if (Output.ContainsKey(i))
|
||||
{
|
||||
Output[i].XRatio = Input[i].XRatio;
|
||||
}
|
||||
}
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public virtual void ExecuteAddRightOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right, true);
|
||||
connector.XRatio = 1;
|
||||
Output.Add(Output.Count, connector);
|
||||
for (int i = 0; i < Output.Values.Count; i++)
|
||||
{
|
||||
Output[i].YRatio = (i + 1.0) / (Output.Values.Count + 1.0);
|
||||
}
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public virtual void ExecuteAddBottomOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom, true);
|
||||
connector.YRatio = 1;
|
||||
Output.Add(Output.Count, connector);
|
||||
for (int i = 0; i < Output.Values.Count; i++)
|
||||
{
|
||||
Output[i].XRatio = (i + 1.0) / (Output.Values.Count + 1.0);
|
||||
if (Input.ContainsKey(i))
|
||||
{
|
||||
Input[i].XRatio = Output[i].XRatio;
|
||||
}
|
||||
}
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public virtual void ExecuteAddActionOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right, true);
|
||||
connector.XRatio = 1;
|
||||
Action.Add(Action.Count, connector);
|
||||
Action[Action.Count - 1].YRatio = 0.5;
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public SFCNodeKinds Kind { get; set; }
|
||||
|
||||
private double _value;
|
||||
public double Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _value, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _expression;
|
||||
public string Expression
|
||||
{
|
||||
get
|
||||
{
|
||||
return _expression;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _expression, value);
|
||||
}
|
||||
}
|
||||
|
||||
#region 暂不保存
|
||||
private int _status;
|
||||
|
||||
public int Status
|
||||
{
|
||||
get { return _status; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _status, value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<SFCNode> NextNode { get; set; } = new List<SFCNode>();
|
||||
public List<SFCNode> PreNode { get; set; } = new List<SFCNode>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
28
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCNodeNode.cs
Normal file
28
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCNodeNode.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCNodeNode : SFCNode
|
||||
{
|
||||
public SFCNodeNode() : base(SFCNodeKinds.Node)
|
||||
{
|
||||
ExecuteAddTopInput(null);
|
||||
ExecuteAddBottomOutput(null);
|
||||
ExecuteAddActionOutput(null);
|
||||
}
|
||||
|
||||
public SFCNodeNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public SFCNodeNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCStartNode.cs
Normal file
31
Extensions/AIStudio.Wpf.SFC/ViewModels/SFCStartNode.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class SFCStartNode : SFCNode
|
||||
{
|
||||
public SFCStartNode() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SFCStartNode(IDiagramViewModel root) : base(root, SFCNodeKinds.Start)
|
||||
{
|
||||
ExecuteAddTopInput(null);
|
||||
ExecuteAddBottomOutput(null);
|
||||
}
|
||||
|
||||
public SFCStartNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public SFCStartNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_ListViewModel : SFCNode
|
||||
{
|
||||
public Simulate_ListViewModel() : base(SFCNodeKinds.Simulate_List)
|
||||
{
|
||||
ItemWidth = 170;
|
||||
ItemHeight = 260;
|
||||
}
|
||||
|
||||
public Simulate_ListViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public Simulate_ListViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_SolenoidViewModel : SFCNode
|
||||
{
|
||||
private IDisposable diChangedSubscription;
|
||||
public Simulate_SolenoidViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Simulate_SolenoidViewModel(IDiagramViewModel root) : base(root, SFCNodeKinds.Simulate_Solenoid)
|
||||
{
|
||||
ItemWidth = 32;
|
||||
ItemHeight = 32;
|
||||
|
||||
ExecuteAddLeftInput(null);
|
||||
ExecuteAddRightOutput(null);
|
||||
}
|
||||
|
||||
public Simulate_SolenoidViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public Simulate_SolenoidViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
CustomText = true;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 输入
|
||||
/// </summary>
|
||||
private LinkPoint _dILinkPoint;
|
||||
public LinkPoint DILinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _dILinkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_dILinkPoint != null)
|
||||
{
|
||||
_dILinkPoint.PropertyChanged -= _dILinkPoint_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _dILinkPoint, value);
|
||||
if (_dILinkPoint != null)
|
||||
{
|
||||
_dILinkPoint.PropertyChanged += _dILinkPoint_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _dILinkPoint_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Value")
|
||||
{
|
||||
if (DOLinkPoint != null)
|
||||
{
|
||||
Value = DILinkPoint.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValueChanged(string propertyName)
|
||||
{
|
||||
if (DOLinkPoint != null)
|
||||
{
|
||||
DOLinkPoint.Value = Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反馈
|
||||
/// </summary>
|
||||
private LinkPoint _dOLinkPoint;
|
||||
public LinkPoint DOLinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _dOLinkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _dOLinkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
Simulate_SolenoidViewModelData data = new Simulate_SolenoidViewModelData(DILinkPoint, DOLinkPoint);
|
||||
if (visualiserService.ShowDialog(data) == true)
|
||||
{
|
||||
this.DILinkPoint = data.DILinkPoint;
|
||||
this.DOLinkPoint = data.DOLinkPoint;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_SolenoidViewModelData : BindableBase
|
||||
{
|
||||
private string _title;
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _title, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Simulate_SolenoidViewModelData(LinkPoint dILinkPoint, LinkPoint dOLinkPoint)
|
||||
{
|
||||
Title = "阀门";
|
||||
DILinkPoint = dILinkPoint;
|
||||
DOLinkPoint = dOLinkPoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 输入
|
||||
/// </summary>
|
||||
private LinkPoint _dILinkPoint;
|
||||
public LinkPoint DILinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _dILinkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _dILinkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反馈
|
||||
/// </summary>
|
||||
private LinkPoint _dOLinkPoint;
|
||||
public LinkPoint DOLinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _dOLinkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _dOLinkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_StartViewModel : SFCNode
|
||||
{
|
||||
public Simulate_StartViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Simulate_StartViewModel(IDiagramViewModel root) : base(root, SFCNodeKinds.Simulate_Start)
|
||||
{
|
||||
ItemWidth = 32;
|
||||
ItemHeight = 32;
|
||||
|
||||
ExecuteAddLeftInput(null);
|
||||
ExecuteAddRightOutput(null);
|
||||
}
|
||||
|
||||
public Simulate_StartViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public Simulate_StartViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private LinkPoint linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_TankViewModel : SFCNode
|
||||
{
|
||||
public Simulate_TankViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Simulate_TankViewModel(IDiagramViewModel root) : base(root, SFCNodeKinds.Simulate_Tank)
|
||||
{
|
||||
ItemWidth = 50;
|
||||
ItemHeight = 120;
|
||||
|
||||
ExecuteAddLeftInput(null);
|
||||
ExecuteAddLeftInput(null);
|
||||
ExecuteAddRightOutput(null);
|
||||
ExecuteAddRightOutput(null);
|
||||
}
|
||||
|
||||
public Simulate_TankViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public Simulate_TankViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExecuteAddLeftInput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left, true);
|
||||
connector.XRatio = 0;
|
||||
connector.YRatio = (30 + Input.Count * 60) / ItemHeight;
|
||||
Input.Add(Input.Count, connector);
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
public override void ExecuteAddRightOutput(object parameter)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right, true);
|
||||
connector.XRatio = 1;
|
||||
connector.YRatio = (30 + Output.Count * 60) / ItemHeight;
|
||||
Output.Add(Output.Count, connector);
|
||||
|
||||
|
||||
AddConnector(connector);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 液位
|
||||
/// </summary>
|
||||
private LinkPoint linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
Simulate_TankViewModelData data = new Simulate_TankViewModelData(LinkPoint);
|
||||
if (visualiserService.ShowDialog(data) == true)
|
||||
{
|
||||
this.LinkPoint = data.LinkPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
double input = PreNode.OfType<Simulate_SolenoidViewModel>().Sum(p => p.DOLinkPoint?.Value ?? 0);
|
||||
double output = NextNode.OfType<Simulate_SolenoidViewModel>().Sum(p => p.DOLinkPoint?.Value ?? 0);
|
||||
if (LinkPoint != null)
|
||||
{
|
||||
LinkPoint.Value += input - output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.SFC.ViewModels
|
||||
{
|
||||
public class Simulate_TankViewModelData : BindableBase
|
||||
{
|
||||
private string _title;
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _title, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Simulate_TankViewModelData(LinkPoint linkPoint)
|
||||
{
|
||||
Title = "容器";
|
||||
LinkPoint = linkPoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 液位
|
||||
/// </summary>
|
||||
private LinkPoint linkPoint;
|
||||
public LinkPoint LinkPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return linkPoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref linkPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user