mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 16:56:34 +08:00
使用设计模式优化一下逻辑图
This commit is contained in:
@@ -169,277 +169,12 @@ namespace AIStudio.Wpf.Logical
|
||||
{
|
||||
link.Value = rd.NextDouble() * 10;
|
||||
}
|
||||
foreach (var item in DiagramViewModel.Items.OfType<ConstantDesignerItemViewModel>())
|
||||
{
|
||||
foreach (var output in item.Output)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Value;
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in DiagramViewModel.Items.OfType<InputItemViewModel>())
|
||||
{
|
||||
if (item.LinkPoint != null)
|
||||
{
|
||||
foreach (var output in item.Output)
|
||||
{
|
||||
output.Value.ConnectorValue = item.LinkPoint.Value;
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in DiagramViewModel.Items.OfType<LogicalGateItemViewModelBase>().OrderBy(p => p.OrderNumber))
|
||||
{
|
||||
if (item.LogicalType != LogicalType.None)
|
||||
{
|
||||
foreach (var input in item.Input)
|
||||
{
|
||||
var connector = GetSourceItem(input.Value);
|
||||
if (connector == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connector.SourceConnectorInfo.DataItem is LogicalGateItemViewModelBase)
|
||||
{
|
||||
input.Value.ConnectorValue = (connector.SourceConnectorInfo as LogicalConnectorInfo).ConnectorValue;
|
||||
|
||||
input.Value.ColorViewModel.FillColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
connector.ColorViewModel.LineColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
connector.ColorViewModel.FillColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
|
||||
if (item.LogicalType == LogicalType.Output)
|
||||
{
|
||||
input.Value.ValueTypePoint = (connector.SourceConnectorInfo as LogicalConnectorInfo).ValueTypePoint;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.NOT)
|
||||
{
|
||||
input.Value.ValueTypePoint = ((connector.SourceConnectorInfo as LogicalConnectorInfo).ValueTypePoint == ValueTypePoint.Bool) ? ValueTypePoint.Bool : ValueTypePoint.Int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var output in item.Output)
|
||||
{
|
||||
if (item.LogicalType == LogicalType.Output)
|
||||
{
|
||||
var first = item.Input.Values.FirstOrDefault();
|
||||
output.Value.ConnectorValue = first.ConnectorValue;
|
||||
output.Value.ValueTypePoint = first.ValueTypePoint;
|
||||
(item as OutputItemViewModel).Value = first.ConnectorValue;
|
||||
(item as OutputItemViewModel).LinkPoint.Value = first.ConnectorValue;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ADD)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Input.Values.Select(p => p.ConnectorValue).Sum();
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SUB)
|
||||
{
|
||||
var first = item.Input.Values.Select(p => p.ConnectorValue).FirstOrDefault();
|
||||
var second = item.Input.Values.Where((value, index) => index != 0).Select(p => p.ConnectorValue).Sum();
|
||||
output.Value.ConnectorValue = first - second;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.MUL)
|
||||
{
|
||||
double result = 0;
|
||||
foreach (var input in item.Input.Values)
|
||||
{
|
||||
if (result == 0)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
result *= input.ConnectorValue;
|
||||
}
|
||||
output.Value.ConnectorValue = result;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.DIV)
|
||||
{
|
||||
double result = item.Input.Values.Select(p => p.ConnectorValue).FirstOrDefault();
|
||||
foreach (var input in item.Input.Values.Where((value, index) => index != 0))
|
||||
{
|
||||
result /= input.ConnectorValue;
|
||||
}
|
||||
output.Value.ConnectorValue = result;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.AVE)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Input.Values.Select(p => p.ConnectorValue).Average();
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.MOD)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Input[0].ConnectorValue % item.Input[1].ConnectorValue;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.AND)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(item.Input[0].ConnectorValue) & Convert.ToInt32(item.Input[1].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.OR)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(item.Input[0].ConnectorValue) | Convert.ToInt32(item.Input[1].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.XOR)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Convert.ToInt32(item.Input[0].ConnectorValue) ^ Convert.ToInt32(item.Input[1].ConnectorValue));
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.NOT)
|
||||
{
|
||||
if (item.Input[0].ValueTypePoint == ValueTypePoint.Bool)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(!Convert.ToBoolean(item.Input[0].ConnectorValue));
|
||||
output.Value.ValueTypePoint = ValueTypePoint.Bool;
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ConnectorValue = ~Convert.ToInt32(item.Input[0].ConnectorValue);
|
||||
output.Value.ValueTypePoint = ValueTypePoint.Int;
|
||||
}
|
||||
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SHL)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(item.Input[0].ConnectorValue) << Convert.ToInt32(item.Input[1].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SHR)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(item.Input[0].ConnectorValue) >> Convert.ToInt32(item.Input[1].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ROL)
|
||||
{
|
||||
output.Value.ConnectorValue = (Convert.ToInt32(item.Input[0].ConnectorValue) << Convert.ToInt32(item.Input[1].ConnectorValue)) | (Convert.ToInt32(item.Input[0].ConnectorValue) >> 32 - Convert.ToInt32(item.Input[1].ConnectorValue));
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ROR)
|
||||
{
|
||||
output.Value.ConnectorValue = (Convert.ToInt32(item.Input[0].ConnectorValue) >> Convert.ToInt32(item.Input[1].ConnectorValue)) | (Convert.ToInt32(item.Input[0].ConnectorValue) << 32 - Convert.ToInt32(item.Input[1].ConnectorValue));
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SEL)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue == output.Key) ? item.Input[1].ConnectorValue : item.Input[2].ConnectorValue;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.MAX)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Input.Values.Select(p => p.ConnectorValue).Max();
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.MIN)
|
||||
{
|
||||
output.Value.ConnectorValue = item.Input.Values.Select(p => p.ConnectorValue).Min();
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.LIMIT)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue > item.Input[1].ConnectorValue) ? item.Input[1].ConnectorValue : item.Input[0].ConnectorValue;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.GT)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue > item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.LT)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue < item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.GE)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue >= item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.LE)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue <= item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.EQ)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue == item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.NE)
|
||||
{
|
||||
output.Value.ConnectorValue = (item.Input[0].ConnectorValue != item.Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ABS)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Abs(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SQRT)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Sqrt(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.LN)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Log10(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.LOG)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Log(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.EXP)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Exp(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.SIN)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Sin(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.COS)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Cos(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.TAN)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Tan(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ASIN)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Asin(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ACOS)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Acos(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.ATAN)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Atan(item.Input[0].ConnectorValue);
|
||||
}
|
||||
else if (item.LogicalType == LogicalType.EXPT)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Exp(item.Input[0].ConnectorValue);
|
||||
}
|
||||
|
||||
if (output.Value.ValueTypePoint == ValueTypePoint.Bool)
|
||||
{
|
||||
if (output.Value.ConnectorValue == 0)
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
if (item.LogicalType == LogicalType.Output)
|
||||
{
|
||||
item.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
if (item.LogicalType == LogicalType.Output)
|
||||
{
|
||||
item.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
}
|
||||
item.GetInput();
|
||||
item.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectionViewModel GetSourceItem(FullyCreatedConnectorInfo sinkConnector)
|
||||
{
|
||||
foreach (var connector in DiagramViewModel.Items.OfType<ConnectionViewModel>())
|
||||
{
|
||||
if (connector.SinkConnectorInfo == sinkConnector)
|
||||
{
|
||||
return connector;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Geometrys
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate first Bezier control points
|
||||
// CalculateOutput first Bezier control points
|
||||
// Right hand side vector
|
||||
double[] rhs = new double[n];
|
||||
|
||||
|
||||
@@ -12,8 +12,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public abstract class LogicalGateItemViewModelBase : DesignerItemViewModelBase
|
||||
{
|
||||
public ICommand AddInputCommand { get; private set; }
|
||||
public ICommand AddOutputCommand { get; private set; }
|
||||
public ICommand AddInputCommand
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
public ICommand AddOutputCommand
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
|
||||
public LogicalGateItemViewModelBase(LogicalType logicalType) : this(null, logicalType)
|
||||
@@ -96,7 +102,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
{
|
||||
ShowRotate = false;
|
||||
ShowArrow = false;
|
||||
AddInputCommand = new SimpleCommand(Command_Enable, para => ExecuteAddInput(para));
|
||||
@@ -216,7 +222,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public LogicalType LogicalType { get; set; }
|
||||
public LogicalType LogicalType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<int, LogicalConnectorInfo> Input { get; set; } = new Dictionary<int, LogicalConnectorInfo>();
|
||||
@@ -294,6 +303,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void GetInput()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void CalculateOutput()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,65 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetInput()
|
||||
{
|
||||
foreach (var input in Input)
|
||||
{
|
||||
var connector = GetSourceItem(input.Value);
|
||||
if (connector == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connector.SourceConnectorInfo.DataItem is LogicalGateItemViewModelBase)
|
||||
{
|
||||
input.Value.ConnectorValue = (connector.SourceConnectorInfo as LogicalConnectorInfo).ConnectorValue;
|
||||
|
||||
input.Value.ColorViewModel.FillColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
connector.ColorViewModel.LineColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
connector.ColorViewModel.FillColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color;
|
||||
|
||||
if (LogicalType == LogicalType.Output)
|
||||
{
|
||||
input.Value.ValueTypePoint = (connector.SourceConnectorInfo as LogicalConnectorInfo).ValueTypePoint;
|
||||
}
|
||||
else if (LogicalType == LogicalType.NOT)
|
||||
{
|
||||
input.Value.ValueTypePoint = ((connector.SourceConnectorInfo as LogicalConnectorInfo).ValueTypePoint == ValueTypePoint.Bool) ? ValueTypePoint.Bool : ValueTypePoint.Int;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
if (output.Value.ValueTypePoint == ValueTypePoint.Bool)
|
||||
{
|
||||
if (output.Value.ConnectorValue == 0)
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
if (LogicalType == LogicalType.Output)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Red;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
if (LogicalType == LogicalType.Output)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
@@ -78,6 +137,18 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ConnectionViewModel GetSourceItem(FullyCreatedConnectorInfo sinkConnector)
|
||||
{
|
||||
foreach (var connector in Root?.Items.OfType<ConnectionViewModel>())
|
||||
{
|
||||
if (connector.SinkConnectorInfo == sinkConnector)
|
||||
{
|
||||
return connector;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class AddGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -98,6 +169,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Input.Values.Select(p => p.ConnectorValue).Sum();
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SubtractGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -118,6 +198,17 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
var first = Input.Values.Select(p => p.ConnectorValue).FirstOrDefault();
|
||||
var second = Input.Values.Where((value, index) => index != 0).Select(p => p.ConnectorValue).Sum();
|
||||
output.Value.ConnectorValue = first - second;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiplyGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -138,6 +229,24 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
double result = 0;
|
||||
foreach (var input in Input.Values)
|
||||
{
|
||||
if (result == 0)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
result *= input.ConnectorValue;
|
||||
}
|
||||
output.Value.ConnectorValue = result;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class DivideGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -159,6 +268,20 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
double result = Input.Values.Select(p => p.ConnectorValue).FirstOrDefault();
|
||||
foreach (var input in Input.Values.Where((value, index) => index != 0))
|
||||
{
|
||||
result /= input.ConnectorValue;
|
||||
}
|
||||
output.Value.ConnectorValue = result;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class AverageGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -181,6 +304,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Input.Values.Select(p => p.ConnectorValue).Average();
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class MODGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -203,6 +335,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Input[0].ConnectorValue % Input[1].ConnectorValue;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ANDGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -225,6 +366,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Input[0].ConnectorValue) & Convert.ToInt32(Input[1].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ORGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -247,6 +397,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Input[0].ConnectorValue) | Convert.ToInt32(Input[1].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class XORGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -269,6 +428,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Convert.ToInt32(Input[0].ConnectorValue) ^ Convert.ToInt32(Input[1].ConnectorValue));
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class NOTGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -291,6 +459,24 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
if (Input[0].ValueTypePoint == ValueTypePoint.Bool)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(!Convert.ToBoolean(Input[0].ConnectorValue));
|
||||
output.Value.ValueTypePoint = ValueTypePoint.Bool;
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Value.ConnectorValue = ~Convert.ToInt32(Input[0].ConnectorValue);
|
||||
output.Value.ValueTypePoint = ValueTypePoint.Int;
|
||||
}
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SHLGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -313,6 +499,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Input[0].ConnectorValue) << Convert.ToInt32(Input[1].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SHRGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -335,6 +530,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Convert.ToInt32(Input[0].ConnectorValue) >> Convert.ToInt32(Input[1].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ROLGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -357,6 +561,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Convert.ToInt32(Input[0].ConnectorValue) << Convert.ToInt32(Input[1].ConnectorValue)) | (Convert.ToInt32(Input[0].ConnectorValue) >> 32 - Convert.ToInt32(Input[1].ConnectorValue));
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class RORGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -379,6 +592,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Convert.ToInt32(Input[0].ConnectorValue) >> Convert.ToInt32(Input[1].ConnectorValue)) | (Convert.ToInt32(Input[0].ConnectorValue) << 32 - Convert.ToInt32(Input[1].ConnectorValue));
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SELGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -401,6 +623,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue == output.Key) ? Input[1].ConnectorValue : Input[2].ConnectorValue;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class MAXGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -423,6 +654,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Input.Values.Select(p => p.ConnectorValue).Max();
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class MINGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -445,6 +685,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Input.Values.Select(p => p.ConnectorValue).Min();
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class LIMITGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -467,6 +716,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue > Input[1].ConnectorValue) ? Input[1].ConnectorValue : Input[0].ConnectorValue;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class GTGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -489,6 +747,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue > Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class LTGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -511,6 +778,14 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue < Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GEGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -533,6 +808,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue >= Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class LEGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -555,6 +839,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue <= Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class EQGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -577,6 +870,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue == Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class NEGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -599,6 +901,16 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = (Input[0].ConnectorValue != Input[1].ConnectorValue) ? 1 : 0;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ABSGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -621,6 +933,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Abs(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SQRTGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -643,6 +964,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Sqrt(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class LNGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -665,6 +995,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Log10(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class LOGGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -687,6 +1026,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Log(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class EXPGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -709,6 +1057,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Exp(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class SINGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -731,6 +1088,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Sin(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class COSGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -753,6 +1119,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Cos(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class TANGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -775,6 +1150,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Tan(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ASINGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -797,6 +1181,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Asin(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ACOSGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -819,6 +1212,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Acos(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ATANGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -841,6 +1243,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Atan(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class EXPTGateItemViewModel : LogicalGateItemViewModel
|
||||
@@ -863,6 +1274,15 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Math.Exp(Input[0].ConnectorValue);
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class ConstantDesignerItemViewModel : LogicalGateItemViewModel
|
||||
@@ -886,6 +1306,20 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void GetInput()
|
||||
{
|
||||
//无输入
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = Value;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public class InputItemViewModel : LogicalGateItemViewModel
|
||||
@@ -941,6 +1375,23 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetInput()
|
||||
{
|
||||
//无输入
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
if (LinkPoint != null)
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = LinkPoint.Value;
|
||||
}
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
LinkPointDesignerItemData data = new LinkPointDesignerItemData(LinkPoint);
|
||||
@@ -1006,6 +1457,19 @@ namespace AIStudio.Wpf.Logical.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public override void CalculateOutput()
|
||||
{
|
||||
var first = Input.Values.FirstOrDefault();
|
||||
Value = first.ConnectorValue;
|
||||
LinkPoint.Value = first.ConnectorValue;
|
||||
foreach (var output in Output)
|
||||
{
|
||||
output.Value.ConnectorValue = first.ConnectorValue;
|
||||
output.Value.ValueTypePoint = first.ValueTypePoint;
|
||||
}
|
||||
base.CalculateOutput();
|
||||
}
|
||||
|
||||
protected override void ExecuteEditCommand(object parameter)
|
||||
{
|
||||
LinkPointDesignerItemData data = new LinkPointDesignerItemData(LinkPoint);
|
||||
|
||||
Reference in New Issue
Block a user