|
|
|
@ -4,20 +4,27 @@ using SparkClient.Model.Helper; |
|
|
|
using SparkClient.ViewModel.BaseWindow; |
|
|
|
using SparkClient.ViewModel.BaseWindow; |
|
|
|
using SparkClient.Views.Dialog; |
|
|
|
using SparkClient.Views.Dialog; |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Data; |
|
|
|
using System.Diagnostics.Metrics; |
|
|
|
using System.Diagnostics.Metrics; |
|
|
|
using System.DirectoryServices.ActiveDirectory; |
|
|
|
using System.DirectoryServices.ActiveDirectory; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using System.Reflection.Metadata; |
|
|
|
using System.Reflection.Metadata; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
using System.Windows; |
|
|
|
using System.Windows; |
|
|
|
using System.Windows.Input; |
|
|
|
using System.Windows.Input; |
|
|
|
using System.Windows.Media.Imaging; |
|
|
|
using System.Windows.Media.Imaging; |
|
|
|
using System.Windows.Threading; |
|
|
|
using System.Windows.Threading; |
|
|
|
|
|
|
|
using Microsoft.Data.Sqlite; |
|
|
|
|
|
|
|
using SparkClient.Model.Entity; |
|
|
|
|
|
|
|
using SparkClient.Model.Services; |
|
|
|
|
|
|
|
using MessageBox = System.Windows.MessageBox; |
|
|
|
|
|
|
|
|
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
|
|
|
|
|
|
|
|
public class DiamondSelectVM : BaseViewModel |
|
|
|
public class DiamondSelectVM : BaseViewModel |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SOCClientService _socClientService; |
|
|
|
|
|
|
|
private AlgorithmServer _algorithmServer; |
|
|
|
|
|
|
|
private AlgorithmConfigEntity _algorithmConfigEntity; |
|
|
|
private string DiamondCode { get; set; } |
|
|
|
private string DiamondCode { get; set; } |
|
|
|
private List<ButtonViewModel> _buttons; |
|
|
|
private List<ButtonViewModel> _buttons; |
|
|
|
private List<ButtonViewModel> _buttons2; |
|
|
|
private List<ButtonViewModel> _buttons2; |
|
|
|
@ -98,45 +105,17 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
Buttons2 = tempButtons2; |
|
|
|
Buttons2 = tempButtons2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public void StartGrading(object param) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DoStartGrading(param); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 开始检测(对soc和算法开始通讯) |
|
|
|
/// 开始检测(对soc和算法开始通讯) |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="param"></param> |
|
|
|
/// <param name="param"></param> |
|
|
|
public async void DoStartGrading(object param) |
|
|
|
public async void StartGrading(object param) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (param != null) |
|
|
|
if (param != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
|
|
|
|
JsonImport jsonImport = new JsonImport(); |
|
|
|
|
|
|
|
bool? a = jsonImport.ShowDialog(); |
|
|
|
|
|
|
|
if (a ?? false) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string fileName = jsonImport.FilePath.Text; |
|
|
|
|
|
|
|
string[] lines = File.ReadAllLines(fileName); |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var line in lines) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stringBuilder.Append(line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parameter = JsonConvert.DeserializeObject<AlgorithmResultEntity>(stringBuilder.ToString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LoadingDialog loading = new LoadingDialog(); |
|
|
|
LoadingDialog loading = new LoadingDialog(); |
|
|
|
var tcs = new TaskCompletionSource<bool>(); |
|
|
|
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => loading.ShowDialog())); |
|
|
|
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => { |
|
|
|
|
|
|
|
loading.Closed += (s, e) => tcs.SetResult(true); |
|
|
|
|
|
|
|
loading.ShowDialog(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
await Task.Run(async () => |
|
|
|
await Task.Run(async () => |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i <= 100; i++) |
|
|
|
for (int i = 0; i <= 100; i++) |
|
|
|
@ -151,14 +130,8 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// SocResultEntity socResolt = new SocResultEntity(); |
|
|
|
SocResultEntity socResolt = new SocResultEntity(); |
|
|
|
// AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
// // 启动soc |
|
|
|
|
|
|
|
// socResolt = DoSoc(); |
|
|
|
|
|
|
|
// // 启动算法 |
|
|
|
|
|
|
|
// parameter = DoAlgorithm(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//parameter = DoSoc(); |
|
|
|
|
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
string value = param.ToString()??""; |
|
|
|
string value = param.ToString()??""; |
|
|
|
if (value!= null && value.Split(" ").Length==3) |
|
|
|
if (value!= null && value.Split(" ").Length==3) |
|
|
|
@ -167,6 +140,13 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 启动soc |
|
|
|
|
|
|
|
socResolt = await DoSoc(); |
|
|
|
|
|
|
|
// 启动算法 |
|
|
|
|
|
|
|
parameter = await DoAlgorithm(socResolt, parameter.Shape, parameter.CrownType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parameter.DiamondCode = DiamondCode; |
|
|
|
parameter.DiamondCode = DiamondCode; |
|
|
|
GradingResult(parameter); |
|
|
|
GradingResult(parameter); |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -189,17 +169,82 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AlgorithmResultEntity DoAlgorithm() |
|
|
|
|
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
AlgorithmResultEntity param = new AlgorithmResultEntity(); |
|
|
|
/// 启动切工仪接口。 |
|
|
|
string json = $"{{\"status\": \"ok\",\r\n \"facets\": [\r\n {{\r\n \"coords\": [\r\n {{\r\n \"x\": 0.03402838855981827,\r\n \"y\": -0.11212713271379471,\r\n \"z\": 5.701290607452393\r\n }},\r\n {{\r\n \"x\": 0.46919262409210205,\r\n \"y\": 0.058160409331321716,\r\n \"z\": 5.289202690124512\r\n }},\r\n {{\r\n \"x\": 0.1256149709224701,\r\n \"y\": 0.3005124032497406,\r\n \"z\": 5.330680847167969\r\n }}\r\n ],\r\n \"facet_id\": \"21_0\",\r\n \"facet_type\": 21\r\n }},\r\n {{\r\n \"coords\": [\r\n {{\r\n \"x\": 2.9093382358551025,\r\n \"y\": 3.4028751850128174,\r\n \"z\": 1.724348783493042\r\n }},\r\n {{\r\n \"x\": 0.46919262409210205,\r\n \"y\": 0.058160409331321716,\r\n \"z\": 5.289202690124512\r\n }},\r\n {{\r\n \"x\": 0.1256149709224701,\r\n \"y\": 0.3005124032497406,\r\n \"z\": 5.330680847167969\r\n }}\r\n ],\r\n \"facet_id\": \"21_1\",\r\n \"facet_type\": 21\r\n }}\r\n ],\r\n \"measurements\": {{\r\n \"DIAMETER\": 6.43,\r\n \"DIAMETER_DEV\": 1.2,\r\n \"M1\": 6.409999847412109,\r\n \"M2\": 6.46999979019165,\r\n \"M3\": 3.9700000286102295,\r\n \"TABLE\": 58.0,\r\n \"TABLE_MIN\": 57.5,\r\n \"TABLE_MAX\": 58.6,\r\n \"CROWN_HEIGHT\": 11.5,\r\n \"CROWN_H_DEV\": 1.4,\r\n \"CROWN_H_MIN\": 10.7,\r\n \"CROWN_H_MAX\": 12.1,\r\n \"CROWN_ANGLE\": 30.5,\r\n \"CROWN_ANGLE_DEV\": 0.9,\r\n \"CROWN_ANGLE_MIN\": 30.2,\r\n \"CROWN_ANGLE_MAX\": 31.1,\r\n \"PAV_DEPTH\": 35.0,\r\n \"PAV_DEPTH_DEV\": 0.8,\r\n \"PAV_DEPTH_MIN\": 34.5,\r\n \"PAV_DEPTH_MAX\": 35.3,\r\n \"PAV_ANGLE\": 35.1,\r\n \"PAV_ANGLE_DEV\": 0.8,\r\n \"PAV_ANGLE_MIN\": 34.7,\r\n \"PAV_ANGLE_MAX\": 35.5,\r\n \"GIRDLE_BEZEL\": 7.1,\r\n \"GIRDLE_BEZEL_DEV\": 1.8,\r\n \"GIRDLE_BEZEL_MIN\": 6.8,\r\n \"GIRDLE_BEZEL_MAX\": 7.5,\r\n \"GIRDLE_BONE\": 7.8,\r\n \"GIRDLE_BONE_MIN\": 7.3,\r\n \"GIRDLE_BONE_MAX\": 8.3,\r\n \"GIRDLE\": 6.3,\r\n \"GIRDLE_DEV\": 3.3,\r\n \"GIRDLE_MIN\": 4.2,\r\n \"GIRDLE_MAX\": 7.5,\r\n \"TOTAL_DEPTH\": 53.5,\r\n \"CULET\": 1.8,\r\n \"LW_RATIO\": 1.0,\r\n \"TOC\": 1.4,\r\n \"COC\": 0.5,\r\n \"TA\": 3.81,\r\n \"LGF\": 75,\r\n \"STAR\": 65,\r\n \"STAR_MIN\": 61.1,\r\n \"STAR_MAX\": 65.4,\r\n \"LOWER_HALVES_RATIO\": 75,\r\n \"LOWER_HALVES_RATIO_MIN\": 73.3,\r\n \"LOWER_HALVES_RATIO_MAX\": 78.1,\r\n \"TWIST\": 1.3,\r\n \"TWIST_DEV\": 2.4,\r\n \"TWIST_MIN\": -0.2,\r\n \"TWIST_MAX\": -2.4,\r\n \"CULET_TO_TABLE\": 1.4\r\n }}\r\n}}\r\n"; |
|
|
|
/// </summary> |
|
|
|
param = JsonConvert.DeserializeObject<AlgorithmResultEntity>(json); |
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
return param; |
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
|
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
|
|
|
|
/// <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); |
|
|
|
|
|
|
|
// // 转换成json |
|
|
|
|
|
|
|
// string jsonResult = JsonConvert.SerializeObject(resultEntity, Formatting.Indented); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SocResultEntity resultEntity = new SocResultEntity(); |
|
|
|
|
|
|
|
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\" ]" ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//算法配置参数 |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将 algoResult 序列化为格式化的 JSON 字符串 |
|
|
|
|
|
|
|
string algoJsonResult = JsonConvert.SerializeObject(algoResult, Formatting.Indented); |
|
|
|
|
|
|
|
ShowMessage(algoJsonResult); |
|
|
|
|
|
|
|
return Task.FromResult(algoResult); |
|
|
|
} |
|
|
|
} |
|
|
|
private SocResultEntity DoSoc() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowMessage(string message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new SocResultEntity(); |
|
|
|
MessageBox.Show(message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public class ButtonInfo |
|
|
|
public class ButtonInfo |
|
|
|
{ |
|
|
|
{ |
|
|
|
|