添加鼠标框选航点以及选中点拖动
This commit is contained in:
parent
db8059a265
commit
789988fcba
@ -111,6 +111,10 @@ namespace Plane.FormationCreator.Formation
|
||||
SelectedCoptersChanged?.Invoke(this, new SelectedCoptersChangedEventArgs { AddedCopters = addedCopters, RemovedCopters = removedCopters });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择飞机
|
||||
/// </summary>
|
||||
/// <param name="copter">Null表示清除所有选择</param>
|
||||
public void Select(ICopter copter)
|
||||
{
|
||||
_selectCopterAction(copter);
|
||||
|
@ -63,7 +63,7 @@ namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
return _ModiFlytoLEDCommand ?? (_ModiFlytoLEDCommand = new RelayCommand<double>(async =>
|
||||
{
|
||||
Alert.Show("sfsdf");
|
||||
Alert.Show("灯光控制");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -43,12 +43,27 @@ namespace Plane.FormationCreator.Views
|
||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||
private void SelectitemMessage(ICopter copter)
|
||||
{
|
||||
|
||||
|
||||
if (!_copterManager.shiftkeydown)
|
||||
lvwDrones.SelectedItem = copter;
|
||||
if (copter == null)
|
||||
{
|
||||
lvwDrones.SelectedItems.Clear();
|
||||
}
|
||||
else
|
||||
lvwDrones.SelectedItems.Add(copter);
|
||||
{
|
||||
if (!_copterManager.shiftkeydown)
|
||||
{
|
||||
lvwDrones.SelectedItems.Clear();
|
||||
lvwDrones.SelectedItem = copter;
|
||||
}
|
||||
else
|
||||
lvwDrones.SelectedItems.Add(copter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SelectitemClearMessage(ICopter copter)
|
||||
{
|
||||
lvwDrones.SelectedItems.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
>
|
||||
<CheckBox Grid.Row="0" Content="所有航点" Margin="5,5,0,0"
|
||||
Click="showallpoint_Checked"
|
||||
Foreground="White"
|
||||
Foreground="White" IsChecked="True"
|
||||
/>
|
||||
<CheckBox Grid.Row="0" Content="计划航线" Margin="5,5,0,0"
|
||||
Click="showpanline_Checked"
|
||||
|
@ -30,6 +30,7 @@ using Microsoft.Practices.ServiceLocation;
|
||||
using Plane.FormationCreator.ViewModels;
|
||||
using Plane.Geography;
|
||||
using Plane.FormationCreator.Maps;
|
||||
using Plane.Windows.Messages;
|
||||
|
||||
namespace Plane.FormationCreator.Views
|
||||
{
|
||||
@ -132,12 +133,16 @@ namespace Plane.FormationCreator.Views
|
||||
var centerLng = copters.Average(c => c.Longitude);
|
||||
var latDelta = pos.Latitude - centerLat;
|
||||
var lngDelta = pos.Longitude - centerLng;
|
||||
|
||||
|
||||
await Task.WhenAll(copters.Select(copter => copter.FlyToAsync(copter.Latitude + latDelta, copter.Longitude + lngDelta, copter.Altitude)));
|
||||
};
|
||||
|
||||
var center = _appConfig.Center;
|
||||
map.Center = new Location(center.Lat, center.Lng);
|
||||
map.ZoomLevel = _appConfig.ZoomLevel;
|
||||
|
||||
|
||||
map.ViewChangeOnFrame += (object sender, MapEventArgs e) =>
|
||||
{
|
||||
if ( map.Mode.GetType().ToString() == "Microsoft.Maps.MapControl.WPF.AerialMode")
|
||||
@ -145,8 +150,76 @@ namespace Plane.FormationCreator.Views
|
||||
map.ZoomLevel = 19;
|
||||
};
|
||||
|
||||
Rectangle rectangle = new Rectangle();
|
||||
bool drawRectangle = false;
|
||||
Point startPosition = new Point();
|
||||
Point leftTopPoint = new Point();
|
||||
map.MouseRightButtonDown += (sender, e) =>
|
||||
{
|
||||
rectangle = new Rectangle();
|
||||
rectangle.Width = 0;
|
||||
rectangle.Height = 0;
|
||||
rectangle.StrokeThickness = 1;
|
||||
rectangle.Stroke = new SolidColorBrush(Color.FromRgb(0, 120, 215));
|
||||
|
||||
rectangle.Fill = new SolidColorBrush(Color.FromArgb(80, 0, 120, 215));
|
||||
rectangle.Tag = "Rectangle";
|
||||
|
||||
map.Children.Add(rectangle);
|
||||
startPosition = e.GetPosition(this);
|
||||
MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(startPosition));
|
||||
drawRectangle = true;
|
||||
};
|
||||
|
||||
map.MouseMove += (sender, e) =>
|
||||
{
|
||||
if (drawRectangle)
|
||||
{
|
||||
Point mousePosition = e.GetPosition(this);
|
||||
rectangle.Width = Math.Abs(mousePosition.X - startPosition.X);
|
||||
rectangle.Height = Math.Abs(mousePosition.Y - startPosition.Y);
|
||||
leftTopPoint = new Point(Math.Min(mousePosition.X, startPosition.X), Math.Min(mousePosition.Y, startPosition.Y));
|
||||
MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(leftTopPoint));
|
||||
}
|
||||
};
|
||||
int selectedCount = 0;
|
||||
map.MouseRightButtonUp += (sender, e) =>
|
||||
{
|
||||
selectedCount = 0;
|
||||
if (rectangle != null && map.Children.Contains(rectangle))
|
||||
{
|
||||
map.Children.Remove(rectangle);
|
||||
if (_flightTaskManager.SelectedTask != null)
|
||||
{
|
||||
_copterManager.shiftkeydown = true;
|
||||
_copterManager.Select(null);
|
||||
foreach (FlightTaskSingleCopterInfo taskCopterInfo in _flightTaskManager.SelectedTask.SingleCopterInfos)
|
||||
{
|
||||
Location seekLocation = new Location(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng);
|
||||
Point seekPoint = map.LocationToViewportPoint(seekLocation);
|
||||
if ((seekPoint.X > leftTopPoint.X && seekPoint.X < leftTopPoint.X + rectangle.Width) &&
|
||||
seekPoint.Y > leftTopPoint.Y && seekPoint.Y < leftTopPoint.Y + rectangle.Height)
|
||||
{
|
||||
selectedCount++;
|
||||
_copterManager.Select(taskCopterInfo.Copter);
|
||||
}
|
||||
}
|
||||
_copterManager.shiftkeydown = false;
|
||||
}
|
||||
}
|
||||
rectangle = null;
|
||||
drawRectangle = false;
|
||||
};
|
||||
|
||||
map.MouseLeave += (sender, e) =>
|
||||
{
|
||||
if (map.Children.Contains(rectangle))
|
||||
{
|
||||
map.Children.Remove(rectangle);
|
||||
}
|
||||
rectangle = null;
|
||||
drawRectangle = false;
|
||||
};
|
||||
}
|
||||
|
||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||
|
@ -291,21 +291,46 @@ namespace Plane.FormationCreator.Views
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<ICopter, Point> selectWayOriginPoint = new Dictionary<ICopter, Point>();
|
||||
private Dictionary<object, bool> _dictDraggingWp = new Dictionary<object, bool>();
|
||||
private void RegisterEventHandlersForDraggingWaypoint(Ellipse wp, int taskIndex)
|
||||
{
|
||||
_dictDraggingWp[wp] = false;
|
||||
double offsetX = 0;
|
||||
double offsetY = 0;
|
||||
double originX = 0;
|
||||
double originY = 0;
|
||||
double wpOffsetX = 0;
|
||||
double wpOffsetY = 0;
|
||||
wp.MouseLeftButtonDown += (sender, e) =>
|
||||
{
|
||||
_copterManager.Select(this.Copter);
|
||||
_flightTaskManager.Select(taskIndex, this.Copter);
|
||||
//判断点击的航点
|
||||
//非SelectedTask中的航点 或者 当前SelectedTask中未选择的航点 单选拖动
|
||||
//否则多选拖动
|
||||
if (_flightTaskManager.SelectedTaskIndex != taskIndex || !_copterManager.SelectedCopters.Contains(this.Copter))
|
||||
{
|
||||
_copterManager.Select(null);
|
||||
_copterManager.Select(this.Copter);
|
||||
_flightTaskManager.Select(taskIndex, this.Copter);
|
||||
}
|
||||
|
||||
var originPoint = e.GetPosition(_map);
|
||||
originX = originPoint.X;
|
||||
originY = originPoint.Y;
|
||||
|
||||
var posInObject = e.GetPosition(wp);
|
||||
offsetX = posInObject.X;
|
||||
offsetY = posInObject.Y;
|
||||
wpOffsetX = posInObject.X;
|
||||
wpOffsetY = posInObject.Y;
|
||||
|
||||
_dictDraggingWp[wp] = true;
|
||||
|
||||
selectWayOriginPoint.Clear();
|
||||
foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos)
|
||||
{
|
||||
if (_copterManager.SelectedCopters.Contains(info.Copter))
|
||||
{
|
||||
Location originLocation = new Location(info.TargetLat, info.TargetLng);
|
||||
selectWayOriginPoint[info.Copter] = _map.LocationToViewportPoint(originLocation);
|
||||
}
|
||||
}
|
||||
};
|
||||
wp.MouseRightButtonDown += (sender, e) =>
|
||||
{
|
||||
@ -316,15 +341,20 @@ namespace Plane.FormationCreator.Views
|
||||
if (_dictDraggingWp[wp])
|
||||
{
|
||||
var eventPos = e.GetPosition(_map);
|
||||
var leftTopPos = new Point(eventPos.X - offsetX, eventPos.Y - offsetY);
|
||||
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
|
||||
var offsetX = eventPos.X - originX;
|
||||
var offsetY = eventPos.Y - originY;
|
||||
|
||||
var centerPos = new Point(leftTopPos.X + WAYPOINT_RADIUS, leftTopPos.Y + WAYPOINT_RADIUS);
|
||||
var centerLoc = _map.ViewportPointToLocation(centerPos);
|
||||
var routePoint = this.Route.Locations[taskIndex];
|
||||
var modifyingSingleCopterInfo = _flightTaskManager.SelectedTask.SingleCopterInfos.Find(i => i.Copter == Copter);
|
||||
modifyingSingleCopterInfo.TargetLat = routePoint.Latitude = centerLoc.Latitude;
|
||||
modifyingSingleCopterInfo.TargetLng = routePoint.Longitude = centerLoc.Longitude;
|
||||
foreach (KeyValuePair<ICopter, Point> kv in selectWayOriginPoint)
|
||||
{
|
||||
Point curPoint = new Point(kv.Value.X + offsetX, kv.Value.Y + offsetY);
|
||||
var curLoc = _map.ViewportPointToLocation(curPoint);
|
||||
var routePoint = this.Route.Locations[taskIndex];
|
||||
var modifyingSingleCopterInfo = _flightTaskManager.SelectedTask.SingleCopterInfos.Find(i => i.Copter == kv.Key);
|
||||
modifyingSingleCopterInfo.TargetLat = routePoint.Latitude = curLoc.Latitude;
|
||||
modifyingSingleCopterInfo.TargetLng = routePoint.Longitude = curLoc.Longitude;
|
||||
}
|
||||
var leftTopPos = new Point(eventPos.X - wpOffsetX, eventPos.Y - wpOffsetY);
|
||||
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
|
||||
}
|
||||
};
|
||||
_map.MouseLeftButtonUp += (sender, e) =>
|
||||
|
Loading…
Reference in New Issue
Block a user