sfc实现中

This commit is contained in:
akwkevin
2021-07-30 18:26:35 +08:00
parent 336249f313
commit 9a0e85e1a9
17 changed files with 346 additions and 3 deletions

View File

@@ -123,6 +123,7 @@
<ProjectReference Include="..\AIStudio.Wpf.BaseDiagram\AIStudio.Wpf.BaseDiagram.csproj" />
<ProjectReference Include="..\AIStudio.Wpf.Flowchart\AIStudio.Wpf.Flowchart.csproj" />
<ProjectReference Include="..\AIStudio.Wpf.Logical\AIStudio.Wpf.Logical.csproj" />
<ProjectReference Include="..\AIStudio.Wpf.SFC\AIStudio.Wpf.SFC.csproj" />
<ProjectReference Include="..\Util.DiagramDesigner\Util.DiagramDesigner.csproj" />
</ItemGroup>

View File

@@ -11,6 +11,7 @@
<ResourceDictionary Source="/AIStudio.Wpf.ADiagram;component/Themes/Generic.xaml" />
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Flowchart;component/ViewModels/FlowNode.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Logical;component/ViewModels/LogicalGateItemViewModel.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.SFC;component/ViewModels/SFCNode.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

View File

@@ -1,4 +1,5 @@
using AIStudio.Wpf.Flowchart;
using AIStudio.Wpf.SFC;
using System;
using System.Windows.Media;
using Util.DiagramDesigner;
@@ -52,6 +53,17 @@ namespace AIStudio.Wpf.ADiagram.Models
}
public class SFCToolBoxData : ToolBoxData
{
public SFCNodeKinds Kind { get; set; }
public SFCToolBoxData(SFCNodeKinds kind, Type type, double width = 32, double height = 32) : base(kind.GetDescription(), null, type, width, height)
{
Kind = kind;
ColorViewModel.LineColor.Color = Colors.Black;
}
}
public class DesignerItemToolBoxData : ToolBoxData
{
public string FileName { get; set; }

View File

@@ -13,6 +13,8 @@ using System.Linq;
using System.Windows.Input;
using Util.DiagramDesigner;
using Util.DiagramDesigner.Helpers;
using AIStudio.Wpf.SFC;
using AIStudio.Wpf.SFC.ViewModels;
namespace AIStudio.Wpf.ADiagram.ViewModels
{
@@ -177,6 +179,16 @@ namespace AIStudio.Wpf.ADiagram.ViewModels
mediaToolBoxItems.Add(new MediaToolBoxData("../Images/SVG.png", typeof(SvgDesignerItemViewModel)));
ToolBoxCategory.Add(new ToolBoxCategory() { Header = "媒体", ToolBoxItems = new ObservableCollection<ToolBoxData>(mediaToolBoxItems) });
List<ToolBoxData> sfcToolBoxItems = new List<ToolBoxData>();
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.Start, typeof(SFCStartNode), 32, 28));
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.Condition, typeof(SFCConditionNode), 32, 28));
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.Node, typeof(SFCNodeNode), 32, 28));
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.Action, typeof(SFCActionNode), 32, 28));
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.COBegin, typeof(SFCCOBeginNode), 32, 10));
sfcToolBoxItems.Add(new SFCToolBoxData(SFCNodeKinds.COEnd, typeof(SFCCOEndNode), 32, 10));
ToolBoxCategory.Add(new ToolBoxCategory() { Header = "SFC顺序控制图", ToolBoxItems = new ObservableCollection<ToolBoxData>(sfcToolBoxItems) });
LoadMyItems();
LoadSvgItems();
}
@@ -243,7 +255,7 @@ namespace AIStudio.Wpf.ADiagram.ViewModels
DiagramItem diagramItem = new DiagramItem();
diagramItem.AddItems(new List<DesignerItemViewModelBase> { designer });
diagramDocument.DiagramItems.Add(diagramItem);
string newname = NewNameHelper.GetNewName(MyToolBoxCategory.ToolBoxItems.OfType<DesignerItemToolBoxData>().Select(p => Path.GetFileNameWithoutExtension(p.FileName)),"");
string newname = NewNameHelper.GetNewName(MyToolBoxCategory.ToolBoxItems.OfType<DesignerItemToolBoxData>().Select(p => Path.GetFileNameWithoutExtension(p.FileName)), "");
var filename = $"{_custom}\\{newname}.json";
File.WriteAllText(filename, JsonConvert.SerializeObject(diagramDocument));

View File

@@ -177,7 +177,23 @@
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type model:SFCToolBoxData}">
<Grid Width="{Binding Width}" Height="{Binding Height}">
<Rectangle Name="Border"
StrokeThickness="1"
StrokeDashArray="2"
Fill="Transparent"
SnapsToDevicePixels="true"/>
<Grid ToolTip="{Binding Text}">
<ContentControl Style="{StaticResource CustomSFCNodeStyle}" Margin="2"/>
</Grid>
</Grid>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Stroke" Value="Gray"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type viewmodels:ToolBoxCategory}">
<Grid Visibility="{Binding IsChecked,Converter={StaticResource boolToVisibilityConverter}}">
<Expander Header="{Binding Header}"

View File

