sunhonglei 5 months ago
commit d622e88016
  1. 5
      Language/zh_CN.xaml
  2. 4
      Model/Helper/DataBaseHelper.cs
  3. 4
      Model/Helper/MultilingualHelper.cs
  4. 8
      Model/Services/AlgorithmServer.cs
  5. 11
      Model/Services/SOCClientService.cs
  6. 8
      ViewModel/BaseWindow/HomeWindowVM.cs
  7. 53
      Views/UserControl/Viewport3D.xaml.cs

@ -189,4 +189,9 @@
<sys:String x:Key="ImageFileReadFailure">图片文件读取失败</sys:String>
<sys:String x:Key="JsonParseFailure">JSON解析失败</sys:String>
<sys:String x:Key="ApplicationError">应用程序出现错误:</sys:String>
</ResourceDictionary>

@ -146,7 +146,7 @@ public class DataBaseHelper
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
System.Windows.MessageBox.Show($"应用程序出现错误:{ex.Message}");
System.Windows.MessageBox.Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}");
}
return null;
}
@ -201,7 +201,7 @@ public class DataBaseHelper
catch (Exception ex)
{
Logger.Error($"全局异常捕获:{ex.Message}", ex);
System.Windows.MessageBox.Show($"应用程序出现错误:{ex.Message}");
System.Windows.MessageBox.Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}");
}
return null;
}

@ -65,13 +65,13 @@ public class MultilingualHelper
else
{
// 如果未找到对应的资源字典,给出提示信息
MessageBox.Show($"未找到与 {resourceKey} 对应的资源字典,请检查资源配置。");
MessageBox.Show($"We could not find the {resourceKey} resource, check the multi-language configuration");
}
}
else
{
// 如果未找到对应的资源字典(根据传入的resourceKey),给出提示信息
MessageBox.Show($"未找到对应 {resourceKey} 的资源字典,请检查App.xaml中的资源配置。");
MessageBox.Show($"We could not find the {resourceKey} resource, check the multi-language configuration");
}

@ -1,6 +1,7 @@
using System.Data;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SparkClient.Model.Entity.ApiEntity;
@ -10,7 +11,7 @@ namespace SparkClient.Model.Services
{
public class AlgorithmServer
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
// 导入 C++ DLL 中的 DetectDiamond 函数
[DllImport("diamond_cut_inspector.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr DetectDiamond(string jsonData);
@ -89,12 +90,15 @@ namespace SparkClient.Model.Services
// 记录日志或处理异常
Console.WriteLine($"Error in CallParseJsonAndReturnActions: {ex.Message}");
Console.WriteLine($"Stack Trace: {ex.StackTrace}");
Logger.Error($"Error in CallParseJsonAndReturnActions: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
// 如果有 InnerException,打印出来
if (ex.InnerException != null)
{
Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
Console.WriteLine($"Inner Stack Trace: {ex.InnerException.StackTrace}");
Logger.Error($"Inner Exception: {ex.InnerException.Message}");
Logger.Error($"Inner Stack Trace: {ex.InnerException.StackTrace}");
}
// 返回一个默认的 AlgorithmResultEntity 对象表示解析失败
MessageBox.Show(ex.Message);

@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using HandyControl.Tools.Extension;
using log4net;
using SparkClient.Model.Common;
using SparkClient.Model.Entity.ApiEntity;
using SparkClient.Model.Helper;
@ -20,7 +21,9 @@ namespace SparkClient.Model.Services
{
// Log地址
private const string LogFilePath = @"..\..\..\Resource\Document\log.txt";
private static readonly ILog Logger = LogManager.GetLogger(typeof(SOCClientService));
/// <summary>
/// 基础URL,用于构建完整的API请求地址。
/// </summary>
@ -115,6 +118,7 @@ namespace SparkClient.Model.Services
{
// 记录日志或进行其他处理
Console.WriteLine($"Error in DoSoc: {ex.Message}");
Logger.Warn($"Error in DoSoc: {ex.Message}");
// 或者使用日志框架记录日志
// logger.LogError(ex, "Error in DoSoc method.");
return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() , DeviceId = ""};
@ -170,6 +174,7 @@ namespace SparkClient.Model.Services
default:
// 其他状态码,记录警告并继续
Console.WriteLine($"Unexpected status code: {status} for URL: {url}");
Logger.Warn($"Unexpected status code: {status} for URL: {url}");
imageIndex++;
break;
}
@ -178,6 +183,7 @@ namespace SparkClient.Model.Services
{
// 捕获HTTP请求异常并记录错误信息
Console.WriteLine($"HTTP request failed for URL: {url}, Exception: {ex.Message}");
Logger.Error($"HTTP request failed for URL: {url}, Exception: {ex.Message}");
imageNames.Clear();
return imageNames;
}
@ -185,6 +191,7 @@ namespace SparkClient.Model.Services
{
// 捕获其他异常并记录错误信息,结束循环
Console.WriteLine($"An unexpected error occurred for URL: {url}, Exception: {ex.Message}");
Logger.Error($"An unexpected error occurred for URL: {url}, Exception: {ex.Message}");
imageNames.Clear();
return imageNames;
}
@ -274,7 +281,7 @@ namespace SparkClient.Model.Services
// 日志记录
// logger.Error(e, "发生异常");
string logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] 发生异常: {e.Message}{Environment.NewLine}";
File.AppendAllText(LogFilePath, logMessage);
Logger.Error(logMessage);
return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() };
}
}

