chore: 工程骨架 — Prism.DryIoc 启动链(Attribute 驱动注册/命名约定绑定) + 纯 WPF 样式 + 导航 shell
This commit is contained in:
commit
e55bd9348a
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# 构建产物
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# IDE
|
||||
.vs/
|
||||
.vscode/
|
||||
*.user
|
||||
|
||||
# 模型文件(体积大,自行放置)
|
||||
models/*.onnx
|
||||
yolo_models/*.onnx
|
||||
|
||||
# 运行期产物
|
||||
logs/
|
||||
snapshots/
|
||||
runs/
|
||||
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# SopHelper
|
||||
|
||||
单 USB 相机的最小 SOP 辅助程序。
|
||||
|
||||
- 架构照搬 `E:\10-Work\plcsharp`:Prism.DryIoc + Attribute 驱动注册 + 命名约定自动绑定。
|
||||
- 不含 HandyControl / SkiaSharp.Views.WPF,纯 WPF 样式。
|
||||
- 判定引擎移植自 `VisionInspectionSystem`(MIT),去掉多相机/海康/ONVIF/Modbus/用户权限。
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
src/SopHelper.Engine/ 纯类库:相机 · 推理 · SOP 引擎(无 UI 依赖)
|
||||
src/SopHelper.App/ Prism shell + SOP 页(WPF)
|
||||
configs/ SOP 配方(YAML)
|
||||
models/ MediaPipe 两个 onnx(不入 git)
|
||||
yolo_models/ YOLO onnx(不入 git)
|
||||
```
|
||||
|
||||
## 构建
|
||||
|
||||
```bash
|
||||
dotnet build SopHelper.sln
|
||||
```
|
||||
6
SopHelper.slnx
Normal file
6
SopHelper.slnx
Normal file
@ -0,0 +1,6 @@
|
||||
<Solution>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/SopHelper.App/SopHelper.App.csproj" />
|
||||
<Project Path="src/SopHelper.Engine/SopHelper.Engine.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
0
models/.gitkeep
Normal file
0
models/.gitkeep
Normal file
12
src/SopHelper.App/App.xaml
Normal file
12
src/SopHelper.App/App.xaml
Normal file
@ -0,0 +1,12 @@
|
||||
<prism:PrismApplication x:Class="SopHelper.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
<prism:PrismApplication.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Themes/Styles.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</prism:PrismApplication.Resources>
|
||||
</prism:PrismApplication>
|
||||
119
src/SopHelper.App/App.xaml.cs
Normal file
119
src/SopHelper.App/App.xaml.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Prism.Ioc;
|
||||
using Prism.Mvvm;
|
||||
using SopHelper.Core.Prism;
|
||||
using SopHelper.Models;
|
||||
using SopHelper.VVMs.MainWindow;
|
||||
|
||||
namespace SopHelper;
|
||||
|
||||
/// <summary>
|
||||
/// 应用程序入口,负责初始化 Prism 框架和注册组件(启动链照搬 plcsharp)
|
||||
/// </summary>
|
||||
public partial class App
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册应用程序所需的类型和服务
|
||||
/// </summary>
|
||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
RegisterEvents(); // 捕获全局异常
|
||||
|
||||
// 注册带 [Model] 特性的类,单例
|
||||
foreach (var model in from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.GetCustomAttribute<ModelAttribute>() is not null
|
||||
select t)
|
||||
{
|
||||
_ = containerRegistry.RegisterSingleton(model);
|
||||
}
|
||||
|
||||
// 注册带 [NavigationPage] 特性的 View 到导航
|
||||
foreach (var view in from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.GetCustomAttribute<NavigationPageAttribute>() is not null
|
||||
select t)
|
||||
{
|
||||
containerRegistry.RegisterForNavigation(view, view.Name);
|
||||
}
|
||||
|
||||
_ = containerRegistry.RegisterSingleton<NavigationModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建Shell
|
||||
/// </summary>
|
||||
protected override Window CreateShell()
|
||||
{
|
||||
var navigate = Container.Resolve<NavigationModel>();
|
||||
|
||||
// 反射收集导航页
|
||||
foreach (var view in from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.GetCustomAttribute<NavigationPageAttribute>() is not null
|
||||
orderby t.GetCustomAttribute<NavigationPageAttribute>()!.Index
|
||||
select t)
|
||||
{
|
||||
var page = view.GetCustomAttribute<NavigationPageAttribute>()!;
|
||||
|
||||
var item = Container.Resolve<NavigateItem>();
|
||||
item.ViewName = page.ViewName;
|
||||
item.DisplayName = page.DisplayName;
|
||||
navigate.Pages.Add(item);
|
||||
}
|
||||
|
||||
var window = Container.Resolve<MainWindow>();
|
||||
|
||||
// 默认页
|
||||
navigate.Navigate("SopPage");
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动寻找ViewModel并绑定到View,要求ViewModel命名为View的全名加上ViewModel,比如MainWindow的ViewModel命名为MainWindowViewModel
|
||||
/// </summary>
|
||||
protected override void ConfigureViewModelLocator()
|
||||
{
|
||||
base.ConfigureViewModelLocator();
|
||||
|
||||
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
|
||||
{
|
||||
var viewName = viewType.FullName;
|
||||
var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
|
||||
var viewModelName = $"{viewName}ViewModel, {viewAssemblyName}";
|
||||
return Type.GetType(viewModelName);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 捕获全局异常
|
||||
/// </summary>
|
||||
private static void RegisterEvents()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
|
||||
Log(e.ExceptionObject as Exception, "AppDomain");
|
||||
|
||||
Current.DispatcherUnhandledException += (_, e) =>
|
||||
{
|
||||
Log(e.Exception, "Dispatcher");
|
||||
e.Handled = true; // 上位机不能因一次异常退出
|
||||
};
|
||||
}
|
||||
|
||||
private static void Log(Exception? ex, string from)
|
||||
{
|
||||
if (ex is null) return;
|
||||
var line = $"[{DateTime.Now:HH:mm:ss.fff}] [{from}] {ex.Message}";
|
||||
Console.WriteLine(line);
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory("logs");
|
||||
File.AppendAllText(Path.Combine("logs", "error.log"), line + Environment.NewLine);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 日志失败不影响主流程
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/SopHelper.App/Core/Prism/CoreAttribute.cs
Normal file
39
src/SopHelper.App/Core/Prism/CoreAttribute.cs
Normal file
@ -0,0 +1,39 @@
|
||||
namespace SopHelper.Core.Prism;
|
||||
|
||||
/// <summary>
|
||||
/// 标志此特性的类会被注册为单例(照搬 plcsharp 约定)
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ModelAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标志此特性的 View 会被注册到导航列表
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class NavigationPageAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 视图名称(导航用)
|
||||
/// </summary>
|
||||
public string ViewName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Display名称
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 排序序号
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标志此特性的类会被注册为弹出窗口
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class DialogAttribute : Attribute
|
||||
{
|
||||
}
|
||||
61
src/SopHelper.App/Core/Prism/MessageEvent.cs
Normal file
61
src/SopHelper.App/Core/Prism/MessageEvent.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using Prism.Events;
|
||||
|
||||
namespace SopHelper.Core.Prism;
|
||||
|
||||
/// <summary>
|
||||
/// 全局消息事件(照搬 plcsharp:模块间解耦都走事件聚合器)
|
||||
/// </summary>
|
||||
public class MessageEvent : PubSubEvent<Message>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public struct Message
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息目标
|
||||
/// </summary>
|
||||
public string Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息类型 1 记录 2 弹出 3 弹出并记录
|
||||
/// </summary>
|
||||
public ShowType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 级别
|
||||
/// </summary>
|
||||
public MsgLevel Level { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示方式
|
||||
/// </summary>
|
||||
public enum ShowType
|
||||
{
|
||||
/// <summary>仅记录日志</summary>
|
||||
Log = 1,
|
||||
|
||||
/// <summary>仅提示</summary>
|
||||
Show = 2,
|
||||
|
||||
/// <summary>提示并记录</summary>
|
||||
Both = 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息级别
|
||||
/// </summary>
|
||||
public enum MsgLevel
|
||||
{
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
}
|
||||
48
src/SopHelper.App/Core/Prism/ModelBase.cs
Normal file
48
src/SopHelper.App/Core/Prism/ModelBase.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Prism.Events;
|
||||
using Prism.Ioc;
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace SopHelper.Core.Prism;
|
||||
|
||||
/// <summary>
|
||||
/// 模型Base
|
||||
/// </summary>
|
||||
public class ModelBase : BindableBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件聚合器
|
||||
/// </summary>
|
||||
protected readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// DI 容器
|
||||
/// </summary>
|
||||
protected readonly IContainerExtension _container;
|
||||
|
||||
/// <summary>
|
||||
/// 模型Base
|
||||
/// </summary>
|
||||
public ModelBase(IContainerExtension container, IEventAggregator ea)
|
||||
{
|
||||
_container = container;
|
||||
_eventAggregator = ea;
|
||||
|
||||
_eventAggregator.GetEvent<MessageEvent>().Subscribe(OnMessage, ThreadOption.PublisherThread, true);
|
||||
|
||||
AppDomain.CurrentDomain.ProcessExit += OnExit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 收到消息(子类覆写做本模块的落库/统计)
|
||||
/// </summary>
|
||||
protected virtual void OnMessage(Message message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进程退出(子类覆写做释放)
|
||||
/// </summary>
|
||||
protected virtual void OnExit(object? sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
31
src/SopHelper.App/Core/Prism/NavigateItem.cs
Normal file
31
src/SopHelper.App/Core/Prism/NavigateItem.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace SopHelper.Core.Prism;
|
||||
|
||||
/// <summary>
|
||||
/// Navigate项
|
||||
/// </summary>
|
||||
public class NavigateItem : BindableBase
|
||||
{
|
||||
private string _viewName = "";
|
||||
|
||||
/// <summary>
|
||||
/// 视图名称
|
||||
/// </summary>
|
||||
public string ViewName
|
||||
{
|
||||
get { return _viewName; }
|
||||
set { SetProperty(ref _viewName, value); }
|
||||
}
|
||||
|
||||
private string _displayName = "";
|
||||
|
||||
/// <summary>
|
||||
/// Display名称
|
||||
/// </summary>
|
||||
public string DisplayName
|
||||
{
|
||||
get { return _displayName; }
|
||||
set { SetProperty(ref _displayName, value); }
|
||||
}
|
||||
}
|
||||
17
src/SopHelper.App/Core/Prism/ViewModelBase.cs
Normal file
17
src/SopHelper.App/Core/Prism/ViewModelBase.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Prism.Mvvm;
|
||||
using Prism.Navigation;
|
||||
|
||||
namespace SopHelper.Core.Prism;
|
||||
|
||||
/// <summary>
|
||||
/// 视图模型Base
|
||||
/// </summary>
|
||||
public abstract class ViewModelBase : BindableBase, IDestructible
|
||||
{
|
||||
/// <summary>
|
||||
/// Destroy
|
||||
/// </summary>
|
||||
public virtual void Destroy()
|
||||
{
|
||||
}
|
||||
}
|
||||
80
src/SopHelper.App/Models/NavigationModel.cs
Normal file
80
src/SopHelper.App/Models/NavigationModel.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Prism.Events;
|
||||
using Prism.Ioc;
|
||||
using Prism.Navigation.Regions;
|
||||
using SopHelper.Core.Prism;
|
||||
|
||||
namespace SopHelper.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Navigate模型
|
||||
/// </summary>
|
||||
[Model]
|
||||
public class NavigationModel : ModelBase
|
||||
{
|
||||
private readonly IRegionManager _regionManager;
|
||||
|
||||
/// <summary>
|
||||
/// Navigate模型
|
||||
/// </summary>
|
||||
public NavigationModel(IContainerExtension container, IEventAggregator ea, IRegionManager regionManager)
|
||||
: base(container, ea)
|
||||
{
|
||||
_regionManager = regionManager;
|
||||
}
|
||||
|
||||
private ObservableCollection<NavigateItem> _pages = [];
|
||||
|
||||
/// <summary>
|
||||
/// 导航页列表(shell 侧栏绑定)
|
||||
/// </summary>
|
||||
public ObservableCollection<NavigateItem> Pages
|
||||
{
|
||||
get { return _pages; }
|
||||
set { SetProperty(ref _pages, value); }
|
||||
}
|
||||
|
||||
private NavigateItem? _target;
|
||||
|
||||
/// <summary>
|
||||
/// 当前页
|
||||
/// </summary>
|
||||
public NavigateItem? Target
|
||||
{
|
||||
get { return _target; }
|
||||
set { SetProperty(ref _target, value); }
|
||||
}
|
||||
|
||||
private int _selectedIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// 侧栏选中索引
|
||||
/// </summary>
|
||||
public int SelectedIndex
|
||||
{
|
||||
get { return _selectedIndex; }
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _selectedIndex, value)) return;
|
||||
if (value >= 0 && value < Pages.Count) Navigate(Pages[value].ViewName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航到指定页
|
||||
/// </summary>
|
||||
public void Navigate(string viewName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(viewName)) return;
|
||||
|
||||
Target = Pages.FirstOrDefault(n => n.ViewName == viewName);
|
||||
if (Target is null) return;
|
||||
|
||||
_regionManager.RequestNavigate(ContentRegion, viewName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容区名(shell 与导航的唯一约定)
|
||||
/// </summary>
|
||||
public const string ContentRegion = "ContentRegion";
|
||||
}
|
||||
36
src/SopHelper.App/SopHelper.App.csproj
Normal file
36
src/SopHelper.App/SopHelper.App.csproj
Normal file
@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<RootNamespace>SopHelper</RootNamespace>
|
||||
<AssemblyName>SopHelper</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- 骨架与 plcsharp 一致:Prism.DryIoc,不引 HandyControl / SkiaSharp.Views.WPF -->
|
||||
<PackageReference Include="Prism.DryIoc" Version="9.0.537" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SopHelper.Engine\SopHelper.Engine.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- 模型文件不入 git,构建时从仓库根目录带到输出目录(照搬参考项目的做法) -->
|
||||
<ItemGroup>
|
||||
<None Include="..\..\models\**\*.onnx" Link="models\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
|
||||
<None Include="..\..\yolo_models\**\*.onnx" Link="yolo_models\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\configs\**\*.*" Link="configs\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
108
src/SopHelper.App/Themes/Styles.xaml
Normal file
108
src/SopHelper.App/Themes/Styles.xaml
Normal file
@ -0,0 +1,108 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!-- 纯 WPF 样式,不依赖任何控件库 -->
|
||||
|
||||
<SolidColorBrush x:Key="Bg" Color="#FF101820" />
|
||||
<SolidColorBrush x:Key="Panel" Color="#FF16222E" />
|
||||
<SolidColorBrush x:Key="Line" Color="#FF2C4257" />
|
||||
<SolidColorBrush x:Key="Fg" Color="#FFDCEBF5" />
|
||||
<SolidColorBrush x:Key="FgDim" Color="#FF8FAFC4" />
|
||||
<SolidColorBrush x:Key="Accent" Color="#FF00B8D4" />
|
||||
<SolidColorBrush x:Key="Ok" Color="#FF37B26D" />
|
||||
<SolidColorBrush x:Key="Ng" Color="#FFF0533C" />
|
||||
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="FontFamily" Value="Microsoft YaHei" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Title" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
|
||||
<Setter Property="FontSize" Value="16" />
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
<Setter Property="Foreground" Value="{StaticResource Accent}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{StaticResource Panel}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource Line}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="CornerRadius" Value="6" />
|
||||
<Setter Property="Padding" Value="10" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="Background" Value="{StaticResource Panel}" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource Line}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Padding" Value="14,7" />
|
||||
<Setter Property="FontFamily" Value="Microsoft YaHei" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="5"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{StaticResource Accent}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value="0.4" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 左侧导航 -->
|
||||
<Style TargetType="ListBox">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="ItemContainerStyle">
|
||||
<Setter.Value>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="Padding" Value="12,10" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="bd" Background="Transparent" Padding="{TemplateBinding Padding}" CornerRadius="5">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#22FFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#3300B8D4" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding DisplayName}" FontSize="14" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
66
src/SopHelper.App/VVMs/MainWindow/MainWindow.xaml
Normal file
66
src/SopHelper.App/VVMs/MainWindow/MainWindow.xaml
Normal file
@ -0,0 +1,66 @@
|
||||
<Window x:Class="SopHelper.VVMs.MainWindow.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Title="{Binding Title}"
|
||||
Height="720" Width="1180"
|
||||
MinHeight="560" MinWidth="900"
|
||||
Background="{StaticResource Bg}"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" Margin="2,2,2,10">
|
||||
<TextBlock Style="{StaticResource Title}" Text="{Binding Title}" />
|
||||
<Button Content="退出" Command="{Binding ExitCommand}" Margin="16,0,0,0" Padding="12,4" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 侧导航 -->
|
||||
<Border Grid.Row="1" Margin="0,0,10,0">
|
||||
<ListBox ItemsSource="{Binding Navigation.Pages}"
|
||||
SelectedIndex="{Binding Navigation.SelectedIndex, Mode=TwoWay}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="Padding" Value="12,10" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="bd" Background="Transparent" Padding="{TemplateBinding Padding}" CornerRadius="5">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#22FFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="bd" Property="Background" Value="#3300B8D4" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding DisplayName}" FontSize="14" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
|
||||
<!-- 内容区(导航宿主) -->
|
||||
<ContentControl Grid.Row="1" Grid.Column="1"
|
||||
prism:RegionManager.RegionName="ContentRegion" />
|
||||
</Grid>
|
||||
</Window>
|
||||
17
src/SopHelper.App/VVMs/MainWindow/MainWindow.xaml.cs
Normal file
17
src/SopHelper.App/VVMs/MainWindow/MainWindow.xaml.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace SopHelper.VVMs.MainWindow;
|
||||
|
||||
/// <summary>
|
||||
/// 主窗口(shell:侧导航 + 内容区)
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// 主窗口
|
||||
/// </summary>
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
49
src/SopHelper.App/VVMs/MainWindow/MainWindowViewModel.cs
Normal file
49
src/SopHelper.App/VVMs/MainWindow/MainWindowViewModel.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using SopHelper.Models;
|
||||
|
||||
namespace SopHelper.VVMs.MainWindow;
|
||||
|
||||
/// <summary>
|
||||
/// Main窗口视图模型
|
||||
/// </summary>
|
||||
public class MainWindowViewModel : BindableBase
|
||||
{
|
||||
private readonly NavigationModel _navigation;
|
||||
|
||||
/// <summary>
|
||||
/// Main窗口视图模型
|
||||
/// </summary>
|
||||
public MainWindowViewModel(NavigationModel navigation)
|
||||
{
|
||||
_navigation = navigation;
|
||||
}
|
||||
|
||||
private string _title = "SopHelper";
|
||||
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title
|
||||
{
|
||||
get { return _title; }
|
||||
set { SetProperty(ref _title, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导航模型(侧栏绑定)
|
||||
/// </summary>
|
||||
public NavigationModel Navigation => _navigation;
|
||||
|
||||
private DelegateCommand? _exitCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 退出
|
||||
/// </summary>
|
||||
public DelegateCommand ExitCommand => _exitCommand ??= new DelegateCommand(OnExit);
|
||||
|
||||
private void OnExit()
|
||||
{
|
||||
System.Windows.Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
14
src/SopHelper.App/VVMs/SopPage/SopPage.xaml
Normal file
14
src/SopHelper.App/VVMs/SopPage/SopPage.xaml
Normal file
@ -0,0 +1,14 @@
|
||||
<UserControl x:Class="SopHelper.VVMs.SopPage.SopPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True">
|
||||
|
||||
<Border>
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<TextBlock Style="{StaticResource Title}" Text="SOP 辅助" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="{Binding Status}" HorizontalAlignment="Center" Margin="0,10,0,0"
|
||||
Foreground="{StaticResource FgDim}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</UserControl>
|
||||
18
src/SopHelper.App/VVMs/SopPage/SopPage.xaml.cs
Normal file
18
src/SopHelper.App/VVMs/SopPage/SopPage.xaml.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using SopHelper.Core.Prism;
|
||||
|
||||
namespace SopHelper.VVMs.SopPage;
|
||||
|
||||
/// <summary>
|
||||
/// SOP 主页(画面 + 步骤卡 + 参数)
|
||||
/// </summary>
|
||||
[NavigationPage(ViewName = "SopPage", DisplayName = "SOP 辅助", Index = 0)]
|
||||
public partial class SopPage : System.Windows.Controls.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// SOP 主页
|
||||
/// </summary>
|
||||
public SopPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
20
src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs
Normal file
20
src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace SopHelper.VVMs.SopPage;
|
||||
|
||||
/// <summary>
|
||||
/// SOP 主页视图模型(占位,画面与步骤卡在 s5 填充)
|
||||
/// </summary>
|
||||
public class SopPageViewModel : BindableBase
|
||||
{
|
||||
private string _status = "骨架已就绪(s2)";
|
||||
|
||||
/// <summary>
|
||||
/// 状态文本
|
||||
/// </summary>
|
||||
public string Status
|
||||
{
|
||||
get { return _status; }
|
||||
set { SetProperty(ref _status, value); }
|
||||
}
|
||||
}
|
||||
22
src/SopHelper.Engine/SopHelper.Engine.csproj
Normal file
22
src/SopHelper.Engine/SopHelper.Engine.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- 纯类库:相机采集 + 推理 + SOP 判定引擎,不含任何 UI 依赖(可单测、可复用) -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<RootNamespace>SopHelper.Engine</RootNamespace>
|
||||
<AssemblyName>SopHelper.Engine</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.10.0.20241108" />
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.23.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
0
yolo_models/.gitkeep
Normal file
0
yolo_models/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user