添加 MX-PD-盘古 项目文件

将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
Shi.Ji
2026-05-18 11:43:09 +08:00
parent 03632a379d
commit e31d3560bb
739 changed files with 99783 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="MainShell.ToolBox.View.DownCamLightView"
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:MainShell.ToolBox.View"
xmlns:customControl="clr-namespace:MainShell.Resources.CustomControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="5">
<UniformGrid HorizontalAlignment="Center" Columns="1" Rows="5">
<customControl:LightControl Value="{Binding DownCamLightConfig.PointRedLight}"
Header="{DynamicResource PointRedLight}"/>
<customControl:LightControl Value="{Binding DownCamLightConfig.PointBlueLight}"
Header="{DynamicResource PointBlueLight}"/>
<customControl:LightControl Value="{Binding DownCamLightConfig.RingRedLight}"
Header="{DynamicResource RingRedLight}"/>
<customControl:LightControl Value="{Binding DownCamLightConfig.RingBlueLight}"
Header="{DynamicResource RingBlueLight}"/>
</UniformGrid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MainShell.ToolBox.View
{
/// <summary>
/// DownCamLightView.xaml 的交互逻辑
/// </summary>
public partial class DownCamLightView : UserControl
{
public DownCamLightView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,17 @@
<UserControl x:Class="MainShell.ToolBox.View.FootView"
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:MainShell.ToolBox.View"
xmlns:mw="http://www.maxwell-gp.com/"
mc:Ignorable="d" Height="60"
>
<Border CornerRadius="10" >
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" IsEnabled="{Binding IsEnabled}">
<Button Style="{StaticResource DarkCrystalButtonStyle}" Click="{mw:Action ToolBoxClick}" Margin="2,4" Content="{DynamicResource ToolBox}"/>
<Button Style="{StaticResource DarkCrystalButtonStyle}" Margin="2,4" Content="{DynamicResource MainAxisHome}"/>
<Button Style="{StaticResource GreenCrystalButtonStyle}" Click="{mw:Action ManualMotionOperateClick}" Margin="2,4" Content="{DynamicResource ManualModeOperation}"/>
</StackPanel>
</Border>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MainShell.ToolBox.View
{
/// <summary>
/// FootView.xaml 的交互逻辑
/// </summary>
public partial class FootView : UserControl
{
public FootView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,13 @@
<Window x:Class="MainShell.ToolBox.View.ManualMotionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MainShell.ToolBox.View"
xmlns:mw="http://www.maxwell.com/controls"
mc:Ignorable="d"
Title="ManualMotionWindow" Height="800" Width="1100">
<Grid>
<mw:ManualControlView/>
</Grid>
</Window>

View File

@@ -0,0 +1,37 @@
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.Shapes;
namespace MainShell.ToolBox.View
{
/// <summary>
/// ManualMotionWindow.xaml 的交互逻辑
/// </summary>
public partial class ManualMotionWindow : Window
{
public ManualMotionWindow()
{
InitializeComponent();
this.Closing += ManualMotionWindow_Closing ;
}
private void ManualMotionWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!IoC.Get<MachineState>().IsExiting)
{
e.Cancel = true;
this.Hide();
}
}
}
}

View File

@@ -0,0 +1,19 @@
<UserControl x:Class="MainShell.ToolBox.View.MapCamLightView"
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:MainShell.ToolBox.View" xmlns:customControl="clr-namespace:MainShell.Resources.CustomControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="5">
<UniformGrid HorizontalAlignment="Center" Columns="1" Rows="5">
<customControl:LightControl Value="{Binding MapCamLightConfig.RedLight}"
Header="{DynamicResource RingRedLight}"/>
<customControl:LightControl Value="{Binding MapCamLightConfig.BlueLight}"
Header="{DynamicResource RingBlueLight}"/>
</UniformGrid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MainShell.ToolBox.View
{
/// <summary>
/// MapCamLightView.xaml 的交互逻辑
/// </summary>
public partial class MapCamLightView : UserControl
{
public MapCamLightView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,135 @@
<Window x:Class="MainShell.ToolBox.View.ToolBoxWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MainShell.ToolBox.View"
xmlns:vm="clr-namespace:MainShell.Models"
xmlns:toolvm="clr-namespace:MainShell.ToolBox.ViewModel"
AllowsTransparency="False"
WindowStyle="None"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Closing="Window_Closing"
Height="450" Width="800">
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
CornerRadius="10"
UseAeroCaptionButtons="False"
ResizeBorderThickness="6"
GlassFrameThickness="-1" />
</WindowChrome.WindowChrome>
<Window.Resources>
<Style TargetType="ListBoxItem">
<!-- 让内容水平拉伸,内边距等 -->
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="12,10"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="bd" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<ContentPresenter Margin="6,0"/>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<Setter TargetName="bd" Property="Background" Value="#DAE4F1"/>
</MultiTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="bd" Property="Background" Value="#5880B2"/>
<Setter Property="BorderBrush" Value="#3688F1"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- DataTemplate不要显式绑定到模型的 Foreground改为继承 ListBoxItem 的 Foreground -->
<DataTemplate DataType="{x:Type vm:ToolNavItem}">
<DockPanel>
<TextBlock Text="{Binding Icon}"
FontFamily="{StaticResource ttfFont}"
Foreground="{Binding Foreground}"
FontSize="16" Margin="2,0,8,0" />
<StackPanel>
<TextBlock Text="{Binding Title}" FontWeight="SemiBold"/>
<TextBlock Text="{Binding Subtitle}" FontSize="11"/>
</StackPanel>
</DockPanel>
</DataTemplate>
<!-- 其余 DataTemplate 保持不变 -->
<DataTemplate DataType="{x:Type toolvm:UpCamLightViewModel}">
<local:UpCamLightView/>
</DataTemplate>
<DataTemplate DataType="{x:Type toolvm:DownCamLightViewModel}">
<local:DownCamLightView/>
</DataTemplate>
<DataTemplate DataType="{x:Type toolvm:MapCamLightViewModel}">
<local:MapCamLightView/>
</DataTemplate>
<DataTemplate DataType="{x:Type toolvm:VisionDisplayTestViewModel}">
<local:VisionDisplayTestView/>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderThickness="1" BorderBrush="#8829F5" Grid.RowSpan="2"/>
<Grid MouseDown="Border_MouseDown" Opacity="0.8" Background="#205496">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{DynamicResource ToolBox}" FontSize="18" FontWeight="Bold" Foreground="White" Margin="20,5"/>
<Button Margin="34,2" Click="MinClick" BorderBrush="White" FontSize="18" HorizontalAlignment="Right" Style="{StaticResource TitleBarMinButtonStyle}"/>
<Button Margin="4,2" Click="CloseClick" BorderBrush="White" FontSize="18" HorizontalAlignment="Right" Style="{StaticResource TitleBarCloseButtonStyle}"/>
</Grid>
<Grid Background="{StaticResource BackgroundBrush}" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListBox x:Name="ToolBoxListBox"
Style="{x:Null}"
Background="#E4E8EA"
BorderThickness="0"
SelectedItem="{Binding SelectedTool}"
ItemsSource="{Binding Tools}"
>
</ListBox>
<ContentControl Grid.Column="1"
Content="{Binding SelectedTool.ContentViewModel}"
Margin="10,0,0,0"/>
</Grid>
</Grid>
</Window>

View File

@@ -0,0 +1,52 @@
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.Shapes;
namespace MainShell.ToolBox.View
{
/// <summary>
/// ToolBoxWindow.xaml 的交互逻辑
/// </summary>
public partial class ToolBoxWindowView : Window
{
public ToolBoxWindowView()
{
InitializeComponent();
this.DataContext = new ViewModel.ToolBoxWindowViewModel();
}
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!IoC.Get<MachineState>().IsExiting)
{
e.Cancel = true;
this.Hide();
}
}
private void MinClick(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void CloseClick(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

View File

@@ -0,0 +1,25 @@
<UserControl x:Class="MainShell.ToolBox.View.UpCamLightView"
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:MainShell.ToolBox.View"
xmlns:customControl="clr-namespace:MainShell.Resources.CustomControl"
mc:Ignorable="d"
>
<Grid Margin="5">
<UniformGrid HorizontalAlignment="Center" Columns="1" Rows="5">
<customControl:LightControl Value="{Binding UpCamLightConfig.PointRedLight}"
Header="{DynamicResource PointRedLight}"/>
<customControl:LightControl Value="{Binding UpCamLightConfig.PointBlueLight}"
Header="{DynamicResource PointBlueLight}"/>
<customControl:LightControl Value="{Binding UpCamLightConfig.RingRedLight}"
Header="{DynamicResource RingRedLight}"/>
<customControl:LightControl Value="{Binding UpCamLightConfig.RingBlueLight}"
Header="{DynamicResource RingBlueLight}"/>
<customControl:LightControl Value="{Binding UpCamLightConfig.RedBackLight}"
Header="{DynamicResource RedBackLight}"/>
</UniformGrid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MainShell.ToolBox.View
{
/// <summary>
/// UpCamLightView.xaml 的交互逻辑
/// </summary>
public partial class UpCamLightView : UserControl
{
public UpCamLightView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,73 @@
<UserControl x:Class="MainShell.ToolBox.View.VisionDisplayTestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mw="http://www.maxwell-gp.com/"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Padding="12" BorderBrush="#C7C7C7" BorderThickness="1" Background="#F8FAFC">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="180"/>
<ColumnDefinition Width="24"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Text="目标相机:" FontWeight="SemiBold"/>
<ComboBox Grid.Column="1"
Margin="8,0,0,0"
ItemsSource="{Binding CameraTypes}"
SelectedItem="{Binding State.SelectedCameraType}"
VerticalAlignment="Center"/>
<CheckBox Grid.Column="3"
VerticalAlignment="Center"
IsChecked="{Binding State.ClearShapesBeforeDisplay}"
Content="显示前清空图形"/>
</Grid>
</Border>
<StackPanel Grid.Row="1" Margin="0,12,0,0" Orientation="Horizontal">
<Button MinWidth="120"
Height="32"
Margin="0,0,12,0"
Content="发送图片事件"
mw:View.ActionTarget="{Binding}"
Click="{mw:Action SendImageEvent}"/>
<Button MinWidth="140"
Height="32"
Margin="0,0,12,0"
Content="发送显示事件"
mw:View.ActionTarget="{Binding}"
Click="{mw:Action SendDisplayEvent}"/>
<Button MinWidth="120"
Height="32"
Content="清空显示"
mw:View.ActionTarget="{Binding}"
Click="{mw:Action ClearDisplayEvent}"/>
</StackPanel>
<Border Grid.Row="2" Margin="0,12,0,0" Padding="12" BorderBrush="#C7C7C7" BorderThickness="1" Background="#FFFFFF">
<StackPanel>
<TextBlock Text="测试说明" FontSize="16" FontWeight="Bold" Foreground="#0B4A8B"/>
<TextBlock Margin="0,10,0,0" TextWrapping="Wrap" Text="1. 发送图片事件后,主界面对应相机区域应显示一张 320x240 的模拟彩色图。"/>
<TextBlock Margin="0,6,0,0" TextWrapping="Wrap" Text="2. 发送显示事件后,主界面对应相机区域应叠加点、文本、矩形、圆和线。"/>
<TextBlock Margin="0,6,0,0" TextWrapping="Wrap" Text="3. 清空显示用于验证 Shapes 清理是否生效。"/>
<Border Margin="0,16,0,0" Padding="10" Background="#EFF6FF" BorderBrush="#BFDBFE" BorderThickness="1">
<TextBlock TextWrapping="Wrap" Text="{Binding State.StatusMessage}" Foreground="#1D4ED8"/>
</Border>
</StackPanel>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,12 @@
using System.Windows.Controls;
namespace MainShell.ToolBox.View
{
public partial class VisionDisplayTestView : UserControl
{
public VisionDisplayTestView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,52 @@
using MainShell.Hardware;
using MainShell.Models;
using Stylet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MainShell.ToolBox.ViewModel
{
public class DownCamLightViewModel : PropertyChangedBase
{
private DownCamLightConfig _downCamLightConfig = new DownCamLightConfig();
public DownCamLightConfig DownCamLightConfig
{
get { return _downCamLightConfig; }
set { SetAndNotify(ref _downCamLightConfig, value); }
}
private readonly HardwareManager _hardwareManager;
public DownCamLightViewModel(HardwareManager hardwareManager)
{
this._hardwareManager = hardwareManager;
_downCamLightConfig.PropertyChanged -= _downCamLightConfig_PropertyChanged;
_downCamLightConfig.PropertyChanged += _downCamLightConfig_PropertyChanged;
}
private void _downCamLightConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == nameof(DownCamLightConfig.RingBlueLight))
{
Debug.WriteLine("RingBlueLight changed to: " + DownCamLightConfig.RingBlueLight);
_hardwareManager.Down_RingBlueLight.SetIntensity(DownCamLightConfig.RingBlueLight);
}
else if(e.PropertyName == nameof(DownCamLightConfig.RingRedLight))
{
_hardwareManager.Down_RingRedLight.SetIntensity(DownCamLightConfig.RingRedLight);
}
else if(e.PropertyName == nameof(DownCamLightConfig.PointBlueLight))
{
_hardwareManager.Down_PointBlueLight.SetIntensity(DownCamLightConfig.PointBlueLight);
}
else if(e.PropertyName == nameof(DownCamLightConfig.PointRedLight))
{
_hardwareManager.Down_PointRedLight.SetIntensity(DownCamLightConfig.PointRedLight);
}
}
}
}

View File

@@ -0,0 +1,62 @@
using MainShell.Hardware;
using MainShell.ToolBox.View;
using MaxwellFramework.Core.Interfaces;
using MwFramework.Controls.UIControl.ViewModel;
using MwFramework.Device;
using MwFramework.ManagerService;
using Stylet;
using StyletIoC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace MainShell.ToolBox.ViewModel
{
[Inject(Key = "Footer")]
public class FootViewModel : Screen, IView
{
private bool _isEnabled = true;
public bool IsEnabled
{
get { return _isEnabled; }
set { SetAndNotify(ref _isEnabled, value); }
}
private ManualMotionWindow _manualMotionWindow;
private ToolBoxWindowView _toolBoxWindow;
private readonly HardwareManager _hardwareManager;
public FootViewModel(HardwareManager hardwareManager)
{
_hardwareManager = hardwareManager;
_manualMotionWindow = new ManualMotionWindow();
_manualMotionWindow.DataContext = new ManualControlViewModel(new List<MwCard>
{
_hardwareManager.TdCard,_hardwareManager.AcsCard
})
{
IsShowVelAxis = false
};
_manualMotionWindow.Owner = Application.Current.MainWindow;
}
public void ToolBoxClick()
{
_toolBoxWindow = _toolBoxWindow ?? new ToolBoxWindowView();
_toolBoxWindow.WindowState = System.Windows.WindowState.Normal;
_toolBoxWindow.Show();
_toolBoxWindow.Activate();
}
public void ManualMotionOperateClick()
{
_manualMotionWindow.Show();
_manualMotionWindow.Activate();
}
}
}

View File

@@ -0,0 +1,42 @@
using MainShell.Hardware;
using MainShell.Models;
using Stylet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.ToolBox.ViewModel
{
public class MapCamLightViewModel : PropertyChangedBase
{
private MapCamLightConfig _mapCamLightConfig = new MapCamLightConfig();
public MapCamLightConfig MapCamLightConfig
{
get { return _mapCamLightConfig; }
set { SetAndNotify(ref _mapCamLightConfig, value); }
}
private readonly HardwareManager _hardwareManager;
public MapCamLightViewModel(HardwareManager hardwareManager)
{
this._hardwareManager = hardwareManager;
_mapCamLightConfig.PropertyChanged -= MapCamLightConfig_PropertyChanged;
_mapCamLightConfig.PropertyChanged += MapCamLightConfig_PropertyChanged;
}
private void MapCamLightConfig_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName==nameof(MapCamLightConfig.BlueLight))
{
_hardwareManager.Map_BlueLight.SetIntensity(MapCamLightConfig.BlueLight);
}
else if(e.PropertyName==nameof(MapCamLightConfig.RedLight))
{
_hardwareManager.Map_RedLight.SetIntensity(MapCamLightConfig.RedLight);
}
}
}
}

View File

@@ -0,0 +1,73 @@
using MainShell.Common;
using MainShell.Models;
using Stylet;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace MainShell.ToolBox.ViewModel
{
public class ToolBoxWindowViewModel : Screen
{
public ObservableCollection<ToolNavItem> Tools { get; }
private ToolNavItem _selectedTool;
public ToolNavItem SelectedTool
{
get { return _selectedTool; }
set { SetAndNotify(ref _selectedTool, value); }
}
public ToolBoxWindowViewModel()
{
Tools = new ObservableCollection<ToolNavItem>();
// 添加工具
Tools.Add(new ToolNavItem()
{
Subtitle = "光源设置",
Title = "定位相机",
Icon = "\ue610",
Foreground=CommonUti.BrushFromString("#EEFA0A"),
ContentViewModel = IoC.Get<MainShell.ToolBox.ViewModel.UpCamLightViewModel>()
});
Tools.Add(new ToolNavItem()
{
Subtitle = "光源设置",
Title = "下相机",
Icon = "\ue610",
Foreground = CommonUti.BrushFromString("#EEFA0A"),
ContentViewModel = IoC.Get<MainShell.ToolBox.ViewModel.DownCamLightViewModel>()
});
Tools.Add(new ToolNavItem()
{
Subtitle = "光源设置",
Title = "Map相机",
Icon = "\ue610",
Foreground = CommonUti.BrushFromString("#EEFA0A"),
ContentViewModel = IoC.Get<MainShell.ToolBox.ViewModel.MapCamLightViewModel>()
});
Tools.Add(new ToolNavItem()
{
Subtitle = "事件模拟",
Title = "显示测试",
Icon = "\ue6d7",
Foreground = CommonUti.BrushFromString("#4F9DFF"),
ContentViewModel = IoC.Get<MainShell.ToolBox.ViewModel.VisionDisplayTestViewModel>()
});
if (Tools.Count > 0)
{
SelectedTool = Tools[0];
}
}
protected override void OnViewLoaded()
{
base.OnViewLoaded();
}
}
}

View File

@@ -0,0 +1,57 @@
using MainShell.Hardware;
using MainShell.Models;
using Stylet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.ToolBox.ViewModel
{
public class UpCamLightViewModel : PropertyChangedBase
{
private UpCamLightConfig _upCamLightConfig = new UpCamLightConfig();
public UpCamLightConfig UpCamLightConfig
{
get { return _upCamLightConfig; }
set { SetAndNotify(ref _upCamLightConfig, value); }
}
private readonly HardwareManager _hardwareManager;
public UpCamLightViewModel(HardwareManager hardwareManager)
{
this._hardwareManager = hardwareManager;
_upCamLightConfig.PropertyChanged -= UpCamLightConfig_PropertyChanged;
_upCamLightConfig.PropertyChanged += UpCamLightConfig_PropertyChanged;
}
private void UpCamLightConfig_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(UpCamLightConfig.RingBlueLight))
{
Debug.WriteLine("RingBlueLight changed to: " + UpCamLightConfig.RingBlueLight);
_hardwareManager.Up_RingBlueLight.SetIntensity(UpCamLightConfig.RingBlueLight);
}
else if (e.PropertyName == nameof(UpCamLightConfig.RingRedLight))
{
_hardwareManager.Up_RingRedLight.SetIntensity(UpCamLightConfig.RingRedLight);
}
else if (e.PropertyName == nameof(UpCamLightConfig.PointBlueLight))
{
_hardwareManager.Up_PointBlueLight.SetIntensity(UpCamLightConfig.PointBlueLight);
}
else if (e.PropertyName == nameof(UpCamLightConfig.PointRedLight))
{
_hardwareManager.Up_PointRedLight.SetIntensity(UpCamLightConfig.PointRedLight);
}
else if (e.PropertyName == nameof(UpCamLightConfig.RedBackLight))
{
_hardwareManager.Up_RedBackLight.SetIntensity(UpCamLightConfig.RedBackLight);
}
}
}
}

View File

@@ -0,0 +1,237 @@
using MainShell.EventArgsFolder;
using MainShell.Log;
using MainShell.Vision;
using MwFramework.Device;
using MwFramework.Device.Model;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using AppCameraType = MainShell.Common.CameraType;
namespace MainShell.ToolBox.ViewModel
{
public class VisionDisplayTestState : PropertyChangedBase
{
private AppCameraType _selectedCameraType = AppCameraType.TopPositionCamera;
public AppCameraType SelectedCameraType
{
get
{
return _selectedCameraType;
}
set
{
SetAndNotify(ref _selectedCameraType, value);
}
}
private bool _clearShapesBeforeDisplay = true;
public bool ClearShapesBeforeDisplay
{
get
{
return _clearShapesBeforeDisplay;
}
set
{
SetAndNotify(ref _clearShapesBeforeDisplay, value);
}
}
private string _statusMessage = "请选择主界面相机区域后发送测试事件。";
public string StatusMessage
{
get
{
return _statusMessage;
}
set
{
SetAndNotify(ref _statusMessage, value);
}
}
}
public class VisionDisplayTestViewModel : PropertyChangedBase
{
private const int ImageWidth = 320;
private const int ImageHeight = 240;
private readonly IEventAggregator _eventAggregator;
private readonly VisionDisplayTestState _state;
private readonly AppCameraType[] _cameraTypes;
public VisionDisplayTestState State
{
get
{
return _state;
}
}
public IEnumerable<AppCameraType> CameraTypes
{
get
{
return _cameraTypes;
}
}
public VisionDisplayTestViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
_state = new VisionDisplayTestState();
_cameraTypes = Enum.GetValues(typeof(AppCameraType)).Cast<AppCameraType>().ToArray();
}
public void SendImageEvent()
{
try
{
CameraData cameraData = CreateTestCameraData();
DisplayImageEventArgs message = new DisplayImageEventArgs(State.SelectedCameraType, cameraData);
_eventAggregator.Publish(message);
State.StatusMessage = $"已发送图片事件到 {State.SelectedCameraType},请查看主界面相机区域。";
}
catch (Exception ex)
{
State.StatusMessage = $"发送图片事件失败:{ex.Message}";
($"VisionDisplayTestViewModel.SendImageEvent exception: {ex}").LogSysError();
}
}
public void SendDisplayEvent()
{
try
{
FindTemplateResult result = CreateTestTemplateResult();
DisplayFindTemplateResultEventArgs message = new DisplayFindTemplateResultEventArgs(
State.SelectedCameraType,
result,
State.ClearShapesBeforeDisplay);
_eventAggregator.Publish(message);
State.StatusMessage = $"已发送结果显示事件到 {State.SelectedCameraType},请查看主界面图形叠加。";
}
catch (Exception ex)
{
State.StatusMessage = $"发送结果显示事件失败:{ex.Message}";
($"VisionDisplayTestViewModel.SendDisplayEvent exception: {ex}").LogSysError();
}
}
public void ClearDisplayEvent()
{
try
{
DisplayFindTemplateResultEventArgs message = new DisplayFindTemplateResultEventArgs(
State.SelectedCameraType,
null,
true);
_eventAggregator.Publish(message);
State.StatusMessage = $"已清空 {State.SelectedCameraType} 的图形叠加。";
}
catch (Exception ex)
{
State.StatusMessage = $"清空结果显示失败:{ex.Message}";
($"VisionDisplayTestViewModel.ClearDisplayEvent exception: {ex}").LogSysError();
}
}
private static CameraData CreateTestCameraData()
{
byte[] buffer = new byte[ImageWidth * ImageHeight * 3];
for (int y = 0; y < ImageHeight; y++)
{
for (int x = 0; x < ImageWidth; x++)
{
int offset = ((y * ImageWidth) + x) * 3;
buffer[offset] = (byte)((x * 255) / ImageWidth);
buffer[offset + 1] = (byte)((y * 255) / ImageHeight);
buffer[offset + 2] = 40;
}
}
AddCrossMark(buffer, ImageWidth / 2, ImageHeight / 2, 36, 255, 255, 255);
CameraData cameraData = new CameraData(
buffer,
(uint)ImageWidth,
(uint)ImageHeight,
CustomPixelFormat.Rgb8Packed,
0L,
DateTime.Now,
false);
cameraData.Bit = 3;
return cameraData;
}
private static void AddCrossMark(byte[] buffer, int centerX, int centerY, int halfLength, byte blue, byte green, byte red)
{
for (int offsetX = -halfLength; offsetX <= halfLength; offsetX++)
{
SetPixel(buffer, centerX + offsetX, centerY, blue, green, red);
}
for (int offsetY = -halfLength; offsetY <= halfLength; offsetY++)
{
SetPixel(buffer, centerX, centerY + offsetY, blue, green, red);
}
}
private static void SetPixel(byte[] buffer, int x, int y, byte blue, byte green, byte red)
{
if (x < 0 || x >= ImageWidth || y < 0 || y >= ImageHeight)
{
return;
}
int offset = ((y * ImageWidth) + x) * 3;
buffer[offset] = blue;
buffer[offset + 1] = green;
buffer[offset + 2] = red;
}
private static FindTemplateResult CreateTestTemplateResult()
{
FindTemplateResult result = new FindTemplateResult();
result.CenterX = 160d;
result.CenterY = 120d;
result.Score = 0.987d;
result.Contour = new FindTemplateContourResult
{
StartX = 90d,
StartY = 70d,
EndX = 230d,
EndY = 170d
};
result.Circles.Add(new FindTemplateCircleResult
{
CenterX = 160d,
CenterY = 120d,
Radius = 24d
});
result.Lines.Add(new FindTemplateLineResult
{
StartX = 80d,
StartY = 40d,
EndX = 260d,
EndY = 200d
});
result.Rectangles.Add(new FindTemplateRectangleResult
{
StartX = 110d,
StartY = 85d,
Width = 90d,
Height = 48d,
Angle = Math.PI / 9d
});
return result;
}
}
}