添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user