fix: 20250310

master
Tongg 4 months ago
parent 1a199f8d85
commit 5abd0bb132
  1. 10
      App.config
  2. 4
      MainWindow.xaml.cs
  3. 4
      Model/Entity/ApiEntity/AlgorithmResultEntity.cs
  4. 6
      Model/Entity/ApiEntity/StatusCodes.cs
  5. 4
      Model/Services/SOCClientService.cs
  6. 5
      SparkClient.csproj
  7. 21
      ViewModel/Grading/DiamondSelectVM.cs
  8. 40
      ViewModel/Grading/GradingLoadingVM.cs
  9. 21
      ViewModel/Grading/GradingResultVM.cs
  10. 84
      Views/Dialog/ImageSelect.xaml
  11. 110
      Views/Dialog/ImageSelect.xaml.cs
  12. 3
      Views/Grading/GradingLoading.xaml
  13. 2
      Views/UserControl/ViewportData/Helper/CommonHelper.cs

@ -2,24 +2,20 @@
<configuration>
<appSettings>
<!-- 切工仪URL -->
<add key="BaseUrl" value="http://192.168.2.168:5000/api/SoC"/>
<add key="BaseUrl" value="http://192.168.10.111:5000/api/SoC"/>
<!-- <add key="BaseUrl" value="http://192.168.3.100:8080"/> -->
<!-- SOC下载图片目录 -->
<add key="ImageFileBasePath" value="D:\diamond_images"/>
<!-- 算法失败时,历史图片保存文件夹路径 -->
<add key="ImageHistoryPath" value="D:\ImageHistory"/>
<!-- 打印机名称 -->
<add key="PrintName" value="Deli DL-770D"/>
<!-- 打印纸张内容宽比 -->
<add key="PrintWidth" value="400"/>
<!-- 打印纸张内容高比 -->
<add key="PrintHeight" value="300"/>
<add key="PrintName" value="Deli DL-720C"/>
<!-- 检测结果默认DS -->
<add key="DSSet" value="NA"/>
<!-- 检测预估耗时:毫秒 -->
<add key="ProgressTime" value="50000"/>
<add key="RunModel" value="999" />
<add key="RunModel" value="0" />
</appSettings>
<connectionStrings>
<add name="" connectionString=""/>

@ -11,6 +11,7 @@ using HandyControl.Tools;
using log4net;
using log4net.Config;
using SparkClient.Model.Helper;
using SparkClient.Model.Services;
using SparkClient.ViewModel;
using SparkClient.ViewModel.BaseWindow;
using SparkClient.Views.BaseWindow;
@ -142,7 +143,7 @@ public partial class MainWindow
}
private void MainWindow_OnClosing(object? sender, CancelEventArgs e)
private async void MainWindow_OnClosing(object? sender, CancelEventArgs e)
{
var message = MultilingualHelper.getString("ExitAsk");
var title = MultilingualHelper.getString("ExitAskTitle");
@ -152,6 +153,7 @@ public partial class MainWindow
if (result == MessageBoxResult.OK)
{
await SOCClientService.Service.OpenPump(false);
DataBaseHelper.CloseConnection();
// this.Close();
Environment.Exit(0);

@ -39,7 +39,9 @@ namespace SparkClient.Model.Entity.ApiEntity
/// 面的类型。
/// </summary>
public int facet_type { get; set; }
/// <summary>
/// 旋转角度
/// </summary>
public double theta { get; set; }
}

@ -33,6 +33,12 @@ namespace SparkClient.Model.Common
// 切工仪舱门未关闭
public const string OpenOfTheHatch = "S007";
/// <summary>
/// 输出参数错误或者未定义
/// </summary>
public const string OutputParameterNotProvidedOrIncorrect = "S008";
public const string PreviousTaskIncomplete = "S009";
// 未找到切工仪
public const string DeviceNotFound = "P001";

@ -77,9 +77,9 @@ namespace SparkClient.Model.Services
// 记录日志
Logger.Info($"Response: Status={statusCode}, Body={responseBody}");
var tempEntity = JsonConvert.DeserializeObject<ResponseStatus>(responseBody);
if ("S007".Equals(tempEntity.Status))
if (StatusCodes.PreviousTaskIncomplete.Equals(tempEntity.Status))
{
Logger.Info($"S007 请求重试");
Logger.Info($"S009 请求重试");
await Task.Delay(50);
return await SendGetRequestAsync(url);
}

@ -258,6 +258,11 @@
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Dialog\ImageSelect.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>

@ -165,16 +165,13 @@ public class DiamondSelectVM : BaseViewModel
WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
return;
}
else if ( res <= -100)
if ( res <= -100)
{
return;
}
else
{
GradingResult(loadingView.Parameter);
loadingView.Dispose();
}
}
else if ("1".Equals(runModel))
{
//Image模式
@ -191,19 +188,16 @@ public class DiamondSelectVM : BaseViewModel
//返回
loadingView.Dispose();
WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
;
await SOCClientService.Service.OpenPump(false);
return;
}
else if ( res <= -100)
if ( res <= -100)
{
return;
}
else
{
GradingResult(loadingView.Parameter);
loadingView.Dispose();
}
}
else
{
//正常模式
@ -221,18 +215,17 @@ public class DiamondSelectVM : BaseViewModel
//返回
loadingView.Dispose();
WindowManager.mainViewModel.Content = WindowManager.PreviousVM();
;
await SOCClientService.Service.OpenPump(false);
return;
}
else if ( res <= -100)
if ( res <= -100)
{
return;
}
else
{
GradingResult(loadingView.Parameter);
loadingView.Dispose();
}
}

