-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
565fd56
commit 0b4a4bc
Showing
11 changed files
with
357 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using OpenSense.Components; | ||
|
||
namespace OpenSense.WPF.Pipeline { | ||
internal static class TypeDisplayHelpers { | ||
|
||
public static string FindInputDataTypeName(ComponentConfiguration configuration, IPortMetadata inputMetadata, IReadOnlyList<ComponentConfiguration> configurations) { | ||
Debug.Assert(inputMetadata.Direction == PortDirection.Input); | ||
var localOutputs = configuration.FindOutputPortDataTypes(configurations); | ||
var localInputs = configuration.FindInputPortDataTypes(configurations, exclude: inputMetadata); | ||
string result; | ||
if (inputMetadata.CanConnectDataType(null, localOutputs, localInputs)) { | ||
result = "Any Type"; | ||
} else { | ||
var inputPortDataType = inputMetadata.GetTransmissionDataType(null, localOutputs, localInputs); | ||
if (inputPortDataType is null) { | ||
result = "Type Unknown"; | ||
} else { | ||
result = GetCSharpStyleTypeName(inputPortDataType); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public static string FindOutputDataTypeName(ComponentConfiguration configuration, IPortMetadata outputMetadata, IReadOnlyList<ComponentConfiguration> configurations) { | ||
Debug.Assert(outputMetadata.Direction == PortDirection.Output); | ||
var localInputs = configuration.FindInputPortDataTypes(configurations); | ||
var localOutputs = configuration.FindOutputPortDataTypes(configurations, exclude: outputMetadata); | ||
string result; | ||
if (outputMetadata.CanConnectDataType(null, localInputs, localOutputs)) { | ||
result = "Any Type"; | ||
} else { | ||
var outputPortDataType = outputMetadata.GetTransmissionDataType(null, localInputs, localOutputs); | ||
if (outputPortDataType is null) { | ||
result = "Type Unknown"; | ||
} else { | ||
result = GetCSharpStyleTypeName(outputPortDataType); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private static string GetCSharpStyleTypeName(Type type) { | ||
if (TypeMappings.TryGetValue(type, out var name)) { | ||
return name; | ||
} | ||
if (type.IsArray) { | ||
return $"{GetCSharpStyleTypeName(type.GetElementType())}[]"; | ||
} | ||
name = $"{type.Namespace}.{type.Name}"; | ||
if (!type.IsGenericType) { | ||
return name; | ||
} | ||
var sb = new StringBuilder(); | ||
var innerText = string.Join(", ", type.GetGenericArguments().Select(GetCSharpStyleTypeName)); | ||
if (name.StartsWith("System.ValueTuple`")) { | ||
sb.Append('('); | ||
sb.Append(innerText); | ||
sb.Append(')'); | ||
} else { | ||
sb.Append(name.Substring(0, name.IndexOf('`'))); | ||
sb.Append('<'); | ||
sb.Append(innerText); | ||
sb.Append('>'); | ||
} | ||
var result = sb.ToString(); | ||
return result; | ||
} | ||
|
||
private static readonly Dictionary<Type, string> TypeMappings = new Dictionary<Type, string>() { | ||
{ typeof(object), "object" }, | ||
{ typeof(string), "string" }, | ||
{ typeof(bool), "bool" }, | ||
{ typeof(float), "float" }, | ||
{ typeof(double), "double" }, | ||
{ typeof(int), "int" }, | ||
{ typeof(uint), "uint" }, | ||
{ typeof(long), "long" }, | ||
{ typeof(ulong), "ulong" }, | ||
{ typeof(short), "short" }, | ||
{ typeof(ushort), "ushort" }, | ||
|
||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<UserControl | ||
x:Class="OpenSense.WPF.Views.Editors.OutputPortView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:OpenSense.WPF.Views.Editors" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800"> | ||
<UserControl.Resources> | ||
<Style | ||
x:Key="HideDescriptionStyle" | ||
TargetType="TextBlock"> | ||
<Style.Triggers> | ||
<DataTrigger | ||
Binding="{Binding Description}" | ||
Value="{x:Null}"> | ||
<Setter | ||
Property="Visibility" | ||
Value="Collapsed" /> | ||
</DataTrigger> | ||
<DataTrigger | ||
Binding="{Binding Description}" | ||
Value=""> | ||
<Setter | ||
Property="Visibility" | ||
Value="Collapsed" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</UserControl.Resources> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Grid.RowDefinitions> | ||
<RowDefinition | ||
Height="auto" /> | ||
<RowDefinition | ||
Height="auto" /> | ||
<RowDefinition | ||
Height="auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<TextBlock | ||
Grid.Row="0" | ||
FontWeight="Bold" | ||
Text="{Binding Name}" /> | ||
|
||
<TextBlock | ||
Grid.Row="2" | ||
Foreground="SlateGray" | ||
Style="{StaticResource HideDescriptionStyle}" | ||
Text="{Binding Description}" /> | ||
|
||
<TextBlock | ||
Grid.Row="1" | ||
Text="{Binding Type}" /> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace OpenSense.WPF.Views.Editors { | ||
public sealed partial class OutputPortView : UserControl { | ||
public OutputPortView() { | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#nullable enable | ||
|
||
namespace OpenSense.WPF.Views.Editors { | ||
internal sealed class OutputPortViewModel { | ||
|
||
public string Name { get; } | ||
|
||
public string? Description { get; } | ||
|
||
public string Type { get; } | ||
|
||
public OutputPortViewModel(string name, string? description, string type) { | ||
Name = name; | ||
Description = description; | ||
Type = type; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<UserControl | ||
x:Class="OpenSense.WPF.Views.Editors.OutputPortsInspector" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:OpenSense.WPF.Views.Editors" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
Unloaded="UserControl_Unloaded"> | ||
<Grid> | ||
<TextBlock | ||
Visibility="Collapsed" | ||
d:Visibility="Visible" | ||
Name="TextBlockNoOutputs" | ||
VerticalAlignment="Center" | ||
HorizontalAlignment="Center"> | ||
No Outpus | ||
</TextBlock> | ||
|
||
<ScrollViewer | ||
Visibility="Visible" | ||
VerticalScrollBarVisibility="Auto" | ||
HorizontalScrollBarVisibility="Auto"> | ||
<ItemsControl | ||
Grid.Column="0" | ||
Name="ListBoxPorts"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<local:OutputPortView | ||
Margin="5" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</ScrollViewer> | ||
</Grid> | ||
</UserControl> |
Oops, something went wrong.