8 Commits

Author SHA1 Message Date
TD
d2f3b3f3aa 修改 2025-04-16 08:47:59 +08:00
TD
b009a7355b 修改日志1 2025-04-15 09:24:39 +08:00
TD
72b67b6a2f 修改合并界面 2025-04-11 14:15:03 +08:00
TD
8a0668ed96 解决合并冲突 2025-04-11 11:52:29 +08:00
TD
e31a890b06 修改图片保存路径 2025-04-11 11:47:29 +08:00
428896dbf8 修改保存相机原图和保存结果图命名一致 2025-04-11 11:09:55 +08:00
TD
f9d472295b 1 2025-04-11 10:42:40 +08:00
4765e0e5bd 修改统计 2025-04-10 14:08:55 +08:00
16 changed files with 1852 additions and 809 deletions

View File

@ -343,7 +343,18 @@ namespace DH.Commons.Base
} }
// 其他方法保持原有逻辑 // 其他方法保持原有逻辑
public Action<DateTime, CameraBase, Mat> OnHImageOutput { get; set; } public MatSet CopyImageSet(MatSet srcSet)
{
MatSet imageSet = new MatSet
{
Id = srcSet.Id,
_mat = srcSet._mat.Clone(),
// ImageSaveOption = srcSet.ImageSaveOption.Copy(),
ImageTime = srcSet.ImageTime
};
return imageSet;
}
public Action<DateTime, CameraBase, MatSet> OnHImageOutput { get; set; }
public virtual bool CameraConnect() { return false; } public virtual bool CameraConnect() { return false; }

View File

@ -509,7 +509,7 @@ namespace DH.Commons.Base
private AntList<SizeTreatParam> _sizeTreatParamList = new AntList<SizeTreatParam>(); private AntList<SizeTreatParam> _sizeTreatParamList = new AntList<SizeTreatParam>();
private CustomizedPoint _showLocation = new CustomizedPoint(); private CustomizedPoint _showLocation = new CustomizedPoint();
private string _imageSaveDirectory="D://Images"; private string _imageSaveDirectory= "D://PROJECTS//Images//";
private bool _saveOKOriginal = false; private bool _saveOKOriginal = false;
private bool _saveNGOriginal = false; private bool _saveNGOriginal = false;
private bool _saveOKDetect = false; private bool _saveOKDetect = false;
@ -1072,6 +1072,15 @@ namespace DH.Commons.Base
OnPropertyChanged(nameof(CellLinks)); OnPropertyChanged(nameof(CellLinks));
} }
} }
public bool FilterOperation(DetectionResultDetail recongnitionResult)
{
double compareValue = recongnitionResult.Area;
double compareScoreValue = recongnitionResult.Score;
return (compareValue >= MinArea && compareValue <= MaxArea)&& (compareScoreValue >= MinScore && compareScoreValue <= MaxScore);
}
} }
public class SizeTreatParam : NotifyProperty public class SizeTreatParam : NotifyProperty

View File

@ -305,7 +305,7 @@ namespace DH.Commons.Base
//if (InitialConfig.IsEnableLog) //if (InitialConfig.IsEnableLog)
//{ //{
// LoggerHelper.LogAsync(msg); LoggerHelper.LogAsync(msg);
//} //}
} }

View File

@ -36,7 +36,7 @@ namespace DH.Commons.Base
public HTuple hv_ModelID; public HTuple hv_ModelID;
public abstract DetectStationResult RunInference(Mat originImgSet, string detectionId = null); public abstract DetectStationResult RunInference(MatSet originImgSet, string detectionId = null);
//public abstract void SaveDetectResultAsync(DetectStationResult detectResult); //public abstract void SaveDetectResultAsync(DetectStationResult detectResult);

View File

@ -12,6 +12,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AntdUI" Version="1.8.9" /> <PackageReference Include="AntdUI" Version="1.8.9" />

View File

