From 6f33c3867cb488f9454da862653dd7e13fbb4255 Mon Sep 17 00:00:00 2001 From: xu Date: Thu, 30 Jan 2020 20:35:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=E9=97=B4=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=20=E9=98=B2=E6=AD=A2=E4=BF=AE=E6=94=B9=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=BA=E8=B5=B7=E9=A3=9E=E4=BB=BB=E5=8A=A1=20?= =?UTF-8?q?=E4=B8=8B=E6=96=B9=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BF=A1=E6=81=AF=20=E4=BB=BB=E5=8A=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E4=BB=BB=E5=8A=A1=E6=A8=A1=E6=8B=9F=E4=B8=AD?= =?UTF-8?q?=E5=8F=8C=E5=87=BB=E6=98=AF=E9=A9=AC=E4=B8=8A=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=AF=A5=E4=BB=BB=E5=8A=A1=EF=BC=8C=E5=8F=B3=E9=94=AE=E6=94=B9?= =?UTF-8?q?=E5=90=8D=20=E8=B0=83=E6=95=B4=E7=95=8C=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E5=85=83?= =?UTF-8?q?=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/FlightTaskManager.cs | 119 +++++++++++++++--- Plane.FormationCreator/MainWindow.xaml | 12 +- Plane.FormationCreator/MainWindow.xaml.cs | 3 + .../ViewModels/MainViewModel.cs | 19 +++ .../ViewModels/TaskBarViewModel.cs | 2 +- Plane.FormationCreator/Views/MapView.xaml | 6 +- Plane.FormationCreator/Views/TaskBarView.xaml | 12 +- .../Views/TaskBarView.xaml.cs | 67 +++++++++- 8 files changed, 207 insertions(+), 33 deletions(-) diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 46e3993..3b961ce 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -161,6 +161,36 @@ namespace Plane.FormationCreator.Formation public ObservableCollection Tasks { get; } = new ObservableCollection(); + + + public int GetTaskTime(int TaskIndex) + { + int tasktime = 0; + if ((Tasks==null)|| TaskIndex> Tasks.Count-1) return tasktime; + + FlightTask value = Tasks[TaskIndex]; + switch (value.TaskType) + { + case FlightTaskType.TakeOff: tasktime = value.TakeOffTime; ; break; + case FlightTaskType.FlyTo: tasktime = value.FlytoTime + value.LoiterTime; break; + //降落时间计算前一个任务目标高度最高的飞机的降落时间按1.5米/秒下降 + case FlightTaskType.Land: + float maxalt = 0.0f; + for (int i = 0; i < Tasks[TaskIndex-1].SingleCopterInfos.Count; i++) + { + var copterInfo = Tasks[TaskIndex - 1].SingleCopterInfos[i]; + if (maxalt < copterInfo.TargetAlt) maxalt = copterInfo.TargetAlt; + } + tasktime =(int) Math.Round(maxalt / 1.5,0); + break; + } + return tasktime; + + } + + + + private FlightTask _SelectedTask; public FlightTask SelectedTask { @@ -169,8 +199,33 @@ namespace Plane.FormationCreator.Formation { if (_SelectedTask != value) { + int starttime=0; + if (_SelectedTask != null) _SelectedTask.IsSelected = false; - if (value != null) value.IsSelected = true; + if (value != null) + { + value.IsSelected = true; + for (int i = 0; i < value.TaskIndex; i++) + starttime += GetTaskTime(i); + + TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(starttime)); + string str = ""; + if (ts.Hours > 0) + { + str = ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分" + ts.Seconds + "秒"; + } + if (ts.Hours == 0 && ts.Minutes > 0) + { + str = ts.Minutes.ToString() + "分" + ts.Seconds + "秒"; + } + if (ts.Hours == 0 && ts.Minutes == 0) + { + str = ts.Seconds + "秒"; + } + Message.ShowStatus($"选中 [{value.TaskIndex+1} {value.TaskCnName }] 从{str}开始执行,需{ GetTaskTime(value.TaskIndex)}秒"); + } + else Message.ShowStatus($"无任务选中"); + } Set(nameof(SelectedTask), ref _SelectedTask, value); } @@ -361,7 +416,7 @@ namespace Plane.FormationCreator.Formation SelectedTask = null; SelectedTaskIndex = 0; TasksCleared?.Invoke(this, EventArgs.Empty); - AddTakeOffTask(_copterManager.Copters); + // AddTakeOffTask(_copterManager.Copters); } @@ -397,12 +452,9 @@ namespace Plane.FormationCreator.Formation public async Task FlyToTasks() { var copters = _copterManager.Copters; - - - - if ((TaskState == TasksStatus.Stop) ||( CurrentRunningTaskIndex == Tasks.Count - 1)) + if ((TaskState == TasksStatus.Stop)) return; - + Pause(); int i = 0; //等待暂停或2s超时(80*25ms) @@ -425,10 +477,36 @@ namespace Plane.FormationCreator.Formation { var copter = copters[j]; var fc = copter as FakeCopter; + float targalt = 0.0f; + double lat = 0.0f; + double lng = 0.0f; + + //飞机回到前一个任务位置, + + //起飞任务直接用当前起飞任务位置 + if (Tasks[SelectedTaskIndex].TaskType == FlightTaskType.TakeOff) + { + lat = Tasks[SelectedTaskIndex].SingleCopterInfos[j].TargetLat; + lng = Tasks[SelectedTaskIndex].SingleCopterInfos[j].TargetLng; + targalt = 0.0f; + } + else + { + //用前一个任务目标位置 + lat = Tasks[SelectedTaskIndex-1].SingleCopterInfos[j].TargetLat; + lng = Tasks[SelectedTaskIndex-1].SingleCopterInfos[j].TargetLng; + + + //如果前一个是起飞任务,没有目标高度,用当前的 + if (Tasks[SelectedTaskIndex - 1].TaskType == FlightTaskType.TakeOff) + targalt = Tasks[SelectedTaskIndex].SingleCopterInfos[j].TargetAlt; + else + targalt = Tasks[SelectedTaskIndex - 1].SingleCopterInfos[j].TargetAlt; + } fc.SetProperties( - latitude: Tasks[SelectedTaskIndex-1].SingleCopterInfos[j].TargetLat, - longitude: Tasks[SelectedTaskIndex-1].SingleCopterInfos[j].TargetLng, - altitude: Tasks[SelectedTaskIndex - 1].SingleCopterInfos[j].TargetAlt + latitude: lat, + longitude: lng, + altitude: targalt ); @@ -1850,11 +1928,16 @@ namespace Plane.FormationCreator.Formation } return copterStr; } + //左键选中任务 public void Select(FlightTask flightTask) { this.SelectedTaskIndex = Tasks.IndexOf(flightTask); this.SelectedTask = flightTask; + + + + } // 右键选中任务 @@ -1898,6 +1981,7 @@ namespace Plane.FormationCreator.Formation DateTime taskStartTime; public async Task RunTaskAsync() { + if (Tasks.Count == 0) return; if (CurrentRunningTaskIndex == 0) { taskStartTime = DateTime.Now; @@ -1922,9 +2006,6 @@ namespace Plane.FormationCreator.Formation //task.Status目前只用于任务条下面状态显示不同颜色 task.Status = FlightTaskStatus.Stop; } - - - AppEx.Current.AppMode = AppMode.RunningTasks; StartAvoidingCrash(); //开始碰撞检测 TaskState = TasksStatus.Running; @@ -1935,13 +2016,23 @@ namespace Plane.FormationCreator.Formation task.Status = FlightTaskStatus.Running; CurrentRunningTask = task; CurrentRunningTaskIndex = i; - Message.Show($"任务{i+1}开始执行"); + + //////////////////显示提示信息 + int starttime = 0; + for (int j = 0; j < task.TaskIndex; j++) + starttime += GetTaskTime(j); + TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(starttime)); + Message.Show($"{ts}:任务{i+1} {task.TaskCnName } 开始执行,需{ GetTaskTime(task.TaskIndex)}秒"); + ///////////////////////// + + await task.RunAsync().ConfigureAwait(false); // 1. 被暂停时,中断 RunAsync。继续运行时将把此时运行了一半的 CurrentRunningTask 重新运行一遍。 if (IsPaused == true) { task.Status = FlightTaskStatus.Paused; TaskState = TasksStatus.Paused; + Message.Show($"任务{i + 1} {task.TaskCnName } 暂停执行"); return; } task.Status = FlightTaskStatus.Stop; diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index 3c4df34..d2c6f7f 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -223,15 +223,19 @@ Background="{StaticResource WhiteBrush}"> - - + + + + - + diff --git a/Plane.FormationCreator/MainWindow.xaml.cs b/Plane.FormationCreator/MainWindow.xaml.cs index 21300b5..cf1026f 100644 --- a/Plane.FormationCreator/MainWindow.xaml.cs +++ b/Plane.FormationCreator/MainWindow.xaml.cs @@ -489,7 +489,10 @@ namespace Plane.FormationCreator if (logTextBox.Visibility == Visibility.Visible) logTextBox.Visibility = Visibility.Hidden; else + { + logTextBox.Height= Math.Max( map.ActualHeight, map3D.ActualHeight) - ((TaskBarView) TaskbarControl).TasksControl.ActualHeight; logTextBox.Visibility = Visibility.Visible; + } } private void LogTextChange(object sender, TextChangedEventArgs e) diff --git a/Plane.FormationCreator/ViewModels/MainViewModel.cs b/Plane.FormationCreator/ViewModels/MainViewModel.cs index 8da7167..27d2e85 100644 --- a/Plane.FormationCreator/ViewModels/MainViewModel.cs +++ b/Plane.FormationCreator/ViewModels/MainViewModel.cs @@ -23,7 +23,11 @@ namespace Plane.FormationCreator.ViewModels { _copterListViewModel = copterListViewModel; + //状态信息 + Plane.Windows.Messages.Message.ConfigureStatus(showAction: msg => this.SysStatusText = msg); + //日志信息 Plane.Windows.Messages.Message.Configure(showAction: msg => this.Message = msg); + //连接信息 Plane.Windows.Messages.Message.Configure(connectAction: connected => this.CommunicationModuleConnected = connected); this.SwitchVelocityModeButtonContent = GetSwitchVelocityModeButtonContent(); @@ -69,6 +73,10 @@ namespace Plane.FormationCreator.ViewModels } } + + + + private bool _CommunicationModuleConnected; public bool CommunicationModuleConnected { @@ -79,6 +87,17 @@ namespace Plane.FormationCreator.ViewModels } } + private string _SysStatusText="系统信息"; + public string SysStatusText + { + get { return _SysStatusText; } + set + { + Set(nameof(SysStatusText), ref _SysStatusText, value); + } + } + + private List _MessageList = new List(); public string Messages diff --git a/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs b/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs index 181f8d9..761498c 100644 --- a/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs +++ b/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs @@ -89,7 +89,7 @@ namespace Plane.FormationCreator.ViewModels { FlightTask task = _flightTaskManager.SelectedTask; - if (task.TaskType != FlightTaskType.FlyTo) return; + if ((task==null) ||(task.TaskType != FlightTaskType.FlyTo)) return; string newName = task.TaskCnName; if (PlaneMessageBox.OnShow("请输入新的名称", "重命名", ref newName)) diff --git a/Plane.FormationCreator/Views/MapView.xaml b/Plane.FormationCreator/Views/MapView.xaml index 4824f1f..3744515 100644 --- a/Plane.FormationCreator/Views/MapView.xaml +++ b/Plane.FormationCreator/Views/MapView.xaml @@ -41,16 +41,16 @@ > - + Click="showrealtimeline_Checked" Visibility="Collapsed" /> - + + - + @@ -145,7 +147,7 @@ - + @@ -166,7 +168,7 @@ - + diff --git a/Plane.FormationCreator/Views/TaskBarView.xaml.cs b/Plane.FormationCreator/Views/TaskBarView.xaml.cs index 35736f1..09a6be3 100644 --- a/Plane.FormationCreator/Views/TaskBarView.xaml.cs +++ b/Plane.FormationCreator/Views/TaskBarView.xaml.cs @@ -28,6 +28,60 @@ namespace Plane.FormationCreator.Views InitializeComponent(); this.DataContext = ServiceLocator.Current.GetInstance(); + + + + hintaddtask.Visibility = Visibility.Visible; + tasktabcont.Visibility = Visibility.Collapsed; + + + + _flightTaskManager.PropertyChanged += (sender, e) => + { + switch (e.PropertyName) + { + //选中任务时触发 + case nameof(FlightTaskManager.SelectedTaskIndex): + if (_flightTaskManager.Tasks.Count == 0) + { + + tasktabcont.Visibility = Visibility.Collapsed; + hintaddtask.Visibility = Visibility.Visible; + + + } + else + { + hintaddtask.Visibility = Visibility.Collapsed; + tasktabcont.Visibility = Visibility.Visible; + + if (_flightTaskManager.Tasks[_flightTaskManager.SelectedTaskIndex].TaskType == FlightTaskType.TakeOff) + { + takeoffpage.Visibility = Visibility.Visible; + landpage.Visibility = Visibility.Collapsed; + flytopage.Visibility = Visibility.Collapsed; + } + else + { + + takeoffpage.Visibility = Visibility.Collapsed; + landpage.Visibility = Visibility.Visible; + flytopage.Visibility = Visibility.Visible; + + + + } + } + + break; + default: + break; + } + }; + + + + } private FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance(); @@ -42,16 +96,17 @@ namespace Plane.FormationCreator.Views } } - //选择任务 + + + + + + //选择任务 private void SelectTask(object sender, MouseButtonEventArgs e) { var elem = sender as FrameworkElement; var task = elem.DataContext as FlightTask; - //if (task.TaskType != FlightTaskType.TakeOff) // 不让选起飞任务。 现在可以选择起飞任务 - { - _flightTaskManager.Select(task); - } - + _flightTaskManager.Select(task); } //以前的右键隐藏航点,已不用