Plane.FormationCreator/Plane.FormationCreator/Formation/CopterManager.cs
xu 1e38390fc6 按VID排序
修改自动编号逻辑
//目前方案是
                //1.保证所有没有正确定位的飞机都人工编号,
                //2.然后选中2-3架飞机,1号飞机,第一排任意飞机,第一列任意飞机(尽量远离1号机),
                //3.开始计算
修改3飞机信息通道数据改为电池图标,并且不让拖动修改
显示VID变换黄色,以前是红色
2020-02-03 23:44:55 +08:00

200 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Plane.Copters;
using GalaSoft.MvvmLight;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plane.FormationCreator.Util;
namespace Plane.FormationCreator.Formation
{
public class CopterCollection : ObservableCollection<ICopter>
{
/// <summary>
/// 实现排序插入
/// </summary>
/// <param name="baseSemObjects"></param>
public int AddCopter(ICopter entityObject,bool sortbyid=true)
{
////给第三方时候限制数量和时间用
DateTime dateTime2019 = DateTime.Parse("2020-03-01");
//新增飞机区域限制:内蒙
// if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756
// || entityObject.Longitude < 97.3493089056 || entityObject.Longitude > 115.8006783856)
// return 0;
if (DateTime.UtcNow > dateTime2019)
{
throw new NotImplementedException();
}
if (this.Count >= VersionControl.CopterUpperLimit)
{
return 0;
}
int _index = 0;
if (this.Count == 0)
{
Add(entityObject);
_index = 0;
}
else
{
bool isInsret = false;
for (int i = 0; i < this.Count; i++)
{
//按ID排序插入
if (sortbyid)
{
if (int.Parse(this[i].Id) > int.Parse(entityObject.Id))
{
InsertItem(i, entityObject);
isInsret = true;
_index = i;
break;
}
}else
//按VID排序插入
{
if (this[i].VirtualId > entityObject.VirtualId)
{
InsertItem(i, entityObject);
isInsret = true;
_index = i;
break;
}
}
}
if (!isInsret)
{
Add(entityObject);
_index = this.Count()-1 ;
}
}
return _index;
}
}
public class CopterManager : ObservableObject
{
public CopterManager()
{
AppEx.Current.AppModeChanged += (sender, e) =>
{
RaisePropertyChanged(nameof(Copters));
};
App.Current.Exit += (sender, e) =>
{
Task.WhenAll(Copters.Select(c => c.DisconnectAsync()));
};
}
public List<ICopter> ShowCopter = new List<ICopter>();
public CopterCollection Copters { get;} = new CopterCollection();
public ArrayList CopterStatus = new ArrayList();
//public ObservableCollection<ICopter> Copters
//{
// get
// {
// switch (AppEx.Instance.CurrentMode)
// {
// case AppMode.ControllingCopters:
// default:
// return CoptersForControlling;
// case AppMode.PreparedForRunningTasks:
// case AppMode.ModifyingTask:
// return CoptersForModifyingTask;
// case AppMode.RunningTasks:
// throw new NotImplementedException();
// }
// }
//}
public bool shiftkeydown;
public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } }
/// <summary>
/// 注意:为避免多线程操作出问题,每次使用此属性时都会新建一个 List
/// </summary>
public IEnumerable<ICopter> AcceptingControlCopters { get { return SelectedCopters.ToList(); } }
private int _SeletedCopterCount;
public int SeletedCopterCount
{
get { return _SeletedCopterCount; }
set { Set(nameof(SeletedCopterCount), ref _SeletedCopterCount, value); }
}
private Func<IList> _selectedCoptersGetter;
private Action<ICopter> _selectCopterAction;
public void SetSelectionDelegates(Func<IList> selectedCoptersGetter, Action<ICopter> selectCopterAction)
{
_selectedCoptersGetter = selectedCoptersGetter;
_selectCopterAction = selectCopterAction;
}
public event EventHandler<SelectedCoptersChangedEventArgs> SelectedCoptersChanged;
public void RaiseSelectedCoptersChanged(IEnumerable<ICopter> addedCopters, IEnumerable<ICopter> removedCopters)
{
SelectedCoptersChanged?.Invoke(this, new SelectedCoptersChangedEventArgs { AddedCopters = addedCopters, RemovedCopters = removedCopters });
SeletedCopterCount = SelectedCopters.Count();
}
/// <summary>
/// 选择飞机
/// </summary>
/// <param name="copter">Null表示清除所有选择</param>
public void Select(ICopter copter)
{
_selectCopterAction(copter);
}
/// <summary>
/// 按VID重新排序飞机
/// </summary>
public void sortbyvid()
{
List<ICopter> tempCopters = new List<ICopter>();
tempCopters.AddRange(Copters);
Copters.Clear();
foreach (var copter in tempCopters)
Copters.AddCopter(copter,false);
}
/// <summary>
/// 按原始ID重新排序飞机
/// </summary>
public void sortbyid()
{
List<ICopter> tempCopters = new List<ICopter>();
tempCopters.AddRange(Copters);
Copters.Clear();
foreach (var copter in tempCopters)
Copters.AddCopter(copter);
}
}
public class SelectedCoptersChangedEventArgs : EventArgs
{
public IEnumerable<ICopter> AddedCopters { get; set; }
public IEnumerable<ICopter> RemovedCopters { get; set; }
}
}