using EC.Entity.Video;
using EC.Entity.Warning;
using ECMonitor.Code;
using ECMonitor.Code.DB;
using ECMonitor.Manager;
using ECMonitor.PlayerDraw.Code;
using ECMonitor.UC.Videos;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace ECMonitor.PlayerDraw
{
///
/// FrmWarningDraw.xaml 的交互逻辑
///
public partial class FrmWarningDraw : Window
{
IEventAggregator _ea;
IUCPlayer _ucFFmpegPlayer;
ECDrawing draw;
private BlackboardData blackboardData;
VideoPlayManager _videoPlayManager { get; set; } = new VideoPlayManager();
public FrmWarningDraw(IEventAggregator ea)
{
InitializeComponent();
_ea = ea;
if (blackboardData == null)
{
blackboardData = new BlackboardData();// BlackboardData.Open();
}
this.DataContext = blackboardData;
SetFormSize();
contenter.Width = this.Width;
contenter.Height = this.Height - 40;
draw = new ECDrawing(blackboardData, contenter, writeBorad);
writeBorad.PreviewMouseLeftButtonDown += draw.MouseDown;
contenter.MouseMove += draw.MouseMove;
contenter.PreviewMouseLeftButtonUp += draw.MouseLeftButtonUp;
_ucFFmpegPlayer = _videoPlayManager.CreateWarnCreateLinePlayer(_ea, contenter.Width, contenter.Height, 0);
this.planMain.Children.Add(_ucFFmpegPlayer.GetControl());
}
#region 系统按钮
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
// Exit_Click(sender, e);
}
private void SetFormSize()
{
double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
double xy = x1 + y1;
x1 = x1 * 0.9;
y1 = y1 * 0.9;
this.Width = x1;
this.Height = y1;
}
private void btnMax_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}
}
private void btnMin_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
#endregion 系统按钮
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
public void Play(string cameraIp)
{
MonitorCamera camera = CameraManager.GetCamera(cameraIp);
Play( camera);
}
public void Play(MonitorCamera camera )
{
if (camera == null)
{
_ucFFmpegPlayer.ShowMsg("相机不存在IP=" + camera.Ip);
}
else
{
_ucFFmpegPlayer.Play(camera);
double width = this._ucFFmpegPlayer.GetControl().Width;
double height = this._ucFFmpegPlayer.GetControl().Height;
draw.LoadDrawShape(camera.Ip, width, height);
}
// ShowAndActive();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
// SizeChange();
}
///
/// 预警级别
///
private int _levelSelectIndex = 2;
///
/// 形状
///
private int _shareSelectIndex = 0;
private void LevelButtons_SelectionChanged(object sender, RoutedEventArgs e)
{
int levelSelectIndex = this.barLevelButtons.SelectedIndex;
if (levelSelectIndex == -1)
{
this.barLevelButtons.SelectedIndex = _levelSelectIndex;
return;
}
_levelSelectIndex = levelSelectIndex;
writeBorad.DefaultDrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)levelSelectIndex);
//if (levelSelectIndex == -1)
//{
// this.barLevelButtons.SelectedIndex = _levelSelectIndex;
// return;
//}
//_levelSelectIndex = this.barLevelButtons.SelectedIndex;
//if (IsLoaded == false)
//{
// return;
//}
//switch (_levelSelectIndex)
//{
// case 0:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Green;
// break;
// case 1:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Yellow;
// break;
// case 2:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Red;
// break;
//}
}
private void MenuOpened(object sender, RoutedEventArgs e)
{
//if (writeBorad.GetSelectedStrokes().Count <= 0)
//{
// copy.IsEnabled = cut.IsEnabled = false;
//}
//else
// copy.IsEnabled = cut.IsEnabled = true;
//if (!writeBorad.CanPaste())
// paste.IsEnabled = false;
//else
// paste.IsEnabled = true;
}
private void ShareButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int shareSelectIndex = this.barShareButtons.SelectedIndex;
if (shareSelectIndex == -1)
{
this.barShareButtons.SelectedIndex = _shareSelectIndex;
return;
}
_shareSelectIndex = this.barShareButtons.SelectedIndex;
if (_shareSelectIndex < 4)
{
blackboardData.Draw = true;
this.writeBorad.EditingMode = InkCanvasEditingMode.None;
}else
{
this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
blackboardData.Draw = false;
}
}
private void btnSelect_Click(object sender, RoutedEventArgs e)
{
this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
blackboardData.Draw = false;
}
//private void ChangeEditingMode()
//{
// if (_shareSelectIndex == 5)
// {
// this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
// blackboardData.Draw = false;
// }
// else
// {
// this.writeBorad.EditingMode = InkCanvasEditingMode.None;
// this.contenter.Cursor = Cursors.Pen;
// blackboardData.Draw = true;
// switch (_shareSelectIndex)
// {
// case 0:
// blackboardData.DrawType = (int)DrawTypes.线段;
// break;
// case 1:
// blackboardData.DrawType = (int)DrawTypes.折线;
// break;
// case 2:
// blackboardData.DrawType = (int)DrawTypes.多边形;
// break;
// case 3:
// blackboardData.DrawType = (int)DrawTypes.矩形;
// break;
// case 4:
// blackboardData.DrawType = (int)DrawTypes.圆;
// break;
// }
// }
//}
#region 画图 事件
//private static DependencyProperty IsDrawingProperty = DependencyProperty.Register(
// "IsDrawing", typeof(bool), typeof(FrmWarningDraw), new PropertyMetadata(false));
//private bool IsDrawing
//{
// get { return (bool)GetValue(IsDrawingProperty); }
// set { SetValue(IsDrawingProperty, value); }
//}
private void writeBorad_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
//if (e != null && e.ClickCount == 2)
// writeBorad.ContextMenu.IsOpen = true;
//else
//{
// //if (!undoStack.Contains(writeBorad.Strokes))
// //{
// // undoStack.Push(writeBorad.Strokes.Clone());
// // if (undo.Visibility == Visibility.Collapsed)
// // undo.Visibility = Visibility.Visible;
// //}
//}
}
//private void Execute(object sender, RoutedEventArgs e)
//{
// var menuItem = sender as MenuItem;
// switch (menuItem.Header.ToString())
// {
// case "打开":
// // OpenFile();
// break;
// case "复制":
// writeBorad.CopySelection();
// break;
// case "粘贴":
// writeBorad_PreviewMouseDown(null, null);
// writeBorad.Paste(Mouse.GetPosition(writeBorad));
// break;
// case "剪切":
// writeBorad.CutSelection();
// writeBorad_PreviewMouseDown(sender, null);
// break;
// case "删除":
// writeBorad_PreviewMouseDown(sender, null);
// foreach (Stroke item in writeBorad.GetSelectedStrokes())
// writeBorad.Strokes.Remove(item);
// break;
// }
//}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
writeBorad_PreviewMouseDown(sender, e as MouseButtonEventArgs);
//if (choose.IsChecked == false)
//{
// if (VerifyWindow.ShowDialog("确认清空黑板", "是否清空黑板?", this) == true)
// {
// writeBorad.Strokes.Clear();
// contenter.Children.Clear();
// contenter.Children.Add(writeBorad);
// contenter.Width = SystemParameters.PrimaryScreenWidth;
// contenter.Height = SystemParameters.PrimaryScreenHeight;
// IsWrote = false;
// }
//}
//else
//{
foreach (Stroke item in writeBorad.GetSelectedStrokes())
writeBorad.Strokes.Remove(item);
//}
}
#endregion
private void btnSave_Click(object sender, RoutedEventArgs e)
{
StrokeCollection strokes = writeBorad.Strokes;
int icount = strokes.Count;
List drawShapeModelList = new List();
for (int i= 0; i < icount;i++)
{
StrokeEx storke = strokes[i] as StrokeEx;
var camera = _ucFFmpegPlayer.GetCamera();
if (camera == null) {
MessageManager.ShowMessage("相机不存在");
return;
}
var ip=camera.Ip;
drawShapeModelList.Add( CreateDrawShape(ip,storke));
}
bool save= DBDataHelper.SaveDrawShape(drawShapeModelList);
if (save)
{
MessageManager.ShowMessage("保存成功");
}
else
{
MessageManager.ShowMessage("保存失败");
}
}
private DrawShape CreateDrawShape(string ip, StrokeEx storke)
{
DrawShape drawShape = new DrawShape();
drawShape.Ip = ip;
drawShape.DrawType = (int)storke.DrawType;
drawShape.WarningLevel = (int)storke.WarningLevel;
double width = _ucFFmpegPlayer.GetControl().Width;
double height = _ucFFmpegPlayer.GetControl().Height;
foreach (var point in storke.StylusPoints)
{
DrawPoint DrawPoint = new DrawPoint(point.X/ width, point.Y/ height);
drawShape.PointList.Add(DrawPoint);
}
return drawShape;
}
}
}