修改起飞点任务错乱bug,修改飞机加入排序后起飞任务错乱问题

This commit is contained in:
pxzleo 2017-04-09 10:47:18 +08:00
parent 6cd247662a
commit 93ed6f778a
3 changed files with 58 additions and 16 deletions

View File

@ -24,7 +24,7 @@ namespace Plane.FormationCreator.Formation
_copterManager.Copters.CollectionChanged += (sender, e) =>
{
// TODO: 林俊清, 20150724, 需要改为正确的做法(清除旧飞机的任务,补充新飞机的任务)。
AddTakeOffTask(e.NewItems?.Cast<ICopter>());
//AddTakeOffTask(e.NewItems?.Cast<ICopter>());
};
_copterManager.SelectedCoptersChanged += (sender, e) =>
@ -101,7 +101,18 @@ namespace Plane.FormationCreator.Formation
}
}
private string _MessageText="test";
public string MessageText
{
get { return _MessageText; }
set
{
if (Set(nameof(MessageText), ref _MessageText, value))
{
// _lastUpdateStatusTextTime = DateTime.Now;
}
}
}
private double _OriginLng;
public double OriginLng
{
@ -196,6 +207,8 @@ namespace Plane.FormationCreator.Formation
var copters = _copterManager.Copters;
if (!copters.Any()) return;
AppEx.Current.AppMode = AppMode.ModifyingTask;
if (Tasks.Count == 0)
AddTakeOffTask(copters);
var lastTask = Tasks.LastOrDefault();
var nullableCenter = copters.GetCenter();
if (nullableCenter == null) return;
@ -211,9 +224,10 @@ namespace Plane.FormationCreator.Formation
int currcol = 0; //当前列号
int currrow = 0; //当前行
Tuple<double,double> colLatLng = new Tuple<double, double>(0, 0);
Tuple<double, double> colLatLng = new Tuple<double, double>(0, 0);
Tuple<double, double> targetLatLng = new Tuple<double, double>(0, 0);
FlightTaskSingleCopterInfo lastSingleCopterInfo =null;
FlightTaskSingleCopterInfo lastSingleCopterInfo = null;
foreach (var copter in copters)
{
if (coptindex == 0)
@ -221,28 +235,30 @@ namespace Plane.FormationCreator.Formation
lastSingleCopterInfo = lastTask.SingleCopterInfos.Find(info => info.Copter == copter);
targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(lastSingleCopterInfo.TargetLat, lastSingleCopterInfo.TargetLng, 0, matrixdis);
colLatLng = targetLatLng;
}
}
else
{
if (currcol < colnum)
targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(colLatLng.Item1, colLatLng.Item2, 90, currcol* coldis);
targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(colLatLng.Item1, colLatLng.Item2, 90, currcol * coldis);
else
{
currrow++;
currcol = 0;
targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(colLatLng.Item1, colLatLng.Item2, 180, rowdis);
colLatLng = targetLatLng;
}
}
}
currcol++;
coptindex++;
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2,
lastTask.SingleCopterInfos.Find(info => info.Copter == copter).TargetAlt, true);
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2, lastSingleCopterInfo.TargetAlt, true);
newSingleCopterInfo.TargetHeading = lastSingleCopterInfo.TargetHeading;
newSingleCopterInfo.CenterDirectionDeg = lastSingleCopterInfo.TargetHeading;
newTask.SingleCopterInfos.Add(newSingleCopterInfo);
}
Tasks.Add(newTask);
try
{
@ -258,6 +274,7 @@ namespace Plane.FormationCreator.Formation
}
}
public void ClearTasks()
{
ResetTasks();
@ -679,7 +696,12 @@ namespace Plane.FormationCreator.Formation
{
dynamic tasks = JsonConvert.DeserializeObject(tasksText);
var copters = _copterManager.Copters;
int i=1;
if (Tasks.Count == 0)
AddTakeOffTask(copters);
int i =1;
foreach (var task in tasks)
{
if ((i >= startindex)&& (i <= endindex))
@ -721,6 +743,8 @@ namespace Plane.FormationCreator.Formation
{
dynamic tasks = JsonConvert.DeserializeObject(tasksText);
var copters = _copterManager.Copters;
if (Tasks.Count == 0)
AddTakeOffTask(copters);
foreach (var task in tasks)
{
switch ((FlightTaskType)task.type)
@ -870,14 +894,28 @@ namespace Plane.FormationCreator.Formation
public bool? IsPaused
{
get { return _IsPaused; }
private set { Set(nameof(IsPaused), ref _IsPaused, value); }
private set {
if (Set(nameof(IsPaused), ref _IsPaused, value))
{
if (_IsPaused??false)
{
MessageText = "任务暂停!";
}else
{
MessageText = "任务运行中";
}
}
}
}
public async Task RunAsync()
{
IsPaused = false;
AppEx.Current.AppMode = AppMode.RunningTasks;
StartAvoidingCrash();
StartAvoidingCrash(); //开始碰撞检测
for (int i = CurrentRunningTaskIndex; i < Tasks.Count; i++)
{
var task = Tasks[i];
@ -928,7 +966,8 @@ namespace Plane.FormationCreator.Formation
if (copter != anotherCopter && copter.IsTooCloseTo(anotherCopter))
{
Pause();
Alert.Show($"{copter.Name} 与 {anotherCopter.Name} 距离过近,已中止任务。");
Message.Show($"{copter.Name} 与 {anotherCopter.Name} 距离过近,已中止任务。");
// Alert.Show($"{copter.Name} 与 {anotherCopter.Name} 距离过近,已中止任务。");
return;
}
}

View File

@ -12,6 +12,8 @@ namespace Plane.FormationCreator.Formation
public partial class FlightTask
{
private bool _StaggerRoutes = true;
//是否有交错
public bool StaggerRoutes
{
get { return _StaggerRoutes; }
@ -513,7 +515,7 @@ namespace Plane.FormationCreator.Formation
public async Task RunFlyToTaskAsync() // 全部飞到指定航点
{
//是否有交错
if (StaggerRoutes)
{
var infos = SingleCopterInfos;

View File

@ -103,7 +103,8 @@ namespace Plane.FormationCreator.ViewModels
// return;
Message.Show("任务开始");
await _flightTaskManager.RunAsync();
Message.Show(_flightTaskManager.IsPaused == true ? "任务暂停" : "任务完成");
if ((_flightTaskManager.IsPaused ?? false) == false)
Message.Show("任务完成");
}));
}
}