diff --git a/App.config b/App.config index fcec6ad..ab3535c 100644 --- a/App.config +++ b/App.config @@ -14,7 +14,8 @@ - + + diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml index 46432fb..9dc7086 100644 --- a/Language/zh_CN.xaml +++ b/Language/zh_CN.xaml @@ -224,4 +224,8 @@ 图像渲染异常: 仿真心箭图预览 仿真心箭图为模拟渲染,实际请以切工镜观测为准。 + + 未找到Nvidia显卡驱动,部分功能可能无法正常运行。 + Nvidia显卡驱动版本过旧,请尝试升级显卡驱动。(当前:%version,最低:528.33) + \ No newline at end of file diff --git a/LoginWindow.xaml.cs b/LoginWindow.xaml.cs index 5ae565a..7a72000 100644 --- a/LoginWindow.xaml.cs +++ b/LoginWindow.xaml.cs @@ -5,6 +5,7 @@ using System.Data; using System.Diagnostics; using System.Windows; using System.Windows.Input; +using Microsoft.Win32; using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient; @@ -17,11 +18,42 @@ public partial class LoginWindow : Window WindowStartupLocation = WindowStartupLocation.CenterScreen; AccountTextBox.Text = Settings.SelectValueById("SAVE_ACCOUNT"); PasswordBox.Password = Settings.SelectValueById("SAVE_PASSWORD"); - checkCUDA(); + //checkCUDA(); + checkNvidia(); // 检测MSVCRuntime是否安装 checkMSVCRuntime(); } + private void checkNvidia() + { + string nvidiaVersion = ""; + const string regPath = @"SOFTWARE\NVIDIA Corporation\Global\NVSMI"; + const string keyName = "DisplayDriverVersion"; + + try + { + // 针对 64 位系统访问注册表 + using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) + using (var key = baseKey.OpenSubKey(regPath)) + { + if (key != null) + { + var value = key.GetValue(keyName)?.ToString(); + nvidiaVersion = !string.IsNullOrEmpty(value) ? value : "未找到驱动版本"; + } + } + } + catch (Exception ex) + { + nvidiaVersion = ex.Message; + Logger.Error("Nvidia检测错误:"+ ex); + } + + MessageBox messageBox = new MessageBox(); + messageBox.Show(nvidiaVersion); + + } + private void checkCUDA() { try diff --git a/Model/Entity/ApiEntity/StatusCodes.cs b/Model/Entity/ApiEntity/StatusCodes.cs index 24f3c97..97948d8 100644 --- a/Model/Entity/ApiEntity/StatusCodes.cs +++ b/Model/Entity/ApiEntity/StatusCodes.cs @@ -1,4 +1,6 @@ -namespace SparkClient.Model.Common +using System.Reflection; + +namespace SparkClient.Model.Common { /// /// 存储状态码及其描述信息的常量类。 @@ -48,5 +50,26 @@ // 检测到钻石需进行清洁 public const string Recheck = "P021"; + + public static string GetConstantNameByValue(string value) + { + // 获取 StatusCodes 类型信息 + var type = typeof(StatusCodes); + + // 遍历所有公共静态常量字段 + foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)) + { + // 确保是字符串类型的常量 + if (field.IsLiteral && !field.IsInitOnly && field.FieldType == typeof(string)) + { + // 获取字段值并比较 + if ((string)field.GetValue(null) == value) + { + return field.Name; + } + } + } + return null; // 未找到时返回 null + } } } \ No newline at end of file diff --git a/Model/Helper/ConfigurationHelper.cs b/Model/Helper/ConfigurationHelper.cs index d6579bd..26705d0 100644 --- a/Model/Helper/ConfigurationHelper.cs +++ b/Model/Helper/ConfigurationHelper.cs @@ -5,7 +5,11 @@ namespace SparkClient.Model.Helper; public class ConfigurationHelper { static System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); - + /// + /// 读取配置Key + /// + /// + /// public static string ReadConfigValue(string key) { @@ -13,7 +17,11 @@ public class ConfigurationHelper return name; } - + /// + /// 写入配置 + /// + /// + /// public static void SetConfigValue(string key, string value) { config.AppSettings.Settings[key].Value = value; diff --git a/SparkClient.csproj b/SparkClient.csproj index 8f16ae0..058b24d 100644 --- a/SparkClient.csproj +++ b/SparkClient.csproj @@ -252,6 +252,11 @@ Wpf Designer + + MSBuild:Compile + Wpf + Designer + diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index b57cc37..752de0d 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -10,7 +10,6 @@ using System.Windows; using System.Windows.Input; using System.Windows.Media.Imaging; using System.Windows.Threading; -using Microsoft.Data.Sqlite; using SparkClient.Model.Entity; using SparkClient.Model.Services; using System.Text; @@ -21,8 +20,6 @@ using Newtonsoft.Json.Linq; using SparkClient.Model.Common; using Color = System.Windows.Media.Color; using MessageBox = SparkClient.Views.Dialog.MessageBox; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices.JavaScript; using SparkClient.Model.Attributes; namespace SparkClient.ViewModel.Grading; @@ -155,6 +152,12 @@ public class DiamondSelectVM : BaseViewModel { 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 () => { @@ -171,7 +174,7 @@ public class DiamondSelectVM : BaseViewModel } // 模拟耗时操作 //System.Threading.Thread.Sleep(50); // 休眠50毫秒 - await Task.Delay(515); + await Task.Delay(setpTime); loading.setValue(i); progress = i; } @@ -251,7 +254,9 @@ public class DiamondSelectVM : BaseViewModel 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 { diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index f3f9c03..60415f3 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -32,6 +32,7 @@ using System.Windows.Media; using Brush = System.Drawing.Brush; using Brushes = System.Drawing.Brushes; using SparkClient.Model.Attributes; +using SparkClient.Model.Common; using PaperSize = System.Drawing.Printing.PaperSize; namespace SparkClient.ViewModel.Grading; @@ -185,6 +186,7 @@ public class GradingResultVM : BaseViewModel InitView(algorithmResult); machine = algorithmResult.DeviceId; username = Settings.SelectValueById("PERMISSIONS"); + if (ruleId.StartsWith("IGI")) { IsEnabled = true; @@ -193,7 +195,11 @@ public class GradingResultVM : BaseViewModel { IsEnabled = false; } + + if (algorithmResult.status.Equals(StatusCodes.Recheck)) IsEnabled = false; + } + DS = ConfigurationManager.AppSettings["DSSet"]; if (IsEnabled) { diff --git a/Views/BaseWindow/BaseControl.xaml b/Views/BaseWindow/BaseControl.xaml index 5402642..f955eb5 100644 --- a/Views/BaseWindow/BaseControl.xaml +++ b/Views/BaseWindow/BaseControl.xaml @@ -77,7 +77,7 @@ diff --git a/Views/BaseWindow/BaseControl.xaml.cs b/Views/BaseWindow/BaseControl.xaml.cs index a084aa9..8122e72 100644 --- a/Views/BaseWindow/BaseControl.xaml.cs +++ b/Views/BaseWindow/BaseControl.xaml.cs @@ -21,6 +21,9 @@ public partial class BaseControl FocusManager.SetFocusedElement(this, this); Keyboard.Focus(this); + #if DEBUG + tbTitle.Text = tbTitle.Text + " -【测试版】"; + #endif } private void Border_Minimize_MouseEnter(object sender, MouseEventArgs e) diff --git a/Views/Grading/GradingLoading.xaml b/Views/Grading/GradingLoading.xaml new file mode 100644 index 0000000..03b840d --- /dev/null +++ b/Views/Grading/GradingLoading.xaml @@ -0,0 +1,785 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Views/Grading/GradingLoading.xaml.cs b/Views/Grading/GradingLoading.xaml.cs new file mode 100644 index 0000000..f98d061 --- /dev/null +++ b/Views/Grading/GradingLoading.xaml.cs @@ -0,0 +1,297 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Forms.VisualStyles; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using log4net; +using SparkClient.ViewModel.Grading; +using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D; + +namespace SparkClient.Views.Grading; + +public partial class GradingLoading +{ + private static readonly ILog Logger = LogManager.GetLogger(typeof(GradingResult)); + + // List triangles = new List(); + List mouseAddModels = new List(); + + // 用于记录当前所有已存在的Popup + private List _allPopups = new List(); + public GradingLoading() + { + InitializeComponent(); + + // 在Window最外层捕获鼠标点击,判断是否点击在Popup之外,如果是则关闭所有Popup + this.PreviewMouseLeftButtonDown += Window_PreviewMouseLeftButtonDown; + //DataContext = new GradingResultVM(null); + + // this.Viewport3Dx.EffectsManager = new DefaultEffectsManager(); + // this.Viewport3Dx.Camera = new PerspectiveCamera() + // { + // Position = new Point3D(0, 0, 5), + // LookDirection = new Vector3D(0, 0, -1), + // UpDirection = new Vector3D(0, 1, 0), + // FarPlaneDistance = 1000, + // NearPlaneDistance = 0.1 + // }; + + // Loaded += (sender, args) => + // { + // var entities = Viewport3DHelper.InitDemo(Viewport3Dx); + // triangles.AddRange(entities); + // }; + } + + + /// + /// 点击模型 + /// + /// + /// + private void Viewport3Dx_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + // // 获取鼠标点击位置 + // var mousePosition = e.GetPosition(Viewport3Dx); + // + // // 查找鼠标点击的 3D 对象 + // var hits = Viewport3Dx.FindHits(mousePosition); + // + // // 如果没有命中任何 3D 对象 + // if (hits == null || hits.Count == 0) + // { + // Console.WriteLine("未点击到任何模型"); + // foreach (var item in mouseAddModels) + // { + // Viewport3Dx.Items.Remove(item); + // } + // mouseAddModels.Clear(); + // return; + // } + // + // // 获取第一个命中的对象 + // var hit = hits[0]; + // + // // 检查是否是 MeshGeometryModel3D + // if (hit.ModelHit is MeshGeometryModel3D modelHit) + // { + // foreach (var item in mouseAddModels) + // { + // Viewport3Dx.Items.Remove(item); + // } + // mouseAddModels.Clear(); + // // 获取几何信息 + // var geometry = modelHit.Geometry as MeshGeometry3D; + // if (geometry != null) + // { + // // 获取命中的三角形索引 + // var triangleIndex = hit.TriangleIndices; + // + // // 获取三角形顶点 + // var vertex1 = geometry.Positions[triangleIndex.Item1]; + // var vertex2 = geometry.Positions[triangleIndex.Item2]; + // var vertex3 = geometry.Positions[triangleIndex.Item3]; + // + // string strPoint = vertex1.X + ","+ vertex1.Y+","+ vertex1.Z + ";"+ vertex2.X + ","+ vertex2.Y + ","+ vertex2.Z+";"+vertex3.X + ","+ vertex3.Y + ","+ vertex3.Z; + // string triangleCode = Viewport3DTriangleEntity.GenerateMD5Hash(strPoint); + // + // //命中实体 + // Viewport3DTriangleEntity res = triangles.Find(e => triangleCode.Equals(e.TriangleCode)); + // + // if (res == null) + // return; + // + // //命中面 + // List facet = triangles.Where(e => res.PlaneCode.Equals(e.PlaneCode)).ToList(); + // var colorFacet = new Color4(1.0f, 1.0f, 0.0f, 1.0f); + // var data1 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facet,colorFacet); + // mouseAddModels.AddRange(data1); + // //命中面标线 + // var data2 = Viewport3DHelper.GenerateLineTextModelByEntity(Viewport3Dx, facet); + // mouseAddModels.AddRange(data2); + // //命中同类面 + // List facetType = triangles.Where(e => res.PlaneType.Equals(e.PlaneType)).ToList(); + // //排除自己 + // facet.ForEach(e=>facetType.Remove(e)); + // var colorFacetType = new Color4(0.9f, 0.9f, 0.7f, 1.0f); + // var data3 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facetType,colorFacetType); + // mouseAddModels.AddRange(data3); + // } + // } + // else + // { + // Console.WriteLine("点击的对象不是 MeshGeometryModel3D"); + // } + } + + private void ChangSymLevel(object sender, SelectionChangedEventArgs e) + { + var d = DataContext as GradingResultVM; + d.ChangeSym(null); + } + + // private void dataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + // { + // detailPopup.IsOpen = false; + // // 获取点击的目标元素 + // var element = sender as FrameworkElement; + // + // var cell = FindVisualParent(element); + // if (cell == null) return; + // + // var row = FindVisualParent(cell); + // if (row == null) return; + // + // if (element != null) + // { + // // 将 firstCell 的边界转换为屏幕坐标系 + // var firstCellBounds = cell.PointToScreen(new Point(0, 0)); + // + // // 计算Popup的位置 + // var popupPosition = new Point(firstCellBounds.X + cell.RenderSize.Width, firstCellBounds.Y + cell.RenderSize.Height); + // var selectObject = row.Item as DataInfo; + // string testItemId = selectObject.TestItemId; + // var d = DataContext as GradingResultVM; + // RowDetail rowDetail = d.getSelectData(testItemId); + // // 设置Popup的位置 + // detailPopup.HorizontalOffset = popupPosition.X; + // detailPopup.VerticalOffset = popupPosition.Y; + // detailPopup.IsOpen = true; + // RowDetail.Items.Clear(); + // RowDetail.Items.Add(rowDetail); + // } + // } + // 辅助方法:查找父元素 + private T FindVisualParent(DependencyObject child) where T : DependencyObject + { + var parentObject = VisualTreeHelper.GetParent(child); + if (parentObject == null) return null; + + if (parentObject is T parent) + { + return parent; + } + else + { + return FindVisualParent(parentObject); + } + } + // private void Window_MouseDown(object sender, MouseButtonEventArgs e) + // { + // detailPopup.IsOpen = false; + // } + // + // private void Window_MouseDown(object sender, RoutedEventArgs e) + // { + // detailPopup.IsOpen = false; + // } + + + private void ClickArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + var border = sender as Border; + if (border == null) return; + + var parentGrid = border.Parent as Grid; + if (parentGrid == null) return; + + var popup = parentGrid.FindName("RowPopup") as Popup; + if (popup == null) return; + popup.DataContext = this.DataContext; + // 先关闭所有已显示的 Popup + CloseAllPopups(); + + var oo = FindVisualParent(parentGrid); + if(oo == null) return; + var d = DataContext as GradingResultVM; + RowDetail rowDetail = d.getSelectData((oo.Item as DataInfo).TestItemId); + + if (!_allPopups.Contains(popup)) + { + _allPopups.Add(popup); + } + + // 显示新Popup + popup.IsOpen = true; + popup.Visibility = Visibility.Visible; + } + + private void CloseAllPopups() + { + foreach (var p in _allPopups) + { + p.IsOpen = false; + p.Visibility = Visibility.Collapsed; + } + } + + private void CloseAllPopup_Click(object sender, RoutedEventArgs e) + { + CloseAllPopups(); + } + + private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + // originalSource 是点击处的控件 + var clickedElement = e.OriginalSource as DependencyObject; + + // 遍历所有已知 Popup + bool isClickOnAnyPopup = false; + foreach (var p in _allPopups) + { + // 如果此 Popup 不可见或未打开,就不用检查了 + if (!p.IsOpen) + continue; + + // 判断点击处是否在此 Popup 内 + if (IsDescendantOf(p.Child, clickedElement)) + { + // 找到一个 Popup 包含这个点击 + isClickOnAnyPopup = true; + break; + } + } + + // 如果没点击到任何 Popup,就关闭全部 + if (!isClickOnAnyPopup) + { + CloseAllPopups(); + } + } + private bool IsDescendantOf(DependencyObject parent, DependencyObject clicked) + { + if (parent == null || clicked == null) + return false; + + // 从 clicked 开始不断向上找 VisualTree + var current = clicked; + while (current != null) + { + if (current == parent) + { + return true; + } + current = VisualTreeHelper.GetParent(current); + } + return false; + } + + + private void UIElement_OnMouseLeave(object sender, MouseEventArgs e) + { + if (sender is Image image) + { + image.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resource/Images/UIResource/01-8.png")); + } + } + + private void UIElement_OnMouseEnter(object sender, MouseEventArgs e) + { + if (sender is Image image) + { + image.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resource/Images/UIResource/01-8-1.png")); + } + } +} \ No newline at end of file diff --git a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs index 9234eab..01de774 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs @@ -311,7 +311,7 @@ public class ViewportHelperPro /// public static List GentrateLineByEntity(Viewport3DX viewport, List entities, Color4? color = null, double thickness = 1.0) { - List result = GentrateLineByEntity(entities, color, thickness); + List result = GentrateLineByEntity(entities, ViewportManager.isUglyDiamond ? new Color4(new Color3(1f, 0,0)):color, thickness); result.ForEach(e => viewport.Items.Add(e)); return result; } diff --git a/Views/UserControl/ViewportData/Helper/ViewportManager.cs b/Views/UserControl/ViewportData/Helper/ViewportManager.cs index 4a46201..e6de322 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportManager.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportManager.cs @@ -15,6 +15,8 @@ namespace SparkClient.Views.UserControl.ViewportData.Helper; public class ViewportManager { + + public static bool isUglyDiamond = false; /// /// 视图中三角形实体们 /// diff --git a/Views/UserControl/ViewportData/ViewportData.cs b/Views/UserControl/ViewportData/ViewportData.cs index 3400c71..59cb4db 100644 --- a/Views/UserControl/ViewportData/ViewportData.cs +++ b/Views/UserControl/ViewportData/ViewportData.cs @@ -145,6 +145,15 @@ public class ViewportData facetsFinal.Add(item); } + if (json["status"].ToString().Equals("P021")) + { + ViewportManager.isUglyDiamond = true; + } + else + { + ViewportManager.isUglyDiamond = false; + } + ViewportManager.ViewportTriangle.Clear(); ViewportManager.ViewportTriangle.AddRange(facetsFinal); ViewportManager.ColorConfig = ColorConfig;