添加原点:
用于导入导出任务、写入航点 后续广播模式起飞需要发送给所有飞机
This commit is contained in:
parent
789988fcba
commit
3dcdacf527
@ -74,13 +74,6 @@ namespace Plane.FormationCreator.Formation
|
||||
|
||||
private CopterManager _copterManager;
|
||||
|
||||
private double _OriginLat;
|
||||
public double OriginLat
|
||||
{
|
||||
get { return _OriginLat; }
|
||||
set { Set(nameof(OriginLat), ref _OriginLat, value); }
|
||||
}
|
||||
|
||||
private int _TakeOffNumAttr = 1;
|
||||
public int TakeOffNumAttr
|
||||
{
|
||||
@ -113,12 +106,7 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
}
|
||||
}
|
||||
private double _OriginLng;
|
||||
public double OriginLng
|
||||
{
|
||||
get { return _OriginLng; }
|
||||
set { Set(nameof(OriginLng), ref _OriginLng, value); }
|
||||
}
|
||||
|
||||
|
||||
private void AddTakeOffTask(IEnumerable<ICopter> copters)
|
||||
{
|
||||
@ -198,6 +186,7 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
|
||||
public event EventHandler<FlightTaskAddedEventArgs> TaskAdded;
|
||||
public event EventHandler<FlightTaskAddedOriginalEventArgs> OnOriginalSet;
|
||||
|
||||
public event EventHandler<SingleCopterInfoChangedEventArgs> SingleCopterInfoChanged;
|
||||
|
||||
@ -285,6 +274,29 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
|
||||
|
||||
private double _OriginLat = 0;
|
||||
public double OriginLat
|
||||
{
|
||||
get { return _OriginLat; }
|
||||
set { Set(nameof(OriginLat), ref _OriginLat, value); }
|
||||
}
|
||||
|
||||
private double _OriginLng = 0;
|
||||
public double OriginLng
|
||||
{
|
||||
get { return _OriginLng; }
|
||||
set { Set(nameof(OriginLng), ref _OriginLng, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 起始点作为参考,设置起始点后飞行写入的数据将为相对坐标
|
||||
/// </summary>
|
||||
public void SetOriginal()
|
||||
{
|
||||
OnOriginalSet?.Invoke(this, new FlightTaskAddedOriginalEventArgs { Lat = OriginLat, Lng = OriginLng });
|
||||
}
|
||||
|
||||
|
||||
public void ClearTasks()
|
||||
{
|
||||
ResetTasks();
|
||||
@ -1061,6 +1073,12 @@ namespace Plane.FormationCreator.Formation
|
||||
public FlightTask AddedTask { get; set; }
|
||||
}
|
||||
|
||||
public class FlightTaskAddedOriginalEventArgs : EventArgs
|
||||
{
|
||||
public double Lat { get; set; }
|
||||
public double Lng { get; set; }
|
||||
}
|
||||
|
||||
public class SingleCopterInfoChangedEventArgs : EventArgs
|
||||
{
|
||||
public SingleCopterInfoChangedEventArgs(FlightTaskSingleCopterInfo changedSingleCopterInfo)
|
||||
|
@ -48,12 +48,14 @@ namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
get
|
||||
{
|
||||
var origin = GetOrigin();
|
||||
//var origin = GetOrigin();
|
||||
var origin = new LatLng(_flightTaskManager.OriginLat, _flightTaskManager.OriginLng);
|
||||
return new LatLng(TargetLat - origin.Lat, TargetLng - origin.Lng);
|
||||
}
|
||||
set
|
||||
{
|
||||
var origin = GetOrigin();
|
||||
//var origin = GetOrigin();
|
||||
var origin = new LatLng(_flightTaskManager.OriginLat, _flightTaskManager.OriginLng);
|
||||
TargetLat = origin.Lat + value.Lat;
|
||||
TargetLng = origin.Lng + value.Lng;
|
||||
}
|
||||
|
@ -593,6 +593,20 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// private ICommand _SetOriginalPointCommand;
|
||||
// public ICommand SetOriginalPointCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _SetOriginalPointCommand ?? (_SetOriginalPointCommand = new RelayCommand(() =>
|
||||
// {
|
||||
// FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
// _flightTaskManager.SetOriginal();
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
private ICommand _WriteMissionCommand;
|
||||
@ -606,6 +620,12 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
ViewModels.ModifyTaskViewModel _taskmodimodel = ServiceLocator.Current.GetInstance<ViewModels.ModifyTaskViewModel>();
|
||||
var _flightTaskManager = _taskmodimodel.FlightTaskManager;
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法写入相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
|
||||
int coptercount = _copterManager.Copters.Count;
|
||||
int taskcount = _flightTaskManager.Tasks.Count;
|
||||
// bool havewritefault = true;
|
||||
@ -630,8 +650,8 @@ namespace Plane.FormationCreator.ViewModels
|
||||
missions[missindex++] = Mission.CreateTakeoffMission(
|
||||
1,//1,
|
||||
5,//takeofftime,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng,
|
||||
_flightTaskManager.Tasks[j+1].SingleCopterInfos[i].TargetAlt);
|
||||
|
||||
//要起飞任务
|
||||
@ -643,8 +663,8 @@ namespace Plane.FormationCreator.ViewModels
|
||||
missions[missindex++] = Mission.CreateWaypointMission(
|
||||
5,//_flightTaskManager.Tasks[j].SingleCopterInfos[i].LoiterTime,
|
||||
5,// _flightTaskManager.Tasks[j].SingleCopterInfos[i].FlytoTime,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
|
||||
break;
|
||||
case FlightTaskType.Loiter:
|
||||
@ -1160,5 +1180,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -219,6 +219,11 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ExportTasksCommand ?? (_ExportTasksCommand = new RelayCommand(() =>
|
||||
{
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法导出相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
var exportedText = _flightTaskManager.ExportTasks();
|
||||
var dialog = new SaveFileDialog
|
||||
{
|
||||
@ -240,6 +245,11 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ImportTasksCommand ?? (_ImportTasksCommand = new RelayCommand(() =>
|
||||
{
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法导入相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
DefaultExt = "fcg",
|
||||
|
@ -65,6 +65,20 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _SetOriginCommand;
|
||||
public ICommand SetOriginCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _SetOriginCommand ?? (_SetOriginCommand = new RelayCommand(() =>
|
||||
{
|
||||
// _flightTaskManager
|
||||
// FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
_flightTaskManager.SetOriginal();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _ResetTasksCommand;
|
||||
public ICommand ResetTasksCommand
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ namespace Plane.FormationCreator.Views
|
||||
_mapManager.SetCenterGetter(() => new LatLng { Lat = map.Center.Latitude, Lng = map.Center.Longitude });
|
||||
|
||||
_flightTaskManager.TaskAdded += FlightTaskManager_TaskAdded;
|
||||
_flightTaskManager.OnOriginalSet += FlightTaskManager_SetOriginal;
|
||||
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
@ -220,6 +221,10 @@ namespace Plane.FormationCreator.Views
|
||||
rectangle = null;
|
||||
drawRectangle = false;
|
||||
};
|
||||
|
||||
|
||||
map.MouseMove += new MouseEventHandler(OriginalMove);
|
||||
map.MouseLeftButtonUp += new MouseButtonEventHandler(OriginalMouseUp);
|
||||
}
|
||||
|
||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||
@ -229,6 +234,7 @@ namespace Plane.FormationCreator.Views
|
||||
|
||||
const string COPTER_TAG = "Copter";
|
||||
const string WAYPOINT_TAG = "Waypoint";
|
||||
const string ORIGINALPOINT_TAG = "Originalpoint";
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
@ -322,7 +328,7 @@ namespace Plane.FormationCreator.Views
|
||||
while (elem != map && elem != null)
|
||||
{
|
||||
tag = elem.Tag?.ToString();
|
||||
if (tag == COPTER_TAG || tag == WAYPOINT_TAG)
|
||||
if (tag == COPTER_TAG || tag == WAYPOINT_TAG || tag == ORIGINALPOINT_TAG)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -341,6 +347,75 @@ namespace Plane.FormationCreator.Views
|
||||
}
|
||||
}
|
||||
|
||||
Ellipse original = null;
|
||||
|
||||
private void FlightTaskManager_SetOriginal(object sender, FlightTaskAddedOriginalEventArgs e)
|
||||
{
|
||||
if (map.Children.Contains(original))
|
||||
return;
|
||||
Location location = new Location();
|
||||
if (e.Lat == 0 && e.Lng == 0)
|
||||
location = map.Center;
|
||||
else
|
||||
location = new Location(e.Lat, e.Lng);
|
||||
//_flightTaskManager
|
||||
|
||||
original = new Ellipse
|
||||
{
|
||||
Tag = ORIGINALPOINT_TAG,
|
||||
Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
|
||||
StrokeThickness = 3,
|
||||
Stroke = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
|
||||
Width = 18,
|
||||
Height = 18,
|
||||
};
|
||||
|
||||
map.Children.Add(original);
|
||||
MapLayer.SetPosition(original, location);
|
||||
original.ToolTip = location.ToString();
|
||||
originaDrag = false;
|
||||
original.MouseLeftButtonDown += new MouseButtonEventHandler(OriginalMouseDown);
|
||||
|
||||
}
|
||||
|
||||
private bool originaDrag = false;
|
||||
double wpOffsetX = 0;
|
||||
double wpOffsetY = 0;
|
||||
private void OriginalMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
originaDrag = true;
|
||||
var posInObject = e.GetPosition(original);
|
||||
wpOffsetX = posInObject.X;
|
||||
wpOffsetY = posInObject.Y;
|
||||
}
|
||||
|
||||
private void OriginalMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (originaDrag)
|
||||
{
|
||||
Point eventPos = e.GetPosition(map);
|
||||
var leftTopPos = new Point(eventPos.X - wpOffsetX, eventPos.Y - wpOffsetY);
|
||||
MapLayer.SetPosition(original, map.ViewportPointToLocation(leftTopPos));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OriginalMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (originaDrag)
|
||||
{
|
||||
Point eventPos = e.GetPosition(map);
|
||||
Location location = map.ViewportPointToLocation(eventPos);
|
||||
_flightTaskManager.OriginLat = location.Latitude;
|
||||
_flightTaskManager.OriginLng = location.Longitude;
|
||||
original.ToolTip = location.ToString();
|
||||
Console.WriteLine("original-----------"+original.ToolTip);
|
||||
Clipboard.SetDataObject(string.Format("{0},{1}", location.Latitude, location.Longitude), true);
|
||||
originaDrag = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void MapSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
switch ((e.AddedItems[0] as FrameworkElement).Tag.ToString())
|
||||
|
@ -127,6 +127,9 @@
|
||||
<Button Content="强制下一步"
|
||||
Background="#232323"
|
||||
Command="{Binding NextTasksCommand}" />
|
||||
<Button Content="设置原点"
|
||||
Background="#232323"
|
||||
Command="{Binding SetOriginCommand}" />
|
||||
<!--<Button Content="保存" />
|
||||
<Button Content="取消" />-->
|
||||
</StackPanel>
|
||||
|
Loading…
Reference in New Issue
Block a user