@ -191,15 +191,29 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
LoadImages(processImage.Result.Images);
}
string strImageModeImagePath = string.Empty;
if (type == 1)
{
ImageSelect jsonImport = new ImageSelect();
bool? a = jsonImport.ShowDialog();
if (a ?? false)
{
strImageModeImagePath = jsonImport.FilePath.Text;
string name = jsonImport.FileName.Text;
List<string> mnFiles = new List<string>();
for (int i = 0; i < 100; i++)
{
mnFiles.Add($"{i}.bmp");
mnFiles.Add(name.Replace("%d", i.ToString()));
}
LoadImages(mnFiles);
}
else
{
return -1;
}
}
ImageIsEnable = true;
StartPlayback();
@ -217,10 +231,17 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
_algorithmConfigVM.InitAlgorithmData(null);
string algo_config = _algorithmConfigVM.AlgorithmConfigJson;
string imageFileBasePath = string.Empty;
//图片根目录
string? image_file_base_path = ConfigurationManager.AppSettings["ImageFileBasePath"];
if (string.IsNullOrEmpty(image_file_base_path))
if (type == 1)
{
imageFileBasePath = strImageModeImagePath;
}
else
{
imageFileBasePath = ConfigurationManager.AppSettings["ImageFileBasePath"];
}
if (string.IsNullOrEmpty(imageFileBasePath))
{
throw new InvalidOperationException("ImageFileBasePath is not configured in AppSettings.");
}
@ -235,7 +256,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
JObject jsonData = new JObject(
new JProperty("shape", _diamnondType.Split(" ")[0]),
new JProperty("shape_mode", _diamnondType.Split(" ")[1]),
new JProperty("image_file_base_path", image_file_base_path),
new JProperty("image_file_base_path", imageFileBasePath),
new JProperty("image_files", ImagePaths),
new JProperty("half_circle", half_circle),
new JProperty("algorithm_log_path", algorithm_log_path),
@ -294,6 +315,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
Progress = (100.00);
string strParam = JsonConvert.SerializeObject(detectTask.Result);
//Logger.Info("序列化字符串:" + strParam);
AlgorithmResultEntity parameter = JsonConvert.DeserializeObject<AlgorithmResultEntity>(strParam);
if (parameter == null && _isCancel == false)
{
@ -328,6 +350,12 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
Parameter = parameter;
if (_isCancel == true) return -100;
if (parameter.status == StatusCodes.Recheck)
{
new MessageBox().Show(MultilingualHelper.getString("Recheck"));
}
return 0;
}
@ -366,7 +394,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
{
current = Math.Min(current + 1, 100);
UpdateProgress(current);
await Task.Delay(stepTime);
await Task.Delay(stepTime/2);
}
}
private void UpdateProgress(int value)

