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.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model;
using System.Text.RegularExpressions;
using System.Collections.ObjectModel;
using Model.MotionControl;
namespace Views.Motion
{
///
/// MotionControl.xaml 的交互逻辑
///
public partial class MotionControWindow : UserControl
{
public MotionControWindow(ObservableCollection shaftlist)
{
InitializeComponent();
shaftlist.Insert(0, new LeiSaiShaft() {ShaftName=" ",ID=0 });
this.shaftX.ItemsSource = shaftlist;
this.shaftY.ItemsSource = shaftlist;
this.shaftZ.ItemsSource = shaftlist;
this.shaftU.ItemsSource = shaftlist;
this.pointType.ItemsSource = new List() { new CommonClass() { ID=1, CommonName="取料点"},
new CommonClass() { ID=2, CommonName="作用点"},
new CommonClass() { ID=3, CommonName="视觉点"},
new CommonClass() { ID=4, CommonName="待机点"}};
//运动控制卡连接类型
this.InterfaceTypeCbox.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="DMC"},
new CommonClass() { UID=1, CommonName="串口"},
new CommonClass() { UID=2, CommonName="网口"}};
List EnableMode = new List() { new CommonClass() { UID = 0, CommonName = "禁用" }, new CommonClass() { UID = 1, CommonName = "启用" } };
List LogicMode = new List() { new CommonClass() { UID = 0, CommonName = "低电平" }, new CommonClass() { UID = 1, CommonName = "高电平" } };
this.GoHomeOrder.ItemsSource = new List { 1, 2, 3, 4, 5,6}; //回原点顺序
//this.PulseOutMode.ItemsSource = new List { 0, 1, 2, 3, 4, 5, 6 };//脉冲输出模式
this.PulseOutMode.ItemsSource = new List() { new CommonClass() { UID = 0, CommonName = "0脉冲+方向" },
new CommonClass() { UID = 1, CommonName = "1脉冲+方向" },
new CommonClass() { UID = 2, CommonName = "2脉冲+方向" },
new CommonClass() { UID = 3, CommonName = "3脉冲+方向" },
new CommonClass() { UID = 4, CommonName = "4双脉冲" },
new CommonClass() { UID = 5, CommonName = "5双脉冲" },};
//硬限位模式
this.Hard_Enable.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="正负限位禁止"},
new CommonClass() { UID=1, CommonName="正负限位允许"},
new CommonClass() { UID=2, CommonName="正禁止,负允许"},
new CommonClass() { UID=3, CommonName="正允许,负禁止"}};
//硬限位电平模式
this.Hard_Logic.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="正负低电平"},
new CommonClass() { UID=1, CommonName="正负高电平"},
new CommonClass() { UID=2, CommonName="正低负高"},
new CommonClass() { UID=3, CommonName="正高负低"}};
//硬限位制动模式
this.Hard_Mode.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="正负立即停止"},
new CommonClass() { UID=1, CommonName="正负减速停止"},
new CommonClass() { UID=2, CommonName="正停负减"},
new CommonClass() { UID=3, CommonName="正减负停"}};
this.Soft_Enable.ItemsSource = EnableMode;
this.Soft_Mode.ItemsSource = new List() { new CommonClass() { UID = 0, CommonName = "立即停止" }, new CommonClass() { UID = 1, CommonName = "减速停止" } };
this.Emg_Enable.ItemsSource = EnableMode;
this.Emg_Logic.ItemsSource = LogicMode;
this.Inp_Enable.ItemsSource = EnableMode;
this.Inp_Logic.ItemsSource = LogicMode;
this.Alm_Enable.ItemsSource = EnableMode;
this.Alm_Logic.ItemsSource = LogicMode;
//回原点模式 (0:一次回零/1:一次回零加回找/2:二次回零)
this.Mode.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="模式0"},
new CommonClass() { UID=1, CommonName="模式1"},
new CommonClass() { UID=2, CommonName="模式2"},
new CommonClass() { UID=3, CommonName="模式3"},
new CommonClass() { UID=4, CommonName="模式4"},
new CommonClass() { UID=5, CommonName="模式5"},
new CommonClass() { UID=6, CommonName="模式6"},
new CommonClass() { UID=7, CommonName="模式7"},
new CommonClass() { UID=8, CommonName="模式8"},
new CommonClass() { UID=9, CommonName="模式9"},
new CommonClass() { UID=10, CommonName="模式10"},
new CommonClass() { UID=11, CommonName="模式11"},
new CommonClass() { UID=12, CommonName="模式12"},
new CommonClass() { UID=13, CommonName="模式13"},
new CommonClass() { UID=14, CommonName="模式14"},
new CommonClass() { UID=15, CommonName="模式15"},
new CommonClass() { UID=16, CommonName="模式16"},
new CommonClass() { UID=17, CommonName="模式17"},
new CommonClass() { UID=18, CommonName="模式18"},
new CommonClass() { UID=19, CommonName="模式19"},
new CommonClass() { UID=20, CommonName="模式20"},
new CommonClass() { UID=21, CommonName="模式21"},
new CommonClass() { UID=22, CommonName="模式22"},
new CommonClass() { UID=23, CommonName="正向23"},
new CommonClass() { UID=24, CommonName="正向24"},
new CommonClass() { UID=25, CommonName="正向25"},
new CommonClass() { UID=26, CommonName="正向26"},
new CommonClass() { UID=27, CommonName="负向27"},
new CommonClass() { UID=28, CommonName="负向28"},
new CommonClass() { UID=29, CommonName="负向29"},
new CommonClass() { UID=30, CommonName="负向30"},
new CommonClass() { UID=31, CommonName="负向31"},
new CommonClass() { UID=32, CommonName="负向32"},
new CommonClass() { UID=33, CommonName="Z 33"},
new CommonClass() { UID=34, CommonName="Z 34"},
new CommonClass() { UID=35, CommonName="就地设原点"},
};
this.Logic.ItemsSource = LogicMode;
this.SpeedMode.ItemsSource = new List() { new CommonClass() { UID = 0, CommonName = "低速回原点" }, new CommonClass() { UID = 1, CommonName = "高速回原点" } };
this.Direction.ItemsSource = new List() { new CommonClass() { UID = 1, CommonName = "正方向" }, new CommonClass() { UID = 0, CommonName = "负方向" } };
//原点归零模式(0:不重置/1:先重置再定位/2:定位后重置)
this.ResetMode.ItemsSource = new List() { new CommonClass() { UID=0, CommonName="不重置"},
new CommonClass() { UID=1, CommonName="先重置再定位"},
new CommonClass() { UID=2, CommonName="定位后重置"}};
this.BrandCbox.ItemsSource = new List { new CommonClass() { ID = 1, CommonName = "雷赛" }, new CommonClass() { ID = 2, CommonName = "众为兴" } };
}
#region 屏蔽非法输入
TextBox TxtBox { get; set; }
Regex Rex { get; set; }
///
/// 限制非法字符输入(可输入数字与小数点)
///
///
///
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
TxtBox = sender as TextBox;
Rex = new Regex("[^0-9.]+");
if (TxtBox.Text.Contains(".") && e.Text == ".")
{
e.Handled = true;
return;
}
e.Handled = Rex.IsMatch(e.Text);
}
TextChange[] change { get; set; }
///
/// 屏蔽中文输入和非法字符粘贴输入
///
///
///
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TxtBox = sender as TextBox;
change = new TextChange[e.Changes.Count];
e.Changes.CopyTo(change, 0);
int offset = change[0].Offset;
if (change[0].AddedLength > 0)
{
double num = 0;
if (!Double.TryParse(TxtBox.Text, out num))
{
TxtBox.Text = TxtBox.Text.Remove(offset, change[0].AddedLength);
TxtBox.Select(offset, 0);
}
}
}
#endregion
}
}