@ -375,6 +375,22 @@ namespace DH.Commons.Enums
[Description("异常")] [Description("异常")]
DSExcept = 32 DSExcept = 32
} }
public enum RunState
{
[ColorSelect("Gold")]
[Description("空闲")]
Idle = 1,
[ColorSelect("Lime")]
[Description("运行中")]
Running = 2,
[ColorSelect("Gray")]
[Description("停止")]
Stop = 3,
[ColorSelect("Red")]
[Description("宕机")]
Down = 99,
}
public enum PriorityDirection public enum PriorityDirection
{ {
X, X,

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DH.Commons.Models
{
public class CameraSummary
{
public string CameraName { get; set; } // 相机名称
public int TiggerCount { get; set; } //触发数
public int OKCount { get; set; } // OK 数
public int NGCount { get; set; } // NG 数
public int TotalCount => OKCount + NGCount; // 总检测数量
public string YieldStr => $"{Yield:f2} %"; // 良率(字符串形式)
public double Yield => OKCount + NGCount > 0 ? (double)OKCount / (OKCount + NGCount) * 100 : 0;
}
public class ProductSummary
{
public int ProductAmount { get; set; }
public string ResultDesc { get; set; }
public string PercentStr { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Xml.Linq; using System.Xml.Linq;
@ -9,6 +10,7 @@ using DVPCameraType;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using static MvCamCtrl.NET.MyCamera;
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel; using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
@ -38,7 +40,7 @@ namespace DH.Devices.Camera
{ {
LoggerHelper.LogPath = "D://"; LoggerHelper.LogPath = "D://";
LoggerHelper.LogPrefix = CameraName; LoggerHelper.LogPrefix = CameraName;
} }
@ -61,6 +63,7 @@ namespace DH.Devices.Camera
{ {
try try
{ {
pCallBackFunc = new DVPCamera.dvpEventCallback(cbExceptiondelegate);
nRet = DVPCamera.dvpOpenByUserId(CameraName, nRet = DVPCamera.dvpOpenByUserId(CameraName,
dvpOpenMode.OPEN_NORMAL, dvpOpenMode.OPEN_NORMAL,
ref m_handle); ref m_handle);
@ -81,13 +84,13 @@ namespace DH.Devices.Camera
nRet = DVPCamera.dvpGetCameraInfo(m_handle, ref camerainfo); nRet = DVPCamera.dvpGetCameraInfo(m_handle, ref camerainfo);
SerialNumber = camerainfo.SerialNumber; SerialNumber = camerainfo.SerialNumber;
// ch:注册异常回调函数 | en:Register Exception Callback //ch: 注册异常回调函数 | en:Register Exception Callback
//nRet = DVPCamera.dvpRegisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero); nRet = DVPCamera.dvpRegisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
//if (nRet != dvpStatus.DVP_STATUS_OK) if (nRet != dvpStatus.DVP_STATUS_OK)
//{ {
// throw new Exception($"Register expection callback failed:{nRet}"); throw new Exception($"Register expection callback failed:{nRet}");
//} }
//GC.KeepAlive(pCallBackFunc); GC.KeepAlive(pCallBackFunc);
//// ch:设置采集连续模式 | en:Set Continues Aquisition Mode //// ch:设置采集连续模式 | en:Set Continues Aquisition Mode
if (IsContinueMode) if (IsContinueMode)
@ -152,7 +155,7 @@ namespace DH.Devices.Camera
SetGain(Gain); SetGain(Gain);
} }
//全画幅 //全画幅
if(!IsAllPicEnabled) if (!IsAllPicEnabled)
SetPictureRoi((int)ROIX, (int)ROIY, (int)ROIW, (int)ROIH); SetPictureRoi((int)ROIX, (int)ROIY, (int)ROIW, (int)ROIH);
//// 设置 触发延迟 //// 设置 触发延迟
@ -190,7 +193,26 @@ namespace DH.Devices.Camera
} }
/// <summary>
/// 回调函数
/// </summary>
/// <param name="handle"></param>
/// <param name="_event"></param>
/// <param name="pContext"></param>
/// <param name="param"></param>
/// <param name="refVariant"></param>
/// <returns></returns>
public int cbExceptiondelegate(uint handle, dvpEvent _event, IntPtr pContext, int param, ref dvpVariant refVariant)
{
if (_event == dvpEvent.EVENT_DISCONNECTED)
{
}
return dvpStatus.DVP_STATUS_OK.ToInt();
}
private void IIConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void IIConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
@ -329,7 +351,7 @@ namespace DH.Devices.Camera
Mat cvImage = new Mat(); Mat cvImage = new Mat();
if (this.CameraName.Equals("Cam1")) if (this.CameraName.Equals("Cam1"))
{ {
Console.WriteLine( ); Console.WriteLine();
} }
if (this.CameraName.Equals("Cam2")) if (this.CameraName.Equals("Cam2"))
{ {
@ -369,13 +391,15 @@ namespace DH.Devices.Camera
{ {
_mat = smat, _mat = smat,
}; };
InitialImageSet(imageSet); InitialImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
var outImgSet = CopyImageSet(imageSet);
OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
//存图 //存图
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount); DisplayAndSaveOriginImage(imageSet.Id, SnapshotCount);
@ -391,7 +415,7 @@ namespace DH.Devices.Camera
} }
return 0; return 0;
} }
public void InitialImageSet(MatSet set) public void InitialImageSet(MatSet set)
{ {
//if (saveOption != null) //if (saveOption != null)
//{ //{
@ -415,13 +439,25 @@ namespace DH.Devices.Camera
{ {
await Task.Run(() => await Task.Run(() =>
{ {
Bitmap showImage = set._mat.ToBitmap(); Bitmap? showImage = null;
try
{
showImage = set._mat.ToBitmap();
}
catch (Exception)
{
//释放 himage
ClearImageSet(set);
return;
}
// showImage.Save("D:/test333.bmp"); // showImage.Save("D:/test333.bmp");
// Marshal.Copy(pbyteImageBuffer, 0, (IntPtr)lAddrImage, (int)dwBufferSize); // Marshal.Copy(pbyteImageBuffer, 0, (IntPtr)lAddrImage, (int)dwBufferSize);
// Bitmap saveImage = showImage?.CopyBitmap(); // Bitmap saveImage = showImage?.CopyBitmap();
// saveImage.Save("d://TEST444.BMP"); // saveImage.Save("d://TEST444.BMP");
// OnShowImageUpdated?.Invoke(this, showImage, imgSetId); // OnShowImageUpdated?.Invoke(this, showImage, imgSetId);
if (IsSavePicEnabled) if (IsSavePicEnabled && showImage != null)
{ {
string fullname = Path.Combine(ImageSaveDirectory, $"{CameraName}_{_counter:D7}_{set.Id}.{set._imageFormat.ToString().ToLower()}"); string fullname = Path.Combine(ImageSaveDirectory, $"{CameraName}_{_counter:D7}_{set.Id}.{set._imageFormat.ToString().ToLower()}");
ImageSaveAsync(fullname, showImage); ImageSaveAsync(fullname, showImage);
@ -466,7 +502,7 @@ namespace DH.Devices.Camera
{ {
FullName = fullName, FullName = fullName,
SaveImage = map, SaveImage = map,
}; };
ImageSaveHelper.ImageSaveAsync(imageSaveSet); ImageSaveHelper.ImageSaveAsync(imageSaveSet);
@ -475,31 +511,39 @@ namespace DH.Devices.Camera
{ {
try try
{ {
dvpStreamState StreamState = new dvpStreamState();
nRet = DVPCamera.dvpGetStreamState(m_handle, ref StreamState); // 1. 停止采集(如果正在运行)
//Debug.Assert(nRet == dvpStatus.DVP_STATUS_OK); dvpStreamState streamState = new dvpStreamState();
if (StreamState == dvpStreamState.STATE_STARTED) nRet = DVPCamera.dvpGetStreamState(m_handle, ref streamState);
if (streamState == dvpStreamState.STATE_STARTED)
{ {
// stop camera // 先停止采集流
nRet = DVPCamera.dvpStop(m_handle); nRet = DVPCamera.dvpStop(m_handle);
Debug.Assert(nRet == dvpStatus.DVP_STATUS_OK);
if (nRet != dvpStatus.DVP_STATUS_OK) if (nRet != dvpStatus.DVP_STATUS_OK)
{ {
throw new Exception($"Stop grabbing failed{nRet:x8}"); throw new Exception($"停止采集失败错误码0x{nRet:X8}");
} }
} }
// 2. 设置触发源为软件触发(此时设备已停止)
nRet = DVPCamera.dvpSetTriggerState(m_handle, false);
if (nRet != dvpStatus.DVP_STATUS_OK)
{
throw new Exception($"设置软件触发失败错误码0x{nRet:X8}");
}
// 3. 注销事件回调
nRet = DVPCamera.dvpUnregisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero); nRet = DVPCamera.dvpUnregisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
if (nRet != dvpStatus.DVP_STATUS_OK) if (nRet != dvpStatus.DVP_STATUS_OK)
{ {
throw new Exception($"Unregister expection callback failed:{nRet}"); throw new Exception($"注销事件回调失败错误码0x{nRet:X8}");
} }
// ch:关闭设备 | en:Close device // 4. 关闭设备
nRet = DVPCamera.dvpClose(m_handle); nRet = DVPCamera.dvpClose(m_handle);
if (nRet != dvpStatus.DVP_STATUS_OK) if (nRet != dvpStatus.DVP_STATUS_OK)
{ {
throw new Exception($"Close device failed{nRet:x8}"); throw new Exception($"关闭设备失败错误码0x{nRet:X8}");
} }
m_handle = 0; m_handle = 0;
@ -525,7 +569,7 @@ namespace DH.Devices.Camera
LoggerHelper.LogAsync(msg); LoggerHelper.LogAsync(msg);
} }
} }
public void LogAsync(DateTime dt, LogLevel logLevel, string msg) public void LogAsync(DateTime dt, LogLevel logLevel, string msg)
{ {
LogAsync(new LogMsg(dt, logLevel, msg)); LogAsync(new LogMsg(dt, logLevel, msg));
} }

View File

@ -368,7 +368,7 @@ namespace DH.Devices.Camera
throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}"); throw new NotSupportedException($"Unsupported pixel type: {pFrameInfo.enPixelType}");
} }
OnHImageOutput?.Invoke(DateTime.Now, this, cvImage); //OnHImageOutput?.Invoke(DateTime.Now, this, cvImage);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -41,7 +41,7 @@ namespace DH.Devices.PLC
{ {
try try
{ {
LoggerHelper.LogPath = "D://"; LoggerHelper.LogPath = "D://PROJECTS//Logs//";
LoggerHelper.LogPrefix = "PLC"; LoggerHelper.LogPrefix = "PLC";
TcpNet.IpAddress = IP; TcpNet.IpAddress = IP;

View File

@ -58,7 +58,7 @@ namespace DH.Devices.Vision
//{ //{
// LogAsync(new LogMsg(dt, LogLevel.Error, msg)); // LogAsync(new LogMsg(dt, LogLevel.Error, msg));
//} //}
public override DetectStationResult RunInference(Mat originImgSet, string detectionId = null) public override DetectStationResult RunInference(MatSet originImgSet, string detectionId = null)
{ {
DetectStationResult detectResult = new DetectStationResult(); DetectStationResult detectResult = new DetectStationResult();
DetectionConfig detectConfig = null; DetectionConfig detectConfig = null;
@ -78,19 +78,20 @@ namespace DH.Devices.Vision
//未能获得检测配置 //未能获得检测配置
return detectResult; return detectResult;
} }
detectResult.Id = originImgSet.Id;
detectResult.DetectName = detectConfig.Name; detectResult.DetectName = detectConfig.Name;
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory; detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
detectResult.SaveNGDetect=detectConfig.SaveNGDetect; detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal; detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
detectResult.SaveOKDetect=detectConfig.SaveOKDetect; detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal; detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
Mat OriginImage = originImgSet.Clone(); Mat OriginImage = originImgSet._mat.Clone();
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap()); detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap(); //detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
#region 1. #region 1.
sw.Start(); sw.Start();
using (Mat PreTMat = originImgSet.Clone()) using (Mat PreTMat = originImgSet._mat.Clone())
{ {
PreTreated(detectConfig, detectResult, PreTMat); PreTreated(detectConfig, detectResult, PreTMat);
PreTreated2(detectConfig, detectResult, PreTMat); PreTreated2(detectConfig, detectResult, PreTMat);
@ -142,7 +143,7 @@ namespace DH.Devices.Vision
req.ResizeHeight = (int)detectConfig.ModelHeight; req.ResizeHeight = (int)detectConfig.ModelHeight;
// req.LabelNames = detectConfig.GetLabelNames(); // req.LabelNames = detectConfig.GetLabelNames();
// req.Score = IIConfig.Score; // req.Score = IIConfig.Score;
req.mImage = originImgSet.Clone(); req.mImage = originImgSet._mat.Clone();
req.in_lable_path = detectConfig.In_lable_path; req.in_lable_path = detectConfig.In_lable_path;
@ -170,41 +171,10 @@ namespace DH.Devices.Vision
// LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference BEGIN"); // LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference BEGIN");
mlWatch.Start(); mlWatch.Start();
//20230802改成多线程推理 RunInferenceFixed
// MLResult result = new MLResult();
var result = mlSet.StationMLEngine.RunInference(req); var result = mlSet.StationMLEngine.RunInference(req);
// var result = mlSet.StationMLEngine.RunInferenceFixed(req);
mlWatch.Stop(); mlWatch.Stop();
// LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference END");
// var req = new MLRequest();
//req.mImage = inferenceImage;
//req.ResizeWidth = detectConfig.ModelWidth;
//req.ResizeHeight = detectConfig.ModelHeight;
//req.confThreshold = detectConfig.ModelconfThreshold;
//req.iouThreshold = 0.3f;
//req.out_node_name = "output0";
//req.in_lable_path = detectConfig.in_lable_path;
//Stopwatch sw = Stopwatch.StartNew();
//var result = Dectection[detectionId].RunInference(req);
//sw.Stop();
//LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理进度1.1,产品{productNumber},耗时{sw.ElapsedMilliseconds}ms");
//this.BeginInvoke(new MethodInvoker(delegate ()
//{
// // pictureBox1.Image?.Dispose(); // 释放旧图像
// // pictureBox1.Image = result.ResultMap;
// richTextBox1.AppendText($"推理成功 {productNumber}, {result.IsSuccess}相机名字{camera.CameraName} 耗时 {mlWatch.ElapsedMilliseconds}ms\n");
//}));
//req.mImage?.Dispose();
@ -268,22 +238,22 @@ namespace DH.Devices.Vision
} }
//foreach (IGrouping<ResultState, DetectionFilter> group in conditionList) foreach (IGrouping<ResultState, DetectionLable> group in conditionList)
//{ {
// bool b = group.ToList().Any(f => bool b = group.ToList().Any(f =>
// { {
// return f.FilterOperation(d); return f.FilterOperation(d);
// }); });
// if (b) if (b)
// { {
// d.FinalResult = group.Key; d.FinalResult = group.Key;
// break; break;
// } }
//} }
}); });
#endregion #endregion
#region 5.NG #region 5.NG
@ -308,7 +278,7 @@ namespace DH.Devices.Vision
DisplayDetectionResult(detectResult, originImgSet.Clone(), detectionId); DisplayDetectionResult(detectResult, originImgSet._mat.Clone(), detectionId);
@ -455,7 +425,7 @@ namespace DH.Devices.Vision
{ {
// throw new ProcessException("异常:模型加载异常", null); // throw new ProcessException("异常:模型加载异常", null);
} }
LogAsync(DateTime.Now, LogLevel.Information, $"模型加载成功是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}"); LogAsync(DateTime.Now, LogLevel.Action, $"模型加载成功是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
} }
} }
catch (Exception ex) catch (Exception ex)

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,11 @@ using System;
using System.CodeDom; using System.CodeDom;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -37,6 +39,7 @@ using static DH.Commons.Enums.EnumHelper;
using Camera = DHSoftware.Models.Camera; using Camera = DHSoftware.Models.Camera;
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel; using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
using ResultState = DH.Commons.Base.ResultState; using ResultState = DH.Commons.Base.ResultState;
using Timer = System.Threading.Timer;
namespace DHSoftware namespace DHSoftware
{ {
@ -44,6 +47,13 @@ namespace DHSoftware
{ {
private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null; private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
public event Action<LogMsg> OnLog; public event Action<LogMsg> OnLog;
public List<CameraSummary> CameraSummaries { get; set; } = new List<CameraSummary>();
public List<ProductSummary> ProductSummaries = new List<ProductSummary>();
static object _productSummaryLock = new object();
public event Action<DateTime, object, string> OnUpdateResult;
public event Action<DateTime, object, string> OnUpdateCamResult;
private string _loginName; private string _loginName;
public string LoginName public string LoginName
@ -261,7 +271,6 @@ namespace DHSoftware
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
//refreshTimer.Start(); //refreshTimer.Start();
//初始化数据 //初始化数据
InitData(); InitData();
@ -273,6 +282,321 @@ namespace DHSoftware
//userControlFrm.Dock = DockStyle.Fill; //userControlFrm.Dock = DockStyle.Fill;
//tabPage2.Controls.Add(userControlFrm); //tabPage2.Controls.Add(userControlFrm);
} }
//#region OEE
// public event Action<RunState> OnProcessRunStateChanged;
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public virtual void Set<T>(ref T field, T newValue, [CallerMemberName] string propName = null)
{
if (!field.Equals(newValue))
{
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
#endregion
#region Properties
private int uph = 0;
private int upm = 0;
private DateTime? startTime = null;
private TimeSpan runTime = new TimeSpan();
private TimeSpan idleTime = new TimeSpan();
private TimeSpan downTime = new TimeSpan();
private TimeSpan totalTime = new TimeSpan();
private int qty_OEE = 0;
private int qty_OEE_OK = 0;
private float oee = 0;
public int UPH
{
get => uph;
set => Set(ref uph, value);
}
public int UPM
{
get => upm;
set => Set(ref upm, value);
}
public DateTime? StartTime
{
get => startTime;
set => Set(ref startTime, value);
}
/// <summary>
/// 有效运行时间
/// </summary>
public TimeSpan RunTime
{
get => runTime;
set => Set(ref runTime, value);
}
/// <summary>
/// 空闲待机时间
/// </summary>
public TimeSpan IdleTime
{
get => idleTime;
set => Set(ref idleTime, value);
}
/// <summary>
/// 故障宕机时间
/// </summary>
public TimeSpan DownTime
{
get => downTime;
set => Set(ref downTime, value);
}
/// <summary>
/// 总开机时间
/// </summary>
public TimeSpan TotalTime
{
get => totalTime;
set => Set(ref totalTime, value);
}
public float OEE
{
get => oee;
set => Set(ref oee, value);
}
#endregion
#region Timer
System.Threading.Timer _runTimer = null;
System.Threading.Timer _idleTimer = null;
System.Threading.Timer _downTimer = null;
System.Threading.Timer _checkIdleTimer = null;
//System.Threading.Timer _calculateTimer = null;
private RunState? currentState = null;
public RunState? CurrentState
{
get => currentState;
set
{
if (value != null)
{
if (value.Value == RunState.Running)
{
_checkIdleTimer?.Change(10 * 1000, -1);
}
if (currentState != value.Value)
{
switch (currentState)
{
case RunState.Idle:
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, false);
break;
case RunState.Down:
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, false);
break;
}
switch (value.Value)
{
case RunState.Stop:
_runTimer?.Change(-1, -1);
_idleTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
break;
case RunState.Running:
_idleTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
_runTimer?.Change(0, 1000);
break;
case RunState.Idle:
_runTimer?.Change(-1, -1);
_downTimer?.Change(-1, -1);
_idleTimer?.Change(0, 1000);
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, true);
break;
case RunState.Down:
_idleTimer?.Change(-1, -1);
_runTimer?.Change(-1, -1);
_downTimer?.Change(0, 1000);
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, true);
break;
}
currentState = value;
}
}
}
}
private void CheckIdleTimeStart(object state)
{
if (CurrentState == RunState.Running)
{
RunTime = RunTime.Add(new TimeSpan(0, 0, 0 - 10));
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 10));
CurrentState = RunState.Idle;
}
}
public void InitialOEEStatistic()
{
InitialStatisticTimers();
ResetOEETimeDistribute();
ResetProductSummaries();
}
public void ResetProductSummaries()
{
ProductSummaries = new List<ProductSummary>();
}
private void InitialStatisticTimers()
{
if (_checkIdleTimer == null)
{
_checkIdleTimer = new Timer(new TimerCallback(CheckIdleTimeStart), null, -1, -1);
}
if (_runTimer == null)
{
_runTimer = new System.Threading.Timer(RunTimerCallBack, null, -1, -1);
}
if (_idleTimer == null)
{
_idleTimer = new System.Threading.Timer(IdleTimerCallBack, null, -1, -1);
}
if (_downTimer == null)
{
_downTimer = new System.Threading.Timer(DownTimerCallBack, null, -1, -1);
}
StartTime = DateTime.Now;
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
CurrentState = RunState.Running;
}
private void DownTimerCallBack(object state)
{
DownTime = DownTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void IdleTimerCallBack(object state)
{
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void RunTimerCallBack(object state)
{
RunTime = RunTime.Add(new TimeSpan(0, 0, 1));
GetTotalTime();
}
private void GetTotalTime()
{
TotalTime = RunTime + IdleTime + DownTime;
}
public void ResetOEETimeDistribute()
{
StartTime = DateTime.Now;
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
ProductNum_Total = ProductNum_OK = 0;
}
public void CloseStatisticTimers()
{
CloseTimer(ref _checkIdleTimer);
CloseTimer(ref _runTimer);
CloseTimer(ref _idleTimer);
CloseTimer(ref _downTimer);
CurrentState = RunState.Stop;
}
private void CloseTimer(ref System.Threading.Timer timer)
{
timer?.Change(-1, -1);
timer?.Dispose();
timer = null;
}
#endregion
#region CameraSum
private void InitialCameraSumsView()
{
dgvProductNums.AutoGenerateColumns = false;
dgvProductNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
dgvProductNums.DataSource = null;
dgvProductNums.DataSource = ProductSummaries;
dgvCamreaNums.Columns.Clear();
// 添加 CCD 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "CCD",
DataPropertyName = "CameraName"
});
// 添加 触发数 列
var TiggerCountColumn = new DataGridViewTextBoxColumn
{
HeaderText = "触发数",
DataPropertyName = "TiggerCount"
};
dgvCamreaNums.Columns.Add(TiggerCountColumn);
// 添加 合格 列
var okColumn = new DataGridViewTextBoxColumn
{
HeaderText = "合格",
DataPropertyName = "OKCount"
};
okColumn.DefaultCellStyle.ForeColor = Color.Green; // 设置背景为绿色
dgvCamreaNums.Columns.Add(okColumn);
// 添加 不合格 列
var ngColumn = new DataGridViewTextBoxColumn
{
HeaderText = "不合格",
DataPropertyName = "NGCount"
};
ngColumn.DefaultCellStyle.ForeColor = Color.LightCoral; // 设置背景为红色
dgvCamreaNums.Columns.Add(ngColumn);
// 添加 总数 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "总数",
DataPropertyName = "TotalCount"
});
// 添加 良率 列
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = "良率",
DataPropertyName = "YieldStr"
});
dgvCamreaNums.AutoGenerateColumns = false;
dgvCamreaNums.DataSource = new BindingList<CameraSummary>(CameraSummaries);
}
#endregion
/// <summary> /// <summary>
/// 窗体对象实例 /// 窗体对象实例
@ -353,22 +677,22 @@ namespace DHSoftware
if (cameraBase.CamType == EnumCamType.Do3think) if (cameraBase.CamType == EnumCamType.Do3think)
{ {
Do3ThinkCamera cam =new Do3ThinkCamera(); Do3ThinkCamera cam = new Do3ThinkCamera();
cam.IsSavePicEnabled = cameraBase.IsSavePicEnabled; cam.IsSavePicEnabled = cameraBase.IsSavePicEnabled;
cam.CameraName = cameraBase.CameraName; cam.CameraName = cameraBase.CameraName;
cam.CameraIP = cameraBase.CameraIP; cam.CameraIP = cameraBase.CameraIP;
cam.IsEnabled = cameraBase.IsEnabled; cam.IsEnabled = cameraBase.IsEnabled;
cam.ImageSaveDirectory = "D://Cam1//"; cam.ImageSaveDirectory = Path.Combine("D://Projects", cameraBase.CameraName);
Cameras.Add(cam); Cameras.Add(cam);
if(cameraBase.IsEnabled) if (cameraBase.IsEnabled)
{ {
cam.OnLog -= _visionEngine_OnLog; cam.OnLog -= _visionEngine_OnLog;
cam.OnLog += _visionEngine_OnLog; cam.OnLog += _visionEngine_OnLog;
cam.CameraConnect(); cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput; cam.OnHImageOutput += OnCameraHImageOutput;
} }
} }
else if (cameraBase.CamType == EnumCamType.hik) else if (cameraBase.CamType == EnumCamType.hik)
{ {
@ -378,7 +702,7 @@ namespace DHSoftware
cam.IsEnabled = cameraBase.IsEnabled; cam.IsEnabled = cameraBase.IsEnabled;
HKCameras.Add(cam); HKCameras.Add(cam);
// cam.CameraConnect(); // cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput; //cam.OnHImageOutput += OnCameraHImageOutput;
} }
} }
} }
@ -424,7 +748,8 @@ namespace DHSoftware
detectionConfig.ModelHeight = detection.ModelHeight; detectionConfig.ModelHeight = detection.ModelHeight;
detectionConfig.In_lable_path = detection.In_lable_path; detectionConfig.In_lable_path = detection.In_lable_path;
detectionConfig.IsEnabled = detection.IsEnabled; detectionConfig.IsEnabled = detection.IsEnabled;
detectionConfig.ImageSaveDirectory = "D://Projects//Images";
detectionConfig.ShowLocation.X = (i + 1) % 5 + (i + 1) / 5; detectionConfig.ShowLocation.X = (i + 1) % 5 + (i + 1) / 5;
// detectionConfig.ShowLocation.X = detection.ShowLocation.X; // detectionConfig.ShowLocation.X = detection.ShowLocation.X;
detectionConfig.ShowLocation.Y = (i + 1) / 5 + 1; detectionConfig.ShowLocation.Y = (i + 1) / 5 + 1;
@ -459,6 +784,8 @@ namespace DHSoftware
// //
_visionEngine = new SimboVisionDriver(); _visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs; _visionEngine.DetectionConfigs = DetectionConfigs;
_visionEngine.LoggerHelper.LogPath = "D://PROJECTS//Logs//";
_visionEngine.LoggerHelper.LogPrefix = "Vision";
_visionEngine.OnLog += _visionEngine_OnLog; _visionEngine.OnLog += _visionEngine_OnLog;
//初始化模型 加载模型 //初始化模型 加载模型
_visionEngine.Init(); _visionEngine.Init();
@ -471,13 +798,14 @@ namespace DHSoftware
private void _visionEngine_OnLog(LogMsg msg) private void _visionEngine_OnLog(LogMsg msg)
{ {
OnLog?.Invoke(msg); //OnLog?.Invoke(msg);
LogDisplay(msg); LogDisplay(msg);
} }
private void LogDisplay(LogMsg msg) private void LogDisplay(LogMsg msg)
{ {
frmLog?.LogDisplay(msg); //frmLog?.LogDisplay(msg);
frmLog?.AddLog(msg);
} }
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper(); public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
public virtual void LogAsync(LogMsg msg) public virtual void LogAsync(LogMsg msg)
@ -496,30 +824,92 @@ namespace DHSoftware
OnLog?.Invoke(msg); OnLog?.Invoke(msg);
//if (IConfig?.IsLogEnabled ?? true) //if (IConfig?.IsLogEnabled ?? true)
//{ //{
LoggerHelper.LogAsync(msg); LoggerHelper.LogAsync(msg);
//} //}
} }
public virtual void LogAsync(DateTime dt, LogLevel logLevel, string msg) public virtual void LogAsync(DateTime dt, LogLevel logLevel, string msg)
{ {
LogAsync(new LogMsg(dt, logLevel, msg)); LogAsync(new LogMsg(dt, logLevel, msg));
} }
System.Windows.Forms.Timer _refreshUITimer = new System.Windows.Forms.Timer();
private void BindEventHandler() private void BindEventHandler()
{ {
btnAddProject.Click += BtnAddProject_Click; btnAddProject.Click += BtnAddProject_Click;
btnDeleteProject.Click += BtnDeleteProject_Click; btnDeleteProject.Click += BtnDeleteProject_Click;
btnLoadProject.Click += BtnLoadProject_Click; btnLoadProject.Click += BtnLoadProject_Click;
LoggerHelper.LogPath = "D://"; LoggerHelper.LogPath = "D://PROJECTS//Logs//";
LoggerHelper.LogPrefix = "Process"; LoggerHelper.LogPrefix = "Process";
OnLog -= LogDisplay; OnLog -= LogDisplay;
OnLog += LogDisplay; OnLog += LogDisplay;
OnUpdateCamResult -= UpdateCamResult;
OnUpdateCamResult += UpdateCamResult;
OnUpdateResult -= UpdateResult;
OnUpdateResult += UpdateResult;
Load += (s, e) =>
{
_refreshUITimer.Interval = 1000;
_refreshUITimer.Tick += _refreshUITimer_Tick;
_refreshUITimer.Enabled = true;
};
lbInBackend.Click += LbInBackend_Click; lbInBackend.Click += LbInBackend_Click;
} }
private void LbInBackend_Click(object? sender, EventArgs e) private void LbInBackend_Click(object? sender, EventArgs e)
{ {
DH.RBAC.RBACWindow.Instance.Show(); DH.RBAC.RBACWindow.Instance.Show();
}
private void _refreshUITimer_Tick(object sender, EventArgs e)
{
_refreshUITimer.Enabled = false;
if (this != null)
{
lblStartTime.Text = StartTime == null ? "" : StartTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
lblTotalTime.Text = TotalTime.ToString(); // 运行时间
// lblRunTime.Text = RunTime.ToString(); // 有效时间
// lblIdleTime.Text = ProcessControl.IdleTime.ToString(); // 空闲时间
// lblDownTime.Text = ProcessControl.DownTime.ToString(); // 宕机时间
lblOEE_Total.Text = ProductNum_Total.ToString();
// lblOEE_OK.Text = ProcessControl.ProductNum_OK.ToString();
}
_refreshUITimer.Enabled = true;
}
private void UpdateCamResult(DateTime updateTime, object objData, string customMessage)
{
this.Invoke(new Action(() =>
{
BindingList<CameraSummary> cameraSummaries = new BindingList<CameraSummary>(CameraSummaries);
dgvCamreaNums.DataSource = cameraSummaries;
}));
}
private void UpdateResult(DateTime updateTime, object objData, string result)
{
this.Invoke(new Action(() =>
{
dgvProductNums.DataSource = new BindingList<ProductSummary>(ProductSummaries);
//if (dgvProductNums.Rows.Count > 0)
//{
// dgvProductNums.Height = dgvProductNums.Rows[0].Height * dgvProductNums.Rows.Count + 15;
//}
//else
//{
// dgvProductNums.Height = 35;
//}
//lblOEE_Rate.Text = ProcessControl.OEE.ToString("f2") + " %";
lblUPH.Text = UPM.ToString();
}));
} }
private void BtnDeleteProject_Click(object? sender, EventArgs e) private void BtnDeleteProject_Click(object? sender, EventArgs e)
@ -716,7 +1106,7 @@ namespace DHSoftware
} }
segmented1.SelectIndex = -1; segmented1.SelectIndex = -1;
} }
public string BatchNO { get; set; }
public bool CurrentMachine = false; public bool CurrentMachine = false;
public volatile int ProductNum_Total = 0; public volatile int ProductNum_Total = 0;
public volatile int ProductNum_OK = 0; public volatile int ProductNum_OK = 0;
@ -729,9 +1119,15 @@ namespace DHSoftware
private Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>(); private Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>();
public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>(); public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>();
public DateTime ProcessstartTime; public DateTime ProcessstartTime;
private void PrepareBatchNO()
{
BatchNO = string.IsNullOrEmpty(BatchNO) ? SystemModel.CurrentScheme + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") : BatchNO;
// DataSavePath = string.IsNullOrEmpty(DataSavePath) ? Path.Combine(X018PLCConfig.ImgDirectory, DateTime.Now.ToString("yyyyMMdd"), BatchNO) : DataSavePath;
}
private void HandleStartButton() private void HandleStartButton()
{ {
InitialCameraSumsView();
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候..."); LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
StartProcess(); StartProcess();
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!"); LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
@ -741,11 +1137,16 @@ namespace DHSoftware
private void StartProcess() private void StartProcess()
{ {
BatchNO = textBoxBatchNO.Text;
textBoxBatchNO.ReadOnly = true;
btnCreateBatchNO.Enabled = false;
PrepareBatchNO();//生成批次号
ProcessstartTime = DateTime.Now; ProcessstartTime = DateTime.Now;
lblstarttime2.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss"); lblStartTime.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
//计数清零 //计数清零
PieceCount = 0; PieceCount = 0;
//CameraSummaries.Clear();
if (PLC?.Enable == true) if (PLC?.Enable == true)
{ {
@ -844,11 +1245,11 @@ namespace DHSoftware
// ProductBaseCount = _MGSCameraList.Count; // ProductBaseCount = _MGSCameraList.Count;
//流程执行时PLC //流程执行时PLC
PLC.StartProcess(); PLC.StartProcess();
InitialOEEStatistic();
@ -889,7 +1290,7 @@ namespace DHSoftware
LogAsync(DateTime.Now, LogLevel.Action, $">> 轴{axisIndex}新产品{pieceNumber}加入队列{index}----板卡计数{PieceCount}"); LogAsync(DateTime.Now, LogLevel.Action, $">> 轴{axisIndex}新产品{pieceNumber}加入队列{index}----板卡计数{PieceCount}");
} }
DateTime dtNow = DateTime.Now; DateTime dtNow = DateTime.Now;
UpdateCT(null, (float)(dtNow - _ctTime).TotalSeconds); UpdateCT(null, (float)(dtNow - _ctTime).TotalSeconds);
_ctTime = dtNow; _ctTime = dtNow;
@ -909,7 +1310,7 @@ namespace DHSoftware
/// <param name="dt"></param> /// <param name="dt"></param>
/// <param name="camera"></param> /// <param name="camera"></param>
/// <param name="imageSet"></param> /// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet) private void OnCameraHImageOutput(DateTime dt, CameraBase camera, MatSet imageSet)
{ {
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase)) //if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{ //{
@ -925,7 +1326,7 @@ namespace DHSoftware
Task.Run(async () => Task.Run(async () =>
{ {
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题 //using (Mat localImageSet = imageSet._mat.Clone()) // 复制 Mat 避免并发问题
{ {
// imageSet?.Dispose(); // imageSet?.Dispose();
// 拍照计数与物件编号一致,查找对应的产品 // 拍照计数与物件编号一致,查找对应的产品
@ -947,7 +1348,7 @@ namespace DHSoftware
} }
else else
{ {
Thread.Sleep(20); Thread.Sleep(20);
//await Task.Delay(20); //await Task.Delay(20);
} }
retryTimes--; retryTimes--;
@ -964,20 +1365,20 @@ namespace DHSoftware
} }
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}"); //LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose(); imageSet.Dispose();
return; return;
} }
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}"); LogAsync(DateTime.Now, LogLevel.Information, $"{camera.CameraName} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName)) if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{ {
localImageSet.Dispose(); imageSet.Dispose();
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber}但是没有推理1");
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber}但是没有推理1");
return; return;
} }
@ -990,19 +1391,37 @@ namespace DHSoftware
for (int i = 0; i < detectionDict.Count; i++) for (int i = 0; i < detectionDict.Count; i++)
{ {
string detectionId = detectionDict[i]; string detectionId = detectionDict[i];
var tmpImgSet = camera.CopyImageSet(imageSet as MatSet);
//imageSet
// using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
DetectStationResult temp1 = _visionEngine.RunInference(tmpImgSet, detectionId);
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
resultStates.Add(temp1.ResultState);
product.ResultCollection.Add(temp1);
if (temp1 != null)
{ {
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId); UpdateResultTigger(dt, temp1.DetectName, (int)productNumber);
//if (tmpModuleData.CamIDs.Count == 1)
//{
// UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
//}
//else //合图的合成一列
//{
// UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
//}
if (product.ResultCollection.Count != 0)
UpdateResultoverride(dt, temp1.DetectName, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
resultStates.Add(temp1.ResultState);
product.ResultCollection.Add(temp1);
} }
} }
stopwatch.Stop(); stopwatch.Stop();
product.InferenceOne(); product.InferenceOne();
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}"); // LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
@ -1011,24 +1430,32 @@ namespace DHSoftware
{ {
return; return;
} }
UpdateResult(DateTime.Now, null, product.ProductResult.GetEnumDescription());
#region 6. #region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK) product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG ? ResultState.B_NG
: ResultState.OK; : ResultState.OK;
//if (product.ProductResult == ResultState.OK)
//{
// PLC.Blowing(productNumber, 1);
//}
//else
//{
// PLC.Blowing(productNumber, 2);
//}
product.ProductLabelCategory = product.ProductResult.GetEnumDescription(); product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription(); product.ProductLabel = product.ProductResult.GetEnumDescription();
UpdateResultPro(DateTime.Now, null, product.ProductResult.GetEnumDescription());
LogAsync(DateTime.Now, LogLevel.Information, $"产品{product.PieceNumber}获取结果:{product.ProductResult} {(product.IsA2B ? "IsA2B" : "")}");
if (product.ProductResult == ResultState.OK)
{
PLC.Blowing(productNumber, 1);
LogAsync(DateTime.Now, LogLevel.Action, $"产品{product.PieceNumber}PLC,OK吹气");
}
else
{
PLC.Blowing(productNumber, 2);
LogAsync(DateTime.Now, LogLevel.Action, $"产品{product.PieceNumber}PLC,NG吹气");
}
#endregion 6. #endregion 6.
@ -1052,12 +1479,12 @@ namespace DHSoftware
$"当前队列产品数量:{tmpDic.Count}"; $"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate () this.BeginInvoke(new MethodInvoker(delegate ()
{ {
// int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y; // int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
// richTextBox1.AppendText(logStr); // richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置 // 设置回原来的滚动位置
// richTextBox1.SelectionStart = richTextBox1.TextLength; // richTextBox1.SelectionStart = richTextBox1.TextLength;
//richTextBox1.ScrollToCaret(); //richTextBox1.ScrollToCaret();
})); }));
} }
@ -1072,18 +1499,15 @@ namespace DHSoftware
{ {
//int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y; //int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
// richTextBox1.AppendText(logStr); // richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置 // 设置回原来的滚动位置
// richTextBox1.SelectionStart = richTextBox1.TextLength; // richTextBox1.SelectionStart = richTextBox1.TextLength;
//richTextBox1.ScrollToCaret(); //richTextBox1.ScrollToCaret();
})); }));
//重新生成实例 销毁之前的实例 //重新生成实例 销毁之前的实例
var saveData = temp.GetProductData(); var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
} }
catch (Exception) { } catch (Exception) { }
finally finally
@ -1105,46 +1529,193 @@ namespace DHSoftware
} }
}); });
} }
public virtual void AddOKProduct(string resultStr)
public async Task UpdateResult(DateTime dt, object objData, string resultStr)
{ {
// CurrentState = RunState.Running; if (resultStr.ToLower() == "ok")
{
ProductNum_OK++;
}
}
public async Task UpdateResultTigger(DateTime dt, string objData, int _cameraDictCount)
{
CurrentState = RunState.Running;
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
var cameraName = objData; // 假设 CameraBase 有 Name 属性
if (string.IsNullOrEmpty(cameraName))
{
throw new ArgumentException("相机名称不能为空");
}
lock (_cameraSummaryLock)
{
// 查找或添加相机统计项
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == cameraName)
?? new CameraSummary { CameraName = cameraName };
if (!CameraSummaries.Contains(summary))
{
CameraSummaries.Add(summary);
}
summary.TiggerCount = _cameraDictCount;
}
await Task.Run(() =>
{
OnUpdateCamResult?.Invoke(dt, objData, "");
});
}
public async Task UpdateResultoverride(DateTime dt, string objData, List<ResultState> resultStr, double total, int _cameraDictCount)
{
// CurrentState = RunState.Running;
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
var cameraName = objData; // 假设 CameraBase 有 Name 属性
if (string.IsNullOrEmpty(cameraName))
{
throw new ArgumentException("相机名称不能为空");
}
lock (_cameraSummaryLock)
{
// 查找或添加相机统计项
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == cameraName)
?? new CameraSummary { CameraName = cameraName };
if (!CameraSummaries.Contains(summary))
{
CameraSummaries.Add(summary);
}
if (resultStr.Any(u => u.ToString().ToLower() == "ok"))
{
summary.OKCount++;
}
else /*if (resultStr.Equals("TBD", StringComparison.OrdinalIgnoreCase))*/
{
summary.NGCount++;
}
}
await Task.Run(() =>
{
OnUpdateCamResult?.Invoke(dt, objData, "");
});
}
public async Task UpdateResultPro(DateTime dt, object objData, string resultStr)
{
CurrentState = RunState.Running;
ProductNum_Total++; ProductNum_Total++;
//AddOKProduct(resultStr); AddOKProduct(resultStr);
lock (_productSummaryLock)
{
var product = ProductSummaries.FirstOrDefault(u => u.ResultDesc == resultStr);
if (product != null)
{
product.ProductAmount++;
}
else
{
product = new ProductSummary();
product.ResultDesc = resultStr;
product.ProductAmount = 1;
ProductSummaries.Add(product);
}
int totalNum = ProductSummaries.Sum(p => p.ProductAmount);
ProductSummaries.ForEach(p => p.PercentStr = ((double)p.ProductAmount * 100.0 / totalNum).ToString("f2") + " %");
}
CalculateOEE(); CalculateOEE();
await Task.Run(() =>
{
OnUpdateResult?.Invoke(dt, objData, resultStr);
});
lock (_cameraSummaryLock)
{
// 查找或添加相机统计项
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == "合计")
?? new CameraSummary { CameraName = "合计" };
summary.OKCount = ProductNum_OK;
summary.NGCount = ProductNum_Total - ProductNum_OK;
if (!CameraSummaries.Contains(summary))
{
CameraSummaries.Add(summary);
}
}
await Task.Run(() =>
{
OnUpdateCamResult?.Invoke(dt, objData, "合计");
});
} }
private void HandleStopButton() private void HandleStopButton()
{ {
// Cameras.Clear(); textBoxBatchNO.ReadOnly = false;
// Dectection.Clear(); btnCreateBatchNO.Enabled = true;
// Cameras.Clear();
// Dectection.Clear();
// Add the code for the "停止" button click here // Add the code for the "停止" button click here
PLC.TurnStart(false); PLC.TurnStart(false);
CurrentMachine = true; CurrentMachine = true;
//sLDMotion.Stop(); //sLDMotion.Stop();
} }
public int UPH = 0;
public void CalculateOEE() public void CalculateOEE()
{ {
TimeSpan timeSpan = DateTime.Now - ProcessstartTime; if (TotalTime.TotalHours == 0)
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
//UPM = (int)UPH / 60;
this.BeginInvoke(new MethodInvoker(delegate ()
{ {
lblNowtime2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); UPH = 0;
lblUPH2.Text = UPH.ToString(); UPM = 0;
lblNum2.Text = ProductNum_Total.ToString(); }
labuph.Text = UPH.ToString(); else
})); {
UPH = (int)(ProductNum_Total / RunTime.TotalHours) + 100;
UPM = (int)UPH / 60;
}
//TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
//UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
////UPM = (int)UPH / 60;
//this.BeginInvoke(new MethodInvoker(delegate ()
//{
// lblNowtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// lblUPH.Text = UPH.ToString();
// lblNum.Text = ProductNum_Total.ToString();
//}));
} }
private void HandleResetButton() private void HandleResetButton()
@ -1167,18 +1738,9 @@ namespace DHSoftware
LoginWindow.Instance.Show(); LoginWindow.Instance.Show();
} }
private void splitter1_SplitterMoved(object sender, SplitterEventArgs e) private void btnCreateBatchNO_Click(object sender, EventArgs e)
{ {
} textBoxBatchNO.Text = SystemModel.CurrentScheme + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
{
} }
} }
} }

