方便批量编辑航点
[MainWindow.xaml.cs]增加键盘wsad调整多个选中航点 [CopterListViewModel.cs]增加多个航点编辑的对齐和均分按钮,目前支持0度和90度(水平和垂直),以后考虑任意角度 [CopterListView.xaml]增加按钮的界面
This commit is contained in:
parent
fda55a6e45
commit
09126211a1
@ -42,7 +42,7 @@ namespace Plane.FormationCreator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||||
|
private FlightTaskManager _flightTaskManager= ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||||
private void ShowConnectDialog(ConnectWindow loginWindow = null)
|
private void ShowConnectDialog(ConnectWindow loginWindow = null)
|
||||||
{
|
{
|
||||||
//var result = await this.ShowLoginAsync("登录", "请输入您的帐户 ID 和密码");
|
//var result = await this.ShowLoginAsync("登录", "请输入您的帐户 ID 和密码");
|
||||||
@ -104,6 +104,7 @@ namespace Plane.FormationCreator
|
|||||||
bool isledon;
|
bool isledon;
|
||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
{
|
{
|
||||||
|
|
||||||
//开关SHOWLED
|
//开关SHOWLED
|
||||||
case Key.C:
|
case Key.C:
|
||||||
{
|
{
|
||||||
@ -121,6 +122,32 @@ namespace Plane.FormationCreator
|
|||||||
case Key.W:
|
case Key.W:
|
||||||
case Key.S:
|
case Key.S:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (_flightTaskManager.CurrentRunningTask==null )
|
||||||
|
{
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat+= e.Key == Key.W ? 0.00001 : -0.00001;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var copters = _copterManager.AcceptingControlCopters;
|
var copters = _copterManager.AcceptingControlCopters;
|
||||||
await Task.WhenAll(copters.Select(async copter =>
|
await Task.WhenAll(copters.Select(async copter =>
|
||||||
{
|
{
|
||||||
@ -139,6 +166,47 @@ namespace Plane.FormationCreator
|
|||||||
case Key.A:
|
case Key.A:
|
||||||
case Key.D:
|
case Key.D:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (_flightTaskManager.CurrentRunningTask == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng += e.Key == Key.D ? 0.00001 : -0.00001;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var copters = _copterManager.AcceptingControlCopters;
|
var copters = _copterManager.AcceptingControlCopters;
|
||||||
await Task.WhenAll(copters.Select(async copter =>
|
await Task.WhenAll(copters.Select(async copter =>
|
||||||
{
|
{
|
||||||
|
@ -46,11 +46,11 @@ namespace Plane.FormationCreator.ViewModels
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _AddVirtualCopterCommand ?? (_AddVirtualCopterCommand = new RelayCommand<int>(async count =>
|
return _AddVirtualCopterCommand ?? (_AddVirtualCopterCommand = new RelayCommand<int>(async addcount =>
|
||||||
{
|
{
|
||||||
var center = _mapManager.Center;
|
var center = _mapManager.Center;
|
||||||
string id;
|
string id;
|
||||||
for (int i = 0; i < count; ++i, ++_virtualCopterId)
|
for (int i = 0; i < addcount; ++i, ++_virtualCopterId)
|
||||||
{
|
{
|
||||||
id = _virtualCopterId.ToString();
|
id = _virtualCopterId.ToString();
|
||||||
_lastVirtualCopterLocation =
|
_lastVirtualCopterLocation =
|
||||||
@ -96,5 +96,251 @@ namespace Plane.FormationCreator.ViewModels
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ICommand _AverageCommand;
|
||||||
|
public ICommand AverageCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _AverageCommand ?? (_AverageCommand = new RelayCommand<int>(async alignmentLine =>
|
||||||
|
{
|
||||||
|
double maxlat = 0;
|
||||||
|
double tlat = 0;
|
||||||
|
double minlat = 0;
|
||||||
|
|
||||||
|
double maxlng = 0;
|
||||||
|
double minlng = 0;
|
||||||
|
double tlng = 0;
|
||||||
|
double avgl=0;
|
||||||
|
|
||||||
|
if (alignmentLine == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
int selectednumber = _copterManager.SelectedCopters.Count()-1;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
tlng = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
|
||||||
|
if (minlng == 0)
|
||||||
|
minlng = tlng;
|
||||||
|
if (tlng > maxlng)
|
||||||
|
maxlng = tlng;
|
||||||
|
else if (tlng < minlng)
|
||||||
|
minlng = tlng;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avgl = (maxlng - minlng) / selectednumber;
|
||||||
|
int coptnum = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng= minlng+ avgl*coptnum;
|
||||||
|
coptnum++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (alignmentLine == 90)
|
||||||
|
{
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
int selectednumber = _copterManager.SelectedCopters.Count() - 1;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
|
||||||
|
if (minlat == 0)
|
||||||
|
minlat = tlat;
|
||||||
|
if (tlat > maxlat)
|
||||||
|
maxlat = tlat;
|
||||||
|
else if (tlat < minlat)
|
||||||
|
minlat = tlat;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avgl = (maxlat - minlat) / selectednumber;
|
||||||
|
int coptnum = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = minlat + avgl * coptnum;
|
||||||
|
coptnum++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
|
||||||
|
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private ICommand _AlignmentCommand;
|
||||||
|
public ICommand AlignmentCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _AlignmentCommand ?? (_AlignmentCommand = new RelayCommand<int>(async alignmentLine =>
|
||||||
|
{
|
||||||
|
double maxlat = 0;
|
||||||
|
double tlat = 0;
|
||||||
|
|
||||||
|
double maxlng = 0;
|
||||||
|
double tlng = 0;
|
||||||
|
|
||||||
|
if (alignmentLine == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
|
||||||
|
if (tlat > maxlat)
|
||||||
|
maxlat = tlat;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = maxlat;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (alignmentLine == 90)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||||
|
bool copterisselect;
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
tlng = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
|
||||||
|
if (tlng > maxlng)
|
||||||
|
maxlng = tlng;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||||
|
{
|
||||||
|
copterisselect = false;
|
||||||
|
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||||
|
foreach (var capter in _copterManager.SelectedCopters)
|
||||||
|
{
|
||||||
|
if (capter == selectedCopter)
|
||||||
|
copterisselect = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (copterisselect)
|
||||||
|
{
|
||||||
|
|
||||||
|
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng = maxlng;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
|
||||||
|
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,16 +55,30 @@
|
|||||||
<StackPanel Grid.Row="1"
|
<StackPanel Grid.Row="1"
|
||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
<TextBox x:Name="txtVirtualCopterCount"
|
<TextBox x:Name="txtVirtualCopterCount"
|
||||||
Width="100"
|
Width="35"
|
||||||
Margin="0,0,5,0"
|
Margin="0,0,5,0"
|
||||||
Text="3"
|
Text="3"
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
<Button Content="添加虚拟飞行器"
|
<Button Content="添加虚拟"
|
||||||
VerticalContentAlignment="Center"
|
VerticalContentAlignment="Center"
|
||||||
Command="{Binding AddVirtualCopterCommand}"
|
Command="{Binding AddVirtualCopterCommand}"
|
||||||
CommandParameter="{Binding ElementName=txtVirtualCopterCount, Path=Text}" />
|
CommandParameter="{Binding ElementName=txtVirtualCopterCount, Path=Text}" />
|
||||||
<Button Content="清除"
|
<Button Content="清除"
|
||||||
Command="{Binding ClearCoptersCommand}" />
|
Command="{Binding ClearCoptersCommand}" />
|
||||||
|
<TextBox x:Name="txtAlignmentLine"
|
||||||
|
Width="30"
|
||||||
|
Margin="0,0,5,0"
|
||||||
|
Text="0"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<Button Content="对齐"
|
||||||
|
|
||||||
|
Command="{Binding AlignmentCommand}"
|
||||||
|
CommandParameter="{Binding ElementName=txtAlignmentLine, Path=Text}"/>
|
||||||
|
<Button Content="均分"
|
||||||
|
|
||||||
|
Command="{Binding AverageCommand}"
|
||||||
|
CommandParameter="{Binding ElementName=txtAlignmentLine, Path=Text}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user