修改自动编号逻辑前

This commit is contained in:
xu 2020-02-01 22:02:25 +08:00
parent 8990d57212
commit 00d03a0025
4 changed files with 144 additions and 39 deletions

View File

@ -37,8 +37,8 @@
True="【编辑模式】" />
<cnv:BooleanToStringConverter x:Key="Show2d3dButtonContentConverter"
False="平面图"
True="三维地图" />
False="平面图"
True="立体视图" />
<cnv:BooleanToResourceConverter x:Key="CheckSignConverter"

View File

@ -13,7 +13,7 @@ using System.Windows.Input;
namespace Plane.FormationCreator.ViewModels
{
public class ConfigVirtualIdViewModel: ViewModelBase
public class ConfigVirtualIdViewModel : ViewModelBase
{
CopterManager _copterManager;
public ConfigVirtualIdViewModel(CopterManager copterManager)
@ -94,75 +94,123 @@ namespace Plane.FormationCreator.ViewModels
int colCount = SingleRowCount;
int copterCount = _copterManager.Copters.Count;
/*
if (copterCount % colCount != 0)
{
Alert.Show($"列数设置错误!");
return;
}
*/
//列数用户设置colCount
//计算行数rowCount
int rowCount = copterCount / colCount;
//有多的飞机,多一行
//有整除余,代表最后一行是否没有满
bool havemode = (copterCount % colCount != 0);
//if (havemode)
// rowCount++;
int num = 1;
if (_copterManager.AcceptingControlCopters.Count() == 4)
//目前方案是 选中3架飞机1号飞机第一排任意飞机第一列任意飞机尽量远离1号机
//用于计算横向和纵向的角度
if (_copterManager.AcceptingControlCopters.Count() == 3)
{
var copters = _copterManager.AcceptingControlCopters.ToList();
var firstCopter = copters[0];
var secondCopter = copters[1];
var thirdCopter = copters[2];
var fourthCopter = copters[3];
// var fourthCopter = copters[3];
//第一列角度
double firstColazimuth = GeographyUtils.RadToDeg(GeographyUtils.CalcDirection2D(
firstCopter.Latitude, firstCopter.Longitude,
thirdCopter.Latitude, thirdCopter.Longitude));
//最后列角度
double lastColazimuth = GeographyUtils.RadToDeg(GeographyUtils.CalcDirection2D(
secondCopter.Latitude, secondCopter.Longitude,
fourthCopter.Latitude, fourthCopter.Longitude));
//第一列角度(1,3) 用于计算每行第一架飞机
float firstColDirect =(float) GeographyUtils.RadToDeg(firstCopter.CalcDirection2D(thirdCopter));
//最后列角度(2,4) 用于计算每行最后一架飞机
float lastColDirect =(float) GeographyUtils.RadToDeg(secondCopter.CalcDirection2D(fourthCopter));
/*
// //四个角从1号机开始选取(第一排第一个1, 第一排最后2, 最后一排第一个3 , 最后一排最后4)
//第一列角度(1,3) 用于计算每行第一架飞机
float firstColazimuth = GeographyUtils.RadToDeg(GeographyUtils.CalcDirection2D(
firstCopter.Latitude, firstCopter.Longitude,
thirdCopter.Latitude, thirdCopter.Longitude));
//最后列角度(2,4) 用于计算每行最后一架飞机
float lastColazimuth = GeographyUtils.RadToDeg(GeographyUtils.CalcDirection2D(
secondCopter.Latitude, secondCopter.Longitude,
fourthCopter.Latitude, fourthCopter.Longitude));
*/
ICopter destCopter = null;
ICopter sourceCopter = null;
ICopter rowfirstCopter = null;
ICopter rowlastCopter = null;
//行头位置行尾位置用ILocation2D不用ICopter是因为可能没有飞机
ILocation2D rowLocfirst = null;
ILocation2D rowLoclast = null;
//行查找步长
int rowfindstep = 1;
//按行循环
for (int i = 0; i < rowCount; i++)
{
//第一行开始结束是12
if (i == 0)
{
rowfirstCopter = firstCopter;
rowLocfirst = rowfirstCopter;
rowlastCopter = secondCopter;
rowLoclast = rowlastCopter;
}
//最后一行3,4
else if (i == rowCount - 1)
{
rowfirstCopter = thirdCopter;
rowLocfirst = rowfirstCopter;
rowlastCopter = fourthCopter;
rowLoclast = rowlastCopter;
}
else
//中间的行找该行的第一架和最后一架飞机
{
rowfirstCopter = FindNextCopter(rowfirstCopter, firstColazimuth);
rowlastCopter = FindNextCopter(rowlastCopter, lastColazimuth);
}
if (rowfirstCopter == null || rowlastCopter == null)
{
Alert.Show($"在确认第{i+1}列时候无法找到起始或结束飞机");
return;
rowLocfirst=rowLocfirst.CalcLatLngSomeMetersAway2D(firstColDirect, 1.5f);
rowLoclast = rowLoclast.CalcLatLngSomeMetersAway2D(firstColDirect, 1.5f);
rowLocfirst.CalcLatLngSomeMetersAway2D(firstColDirect, 1.5f);
rowfirstCopter = FindNextCopter(rowLocfirst, firstColDirect, 1);
rowlastCopter = FindNextCopter(rowLoclast, lastColDirect, 1);
}
if (rowfirstCopter == null)
Message.Show($"无法找到第{i + 1}行的起始飞机");
if (rowlastCopter == null)
Message.Show($"无法找到第{i + 1}行的结束飞机");
rowfindstep = 1;
//每一行按列循环
for (int j = 0; j < colCount; j++)
{
//计算每一行方向
double curRowAzimuth = GeographyUtils.RadToDeg(GeographyUtils.CalcDirection2D(
rowfirstCopter.Latitude, rowfirstCopter.Longitude,
rowlastCopter.Latitude, rowlastCopter.Longitude));
if (j == 0)
{
destCopter = rowfirstCopter;
sourceCopter = rowfirstCopter;
}
else if (j == colCount - 1)
{
destCopter = rowlastCopter;
}
else
//按行查找飞机
{
ICopter tempCopter = null;
tempCopter = _copterManager.Copters.FirstOrDefault(o => o.VirtualId == num);
@ -173,19 +221,36 @@ namespace Plane.FormationCreator.ViewModels
tempCopter = _copterManager.Copters.FirstOrDefault(o => o.VirtualId == num);
}
destCopter = FindNextCopter(destCopter, curRowAzimuth);
//根据当前飞机destCopter按curRowAzimuth方向按间距1.5米找下一个飞机
destCopter = FindNextCopter(sourceCopter, curRowAzimuth, rowfindstep);
if (destCopter == null)
{
Alert.Show($"在寻找第{num}号位置时候无法找到对应位置飞机");
return;
Message.Show($"在寻找第{num}号位置时候无法找到对应位置飞机");
//增加步长继续找
rowfindstep++;
//Alert.Show($"在寻找第{num}号位置时候无法找到对应位置飞机");
//return;
}
else
{
rowfindstep = 1;
sourceCopter = destCopter;
}
}
destCopter.VirtualId = num;
if (destCopter != null)
{
//赋予虚拟ID
destCopter.VirtualId = num;
Message.Show($"飞机{destCopter.Name} 虚拟ID = {destCopter.VirtualId}");
Message.Show($"飞机{destCopter.Name} 虚拟ID = {destCopter.VirtualId}");
}
num++;
}
}
@ -196,37 +261,78 @@ namespace Plane.FormationCreator.ViewModels
}
private ICopter FindNextCopter(ICopter startCopter, double azimuth)
private ICopter FindNextCopter(ILocation2D startLoc, double azimuth, int findstep)
{
ICopter retCopter = null;
bool foundCopter = false;
float stepLength = 0;
double mindis = 500.0f;
while (!foundCopter)
{
stepLength += 1.5f;
mindis = 500.0f;
stepLength += 1.5f * findstep;
//计算startCopter按azimuth方向移动stepLength后的位置targetLatLng
Tuple<double, double> targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
startCopter.Latitude, startCopter.Longitude, (float)azimuth, stepLength);
startLoc.Latitude, startLoc.Longitude, (float)azimuth, stepLength);
//所有没有虚拟ID的飞机
List<ICopter> remainCopters = _copterManager.Copters.Where(o => o.VirtualId == 0).ToList();
foreach (var copter in remainCopters)
{
//计算这些飞机和targetLatLng的距离
double temp = GeographyUtils.CalcDistance2D(copter.Latitude, copter.Longitude,
targetLatLng.Item1, targetLatLng.Item2);
if (temp < 1.5)
//找最近的飞机
if (temp < mindis)
{
mindis = temp;
retCopter = copter;
}
//如果目标点最近未标注飞机小于1米就认为找到了
if (mindis < 1.0)
{
foundCopter = true;
retCopter = copter;
break;
}
}
//不找更多步长
break;
if (stepLength > 15)
{
break;
}
}
return retCopter;
if (foundCopter)
return retCopter;
else
return null;
}
//根据当前位置和角度距离查找下一个位置
private ILocation2D FindNextLocal(ILocation2D startLoc, float directionDegrees, float distance)
{
ILocation2D retLoc = null;
//计算startCopter按azimuth方向移动stepLength后的位置targetLatLng
Tuple<double, double> targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
startLoc.Latitude, startLoc.Longitude, directionDegrees, distance);
return retLoc;
}
}
}

View File

@ -104,7 +104,7 @@
Margin="5,0,0,0"
Command="{Binding ShowLackCopterNumsCommand}"/>
<Button Content="自动编号"
Margin="5,0,0,0"
Margin="5,0,0,0" Visibility="Collapsed"
Command="{Binding AutoLocationNumsCommand}"/>
<Button Content="设置"
Margin="5,0,5,0"

View File

@ -132,7 +132,6 @@ namespace Plane.FormationCreator.Views
public void AddOrMoveCopter()
{
// return;
if (!_flightTaskManager.TaskRun_2D) return; //不在2D模式运行直接退出
try
{