View File

@ -117,34 +117,34 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="segmentedItem1.IconActiveSvg" xml:space="preserve"> <data name="segmentedItem6.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/&gt;&lt;path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/&gt;&lt;path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem1.IconSvg" xml:space="preserve"> <data name="segmentedItem6.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/&gt;&lt;path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/&gt;&lt;path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem2.IconActiveSvg" xml:space="preserve"> <data name="segmentedItem7.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem2.IconSvg" xml:space="preserve"> <data name="segmentedItem7.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem3.IconActiveSvg" xml:space="preserve"> <data name="segmentedItem8.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem3.IconSvg" xml:space="preserve"> <data name="segmentedItem8.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem4.IconActiveSvg" xml:space="preserve"> <data name="segmentedItem9.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem4.IconSvg" xml:space="preserve"> <data name="segmentedItem9.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem5.IconActiveSvg" xml:space="preserve"> <data name="segmentedItem10.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/&gt;&lt;path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/&gt;&lt;path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<data name="segmentedItem5.IconSvg" xml:space="preserve"> <data name="segmentedItem10.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/&gt;&lt;path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value> <value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/&gt;&lt;path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/&gt;&lt;path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/&gt;&lt;/svg&gt;</value>
</data> </data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

View File

@ -87,7 +87,7 @@
this.tsmiClearLog2.Name = "tsmiClearLog2"; this.tsmiClearLog2.Name = "tsmiClearLog2";
this.tsmiClearLog2.Size = new System.Drawing.Size(68, 21); this.tsmiClearLog2.Size = new System.Drawing.Size(68, 21);
this.tsmiClearLog2.Text = "清空日志"; this.tsmiClearLog2.Text = "清空日志";
this.tsmiClearLog2.Click += new System.EventHandler(this.tsmiClearLog2_Click); // this.tsmiClearLog2.Click += new System.EventHandler(this.tsmiClearLog2_Click);
// //
// lvLog // lvLog
// //

