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 Shaft() {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 }; //回原点顺序 this.PulseOutMode.ItemsSource = new List { 0, 1, 2, 3, 4, 5, 6 };//脉冲输出模式 //硬限位模式 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="一次回零"}, new CommonClass() { UID=1, CommonName="一次回零加回找"}, new CommonClass() { UID=2, 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="定位后重置"}}; } #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 } }