generated from wenjy/SlnMesnac
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
7.8 KiB
C#
253 lines
7.8 KiB
C#
using SlnMesnac.WPF.ViewModel;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace SlnMesnac.WPF.Page
|
|
{
|
|
/// <summary>
|
|
/// IndexControl.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class IndexControl : UserControl
|
|
{
|
|
private IndexControlViewModel indexControlViewModel;
|
|
public IndexControl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
indexControlViewModel = new IndexControlViewModel();
|
|
|
|
this.DataContext = indexControlViewModel;
|
|
|
|
indexControlViewModel.RefreshHighlightStationEvent += HighlightStation;
|
|
}
|
|
|
|
#region 云台控制
|
|
private void btnUp_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("up", true);
|
|
}
|
|
|
|
private void btnUp_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("up", false);
|
|
}
|
|
|
|
private void btnDown_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("down", true);
|
|
}
|
|
|
|
private void btnDown_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("down", false);
|
|
}
|
|
|
|
private void btnLeft_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("left", true);
|
|
}
|
|
|
|
private void btnLeft_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("left", false);
|
|
}
|
|
|
|
private void btnRight_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("right", true);
|
|
}
|
|
|
|
private void btnRight_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("right", false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变倍 +
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnZoomIn_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("zoomIn", true);
|
|
}
|
|
|
|
private void btnZoomIn_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("zoomIn", false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变倍 +
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnZoomOut_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("zoomOut", true);
|
|
}
|
|
|
|
private void btnZoomOut_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("zoomOut", false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变焦
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnFocusFar_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("focusFar", true);
|
|
}
|
|
|
|
private void btnFocusFar_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("focusFar", false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变焦
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnFocusNear_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("focusNear", true);
|
|
}
|
|
|
|
private void btnFocusNear_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalOperate("focusNear", false);
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 云台自动运行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_auto_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
indexControlViewModel.GimbalAutoRun();
|
|
}
|
|
|
|
private bool is_insp_model = false;
|
|
/// <summary>
|
|
/// 巡检模式切换
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_inspmode_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (!is_insp_model)
|
|
{
|
|
if (is_auto_model)
|
|
{
|
|
MessageBox.Show("当前处于自动模式中,请先关闭自动模式,再开启巡检模式");
|
|
return;
|
|
}
|
|
|
|
btn_automatic.Background = new SolidColorBrush(Colors.LightBlue);
|
|
is_insp_model = true;
|
|
indexControlViewModel.Start_InspMode();
|
|
}
|
|
else
|
|
{
|
|
btn_automatic.Background = new SolidColorBrush(Colors.Transparent);
|
|
is_insp_model = false;
|
|
indexControlViewModel.Stop_InspMode();
|
|
|
|
}
|
|
}
|
|
|
|
private bool is_auto_model = false;
|
|
/// <summary>
|
|
/// 自动模式切换
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_automode_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (!is_auto_model)
|
|
{
|
|
if (is_insp_model)
|
|
{
|
|
MessageBox.Show("当前处于巡检模式中,请先关闭巡检模式,再开启自动模式");
|
|
}
|
|
btn_autotask.Background = new SolidColorBrush(Colors.LightBlue);
|
|
is_auto_model = true;
|
|
indexControlViewModel.Start_AutoMode();
|
|
}
|
|
else
|
|
{
|
|
btn_autotask.Background = new SolidColorBrush(Colors.Transparent);
|
|
is_auto_model = false;
|
|
indexControlViewModel.Stop_AutoMode();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启预览
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_start_preview_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
indexControlViewModel.Login(RealPlayWnd, RealPlayWnd2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止预览
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_stop_preview_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
indexControlViewModel.ClosePreview(RealPlayWnd, RealPlayWnd2);
|
|
Thread.Sleep(1000);
|
|
indexControlViewModel.Logout();
|
|
}
|
|
|
|
private void HighlightStation(int stationNumber)
|
|
{
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
ResetStationColors();
|
|
// 根据输入的站点编号高亮对应的站点
|
|
if(canvasTrack!= null)
|
|
{
|
|
Rectangle station = (Rectangle)canvasTrack.FindName($"station{stationNumber}");
|
|
if (station != null)
|
|
{
|
|
station.Fill = Brushes.GreenYellow;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void ResetStationColors()
|
|
{
|
|
// 重置所有站点的颜色
|
|
for (int i = 1; i <= 18; i++)
|
|
{
|
|
Rectangle station = (Rectangle)canvasTrack.FindName($"station{i}");
|
|
if (station != null)
|
|
{
|
|
station.Fill = Brushes.Gray;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|