mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-04 15:26:34 +08:00
新增了UI节点
This commit is contained in:
@@ -17,13 +17,13 @@ namespace Serein.Workbench
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
if (1 == 2)
|
||||
if (1 == 1)
|
||||
{
|
||||
// 这里是测试代码,可以删除
|
||||
string filePath;
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\net8.0\PLCproject.dnf";
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\banyunqi\project.dnf";
|
||||
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\debug\net8.0\project.dnf";
|
||||
filePath = @"F:\临时\project\project.dnf";
|
||||
//filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\debug\net8.0\test.dnf";
|
||||
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
|
||||
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
||||
|
||||
@@ -162,6 +162,7 @@ namespace Serein.Workbench
|
||||
IOCObjectViewer.SelectObj += ViewObjectViewer.LoadObjectInformation; // 使选择 IOC容器视图 的某项(对象)时,可以在 数据视图 呈现数据
|
||||
|
||||
#region 为 NodeControlType 枚举 不同项添加对应的 Control类型 、 ViewModel类型
|
||||
NodeMVVMManagement.RegisterUI(NodeControlType.UI, typeof(UINodeControl), typeof(UINodeControlViewModel));
|
||||
NodeMVVMManagement.RegisterUI(NodeControlType.Action, typeof(ActionNodeControl), typeof(ActionNodeControlViewModel));
|
||||
NodeMVVMManagement.RegisterUI(NodeControlType.Flipflop, typeof(FlipflopNodeControl), typeof(FlipflopNodeControlViewModel));
|
||||
NodeMVVMManagement.RegisterUI(NodeControlType.ExpOp, typeof(ExpOpNodeControl), typeof(ExpOpNodeControlViewModel));
|
||||
@@ -492,6 +493,9 @@ namespace Serein.Workbench
|
||||
case Library.NodeType.Flipflop:
|
||||
dllControl.AddFlipflop(methodDetailsInfo); // 添加触发器方法到控件
|
||||
break;
|
||||
case Library.NodeType.UI:
|
||||
dllControl.AddUI(methodDetailsInfo); // 添加触发器方法到控件
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -26,6 +27,9 @@
|
||||
<GroupBox x:Name="FlipflopNodeGroupBox" Grid.Row="1" Header="触发器" Margin="5">
|
||||
<ListBox x:Name="FlipflopsListBox" Background="#FACFC1"/>
|
||||
</GroupBox>
|
||||
<GroupBox x:Name="UINodeGroupBox" Grid.Row="2" Header="UI" Margin="5">
|
||||
<ListBox x:Name="UIListBox" Background="#FFFBD7"/>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,7 @@ using System.Windows.Input;
|
||||
|
||||
namespace Serein.Workbench.Node.View
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// UserControl1.xaml 的交互逻辑
|
||||
@@ -28,8 +25,11 @@ namespace Serein.Workbench.Node.View
|
||||
this.nodeLibraryInfo = nodeLibraryInfo;
|
||||
Header = "DLL name : " + nodeLibraryInfo.AssemblyName;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
FlipflopNodeGroupBox.Visibility = Visibility.Collapsed;
|
||||
ActionNodeGroupBox.Visibility = Visibility.Collapsed;
|
||||
UINodeGroupBox.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -65,6 +65,16 @@ namespace Serein.Workbench.Node.View
|
||||
FlipflopNodeGroupBox.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向触发器面板添加类型的文本块
|
||||
/// </summary>
|
||||
/// <param name="type">要添加的类型</param>
|
||||
public void AddUI(MethodDetailsInfo mdInfo)
|
||||
{
|
||||
AddTypeToListBox(mdInfo, UIListBox);
|
||||
UINodeGroupBox.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向指定面板添加类型的文本块
|
||||
/// </summary>
|
||||
@@ -137,6 +147,7 @@ namespace Serein.Workbench.Node.View
|
||||
{
|
||||
NodeType.Action => NodeControlType.Action,
|
||||
NodeType.Flipflop => NodeControlType.Flipflop,
|
||||
NodeType.UI => NodeControlType.UI,
|
||||
_ => NodeControlType.None,
|
||||
},
|
||||
MethodDetailsInfo = mdInfo,
|
||||
|
||||
40
Workbench/Node/View/UINodeControl.xaml
Normal file
40
Workbench/Node/View/UINodeControl.xaml
Normal file
@@ -0,0 +1,40 @@
|
||||
<local:NodeControlBase x:Class="Serein.Workbench.Node.View.UINodeControl"
|
||||
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:Serein.Workbench.Node.View"
|
||||
xmlns:vm="clr-namespace:Serein.Workbench.Node.ViewModel"
|
||||
xmlns:themes="clr-namespace:Serein.Workbench.Themes"
|
||||
d:DataContext="{d:DesignInstance vm:UINodeControlViewModel}"
|
||||
mc:Ignorable="d"
|
||||
MinWidth="50"
|
||||
Initialized="NodeControlBase_Initialized"
|
||||
Loaded="NodeControlBase_Loaded"
|
||||
>
|
||||
<Grid x:Name="MainGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0" Background="#E7EFF5" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:ExecuteJunctionControl Grid.Column="0" MyNode="{Binding NodeModel}" x:Name="ExecuteJunctionControl" HorizontalAlignment="Left" Grid.RowSpan="2"/>
|
||||
<Border Grid.Column="1" BorderThickness="1" HorizontalAlignment="Stretch">
|
||||
<TextBlock Text="UI控件" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1" x:Name="EmbedContainer" BorderBrush="Black" BorderThickness="1"
|
||||
Width="500" Height="400"/>
|
||||
|
||||
|
||||
</Grid>
|
||||
</local:NodeControlBase>
|
||||
65
Workbench/Node/View/UINodeControl.xaml.cs
Normal file
65
Workbench/Node/View/UINodeControl.xaml.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Serein.Workbench.Node.ViewModel;
|
||||
using Serein.Workbench.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Serein.Workbench.Node.View
|
||||
{
|
||||
/// <summary>
|
||||
/// UINodeControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class UINodeControl : NodeControlBase, INodeJunction
|
||||
{
|
||||
public UINodeControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public UINodeControl(UINodeControlViewModel viewModel) : base(viewModel)
|
||||
{
|
||||
DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JunctionControlBase ExecuteJunction => this.ExecuteJunctionControl;
|
||||
|
||||
public JunctionControlBase NextStepJunction => throw new NotImplementedException();
|
||||
|
||||
public JunctionControlBase[] ArgDataJunction => throw new NotImplementedException();
|
||||
|
||||
public JunctionControlBase ReturnDataJunction => throw new NotImplementedException();
|
||||
|
||||
|
||||
private void NodeControlBase_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UINodeControlViewModel vm = (UINodeControlViewModel)DataContext;
|
||||
vm.InitAdapter(userControl => {
|
||||
EmbedContainer.Child = userControl;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void NodeControlBase_Initialized(object sender, EventArgs e)
|
||||
{
|
||||
UINodeControlViewModel vm = (UINodeControlViewModel)DataContext;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Workbench/Node/ViewModel/UINodeControlViewModel.cs
Normal file
40
Workbench/Node/ViewModel/UINodeControlViewModel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.NodeFlow.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Serein.Workbench.Node.ViewModel
|
||||
{
|
||||
public class UINodeControlViewModel : NodeControlViewModelBase
|
||||
{
|
||||
private SingleUINode NodeModel => (SingleUINode)base.NodeModel;
|
||||
//public IEmbeddedContent Adapter => NodeModel.Adapter;
|
||||
|
||||
public UINodeControlViewModel(NodeModelBase nodeModel) : base(nodeModel)
|
||||
{
|
||||
//NodeModel.Adapter.GetWindowHandle();
|
||||
}
|
||||
|
||||
public void InitAdapter(Action<UserControl> setUIDisplayHandle)
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
var context = new DynamicContext(NodeModel.Env);
|
||||
await NodeModel.ExecutingAsync(context);
|
||||
if (context.NextOrientation == ConnectionInvokeType.IsSucceed
|
||||
&& NodeModel.Adapter.GetUserControl() is UserControl userControl)
|
||||
{
|
||||
NodeModel.Env.UIContextOperation.Invoke(() =>
|
||||
{
|
||||
setUIDisplayHandle.Invoke(userControl);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,14 +51,18 @@
|
||||
<ProjectReference Include="..\NodeFlow\Serein.NodeFlow.csproj" />
|
||||
<ProjectReference Include="..\Serein.Script\Serein.Script.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
||||
<PackageReference Include="Lagrange.Core" Version="0.3.1" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
<PackageReference Include="ZXing.Net" Version="0.16.10" />
|
||||
<PackageReference Include="ZXing.Net.Bindings.ImageSharp" Version="0.16.15" />
|
||||
<!--<PackageReference Include="Lagrange.Core" Version="0.3.1" />-->
|
||||
<!--<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />-->
|
||||
<!--<PackageReference Include="ZXing.Net.Bindings.ImageSharp" Version="0.16.15" />-->
|
||||
|
||||
<!--<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
||||
@@ -74,4 +78,9 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\" />
|
||||
<Folder Include="VIewModels\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
64
Workbench/Tool/EmbeddedHost.cs
Normal file
64
Workbench/Tool/EmbeddedHost.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace Serein.Workbench.Tool
|
||||
{
|
||||
|
||||
|
||||
/*public class EmbeddedHost : HwndHost
|
||||
{
|
||||
private readonly IntPtr _hwnd;
|
||||
|
||||
public EmbeddedHost(IEmbeddedContent content)
|
||||
{
|
||||
_hwnd = content.GetWindowHandle();
|
||||
}
|
||||
|
||||
protected override HandleRef BuildWindowCore(HandleRef hwndParent)
|
||||
{
|
||||
if (_hwnd == IntPtr.Zero)
|
||||
throw new InvalidOperationException("无效的窗口句柄");
|
||||
|
||||
// 设置窗口为子窗口(必须去掉 WS_POPUP,添加 WS_CHILD)
|
||||
SetWindowLongPtr(_hwnd, GWL_STYLE, GetWindowLongPtr(_hwnd, GWL_STYLE) | WS_CHILD);
|
||||
SetParent(_hwnd, hwndParent.Handle);
|
||||
|
||||
// 让窗口填充整个区域
|
||||
SetWindowPos(_hwnd, IntPtr.Zero, 0, 0, (int)ActualWidth, (int)ActualHeight,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
|
||||
|
||||
return new HandleRef(this, _hwnd);
|
||||
}
|
||||
|
||||
protected override void DestroyWindowCore(HandleRef hwnd)
|
||||
{
|
||||
// 窗口销毁时的操作(如果需要)
|
||||
}
|
||||
|
||||
// WinAPI 导入
|
||||
private const int GWL_STYLE = -16;
|
||||
private const int WS_CHILD = 0x40000000;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern int GetWindowLongPtr(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern int SetWindowLongPtr(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||
|
||||
private const uint SWP_NOZORDER = 0x0004;
|
||||
private const uint SWP_NOACTIVATE = 0x0010;
|
||||
private const uint SWP_SHOWWINDOW = 0x0040;
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user