2026-01-26 18:56:53 +09:00

101 lines
3.7 KiB
C#

using Aurora;
using Aurora.View;
using AuroraCAS;
using Hermes.Functional;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using VisionCommon;
using VisionCommonUI;
using VisionCommonUI.Resources;
namespace WeldingCommon.Views {
public class WDSelectScoutFieldViewModel : NotifyPropertyChangedBase
{
public delegate void RequestCloseEventHandler();
public event RequestCloseEventHandler RequestClose;
private CamConfig _CamConfig;
#region Binding Properties
public ImageSource BackgroundImage { get; set; }
public List<ChildBufRowCol> FieldScanParamList { get; set; }
private int _RowCount;
public int RowCount { get => _RowCount; set => SetProperty(ref _RowCount, value); }
private int _ColumnCount;
public int ColumnCount { get => _ColumnCount; set => SetProperty(ref _ColumnCount, value); }
#endregion
public WDSelectScoutFieldViewModel(IAuroraEnvironment aurora)
{
_CamConfig = aurora.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig;
SetBackgroundImage(aurora);
LoadFieldScanParams();
}
private void SetBackgroundImage(IAuroraEnvironment aurora)
{
//var defaultValue = "D:\\ILSOSConfig\\_Vision\\Default\\DefaultFieldScanImage.Jpeg";
var defaultValue = "D:\\ILSOSConfig\\_vision\\FieldScanImage\\Default\\DefaultFieldScanImage.Jpeg";
var imagePath = DB.LASARecipeHelper.GetValue("ScannerFieldImageFile", defaultValue).ToString();
if (File.Exists(imagePath)) {
BackgroundImage = new BitmapImage(new Uri(imagePath));
return;
}
//var imageSizeWidthChild = _CamConfig.ImageSize.Width / 2;
//var imageSizeHeightChild = _CamConfig.ImageSize.Height / 2;
var imageSizeWidthChild = (int)(_CamConfig.ImageSize.Width * _CamConfig.ImageSizeRatioX); // 이게 맞지 않나..?
var imageSizeHeightChild = (int)(_CamConfig.ImageSize.Height * _CamConfig.ImageSizeRatioY);
int stride = imageSizeWidthChild / 8;
byte[] pixels = new byte[imageSizeHeightChild * stride];
//Fill pixel data with black color.
pixels.ForEach(pixel => pixel = 0x00);
BitmapSource bitmap = BitmapSource.Create(
imageSizeWidthChild,
imageSizeHeightChild,
96, 96,
PixelFormats.Indexed1,
new BitmapPalette(new List<Color> { Colors.Black }),
pixels,
stride);
BackgroundImage = bitmap;
}
private void LoadFieldScanParams()
{
FieldScanParamList = _CamConfig.ChildImage.ChildBufRowCols
.OrderBy(row => row.RowIdx)
.ThenBy(col => col.ColIdx)
.Select(param => param.Clone() as ChildBufRowCol)
.ToList();
ColumnCount = FieldScanParamList.Max(x => x.ColIdx) + 1;
RowCount = FieldScanParamList.Max(y => y.RowIdx) + 1;
}
public void PerformCmdSave()
{
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig;
camConfig.ChildImage.ChildBufRowCols = FieldScanParamList.ConvertAll(o => o.Clone() as ChildBufRowCol);
VisionEnv.AuroraEnv.DeviceManager.SaveDeviceConfig(eCamId.CAM1.ToString());
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
RequestClose?.Invoke();
}
}
}