diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 79dbf83..bd9217f 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -712,7 +712,140 @@ namespace Plane.FormationCreator.Formation return sb.ToString().Trim(); } - //导入外部航点 + + public void ImportC4DFlytoVCopter(string txt) + { + string[] lines = txt.Replace("\r\n", "\n").Split('\n'); + + if (lines.Length % (_copterManager.Copters.Count + 1) != 0) + { + Alert.Show("文件内容错误!"); + return; + } + + int taskCount = lines.Length / (_copterManager.Copters.Count + 1); + int startIndex; + string line; + Dictionary PointDic; + for (int i = 0; i < taskCount; i++) + { + startIndex = i * (_copterManager.Copters.Count + 1); + string taskName = lines[startIndex]; + PointDic = new Dictionary(); + for (int j = 0; j < _copterManager.Copters.Count; j++) + { + line = lines[startIndex + j + 1]; + string[] parameters = line.Split(' '); + int id = Convert.ToInt32(parameters[0]); + string frame = parameters[1]; + string[] point = new string[3]; + point[0] = parameters[1]; //左右 经度 + point[1] = parameters[2]; //上下 高度 + point[2] = parameters[3]; //前后 纬度 + PointDic.Add(id, point); + } + + var lastTask = Tasks.LastOrDefault(); + var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = true, FlytoTime = 10, LoiterTime = 1 }; + newTask.TaskCnName = taskName; + for (int k = 0; k < PointDic.Count; k++) + { + string[] point = PointDic[k + 1]; + + //string frame = parameters[1]; + string x = point[0]; //左右 经度 + string y = point[1]; //上下 高度 + string z = point[2]; //前后 纬度 + Tuple observationLatLng = null; + observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D( + OriginLat, + OriginLng, + 90, + Convert.ToSingle(x) / 100); + + observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D( + observationLatLng.Item1, + observationLatLng.Item2, + 0, + Convert.ToSingle(z) / 100); + + var fc = _copterManager.Copters[k] as FakeCopter; + double vlatitude = observationLatLng.Item1; + double vlongitude = observationLatLng.Item2; + + + fc.SetProperties( + latitude: vlatitude, + longitude: vlongitude, + altitude: Convert.ToSingle(y) / 100); + + + + + } + Tasks.Add(newTask); + RaiseTaskAdded(lastTask, newTask); + } + + + } + + public void ImportDlltoVCopter(string filename) + { + Vector3[] vc; + + + + + string extname = Path.GetExtension(filename); + if (extname == ".svg") + { + vc = FlyBase.svgToPos(filename); + } + else if (extname == ".obj") + { + vc = FlyBase.objToPos(filename); + } + else return; + + if (vc.Count() != _copterManager.Copters.Count) + { + Alert.Show($"飞机数量不匹配!导入{vc.Count()}架,实际{_copterManager.Copters.Count}"); + return; + } + int id = 0; + foreach (Vector3 item in vc) + { + Tuple observationLatLng = null; + observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D( + OriginLat, + OriginLng, + 90, + (float)item.x / 100); + + observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D( + observationLatLng.Item1, + observationLatLng.Item2, + 0, + (float)item.z / 100); + + + var fc = _copterManager.Copters[id] as FakeCopter; + double vlatitude = observationLatLng.Item1;// - OriginLat; + double vlongitude = observationLatLng.Item2;// - OriginLng; + + + fc.SetProperties( + latitude: vlatitude, + longitude: vlongitude, + altitude: (float)item.y / 100); + id++; + + } + } + + + //导入外部航点 public void ImportDlltoTask(string filename) { Vector3[] vc; @@ -736,7 +869,9 @@ namespace Plane.FormationCreator.Formation } var lastTask = Tasks.LastOrDefault(); var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = true, FlytoTime = 10, LoiterTime = 1 }; - newTask.TaskCnName = Path.GetFileNameWithoutExtension(filename).Substring(0,6); + string vname=Path.GetFileNameWithoutExtension(filename); + if (vname.Length>6) vname= vname.Substring(0, 6); + newTask.TaskCnName = vname; int id =0; foreach (Vector3 item in vc) { diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs index 4fc0a96..143d69b 100644 --- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs +++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs @@ -340,8 +340,8 @@ namespace Plane.FormationCreator.ViewModels // copter.VirtualId = _virtualCopterId; await copter.ConnectAsync(); await copter.GetCopterDataAsync(); - _copterManager.Copters.AddCopter(copter, _copterManager.SortType); _copterManager.CopterStatus.Add(false); + _copterManager.Copters.AddCopter(copter, _copterManager.SortType); } } if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0) diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index a40750a..536c495 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -713,6 +713,52 @@ namespace Plane.FormationCreator.ViewModels + private ICommand _ImportBlenderrCopterPosCommand; + public ICommand ImportBlenderCopterPosCommand + { + get + { + return _ImportBlenderrCopterPosCommand ?? (_ImportBlenderrCopterPosCommand = new RelayCommand(async => + { + + //有不是虚拟飞机的直接退出 + foreach (var copter in _copterManager.Copters) + { + if (!(copter is FakeCopter)) + { + Alert.Show($"导入起飞位置只能用于虚拟飞机,{copter.Id}不是虚拟飞机", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + } + + + var dialog = new OpenFileDialog + { + DefaultExt = "txt", + Filter = "航点文件(*.txt,*.svg,*.obj) |*.txt;*.svg;*.obj" // "图片文件(*.jpg, *.gif, *.bmp, *.png) | *.jpg; *.gif; *.bmp; *.png" + }; + + if (dialog.ShowDialog() == true) + { + string extname = Path.GetExtension(dialog.FileName); + if (extname == ".txt") + { + var tasksText = File.ReadAllText(dialog.FileName); + _flightTaskManager.ImportC4DFlytoVCopter(tasksText); + } + else + if ((extname == ".svg") || (extname == ".obj")) + { + _flightTaskManager.ImportDlltoVCopter(dialog.FileName); + }; + } + })); + } + } + + + + private ICommand _ExportWayPointCommand; diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml index 594894e..713bed4 100644 --- a/Plane.FormationCreator/Views/ModifyTaskView.xaml +++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml @@ -564,10 +564,11 @@