|
|
@ -16,6 +16,7 @@ using MessageBox = System.Windows.MessageBox; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
using System.Windows.Media; |
|
|
|
using System.Windows.Media; |
|
|
|
|
|
|
|
using SparkClient.Model.Common; |
|
|
|
using Color = System.Windows.Media.Color; |
|
|
|
using Color = System.Windows.Media.Color; |
|
|
|
|
|
|
|
|
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
@ -113,9 +114,7 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
/// <param name="param"></param> |
|
|
|
/// <param name="param"></param> |
|
|
|
public async void StartGrading(object param) |
|
|
|
public async void StartGrading(object param) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if DEBUG |
|
|
|
|
|
|
|
DoStartGrading(param); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
LoadingDialog loading = new LoadingDialog(); |
|
|
|
LoadingDialog loading = new LoadingDialog(); |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
@ -137,7 +136,7 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
} |
|
|
|
} |
|
|
|
// 模拟耗时操作 |
|
|
|
// 模拟耗时操作 |
|
|
|
//System.Threading.Thread.Sleep(50); // 休眠50毫秒 |
|
|
|
//System.Threading.Thread.Sleep(50); // 休眠50毫秒 |
|
|
|
await Task.Delay(400); |
|
|
|
await Task.Delay(710); |
|
|
|
loading.setValue(i); |
|
|
|
loading.setValue(i); |
|
|
|
progress = i; |
|
|
|
progress = i; |
|
|
|
} |
|
|
|
} |
|
|
@ -154,38 +153,53 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化SOC客户端服务,传入SOC端的地址和认证Token |
|
|
|
|
|
|
|
_socClientService = new SOCClientService(); |
|
|
|
// 启动soc |
|
|
|
// 启动soc |
|
|
|
// socResolt = await DoSoc(); |
|
|
|
socResolt = await _socClientService.ProcessImageCollectionAsync(); |
|
|
|
// if (socResolt.Status == "P001" || socResolt.Images.Count == 0) |
|
|
|
switch (socResolt.Status) |
|
|
|
// { |
|
|
|
{ |
|
|
|
// // /*// 使用 Dispatcher 将 UI 操作调度到主线程 |
|
|
|
case StatusCodes.DeviceNotFound: |
|
|
|
// // Application.Current.Dispatcher.Invoke(() => |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("DeviceNotFound"), loading); |
|
|
|
// // { |
|
|
|
return; |
|
|
|
// // MsgDialog msgDialog = new MsgDialog(); |
|
|
|
case StatusCodes.InProgress: |
|
|
|
// // msgDialog.ShowDialog(); |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("InProgress"), loading); |
|
|
|
// // }); |
|
|
|
return; |
|
|
|
// // loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
case StatusCodes.CacheCleared: |
|
|
|
// // return;*/ |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CacheCleared"), loading); |
|
|
|
// MessageBox.Show("未找到切工仪", "错误", MessageBoxButton.OK, MessageBoxImage.Error); |
|
|
|
return; |
|
|
|
// loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
case StatusCodes.CannotSendCommand: |
|
|
|
// return; |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CannotSendCommand"), loading); |
|
|
|
// } |
|
|
|
return; |
|
|
|
|
|
|
|
case StatusCodes.MicrocontrollerTimeout: |
|
|
|
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerTimeout"), loading); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
case StatusCodes.MicrocontrollerError: |
|
|
|
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("MicrocontrollerError"), loading); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
case StatusCodes.CameraNotConnected: |
|
|
|
|
|
|
|
ShowErrorMessage(MultilingualHelper.getString("CameraNotConnected"), loading); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_algorithmServer = new AlgorithmServer(); |
|
|
|
|
|
|
|
//图片集合 |
|
|
|
|
|
|
|
string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); |
|
|
|
|
|
|
|
//string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\" ]" ; |
|
|
|
|
|
|
|
|
|
|
|
// 启动算法 |
|
|
|
// 启动算法 |
|
|
|
parameter = await DoAlgorithm(socResolt, parameter.Shape, parameter.CrownType); |
|
|
|
parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files); |
|
|
|
MessageBox.Show(parameter.error_msg); |
|
|
|
//机器号 |
|
|
|
|
|
|
|
parameter.DeviceId = socResolt.DeviceId; |
|
|
|
switch (parameter.status) |
|
|
|
switch (parameter.status) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case "P002": |
|
|
|
case StatusCodes.AlgorithmFailed: |
|
|
|
MessageBox.Show("P002:调用算法失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error); |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("AlgorithmFailed"), loading); |
|
|
|
loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
case "P003": |
|
|
|
case StatusCodes.ImageFileReadFailure: |
|
|
|
MessageBox.Show("P003:图片文件读取失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error); |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("ImageFileReadFailure"), loading); |
|
|
|
loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
case "P004": |
|
|
|
case StatusCodes.JsonParseFailure: |
|
|
|
MessageBox.Show("P004:JSON解析失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error); |
|
|
|
ShowErrorMessage(MultilingualHelper.getString("JsonParseFailure"), loading); |
|
|
|
loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
@ -222,9 +236,21 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
finally { |
|
|
|
finally { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将 UI 操作调度到主线程并显示错误信息 |
|
|
|
|
|
|
|
void ShowErrorMessage(string errorMessage, LoadingDialog loading) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Application.Current.Dispatcher.Invoke(() => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MsgDialog msgDialog = new MsgDialog(); |
|
|
|
|
|
|
|
msgDialog.ErrorMessage = errorMessage; |
|
|
|
|
|
|
|
msgDialog.ShowDialog(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
loading.Dispatcher.Invoke(() => loading.Close()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 开始检测(对soc和算法开始通讯) |
|
|
|
/// 开始检测(对soc和算法开始通讯) |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -310,67 +336,6 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 启动切工仪接口。 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <returns>图片的字节数组</returns> |
|
|
|
|
|
|
|
private async Task<SocResultEntity> DoSoc() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// 光照度 |
|
|
|
|
|
|
|
string sql = new CutterConfigEntity |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ItemName = null, |
|
|
|
|
|
|
|
Key = null, |
|
|
|
|
|
|
|
Value = null |
|
|
|
|
|
|
|
}.GenerateSelectSQL(new List<string> { "Value" }, new Dictionary<string, object> { { "Key", "light_level" } }); |
|
|
|
|
|
|
|
SqliteParameter[] sqliteParameters = [new("@Key", "light_level")]; |
|
|
|
|
|
|
|
DataTable table = DataBaseHelper.ExecuteQuery(sql,sqliteParameters); |
|
|
|
|
|
|
|
object lightLevelValue = table.Rows[0][0]; |
|
|
|
|
|
|
|
if (!int.TryParse(lightLevelValue.ToString(), out int lightLevel)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new InvalidOperationException("Light level value is not a valid integer."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 初始化SOC客户端服务,传入SOC端的地址和认证Token |
|
|
|
|
|
|
|
_socClientService = new SOCClientService(); |
|
|
|
|
|
|
|
// SOC接口 |
|
|
|
|
|
|
|
string savePath = @"d:\\diamond_images"; |
|
|
|
|
|
|
|
SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath); |
|
|
|
|
|
|
|
return resultEntity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 启动算法接口。 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="socResolt">切工仪接口返回值</param> |
|
|
|
|
|
|
|
/// <param name="crownType"></param> |
|
|
|
|
|
|
|
/// <param name="shape"></param> |
|
|
|
|
|
|
|
/// <returns>定级参数,3D模型参数</returns> |
|
|
|
|
|
|
|
private Task<AlgorithmResultEntity> DoAlgorithm(SocResultEntity socResolt, String shape, String crownType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_algorithmServer = new AlgorithmServer(); |
|
|
|
|
|
|
|
//钻石形状:shape |
|
|
|
|
|
|
|
//钻石子形状 |
|
|
|
|
|
|
|
string shape_mode = crownType; |
|
|
|
|
|
|
|
//图片根目录 |
|
|
|
|
|
|
|
string image_file_base_path = "D:\\diamond_images"; |
|
|
|
|
|
|
|
//图片集合 |
|
|
|
|
|
|
|
//string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); |
|
|
|
|
|
|
|
string image_files =$"[ \"image_0.bmp\", \"image_1.bmp\", \"image_2.bmp\", \"image_3.bmp\", \"image_4.bmp\", \"image_5.bmp\", \"image_6.bmp\", \"image_7.bmp\", \"image_8.bmp\", \"image_9.bmp\", \"image_10.bmp\", \"image_11.bmp\", \"image_12.bmp\", \"image_13.bmp\", \"image_14.bmp\", \"image_15.bmp\", \"image_16.bmp\", \"image_17.bmp\", \"image_18.bmp\", \"image_19.bmp\", \"image_20.bmp\", \"image_21.bmp\", \"image_22.bmp\", \"image_23.bmp\", \"image_24.bmp\", \"image_25.bmp\", \"image_26.bmp\", \"image_27.bmp\", \"image_28.bmp\", \"image_29.bmp\", \"image_30.bmp\", \"image_31.bmp\", \"image_32.bmp\", \"image_33.bmp\", \"image_34.bmp\", \"image_35.bmp\", \"image_36.bmp\", \"image_37.bmp\", \"image_38.bmp\", \"image_39.bmp\", \"image_40.bmp\", \"image_41.bmp\", \"image_42.bmp\", \"image_43.bmp\", \"image_44.bmp\", \"image_45.bmp\", \"image_46.bmp\", \"image_47.bmp\", \"image_48.bmp\", \"image_49.bmp\" ]" ; |
|
|
|
|
|
|
|
//半圆 |
|
|
|
|
|
|
|
Boolean half_circle = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//算法配置参数 |
|
|
|
|
|
|
|
string sql = $"SELECT JSON FROM ALGORITHM_CONFIG ORDER BY JSON_ORDER ASC"; |
|
|
|
|
|
|
|
DataTable table = DataBaseHelper.ExecuteQuery(sql); |
|
|
|
|
|
|
|
object lightLevelValue = table.Rows[0][0]; |
|
|
|
|
|
|
|
string algo_config = lightLevelValue.ToString() ?? throw new InvalidOperationException(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlgorithmResultEntity algoResult = _algorithmServer.CallParseJsonAndReturnActions(shape, shape_mode, image_file_base_path, image_files, algo_config,half_circle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(algoResult); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public class ButtonInfo |
|
|
|
public class ButtonInfo |
|
|
|
{ |
|
|
|
{ |
|
|
|