iFactory.Cutting.Mod.auto_s.../Class1.cs

67 lines
1.9 KiB
C#
Raw Normal View History

2024-03-03 18:00:03 +08:00
using System;
using System.IO;
using BITFactory.Cutting;
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 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}");
foreach (var x in commands)
2024-03-03 17:32:06 +08:00
{
2024-03-03 18:15:47 +08:00
if(x is CuttingPointCommand pointCommand)
2024-03-03 18:04:13 +08:00
{
2024-03-03 18:15:47 +08:00
stringBuilder.AppendLine(
$"切削点: {pointCommand.PlanePoint.x} {pointCommand.PlanePoint.y} {pointCommand.PlanePoint.z}");
2024-03-03 18:04:13 +08:00
}
2024-03-03 18:15:47 +08:00
// switch (x)
// {
// 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
}
}
}