fix:网格线矫正

master
sunhonglei 5 months ago
parent 6e7946b3aa
commit 21226ffe47
  1. 1
      Language/zh_CN.xaml
  2. 274
      ViewModel/Grading/DiamondSelectVM.cs
  3. 12
      ViewModel/Grading/GradingResultVM.cs
  4. 1
      Views/UserControl/Viewport3D.xaml
  5. 3
      Views/UserControl/Viewport3D.xaml.cs
  6. 10
      Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs
  7. 27
      Views/UserControl/ViewportData/Helper/ViewportManager.cs

@ -148,6 +148,7 @@
<sys:String x:Key="ViewportSaveSucceed">保存成功</sys:String>
<sys:String x:Key="ViewportSaveFail">保存失败</sys:String>
<sys:String x:Key="ViewportSelectPath">选择路径</sys:String>
<sys:String x:Key="ViewportRightMenuReset">重置网格线</sys:String>
<!-- 登录页 -->
<sys:String x:Key="LoginWindowTitle">星辉钻石检测系统</sys:String>

@ -21,6 +21,7 @@ using Newtonsoft.Json.Linq;
using SparkClient.Model.Common;
using Color = System.Windows.Media.Color;
using MessageBox = SparkClient.Views.Dialog.MessageBox;
using System.Runtime.CompilerServices;
namespace SparkClient.ViewModel.Grading;
@ -276,6 +277,11 @@ public class DiamondSelectVM : BaseViewModel
});
}
}
catch (DirectoryNotFoundException ex)
{
loading.Close();
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
}
finally {
}
@ -315,160 +321,172 @@ public class DiamondSelectVM : BaseViewModel
/// <param name="param"></param>
public async void DoStartGrading(object param)
{
if (param != null)
{
AlgorithmResultEntity parameter = new AlgorithmResultEntity();
JsonImport jsonImport = new JsonImport();
//jsonImport.FilePath.Text = "D:\\项目\\TEST240.json";
bool? a = jsonImport.ShowDialog();
if (a ?? false)
LoadingDialog loading = new LoadingDialog();
try {
if (param != null)
{
string fileName = jsonImport.FilePath.Text;
string[] lines = File.ReadAllLines(fileName);
StringBuilder stringBuilder = new StringBuilder();
foreach (var line in lines)
AlgorithmResultEntity parameter = new AlgorithmResultEntity();
JsonImport jsonImport = new JsonImport();
//jsonImport.FilePath.Text = "D:\\项目\\TEST240.json";
bool? a = jsonImport.ShowDialog();
if (a ?? false)
{
stringBuilder.Append(line);
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());
}
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++)
else
{
// 模拟耗时操作
//System.Threading.Thread.Sleep(50); // 休眠50毫秒
await Task.Delay(5);
// 更新进度条的值(需要在UI线程上执行)
loading.Dispatcher.Invoke(() =>
{
loading.setValue(i);
});
return;
}
var tcs = new TaskCompletionSource<bool>();
var progressTask = Task.Run(() => Application.Current.Dispatcher.Invoke(() => {
loading.Closed += (s, e) => tcs.SetResult(true);
loading.ShowDialog();
}
// SocResultEntity socResolt = new SocResultEntity();
// AlgorithmResultEntity parameter = new AlgorithmResultEntity();
// // 启动soc
// socResolt = DoSoc();
// // 启动算法
// parameter = DoAlgorithm();
//parameter = DoSoc();
parameter.Standard = getStandardName();
string value = param.ToString() ?? "";
if (value != null && value.Split(" ").Length == 3)
));
await Task.Run(async () =>
{
parameter.Shape = value.Split(" ")[0];
parameter.CrownType = value.Split(" ")[1];
parameter.PavType = value.Split(" ")[2];
}
parameter.DiamondCode = DiamondCode;
GradingResult(parameter);
});
await Task.Delay(5);
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 = getStandardName();
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();
}
}
catch (DirectoryNotFoundException ex)
{
loading.Close();
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
}
catch (Exception ex)
{
new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}");
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
}
/// <summary>
/// 处理算法调用失败时的逻辑,包括保存图片到历史记录文件夹
/// </summary>
/// <param name="image_files">图片文件路径的 JSON 字符串</param>
///
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
private void HandleAlgorithmFailure(string image_files)
{
/// 处理算法调用失败时的逻辑,包括保存图片到历史记录文件夹
/// </summary>
/// <param name="image_files">图片文件路径的 JSON 字符串</param>
///
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
private void HandleAlgorithmFailure(string image_files)
{
// 从配置文件中读取 imageHistoryPath
// 定义历史记录文件夹路径
string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"];
if (string.IsNullOrEmpty(imageHistoryPath))
{
Logger.Error("ImageHistoryPath is not configured in AppSettings.");
return;
}
// 从配置文件中读取 imageHistoryPath
// 定义历史记录文件夹路径
string? imageHistoryPath = ConfigurationManager.AppSettings["ImageHistoryPath"];
if (string.IsNullOrEmpty(imageHistoryPath))
{
Logger.Error("ImageHistoryPath is not configured in AppSettings.");
return;
}
// 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
// 组合新的文件夹路径
string newFolderPath = Path.Combine(imageHistoryPath, $"image-{timestamp}");
// 生成时间戳,格式为 yyyyMMddHHmmss
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
// 组合新的文件夹路径
string newFolderPath = Path.Combine(imageHistoryPath, $"image-{timestamp}");
// 检查 D 盘内存空间
DriveInfo dDrive = new DriveInfo("D");
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB
if (dDrive.TotalFreeSpace < requiredSpace)
// 检查 D 盘内存空间
DriveInfo dDrive = new DriveInfo("D");
long requiredSpace = 10L * 1024 * 1024 * 1024; // 10GB
if (dDrive.TotalFreeSpace < requiredSpace)
{
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹
DirectoryInfo historyDir = new DirectoryInfo(imageHistoryPath); // 获取历史记录文件夹的信息
DirectoryInfo[] subDirs = historyDir.GetDirectories(); // 获取历史记录文件夹中的所有子文件夹
if (subDirs.Length > 0)
{
// 如果 D 盘空间不足 10GB,删除最早创建的10个文件夹
DirectoryInfo historyDir = new DirectoryInfo(imageHistoryPath); // 获取历史记录文件夹的信息
DirectoryInfo[] subDirs = historyDir.GetDirectories(); // 获取历史记录文件夹中的所有子文件夹
if (subDirs.Length > 0)
{
// 按创建时间排序子文件夹
var orderedSubDirs = subDirs.OrderBy(d => d.CreationTime).ToList();
int foldersToDelete = Math.Min(10, orderedSubDirs.Count);
// 按创建时间排序子文件夹
var orderedSubDirs = subDirs.OrderBy(d => d.CreationTime).ToList();
int foldersToDelete = Math.Min(10, orderedSubDirs.Count);
// 删除最早的 10 个文件夹,如果不够 10 个则全删掉
for (int i = 0; i < foldersToDelete; i++)
{
orderedSubDirs[i].Delete(true);
}
// 删除最早的 10 个文件夹,如果不够 10 个则全删掉
for (int i = 0; i < foldersToDelete; i++)
{
orderedSubDirs[i].Delete(true);
}
}
}
// 创建新文件夹
Directory.CreateDirectory(newFolderPath);
// 创建新文件夹
Directory.CreateDirectory(newFolderPath);
// 保存图片到新文件夹
try
{
// 解析 image_files JSON 数组
JArray imageFilesArray = JArray.Parse(image_files);
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray();
string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录
if (string.IsNullOrEmpty(imageBasePath))
{
Logger.Error("ImageFileBasePath is not configured in AppSettings.");
return;
}
// 保存图片到新文件夹
try
{
// 解析 image_files JSON 数组
JArray imageFilesArray = JArray.Parse(image_files);
string[] imageFiles = imageFilesArray.Select(token => token.ToString()).ToArray();
foreach (string imageFile in imageFiles)
{
// 获取文件名
string fileName = Path.GetFileName(imageFile);
// 构建完整的源文件路径
string sourcePath = Path.Combine(imageBasePath, imageFile);
// 组合目标路径
string destinationPath = Path.Combine(newFolderPath, fileName);
// 复制文件到目标路径,如果目标文件已存在则覆盖
File.Copy(sourcePath, destinationPath, true);
}
}
catch (JsonException ex)
string? imageBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"]; // 图片根目录
if (string.IsNullOrEmpty(imageBasePath))
{
// 记录日志或处理异常
Logger.Error($"Error parsing image_files JSON: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
Logger.Error("ImageFileBasePath is not configured in AppSettings.");
return;
}
catch (Exception ex)
foreach (string imageFile in imageFiles)
{
// 记录其他异常
Logger.Error($"Error saving images: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
// 获取文件名
string fileName = Path.GetFileName(imageFile);
// 构建完整的源文件路径
string sourcePath = Path.Combine(imageBasePath, imageFile);
// 组合目标路径
string destinationPath = Path.Combine(newFolderPath, fileName);
// 复制文件到目标路径,如果目标文件已存在则覆盖
File.Copy(sourcePath, destinationPath, true);
}
}
catch (JsonException ex)
{
// 记录日志或处理异常
Logger.Error($"Error parsing image_files JSON: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
catch (Exception ex)
{
// 记录其他异常
Logger.Error($"Error saving images: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
}
/// <summary>
/// 跳转至检测结果
/// </summary>

@ -190,8 +190,8 @@ public class GradingResultVM : BaseViewModel
}
catch (Exception ex)
{
new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}");
Logger.Error($"全局异常捕获:{ex.Message}", ex);
throw ex;
}
}
@ -749,10 +749,11 @@ public class GradingResultVM : BaseViewModel
}
else
{
if (!File.Exists(getFilePath()))
if (!Directory.Exists(getFilePath()))
{
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
return;
//new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
//return;
throw new DirectoryNotFoundException(getFilePath());
}
string fullPath = Path.Combine(getFilePath(), this.DiamondCode);
if (FileSaveEnabled("Txt"))
@ -796,7 +797,7 @@ public class GradingResultVM : BaseViewModel
}
private string getFilePath()
{
string defultFilePath = "D://DTest//";
string defultFilePath = "";
string sql = $"SELECT SETTING_P FROM SETTING WHERE SETTING_ID = 'FilePath'";
DataTable data = DataBaseHelper.ExecuteQuery(sql);
if (data!= null && data.Rows.Count>0)
@ -813,7 +814,6 @@ public class GradingResultVM : BaseViewModel
}
catch (Exception ex)
{
new MessageBox().Show(MultilingualHelper.getString("SavePathIsnotExists"));
Logger.Error($"全局异常捕获:{ex.Message}", ex);
}
return defultFilePath;

@ -72,6 +72,7 @@
<!-- <MenuItem Header="{StaticResource ViewportRightMenuSelectFaceAngleText}" x:Name="ViewportRightMenuSelectFaceAngleText" IsCheckable="True" StaysOpenOnClick="True" Checked="MenuItem_OnCheckedChanged" Unchecked="MenuItem_OnCheckedChanged"/> -->
<MenuItem Header="{StaticResource ViewportRightMenuSelectFaceKind}" x:Name="ViewportRightMenuSelectFaceKind" IsCheckable="True" StaysOpenOnClick="True" Checked="MenuItem_OnCheckedChanged" Unchecked="MenuItem_OnCheckedChanged"/>
<MenuItem Header="{StaticResource ViewportRightMenuShowMeshLines}" x:Name="ViewportRightMenuShowMeshLines" IsCheckable="True" StaysOpenOnClick="True" Checked="MenuItem_OnCheckedChanged" Unchecked="MenuItem_OnCheckedChanged"/>
<MenuItem Header="{StaticResource ViewportRightMenuReset}" x:Name="ViewportRightMenuReset" Click="MenuItem_OnClick"/>
</ContextMenu>
</Border.ContextMenu>
<hx:Viewport3DX x:Name="Viewport3Dx" ShowCoordinateSystem="True"

@ -487,6 +487,9 @@ public partial class Viewport3D
}
break;
case "ViewportRightMenuReset":
ViewportManager.ResetMeshLines();
break;
}
}

@ -1282,6 +1282,10 @@ public class ViewportHelperPro
lights.ForEach(item => viewport.Items.Remove(item));
}
private static Dictionary<Guid, Guid> moveLines = new Dictionary<Guid, Guid>();
public static void InitMeshLines()
{
moveLines = new();
}
/// <summary>
/// 网状参考线
/// </summary>
@ -1290,10 +1294,6 @@ public class ViewportHelperPro
/// <returns></returns>
public static List<LineGeometryModel3D> ShowMeshLines(bool isCrown = true, double thickness = 0.2)
{
if (isCrown)
{
moveLines = new();
}
List<LineGeometryModel3D> lines = new();
var Y = -0.01F;
if (!isCrown)
@ -1438,7 +1438,7 @@ public class ViewportHelperPro
// 计算直线的新位置
var transform = new TranslateTransform3D(projectedVector);
var newTransform = new MatrixTransform3D(transform.Value * initialTransform.Value);
var newProjectedVector = new Vector3D(newTransform.Matrix.OffsetX ,Y, newTransform.Matrix.OffsetZ);
var newProjectedVector = new Vector3D(newTransform.Matrix.OffsetX ,0, newTransform.Matrix.OffsetZ);
var newPosition1 = line.Geometry.Positions[0].ToVector3D();
newPosition1.X += newTransform.Matrix.OffsetX;
newPosition1.Z += newTransform.Matrix.OffsetZ;

@ -1,3 +1,4 @@
using System.Linq;
using System.Text.Json.Nodes;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
@ -178,9 +179,9 @@ public class ViewportManager
}
ChooseAddModels.Clear();
}
public static void ResetMeshLines()
public static void InitMeshLines()
{
ViewportHelperPro.InitMeshLines();
MainModelMeshLines_C.Clear();
MainModelMeshLines_C.AddRange(ViewportHelperPro.ShowMeshLines());
MainModelCircleLine_C = ViewportHelperPro.ShowCircleLine();
@ -188,6 +189,25 @@ public class ViewportManager
MainModelMeshLines_P.AddRange(ViewportHelperPro.ShowMeshLines(false));
MainModelCircleLine_P = ViewportHelperPro.ShowCircleLine(false);
}
public static void ResetMeshLines()
{
if (_viewport.Items.Contains(MainModelMeshLines_C[0]))
{
ViewportManager.ShowMeshLines(false, true);
MainModelMeshLines_C.Clear();
MainModelMeshLines_C.AddRange(ViewportHelperPro.ShowMeshLines());
MainModelCircleLine_C = ViewportHelperPro.ShowCircleLine();
ViewportManager.ShowMeshLines(true, true);
}
if (_viewport.Items.Contains(MainModelMeshLines_P[0]))
{
ViewportManager.ShowMeshLines(false, false);
MainModelMeshLines_P.Clear();
MainModelMeshLines_P.AddRange(ViewportHelperPro.ShowMeshLines(false));
MainModelCircleLine_P = ViewportHelperPro.ShowCircleLine(false);
ViewportManager.ShowMeshLines(true, false);
}
}
/// <summary>
/// 模拟面选中
/// </summary>
@ -321,7 +341,7 @@ public class ViewportManager
_viewport.Camera.UpDirection = new Vector3D(0, -1, 0);
_viewport.RenderHost.MSAA = MSAALevel.Maximum;
// TODO:
ResetMeshLines();
InitMeshLines();
}
/// <summary>
@ -497,7 +517,6 @@ public class ViewportManager
_viewport.Items.Remove(MainModelCircleLine_C);
MainModelMeshLines_P.ForEach(e => _viewport.Items.Remove(e));
_viewport.Items.Remove(MainModelCircleLine_P);
ResetMeshLines();
}
}

Loading…
Cancel
Save