using DataEntity.Share;
|
using DriverLib.Engine;
|
using NPOI.SS.Formula.Functions;
|
using NPOI.Util;
|
using System;
|
using System.Text.RegularExpressions;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using XCommon.Log;
|
using XHandler.View.MethodProperty;
|
|
namespace XHandler.View
|
{
|
/// <summary>
|
/// 控制夹爪类
|
/// </summary>
|
public partial class ControlGrip : Window
|
{
|
#region 构造函数
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public ControlGrip()
|
{
|
InitializeComponent();
|
}
|
#endregion
|
|
#region 初始化
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ControlGrip_Loaded(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region 关闭窗口
|
/// <summary>
|
/// 关闭窗口
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
this.Close();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region X-轴偏移 TODO
|
/// <summary>
|
/// 往左偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnLeft_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxXOffset, "请输入X-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.XMoveLeft(Shared.ChanelArmId, float.Parse(tBoxXOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪X轴向右偏移");
|
}
|
}
|
|
/// <summary>
|
/// 往右偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnRight_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxXOffset, "请输入X-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.XMoveRight(Shared.ChanelArmId, float.Parse(tBoxXOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪X轴向左偏移");
|
}
|
}
|
#endregion
|
|
#region Y-轴偏移 TODO
|
/// <summary>
|
/// 往前偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnFwd_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxYOffset, "请输入Y-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperYMoveForward(float.Parse(tBoxYOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪Y轴向前偏移");
|
}
|
}
|
|
/// <summary>
|
/// 往后偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnBack_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxYOffset, "请输入Y-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperYMoveBackward(float.Parse(tBoxYOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪Y轴向后偏移");
|
}
|
}
|
#endregion
|
|
#region Z-轴偏移
|
/// <summary>
|
/// 向上偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnUp_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxZOffset, "请输入Z-轴偏移量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperZUp(float.Parse(tBoxZOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪Z轴向上偏移");
|
}
|
}
|
|
/// <summary>
|
/// 向下偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnDown_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxZOffset, "请输入Z-轴偏移量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperZDown(float.Parse(tBoxZOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪Z轴向下偏移");
|
}
|
}
|
#endregion
|
|
#region 夹爪伸缩量
|
/// <summary>
|
/// 夹紧
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnSqueeze_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxSqueezeOffset, "请输入夹爪伸缩量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperClose(float.Parse(tBoxSqueezeOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪加紧");
|
}
|
}
|
|
/// <summary>
|
/// 张开
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnUnSqueeze_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxSqueezeOffset, "请输入夹爪伸缩量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
result = MethodAction.Instance.GripperOpen(float.Parse(tBoxSqueezeOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
// 判断结果是否失败
|
ResultIsFail(result, "夹爪张开");
|
}
|
}
|
#endregion
|
|
#region 旋转角度 TODO
|
/// <summary>
|
/// 顺时针旋转
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnClockWise_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
PlsToolTipWin plsToolTipWin = null;
|
try
|
{
|
this.Cursor = Cursors.Arrow;
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
plsToolTipWin = new PlsToolTipWin("暂不支持!");
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
}
|
}
|
|
/// <summary>
|
/// 逆时针旋转
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnAntiClockWise_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
result = MethodAction.Instance.GripperRotateReverse(float.Parse(tBoxRotationOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
}
|
}
|
#endregion
|
|
#region Footer TODO
|
/// <summary>
|
/// 抓板
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnPick_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
PlsToolTipWin plsToolTipWin = null;
|
try
|
{
|
this.Cursor = Cursors.Arrow;
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
plsToolTipWin = new PlsToolTipWin("暂不支持!");
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
}
|
}
|
|
/// <summary>
|
/// 放板
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnPlace_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin("");
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.Height = 200;
|
plsToolTipWin.Width = 520;
|
SolidColorBrush mybtn2_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
|
plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn2_Brush;
|
bool bResult = (bool)plsToolTipWin.ShowDialog();
|
if (bResult)
|
{
|
result = MethodAction.Instance.GripperOpen(float.Parse(tBoxSqueezeOffset.Text));
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
}
|
}
|
|
/// <summary>
|
/// 取消
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
this.Close();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region 数据检查
|
/// <summary>
|
/// 只能输入正浮点数
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
{
|
TextBox textElem = (sender as TextBox);
|
// 解决连续输入很多.
|
if ((textElem.Text.StartsWith(".") ||
|
string.IsNullOrWhiteSpace(textElem.Text) ||
|
textElem.Text.Contains(".")) && e.Text == ".")
|
{
|
e.Handled = true;
|
return;
|
}
|
|
// 禁止在0前面继续输入0
|
int index = ((System.Windows.Controls.TextBox)e.Source).CaretIndex;
|
if (textElem.Text.StartsWith("0.") && index == 0 && e.Text == "0")
|
{
|
e.Handled = true;
|
return;
|
}
|
|
Regex re = new Regex("[^0-9.]+");
|
e.Handled = re.IsMatch(e.Text);
|
}
|
|
/// <summary>
|
/// 输入框失去焦点:限制一位小数
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxLostFocus(object sender, RoutedEventArgs e)
|
{
|
TextBox textElem = (sender as TextBox);
|
if (textElem.Text.Length > 0)
|
{
|
textElem.Text = Math.Round(double.Parse(textElem.Text), 1).ToString();
|
}
|
}
|
|
/// <summary>
|
/// 禁用快捷指令
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxPreviewPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
|
{
|
if (e.Command == ApplicationCommands.Copy ||
|
e.Command == ApplicationCommands.Cut ||
|
e.Command == ApplicationCommands.Paste)
|
{
|
e.CanExecute = false;
|
e.Handled = true;
|
}
|
}
|
|
/// <summary>
|
/// 判断输入值是否为空
|
/// </summary>
|
/// <param name="tbox"></param>
|
/// <param name="strMsg"></param>
|
/// <returns></returns>
|
private bool ValueIsEmpty(TextBox tbox, string strMsg)
|
{
|
if (string.IsNullOrEmpty(tbox.Text))
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(strMsg);
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
plsToolTipWin.ShowDialog();
|
tbox.Focus();
|
return false;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 判断结果是否失败
|
/// </summary>
|
/// <param name="result"></param>
|
/// <param name="strMsg"></param>
|
private void ResultIsFail(HxResult result, string strMsg)
|
{
|
if (result.Result != ResultType.Success)
|
{
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(string.Format("{0}失败:{1}", strMsg, result.AlarmInfo));
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
}
|
#endregion
|
|
}
|
}
|