diff --git a/App.config b/App.config index 276f379..346b79c 100644 --- a/App.config +++ b/App.config @@ -18,7 +18,7 @@ - + diff --git a/LoginWindow.xaml.cs b/LoginWindow.xaml.cs index beb09fc..9ae2cc1 100644 --- a/LoginWindow.xaml.cs +++ b/LoginWindow.xaml.cs @@ -7,6 +7,7 @@ using System.Text; using System.Windows; using System.Windows.Input; using Microsoft.Win32; +using SparkClient.Model.Attributes; using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient; @@ -19,13 +20,23 @@ public partial class LoginWindow : Window WindowStartupLocation = WindowStartupLocation.CenterScreen; AccountTextBox.Text = Settings.SelectValueById("SAVE_ACCOUNT"); PasswordBox.Password = Settings.SelectValueById("SAVE_PASSWORD"); - TBlockAppVersion.Text = $"Version {ConfigurationHelper.ReadConfigValue("AppVersion")}"; + try + { + string version = AESHelper.Decrypt(ConfigurationHelper.ReadConfigValue("AppVersion")); + TBlockAppVersion.Text = $"Version {version}"; + } + catch + { + TBlockAppVersion.Text = $"Illegal Version"; + } + + //checkCUDA(); checkNvidia(); // 检测MSVCRuntime是否安装 checkMSVCRuntime(); } - + [Log] private void checkNvidia() { string nvidiaVersion = ""; @@ -90,7 +101,7 @@ public partial class LoginWindow : Window messageBox.Show(MultilingualHelper.getString("NotNvidia")); } } - + [Log] public static int CompareVersions(string versionA, string versionB) { int[] partsA = ParseVersion(versionA); @@ -110,6 +121,7 @@ public partial class LoginWindow : Window return 0; // 版本相同 } + [Log] private static int[] ParseVersion(string version) { string[] stringParts = version.Split('.'); @@ -126,6 +138,7 @@ public partial class LoginWindow : Window return intParts; } + [Log] private void checkCUDA() { try @@ -164,6 +177,7 @@ public partial class LoginWindow : Window Logger.Error("CUDA 安装检测错误:"+ ex); } } + [Log] private void checkMSVCRuntime() { try @@ -204,6 +218,7 @@ public partial class LoginWindow : Window Environment.Exit(0); // 退出程序 } } + [Log] private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed) @@ -211,12 +226,12 @@ public partial class LoginWindow : Window this.DragMove(); } } - + [Log] private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { AccountTextBox.Text = string.Empty; } - + [Log] private void CloseButton_OnClick(object sender, RoutedEventArgs e) { this.Close(); @@ -245,7 +260,7 @@ public partial class LoginWindow : Window this.Close(); #endif } - + [Log] private void savePassword() { if (IsRemberPassword.IsChecked ?? false) @@ -292,7 +307,7 @@ public partial class LoginWindow : Window }; PERMISSIONS.insert(); } - + [Log] private string getPassword(string userName) { string password = string.Empty; @@ -304,6 +319,7 @@ public partial class LoginWindow : Window } return password; } + [Log] private void PasswordBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index af84ac6..986891c 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -10,6 +10,7 @@ using HandyControl.Controls; using HandyControl.Tools; using log4net; using log4net.Config; +using SparkClient.Model.Attributes; using SparkClient.Model.Helper; using SparkClient.Model.Services; using SparkClient.ViewModel; @@ -30,7 +31,7 @@ public partial class MainWindow public MainWindow() { InitializeComponent(); - Logger.Info("Application started"); + var vm = DataContext as MainWindowViewModel; if (vm != null) { @@ -47,7 +48,7 @@ public partial class MainWindow } public static extern int GetDpiForSystem(); - + [Log] protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); diff --git a/Model/Attributes/LogAttribute.cs b/Model/Attributes/LogAttribute.cs index db47fe7..a83785b 100644 --- a/Model/Attributes/LogAttribute.cs +++ b/Model/Attributes/LogAttribute.cs @@ -18,15 +18,15 @@ namespace SparkClient.Model.Attributes { //Logger.Debug($"Entering {context.Method.DeclaringType?.Name}.{context.Method.Name}"); // 获取方法参数 - var parameters = context.Method.GetParameters(); - var arguments = context.Arguments; - - // 构建参数字符串 - var parameterLog = new StringBuilder(); - for (int i = 0; i < parameters.Length; i++) - { - parameterLog.Append($"{parameters[i].Name} = {arguments[i]}, "); - } + // var parameters = context.Method.GetParameters(); + // var arguments = context.Arguments; + // + // // 构建参数字符串 + // var parameterLog = new StringBuilder(); + // for (int i = 0; i < parameters.Length; i++) + // { + // parameterLog.Append($"{parameters[i].Name} = {arguments[i]}, "); + // } // 记录日志 //Logger.Debug($"Entering {context.Method.DeclaringType?.Name}.{context.Method.Name} with parameters: {parameterLog}"); diff --git a/Model/Helper/Common.cs b/Model/Helper/Common.cs index e36ec44..21566b6 100644 --- a/Model/Helper/Common.cs +++ b/Model/Helper/Common.cs @@ -11,9 +11,9 @@ public class Common public const string DatabasePwd = "DyumL4FvF6wVHWw"; - public const string AesKey = "JbI36Snd3s+QjlOcz5dytgkL5W6OnFEV5ZNRg/OYp58="; + public const string AesKey = "2AB6AA27B1302AEB747E952D5C5C73B9"; - public const string AesIV = "QRYL9P9NcV9Uny29DqEBqg=="; + public const string AesIV = "B1302AEB747E952D"; public static readonly string BasePath = AppDomain.CurrentDomain.BaseDirectory; diff --git a/SparkClient.sln.DotSettings.user b/SparkClient.sln.DotSettings.user index 322b3d7..018b7c3 100644 --- a/SparkClient.sln.DotSettings.user +++ b/SparkClient.sln.DotSettings.user @@ -1,12 +1,11 @@  - True + True + True ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -14,23 +13,25 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded - ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -38,20 +39,21 @@ ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded - ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -68,32 +70,36 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded - ForceIncluded ForceIncluded - ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded - ForceIncluded ForceIncluded ForceIncluded - ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -105,8 +111,9 @@ ForceIncluded ForceIncluded ForceIncluded - ForceIncluded + ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -114,4 +121,7 @@ ForceIncluded ForceIncluded ForceIncluded - ForceIncluded \ No newline at end of file + ForceIncluded + <AssemblyExplorer> + <Assembly Path="D:\WorkSpace\spark\SparkClient\bin\Debug\net8.0-windows\SparkDotNetCore.dll" /> +</AssemblyExplorer> \ No newline at end of file diff --git a/ViewModel/BaseWindow/BaseControlVM.cs b/ViewModel/BaseWindow/BaseControlVM.cs index be313e1..3432b84 100644 --- a/ViewModel/BaseWindow/BaseControlVM.cs +++ b/ViewModel/BaseWindow/BaseControlVM.cs @@ -1,12 +1,10 @@ using System.Windows; using System.Windows.Input; using GlobalHotKey; -using HandyControl.Controls; +using SparkClient.Model.Attributes; using SparkClient.Model.Helper; using SparkClient.Model.Services; using SparkClient.ViewModel.Grading; -using SparkClient.Views.Grading; -using MessageBox = SparkClient.Views.Dialog.MessageBox; namespace SparkClient.ViewModel.BaseWindow; public class BaseControlVM : BaseViewModel @@ -51,6 +49,7 @@ public class BaseControlVM : BaseViewModel /// /// 子页面 /// 子窗口标题 + public BaseControlVM(BaseViewModel vm, string windowTitle) { Content = vm; @@ -148,6 +147,7 @@ public class BaseControlVM : BaseViewModel /// 关闭并退回至上一个页面 /// /// + [Log] public async void CloseVM(object parameter) { if(Content is GradingResultVM) diff --git a/ViewModel/Configuration/AlgorithmConfigVM.cs b/ViewModel/Configuration/AlgorithmConfigVM.cs index 81bb648..03ba158 100644 --- a/ViewModel/Configuration/AlgorithmConfigVM.cs +++ b/ViewModel/Configuration/AlgorithmConfigVM.cs @@ -54,7 +54,7 @@ public class AlgorithmConfigVM : BaseViewModel InitAgileJsonConfig(); } - + [Log] private void InitAgileJsonConfig() { AgileJsonConfigEntities = new ObservableCollection(); @@ -79,6 +79,7 @@ public class AlgorithmConfigVM : BaseViewModel } } } + [Log] private bool CheckAndSaveAgileJson() { var finalSaveData = new ObservableCollection(); @@ -117,6 +118,7 @@ public class AlgorithmConfigVM : BaseViewModel return true; } + [Log] public string GetAlgorithmConfig(string param) { string sql = @"SELECT Mode, Shape, Spec, JsonKey, Value FROM AGILE_ALGORITHM_CONFIG"; @@ -205,7 +207,7 @@ public class AlgorithmConfigVM : BaseViewModel AgileJsonConfigEntities.Add(new AgileJsonConfigEntity(_jsonKeysBak)); }); - + [Log] private List GetNestedKeys(JToken token, string prefix = "") { var keys = new List(); @@ -292,6 +294,7 @@ public class AlgorithmConfigVM : BaseViewModel Logger.Error($"全局异常捕获:{ex.Message}",ex); } } + [Log] private void IsEnabledByRole (){ string PERMISSIONS = Settings.SelectValueById("PERMISSIONS"); if ("admin".Equals(PERMISSIONS)) diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index d04cc24..768e0f1 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -8,6 +8,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SparkClient.Model.Attributes; using SparkClient.Model.Common; using SparkClient.Model.Entity.ApiEntity; using SparkClient.Model.Extension; @@ -136,7 +137,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable /// /// 开始检测 /// - //[Log] + [Log] public async Task Start(int type = 0) { @@ -309,7 +310,8 @@ public class GradingLoadingVM : BaseViewModel,IDisposable } } - + + [Log] private async Task ReslutGen(Task detectTask) { bool hasErr = false; @@ -418,7 +420,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable } } } - + [Log] private async Task CompleteProgressSlowlyAsync() { // 缓慢完成剩余3%(总耗时保持原速度的3倍) @@ -433,7 +435,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable await Task.Delay(stepTime); } } - + [Log] private async Task CompleteProgressQuicklyAsync() { // 取消原进度任务 @@ -453,6 +455,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable await Task.Delay(stepTime/2); } } + [Log] private void UpdateProgress(int value) { // UI线程安全更新 @@ -461,6 +464,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable Progress = value; }); } + [Log] private void Stop(object param) { //询问?停止:忽略 @@ -484,7 +488,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable } } - + [Log] private async Task RunProgressAsync(CancellationToken token) { var configValue = ConfigurationHelper.ReadConfigValue("ProgressTime"); @@ -513,13 +517,13 @@ public class GradingLoadingVM : BaseViewModel,IDisposable }, token); } - + [Log] public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } - + [Log] protected virtual void Dispose(bool disposing) { if (_disposed) return; @@ -537,7 +541,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable _disposed = true; } - + [Log] private string getStandardName() { string sql = $"select\r\nRULE_NAME AS NAME,\r\nRULE_EN_NAME AS EN_NAME\r\nfrom\r\nsetting\r\nleft join rule\r\non setting.SETTING_P = rule.RULE_ID\r\nwhere\r\nsetting.SETTING_ID = 'RuleId'\r\n"; @@ -552,19 +556,21 @@ public class GradingLoadingVM : BaseViewModel,IDisposable } } #region 图片播放处理 - + [Log] public void LoadImages(string folderPath) { ImagePaths = Directory.GetFiles(folderPath, "*.bmp"); CurrentIndex = 0; CurrentStatus = PlayStatus.Stopped; } + [Log] public void LoadImages(List folderPath) { ImagePaths = folderPath.ToArray(); CurrentIndex = 0; CurrentStatus = PlayStatus.Stopped; } + [Log] private async Task HandlePlayControl() { switch (CurrentStatus) @@ -580,6 +586,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable break; } } + [Log] private async Task StartPlayback() { CurrentStatus = PlayStatus.Playing; @@ -602,19 +609,20 @@ public class GradingLoadingVM : BaseViewModel,IDisposable } catch (TaskCanceledException) { /* 正常取消处理 */ } } - + [Log] private void PausePlayback() { _cts?.Cancel(); CurrentStatus = PlayStatus.Paused; } - + [Log] private async Task ResumePlayback() { CurrentStatus = PlayStatus.Playing; _cts = new CancellationTokenSource(); await StartPlayback(); } + [Log] private void UpdateCurrentImage() { if (ImagePaths == null || CurrentIndex < 0 || CurrentIndex >= ImagePaths.Length) @@ -630,7 +638,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable CurrentImage = bitmap; OnPropertyChanged(nameof(CurrentImage)); } - + [Log] private void MovePrevious() { if (CurrentStatus == PlayStatus.Playing) @@ -638,7 +646,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable CurrentIndex = (CurrentIndex - 1 + ImagePaths.Length) % ImagePaths.Length; } - + [Log] private void MoveNext() { if (CurrentStatus == PlayStatus.Playing) diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 537ca20..d2560fc 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -331,7 +331,7 @@ public class GradingResultVM : BaseViewModel Logger.Error($"Auto Save Error: {ex.Message}"); } } - + [Log] private void saveTempDS(string selValue) { ConfigurationHelper.SetConfigValue("DSSet",selValue); @@ -391,6 +391,7 @@ public class GradingResultVM : BaseViewModel /// 参数列表测试内容获取 /// /// + [Log] private List GetTestItemList() { // DB 没关联 @@ -446,6 +447,7 @@ public class GradingResultVM : BaseViewModel } return ruleIdForSelect; } + [Log] private List GetCalGradeInfos(string item) { string ruleIdForSelect = getActualRuleId(); @@ -453,6 +455,7 @@ public class GradingResultVM : BaseViewModel List calGrades = DataBaseHelper.ExecuteQuery(sql); return calGrades; } + [Log] private List GetCalGradeInfos_SYM(string item) { string ruleIdForSelect = getActualRuleId(); @@ -696,6 +699,7 @@ public class GradingResultVM : BaseViewModel decimal.TryParse(min, out Min); return (Max-Min).ToString(); } + [Log] private double calSymValue(double Min, double Max, double Avg,bool isPercentage = true) { int c = 1; @@ -2505,7 +2509,7 @@ public class GradingResultVM : BaseViewModel e.Graphics.DrawString($"{MultilingualHelper.getString("DateOfIssue")}: {DateTime.Now:yyyy/M/d}", font, brush, new PointF(X, Y)); } - + [Log] private string GenerateTempExcelFile() { try diff --git a/Views/HelperPage.xaml.cs b/Views/HelperPage.xaml.cs index 09e3dce..f5ea13a 100644 --- a/Views/HelperPage.xaml.cs +++ b/Views/HelperPage.xaml.cs @@ -2,6 +2,7 @@ using System.Windows.Controls; using log4net; using Microsoft.Web.WebView2.Core; +using SparkClient.Model.Attributes; using SparkClient.Model.Helper; using SparkClient.ViewModel.Configuration; @@ -16,7 +17,7 @@ public partial class HelperPage InitializeWebView(); } - + [Log] private async void InitializeWebView() { try diff --git a/Views/UserControl/Viewport3D.xaml.cs b/Views/UserControl/Viewport3D.xaml.cs index baa61cc..f3f2aa9 100644 --- a/Views/UserControl/Viewport3D.xaml.cs +++ b/Views/UserControl/Viewport3D.xaml.cs @@ -19,6 +19,7 @@ using MathNet.Numerics; using System.Windows.Media; using GlobalHotKey; using NPOI.SS.Formula.Functions; +using SparkClient.Model.Attributes; using SparkClient.Model.Services; using MessageBox = SparkClient.Views.Dialog.MessageBox; using ObjExporter = SparkClient.Views.UserControl.ViewportData.Helper.ObjExporter; @@ -46,6 +47,7 @@ public partial class Viewport3D /// /// /// + [Log] private void Viewport3D_OnLoaded(object sender, RoutedEventArgs e) { ViewportManager.SetViewport3D(Viewport3Dx); @@ -148,6 +150,7 @@ public partial class Viewport3D /// /// /// + [Log] private void Viewport3Dx_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (ViewportManager.DoubleClickSelect == false) return; @@ -194,6 +197,7 @@ public partial class Viewport3D /// /// /// + [Log] private void BtnAngle_OnClick(object sender, RoutedEventArgs e) { var directionName = ((Button)sender).Name.ToString(); @@ -239,6 +243,7 @@ public partial class Viewport3D /// /// /// + [Log] private async void BtnFunction_OnClick(object sender, RoutedEventArgs e) { var directionName = ((Button)sender).Name.ToString(); @@ -296,6 +301,7 @@ public partial class Viewport3D /// /// /// + [Log] private void BtnDirection_OnClick(object sender, RoutedEventArgs e) { var directionName = ((Button)sender).Name.ToString(); @@ -351,7 +357,7 @@ public partial class Viewport3D // camera.UpDirection = new Vector3D(0, 1, 0); // 保持 Y 轴为上方向 } - + [Log] private void ShowArrowAndHeart(object sender, KeyPressedEventArgs e) { try @@ -445,6 +451,7 @@ public partial class Viewport3D /// /// /// + [Log] private void MenuItem_OnCheckedChanged(object sender, RoutedEventArgs e) { ViewportRightMenuSelectFaceFrame.IsEnabled = ViewportRightMenuSelectFace.IsChecked ; @@ -538,6 +545,7 @@ public partial class Viewport3D /// /// /// + [Log] private void MenuItem_OnClick(object sender, RoutedEventArgs e) { var controlName = ((MenuItem)sender).Name.ToString(); @@ -703,7 +711,7 @@ public partial class Viewport3D #endregion - + [Log] private void TbCustomizeRevolve_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { //Viewport3Dx.ShowCameraInfo = !Viewport3Dx.ShowCameraInfo; diff --git a/Views/UserControl/ViewportData/Helper/CommonHelper.cs b/Views/UserControl/ViewportData/Helper/CommonHelper.cs index 7b52e3b..0df816e 100644 --- a/Views/UserControl/ViewportData/Helper/CommonHelper.cs +++ b/Views/UserControl/ViewportData/Helper/CommonHelper.cs @@ -4,6 +4,7 @@ using System.Text; using System.Windows.Input; using Newtonsoft.Json; using SharpDX; +using SparkClient.Model.Attributes; using SparkClient.Views.UserControl.ViewportData.Entity; using SparkClient.Views.UserControl.ViewportData.Enum; @@ -11,18 +12,18 @@ namespace SparkClient.Views.UserControl.ViewportData.Helper; public class CommonHelper { - + [Log] public static bool IsTextNumeric(string text) { return int.TryParse(text, out _); // 只允许数字输入 } - + [Log] public static bool IsKeyNumeric(Key key) { // 判断按键是否是数字键 return (key >= Key.D0 && key <= Key.D9) || (key >= Key.NumPad0 && key <= Key.NumPad9); } - + [Log] public static Viewport3DTriangleEntity CreateByJsonStr(string json) { // 解析 JSON 数据 @@ -71,6 +72,7 @@ public class CommonHelper /// /// /// + [Log] public static string GenerateTriangleCode(Vector3 p1, Vector3 p2, Vector3 p3) { var concatenated = $"{p1.X},{p1.Y},{p1.Z};{p2.X},{p2.Y},{p2.Z};{p3.X},{p3.Y},{p3.Z}"; @@ -81,6 +83,7 @@ public class CommonHelper /// /// /// + [Log] private static string GenerateMd5Hash(string input) { using (var md5 = MD5.Create()) @@ -90,7 +93,7 @@ public class CommonHelper return string.Concat(hashBytes.Select(b => b.ToString("X2"))); } } - + [Log] public static string Color4ToHex(Color4 color) { int a = (int)(color.Alpha * 255); @@ -101,7 +104,7 @@ public class CommonHelper // 返回 Hex 字符串 return $"#{a:X2}{r:X2}{g:X2}{b:X2}"; } - + [Log] public static Color4 HexToColor4(string hex) { // 移除可能的前导 '#' @@ -123,7 +126,7 @@ public class CommonHelper throw new ArgumentException("Hex string must be in the format #AARRGGBB or #RRGGBB."); } } - + [Log] private static Color4 ConvertArgb(string hex) { // 解析 ARGB 组件 @@ -135,7 +138,7 @@ public class CommonHelper // 创建 Color4 对象,RGBA 的范围是 0 到 1,因此除以 255 return new Color4(r / 255f, g / 255f, b / 255f, a / 255f); } - + [Log] private static Color4 ConvertRgb(string hex) { // 解析 RGB 组件,Alpha 默认 255 diff --git a/Views/UserControl/ViewportData/Helper/ObjExporter.cs b/Views/UserControl/ViewportData/Helper/ObjExporter.cs index 3de32de..4a1dfed 100644 --- a/Views/UserControl/ViewportData/Helper/ObjExporter.cs +++ b/Views/UserControl/ViewportData/Helper/ObjExporter.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using HelixToolkit.SharpDX.Core; using SharpDX; +using SparkClient.Model.Attributes; using SparkClient.Views.UserControl.ViewportData.Entity; using SparkClient.Views.UserControl.ViewportData.Enum; @@ -9,6 +10,7 @@ namespace SparkClient.Views.UserControl.ViewportData.Helper; public class ObjExporter { + [Log] public static void ExportToObj2(List entities, string outputPath) { string obj = GenerateObj(entities); @@ -17,7 +19,7 @@ public class ObjExporter writer.Write(obj); } } - + [Log] public static string GenerateObj(IEnumerable triangles) { var groups = triangles.GroupBy(t => t.PlaneCode); @@ -122,6 +124,7 @@ public class ObjExporter /// /// 凸包排序(Andrew's Monotone Chain 算法) /// + [Log] private static List ConvexHullSort(List points) { if (points.Count <= 3) return points; @@ -152,6 +155,7 @@ public class ObjExporter /// /// 计算叉积 (p2-p0) × (p1-p0) /// + [Log] private static float Cross(Vector3 p0, Vector3 p1, Vector3 p2) { return (p1.X - p0.X) * (p2.Z - p0.Z) - (p1.Z - p0.Z) * (p2.X - p0.X); @@ -159,6 +163,7 @@ public class ObjExporter /// /// 计算面的法线(基于顶点顺序) /// + [Log] private static Vector3 CalculateFaceNormal(List vertices, Vector3 modelCenter) { // 使用前三个顶点计算初始法线 @@ -183,6 +188,7 @@ public class ObjExporter /// /// 计算顶点列表的中心点 /// + [Log] private static Vector3 GetCenter(List vertices) { var center = Vector3.Zero; diff --git a/Views/UserControl/ViewportData/Helper/RayHelper.cs b/Views/UserControl/ViewportData/Helper/RayHelper.cs index c48ef15..e6123cf 100644 --- a/Views/UserControl/ViewportData/Helper/RayHelper.cs +++ b/Views/UserControl/ViewportData/Helper/RayHelper.cs @@ -1,5 +1,6 @@ using System.Drawing; using System.Text; +using SparkClient.Model.Attributes; using SparkClient.Model.Helper; using SparkDotNetCore.ArrowAndHeart; using SparkDotNetCore.ArrowAndHeart.Entity; @@ -16,7 +17,7 @@ public class RayHelper private static string _image_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\Image\"; //unity渲染模型缓存(运行前清理) private static string _obj_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\Obj"; - + [Log] public static void GenerateRender(string modelInfo, string diamondCode) { string fileName = GenerateSignature(modelInfo, diamondCode); @@ -56,13 +57,13 @@ public class RayHelper } } - + [Log] private static string GenerateSignature(string modelInfo, string diamondCode) { // 模拟生成签名逻辑,可以自定义为更复杂的算法 return modelInfo; } - + [Log] private static void CleanDirectory(string path) { if (Directory.Exists(path)) @@ -130,7 +131,7 @@ public class RayHelper // } // } // } - + [Log] private static bool ValidateImages() { string heartImage = Path.Combine(_image_path, @"Heart.png"); @@ -138,7 +139,7 @@ public class RayHelper return File.Exists(heartImage) && File.Exists(arrowImage); } - + [Log] private static void ShowImages() { // 创建一个简单的图片展示窗口 diff --git a/Views/UserControl/ViewportData/Helper/VideoHelper.cs b/Views/UserControl/ViewportData/Helper/VideoHelper.cs index 464d2a6..d7a4e04 100644 --- a/Views/UserControl/ViewportData/Helper/VideoHelper.cs +++ b/Views/UserControl/ViewportData/Helper/VideoHelper.cs @@ -9,11 +9,13 @@ using System.IO; using System.Windows.Media.Imaging; using System.Drawing; using System.Windows; +using SparkClient.Model.Attributes; namespace SparkClient.Views.UserControl.ViewportData.Helper; public class VideoHelper { + [Log] public static void CreateVideoFromPngList(List pngEncoders, string outputPath) { string tempDirectory = Path.Combine(System.Environment.CurrentDirectory, "PngFrames"); @@ -72,7 +74,7 @@ public class VideoHelper Directory.Delete(tempDirectory, true); } } - + [Log] public static async Task CreateVideoFromPngListAsync(List pngEncoders, string outputPath) { string tempDirectory = Path.Combine(Environment.CurrentDirectory, "PngFrames"); @@ -140,7 +142,7 @@ public class VideoHelper Directory.Delete(tempDirectory, true); } } - + [Log] public static void ConvertMp4ToDat(string inputFilePath, string outputFilePath) { string ffmpegPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg.exe"); // Assuming ffmpeg.exe is in the same directory as the application @@ -162,7 +164,7 @@ public class VideoHelper File.Delete(outputFilePath); } - + [Log] public static async Task> StartGenerationAndRotation(Viewport3DX viewport) { @@ -175,7 +177,7 @@ public class VideoHelper return genPngTask.Result; } - + [Log] public static List GenPng(Viewport3DX viewport) { List result = new List(); @@ -191,7 +193,7 @@ public class VideoHelper return result; } - + [Log] public static async void RotateModel() { await Application.Current.Dispatcher.InvokeAsync(() => @@ -215,7 +217,7 @@ public class VideoHelper ViewportManager.DoubleClickSelect = !false; } - + [Log] public static PngBitmapEncoder CutPng(Viewport3DX viewport) { int width = (int)viewport.ActualWidth; diff --git a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs index b4e7ad5..9d4c2d8 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs @@ -22,6 +22,7 @@ using HelixToolkit.Wpf; using MeshBuilder = HelixToolkit.Wpf.SharpDX.MeshBuilder; using OrthographicCamera = HelixToolkit.Wpf.SharpDX.OrthographicCamera; using System.Windows.Input; +using SparkClient.Model.Attributes; using SparkClient.Model.Extension; using SparkClient.Model.Helper; using MessageBox = SparkClient.Views.Dialog.MessageBox; @@ -50,6 +51,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static MeshGeometryModel3D GenerateModelByEntity(Viewport3DX viewport, List entities, Color4? color = null) { var geometryModel = GenerateModelByEntity(entities, color); @@ -63,6 +65,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static MeshGeometryModel3D GenerateModelByEntity(List entities, Color4? color = null) { var meshBuilder = new MeshBuilder(true, false); @@ -111,6 +114,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List GenerateModelByEntityGroupByType(List entities) { var groupedDict = entities @@ -128,7 +132,7 @@ public class ViewportHelperPro } - + [Log] private static Color4? GenFaceColor4(PlaneType planeType) { switch (planeType) @@ -159,6 +163,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static void SaveViewportAsImage(Viewport3DX viewport, string filePath) { // 定义图像大小 @@ -179,7 +184,7 @@ public class ViewportHelperPro } } - + [Log] public static async Task ExportModelsToVideo(Viewport3DX viewport, string filePath) { if (viewport == null) @@ -197,6 +202,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static void ExportModelsToStl(Viewport3DX viewport, string filePath) { if (viewport == null) @@ -248,6 +254,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static async Task ExportModelsToStlASync(string filePath) { Viewport3DX viewport = ViewportManager.GetViewport3D(); @@ -310,7 +317,7 @@ public class ViewportHelperPro }).ConfigureAwait(false); } - + [Log] public static List ShowCenterTag(float lineLength = 0.5f) { List result = new List(); @@ -382,6 +389,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List GentrateLineByEntity(Viewport3DX viewport, List entities, Color4? color = null, double thickness = 1.0) { List result = GentrateLineByEntity(entities, ViewportManager.isUglyDiamond ? new Color4(new Color3(1f, 0,0)):color, thickness); @@ -397,6 +405,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List GentrateLineGirdleByEntity(List entities, Color4? color = null, double thickness = 1.0) { @@ -503,6 +512,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List GentrateLineByEntity(List entities, Color4? color = null, double thickness = 1.0) { List result = new List(); @@ -560,7 +570,7 @@ public class ViewportHelperPro return result; } - + [Log] public static List GenerateLineTextModelsByType(PlaneType type, Color4? textColor = null, bool showAll = false) { @@ -585,6 +595,7 @@ public class ViewportHelperPro /// 三角形集合 /// 指定数据集 /// + [Log] public static List GenerateLineTextModels(List entities, string valKey = "") { var result = new List(); @@ -1119,6 +1130,7 @@ public class ViewportHelperPro /// 三角形ID /// 生成范围 /// + [Log] public static List GentrateChosenView(string triangleCode, string valKey = "", params SelShowType[] selType) { var res = ViewportManager.ViewportTriangle.Find(e => triangleCode.Equals(e.TriangleCode)); @@ -1134,6 +1146,7 @@ public class ViewportHelperPro /// 生成范围 /// /// + [Log] public static List GentrateChosenView(Viewport3DTriangleEntity entity, string valKey = "", params SelShowType[] selType) { if (entity == null || entity.TriangleCode == null || entity.TriangleCode.Length == 0) @@ -1192,6 +1205,7 @@ public class ViewportHelperPro /// 文本颜色(默认红) /// 是否显示全部(默认否) /// + [Log] public static List GenerateLineAngleTextModels(List entities, Color4? textColor = null, bool showAll = false) { @@ -1245,6 +1259,7 @@ public class ViewportHelperPro /// 中心 /// 是否包含线 /// 旋转时间 秒 + [Log] public static void RotateModel(Vector3D axis, bool hasLine = true, int speed = 7, int to = 360) { ViewportManager.GetViewport().ViewportRightMenuShowModelFaceByType.IsChecked = false; @@ -1285,6 +1300,7 @@ public class ViewportHelperPro /// 文字 /// 位置 /// + [Log] public static BillboardTextModel3D DisplayText3D(string text, Vector3 position, Color4? color = null) { var billboardTextModel = new BillboardTextModel3D(); @@ -1308,6 +1324,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static BillboardTextModel3D DisplayText3D(string text, Vector3 position, Vector3 direction, Color4? color = null) { // 计算线段方向的角度 @@ -1342,6 +1359,7 @@ public class ViewportHelperPro /// 线颜色 /// 线粗细 默认1 /// + [Log] public static LineGeometryModel3D DisplayLineModel3D(List points, Color4 lineColor, double thickness = 1.0) { @@ -1364,6 +1382,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static HelixToolkit.Wpf.SharpDX.OrthographicCamera CalculateCamera(Vector3 positiveDirection, BoundingBox boundingBox, double fieldOfView = 45, double aspectRatio = 16.0 / 9.0) { // 单位化正方向 @@ -1409,6 +1428,7 @@ public class ViewportHelperPro /// 圆锥直径与圆柱直径的比例 1.5 /// 模型边界范围 1 /// + [Log] public static MeshGeometryModel3D CreateArrow( Vector3 cameraPosition, Vector3 modelCenter, @@ -1474,6 +1494,7 @@ public class ViewportHelperPro /// 线段颜色 /// 线段粗细 /// + [Log] public static LineGeometryModel3D DisplayLineModel3D(List> points, Color4 lineColor, double thickness = 1.0) { @@ -1506,6 +1527,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List GenerateLightingForModel(Viewport3DX viewport) { @@ -1582,7 +1604,7 @@ public class ViewportHelperPro result.ForEach(e => viewport.Items.Add(e)); return result; } - + [Log] public static Vector3 GetCenterOfTriangles(List triangles) { if (triangles == null || triangles.Count == 0) @@ -1603,7 +1625,7 @@ public class ViewportHelperPro // 计算平均坐标 return total / vertexCount; } - + [Log] public static Vector3 CalculateCenter(List girdleTopLines, List girdleBottomLines) { // 计算 GirdleTopLines 的中心点 @@ -1625,6 +1647,7 @@ public class ViewportHelperPro /// 删除视图中的照明 /// /// + [Log] public static void RemoveLightingInViewport(Viewport3DX viewport) { List lights = new List(); @@ -1648,6 +1671,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List ShowMeshLines(bool isCrown = true, double thickness = 0.5) { List lines = new(); @@ -1735,6 +1759,7 @@ public class ViewportHelperPro /// /// /// + [Log] private static void bindingMoveLine(LineGeometryModel3D lineA, LineGeometryModel3D lineB) { lineA.HitTestThickness = HitTestThickness; @@ -1752,6 +1777,7 @@ public class ViewportHelperPro private static Point startDragPoint = new Point(); private static Transform3D initialTransform; private static Transform3D initialOtherTransform; + [Log] private static void LineA_MouseMove3D(object sender, RoutedEventArgs e) { if (isDrawing) @@ -1869,13 +1895,14 @@ public class ViewportHelperPro } } // 检查点是否在范围内(距离大于 minDistance 且小于等于 radius) + [Log] private static bool IsPointInRange(Point3D point, Point3D center, double radius, double minDistance) { double distance = (point - center).Length; Logger.Info("距离:" + distance); return distance > minDistance && distance <= radius; } - + [Log] private static Point3D LimitToMaxPosition(Point3D center, double radius, Point3D currentCenter) { // 计算当前中心点与中心点的方向 @@ -1885,7 +1912,7 @@ public class ViewportHelperPro // 计算最大允许位置 return center + direction * radius; } - + [Log] private static void LineA_MouseUp3D(object sender, RoutedEventArgs e) { isDrawing = false; @@ -1893,7 +1920,7 @@ public class ViewportHelperPro Viewport.Cursor = Cursors.Arrow; startDragPoint = new Point(); } - + [Log] private static void LineA_MouseDown3D(object sender, RoutedEventArgs e) { isDrawing = true; @@ -1912,6 +1939,7 @@ public class ViewportHelperPro } } } + [Log] private static Point3D Get3DPointFromMouse(Point mousePosition) { // 使用 HelixToolkit 的 Ray3D 和 Plane3D @@ -1932,7 +1960,7 @@ public class ViewportHelperPro } return intersection.Value; } - + [Log] private static Ray3D GetRayFromMouse(Point mousePosition, Viewport3DX viewport) { // 将鼠标坐标转换为归一化设备坐标 (NDC) @@ -1951,7 +1979,7 @@ public class ViewportHelperPro // 返回射线 return new Ray3D(cameraPosition, ray); } - + [Log] private static Point3D? GetIntersection(Ray3D ray, Plane3D plane) { // 计算射线方向与平面法向量的点积 @@ -1971,7 +1999,7 @@ public class ViewportHelperPro // 返回交点 return ray.Origin + ray.Direction * t; } - + //private static Point3D? GetIntersection(Ray3D ray, Plane3D plane) //{ // // 将射线转换为直线(起点和终点) @@ -1987,6 +2015,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static LineGeometryModel3D ShowCircleLine(bool isCrown = true, double radius = 1.0, double thickness = 0.5) { var Y = -0.01F; @@ -2003,6 +2032,7 @@ public class ViewportHelperPro Circle.MouseMove3D += Circle_MouseMove3D; return Circle; } + [Log] private static LineGeometryModel3D UpdateCircleGeometry(Vector3 center, double radius = 1.0, double thickness = 1.0) { // 生成圆形线的点 @@ -2026,7 +2056,7 @@ public class ViewportHelperPro // 更新圆形线的几何形状 return Circle; } - + [Log] private static void Circle_MouseMove3D(object sender, RoutedEventArgs e) { if (isDrawing) @@ -2073,6 +2103,7 @@ public class ViewportHelperPro } } // 计算两点之间的距离 + [Log] private static double CalculateDistance(Point3D p1, Point3D p2) { double dx = p2.X - p1.X; @@ -2081,6 +2112,7 @@ public class ViewportHelperPro return Math.Sqrt(dx * dx + dy * dy + dz * dz); } + [Log] private static void Circle_MouseUp3D(object sender, RoutedEventArgs e) { isDrawing = false; @@ -2089,7 +2121,7 @@ public class ViewportHelperPro // 释放鼠标捕获 Viewport.ReleaseMouseCapture(); } - + [Log] private static void Circle_MouseDown3D(object sender, RoutedEventArgs e) { isDrawing = true; @@ -2102,6 +2134,7 @@ public class ViewportHelperPro Viewport.CaptureMouse(); } } + [Log] public static bool IsCrown() { bool isCrown = false; @@ -2119,6 +2152,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List VectorClockwiseSort(List points) { Vector3 center = GetCentroid(points); @@ -2131,6 +2165,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static List VectorClockwiseSort(List points, Vector3 center) { points.Sort((v1, v2) => @@ -2141,7 +2176,7 @@ public class ViewportHelperPro }); return points; } - + [Log] private static Vector3 GetCenter(List points) { float x = points.Average(p => p.X); @@ -2155,6 +2190,7 @@ public class ViewportHelperPro /// /// /// + [Log] public static Vector3 GetCentroid(List vectors) { float x = vectors.Sum(v => v.X) / vectors.Count; @@ -2162,6 +2198,7 @@ public class ViewportHelperPro float z = vectors.Sum(v => v.Z) / vectors.Count; return new Vector3(x, y, z); } + [Log] public static Vector3 GetOffsetCenter(List facetVector, Vector3 center, float dev = 0.4f) { // 1. 去重 facetVector @@ -2184,6 +2221,7 @@ public class ViewportHelperPro /// /// /// + [Log] private static float AngleBetween(Vector3 v1, Vector3 v2) { // 计算两个向量的点积 @@ -2208,19 +2246,20 @@ public class ViewportHelperPro // 返回角度,单位是度 return (float)(Math.Acos(cosTheta) * (180.0 / Math.PI)); } - + [Log] private static double GetBoundingBoxVolume(BoundingBox bound) { var size = bound.Size; return size.X * size.Y * size.Z; } - + [Log] private static Vector3 CalculateNormal(Vector3 p0, Vector3 p1, Vector3 p2) { var u = p1 - p0; var v = p2 - p0; return Vector3.Cross(u, v); } + [Log] private static bool IsLineSegmentParallelToYAxis(Tuple lineSegment,float epsilon = 0.001f) { Vector3 nowItem = lineSegment.Item1; @@ -2233,12 +2272,14 @@ public class ViewportHelperPro return false; // 不平行于 Y 轴 } // 计算两个点之间的距离 + [Log] private static float GetDistance(Vector3 point1, Vector3 point2) { return (float)Math.Sqrt(Math.Pow(point2.X - point1.X, 2) + Math.Pow(point2.Y - point1.Y, 2) + Math.Pow(point2.Z - point1.Z, 2)); } // 判断是否平行于Y轴的线段,返回较长或者较短的线段 + [Log] private static Tuple GetLongestOrShortestLineSegment(List facetPoints, bool returnLongest = true) { Tuple resultSegment = null; @@ -2269,7 +2310,7 @@ public class ViewportHelperPro return resultSegment; // 返回符合条件的线段 } - + [Log] private static Tuple GetLeftOrRightLineSegment(List facetPoints, bool isLeft = true) { @@ -2302,7 +2343,7 @@ public class ViewportHelperPro return resultSegment; // 返回符合条件的线段 } - + [Log] private static void CalculateLineSegmentStats(List> lines, out Tuple maxLine, out Tuple minLine, @@ -2334,6 +2375,7 @@ public class ViewportHelperPro /// 四边形的顶点列表 /// 是否返回最长的边线 /// 符合条件的边线,如果不存在则返回null + [Log] public static Tuple GetLeftParallelLineSegment( List facetPoints) { @@ -2365,7 +2407,7 @@ public class ViewportHelperPro } - + [Log] private static string ValueFormat(string value, string type, bool hasUnit = false) { if (double.TryParse(value, out var v) ) @@ -2403,7 +2445,7 @@ public class ViewportHelperPro return "--"; } - + [Log] private static Vector3? CalculateIntersection( Tuple line1, Tuple line2) @@ -2446,7 +2488,7 @@ public class ViewportHelperPro return new Vector3(x, maxY, z); } #endregion - + [Log] private static bool FactoryShowTextCheck(string diamondType, PlaneType planeType) { Dictionary> stepPlaneMappings = new() @@ -2467,7 +2509,7 @@ public class ViewportHelperPro } return allowedTypes.Contains(planeType); } - + [Log] private static string[] GetAlgorithmParam(string diamondType, PlaneType planeType) { Dictionary> stepPlaneMappings = new() @@ -2516,7 +2558,7 @@ public class ViewportHelperPro return []; } - + [Log] private static float DisplacementCalculations(PlaneType planeType, float vol = 0.4f) { switch (planeType) diff --git a/Views/UserControl/ViewportData/Helper/ViewportManager.cs b/Views/UserControl/ViewportData/Helper/ViewportManager.cs index 79a035d..7d3a07c 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportManager.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportManager.cs @@ -6,6 +6,7 @@ using HelixToolkit.Wpf.SharpDX; using MathNet.Numerics; using SharpDX; using SharpDX.Direct3D11; +using SparkClient.Model.Attributes; using SparkClient.Views.Dialog; using SparkClient.Views.UserControl.ViewportData.Entity; using SparkClient.Views.UserControl.ViewportData.Enum; @@ -306,6 +307,7 @@ public class ViewportManager #region 统一控制方法 public static MeshGeometryModel3D PointTowardsTheFrontModel = new MeshGeometryModel3D(); + [Log] public static void PointTowardsTheFront(bool isPoint) { if (isPoint) @@ -321,6 +323,7 @@ public class ViewportManager } public static MeshGeometryModel3D MarkFacesModel = new MeshGeometryModel3D(); + [Log] public static void MarkSpecificFaces(bool isMark) { if (isMark) @@ -339,6 +342,7 @@ public class ViewportManager /// /// /// + [Log] public static void LoadModelByEntities(List entities) { if (entities.Count == 0 && ViewportTriangle.Count != 0) diff --git a/Views/UserControl/ViewportData/ViewportData.cs b/Views/UserControl/ViewportData/ViewportData.cs index 8b8480c..69f6ccf 100644 --- a/Views/UserControl/ViewportData/ViewportData.cs +++ b/Views/UserControl/ViewportData/ViewportData.cs @@ -1,5 +1,6 @@ using System.Text.Json.Nodes; using SharpDX; +using SparkClient.Model.Attributes; using SparkClient.Model.Extension; using SparkClient.Model.Helper; using SparkClient.Views.UserControl.ViewportData.Entity; @@ -49,7 +50,7 @@ public class ViewportData public ViewportData() { } - + [Log] public void LoadData() { JsonNode? json = null; @@ -169,7 +170,7 @@ public class ViewportData } } - + [Log] public async Task SaveAsToStlFile(string filename) { try @@ -182,7 +183,7 @@ public class ViewportData return ; } } - + [Log] public async Task SaveAsToVedioFile(string filename) { try @@ -195,7 +196,7 @@ public class ViewportData return ; } } - + [Log] public bool ConvertMp4ToDat(string mp4FilePath, string datFilePath) {