@ -1976,6 +1976,10 @@ public class GradingResultVM : BaseViewModel
// 执行热敏打印的方法
[Log]
private void ExecuteThermalPrint(object parameter)
{
Microsoft.Office.Interop.Excel.Application excelApp = null;
string tempFilePath = string.Empty;
try
{
MessageBox messageBox = new MessageBox();
MessageBoxResult boxResult = messageBox.ShowAsk(MultilingualHelper.getString("YesOrNo"));
@ -1984,10 +1988,6 @@ public class GradingResultVM : BaseViewModel
return;
}
string tempFilePath = string.Empty;
Microsoft.Office.Interop.Excel.Application excelApp = null;
try
{
// 步骤2:加载模板并填充数据
tempFilePath = GenerateTempExcelFile();
@ -1998,12 +1998,13 @@ public class GradingResultVM : BaseViewModel
Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(tempFilePath);
string printName = ConfigurationHelper.ReadConfigValue("PrintName");
string? targetPrinter = System.Drawing.Printing.PrinterSettings.InstalledPrinters
.Cast<string>()
.FirstOrDefault(p => p.Contains(ConfigurationHelper.ReadConfigValue("PrintName")));
.FirstOrDefault(p => p.Contains(printName));
if (targetPrinter == null)
{
throw new Exception($"未找到打印机{targetPrinter}");
throw new Exception($"未找到打印机{printName}");
}
// 打印配置
@ -2334,6 +2335,8 @@ public class GradingResultVM : BaseViewModel
}
private string GenerateTempExcelFile()
{
try
{
string TemplatePath = @"Resource\ResultReport.xlsx";
using (FileStream templateStream = new FileStream(TemplatePath, FileMode.Open, FileAccess.Read))
@ -2414,9 +2417,15 @@ public class GradingResultVM : BaseViewModel
{
workbook.Write(fs);
}
return tempFile;
}
}
catch (Exception e)
{
throw e;
}
}
[Log]
private void SetCellValue(ISheet sheet, string cellAddress, object value)

@ -0,0 +1,84 @@
<Window x:Class="SparkClient.Views.Dialog.ImageSelect"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SparkClient.Views.Dialog"
mc:Ignorable="d"
Title="JsonImport" Height="450" Width="800"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
WindowStyle="None" AllowsTransparency="True" Background="Transparent">
<Border CornerRadius="10" Background="White" x:Name="Border" BorderBrush="Blue" BorderThickness="2">
<Grid ClipToBounds="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<!-- 模拟顶部标题栏 -->
<Grid Grid.Row="0" Background="#795C2A" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- 关闭按钮 -->
<Border Grid.Column="2"
Width="40" Height="30"
Margin=" 0 0 10 0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Background="Transparent"
MouseEnter="Border_Close_MouseEnter"
MouseLeave="Border_MouseLeave">
<Button Background="Transparent" BorderBrush="Transparent" Click="Close_Click">
<Viewbox Stretch="Uniform">
<Path Data="{StaticResource CloseGeometry}"
Fill="Azure"
Stroke="Azure"
StrokeThickness="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="20 0 0 0"
Width="30" />
</Viewbox>
</Button>
</Border>
</Grid>
<StackPanel Grid.Row="1" VerticalAlignment="Center" >
<Grid Height="80" Margin="0 10 0 10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="9*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" HorizontalAlignment="right" Content="图片路径" Background="Transparent"
BorderBrush="Transparent"
FontSize="16" FontFamily="AlibabaPuHui-regular" />
<TextBox Grid.Row="0" TextWrapping="Wrap" x:Name ="FilePath" Grid.Column="2" IsReadOnly="True"/>
<Button Grid.Row="0" Grid.Column="3" Content="浏览" HorizontalAlignment="Left" Click="open_Click"/>
<Label Grid.Row="2" Grid.Column="1" HorizontalAlignment="right" Content="文件名格式" Background="Transparent"
BorderBrush="Transparent"
FontSize="16" FontFamily="AlibabaPuHui-regular" />
<TextBox Grid.Row="2" Grid.ColumnSpan="1" TextWrapping="Wrap" x:Name ="FileName" Grid.Column="2" Text="%d.bmp"/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="2" Content="{DynamicResource ok}" HorizontalAlignment="Center" Click="Ok_Click" />
<Button Grid.Column="3" Content="{DynamicResource Cancel}" HorizontalAlignment="Center" Click="Close_Click" />
</Grid>
</StackPanel>
</Grid>
</Border>
</Window>

