diff --git a/Resource/Images/UIResource/Diamond/oval_p8-p8.png b/Resource/Images/UIResource/Diamond/oval_p8-p8.png
new file mode 100644
index 0000000..d9deaae
Binary files /dev/null and b/Resource/Images/UIResource/Diamond/oval_p8-p8.png differ
diff --git a/Resource/Images/UIResource/Diamond/pear_P8-P8.png b/Resource/Images/UIResource/Diamond/pear_P8-P8.png
new file mode 100644
index 0000000..e6edd14
Binary files /dev/null and b/Resource/Images/UIResource/Diamond/pear_P8-P8.png differ
diff --git a/SparkClient.csproj b/SparkClient.csproj
index 4429073..03a3ba1 100644
--- a/SparkClient.csproj
+++ b/SparkClient.csproj
@@ -56,6 +56,8 @@
+
+
@@ -80,6 +82,10 @@
+
+
+
+
diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs
index bb517d7..71c1df4 100644
--- a/ViewModel/Grading/DiamondSelectVM.cs
+++ b/ViewModel/Grading/DiamondSelectVM.cs
@@ -30,7 +30,7 @@ namespace SparkClient.ViewModel.Grading;
///
public class DiamondSelectVM : BaseViewModel
{
-
+
private SOCClientService _socClientService;
private AlgorithmServer _algorithmServer;
private AlgorithmConfigEntity _algorithmConfigEntity;
@@ -39,7 +39,8 @@ public class DiamondSelectVM : BaseViewModel
private List _buttons2;
private ICommand ChangeDiamondTypeCommand;
private ICommand StartGradingCommand;
- public List Buttons {
+ public List Buttons
+ {
get { return _buttons; }
set
{
@@ -56,7 +57,7 @@ public class DiamondSelectVM : BaseViewModel
OnPropertyChanged(nameof(Buttons2));
}
}
-
+
public DiamondSelectVM()
{
ChangeDiamondTypeCommand = new RelayCommand(ChangeDiamondType);
@@ -66,7 +67,7 @@ public class DiamondSelectVM : BaseViewModel
foreach (var buttonInfo in buttonInfos)
{
var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/" + buttonInfo.ImageName, UriKind.RelativeOrAbsolute));
- ButtonViewModel button = new ButtonViewModel() { Text = buttonInfo.ButtonName, ImageSource = bitmap, Type = buttonInfo.Type, Command = ChangeDiamondTypeCommand ,IsEnabled= buttonInfo.IsEnabled, IsHighlighted = false};
+ ButtonViewModel button = new ButtonViewModel() { Text = buttonInfo.ButtonName, ImageSource = bitmap, Type = buttonInfo.Type, Command = ChangeDiamondTypeCommand, IsEnabled = buttonInfo.IsEnabled, IsHighlighted = false };
tempButtons.Add(button);
}
Buttons = tempButtons;
@@ -78,17 +79,17 @@ public class DiamondSelectVM : BaseViewModel
///
private List GetButtonInfos()
{
-
+
List buttonInfos = new List();
buttonInfos.Add(new ButtonInfo() { Type = "round", IsEnabled = true, ImageName = "round.png", ButtonName = MultilingualHelper.getString("圆形") });
buttonInfos.Add(new ButtonInfo() { Type = "Hexagon", IsEnabled = false, ImageName = "Hexagon.png", ButtonName = MultilingualHelper.getString("六边形") });
buttonInfos.Add(new ButtonInfo() { Type = "cushion", IsEnabled = false, ImageName = "Cushion.png", ButtonName = MultilingualHelper.getString("枕形") });
- buttonInfos.Add(new ButtonInfo() { Type = "Pear", IsEnabled = false, ImageName = "Pear.png", ButtonName = MultilingualHelper.getString("梨形") });
+ buttonInfos.Add(new ButtonInfo() { Type = "Pear", IsEnabled = true, ImageName = "Pear.png", ButtonName = MultilingualHelper.getString("梨形") });
buttonInfos.Add(new ButtonInfo() { Type = "Princess", IsEnabled = false, ImageName = "Princess.png", ButtonName = MultilingualHelper.getString("公主方形") });
- buttonInfos.Add(new ButtonInfo() { Type = "oval", IsEnabled = false, ImageName = "oval.png", ButtonName = MultilingualHelper.getString("椭圆形") });
+ buttonInfos.Add(new ButtonInfo() { Type = "oval", IsEnabled = true, ImageName = "oval.png", ButtonName = MultilingualHelper.getString("椭圆形") });
buttonInfos.Add(new ButtonInfo() { Type = "Emerald", IsEnabled = false, ImageName = "Emerald.png", ButtonName = MultilingualHelper.getString("祖母绿形") });
buttonInfos.Add(new ButtonInfo() { Type = "Odd", IsEnabled = false, ImageName = "Odd.png", ButtonName = MultilingualHelper.getString("异形钻") });
- return buttonInfos;
+ return buttonInfos;
}
///
/// 获取钻石列表
@@ -107,26 +108,70 @@ public class DiamondSelectVM : BaseViewModel
[Log]
public void ChangeDiamondType(object type)
{
- if (type!= null)
+ // 非空处理
+ if (type == null) return;
+
+ // 获取当前点选钻石形状
+ string selectedType = type.ToString();
+
+ // 恢复所有按钮状态,并高亮当前选中的按钮
+ foreach (var item in Buttons)
+ {
+ item.IsHighlighted = item.Type == selectedType;
+ }
+
+ //初始化按键集
+ List tempButtons2 = new List();
+
+ // 设置二级图片按钮路径
+ string basePath = "pack://application:,,,/Resource/Images/UIResource/Diamond/";
+ Func getBitmap = (fileName) => new BitmapImage(new Uri(basePath + fileName, UriKind.RelativeOrAbsolute));
+
+ // 根据选中类型生成右侧按钮
+ switch (selectedType.ToLower())
+ {
+ case "round":
+ // 圆形钻石
+ AddRoundButtons(tempButtons2, getBitmap);
+ break;
+ case "pear":
+ // 梨形钻石
+ AddPearButtons(tempButtons2, getBitmap);
+ break;
+ case "oval":
+ // 椭圆形钻石
+ AddOvalButtons(tempButtons2, getBitmap);
+ break;
+ default:
+ // 默认圆形
+ AddRoundButtons(tempButtons2, getBitmap);
+ break;
+ }
+ Buttons2 = tempButtons2;
+ }
+
+ ///
+ /// 圆形二级界面按键加载处理
+ ///
+ /// 当前页面按键
+ /// 图片路径
+ private void AddRoundButtons(List buttons, Func getBitmap)
+ {
+ // 运行模式为实验室模式
+ if (Common.RunMode == 0)
{
- foreach (var item in Buttons.Where(x => x.Type == type))
- {
- item.IsHighlighted = true;
- };
- List tempButtons2 = new List();
- if (Common.RunMode == 0)
- {
- var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/round_P8-P8.png", UriKind.RelativeOrAbsolute));
- ButtonViewModel button = new ButtonViewModel() { Text = "P8-P8", ImageSource = bitmap, Type = "ROUND P8 P8", Command = StartGradingCommand, IsFocused = true};
- tempButtons2.Add(button);
- }else if (Common.RunMode == 1)
- {
- var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8.png", UriKind.RelativeOrAbsolute));
- var bitmap_p8p8s1 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S1.png", UriKind.RelativeOrAbsolute));
- var bitmap_p8p8s2 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S2.png", UriKind.RelativeOrAbsolute));
- var bitmap_p8p8s7 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S7.png", UriKind.RelativeOrAbsolute));
- var bitmap_p8p8s8 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S8.png", UriKind.RelativeOrAbsolute));
- List listBtn = new List()
+ var bitmap_p8p8 = getBitmap("round_P8-P8.png");
+ buttons.Add(new ButtonViewModel() { Text = "P8-P8", ImageSource = bitmap_p8p8, Type = "ROUND P8 P8", Command = StartGradingCommand, IsFocused = true });
+ }
+ // 运行模式为工厂模式
+ else if (Common.RunMode == 1)
+ {
+ var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8.png", UriKind.RelativeOrAbsolute));
+ var bitmap_p8p8s1 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S1.png", UriKind.RelativeOrAbsolute));
+ var bitmap_p8p8s2 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S2.png", UriKind.RelativeOrAbsolute));
+ var bitmap_p8p8s7 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S7.png", UriKind.RelativeOrAbsolute));
+ var bitmap_p8p8s8 = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/UIResource/Diamond/round_P8-P8-S8.png", UriKind.RelativeOrAbsolute));
+ List listBtn = new List()
{
new ButtonViewModel() { Text = "P8-P8 Stage 1", ImageSource = bitmap_p8p8s1, Type = "ROUND P8 P8 S1", Command = StartGradingCommand, IsFocused = true},
new ButtonViewModel() { Text = "P8-P8 Stage 2", ImageSource = bitmap_p8p8s2, Type = "ROUND P8 P8 S2", Command = StartGradingCommand, IsFocused = true},
@@ -138,15 +183,66 @@ public class DiamondSelectVM : BaseViewModel
new ButtonViewModel() { Text = "P8-P8 Stage 8", ImageSource = bitmap_p8p8s8, Type = "ROUND P8 P8 S8", Command = StartGradingCommand, IsFocused = true},
new ButtonViewModel() { Text = "P8-P8 Stage 9", ImageSource = bitmap, Type = "ROUND P8 P8 S9", Command = StartGradingCommand, IsFocused = true},
new ButtonViewModel() { Text = "P8-P8", ImageSource = bitmap, Type = "ROUND P8 P8", Command = StartGradingCommand, IsFocused = true},
-
};
-
- listBtn.ForEach(e => tempButtons2.Add(e));
-
- }
+ listBtn.ForEach(e => buttons.Add(e));
+ }
+ }
+ ///
+ /// 梨形二级界面按键加载处理
+ ///
+ /// 当前页面按键
+ /// 图片路径
+ private void AddPearButtons(List buttons, Func getBitmap)
+ {
+ // 运行模式为实验室模式
+ if (Common.RunMode == 0)
+ {
+ // TODO 待二级图片作成后替换,以及后续检测处理追加
+ var bitmap_p8p8 = getBitmap("pear_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Pear Stage 1", ImageSource = bitmap_p8p8, Type = "PEAR S1", Command = StartGradingCommand, IsFocused = true });
- Buttons2 = tempButtons2;
+ // 追加按钮2
+ //var bitmap_p8p8s2 = getBitmap("pear_P8-P8-S2.png");
+ //buttons.Add(new ButtonViewModel { Text = "Pear Stage 2", ImageSource = bitmap_p8p8s2, Type = "PEAR S2", Command = StartGradingCommand, IsFocused = true });
+ }
+ // 运行模式为工厂模式
+ else if (Common.RunMode == 1)
+ {
+ // TODO 待二级图片作成后替换,以及后续检测处理追加
+ var bitmap_p8p8 = getBitmap("pear_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Pear Stage 1", ImageSource = bitmap_p8p8, Type = "PEAR S1", Command = StartGradingCommand, IsFocused = true });
+
+ // TODO 虚拟追加按钮2
+ var bitmap_p8p8s2 = getBitmap("pear_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Pear Stage 2", ImageSource = bitmap_p8p8, Type = "PEAR S2", Command = StartGradingCommand, IsFocused = true });
+ }
+ }
+
+ ///
+ /// 椭圆形二级界面按键加载处理
+ ///
+ /// 当前页面按键
+ /// 图片路径
+ private void AddOvalButtons(List buttons, Func getBitmap)
+ {
+ // 运行模式为实验室模式
+ if (Common.RunMode == 0)
+ {
+ // TODO 待二级图片作成后替换,以及后续检测处理追加
+ var bitmap_p8p8 = getBitmap("oval_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Oval Stage 1", ImageSource = bitmap_p8p8, Type = "OVAL S1", Command = StartGradingCommand, IsFocused = true });
+ }
+ // 运行模式为工厂模式
+ else if (Common.RunMode == 1)
+ {
+ // TODO 待二级图片作成后替换,以及后续检测处理追加
+ var bitmap_p8p8 = getBitmap("oval_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Oval Stage 1", ImageSource = bitmap_p8p8, Type = "OVAL S1", Command = StartGradingCommand, IsFocused = true });
+
+ // TODO 虚拟追加按钮2
+ var bitmap_p8p8s2 = getBitmap("oval_P8-P8.png");
+ buttons.Add(new ButtonViewModel { Text = "Oval Stage 2", ImageSource = bitmap_p8p8, Type = "OVAL S2", Command = StartGradingCommand, IsFocused = true });
}
}
@@ -186,11 +282,11 @@ public class DiamondSelectVM : BaseViewModel
DiamondCode = "";
}
- string runModel = ConfigurationHelper.ReadConfigValue("RunModel")??"1";
+ string runModel = ConfigurationHelper.ReadConfigValue("RunModel") ?? "1";
if ("0".Equals(runModel))
- //json模式
-
+ //json模式
+
{
Logger.Info($"当前运行JSON模式:{runModel}");
var loadingView = new GradingLoadingVM(param.ToString(), DiamondCode);
@@ -204,10 +300,10 @@ public class DiamondSelectVM : BaseViewModel
{
//返回
loadingView.Dispose();
- WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
+ WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
return;
}
- if ( res <= -100)
+ if (res <= -100)
{
return;
}
@@ -223,18 +319,18 @@ public class DiamondSelectVM : BaseViewModel
vm.WindowTitle = string.IsNullOrWhiteSpace(DiamondCode) ? vm.WindowTitle : $"{vm.WindowTitle} - {DiamondCode}";
WindowManager.mainViewModel.Content = vm;
WindowManager.openContent.Add(vm);
-
+
int res = await loadingView.Start(1);
if (res > -100 && res < 0)
{
//返回
loadingView.Dispose();
- WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
+ WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
await SOCClientService.Service.OpenPump(false);
return;
}
- if ( res <= -100)
+ if (res <= -100)
{
return;
}
@@ -250,207 +346,207 @@ public class DiamondSelectVM : BaseViewModel
vm.WindowTitle = string.IsNullOrWhiteSpace(DiamondCode) ? vm.WindowTitle : $"{vm.WindowTitle} - {DiamondCode}";
WindowManager.mainViewModel.Content = vm;
WindowManager.openContent.Add(vm);
-
+
int res = await loadingView.Start();
if (res > -100 && res < 0)
{
//返回
loadingView.Dispose();
- WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
+ WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
await SOCClientService.Service.OpenPump(false);
return;
}
- if ( res <= -100)
+ if (res <= -100)
{
return;
}
-
+
GradingResult(loadingView.Parameter);
loadingView.Dispose();
-
+
}
-
-
-/**
- LoadingDialog loading = new LoadingDialog(DiamondCode);
- try
- {
- if (param != null)
- {
- string progTime = ConfigurationHelper.ReadConfigValue("ProgressTime");
- int iProgTime = 50000;
- int.TryParse(progTime, out iProgTime);
- int setpTime = iProgTime / 97;
+ /**
- var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => loading.ShowDialog()));
- await Task.Run(async () =>
+ LoadingDialog loading = new LoadingDialog(DiamondCode);
+ try
{
- bool isEnd = false;
- int progress = 0;
- // 更新进度条的值(需要在UI线程上执行)
- loading.Dispatcher.Invoke(async () =>
+ if (param != null)
{
- for (int i = 0; i <= 97; i++)
+ string progTime = ConfigurationHelper.ReadConfigValue("ProgressTime");
+
+ int iProgTime = 50000;
+ int.TryParse(progTime, out iProgTime);
+ int setpTime = iProgTime / 97;
+
+ var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => loading.ShowDialog()));
+ await Task.Run(async () =>
{
- if (isEnd)
+ bool isEnd = false;
+ int progress = 0;
+ // 更新进度条的值(需要在UI线程上执行)
+ loading.Dispatcher.Invoke(async () =>
+ {
+ for (int i = 0; i <= 97; i++)
+ {
+ if (isEnd)
+ {
+ break;
+ }
+ // 模拟耗时操作
+ //System.Threading.Thread.Sleep(50); // 休眠50毫秒
+ await Task.Delay(setpTime);
+ loading.setValue(i);
+ progress = i;
+ }
+ });
+
+ SocResultEntity socResolt = new SocResultEntity();
+ AlgorithmResultEntity parameter = new AlgorithmResultEntity();
+ parameter.Standard = "IGI 2024";
+ string value = param.ToString() ?? "";
+ if (value != null && value.Split(" ").Length == 3)
{
- break;
+ parameter.Shape = value.Split(" ")[0];
+ parameter.CrownType = value.Split(" ")[1];
+ parameter.PavType = value.Split(" ")[2];
}
- // 模拟耗时操作
- //System.Threading.Thread.Sleep(50); // 休眠50毫秒
- await Task.Delay(setpTime);
- loading.setValue(i);
- progress = i;
- }
- });
-
- SocResultEntity socResolt = new SocResultEntity();
- AlgorithmResultEntity parameter = new AlgorithmResultEntity();
- parameter.Standard = "IGI 2024";
- string value = param.ToString() ?? "";
- if (value != null && value.Split(" ").Length == 3)
- {
- parameter.Shape = value.Split(" ")[0];
- parameter.CrownType = value.Split(" ")[1];
- parameter.PavType = value.Split(" ")[2];
- }
- // 初始化SOC客户端服务,传入SOC端的地址和认证Token
- _socClientService = new SOCClientService();
- // 启动soc
- socResolt = await _socClientService.ProcessImageCollectionAsync();
- switch (socResolt.Status)
- {
- case StatusCodes.OpenOfTheHatch:
- ShowErrorMessage(MultilingualHelper.getString("OpenOfTheHatch"), loading);
- return;
- case StatusCodes.DeviceNotFound:
- ShowErrorMessage(MultilingualHelper.getString("DeviceNotFound"), loading);
- return;
- case StatusCodes.InProgress:
- ShowErrorMessage(MultilingualHelper.getString("InProgress"), loading);
- return;
- case StatusCodes.CacheCleared:
- ShowErrorMessage(MultilingualHelper.getString("CacheCleared"), loading);
- return;
- case StatusCodes.CannotSendCommand:
- 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\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ;
+ // 初始化SOC客户端服务,传入SOC端的地址和认证Token
+ _socClientService = new SOCClientService();
+ // 启动soc
+ socResolt = await _socClientService.ProcessImageCollectionAsync();
+ switch (socResolt.Status)
+ {
+ case StatusCodes.OpenOfTheHatch:
+ ShowErrorMessage(MultilingualHelper.getString("OpenOfTheHatch"), loading);
+ return;
+ case StatusCodes.DeviceNotFound:
+ ShowErrorMessage(MultilingualHelper.getString("DeviceNotFound"), loading);
+ return;
+ case StatusCodes.InProgress:
+ ShowErrorMessage(MultilingualHelper.getString("InProgress"), loading);
+ return;
+ case StatusCodes.CacheCleared:
+ ShowErrorMessage(MultilingualHelper.getString("CacheCleared"), loading);
+ return;
+ case StatusCodes.CannotSendCommand:
+ 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\", \"image_50.bmp\", \"image_51.bmp\", \"image_52.bmp\", \"image_53.bmp\", \"image_54.bmp\", \"image_55.bmp\", \"image_56.bmp\", \"image_57.bmp\", \"image_58.bmp\", \"image_59.bmp\", \"image_60.bmp\", \"image_61.bmp\", \"image_62.bmp\", \"image_63.bmp\", \"image_64.bmp\", \"image_65.bmp\", \"image_66.bmp\", \"image_67.bmp\", \"image_68.bmp\", \"image_69.bmp\", \"image_70.bmp\", \"image_71.bmp\", \"image_72.bmp\", \"image_73.bmp\", \"image_74.bmp\", \"image_75.bmp\", \"image_76.bmp\", \"image_77.bmp\", \"image_78.bmp\", \"image_79.bmp\", \"image_80.bmp\", \"image_81.bmp\", \"image_82.bmp\", \"image_83.bmp\", \"image_84.bmp\", \"image_85.bmp\", \"image_86.bmp\", \"image_87.bmp\", \"image_88.bmp\", \"image_89.bmp\", \"image_90.bmp\", \"image_91.bmp\", \"image_92.bmp\", \"image_93.bmp\", \"image_94.bmp\", \"image_95.bmp\", \"image_96.bmp\", \"image_97.bmp\", \"image_98.bmp\", \"image_99.bmp\"]" ;
- // 保存图片到历史记录文件夹
- HandleAlgorithmFailure(image_files, DiamondCode);
+ // 保存图片到历史记录文件夹
+ HandleAlgorithmFailure(image_files, DiamondCode);
- // 启动算法
- parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files);
- //机器号
- parameter.DeviceId = socResolt.DeviceId;
- switch (parameter.status)
- {
- case StatusCodes.AlgorithmFailed:
- ShowErrorMessage(MultilingualHelper.getString("AlgorithmFailed"), loading);
- return;
- case StatusCodes.ImageFileReadFailure:
- ShowErrorMessage(MultilingualHelper.getString("ImageFileReadFailure"), loading);
- return;
- case StatusCodes.JsonParseFailure:
- ShowErrorMessage(MultilingualHelper.getString("JsonParseFailure"), loading);
- return;
- case StatusCodes.NoDiamond:
- ShowErrorMessage(MultilingualHelper.getString("NoDiamond"), loading);
- return;
- }
- parameter.Standard = getStandardName();
- parameter.Shape = value.Split(" ")[0];
- parameter.CrownType = value.Split(" ")[1];
- parameter.PavType = value.Split(" ")[2];
- parameter.DiamondCode = DiamondCode;
-
- if (!parameter.status.Equals(StatusCodes.Ok))
- parameter.error_msg = MultilingualHelper.getString(StatusCodes.GetConstantNameByValue(parameter.status));
- //参数实体转json输出
- try
- {
- string parameterJson = JsonConvert.SerializeObject(parameter);
- parameterJson = JToken.Parse(parameterJson).ToString();
- string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "result");
- if (!Directory.Exists(outputPath))
- Directory.CreateDirectory(outputPath);
- string outputFilePath = $"{outputPath}/{DiamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json";
- using (var file = File.Create(outputFilePath))
- using (StreamWriter stream = new StreamWriter(file))
- {
- stream.Write(parameterJson);
- }
- }
- catch (Exception ex)
- {
- Logger.Error("output输出失败:"+ex.Message);
- }
-
- isEnd = true;
- //GradingResult(parameter);
- await loading.Dispatcher.Invoke(async () =>
- {
- for (int i = progress; progress <= 100; i++)
- {
- Random random = new Random(); int minValue = 20; int maxValue = 100; // 生成50到150之间的随机整数
- int randomNumber = random.Next(minValue, maxValue + 1);
- await Task.Delay(randomNumber);
- loading.setValue(i);
- if (loading.ProgressBar.Value == 98)
+ // 启动算法
+ parameter = _algorithmServer.CallParseJsonAndReturnActions(parameter.Shape, parameter.CrownType, image_files);
+ //机器号
+ parameter.DeviceId = socResolt.DeviceId;
+ switch (parameter.status)
{
- GradingResult(parameter);
+ case StatusCodes.AlgorithmFailed:
+ ShowErrorMessage(MultilingualHelper.getString("AlgorithmFailed"), loading);
+ return;
+ case StatusCodes.ImageFileReadFailure:
+ ShowErrorMessage(MultilingualHelper.getString("ImageFileReadFailure"), loading);
+ return;
+ case StatusCodes.JsonParseFailure:
+ ShowErrorMessage(MultilingualHelper.getString("JsonParseFailure"), loading);
+ return;
+ case StatusCodes.NoDiamond:
+ ShowErrorMessage(MultilingualHelper.getString("NoDiamond"), loading);
+ return;
}
- if(loading.ProgressBar.Value >= 100)
+ parameter.Standard = getStandardName();
+ parameter.Shape = value.Split(" ")[0];
+ parameter.CrownType = value.Split(" ")[1];
+ parameter.PavType = value.Split(" ")[2];
+ parameter.DiamondCode = DiamondCode;
+
+ if (!parameter.status.Equals(StatusCodes.Ok))
+ parameter.error_msg = MultilingualHelper.getString(StatusCodes.GetConstantNameByValue(parameter.status));
+ //参数实体转json输出
+ try
{
-
- loading.Close();
- break;
+ string parameterJson = JsonConvert.SerializeObject(parameter);
+ parameterJson = JToken.Parse(parameterJson).ToString();
+ string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "result");
+ if (!Directory.Exists(outputPath))
+ Directory.CreateDirectory(outputPath);
+ string outputFilePath = $"{outputPath}/{DiamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json";
+ using (var file = File.Create(outputFilePath))
+ using (StreamWriter stream = new StreamWriter(file))
+ {
+ stream.Write(parameterJson);
+ }
}
- }
- // 检测到钻石需进行清洁
- if (parameter.status == StatusCodes.Recheck)
- {
- ShowErrorMessage(MultilingualHelper.getString("Recheck"), loading);
- }
-
- });
- });
- }
- }
- catch (DirectoryNotFoundException ex)
- {
- loading.Close();
- new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
- }
- catch (IOException ex)
- {
- loading.Close();
- new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}");
- }
- finally {
-
- }
-**/
+ catch (Exception ex)
+ {
+ Logger.Error("output输出失败:"+ex.Message);
+ }
+
+ isEnd = true;
+ //GradingResult(parameter);
+ await loading.Dispatcher.Invoke(async () =>
+ {
+ for (int i = progress; progress <= 100; i++)
+ {
+ Random random = new Random(); int minValue = 20; int maxValue = 100; // 生成50到150之间的随机整数
+ int randomNumber = random.Next(minValue, maxValue + 1);
+ await Task.Delay(randomNumber);
+ loading.setValue(i);
+ if (loading.ProgressBar.Value == 98)
+ {
+ GradingResult(parameter);
+ }
+ if(loading.ProgressBar.Value >= 100)
+ {
+
+ loading.Close();
+ break;
+ }
+ }
+ // 检测到钻石需进行清洁
+ if (parameter.status == StatusCodes.Recheck)
+ {
+ ShowErrorMessage(MultilingualHelper.getString("Recheck"), loading);
+ }
+
+ });
+ });
+ }
+ }
+ catch (DirectoryNotFoundException ex)
+ {
+ loading.Close();
+ new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
+ }
+ catch (IOException ex)
+ {
+ loading.Close();
+ new MessageBox().Show($"{MultilingualHelper.getString("FileOpened")}:{ex.Message}");
+ }
+ finally {
+
+ }
+ **/
}
[Log]
@@ -464,7 +560,7 @@ public class DiamondSelectVM : BaseViewModel
}
else
{
- return dataTable.Rows[0][MultilingualHelper.getString("NameType")].ToString()??"";
+ return dataTable.Rows[0][MultilingualHelper.getString("NameType")].ToString() ?? "";
}
}
// 将 UI 操作调度到主线程并显示错误信息
@@ -489,7 +585,8 @@ public class DiamondSelectVM : BaseViewModel
public async void DoStartGrading(object param)
{
LoadingDialog loading = new LoadingDialog(DiamondCode);
- try {
+ try
+ {
if (param != null)
{
AlgorithmResultEntity parameter = new AlgorithmResultEntity();
@@ -512,9 +609,10 @@ public class DiamondSelectVM : BaseViewModel
{
return;
}
-
+
var tcs = new TaskCompletionSource();
- var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => {
+ var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() =>
+ {
loading.Closed += (s, e) => tcs.SetResult(true);
loading.ShowDialog();
}
@@ -581,7 +679,7 @@ public class DiamondSelectVM : BaseViewModel
[Log]
public static void HandleAlgorithmFailure(string[] image_files, string dCode = "", string dType = "")
{
-
+
// 从配置文件中读取 imageHistoryPath
// 定义历史记录文件夹路径
string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"];
@@ -594,13 +692,13 @@ public class DiamondSelectVM : BaseViewModel
// 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
// 组合新的文件夹路径
- string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}-{dType}" : $"image-{dCode}-{timestamp}-{dType}" );
-
+ string newFolderPath = Path.Combine(imageHistoryPath, string.IsNullOrWhiteSpace(dCode) ? $"image-{timestamp}-{dType}" : $"image-{dCode}-{timestamp}-{dType}");
+
// 检查 D 盘内存空间
string strSafeSpace = ConfigurationHelper.ReadConfigValue("SafeSpaceReservation");
long safeSpace = 10L;
long.TryParse(strSafeSpace, out safeSpace);
- DriveInfo dDrive = new DriveInfo(imageHistoryPath.Substring(0,1));
+ DriveInfo dDrive = new DriveInfo(imageHistoryPath.Substring(0, 1));
long requiredSpace = safeSpace * 1024 * 1024 * 1024;
if (dDrive.TotalFreeSpace < requiredSpace)
{
@@ -687,7 +785,7 @@ public class DiamondSelectVM : BaseViewModel
throw;
}
}
-
+
}
public class ButtonInfo
{
@@ -746,7 +844,7 @@ public class ButtonViewModel : BaseViewModel
OnPropertyChanged(nameof(Type));
}
}
- public int Column
+ public int Column
{
get { return _col; }
set
@@ -790,7 +888,8 @@ public class ButtonViewModel : BaseViewModel
public Brush BackgroundColor
{
- get {
+ get
+ {
return _background;
}
set