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.

190 lines
5.9 KiB
C#

using Rs.Motion.Base.Config;
using Rs.Motion.Base;
using Rs.Motion;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Rs.Framework;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Rs.MotionPlat
{
public partial class ZtmAxisProperty : UserControl
{
private ToolTip m_tip;
private IAxis m_axis;
private List<Control> m_axisProControls = new List<Control>();
public ZtmAxisProperty()
{
InitializeComponent();
m_tip = new ToolTip();
m_tip.AutoPopDelay = 60 * 1000;
this.BackColor = Color.Black;
this.ForeColor = Color.White;
gboxCardProperty.ForeColor = this.ForeColor;
gboxHomePro.ForeColor = this.ForeColor;
gboxMotorPro.ForeColor = this.ForeColor;
this.btnSave.BackColor = Color.FromArgb(19, 52, 104);
Init();
}
private void Init()
{
m_axisProControls.Clear();
foreach (Control ctl in gboxCardProperty.Controls)
{
if (ctl != null && ctl is TextBox)
{
m_axisProControls.Add((TextBox)ctl);
}
}
foreach (Control ctl in gboxHomePro.Controls)
{
if (ctl != null && ctl is TextBox)
{
m_axisProControls.Add((TextBox)ctl);
}
}
foreach (Control ctl in gboxMotorPro.Controls)
{
if (ctl != null && ctl is TextBox)
{
m_axisProControls.Add((TextBox)ctl);
}
else if(ctl!=null && ctl is CheckBox)
{
m_axisProControls.Add(ctl);
}
}
}
protected override void OnLoad(EventArgs e)
{
if (m_axis != null)
{
DataBinding();
}
}
public void BindAxis(IAxis axis)
{
m_axis = axis;
DataBinding();
}
void DataBinding()
{
foreach (Control ctl in m_axisProControls)
{
if (ctl != null && ctl is TextBox)
{
try
{
ctl.DataBindings.Clear();
ctl.DataBindings.Add("Text", m_axis.Config, ctl.Name.Replace("txt", ""));
ctl.MouseLeave += (s, e) => {
TextBox tbox = (TextBox)s;
m_tip.Hide(tbox);
};
ctl.MouseHover += (s, e) => {
TextBox tbox = (TextBox)s;
//获取这个轴属性的自定义属性
Type type = m_axis.Config.GetType();
ZTMPropertyDescriptionAttribute ztmPro = type.GetProperty(tbox.Name.Replace("txt", "")).GetCustomAttribute<ZTMPropertyDescriptionAttribute>();
if (ztmPro == null)
{
CommonPropertyDescriptionAttribute pro = type.GetProperty(tbox.Name.Replace("txt", "")).GetCustomAttribute<CommonPropertyDescriptionAttribute>();
if (pro != null)
{
//m_tip.SetToolTip(tbox, pro.Description);
m_tip.Show(pro.Description, ctl, 60 * 1000);
}
}
else
{
//m_tip.SetToolTip(tbox, ztmPro.Description);
m_tip.Show(ztmPro.Description, ctl, 60 * 1000);
}
};
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else if(ctl!=null&&ctl is CheckBox)
{
ctl.DataBindings.Clear();
ctl.DataBindings.Add("Checked", m_axis.Config, "CanJogMove");
}
}
}
private void Ctl_GotFocus(object sender, EventArgs e)
{
}
public ErrorCode Save()
{
if (m_axis != null)
{
return m_axis.Card.Save();
}
return ErrorCode.AxisNotInit;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (m_axis != null)
{
ErrorCode err = m_axis.Card.Save();
if (err > ErrorCode.Ok)
{
MessageBox.Show(err.ToString());
}
else
{
MessageBox.Show("Save success!");
}
}
}
private void label3_DoubleClick(object sender, EventArgs e)
{
CopyObject<IAxis>.SetObject(m_axis);
}
private void label4_DoubleClick(object sender, EventArgs e)
{
IAxis axis = CopyObject<IAxis>.GetObject();
if (axis != null)
{
//深度COPY
foreach(PropertyInfo pi in axis.Config.GetType().GetProperties())
{
Attribute attr = pi.GetCustomAttribute(typeof(CopyAttribute));
if(attr!=null)
{
pi.SetValue(m_axis.Config, pi.GetValue(axis.Config, null));
}
}
DataBinding();
}
}
}
}