@ -0,0 +1,110 @@
using HandyControl.Controls;
using log4net;
using SparkClient.ViewModel;
using SparkClient.ViewModel.Dialog;
using SparkClient.Views.Grading;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Win32;
namespace SparkClient.Views.Dialog
{
/// <summary>
/// JsonImport.xaml 的交互逻辑
/// </summary>
public partial class ImageSelect
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(ImageSelect));
public BaseViewModel ViewModel = null;
public ImageSelect()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
// 动态设置圆角裁剪
this.Loaded += (s, e) => ApplyCornerRadiusClip();
this.SizeChanged += (s, e) => ApplyCornerRadiusClip(); // 保证在大小改变时也裁剪
this.Width = 562;
this.Height = 222;
this.ViewModel = new StartDialogVM();
this.DataContext = this.ViewModel;
}
#region 重写窗体操作按钮
private void Border_Close_MouseEnter(object sender, MouseEventArgs e)
{
// 鼠标进入时更改背景色
if (sender is Border border)
{
border.Background = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0));
}
}
private void Border_MouseLeave(object sender, MouseEventArgs e)
{
// 鼠标离开时恢复背景色
if (sender is Border border)
{
border.Background = new SolidColorBrush(Colors.Transparent);
}
}
private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
try
{
this.DragMove();
}
catch (InvalidOperationException ex)
{
}
}
}
#endregion
private void Close_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
this.Close();
}
private void open_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFolderDialog
{
Title = "请选择部署位置"
};
bool? result = dialog.ShowDialog();
if (result == true)
{
FilePath.Text = dialog.FolderName;
}
}
private void Ok_Click(object sender, RoutedEventArgs e)
{
if (FilePath.Text.Trim().Length > 0) {
DialogResult = true;
this.Close();
}
else
{
Growl.Error("请选择图片路径");
}
}
private void ApplyCornerRadiusClip()
{
// 使用矩形几何生成圆角裁剪
this.Border.Clip = new RectangleGeometry
{
Rect = new Rect(0, 0, this.Border.ActualWidth, this.Border.ActualHeight),
RadiusX = this.Border.CornerRadius.TopLeft, // 使用 Border 的 CornerRadius
RadiusY = this.Border.CornerRadius.TopLeft
};
}
}
}

@ -337,7 +337,8 @@
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="{StaticResource GradingLoading}" BorderBrush="Transparent" BorderThickness="0"
TextAlignment="Center" FontSize="30" IsEnabled="False"/>
<ProgressBar Grid.Row="1" Margin="50 0" Height="30" Value="{Binding Progress}" FontSize="24"/>
<ProgressBar Grid.Row="1" Margin="50 0" Height="30" Value="{Binding Progress}" FontSize="24" Visibility="Hidden"/>
<hc:LoadingLine Grid.Row="1" Margin="50 0" Foreground="#40B1FF" Style="{StaticResource LoadingLineLarge}"/>
</Grid>

@ -46,7 +46,7 @@ public class CommonHelper
// 提取 PlaneCode 和 PlaneType
string planeCode = jsonObject.facet_id ?? (string)jsonObject.facet_id;
PlaneType planeType = (PlaneType)(int)jsonObject.facet_type;
Double theta = jsonObject.theta ?? (Double)jsonObject.theta;
double theta = jsonObject.theta ?? (double)jsonObject.theta;
// 生成 TriangleCode
var triangleCode = GenerateTriangleCode(point1, point2, point3);

Loading…
Cancel
Save