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.
171 lines
7.2 KiB
C#
171 lines
7.2 KiB
C#
using Rs.Controls;
|
|
using Rs.Framework;
|
|
using Rs.MotionPlat.Flow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
|
|
|
namespace Rs.MotionPlat.Commom
|
|
{
|
|
public class PositionHelper
|
|
{
|
|
public static void BindSinglePosition(Control control, string dataType = "double")
|
|
{
|
|
if (control is TextBox)
|
|
{
|
|
TextBox txt = ((TextBox)control);
|
|
if (dataType == "double")
|
|
{
|
|
txt.Text = SysConfigParam.GetValue<double>(txt.Name.Replace("txt", "")).ToString("0.000");
|
|
}
|
|
else if (dataType == "int")
|
|
{
|
|
txt.Text = SysConfigParam.GetValue<int>(txt.Name.Replace("txt", "")).ToString();
|
|
}
|
|
else if(dataType=="string")
|
|
{
|
|
txt.Text = SysConfigParam.GetValue<string>(txt.Name.Replace("txt", "")).ToString();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static void BindPosition(Control control, string dataType = "double")
|
|
{
|
|
foreach (Control ctl in control.Controls)
|
|
{
|
|
if (ctl is TextBox)
|
|
{
|
|
TextBox txt = ((TextBox)ctl);
|
|
if (dataType == "double")
|
|
{
|
|
txt.Text = SysConfigParam.GetValue<double>(txt.Name.Replace("txt", "")).ToString("0.000");
|
|
}
|
|
else if (dataType == "int")
|
|
{
|
|
txt.Text = SysConfigParam.GetValue<int>(txt.Name.Replace("txt", "")).ToString();
|
|
}
|
|
txt.TextAlign = HorizontalAlignment.Center;
|
|
txt.Invalidate();
|
|
}
|
|
else if (ctl is System.Windows.Forms.CheckBox)
|
|
{
|
|
System.Windows.Forms.CheckBox cbox = ((System.Windows.Forms.CheckBox)ctl);
|
|
string val = SysConfigParam.GetValue<bool>(ctl.Name.Replace("cbox", "")).ToString().ToLower();
|
|
if (val == "true")
|
|
{
|
|
cbox.Checked = true;
|
|
}
|
|
else
|
|
{
|
|
cbox.Checked = false;
|
|
}
|
|
}
|
|
else if (ctl is System.Windows.Forms.TrackBar)
|
|
{
|
|
System.Windows.Forms.TrackBar tbar = ((System.Windows.Forms.TrackBar)ctl);
|
|
tbar.Value = SysConfigParam.GetValue<int>(ctl.Name.Replace("tbar", "")) == 0 ? 1 : SysConfigParam.GetValue<int>(ctl.Name.Replace("tbar", ""));
|
|
}
|
|
}
|
|
}
|
|
public static void Teach(Form form, object btnSource, string xy = "")
|
|
{
|
|
Button btn = (Button)btnSource;
|
|
if (string.IsNullOrEmpty(xy))
|
|
{
|
|
string name = "txt" + btn.Name.Replace("btnTeach", "");
|
|
Control control = ControlManager.FindControl(form, name);
|
|
if (control != null)
|
|
{
|
|
string axisname = ((TextBox)control).Tag.ToString();
|
|
double pos = Ops.GetCurPosition(axisname);
|
|
DialogResult dr = Msg.ShowQuestion($"Are you sure teach {name.Replace("txt", "")} axis position at {pos}?");
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
((TextBox)control).Text = pos.ToString("0.000");
|
|
SysConfigParam.Update(((TextBox)control).Name.Replace("txt", ""), pos.ToString());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string[] axises = xy.Split(',');
|
|
foreach (var item in axises)
|
|
{
|
|
string name = "txt" + btn.Name.Replace("btnTeach", "") + item;
|
|
Control control = ControlManager.FindControl(form, name);
|
|
if (control != null)
|
|
{
|
|
string axisname = ((TextBox)control).Tag.ToString();
|
|
double pos = Ops.GetCurPosition(axisname);
|
|
DialogResult dr = Msg.ShowQuestion($"Are you sure teach {name.Replace("txt", "")} axis position at {pos}?");
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
((TextBox)control).Text = pos.ToString("0.000");
|
|
SysConfigParam.Update(((TextBox)control).Name.Replace("txt", ""), pos.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public static void Move2This(Form form, object btnSource, string xy = "",int speed=2)
|
|
{
|
|
Button btn = (Button)btnSource;
|
|
if (string.IsNullOrEmpty(xy))
|
|
{
|
|
string name = "txt" + btn.Name.Replace("btnMove", "");
|
|
Control control = ControlManager.FindControl(form, name);
|
|
if (control != null)
|
|
{
|
|
string axisname = ((TextBox)control).Tag.ToString();
|
|
double gotoPos = double.Parse(((TextBox)control).Text);
|
|
//DialogResult dr = Msg.ShowQuestion($"Are you sure to move {axisname} to postion at: {gotoPos}");
|
|
EButtonType btnType = Msgbox.ShowTipDialog(EButtonType.Ok | EButtonType.Cancel, $"Are you sure to move {axisname} to postion at: {gotoPos}");
|
|
//if (dr == DialogResult.OK)
|
|
if(btnType== EButtonType.Ok)
|
|
{
|
|
Motion.ErrorCode errCode = AxisControl.GetAxis(axisname).MovePos(gotoPos, speed);
|
|
if (errCode > Motion.ErrorCode.Ok)
|
|
{
|
|
//Msg.ShowError($"axis {axisname} move fail {errCode}");
|
|
Msgbox.ShowTipDialog(EButtonType.Ok, $"axis {axisname} move fail {errCode}","move",true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string[] axises = xy.Split(',');
|
|
foreach (var item in axises)
|
|
{
|
|
string name = "txt" + btn.Name.Replace("btnMove", "") + item;
|
|
Control control = ControlManager.FindControl(form, name);
|
|
if (control != null)
|
|
{
|
|
string axisname = ((TextBox)control).Tag.ToString();
|
|
double gotoPos = double.Parse(((TextBox)control).Text);
|
|
DialogResult dr = Msg.ShowQuestion($"Are you sure to move {axisname} to postion at: {gotoPos}");
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
AxisControl.GetAxis(axisname).MovePos(gotoPos, 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void Stop(object sender)
|
|
{
|
|
TextBox txt = (TextBox)sender;
|
|
string axisname = txt.Tag.ToString();
|
|
AxisControl.GetAxis(axisname).Stop();
|
|
}
|
|
}
|
|
}
|