mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
Connector 错误处理
This commit is contained in:
@@ -14,31 +14,34 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (values == null || values.Length < 2)
|
||||
if (values[0] is LogicalConnectorInfo logicalConnectorInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (values[0] is double && values[2] is ConnectorValueType)
|
||||
if (logicalConnectorInfo.ErrorCode != Enums.ConnectorErrorCode.None)
|
||||
{
|
||||
double connectorValue = (double)values[0];
|
||||
string connectorString = values[1] as string;
|
||||
ConnectorValueType valueTypePoint = (ConnectorValueType)values[2];
|
||||
|
||||
if (valueTypePoint == ConnectorValueType.Bool)
|
||||
if (parameter?.ToString() == "ToolTip")
|
||||
{
|
||||
return (connectorValue == 0) ? "F" : "T";
|
||||
}
|
||||
else if (valueTypePoint == ConnectorValueType.Int)
|
||||
{
|
||||
return connectorValue.ToString("0");
|
||||
}
|
||||
else if (valueTypePoint == ConnectorValueType.Real)
|
||||
{
|
||||
return connectorValue.ToString("f3");
|
||||
return logicalConnectorInfo.ErrorMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
return connectorString;
|
||||
return logicalConnectorInfo.ErrorCode.ToString();
|
||||
}
|
||||
}
|
||||
else if (logicalConnectorInfo.ConnectorValueType == ConnectorValueType.Bool)
|
||||
{
|
||||
return (logicalConnectorInfo.ConnectorValue == 0) ? "F" : "T";
|
||||
}
|
||||
else if (logicalConnectorInfo.ConnectorValueType == ConnectorValueType.Int)
|
||||
{
|
||||
return logicalConnectorInfo.ConnectorValue.ToString("0");
|
||||
}
|
||||
else if (logicalConnectorInfo.ConnectorValueType == ConnectorValueType.Real)
|
||||
{
|
||||
return logicalConnectorInfo.ConnectorValue.ToString("f3");
|
||||
}
|
||||
else
|
||||
{
|
||||
return logicalConnectorInfo.ConnectorString;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
15
AIStudio.Wpf.DiagramDesigner/Enums/ConnectorErrorCode.cs
Normal file
15
AIStudio.Wpf.DiagramDesigner/Enums/ConnectorErrorCode.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Enums
|
||||
{
|
||||
public enum ConnectorErrorCode
|
||||
{
|
||||
None,
|
||||
ConnErr,
|
||||
ValueErr
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Real = 0,
|
||||
Int = 1,
|
||||
Bool = 2,
|
||||
ValueType = 10,
|
||||
String = 11,
|
||||
ValueType = 99,
|
||||
String = 100,
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:LogicalConnectorInfo}">
|
||||
<Grid ToolTip="{Binding Name}">
|
||||
<Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Grid >
|
||||
<Grid ToolTip="{Binding Name}" Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding MenuOptions}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
@@ -55,14 +55,19 @@
|
||||
<Control x:Name="label">
|
||||
<Control.Template>
|
||||
<ControlTemplate>
|
||||
<TextBlock x:Name="txtleft" FontSize="10" RenderTransformOrigin="0.5,0.5">
|
||||
<TextBlock x:Name="txtleft" FontSize="10" RenderTransformOrigin="0.5,0.5" TextTrimming="CharacterEllipsis">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding Converter="{StaticResource ConectorValueConverter}">
|
||||
<Binding Path="ConnectorValue" />
|
||||
<Binding Path="ConnectorString" />
|
||||
<Binding Path="ConnectorValueType"/>
|
||||
<Binding Path="." />
|
||||
<Binding Path="ConnectorChanged" />
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
<TextBlock.ToolTip>
|
||||
<MultiBinding Converter="{StaticResource ConectorValueConverter}" ConverterParameter="ToolTip">
|
||||
<Binding Path="." />
|
||||
<Binding Path="ConnectorChanged" />
|
||||
</MultiBinding>
|
||||
</TextBlock.ToolTip>
|
||||
<TextBlock.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform/>
|
||||
@@ -82,14 +87,19 @@
|
||||
<Setter TargetName="label" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<TextBlock x:Name="txtRight" FontSize="10" RenderTransformOrigin="0.5,0.5" >
|
||||
<TextBlock x:Name="txtRight" FontSize="10" RenderTransformOrigin="0.5,0.5" TextTrimming="CharacterEllipsis">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding Converter="{StaticResource ConectorValueConverter}">
|
||||
<Binding Path="ConnectorValue" />
|
||||
<Binding Path="ConnectorString" />
|
||||
<Binding Path="ConnectorValueType"/>
|
||||
<Binding Path="." />
|
||||
<Binding Path="ConnectorChanged" />
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
<TextBlock.ToolTip>
|
||||
<MultiBinding Converter="{StaticResource ConectorValueConverter}" ConverterParameter="ToolTip">
|
||||
<Binding Path="." />
|
||||
<Binding Path="ConnectorChanged" />
|
||||
</MultiBinding>
|
||||
</TextBlock.ToolTip>
|
||||
<TextBlock.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform/>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner.Enums;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -81,21 +83,54 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public bool ConnectorError
|
||||
private ConnectorErrorCode _errorCode;
|
||||
public ConnectorErrorCode ErrorCode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool ValueError
|
||||
{
|
||||
get; set;
|
||||
get
|
||||
{
|
||||
return _errorCode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _errorCode, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _errorMessage;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
return _errorMessage;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _errorMessage, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ConnectorChanged
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
protected override void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (IsLoaded == false) { return; }
|
||||
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ConnectorValue):
|
||||
case nameof(ConnectorString):
|
||||
case nameof(ConnectorValueType):
|
||||
case nameof(ErrorCode):
|
||||
case nameof(ErrorMessage):
|
||||
RaisePropertyChanged(nameof(ConnectorChanged));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool CanAttachTo(FullyCreatedConnectorInfo port)
|
||||
{
|
||||
if (!base.CanAttachTo(port))
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Enums;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -276,6 +277,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var connector = GetSourceItem(input.Value);
|
||||
if (connector == null)
|
||||
{
|
||||
input.Value.ErrorCode = ConnectorErrorCode.None;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -301,9 +303,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Value.ConnectorError = true;
|
||||
input.Value.ErrorCode = ConnectorErrorCode.ConnErr;
|
||||
input.Value.ErrorMessage = "连接类型不匹配";
|
||||
input.Value.ColorViewModel.FillColor.Color = Colors.Orange;
|
||||
input.Value.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,9 +315,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
foreach (var output in Output)
|
||||
{
|
||||
if (output.Value.ValueError)
|
||||
if (output.Value.ErrorCode != ConnectorErrorCode.None)
|
||||
{
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.Orange;
|
||||
output.Value.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
}
|
||||
else if (output.Value.ConnectorValueType == ConnectorValueType.Bool)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user