diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs
index 655c457..1c51c57 100644
--- a/Plane.FormationCreator/App.xaml.cs
+++ b/Plane.FormationCreator/App.xaml.cs
@@ -261,6 +261,13 @@ namespace Plane.FormationCreator
lock(locker)
{
var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == id.ToString());
+ if ((copter != null)&&(copter is FakeCopter))
+ {
+ _copterManager.Copters.Remove(copter);
+ copter = null;
+ }
+
+
if (copter == null)
{
if (_copterManager.EnAddCopter_Real())
@@ -273,6 +280,7 @@ namespace Plane.FormationCreator
Id = id.ToString(),
Name = id.ToString(),
};
+ copter.VirtualId = 0;
int _index;
_index = _copterManager.Copters.AddCopter(copter);
copterStatus.Insert(_index, false);
diff --git a/Plane.FormationCreator/Converters/HeartbeatCountToBrushConverter.cs b/Plane.FormationCreator/Converters/HeartbeatCountToBrushConverter.cs
index 253662f..cc64b1d 100644
--- a/Plane.FormationCreator/Converters/HeartbeatCountToBrushConverter.cs
+++ b/Plane.FormationCreator/Converters/HeartbeatCountToBrushConverter.cs
@@ -17,12 +17,22 @@ namespace Plane.FormationCreator.Converters
private static SolidColorBrush _zeroBrush = new SolidColorBrush(Color.FromArgb(125, 125, 125, 125));
private static SolidColorBrush _oneBrush = Copter.DefaultBrush;
+ private static SolidColorBrush _FakeCopterBrush = Copter.DefaultFakeBrush;
+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] == DependencyProperty.UnsetValue) return _zeroBrush;
var heartbeatCount = (ulong)values[0];
if (heartbeatCount % 2 == 0) return _zeroBrush;
+
+ if (values[1] is FakeCopter)
+ return _FakeCopterBrush;
+
+ if (values[1] is PLCopter)
+ return _oneBrush;
+
var copter = values[1] as Copter;
+
return copter == null ? _oneBrush : copter.Brush;
}
diff --git a/Plane.FormationCreator/Formation/Copter.cs b/Plane.FormationCreator/Formation/Copter.cs
index c16fd4e..6c1d209 100644
--- a/Plane.FormationCreator/Formation/Copter.cs
+++ b/Plane.FormationCreator/Formation/Copter.cs
@@ -43,8 +43,12 @@ namespace Plane.FormationCreator.Formation
{
return _brushIndex++ % _brushes.Length;
}
+ //真实飞机列表默认颜色
+ internal static SolidColorBrush DefaultBrush { get; } = new SolidColorBrush(Color.FromRgb(50, 205, 50));
+ //虚拟飞机列表默认颜色
+ internal static SolidColorBrush DefaultFakeBrush { get; } = new SolidColorBrush(Color.FromRgb(28, 151, 234));
+
- internal static SolidColorBrush DefaultBrush { get; } = new SolidColorBrush(Color.FromRgb(28, 151, 234));
private SolidColorBrush _Brush;
public SolidColorBrush Brush
{
diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs
index b3ab4a2..7682aa9 100644
--- a/Plane.FormationCreator/Formation/CopterManager.cs
+++ b/Plane.FormationCreator/Formation/CopterManager.cs
@@ -90,6 +90,45 @@ namespace Plane.FormationCreator.Formation
}
else
{
+ //删除重复
+ // if (entityObject is PLCopter)
+ // {
+ for (int i = 0; i < this.Count; i++)
+ {
+ if (sortbyid)
+ {
+ if (int.Parse(this[i].Id) == int.Parse(entityObject.Id))
+ {
+ if (this[i] is FakeCopter)
+ Remove(this[i]);
+ else
+ {
+ Message.Show($"无法加入飞机,已有重复的真实飞机ID[{this[i].Id}]!");
+ return -1;
+ }
+
+ }
+ }else
+ {
+
+ if ((entityObject.VirtualId!=0) &&(this[i].VirtualId == entityObject.VirtualId))
+ {
+ if (this[i] is FakeCopter)
+ Remove(this[i]);
+ else
+ {
+ Message.Show($"无法加入飞机,已有重复的真实飞机ID[{this[i].VirtualId}]!");
+ return -1;
+ }
+
+ }
+
+ }
+
+ }
+ // }
+
+
bool isInsret = false;
for (int i = 0; i < this.Count; i++)
{
@@ -103,13 +142,15 @@ namespace Plane.FormationCreator.Formation
_index = i;
break;
- }
- }else
+ }
+ }
+ else
//按VID排序插入
{
if (this[i].VirtualId > entityObject.VirtualId)
{
+
InsertItem(i, entityObject);
isInsret = true;
_index = i;
@@ -210,6 +251,35 @@ namespace Plane.FormationCreator.Formation
netStatusChanged(Logined,Loginstate);
}
}
+ public enum CopterSortType { ByID, ByVID, ByVIDShowAll };
+ //排序类型
+ private CopterSortType _SortType =0;
+ public CopterSortType SortType
+ {
+ get { return _SortType; }
+ set
+ {
+ Set(nameof(SortType), ref _SortType, value);
+ switch (value)
+ {
+ case CopterSortType.ByID:
+ sortbyid();
+ break;
+ case CopterSortType.ByVID:
+ sortbyvid();
+ break;
+ case CopterSortType.ByVIDShowAll:
+ sortbyvid(true);
+ break;
+ default:
+ sortbyid();
+ break;
+ }
+
+
+ }
+ }
+
private int _EnCopterNumber = 0;
@@ -639,13 +709,21 @@ namespace Plane.FormationCreator.Formation
///
/// 按VID重新排序飞机
///
- public void sortbyvid()
+ public void sortbyvid(bool displayid=false)
{
List tempCopters = new List();
tempCopters.AddRange(Copters);
Copters.Clear();
foreach (var copter in tempCopters)
Copters.AddCopter(copter,false);
+
+ foreach (var copter in Copters)
+ {
+ copter.DisplayVirtualId = true;
+ copter.DisplayID = displayid;
+ }
+
+
}
///
/// 按原始ID重新排序飞机
@@ -657,6 +735,11 @@ namespace Plane.FormationCreator.Formation
Copters.Clear();
foreach (var copter in tempCopters)
Copters.AddCopter(copter);
+ foreach (var copter in Copters)
+ {
+ copter.DisplayVirtualId = false;
+ copter.DisplayID = true;
+ }
}
}
diff --git a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs
index ec16bc3..bf9b35c 100644
--- a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs
+++ b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs
@@ -154,7 +154,7 @@ namespace Plane.FormationCreator.Formation
LEDTestRun = true;
foreach (LEDInfo vLEDInfo in LEDInfos)
{
- Thread.Sleep((int)vLEDInfo.Delay * 1000);
+ Thread.Sleep((int)(vLEDInfo.Delay * 1000));
if (!LEDTestRun) break;
_commModuleManager.LED_TaskAsync(vLEDInfo.LEDMode, vLEDInfo.LEDInterval, vLEDInfo.LEDTimes, vLEDInfo.LEDRGB, this.Copter);
}
diff --git a/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs b/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs
index bfe406b..ced2182 100644
--- a/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ConfigVirtualIdViewModel.cs
@@ -108,7 +108,9 @@ namespace Plane.FormationCreator.ViewModels
copter.VirtualId = int.Parse(arrs[1]);
}
}
- Message.Show($"读入成功");
+
+ _copterManager.SortType = CopterManager.CopterSortType.ByVID;// .sortbyvid();
+ Message.Show($"读入成功");
}));
}
}
diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
index ac73a58..c00a5c0 100644
--- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
@@ -169,16 +169,9 @@ namespace Plane.FormationCreator.ViewModels
{
return _SortbyVIdCommand ?? (_SortbyVIdCommand = new RelayCommand( () =>
{
- _copterManager.sortbyvid();
-
-
- foreach (var copter in _copterManager.Copters)
- {
- copter.DisplayVirtualId = true;
- copter.DisplayID = false;
- }
+ _copterManager.SortType = CopterManager.CopterSortType.ByVID;
//强制刷新飞机显示
- // _copterManager.Copters.ForEach(copter => copter.RefreashLoc());
+ // _copterManager.Copters.ForEach(copter => copter.RefreashLoc());
}));
@@ -193,14 +186,10 @@ namespace Plane.FormationCreator.ViewModels
{
return _SortbyIdCommand ?? (_SortbyVIdCommand = new RelayCommand(() =>
{
- _copterManager.sortbyid();
- foreach (var copter in _copterManager.Copters)
- {
- copter.DisplayVirtualId = false;
- copter.DisplayID = true;
- }
+ _copterManager.SortType = CopterManager.CopterSortType.ByID;
+
//强制刷新飞机显示
- // _copterManager.Copters.ForEach(copter => copter.RefreashLoc());
+ // _copterManager.Copters.ForEach(copter => copter.RefreashLoc());
}));
}
@@ -223,24 +212,6 @@ namespace Plane.FormationCreator.ViewModels
}
}
- bool showVirtualId = false;
-
- private ICommand _SwitchIdVirtualIdCommand;
- public ICommand SwitchIdVirtualIdCommand
- {
- get
- {
- return _SwitchIdVirtualIdCommand ?? (_SwitchIdVirtualIdCommand = new RelayCommand(() =>
- {
- showVirtualId = !showVirtualId;
- foreach (var copter in _copterManager.Copters)
- {
- copter.DisplayVirtualId = showVirtualId;
- }
- }));
- }
- }
-
@@ -251,11 +222,9 @@ namespace Plane.FormationCreator.ViewModels
{
return _ShowAllIDCommand ?? (_ShowAllIDCommand = new RelayCommand(() =>
{
- foreach (var copter in _copterManager.Copters)
- {
- copter.DisplayVirtualId = true;
- copter.DisplayID = true;
- }
+
+ _copterManager.SortType = CopterManager.CopterSortType.ByVIDShowAll;
+
//强制刷新飞机显示
// _copterManager.Copters.ForEach(copter => copter.RefreashLoc());
@@ -367,6 +336,7 @@ namespace Plane.FormationCreator.ViewModels
id: id,
name: id
);
+ copter.VirtualId = _virtualCopterId;
await copter.ConnectAsync();
await copter.GetCopterDataAsync();
_copterManager.Copters.AddCopter(copter);