FlyTest/FlyExe/MainWindow.xaml.cs
2020-10-13 10:51:23 +08:00

91 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FlightRoute;
namespace FlyExe
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public bool isSuccess;//记录绕行最终是否成功
public MainWindow()
{
InitializeComponent();
}
//保存输出文本
private static void saveFile(string filePath, string txtCon)
{
txtCon = txtCon.TrimEnd((char[])"\n\r".ToCharArray());//去除最后的回车符
Console.WriteLine(txtCon);
string stream = null;
if (File.Exists(filePath))
{
StreamReader reader = new StreamReader(filePath);
stream = reader.ReadToEnd();
reader.Close();
}
FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.Write(txtCon);
sw.Close();
fs.Close();
}
//回调 输出日志
public void strPrint(string str)
{
vLogBox.Text += "\r\n"+str;
}
//3D绕行 按钮执行
private void Button_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog ofdl = new Microsoft.Win32.OpenFileDialog();//打开资源管理器
ofdl.Filter = "文本文件|*.txt";//资源管理器限制扩展名
strPrint("开始");
if (ofdl.ShowDialog() == true)
{
List<Vector3[]> txt = FlyBase.txtToPos(ofdl.FileName, out string[] fightNames);//从txt文件里面读取航点 信息
//3D绕行计算
List<Vector3[]> txtC = FlyBase.exeABypassB(txt[0], txt[1], out this.isSuccess, strPrint);
string txta = "";
string txtb = "";
string txtc = "";
int id = 1;
foreach (Vector3 item in txtC[0])
{
txta += id + " 0" + " " + item.x + " " + item.y + " " + item.z + "\r\n";
if (txtC.Count > 1) txtb += id + " 0" + " " + txtC[1][id - 1].x + " " + txtC[1][id - 1].y + " " + txtC[1][id - 1].z + "\r\n";
if (txtC.Count > 2) txtc += id + " 0" + " " + txtC[2][id - 1].x + " " + txtC[2][id - 1].y + " " + txtC[2][id - 1].z + "\r\n";
id++;
}
saveFile("C:/Users/ddkk/Desktop/a.txt", txta);
if (txtC.Count > 1) saveFile("C:/Users/ddkk/Desktop/b.txt", txtb);
if (txtC.Count > 2) saveFile("C:/Users/ddkk/Desktop/c.txt", txtc);
}
if (this.isSuccess == true)
{
strPrint("成功");
}
else
{
strPrint("未成功");
}
strPrint("结束");
}
}
}