View File

@ -11,226 +11,534 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static DH.Commons.Enums.EnumHelper; using static DH.Commons.Enums.EnumHelper;
using DH.Commons.Enums; using DH.Commons.Enums;
using System.ComponentModel;
using System.Reflection;
namespace DHSoftware.Views namespace DHSoftware.Views
{ {
public partial class FrmLog : UserControl public partial class FrmLog : UserControl
{ {
#region Win32 API双缓冲处理
private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1036;
private const int LVS_EX_DOUBLEBUFFER = 0x00010000;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
#endregion
#region
private const string SOURCE_PROCESS = "流程";
private const int LOG_NUM_LIMIT = 2000;
private const int BATCH_SIZE = 50;
private const int PROCESS_INTERVAL = 100;
private const int FIRST_COL_WIDTH = 120;
#endregion
#region
private readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
private List<LogMsg> _logBuffer = new List<LogMsg>();
private List<LogLevel> _showLevels = new List<LogLevel>();
private List<string> _showSources = new List<string>();
private Task _logTask;
private static readonly object _logLock = new object();
#endregion
public FrmLog() public FrmLog()
{ {
InitializeComponent(); InitializeComponent();
InitializeCustomComponents();
lvLog.ShowItemToolTips = true;
this.Load += (s, e) =>
{
_showLevels.Clear();
tsmiLogLevels.DropDownItems.Clear();
JsonConvert.DeserializeObject<List<dynamic>>(JsonConvert.SerializeObject(EnumHelper.GetEnumListByType(typeof(LogLevel)))).ForEach(d =>
{
LogLevel lvl = (LogLevel)((int)d.Value);
ToolStripMenuItem item = new ToolStripMenuItem(d.Desc.ToString());
item.CheckOnClick = true;
item.Checked = true;
item.Tag = lvl;
item.CheckedChanged += LevelItem_CheckedChanged;
item.BackColor = lvl.GetEnumSelectedColor();
item.ForeColor = lvl.GetEnumSelectedFontColor();
tsmiLogLevels.DropDownItems.Add(item);
_showLevels.Add(lvl);
});
};
} }
//public override void OnProcessUpdated() private void InitializeCustomComponents()
//{ {
// 启用双缓冲
SendMessage(lvLog.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
// Invoke(new Action(() => lvLog.ShowItemToolTips = true;
// { lvLog.FullRowSelect = true;
// _showDevice.Clear(); lvLog.View = View.Details;
// tsmiLogSources.DropDownItems.Clear(); // 启用自定义绘制
// ToolStripMenuItem processItem = new ToolStripMenuItem(SOURCE_PROCESS); //lvLog.OwnerDraw = true;
// processItem.CheckOnClick = true; //lvLog.DrawColumnHeader += LvLog_DrawColumnHeader;
// processItem.Checked = true; //lvLog.DrawSubItem += LvLog_DrawSubItem;
// processItem.CheckedChanged += SourceItem_CheckedChanged; //lvLog.DrawItem += LvLog_DrawItem;
// tsmiLogSources.DropDownItems.Add(processItem);
// _showDevice.Add(SOURCE_PROCESS);
// Process.DeviceCollection.ForEach(d => // 初始化列头
// { lvLog.Columns.Add("时间", FIRST_COL_WIDTH);
// ToolStripMenuItem item = new ToolStripMenuItem(d.Name); lvLog.Columns.Add("来源", 150);
// item.CheckOnClick = true; lvLog.Columns.Add("内容", 400);
// item.Checked = true;
// item.CheckedChanged += SourceItem_CheckedChanged;
// tsmiLogSources.DropDownItems.Add(item);
// _showDevice.Add(d.Name);
// });
// }));
//}
private void LevelItem_CheckedChanged(object sender, EventArgs e) InitializeLevelFilter();
StartProcessingTask();
}
private void InitializeLevelFilter()
{ {
_showLevels.Clear(); _showLevels.Clear();
foreach (ToolStripMenuItem item in tsmiLogLevels.DropDownItems) tsmiLogLevels.DropDownItems.Clear();
foreach (LogLevel level in Enum.GetValues(typeof(LogLevel)))
{ {
if (item.Checked) var item = new ToolStripMenuItem(level.GetEnumDescription())
{ {
LogLevel lv = (LogLevel)Convert.ToInt32(item.Tag); CheckOnClick = true,
_showLevels.Add(lv); Checked = true,
Tag = level,
BackColor = level.GetEnumSelectedColor(),
ForeColor = level.GetEnumSelectedFontColor()
};
item.CheckedChanged += LevelItem_CheckedChanged;
tsmiLogLevels.DropDownItems.Add(item);
_showLevels.Add(level);
}
}
#region
private void LvLog_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.DrawDefault = true;
}
private void LvLog_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
var item = e.Item;
var log = item.Tag as LogMsg;
// 设置背景色
e.Graphics.FillRectangle(new SolidBrush(log.LogLevel.GetEnumSelectedColor()), e.Bounds);
// 设置文字颜色
TextRenderer.DrawText(e.Graphics, e.SubItem.Text, lvLog.Font,
e.Bounds, log.LogLevel.GetEnumSelectedFontColor(), TextFormatFlags.Left);
}
//private ListViewItem CreateLogItem(LogMsg log)
//{
// var item = new ListViewItem(log.LogTime.ToString("HH:mm:ss.fff"));
// item.SubItems.Add(FormatSource(log));
// item.SubItems.Add(log.Msg);
// item.Tag = log; // 重要将日志对象绑定到Tag
// return item;
//}
private void LvLog_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawDefault = false; // 禁用默认绘制
}
#endregion
private void StartProcessingTask()
{
lock (_logLock)
{
if (_logTask == null || _logTask.IsCompleted)
{
_logTask = Task.Run(ProcessLogs);
} }
} }
}
private async Task ProcessLogs()
{
while (!IsDisposed)
{
try
{
await Task.Delay(PROCESS_INTERVAL);
ProcessBatch(BATCH_SIZE);
}
catch (Exception ex)
{
DebugWrite($"日志处理异常: {ex.Message}");
}
}
}
private void ProcessBatch(int batchSize)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => ProcessBatch(batchSize)));
return;
}
lvLog.BeginUpdate();
try
{
var items = new List<ListViewItem>();
int processed = 0;
while (processed < batchSize && _logQueue.TryDequeue(out var log))
{
_logBuffer.Add(log);
if (ShouldShow(log))
{
items.Add(CreateLogItem(log));
processed++;
}
}
if (items.Count > 0)
{
lvLog.Items.AddRange(items.ToArray());
MaintainBuffer();
AutoScrollIfNeeded();
}
}
finally
{
lvLog.EndUpdate();
UpdateLayout();
}
}
private bool ShouldShow(LogMsg log)
{
return _showLevels.Contains(log.LogLevel) &&
(_showSources.Count == 0 ||
(string.IsNullOrEmpty(log.MsgSource) ?
_showSources.Contains(SOURCE_PROCESS) :
_showSources.Contains(log.MsgSource)));
}
private ListViewItem CreateLogItem(LogMsg log)
{
var item = new ListViewItem(log.LogTime.ToString("HH:mm:ss.fff"));
item.SubItems.Add(FormatSource(log));
item.SubItems.Add(log.Msg);
item.ToolTipText = log.Msg;
item.BackColor = log.LogLevel.GetEnumSelectedColor();
item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
return item;
}
private string FormatSource(LogMsg log)
{
return string.IsNullOrEmpty(log.MsgSource) ?
SOURCE_PROCESS :
$"{log.MsgSource}[{log.ThreadId}]";
}
private void MaintainBuffer()
{
if (_logBuffer.Count > LOG_NUM_LIMIT * 2)
{
_logBuffer = _logBuffer
.Skip(_logBuffer.Count - LOG_NUM_LIMIT)
.ToList();
RefreshLogs();
}
}
public void AddLog(LogMsg log)
{
_logQueue.Enqueue(log);
}
private void RefreshLogs()
{
lvLog.BeginUpdate();
try
{
lvLog.Items.Clear();
var items = _logBuffer
.Where(ShouldShow)
.Select(CreateLogItem);
lvLog.Items.AddRange(items.ToArray());
}
finally
{
lvLog.EndUpdate();
UpdateLayout();
}
}
private void AutoScrollIfNeeded()
{
if (lvLog.Items.Count > 0 /*&& chkAutoScroll.Checked*/)
{
lvLog.EnsureVisible(lvLog.Items.Count - 1);
}
}
private void UpdateLayout()
{
if (lvLog.Columns.Count < 3) return;
// 动态调整列宽
lvLog.Columns[0].Width = FIRST_COL_WIDTH;
lvLog.Columns[1].Width = lvLog.Width > 600 ? 150 : 0;
lvLog.Columns[2].Width = lvLog.ClientSize.Width -
lvLog.Columns[0].Width -
lvLog.Columns[1].Width -
SystemInformation.VerticalScrollBarWidth;
}
#region
private void LevelItem_CheckedChanged(object sender, EventArgs e)
{
_showLevels = tsmiLogLevels.DropDownItems
.Cast<ToolStripMenuItem>()
.Where(i => i.Checked)
.Select(i => (LogLevel)i.Tag)
.ToList();
RefreshLogs(); RefreshLogs();
} }
private void SourceItem_CheckedChanged(object sender, EventArgs e) private void SourceItem_CheckedChanged(object sender, EventArgs e)
{ {
_showDevice.Clear(); _showSources = tsmiLogSources.DropDownItems
foreach (ToolStripMenuItem item in tsmiLogSources.DropDownItems) .Cast<ToolStripMenuItem>()
{ .Where(i => i.Checked)
if (item.Checked) .Select(i => i.Text)
{ .ToList();
_showDevice.Add(item.Text);
}
}
RefreshLogs(); RefreshLogs();
} }
//public TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
Task _logTask = null;
static readonly object _logLock = new object();
List<LogMsg> _logBuffer = new List<LogMsg>();
List<LogLevel> _showLevels = new List<LogLevel>();
List<string> _showDevice = new List<string>();
const string SOURCE_PROCESS = "流程";
const int LOG_NUM_LIMIT = 20;
public void LogDisplay(LogMsg msg)
{
_logQueue.Enqueue(msg);
lock (_logLock)
{
if (_logTask == null)
{
_logTask = Task.Run(async () =>
{
while (true)
{
try
{
Invoke(new Action(() =>
{
bool isNeedScroll = false;
while (_logQueue.TryDequeue(out LogMsg log))
{
_logBuffer.Add(log);
if (_showLevels.Contains(log.LogLevel) && (_showDevice.Count == 0 || (string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
{
isNeedScroll = true;
ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
item.SubItems.Add(log.Msg);
item.ToolTipText = log.Msg;
item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
item.BackColor = log.LogLevel.GetEnumSelectedColor();
lvLog.Items.Add(item);
}
}
if (_logBuffer.Count > LOG_NUM_LIMIT * 2)
{
_logBuffer = _logBuffer.Skip(_logBuffer.Count - LOG_NUM_LIMIT).ToList();
RefreshLogs();
isNeedScroll = true;
}
if (isNeedScroll && lvLog.Items.Count > 0)
{
RefreshLvLayout();
}
}));
}
catch (Exception ex)
{
}
await Task.Delay(2000);
}
});
}
}
}
private void RefreshLogs()
{
lvLog.Items.Clear();
_logBuffer.ForEach(log =>
{
if (_showLevels.Contains(log.LogLevel) && ((string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
{
ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
item.SubItems.Add(log.Msg);
item.ToolTipText = log.Msg;
item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
item.BackColor = log.LogLevel.GetEnumSelectedColor();
lvLog.Items.Add(item);
}
});
RefreshLvLayout();
}
private void lvLog_SizeChanged(object sender, EventArgs e)
{
RefreshLvLayout();
}
int width_1stCol = 80;
public event Action<LogMsg> OnLogMsgOutput;
private void RefreshLvLayout()
{
if (lvLog.Columns.Count <= 0)
return;
lvLog.Columns[0].Width = width_1stCol;
if (lvLog.Width <= lvLog.Height)
{
lvLog.Columns[1].Width = 0;
}
else
{
lvLog.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
}
lvLog.Columns[2].Width = lvLog.Width - width_1stCol - lvLog.Columns[1].Width - 10;
if (lvLog.Items.Count > 0)
lvLog.EnsureVisible(lvLog.Items.Count - 1);
}
private void tsmiClearLog_Click(object sender, EventArgs e) private void tsmiClearLog_Click(object sender, EventArgs e)
{ {
lvLog.Items.Clear(); lvLog.Items.Clear();
_logBuffer.Clear();
} }
private void tsmiClearLog2_Click(object sender, EventArgs e) private void lvLog_SizeChanged(object sender, EventArgs e)
{ {
lvLog.Items.Clear(); UpdateLayout();
} }
#endregion
#region
private void DebugWrite(string message)
{
System.Diagnostics.Debug.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] {message}");
}
#endregion
} }
//public partial class FrmLog1 : UserControl
//{
// // 添加双缓冲字段
// private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1036;
// private const int LVS_EX_DOUBLEBUFFER = 0x00010000;
// [System.Runtime.InteropServices.DllImport("user32.dll")]
// private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
// public FrmLog()
// {
// InitializeComponent();
// // 启用双缓冲
// SendMessage(lvLog.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
// lvLog.ShowItemToolTips = true;
// this.Load += (s, e) =>
// {
// _showLevels.Clear();
// tsmiLogLevels.DropDownItems.Clear();
// JsonConvert.DeserializeObject<List<dynamic>>(JsonConvert.SerializeObject(EnumHelper.GetEnumListByType(typeof(LogLevel)))).ForEach(d =>
// {
// LogLevel lvl = (LogLevel)((int)d.Value);
// ToolStripMenuItem item = new ToolStripMenuItem(d.Desc.ToString());
// item.CheckOnClick = true;
// item.Checked = true;
// item.Tag = lvl;
// item.CheckedChanged += LevelItem_CheckedChanged;
// item.BackColor = lvl.GetEnumSelectedColor();
// item.ForeColor = lvl.GetEnumSelectedFontColor();
// tsmiLogLevels.DropDownItems.Add(item);
// _showLevels.Add(lvl);
// });
// };
// }
// //public override void OnProcessUpdated()
// //{
// // Invoke(new Action(() =>
// // {
// // _showDevice.Clear();
// // tsmiLogSources.DropDownItems.Clear();
// // ToolStripMenuItem processItem = new ToolStripMenuItem(SOURCE_PROCESS);
// // processItem.CheckOnClick = true;
// // processItem.Checked = true;
// // processItem.CheckedChanged += SourceItem_CheckedChanged;
// // tsmiLogSources.DropDownItems.Add(processItem);
// // _showDevice.Add(SOURCE_PROCESS);
// // Process.DeviceCollection.ForEach(d =>
// // {
// // ToolStripMenuItem item = new ToolStripMenuItem(d.Name);
// // item.CheckOnClick = true;
// // item.Checked = true;
// // item.CheckedChanged += SourceItem_CheckedChanged;
// // tsmiLogSources.DropDownItems.Add(item);
// // _showDevice.Add(d.Name);
// // });
// // }));
// //}
// private void LevelItem_CheckedChanged(object sender, EventArgs e)
// {
// _showLevels.Clear();
// foreach (ToolStripMenuItem item in tsmiLogLevels.DropDownItems)
// {
// if (item.Checked)
// {
// LogLevel lv = (LogLevel)Convert.ToInt32(item.Tag);
// _showLevels.Add(lv);
// }
// }
// RefreshLogs();
// }
// private void SourceItem_CheckedChanged(object sender, EventArgs e)
// {
// _showDevice.Clear();
// foreach (ToolStripMenuItem item in tsmiLogSources.DropDownItems)
// {
// if (item.Checked)
// {
// _showDevice.Add(item.Text);
// }
// }
// RefreshLogs();
// }
// //public TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
// readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
// Task _logTask = null;
// static readonly object _logLock = new object();
// List<LogMsg> _logBuffer = new List<LogMsg>();
// List<LogLevel> _showLevels = new List<LogLevel>();
// List<string> _showDevice = new List<string>();
// const string SOURCE_PROCESS = "流程";
// const int LOG_NUM_LIMIT = 20;
// public void LogDisplay(LogMsg msg)
// {
// _logQueue.Enqueue(msg);
// lock (_logLock)
// {
// if (_logTask == null)
// {
// _logTask = Task.Run(async () =>
// {
// while (true)
// {
// try
// {
// Invoke(new Action(() =>
// {
// bool isNeedScroll = false;
// while (_logQueue.TryDequeue(out LogMsg log))
// {
// _logBuffer.Add(log);
// if (_showLevels.Contains(log.LogLevel) && (_showDevice.Count == 0 || (string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
// {
// isNeedScroll = true;
// ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
// item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
// item.SubItems.Add(log.Msg);
// item.ToolTipText = log.Msg;
// item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
// item.BackColor = log.LogLevel.GetEnumSelectedColor();
// lvLog.Items.Add(item);
// }
// }
// if (_logBuffer.Count > LOG_NUM_LIMIT * 2)
// {
// _logBuffer = _logBuffer.Skip(_logBuffer.Count - LOG_NUM_LIMIT).ToList();
// RefreshLogs();
// isNeedScroll = true;
// }
// if (isNeedScroll && lvLog.Items.Count > 0)
// {
// RefreshLvLayout();
// }
// }));
// }
// catch (Exception ex)
// {
// }
// await Task.Delay(2000);
// }
// });
// }
// }
// }
// private void RefreshLogs()
// {
// lvLog.Items.Clear();
// _logBuffer.ForEach(log =>
// {
// if (_showLevels.Contains(log.LogLevel) && ((string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
// {
// ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
// item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
// item.SubItems.Add(log.Msg);
// item.ToolTipText = log.Msg;
// item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
// item.BackColor = log.LogLevel.GetEnumSelectedColor();
// lvLog.Items.Add(item);
// }
// });
// RefreshLvLayout();
// }
// private void lvLog_SizeChanged(object sender, EventArgs e)
// {
// RefreshLvLayout();
// }
// int width_1stCol = 80;
// public event Action<LogMsg> OnLogMsgOutput;
// private void RefreshLvLayout()
// {
// if (lvLog.Columns.Count <= 0)
// return;
// lvLog.Columns[0].Width = width_1stCol;
// if (lvLog.Width <= lvLog.Height)
// {
// lvLog.Columns[1].Width = 0;
// }
// else
// {
// lvLog.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
// }
// lvLog.Columns[2].Width = lvLog.Width - width_1stCol - lvLog.Columns[1].Width - 10;
// if (lvLog.Items.Count > 0)
// lvLog.EnsureVisible(lvLog.Items.Count - 1);
// }
// private void tsmiClearLog_Click(object sender, EventArgs e)
// {
// lvLog.Items.Clear();
// }
// private void tsmiClearLog2_Click(object sender, EventArgs e)
// {
// lvLog.Items.Clear();
// }
//}
} }