| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | using Aitex.Core.UI.MVVM;using Aitex.Core.Utilities;using MECF.Framework.Common.CommonData.PUF;using MECF.Framework.Common.OperationCenter;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;namespace PunkHPX8_Themes.UserControls{    /// <summary>    /// VPWMotionControl.xaml 的交互逻辑    /// </summary>    public partial class VPWMotionControl : UserControl    {        #region 属性        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(          "ModuleName", typeof(string), typeof(VPWMotionControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// 模块名称        /// </summary>        public string ModuleName        {            get            {                return (string)this.GetValue(ModuleNameProperty);            }            set            {                this.SetValue(ModuleNameProperty, value);            }        }        public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register(            "ModuleTitle", typeof(string), typeof(VPWMotionControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// 标题        /// </summary>        public string ModuleTitle        {            get            {                return (string)this.GetValue(ModuleTitleProperty);            }            set            {                this.SetValue(ModuleTitleProperty, value);            }        }        public static readonly DependencyProperty ModuleUnitProperty = DependencyProperty.Register(           "ModuleUnit", typeof(string), typeof(VPWMotionControl), new FrameworkPropertyMetadata("deg", FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// 标题        /// </summary>        public string ModuleUnit        {            get            {                return (string)this.GetValue(ModuleUnitProperty);            }            set            {                this.SetValue(ModuleUnitProperty, value);            }        }        public static readonly DependencyProperty InputSpeedProperty = DependencyProperty.Register(           "InputSpeed", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InSpeed        /// </summary>        public double InputSpeed        {            get            {                return (double)this.GetValue(InputSpeedProperty);            }            set            {                this.SetValue(InputSpeedProperty, value);            }        }        public static readonly DependencyProperty InputAccelerationProperty = DependencyProperty.Register(          "InputAcceleration", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InSpeed        /// </summary>        public double InputAcceleration        {            get            {                return (double)this.GetValue(InputAccelerationProperty);            }            set            {                this.SetValue(InputAccelerationProperty, value);            }        }        public static readonly DependencyProperty InputDecelerationProperty = DependencyProperty.Register(         "InputDeceleration", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InputDeceleration        /// </summary>        public double InputDeceleration        {            get            {                return (double)this.GetValue(InputDecelerationProperty);            }            set            {                this.SetValue(InputDecelerationProperty, value);            }        }        public static readonly DependencyProperty InputHomeSpeedSwitchProperty = DependencyProperty.Register(        "InputHomeSpeedSwitch", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InputHomeSpeedSwitch        /// </summary>        public double InputHomeSpeedSwitch        {            get            {                return (double)this.GetValue(InputHomeSpeedSwitchProperty);            }            set            {                this.SetValue(InputHomeSpeedSwitchProperty, value);            }        }        public static readonly DependencyProperty InputHomeSpeedIndexProperty = DependencyProperty.Register(        "InputHomeSpeedIndex", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InputHomeSpeedIndex        /// </summary>        public double InputHomeSpeedIndex        {            get            {                return (double)this.GetValue(InputHomeSpeedIndexProperty);            }            set            {                this.SetValue(InputHomeSpeedIndexProperty, value);            }        }        public static readonly DependencyProperty JogValueIndexProperty = DependencyProperty.Register(        "JogValue", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// JogValue        /// </summary>        public double JogValue        {            get            {                return (double)this.GetValue(JogValueIndexProperty);            }            set            {                this.SetValue(JogValueIndexProperty, value);            }        }        public static readonly DependencyProperty InputHomeAccelDecelProperty = DependencyProperty.Register(        "InputHomeAccelDecel", typeof(double), typeof(VPWMotionControl), new FrameworkPropertyMetadata(0.00, FrameworkPropertyMetadataOptions.AffectsRender));        /// <summary>        /// InputHomeAccelDecel        /// </summary>        public double InputHomeAccelDecel        {            get            {                return (double)this.GetValue(InputHomeAccelDecelProperty);            }            set            {                this.SetValue(InputHomeAccelDecelProperty, value);            }        }        public static readonly DependencyProperty MotionDataProperty = DependencyProperty.Register(          "MotionData", typeof(CommandMotionData), typeof(VPWMotionControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged)));        /// <summary>        /// MotionData        /// </summary>        public CommandMotionData MotionData        {            get            {                return (CommandMotionData)this.GetValue(MotionDataProperty);            }            set            {                this.SetValue(MotionDataProperty, value);            }        }        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)        {            if (e.NewValue != null)            {                CommandMotionData data = (CommandMotionData)e.NewValue;                d.SetValue(InputSpeedProperty, data.FileProfileVelocity);                d.SetValue(InputAccelerationProperty, data.FileAcceleration);                d.SetValue(InputDecelerationProperty, data.FileDeceleration);                d.SetValue(InputHomeSpeedSwitchProperty, data.FileHomingVelocity);                d.SetValue(InputHomeSpeedIndexProperty, data.FileHomingVelocitySlow);                d.SetValue(InputHomeAccelDecelProperty, data.FileHomingAccel);            }        }        public static readonly DependencyProperty IncrementValueProperty = DependencyProperty.Register("IncrementValue", typeof(double), typeof(VPWMotionControl));        /// <summary>        /// 当前位置        /// </summary>        public double IncrementValue        {            get            {                return (double)this.GetValue(IncrementValueProperty);            }            set            {                this.SetValue(IncrementValueProperty, Math.Round(value, 2));            }        }        [IgnorePropertyChange]        public ICommand KeyDownCommand        {            get;            private set;        }        #endregion        public VPWMotionControl()        {            KeyDownCommand = new DelegateCommand<object[]>(KeyDownAction);            InitializeComponent();        }        private void KeyDownAction(object[] param)        {            if (param.Length >= 2)            {                if (double.TryParse(param[1].ToString(), out double paramValue))                {                    InvokeClient.Instance.Service.DoOperation($"{ModuleName}.KeyDown", param[0].ToString(), paramValue);                }            }        }        private void JogDown_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.JogDown", "TargetPosition", JogValue, MotionData.MotorPosition);        }        private void JogUp_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.JogUp", "TargetPosition", JogValue, MotionData.MotorPosition);        }        private void JogStop_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Stop");        }        private void SwitchOn_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SwitchOn");        }        private void SwitchOff_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SwitchOff");        }        private void Home_Click(object sender, RoutedEventArgs e)        {            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Home");        }    }}
 |