@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIStudio.Wpf.Logical", "AIS
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{4959F170-02FB-4B7F-8F53-93DAF22713F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIStudio.Wpf.SFC", "AIStudio.Wpf.SFC\AIStudio.Wpf.SFC.csproj", "{2AB69067-277E-4EE0-9949-8326A145EEE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -41,6 +43,10 @@ Global
{CC68D39D-7935-4079-9CEB-FC2FD498D511}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC68D39D-7935-4079-9CEB-FC2FD498D511}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC68D39D-7935-4079-9CEB-FC2FD498D511}.Release|Any CPU.Build.0 = Release|Any CPU
{2AB69067-277E-4EE0-9949-8326A145EEE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AB69067-277E-4EE0-9949-8326A145EEE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AB69067-277E-4EE0-9949-8326A145EEE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AB69067-277E-4EE0-9949-8326A145EEE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -48,6 +54,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{86ED5B40-D185-4AFA-B5BD-BC8E78DB8758} = {4959F170-02FB-4B7F-8F53-93DAF22713F9}
{CC68D39D-7935-4079-9CEB-FC2FD498D511} = {4959F170-02FB-4B7F-8F53-93DAF22713F9}
{2AB69067-277E-4EE0-9949-8326A145EEE4} = {4959F170-02FB-4B7F-8F53-93DAF22713F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D30FC641-F06C-4E35-AEA5-48A9B6E59CE0}

View File

@@ -54,7 +54,7 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
}
private string _color;
[Browsable(true)]
[Browsable(false)]
public string Color
{
get { return _color; }

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AIStudio.Wpf.BaseDiagram\AIStudio.Wpf.BaseDiagram.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace AIStudio.Wpf.SFC
{
public enum SFCNodeKinds
{
[Description("开始")]
Start = 1,
[Description("节点")]
Node = 2,
[Description("转移条件")]
Condition = 3,
[Description("动作")]
Action = 4,
[Description("并行开始")]
COBegin = 5,
[Description("并行结束")]
COEnd = 6,
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCActionNode : SFCNode
{
public SFCActionNode() : base(SFCNodeKinds.Action)
{
}
public SFCActionNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCCOBeginNode : SFCNode
{
public SFCCOBeginNode() : base(SFCNodeKinds.COBegin)
{
}
public SFCCOBeginNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCCOEndNode : SFCNode
{
public SFCCOEndNode() : base(SFCNodeKinds.COEnd)
{
}
public SFCCOEndNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCConditionNode : SFCNode
{
public SFCConditionNode() : base(SFCNodeKinds.Condition)
{
}
public SFCConditionNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}

View File

@@ -0,0 +1,48 @@
using AIStudio.Wpf.BaseDiagram;
using AIStudio.Wpf.BaseDiagram.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCNode : DesignerItemViewModelBase
{
protected IUIVisualizerService visualiserService;
public SFCNode(SFCNodeKinds kind) : base()
{
Kind = kind;
ItemWidth = 80;
ItemHeight = 40;
}
public SFCNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
protected override void Init()
{
base.Init();
ShowRotate = false;
ShowText = true;
IsReadOnlyText = true;
visualiserService = ApplicationServicesProvider.Instance.Provider.VisualizerService;
}
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
{
base.LoadDesignerItemViewModel(parent, designerbase);
}
[Browsable(false)]
public SFCNodeKinds Kind { get; set; }
}
}

View File

@@ -0,0 +1,99 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Util.DiagramDesigner;assembly=Util.DiagramDesigner"
xmlns:viewmodel="clr-namespace:AIStudio.Wpf.SFC.ViewModels"
xmlns:converter="clr-namespace:AIStudio.Wpf.BaseDiagram.Converters;assembly=AIStudio.Wpf.BaseDiagram">
<s:ColorBrushConverter x:Key="ColorBrushConverter"/>
<ControlTemplate x:Key="StartStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}">
<Border BorderThickness="1" Margin="3" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<Grid>
</Grid>
</Border>
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="NodeStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="4" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<Grid>
</Grid>
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ConditionStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="1" HorizontalAlignment="Center" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}">
</Border>
<Border BorderThickness="1" VerticalAlignment="Center" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}">
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ActionStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<Grid>
</Grid>
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="COBeginStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="0,1,0,1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<Grid>
</Grid>
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="COEndStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Border BorderThickness="0,1,0,1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<Grid>
</Grid>
</Border>
</Grid>
</ControlTemplate>
<Style x:Key="CustomSFCNodeStyle" TargetType="{x:Type ContentControl}">
<Setter Property="Template" Value="{StaticResource StartStyle}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Kind}" Value="Start">
<Setter Property="Template" Value="{StaticResource StartStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="Node">
<Setter Property="Template" Value="{StaticResource NodeStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="Condition">
<Setter Property="Template" Value="{StaticResource ConditionStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="Action">
<Setter Property="Template" Value="{StaticResource ActionStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="COBegin">
<Setter Property="Template" Value="{StaticResource COBeginStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="COEnd">
<Setter Property="Template" Value="{StaticResource COEndStyle}" />
</DataTrigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="{x:Type viewmodel:SFCNode}">
<Grid IsHitTestVisible="False">
<ContentControl Style="{StaticResource CustomSFCNodeStyle}"/>
</Grid>
</DataTemplate>
</ResourceDictionary>

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCNodeNode : SFCNode
{
public SFCNodeNode() : base(SFCNodeKinds.Node)
{
}
public SFCNodeNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Util.DiagramDesigner;
namespace AIStudio.Wpf.SFC.ViewModels
{
public class SFCStartNode : SFCNode
{
public SFCStartNode() : base(SFCNodeKinds.Start)
{
}
public SFCStartNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
}
}