@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Input;
using log4net;
using SparkClient.Model.Helper;
using SparkClient.Model.Services;
using SparkClient.ViewModel.Configuration;
@ -10,7 +11,7 @@ namespace SparkClient.ViewModel.BaseWindow;
public class HomeWindowVM : BaseViewModel
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(HomeWindowVM));
private SOCClientService _socClientService;
public ICommand ShowHelperPageCommand { get; }
@ -74,7 +75,7 @@ public class HomeWindowVM : BaseViewModel
{
// 记录日志
LogError(e);
ShowMessage("错误: " + e.Message);
ShowMessage("Error: " + e.Message);
}
}
@ -87,7 +88,8 @@ public class HomeWindowVM : BaseViewModel
private void LogError(Exception e)
{
// 实现日志记录逻辑,例如写入文件或数据库
Console.WriteLine($"Error: {e.Message}\n{e.StackTrace}");
// Console.WriteLine($"Error: {e.Message}\n{e.StackTrace}");
Logger.Error($"Error: {e.Message}\n{e.StackTrace}");
}

@ -202,67 +202,56 @@ public partial class Viewport3D
private void BtnDirection_OnClick(object sender, RoutedEventArgs e)
{
var directionName = ((Button)sender).Name.ToString();
var directionValue = (int)TbCustomizeRevolve.Value;
var directionValue = (int)TbCustomizeRevolve.Value; // 旋转角度(单位:度)
if (directionValue == 0) return;
// 获取当前相机和模型中心
var camera = Viewport3Dx.Camera as HelixToolkit.Wpf.SharpDX.PerspectiveCamera;
if (camera == null) return;
var modelCenter = ViewportManager.CenterVector;
var modelCenter = ViewportManager.CenterVector; // 模型中心
var currentPosition = camera.Position;
// 将相机位置转换为极坐标
var dx = currentPosition.X - modelCenter.X;
var dy = currentPosition.Y - modelCenter.Y;
var dz = currentPosition.Z - modelCenter.Z;
var radius = Math.Sqrt(dx * dx + dy * dy + dz * dz);
var azimuth = Math.Atan2(dz, dx) * 180.0 / Math.PI;
var elevation = Math.Atan2(dy, Math.Sqrt(dx * dx + dz * dz)) * 180.0 / Math.PI;
var radius = Math.Sqrt(dx * dx + dy * dy + dz * dz); // 相机与模型中心的距离
var azimuth = Math.Atan2(dz, dx) * 180.0 / Math.PI; // 方位角(水平平面上的角度)
var elevation = Math.Atan2(dy, Math.Sqrt(dx * dx + dz * dz)) * 180.0 / Math.PI; // 仰角(垂直方向的角度)
switch (directionName)
{
case "BtnTop":
//上
elevation += directionValue;
break;
case "BtnBottom":
//下
elevation -= directionValue;
break;
case "BtnLeft":
//左
azimuth -= directionValue;
break;
case "BtnRight":
//右
azimuth += directionValue;
break;
}
if (elevation >= 90)
{
elevation = 89.9f;
azimuth += 180.0f;
}
else if (elevation <= -90)
{
elevation = -89.9f;
azimuth += 180.0f;
}
azimuth = (azimuth + 360) % 360;
// 限制仰角范围在 -89.9 到 89.9 度,避免超出范围导致位置错误
elevation = Math.Clamp(elevation, -89.9, 89.9);
azimuth = (azimuth + 360) % 360; // 方位角在 0 到 360 范围内循环
// 将极坐标转换回直角坐标
var newX = modelCenter.X + radius * Math.Cos(elevation * Math.PI / 180.0) * Math.Cos(azimuth * Math.PI / 180.0);
var newY = modelCenter.Y + radius * Math.Sin(elevation * Math.PI / 180.0);
var newZ = modelCenter.Z + radius * Math.Cos(elevation * Math.PI / 180.0) * Math.Sin(azimuth * Math.PI / 180.0);
// 更新相机位置和视角
camera.Position = new Point3D(newX, newY, newZ);
camera.LookDirection = new Vector3D(modelCenter.X - newX, modelCenter.Y - newY, modelCenter.Z - newZ);
var rightDirection = Vector3D.CrossProduct(camera.LookDirection, new Vector3D(0, 1, 0)); // 计算右方向
if (rightDirection.Length < 0.027)
{
rightDirection = Vector3D.CrossProduct(camera.LookDirection, new Vector3D(-1, 0, 0)); // 计算右方向
}
camera.UpDirection = Vector3D.CrossProduct(camera.LookDirection, rightDirection);
// camera.UpDirection = new Vector3D(0, 1, 0); // 保持 Y 轴为上方向
}

Loading…
Cancel
Save