You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
287 lines
12 KiB
287 lines
12 KiB
using Newtonsoft.Json; |
|
using SparkClient.Model.Entity.ApiEntity; |
|
using SparkClient.Model.Helper; |
|
using SparkClient.ViewModel.BaseWindow; |
|
using SparkClient.Views.Dialog; |
|
using System; |
|
using System.Diagnostics.Metrics; |
|
using System.DirectoryServices.ActiveDirectory; |
|
using System.IO; |
|
using System.Reflection.Metadata; |
|
using System.Text; |
|
using System.Windows; |
|
using System.Windows.Input; |
|
using System.Windows.Media.Imaging; |
|
using System.Windows.Threading; |
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
public class DiamondSelectVM : BaseViewModel |
|
{ |
|
private string DiamondCode { get; set; } |
|
private List<ButtonViewModel> _buttons; |
|
private List<ButtonViewModel> _buttons2; |
|
private ICommand ChangeDiamondTypeCommand; |
|
private ICommand StartGradingCommand; |
|
public List<ButtonViewModel> Buttons { |
|
get { return _buttons; } |
|
set |
|
{ |
|
_buttons = value; |
|
OnPropertyChanged(nameof(Buttons)); |
|
} |
|
} |
|
public List<ButtonViewModel> Buttons2 |
|
{ |
|
get { return _buttons2; } |
|
set |
|
{ |
|
_buttons2 = value; |
|
OnPropertyChanged(nameof(Buttons2)); |
|
} |
|
} |
|
|
|
public DiamondSelectVM(string DiamondCode) |
|
{ |
|
ChangeDiamondTypeCommand = new RelayCommand(ChangeDiamondType); |
|
StartGradingCommand = new RelayCommand(StartGrading); |
|
this.DiamondCode = DiamondCode; |
|
List<ButtonViewModel> tempButtons = new List<ButtonViewModel>(); |
|
List<ButtonInfo> buttonInfos = GetButtonInfos(); |
|
foreach (var buttonInfo in buttonInfos) |
|
{ |
|
var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/" + buttonInfo.ImageName, UriKind.RelativeOrAbsolute)); |
|
ButtonViewModel button = new ButtonViewModel() { Text = buttonInfo.ButtonName, ImageSource = bitmap, Type = buttonInfo.Type, Command = ChangeDiamondTypeCommand ,IsEnabled= buttonInfo.IsEnabled, IsHighlighted = false}; |
|
tempButtons.Add(button); |
|
} |
|
Buttons = tempButtons; |
|
|
|
} |
|
private List<ButtonInfo> GetButtonInfos() |
|
{ |
|
List<ButtonInfo> buttonInfos = new List<ButtonInfo>(); |
|
buttonInfos.Add(new ButtonInfo() { Type = "round", IsEnabled = true, ImageName = "round_3x.png", ButtonName = MultilingualHelper.getString("圆形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "Heart", IsEnabled = false, ImageName = "Heart-shaped.png", ButtonName = MultilingualHelper.getString("心形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "cushion", IsEnabled = false, ImageName = "Cushion-shaped.png", ButtonName = MultilingualHelper.getString("枕形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "Pear", IsEnabled = false, ImageName = "Pear-shaped.png", ButtonName = MultilingualHelper.getString("梨形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "Princess", IsEnabled = false, ImageName = "Princess-shaped.png", ButtonName = MultilingualHelper.getString("公主方形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "oval", IsEnabled = false, ImageName = "oval.png", ButtonName = MultilingualHelper.getString("椭圆形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "Emerald", IsEnabled = false, ImageName = "Emerald-shape.png", ButtonName = MultilingualHelper.getString("祖母绿形") }); |
|
buttonInfos.Add(new ButtonInfo() { Type = "Odd", IsEnabled = false, ImageName = "Odd-shaped.png", ButtonName = MultilingualHelper.getString("异形钻") }); |
|
return buttonInfos; |
|
} |
|
/// <summary> |
|
/// 获取钻石列表 |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public void InitDiamondList(object param) |
|
{ |
|
|
|
} |
|
|
|
/// <summary> |
|
/// 切换钻石类型(右侧列表) |
|
/// </summary> |
|
/// <param name="type">钻石类型</param> |
|
public void ChangeDiamondType(object type) |
|
{ |
|
if (type!= null) |
|
{ |
|
foreach (var item in Buttons.Where(x => x.Type == type)) |
|
{ |
|
item.IsHighlighted = true; |
|
}; |
|
List<ButtonViewModel> tempButtons2 = new List<ButtonViewModel>(); |
|
var bitmap = new BitmapImage(new Uri("pack://application:,,,/Resource/Images/round_P8-P8.png", UriKind.RelativeOrAbsolute)); |
|
ButtonViewModel button = new ButtonViewModel() { Text = "P8-P8", ImageSource = bitmap, Type = "round P8 P8", Command = StartGradingCommand }; |
|
tempButtons2.Add(button); |
|
Buttons2 = tempButtons2; |
|
} |
|
} |
|
public void StartGrading(object param) |
|
{ |
|
DoStartGrading(param); |
|
} |
|
|
|
/// <summary> |
|
/// 开始检测(对soc和算法开始通讯) |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public async void DoStartGrading(object param) |
|
{ |
|
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(); |
|
var tcs = new TaskCompletionSource<bool>(); |
|
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => { |
|
loading.Closed += (s, e) => tcs.SetResult(true); |
|
loading.ShowDialog(); |
|
} |
|
)); |
|
await Task.Run(async () => |
|
{ |
|
for (int i = 0; i <= 100; i++) |
|
{ |
|
// 模拟耗时操作 |
|
//System.Threading.Thread.Sleep(50); // 休眠50毫秒 |
|
await Task.Delay(5); |
|
// 更新进度条的值(需要在UI线程上执行) |
|
loading.Dispatcher.Invoke(() => |
|
{ |
|
loading.setValue(i); |
|
}); |
|
|
|
} |
|
// SocResultEntity socResolt = new SocResultEntity(); |
|
// AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
// // 启动soc |
|
// socResolt = DoSoc(); |
|
// // 启动算法 |
|
// parameter = DoAlgorithm(); |
|
|
|
//parameter = DoSoc(); |
|
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]; |
|
} |
|
parameter.DiamondCode = DiamondCode; |
|
GradingResult(parameter); |
|
}); |
|
await Task.Delay(5); |
|
loading.Close(); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 跳转至检测结果 |
|
/// </summary> |
|
/// <param name="param"></param> |
|
public void GradingResult(AlgorithmResultEntity param) |
|
{ |
|
|
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
BaseControlVM vm = new BaseControlVM(new GradingResultVM(param), MultilingualHelper.getString("DetectionResult")); |
|
vm.ShowFunctionButton = System.Windows.Visibility.Hidden; |
|
WindowManager.mainViewModel.Content = vm; |
|
WindowManager.openContent.Add(vm); |
|
} |
|
|
|
private AlgorithmResultEntity DoAlgorithm() |
|
{ |
|
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"; |
|
param = JsonConvert.DeserializeObject<AlgorithmResultEntity>(json); |
|
return param; |
|
} |
|
private SocResultEntity DoSoc() |
|
{ |
|
return new SocResultEntity(); |
|
} |
|
} |
|
public class ButtonInfo |
|
{ |
|
public string Type { get; set; } |
|
public string ImageName { get; set; } |
|
public string ButtonName { get; set; } |
|
public bool IsEnabled { get; set; } |
|
} |
|
public class ButtonViewModel : BaseViewModel |
|
{ |
|
private string _text; |
|
private BitmapImage _imageSource; |
|
private ICommand _command; |
|
private string _type; |
|
private int _col; |
|
private bool _isEnabled; |
|
private bool _isHighlighted; |
|
|
|
|
|
public string Text |
|
{ |
|
get { return _text; } |
|
set |
|
{ |
|
_text = value; |
|
OnPropertyChanged(nameof(Text)); |
|
} |
|
} |
|
|
|
public BitmapImage ImageSource |
|
{ |
|
get { return _imageSource; } |
|
set |
|
{ |
|
_imageSource = value; |
|
OnPropertyChanged(nameof(ImageSource)); |
|
} |
|
} |
|
|
|
public ICommand Command |
|
{ |
|
get { return _command; } |
|
set |
|
{ |
|
_command = value; |
|
OnPropertyChanged(nameof(Command)); |
|
} |
|
} |
|
public string Type |
|
{ |
|
get { return _type; } |
|
set |
|
{ |
|
_type = value; |
|
OnPropertyChanged(nameof(Type)); |
|
} |
|
} |
|
public int Column |
|
{ |
|
get { return _col; } |
|
set |
|
{ |
|
_col = value; |
|
OnPropertyChanged(nameof(Column)); |
|
} |
|
} |
|
public bool IsEnabled |
|
{ |
|
get { return _isEnabled; } |
|
set |
|
{ |
|
_isEnabled = value; |
|
OnPropertyChanged(nameof(IsEnabled)); |
|
} |
|
} |
|
public bool IsHighlighted |
|
{ |
|
get { return _isHighlighted; } |
|
set |
|
{ |
|
_isHighlighted = value; |
|
OnPropertyChanged(nameof(IsHighlighted)); |
|
} |
|
} |
|
} |