2024-03-03 18:00:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
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 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; } = "自动保存导出数据";
|
|
|
|
|
|
|
|
|
|
[Inject] private ICuttingTool _cuttingTool;
|
|
|
|
|
|
|
|
|
|
public override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
_cuttingTool.OnRelease += OnRelease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 17:48:11 +08:00
|
|
|
|
var commands = obj.OfType<ICuttingCommand>();
|
|
|
|
|
var stringBuilder = new System.Text.StringBuilder();
|
|
|
|
|
var path = Path.Combine(FolderPath, $"export_{DateTime.Now.Ticks}.cfg");
|
|
|
|
|
stringBuilder.AppendLine($"导出时间: {DateTime.Now}");
|
2024-03-03 18:30:19 +08:00
|
|
|
|
foreach (var command in commands)
|
2024-03-03 17:32:06 +08:00
|
|
|
|
{
|
2024-03-03 19:12:50 +08:00
|
|
|
|
if(command is CuttingPointCommand pointCommand)
|
2024-03-03 18:04:13 +08:00
|
|
|
|
{
|
2024-03-03 19:12:50 +08:00
|
|
|
|
stringBuilder.AppendLine(
|
|
|
|
|
$"切削点: {pointCommand.PlanePoint.x} {pointCommand.PlanePoint.y} {pointCommand.PlanePoint.z}");
|
2024-03-03 18:04:13 +08:00
|
|
|
|
}
|
2024-03-03 19:12:50 +08:00
|
|
|
|
else if(command is CuttingLineCommand lineCommand)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.AppendLine($"切削线:{lineCommand.Line.Length}");
|
|
|
|
|
foreach (var linePos in lineCommand.Line)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.AppendLine($"切削线点: {linePos.x} {linePos.y} {linePos.z}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// switch (command)
|
|
|
|
|
// {
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
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 17:32:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|