导入外部起飞形状
This commit is contained in:
parent
417f761e40
commit
3719c74753
@ -712,7 +712,140 @@ namespace Plane.FormationCreator.Formation
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
//导入外部航点
|
||||
|
||||
public void ImportC4DFlytoVCopter(string txt)
|
||||
{
|
||||
string[] lines = txt.Replace("\r\n", "\n").Split('\n');
|
||||
|
||||
if (lines.Length % (_copterManager.Copters.Count + 1) != 0)
|
||||
{
|
||||
Alert.Show("文件内容错误!");
|
||||
return;
|
||||
}
|
||||
|
||||
int taskCount = lines.Length / (_copterManager.Copters.Count + 1);
|
||||
int startIndex;
|
||||
string line;
|
||||
Dictionary<int, string[]> PointDic;
|
||||
for (int i = 0; i < taskCount; i++)
|
||||
{
|
||||
startIndex = i * (_copterManager.Copters.Count + 1);
|
||||
string taskName = lines[startIndex];
|
||||
PointDic = new Dictionary<int, string[]>();
|
||||
for (int j = 0; j < _copterManager.Copters.Count; j++)
|
||||
{
|
||||
line = lines[startIndex + j + 1];
|
||||
string[] parameters = line.Split(' ');
|
||||
int id = Convert.ToInt32(parameters[0]);
|
||||
string frame = parameters[1];
|
||||
string[] point = new string[3];
|
||||
point[0] = parameters[1]; //左右 经度
|
||||
point[1] = parameters[2]; //上下 高度
|
||||
point[2] = parameters[3]; //前后 纬度
|
||||
PointDic.Add(id, point);
|
||||
}
|
||||
|
||||
var lastTask = Tasks.LastOrDefault();
|
||||
var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = true, FlytoTime = 10, LoiterTime = 1 };
|
||||
newTask.TaskCnName = taskName;
|
||||
for (int k = 0; k < PointDic.Count; k++)
|
||||
{
|
||||
string[] point = PointDic[k + 1];
|
||||
|
||||
//string frame = parameters[1];
|
||||
string x = point[0]; //左右 经度
|
||||
string y = point[1]; //上下 高度
|
||||
string z = point[2]; //前后 纬度
|
||||
Tuple<double, double> observationLatLng = null;
|
||||
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
|
||||
OriginLat,
|
||||
OriginLng,
|
||||
90,
|
||||
Convert.ToSingle(x) / 100);
|
||||
|
||||
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
|
||||
observationLatLng.Item1,
|
||||
observationLatLng.Item2,
|
||||
0,
|
||||
Convert.ToSingle(z) / 100);
|
||||
|
||||
var fc = _copterManager.Copters[k] as FakeCopter;
|
||||
double vlatitude = observationLatLng.Item1;
|
||||
double vlongitude = observationLatLng.Item2;
|
||||
|
||||
|
||||
fc.SetProperties(
|
||||
latitude: vlatitude,
|
||||
longitude: vlongitude,
|
||||
altitude: Convert.ToSingle(y) / 100);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Tasks.Add(newTask);
|
||||
RaiseTaskAdded(lastTask, newTask);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ImportDlltoVCopter(string filename)
|
||||
{
|
||||
Vector3[] vc;
|
||||
|
||||
|
||||
|
||||
|
||||
string extname = Path.GetExtension(filename);
|
||||
if (extname == ".svg")
|
||||
{
|
||||
vc = FlyBase.svgToPos(filename);
|
||||
}
|
||||
else if (extname == ".obj")
|
||||
{
|
||||
vc = FlyBase.objToPos(filename);
|
||||
}
|
||||
else return;
|
||||
|
||||
if (vc.Count() != _copterManager.Copters.Count)
|
||||
{
|
||||
Alert.Show($"飞机数量不匹配!导入{vc.Count()}架,实际{_copterManager.Copters.Count}");
|
||||
return;
|
||||
}
|
||||
int id = 0;
|
||||
foreach (Vector3 item in vc)
|
||||
{
|
||||
Tuple<double, double> observationLatLng = null;
|
||||
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
|
||||
OriginLat,
|
||||
OriginLng,
|
||||
90,
|
||||
(float)item.x / 100);
|
||||
|
||||
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
|
||||
observationLatLng.Item1,
|
||||
observationLatLng.Item2,
|
||||
0,
|
||||
(float)item.z / 100);
|
||||
|
||||
|
||||
var fc = _copterManager.Copters[id] as FakeCopter;
|
||||
double vlatitude = observationLatLng.Item1;// - OriginLat;
|
||||
double vlongitude = observationLatLng.Item2;// - OriginLng;
|
||||
|
||||
|
||||
fc.SetProperties(
|
||||
latitude: vlatitude,
|
||||
longitude: vlongitude,
|
||||
altitude: (float)item.y / 100);
|
||||
id++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//导入外部航点
|
||||
public void ImportDlltoTask(string filename)
|
||||
{
|
||||
Vector3[] vc;
|
||||
@ -736,7 +869,9 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
var lastTask = Tasks.LastOrDefault();
|
||||
var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = true, FlytoTime = 10, LoiterTime = 1 };
|
||||
newTask.TaskCnName = Path.GetFileNameWithoutExtension(filename).Substring(0,6);
|
||||
string vname=Path.GetFileNameWithoutExtension(filename);
|
||||
if (vname.Length>6) vname= vname.Substring(0, 6);
|
||||
newTask.TaskCnName = vname;
|
||||
int id =0;
|
||||
foreach (Vector3 item in vc)
|
||||
{
|
||||
|
@ -340,8 +340,8 @@ namespace Plane.FormationCreator.ViewModels
|
||||
// copter.VirtualId = _virtualCopterId;
|
||||
await copter.ConnectAsync();
|
||||
await copter.GetCopterDataAsync();
|
||||
_copterManager.Copters.AddCopter(copter, _copterManager.SortType);
|
||||
_copterManager.CopterStatus.Add(false);
|
||||
_copterManager.Copters.AddCopter(copter, _copterManager.SortType);
|
||||
}
|
||||
}
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
|
@ -713,6 +713,52 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
|
||||
|
||||
private ICommand _ImportBlenderrCopterPosCommand;
|
||||
public ICommand ImportBlenderCopterPosCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ImportBlenderrCopterPosCommand ?? (_ImportBlenderrCopterPosCommand = new RelayCommand<int>(async =>
|
||||
{
|
||||
|
||||
//有不是虚拟飞机的直接退出
|
||||
foreach (var copter in _copterManager.Copters)
|
||||
{
|
||||
if (!(copter is FakeCopter))
|
||||
{
|
||||
Alert.Show($"导入起飞位置只能用于虚拟飞机,{copter.Id}不是虚拟飞机", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
DefaultExt = "txt",
|
||||
Filter = "航点文件(*.txt,*.svg,*.obj) |*.txt;*.svg;*.obj" // "图片文件(*.jpg, *.gif, *.bmp, *.png) | *.jpg; *.gif; *.bmp; *.png"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
string extname = Path.GetExtension(dialog.FileName);
|
||||
if (extname == ".txt")
|
||||
{
|
||||
var tasksText = File.ReadAllText(dialog.FileName);
|
||||
_flightTaskManager.ImportC4DFlytoVCopter(tasksText);
|
||||
}
|
||||
else
|
||||
if ((extname == ".svg") || (extname == ".obj"))
|
||||
{
|
||||
_flightTaskManager.ImportDlltoVCopter(dialog.FileName);
|
||||
};
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private ICommand _ExportWayPointCommand;
|
||||
|
@ -564,10 +564,11 @@
|
||||
<StackPanel x:Name="PanelDesign1">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,5,0,5" >
|
||||
<Button Width="120" Margin="10,5,0,5" Content="导入外部航点" Command="{Binding ImportBlenderWayPointCommand}"/>
|
||||
<Button Width="120" Margin="10,5,0,5" Content="导入起飞位置" Command="{Binding ImportBlenderCopterPosCommand}"/>
|
||||
<Button Width="120" Content="自动飞行时间" Margin="10,5,0,5"
|
||||
Command="{Binding AutoWayPointAllTmCommand}" HorizontalAlignment="Right" />
|
||||
<Button Width="120" Content="飞行图案设计" Margin="10,5,0,5"
|
||||
Command="{Binding SetHorseRaceLampCommand}" HorizontalAlignment="Right" Height="26"/>
|
||||
<Button Width="120" Content="飞行图案" Margin="10,5,0,5"
|
||||
Command="{Binding SetHorseRaceLampCommand}" Visibility="Collapsed" HorizontalAlignment="Right" Height="26"/>
|
||||
</StackPanel>
|
||||
<Separator Margin="5,0,5,0" />
|
||||
</StackPanel>
|
||||
|
Loading…
Reference in New Issue
Block a user