2024-03-03 18:00:03 +08:00
|
|
|
|
using System;
|
2024-03-05 15:12:33 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-03 18:00:03 +08:00
|
|
|
|
using System.IO;
|
2024-03-03 17:32:06 +08:00
|
|
|
|
using BITKit;
|
|
|
|
|
using BITKit.CommandPattern;
|
|
|
|
|
using BITKit.Mod;
|
2024-03-03 17:58:14 +08:00
|
|
|
|
using System.Linq;
|
2024-03-03 18:30:19 +08:00
|
|
|
|
using BITFactory.Cutting;
|
2024-03-03 23:27:02 +08:00
|
|
|
|
using BITKit.UX;
|
2024-03-03 17:32:06 +08:00
|
|
|
|
|
2024-03-03 18:05:45 +08:00
|
|
|
|
namespace BITFactory.Cutting.Mod
|
2024-03-03 17:32:06 +08:00
|
|
|
|
{
|
2024-03-03 17:48:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 该程序将自动保存导出的数据到同级目录下
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AutoSaveImage : MyMod
|
2024-03-03 17:32:06 +08:00
|
|
|
|
{
|
2024-03-03 17:48:11 +08:00
|
|
|
|
public override string PackageName { get; set; } = "iFactory.Cutting.Mod.auto_save_images";
|
|
|
|
|
public override string Name { get; set; } = "自动保存导出数据";
|
|
|
|
|
|
2024-03-05 15:12:33 +08:00
|
|
|
|
public override string Description { get; set; } =
|
2024-04-16 04:15:17 +08:00
|
|
|
|
"自动保存导出的数据到该程序所在目录下,并且在导出后弹出对话框提示\n导出的格式为export_{Timestamp}.cfg";
|
2024-03-05 15:12:33 +08:00
|
|
|
|
|
2024-03-03 17:48:11 +08:00
|
|
|
|
[Inject] private ICuttingTool _cuttingTool;
|
2024-03-03 23:27:02 +08:00
|
|
|
|
[Inject] private IUXDialogue _dialogue;
|
|
|
|
|
|
2024-03-03 17:48:11 +08:00
|
|
|
|
public override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
_cuttingTool.OnRelease += OnRelease;
|
2024-03-03 23:27:02 +08:00
|
|
|
|
|
2024-03-03 17:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnDisposed()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisposed();
|
|
|
|
|
_cuttingTool.OnRelease -= OnRelease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRelease(ICommand[] obj)
|
2024-03-03 17:32:06 +08:00
|
|
|
|
{
|
2024-03-03 19:15:27 +08:00
|
|
|
|
var commands = obj.OfType<ICuttingCommand>().ToArray();
|
2024-03-03 17:48:11 +08:00
|
|
|
|
var stringBuilder = new System.Text.StringBuilder();
|
|
|
|
|
var path = Path.Combine(FolderPath, $"export_{DateTime.Now.Ticks}.cfg");
|
2024-03-05 15:12:33 +08:00
|
|
|
|
stringBuilder.AppendLine($"导出时间: {DateTime.Now},导出命令数量: {obj.Length},有效命名数量: {commands.Length}");
|
2024-03-03 18:30:19 +08:00
|
|
|
|
foreach (var command in commands)
|
2024-03-03 17:32:06 +08:00
|
|
|
|
{
|
2024-03-05 15:12:33 +08:00
|
|
|
|
switch (command)
|
2024-03-03 19:15:27 +08:00
|
|
|
|
{
|
2024-03-05 15:12:33 +08:00
|
|
|
|
case CuttingPointCommand pointCommand:
|
|
|
|
|
stringBuilder.AppendLine(
|
|
|
|
|
$"切削点: {pointCommand.PlanePoint.x} {pointCommand.PlanePoint.y} {pointCommand.PlanePoint.z}");
|
|
|
|
|
break;
|
|
|
|
|
case CuttingLineCommand lineCommand:
|
|
|
|
|
stringBuilder.AppendLine($"切削线:{lineCommand.Line.Length}");
|
|
|
|
|
foreach (var linePos in lineCommand.Line)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.AppendLine($"切削线点: {linePos.x} {linePos.y} {linePos.z}");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
stringBuilder.AppendLine($"{command.Name}:{command.GetType().FullName}");
|
|
|
|
|
break;
|
2024-03-03 19:15:27 +08:00
|
|
|
|
}
|
2024-03-03 17:32:06 +08:00
|
|
|
|
}
|
2024-03-03 17:48:11 +08:00
|
|
|
|
|
|
|
|
|
File.WriteAllText(path, stringBuilder.ToString());
|
|
|
|
|
|
|
|
|
|
BIT4Log.Log<AutoSaveImage>($"导出数据已保存到:{path}");
|
2024-03-03 23:27:02 +08:00
|
|
|
|
|
|
|
|
|
_dialogue.Show($"导出数据已保存到\n{path}", $"数据已保存",OpenFile);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
void OpenFile()
|
|
|
|
|
{
|
|
|
|
|
//打开path的文件
|
|
|
|
|
System.Diagnostics.Process.Start(path);
|
|
|
|
|
}
|
2024-03-03 17:32:06 +08:00
|
|
|
|
}
|
2024-03-03 23:27:02 +08:00
|
|
|
|
|
2024-03-03 17:32:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|