#0013: 增加etalon 接口运动功能完成,加载etalon文件并按实现点动

This commit is contained in:
zhengxuan.zhang
2024-09-11 15:37:07 +08:00
parent e27c65d01a
commit 8093dcd4a4
14 changed files with 729 additions and 221 deletions
+18 -10
View File
@@ -91,7 +91,8 @@ namespace Plot3D
Spring,
Summer,
Winter,
}
Green
}
public enum eRaster
{
@@ -1344,6 +1345,7 @@ namespace Plot3D
Byte[,] u8_RGB;
switch (e_Scheme)
{
case eColorScheme.Green: return new Color[] { Color.Green };
case eColorScheme.Rainbow_Sweep: return CalcRainbow(6); // all colors, also magenta
case eColorScheme.Rainbow_Bright: return CalcRainbow(4); // from red to blue, no magenta
case eColorScheme.Monochrome: return new Color[] { Color.Goldenrod };
@@ -1411,7 +1413,7 @@ namespace Plot3D
/// Constructor 1
/// </summary>
public cColorScheme(eColorScheme e_Scheme)
: this (GetSchema(e_Scheme))
: this (GetSchema(e_Scheme))
{
}
@@ -1817,10 +1819,14 @@ namespace Plot3D
mi_ColorScheme = i_ColorScheme;
}
/// <summary>
/// s32_Radius defines the size of the shape and i_Brush the color
/// </summary>
public cShape3D AddShape(cPoint3D i_Point, eScatterShape e_Shape, int s32_Radius, Brush i_Brush, Object o_Tag = null)
public cScatterData()
{
}
/// <summary>
/// s32_Radius defines the size of the shape and i_Brush the color
/// </summary>
public cShape3D AddShape(cPoint3D i_Point, eScatterShape e_Shape, int s32_Radius, Brush i_Brush, Object o_Tag = null)
{
cShape3D i_Shape3D = new cShape3D(-1, -1, i_Point, e_Shape, s32_Radius, i_Brush, o_Tag);
mi_Shapes3D.Add(i_Shape3D);
@@ -4146,8 +4152,9 @@ namespace Plot3D
/// </summary>
public Editor3D()
{
// avoid flicker
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.DoubleBuffered = true; // 启用双缓冲
// avoid flicker
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
mi_Bounds = new cBounds (this);
@@ -4593,8 +4600,9 @@ namespace Plot3D
/// </summary>
protected override void OnPaint(PaintEventArgs e)
{
// Stupidly the .NET framework draws a red cross if any exception occurres in OnPaint()
try
base.OnPaint(e);
// Stupidly the .NET framework draws a red cross if any exception occurres in OnPaint()
try
{
Render(e.Graphics);
}
+1
View File
@@ -307,6 +307,7 @@
<None Include="Resources\stop.png" />
<None Include="Resources\home.png" />
<None Include="Resources\etalon.png" />
<None Include="Resources\start.png" />
<Content Include="SharpGL.ico" />
<Content Include="SharpGL.png" />
</ItemGroup>
-14
View File
@@ -5,8 +5,6 @@ VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HexcalMC", "HexcalMC.csproj", "{19741897-37D8-43EE-94A2-637975035CEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Editor3D", "..\..\..\..\Editor3D\Editor3D\Editor3D\Editor3D.csproj", "{70634D82-9FD4-4EC9-A1A8-92638B07E832}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -29,18 +27,6 @@ Global
{19741897-37D8-43EE-94A2-637975035CEA}.Release|x64.Build.0 = Release|x64
{19741897-37D8-43EE-94A2-637975035CEA}.Release|x86.ActiveCfg = Release|x86
{19741897-37D8-43EE-94A2-637975035CEA}.Release|x86.Build.0 = Release|x86
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|x64.ActiveCfg = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|x64.Build.0 = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|x86.ActiveCfg = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Debug|x86.Build.0 = Debug|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|Any CPU.Build.0 = Release|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|x64.ActiveCfg = Release|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|x64.Build.0 = Release|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|x86.ActiveCfg = Release|Any CPU
{70634D82-9FD4-4EC9-A1A8-92638B07E832}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+95 -52
View File
@@ -1,4 +1,9 @@
using System;
using ACS.SPiiPlusNET;
using HexcalMC.Base;
using HexcalMC.Form;
using HexcalMC.Hexcal;
using HexcalMC.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -6,12 +11,8 @@ using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using ACS.SPiiPlusNET;
using HexcalMC.Base;
using HexcalMC.Form;
using HexcalMC.Hexcal;
using HexcalMC.Properties;
using Telerik.WinControls.UI;
using static HexcalMC.EtalonForm;
namespace HexcalMC
{
@@ -43,11 +44,41 @@ namespace HexcalMC
private int m_nTotalAxis; //定义总轴数
private Axis[] m_arrAxisList = null;
//定一个运动到位次数的变量和三个方法,开始统计运动到位次数,停止统计运动到位次数,获取运动到位次数
#region
// 记录运动到位次数的变量
private int m_nInPosCount = 0;
private bool isCounting = false;
// 开始统计运动到位次数
public void StartCounting()
{
isCounting = true;
m_nInPosCount = 0; // 重置计数器
}
// 停止统计运动到位次数
public void StopCounting()
{
isCounting = false;
m_nInPosCount = 0; // 重置计数器
}
// 获取运动到位次数
public int GetInPosCount()
{
return m_nInPosCount;
}
#endregion
public MainFrom()
{
InitializeComponent();
// 处理未被捕获的线程异常
Application.ThreadException += Application_ThreadException;
@@ -61,12 +92,10 @@ namespace HexcalMC
MaximizeBox = false; // 禁用窗体的最大化按钮
DebugDfn.textBox_Msg = TextBoxMsg;
//加载配置文件
LoadConfig();
_acs = new Api(); //初始化 ACS运动控制类
//启动界面刷新
timer_RefreshUI.Start();
}
@@ -88,11 +117,11 @@ namespace HexcalMC
DebugDfn._strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
timer_RefreshUI.Stop();
Btn_StopServer_Click(null,null);
Btn_StopServer_Click(null, null);
Btn_ACSStop_Click(null, null);//关闭ACS
string copyFileName = DebugDfn.StrDebugSavePath + "\\Debug(" + DebugDfn._strStartTime + " To " +
DebugDfn._strEndTime + ")" + ".txt";
DebugDfn._strEndTime + ")" + ".txt";
if (!File.Exists(DebugDfn.StrDebugSavePath))
{
//创建文件夹 DebugDfn.StrDebugSavePath
@@ -118,9 +147,8 @@ namespace HexcalMC
return;
}
MotionSpeed = FileIni.ReadDouble(StrConfigFile, "MOTOR", "MOTION_SPEED"); //运动定位速度
//正限位
//正限位
XMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MAXSTROKESW");
YMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MAXSTROKESW");
ZMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MAXSTROKESW");
@@ -159,19 +187,20 @@ namespace HexcalMC
formsPlot1.Refresh();
}
#region
public Api _acs;
private const int MaxUiLimitCnt = 24;
private int _mNTotalAxis;
private int _mNTotalBuffer = 0;
private Axis[] _mArrAxisList = null;
//private int _mNTotalBuffer = 0;
//private Axis[] _mArrAxisList = null;
public bool _mAcsConnected; //ACS通讯状态
// For update values
private MotorStates _mNMotorState; //运动状态
private ProgramStates _mNProgramState; //程序状态
private object _mObjReadVar;
private Array _mArrReadVector;
@@ -184,7 +213,7 @@ namespace HexcalMC
private Label[] _mlblAcc; //加速中
private Label[] _mlblInPos; //轴就位
private Label[] _mlblEnable; //使能
bool[] axisEnabled = new bool[MaxUiLimitCnt]; //轴使能状态
private bool[] axisEnabled = new bool[MaxUiLimitCnt]; //轴使能状态
public bool totalAxisEnabled = false;
private HomeStates _homeStates; //回家状态
@@ -198,6 +227,7 @@ namespace HexcalMC
//定义 XYZ三个轴的左右行程范围
public string StrConfigFile = Application.StartupPath + "\\File\\config.ini";
public static double MotionSpeed = 60;
public static double XMaxstrokesw = 730; //正限位
public static double YMaxstrokesw = 1000;
@@ -211,14 +241,13 @@ namespace HexcalMC
//定义一个3D点,存储当前平台实时位置
public Point3D _mPoint3D;
#endregion
#endregion
#region hexcal软件交互
private void StartServer()
{
// 对_mTcpIpServer增加判断是否已经启动且存在设备连接
// 对_mTcpIpServer增加判断是否已经启动且存在设备连接
if (_mTcpIpServer != null && _mTcpIpServer.ConnectStatus)
{
//弹窗提醒已经启动
@@ -268,9 +297,11 @@ namespace HexcalMC
case "100.0.0.1":
ParseHexcalMsg(msg);
break;
case "100.0.0.2":
ParseHexcalMsg(msg);
break;
default:
DebugDfn.AddLogText("未知来源,没有应答");
break;
@@ -353,7 +384,6 @@ namespace HexcalMC
//{
// checkPlatformStatus();
//}
else if (msg.Contains("CMMTYP")) //测量机类型
{
SendMsgToHexcal("CMMTYP MA 19617, FDC V15.00, 10 8 3 , 0");
@@ -362,7 +392,6 @@ namespace HexcalMC
{
SendMsgToHexcal("00-000-000-00000 FDC V51.04.0000 DATE: 12/21/22 TIME: 12:50:55");
}
else if (msg.Contains("SHOW MAXSTROKESW")) //最大行程,根据实际情况填写
{
//MAXSTROKESW 233.200000,346.500000,15.100000,0.000000,0.000000,0.000000,0.000000
@@ -371,7 +400,6 @@ namespace HexcalMC
string resultString = ConstructString("MAXSTROKESW", values);
SendMsgToHexcal(resultString);
}
else if (msg.Contains("SHOW MINSTROKESW")) //最小行程,根据实际情况填写
{
//MINSTROKESW -68.800000,-55.500000,-286.900000,0.000000,0.000000,0.000000,0.000000
@@ -470,7 +498,7 @@ namespace HexcalMC
//执行回家
IsHomed();
}
else if (msg.Contains("MOVABS")) //移动指令,解析移动位置
else if (msg.Contains("MOVABS")) //移动指令,解析移动位置
{
//收到指令 ,形如 MOVABS 0.015000,127.172997,-114.897003,0.000000\r\n
SendMsgToHexcal("%");
@@ -504,6 +532,7 @@ namespace HexcalMC
case TcpIpServer.EnumTcpIpServer.ClientConnect:
_mBHexcalConnected = true;
break;
default:
_mBHexcalConnected = false;
break;
@@ -514,7 +543,6 @@ namespace HexcalMC
{
if (_mTcpIpServer == null) return;
//发送数据
DebugDfn.AddLogText("回复 " + msg);
_mTcpIpServer.SendMessageToAllClients(msg += "\r\n"); //回复内容末尾加上\r\n,协议要求
@@ -542,7 +570,7 @@ namespace HexcalMC
DebugDfn.AddLogText("TCP服务端已关闭");
}
#endregion
#endregion hexcal软件交互
#region ACS平台相关
@@ -550,7 +578,6 @@ namespace HexcalMC
//实现函数
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
// 防止程序终止
@@ -558,7 +585,6 @@ namespace HexcalMC
MessageBoxIcon.Information);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception ex)
@@ -573,7 +599,6 @@ namespace HexcalMC
MessageBoxIcon.Information);
}
//订阅报错
private void EnableFaultEvent()
{
@@ -689,8 +714,7 @@ namespace HexcalMC
//DebugDfn.AddLogText(string.Format(" - Axis {0}, Stoppped", axisNo));
}
#endregion
#endregion
private void BtnEnable_Click(object sender, EventArgs e) //使能所有轴
{
@@ -768,8 +792,7 @@ namespace HexcalMC
UpdateSingleAxisStatus(); //刷新运动状态
#endregion
#endregion
#region
@@ -788,11 +811,15 @@ namespace HexcalMC
if (_currentMotionState == MotionStates.InPos && _currentMotionState != _currentMotorStateLast)
{
DebugDfn.AddLogText("运动到位");
if (isCounting)
{
m_nInPosCount++;
}
}
_currentMotorStateLast = _currentMotionState;
#endregion
#endregion
}
catch (Exception ex)
{
@@ -823,7 +850,6 @@ namespace HexcalMC
tmrMonitor.Interval = 50;
tmrMonitor.Start();
}
catch (COMException comex)
{
MessageBox.Show("Connection fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -831,7 +857,6 @@ namespace HexcalMC
_mAcsConnected = false;
}
catch (Exception ex)
{
DebugDfn.AddLogText("ACS平台连接异常" + ex);
@@ -841,12 +866,10 @@ namespace HexcalMC
private void Btn_ACSStop_Click(object sender, EventArgs e) //断开连接
{
if (_mAcsConnected)
{
//DisableFaultEvent(); //取消注册事件
_acs.CloseComm();
}
tmrMonitor.Stop();
@@ -877,9 +900,11 @@ namespace HexcalMC
case Axis.ACSC_AXIS_1: //X轴
newAxisNumber = 0;
break;
case Axis.ACSC_AXIS_0:
newAxisNumber = 1; //Y轴
break;
case Axis.ACSC_AXIS_8:
newAxisNumber = 2;
break;
@@ -1053,7 +1078,6 @@ namespace HexcalMC
_mLblLeftLimit[1] = lblLL1;
_mLblLeftLimit[2] = lblLL2;
_mLblRightLimit = new Label[MaxUiLimitCnt]; //右限位
_mLblRightLimit[0] = lblRL0;
_mLblRightLimit[1] = lblRL1;
@@ -1085,8 +1109,20 @@ namespace HexcalMC
public static bool IsWithinLimit(Point3D point) //判断点是否在行程范围内
{
if (point.X >= XMinstrokesw && point.X <= XMaxstrokesw &&
point.Y >= YMinstrokesw && point.Y <= YMaxstrokesw &&
point.Z >= ZMinstrokesw && point.Z <= ZMaxstrokesw)
point.Y >= YMinstrokesw && point.Y <= YMaxstrokesw &&
point.Z >= ZMinstrokesw && point.Z <= ZMaxstrokesw)
{
return true;
}
return false;
}
public static bool IsWithinLimit(Point point) //判断点是否在行程范围内
{
if (point.X >= XMinstrokesw && point.X <= XMaxstrokesw &&
point.Y >= YMinstrokesw && point.Y <= YMaxstrokesw &&
point.Z >= ZMinstrokesw && point.Z <= ZMaxstrokesw)
{
return true;
}
@@ -1106,7 +1142,7 @@ namespace HexcalMC
if (_currentMotionState != MotionStates.Moving)
{
_currentMotionState = MotionStates.Moving; //设置当前运动状态
//判断 point3D是否合法
//判断 point3D是否合法
if (point3D != null)
{
if (IsWithinLimit(point3D)) //判断点是否在行程范围内
@@ -1118,7 +1154,7 @@ namespace HexcalMC
point3D.Z
};
//判断各轴使能状态,如果未使能,则使能
if (!totalAxisEnabled)
{
_acs.EnableM(UseAxis);
@@ -1176,7 +1212,6 @@ namespace HexcalMC
DebugDfn.AddLogText("参考位置: " + xPosition + " " + yPosition + " " + zPosition);
}
//构造point3D格式
point3D = new Point3D(xPosition, yPosition, zPosition);
@@ -1209,7 +1244,6 @@ namespace HexcalMC
private void rtb_quick_loc_Click(object sender, EventArgs e)//快速定位
{
// 获取文本框的值
double x = double.Parse(rtb_SetX.Text);
double y = double.Parse(rtb_Sety.Text);
@@ -1221,7 +1255,7 @@ namespace HexcalMC
SetPositionXyz(point);
}
static bool CalculateTotalEnabled(bool[] axisEnabled, params int[] axisIndices)//判断轴使能状态
private static bool CalculateTotalEnabled(bool[] axisEnabled, params int[] axisIndices)//判断轴使能状态
{
bool totalEnabled = true;
foreach (int index in axisIndices)
@@ -1271,8 +1305,6 @@ namespace HexcalMC
return;
}
if (_currentMotionState != MotionStates.Moving)
{
_currentMotionState = MotionStates.Moving; //设置当前运动状态
@@ -1297,8 +1329,21 @@ namespace HexcalMC
private void rtb_etalon_Click(object sender, EventArgs e) //etalon校准
{
DebugDfn.AddLogText("Etalon校准");
EtalonForm etalonForm = new EtalonForm();
etalonForm.ShowDialog();
//判断通讯对象是否存在
if (_acs == null || !_acs.IsConnected)
{
DebugDfn.AddLogText("未建立与运动平台通讯,请在主界面先建立通讯");
// 在合适的位置调用 MessageBox.Show() 方法
MessageBox.Show("未建立与运动平台通讯,请在主界面先建立通讯", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
EtalonForm etalonForm = new EtalonForm(this);
etalonForm.Show();
}
}
#endregion ACS平台相关
@@ -1321,9 +1366,7 @@ namespace HexcalMC
{
Motion motion = new Motion(this);
motion.Show();
}
}
private void Rtb_about_Click(object sender, EventArgs e) //关于界面
+173 -95
View File
@@ -29,9 +29,7 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EtalonForm));
this.button1 = new System.Windows.Forms.Button();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.editor3D = new Plot3D.Editor3D();
this.btn_draw_test = new System.Windows.Forms.Button();
this.checkMirrorY = new System.Windows.Forms.CheckBox();
this.checkMirrorX = new System.Windows.Forms.CheckBox();
this.label8 = new System.Windows.Forms.Label();
@@ -42,73 +40,58 @@
this.label3 = new System.Windows.Forms.Label();
this.comboRaster = new System.Windows.Forms.ComboBox();
this.comboColors = new System.Windows.Forms.ComboBox();
this.labelMouseInfo = new System.Windows.Forms.ToolStripStatusLabel();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.statusStrip1.SuspendLayout();
this.btn_etalon_import = new System.Windows.Forms.Button();
this.labelMouseInfo = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btn_clear = new System.Windows.Forms.Button();
this.btn_startmove = new System.Windows.Forms.Button();
this.btn_stop = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.text_etalon_info = new System.Windows.Forms.RichTextBox();
this.editor3D = new Plot3D.Editor3D();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// button1
// btn_draw_test
//
this.button1.Location = new System.Drawing.Point(9, 569);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(121, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.labelMouseInfo});
this.statusStrip1.Location = new System.Drawing.Point(0, 679);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1020, 22);
this.statusStrip1.TabIndex = 2;
this.statusStrip1.Text = "statusStrip1";
//
// editor3D
//
this.editor3D.BackColor = System.Drawing.Color.White;
this.editor3D.BorderColorFocus = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
this.editor3D.BorderColorNormal = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
this.editor3D.LegendPos = Plot3D.Editor3D.eLegendPos.BottomLeft;
this.editor3D.Location = new System.Drawing.Point(159, 25);
this.editor3D.Name = "editor3D";
this.editor3D.Normalize = Plot3D.Editor3D.eNormalize.Separate;
this.editor3D.Raster = Plot3D.Editor3D.eRaster.Labels;
this.editor3D.Size = new System.Drawing.Size(515, 610);
this.editor3D.TabIndex = 0;
this.editor3D.TooltipMode = ((Plot3D.Editor3D.eTooltip)((Plot3D.Editor3D.eTooltip.UserText | Plot3D.Editor3D.eTooltip.Coord)));
this.editor3D.TopLegendColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(150)))));
this.btn_draw_test.Location = new System.Drawing.Point(8, 539);
this.btn_draw_test.Name = "btn_draw_test";
this.btn_draw_test.Size = new System.Drawing.Size(121, 23);
this.btn_draw_test.TabIndex = 1;
this.btn_draw_test.Text = "绘图测试";
this.btn_draw_test.UseVisualStyleBackColor = true;
this.btn_draw_test.Click += new System.EventHandler(this.btn_draw_test_Click);
//
// checkMirrorY
//
this.checkMirrorY.AutoSize = true;
this.checkMirrorY.BackColor = System.Drawing.Color.Transparent;
this.checkMirrorY.Location = new System.Drawing.Point(81, 149);
this.checkMirrorY.Location = new System.Drawing.Point(80, 111);
this.checkMirrorY.Name = "checkMirrorY";
this.checkMirrorY.Size = new System.Drawing.Size(72, 16);
this.checkMirrorY.TabIndex = 39;
this.checkMirrorY.Text = "Mirror Y";
this.checkMirrorY.UseVisualStyleBackColor = false;
this.checkMirrorY.CheckedChanged += new System.EventHandler(this.checkMirrorY_CheckedChanged);
//
// checkMirrorX
//
this.checkMirrorX.AutoSize = true;
this.checkMirrorX.BackColor = System.Drawing.Color.Transparent;
this.checkMirrorX.Location = new System.Drawing.Point(9, 149);
this.checkMirrorX.Location = new System.Drawing.Point(8, 111);
this.checkMirrorX.Name = "checkMirrorX";
this.checkMirrorX.Size = new System.Drawing.Size(72, 16);
this.checkMirrorX.TabIndex = 38;
this.checkMirrorX.Text = "Mirror X";
this.checkMirrorX.UseVisualStyleBackColor = false;
this.checkMirrorX.CheckedChanged += new System.EventHandler(this.checkMirrorX_CheckedChanged);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(7, 168);
this.label8.Location = new System.Drawing.Point(6, 130);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(89, 12);
this.label8.TabIndex = 31;
@@ -122,119 +105,209 @@
"Left Theta, Right Phi",
"Left Theta and Phi",
"Middle Theta and Phi"});
this.comboMouse.Location = new System.Drawing.Point(9, 181);
this.comboMouse.Location = new System.Drawing.Point(8, 143);
this.comboMouse.MaxDropDownItems = 30;
this.comboMouse.Name = "comboMouse";
this.comboMouse.Size = new System.Drawing.Size(121, 20);
this.comboMouse.TabIndex = 40;
this.comboMouse.SelectedIndexChanged += new System.EventHandler(this.comboMouse_SelectedIndexChanged);
//
// btnReset
//
this.btnReset.Location = new System.Drawing.Point(9, 205);
this.btnReset.Location = new System.Drawing.Point(8, 167);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(121, 21);
this.btnReset.TabIndex = 41;
this.btnReset.Text = "Reset Position";
this.btnReset.Text = "重置视图";
this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btnScreenshot
//
this.btnScreenshot.Location = new System.Drawing.Point(9, 230);
this.btnScreenshot.Location = new System.Drawing.Point(8, 192);
this.btnScreenshot.Name = "btnScreenshot";
this.btnScreenshot.Size = new System.Drawing.Size(121, 21);
this.btnScreenshot.TabIndex = 42;
this.btnScreenshot.Text = "Save Screenshot";
this.btnScreenshot.Text = "保存截图";
this.btnScreenshot.UseVisualStyleBackColor = true;
this.btnScreenshot.Click += new System.EventHandler(this.btnScreenshot_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(7, 95);
this.label4.Location = new System.Drawing.Point(6, 57);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(113, 12);
this.label4.Size = new System.Drawing.Size(47, 12);
this.label4.TabIndex = 28;
this.label4.Text = "Coordinate System:";
this.label4.Text = "坐标系:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 58);
this.label3.Location = new System.Drawing.Point(6, 20);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(83, 12);
this.label3.Size = new System.Drawing.Size(35, 12);
this.label3.TabIndex = 27;
this.label3.Text = "Color Scheme:";
this.label3.Text = "色卡:";
//
// comboRaster
//
this.comboRaster.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboRaster.FormattingEnabled = true;
this.comboRaster.Location = new System.Drawing.Point(9, 109);
this.comboRaster.Location = new System.Drawing.Point(8, 71);
this.comboRaster.MaxDropDownItems = 30;
this.comboRaster.Name = "comboRaster";
this.comboRaster.Size = new System.Drawing.Size(121, 20);
this.comboRaster.TabIndex = 36;
this.comboRaster.SelectedIndexChanged += new System.EventHandler(this.comboRaster_SelectedIndexChanged);
//
// comboColors
//
this.comboColors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboColors.FormattingEnabled = true;
this.comboColors.Location = new System.Drawing.Point(9, 73);
this.comboColors.Location = new System.Drawing.Point(8, 35);
this.comboColors.MaxDropDownItems = 30;
this.comboColors.Name = "comboColors";
this.comboColors.Size = new System.Drawing.Size(121, 20);
this.comboColors.TabIndex = 35;
this.comboColors.SelectedIndexChanged += new System.EventHandler(this.comboColors_SelectedIndexChanged);
//
// btn_etalon_import
//
this.btn_etalon_import.Location = new System.Drawing.Point(15, 29);
this.btn_etalon_import.Name = "btn_etalon_import";
this.btn_etalon_import.Size = new System.Drawing.Size(102, 30);
this.btn_etalon_import.TabIndex = 43;
this.btn_etalon_import.Text = "导入etalon文件";
this.btn_etalon_import.UseVisualStyleBackColor = true;
this.btn_etalon_import.Click += new System.EventHandler(this.btn_etalon_import_Click);
//
// labelMouseInfo
//
this.labelMouseInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelMouseInfo.AutoSize = true;
this.labelMouseInfo.ForeColor = System.Drawing.Color.Blue;
this.labelMouseInfo.Location = new System.Drawing.Point(146, 614);
this.labelMouseInfo.Name = "labelMouseInfo";
this.labelMouseInfo.Size = new System.Drawing.Size(99, 17);
this.labelMouseInfo.Text = "labelMouseInfo";
this.labelMouseInfo.Size = new System.Drawing.Size(65, 12);
this.labelMouseInfo.TabIndex = 45;
this.labelMouseInfo.Text = "Mouse Info";
//
// button2
// groupBox1
//
this.button2.Location = new System.Drawing.Point(933, 106);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 43;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.groupBox1.Controls.Add(this.btn_clear);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.labelMouseInfo);
this.groupBox1.Controls.Add(this.btn_draw_test);
this.groupBox1.Controls.Add(this.comboColors);
this.groupBox1.Controls.Add(this.comboRaster);
this.groupBox1.Controls.Add(this.editor3D);
this.groupBox1.Controls.Add(this.checkMirrorY);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.checkMirrorX);
this.groupBox1.Controls.Add(this.btnScreenshot);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.btnReset);
this.groupBox1.Controls.Add(this.comboMouse);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(717, 643);
this.groupBox1.TabIndex = 46;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "可视化";
//
// textBox1
// btn_clear
//
this.textBox1.Location = new System.Drawing.Point(691, 106);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(213, 23);
this.textBox1.TabIndex = 44;
this.btn_clear.Location = new System.Drawing.Point(8, 568);
this.btn_clear.Name = "btn_clear";
this.btn_clear.Size = new System.Drawing.Size(121, 23);
this.btn_clear.TabIndex = 46;
this.btn_clear.Text = "清空绘图";
this.btn_clear.UseVisualStyleBackColor = true;
this.btn_clear.Click += new System.EventHandler(this.btn_clear_Click);
//
// btn_startmove
//
this.btn_startmove.Image = global::HexcalMC.Properties.Resources.start;
this.btn_startmove.Location = new System.Drawing.Point(15, 116);
this.btn_startmove.Name = "btn_startmove";
this.btn_startmove.Size = new System.Drawing.Size(72, 72);
this.btn_startmove.TabIndex = 47;
this.btn_startmove.UseVisualStyleBackColor = true;
this.btn_startmove.Click += new System.EventHandler(this.btn_startmove_Click);
//
// btn_stop
//
this.btn_stop.Image = global::HexcalMC.Properties.Resources.stop;
this.btn_stop.Location = new System.Drawing.Point(128, 116);
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(72, 72);
this.btn_stop.TabIndex = 48;
this.btn_stop.UseVisualStyleBackColor = true;
this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.text_etalon_info);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Controls.Add(this.btn_startmove);
this.groupBox2.Controls.Add(this.btn_stop);
this.groupBox2.Controls.Add(this.btn_etalon_import);
this.groupBox2.Location = new System.Drawing.Point(747, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(465, 643);
this.groupBox2.TabIndex = 49;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "etalon操作";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 225);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 12);
this.label1.TabIndex = 49;
this.label1.Text = "输出";
//
// text_etalon_info
//
this.text_etalon_info.Location = new System.Drawing.Point(6, 249);
this.text_etalon_info.Name = "text_etalon_info";
this.text_etalon_info.Size = new System.Drawing.Size(440, 361);
this.text_etalon_info.TabIndex = 50;
this.text_etalon_info.Text = "";
//
// editor3D
//
this.editor3D.BackColor = System.Drawing.Color.White;
this.editor3D.BorderColorFocus = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
this.editor3D.BorderColorNormal = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
this.editor3D.LegendPos = Plot3D.Editor3D.eLegendPos.BottomLeft;
this.editor3D.Location = new System.Drawing.Point(148, 20);
this.editor3D.Name = "editor3D";
this.editor3D.Normalize = Plot3D.Editor3D.eNormalize.Separate;
this.editor3D.Raster = Plot3D.Editor3D.eRaster.Labels;
this.editor3D.Size = new System.Drawing.Size(548, 590);
this.editor3D.TabIndex = 0;
this.editor3D.TooltipMode = ((Plot3D.Editor3D.eTooltip)((Plot3D.Editor3D.eTooltip.UserText | Plot3D.Editor3D.eTooltip.Coord)));
this.editor3D.TopLegendColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(150)))));
//
// EtalonForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1020, 701);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.checkMirrorY);
this.Controls.Add(this.checkMirrorX);
this.Controls.Add(this.label8);
this.Controls.Add(this.comboMouse);
this.Controls.Add(this.btnReset);
this.Controls.Add(this.btnScreenshot);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboRaster);
this.Controls.Add(this.comboColors);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.button1);
this.Controls.Add(this.editor3D);
this.ClientSize = new System.Drawing.Size(1237, 681);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "EtalonForm";
this.Text = "EtalonForm";
this.Load += new System.EventHandler(this.EtalonForm_Load);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
@@ -242,8 +315,7 @@
#endregion
private Plot3D.Editor3D editor3D;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.Button btn_draw_test;
private System.Windows.Forms.CheckBox checkMirrorY;
private System.Windows.Forms.CheckBox checkMirrorX;
private System.Windows.Forms.Label label8;
@@ -254,8 +326,14 @@
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboRaster;
private System.Windows.Forms.ComboBox comboColors;
private System.Windows.Forms.ToolStripStatusLabel labelMouseInfo;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btn_etalon_import;
private System.Windows.Forms.Label labelMouseInfo;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btn_startmove;
private System.Windows.Forms.Button btn_stop;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button btn_clear;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox text_etalon_info;
}
}
+419 -37
View File
@@ -10,9 +10,6 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ScottPlot;
using ScottPlot.Plottable;
using Plot3D;
// enums
@@ -47,6 +44,13 @@ using cUserInput = Plot3D.Editor3D.cUserInput;
using delRendererFunction = Plot3D.Editor3D.delRendererFunction;
using static Plot3D.Editor3D;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.IO;
using Telerik.WinControls;
using static Telerik.WinControls.UI.ValueMapper;
using HexcalMC.Base;
using ACS.SPiiPlusNET;
namespace HexcalMC
{
@@ -85,18 +89,65 @@ namespace HexcalMC
private cPoint3D[] mi_Pyramid;
private int ms32_AnimationAngle;
public EtalonForm()
// etalon解析变量
private List<Point> etalon_points = new List<Point>();
private List<Point> filteredPoints = new List<Point>(); //过滤后的点
private List<int> dwellTimes = new List<int>();
private static Timer refresh_time = new Timer();
private static int currentIndex = 0;
private readonly MainFrom mainFrom;
private readonly Api _acs; //ACS控制器
public EtalonForm(MainFrom _mainFrom)
{
InitializeComponent();
mainFrom = _mainFrom;
this._acs = _mainFrom._acs;
}
private void EtalonForm_Load(object sender, EventArgs e)
{
InitScatterPlot(); //清空绘图
DebugDfn.textBox_Msg = this.text_etalon_info;
}
private void InitScatterPlot() //绘图区初始化
{
comboColors.Sorted = false;
foreach (eColorScheme e_Scheme in Enum.GetValues(typeof(eColorScheme)))
{
comboColors.Items.Add(e_Scheme.ToString().Replace('_', ' '));
}
comboColors.SelectedIndex = (int)eColorScheme.Monochrome; //默认色卡
comboRaster.Sorted = false;
foreach (eRaster e_Raster in Enum.GetValues(typeof(eRaster)))
{
comboRaster.Items.Add(e_Raster);
}
comboRaster.SelectedIndex = (int)eRaster.Labels; //坐标系栅格样式
//设置默认
comboMouse.SelectedIndex = 0;
// 设置定时器
refresh_time.Interval = 100;
refresh_time.Tick += new EventHandler(OnAnimationTimer);
refresh_time.Start();
}
private void DemoScatterPlot(bool b_Lines)
{
comboColors.Enabled = true; // Some of the demos will disable this combobox
me_ColorScheme = (eColorScheme)comboColors.SelectedIndex;
checkMirrorX.Checked = editor3D.AxisX.Mirror;
checkMirrorY.Checked = editor3D.AxisY.Mirror;
// 3 pixels for line width and for circle radius
const int SIZE = 3;
@@ -138,31 +189,8 @@ namespace HexcalMC
editor3D.Selection.Enabled = true;
editor3D.UndoBuffer.Enabled = true;
editor3D.Invalidate();
// For shapes this setting does not make a difference
//checkPointSelection.Checked = false;
//if (!b_Lines)
// checkPointSelection.Enabled = false;
}
//; Machine: ZIM
//; Position: 1
//; Created: 2/15/2023 12:29:13 PM
//; Program: TRAC-CAL V48, Build: 10, 5/13/2022 8:29:25 AM
//; File: 'cncData.xml'
//G71
//G90
//G500
//G01 X8000.000 Y200.000 Z-1400.000 F2000
//G04 F=2
//G01 X7800.000 Y300.000 Z-1400.000 F2000
//G04 F=2
//G01 X7600.000 Y400.000 Z-1400.000 F2000
//G04 F=2
//G01 X7400.000 Y500.000 Z-1400.000 F2000
//G04 F=2
//G01 X7200.000 Y600.000 Z-1400.000 F2000
private eInvalidate OnSelectEvent(eSelEvent e_Event, Keys e_Modifiers, int s32_DeltaX, int s32_DeltaY, cObject3D i_Object)//
{
eInvalidate e_Invalidate = eInvalidate.NoChange;
@@ -219,41 +247,395 @@ namespace HexcalMC
mi_StatusTimer.Stop();
mi_StatusTimer.Start();
return e_Invalidate;
}
private void button1_Click(object sender, EventArgs e)
private void comboRaster_SelectedIndexChanged(object sender, EventArgs e) //坐标栅格样式
{
DemoScatterPlot(false);
editor3D.Raster = (eRaster)comboRaster.SelectedIndex;
editor3D.Invalidate();
}
private void checkMirrorY_CheckedChanged(object sender, EventArgs e) //Y轴镜像
{
editor3D.AxisY.Mirror = checkMirrorY.Checked;
editor3D.Invalidate();
}
private void comboMouse_SelectedIndexChanged(object sender, EventArgs e)
private void checkMirrorX_CheckedChanged(object sender, EventArgs e) //x轴镜像
{
editor3D.AxisX.Mirror = checkMirrorX.Checked;
editor3D.Invalidate();
}
private void btnReset_Click(object sender, EventArgs e) //重置视图
{
editor3D.SetCoefficients(1350, 70, 230);
editor3D.Invalidate();
}
private void btnScreenshot_Click(object sender, EventArgs e) //截图保存
{
SaveFileDialog i_Dlg = new SaveFileDialog();
i_Dlg.Title = "Save as PNG image";
i_Dlg.Filter = "PNG Image|*.png";
i_Dlg.DefaultExt = ".png";
if (DialogResult.Cancel == i_Dlg.ShowDialog(this))
return;
Bitmap i_Bitmap = editor3D.GetScreenshot();
try
{
i_Bitmap.Save(i_Dlg.FileName, ImageFormat.Png);
}
catch (Exception Ex)
{
MessageBox.Show(this, Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void comboMouse_SelectedIndexChanged(object sender, EventArgs e) //鼠标控制方式
{
switch (comboMouse.SelectedIndex)
{
case 0:
editor3D.SetUserInputs(eMouseCtrl.L_Theta_R_Phi);
labelMouseInfo.Text = "Left mouse: Elevate, Right mouse: Rotate";
labelMouseInfo.Text = "鼠标左键:升高,鼠标右键:旋转";
break;
case 1:
editor3D.SetUserInputs(eMouseCtrl.L_Theta_L_Phi);
labelMouseInfo.Text = "Left mouse: Elevate and Rotate";
labelMouseInfo.Text = "鼠标左键:升高和旋转";
break;
case 2:
editor3D.SetUserInputs(eMouseCtrl.M_Theta_M_Phi);
labelMouseInfo.Text = "Middle mouse: Elevate and Rotate";
labelMouseInfo.Text = "鼠标中键:升高和旋转";
break;
default:
Debug.Assert(false);
break;
}
labelMouseInfo.Text += ", Left mouse + SHIFT: Move, Left mouse + CTRL or wheel: Zoom, Left mouse + ALT: Select";
labelMouseInfo.Text += ", 鼠标左键 + SHIFT:移动、鼠标左键 + CTRL 或滚轮:缩放、鼠标左键 + ALT:选择";
}
private void comboColors_SelectedIndexChanged(object sender, EventArgs e)
{
me_ColorScheme = (eColorScheme)comboColors.SelectedIndex;
//判断 points 是否为空,表示当前是否已经有真实数据
if (etalon_points.Count > 0)
{
PointScatterPlot(etalon_points); //更新真实数据
}
//else
//{
// DemoScatterPlot(false); //更新虚拟数据
//}
}
private void btn_startmove_Click(object sender, EventArgs e) //开始运动
{
DebugDfn.AddLogText("开始运动");
int timeout = 5000;
Axis[] axes = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
//判断电机状态
if (!mainFrom.totalAxisEnabled)
{
DebugDfn.AddLogText("存在电机未使能");
_acs.WaitMotorEnabled(Axis.ACSC_AXIS_0, 1, timeout); //Y轴
// Wait axis 1 enabled during 5 sec
_acs.WaitMotorEnabled(Axis.ACSC_AXIS_1, 1, timeout);
_acs.WaitMotorEnabled(Axis.ACSC_AXIS_8, 1, timeout);
DebugDfn.AddLogText("电机已启用");
}
// 创建多点运动
double dwellTime = dwellTimes.Average()*1000; //将秒转换为毫秒
DebugDfn.AddLogText("平均停顿时间(毫秒):" + dwellTime);
_acs.MultiPointM(MotionFlags.ACSC_NONE, axes, dwellTime);
//判断是否有点
if (filteredPoints.Count == 0)
{
DebugDfn.AddLogText("没有点");
return;
}
// 添加符合条件的点到运动路径中
foreach (var point in filteredPoints)
{
double[] points = new double[3];
points[0] = point.Y;
points[1] = point.X;
points[2] = point.Z;
_acs.AddPointM(axes, points);
}
// 打印添加点的数量
DebugDfn.AddLogText("添加点的数量:" + filteredPoints.Count);
// Finish the motion End of the multi-point motion
_acs.EndSequenceM(axes);
//启动统计
mainFrom.StartCounting();
}
private void btn_stop_Click(object sender, EventArgs e) //停止运动
{
DebugDfn.AddLogText("停止运动");
try
{
Axis[] m_arrAxisList = new Axis[] { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
if (m_arrAxisList != null) _acs.HaltM(m_arrAxisList);
DebugDfn.AddLogText("立即停止 已发送命令");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
Debug.WriteLine(ex.Message);
}
//停止统计
mainFrom.StopCounting();
}
private void btn_etalon_import_Click(object sender, EventArgs e) //解析Etalon文件
{
//打开文件对号框,选择 mpf格式文件
OpenFileDialog i_Dlg = new OpenFileDialog();
i_Dlg.Title = "导入Etalon文件";
i_Dlg.Filter = "Etalon文件|*.mpf";
i_Dlg.DefaultExt = ".mpf";
i_Dlg.Multiselect = false;
if (DialogResult.Cancel == i_Dlg.ShowDialog(this))
return;
//读取文件
string s_File = i_Dlg.FileName;
//设置路径显示
DebugDfn.AddLogText("导入Etalon文件:" + s_File);
//解析文件
parse_mpf_file(s_File);
DebugDfn.AddLogText("Etalon文件解析完成");
}
private bool parse_mpf_file(string mpf_file_path) // 编写解析mpf文件的函数
{
//; Machine: ZIM
//; Position: 1
//; Created: 2/15/2023 12:29:13 PM
//; Program: TRAC-CAL V48, Build: 10, 5/13/2022 8:29:25 AM
//; File: 'cncData.xml'
//G71
//G90
//G500
//G01 X8000.000 Y200.000 Z-1400.000 F2000 //坐标
//G04 F=2 // 停顿时间
//G01 X7800.000 Y300.000 Z-1400.000 F2000
//G04 F=2
//G01 X7600.000 Y400.000 Z-1400.000 F2000
//G04 F=2
//G01 X7400.000 Y500.000 Z-1400.000 F2000
//G04 F=2
//G01 X7200.000 Y600.000 Z-1400.000 F2000
//判断文件是否存在
if (!File.Exists(mpf_file_path))
{
MessageBox.Show("文件不存在");
return false;
}
//清空之前的数据
etalon_points.Clear();
filteredPoints.Clear();
dwellTimes.Clear();
//读取文件
string[] lines = File.ReadAllLines(mpf_file_path);
Regex regex = new Regex(@"G01 X(?<X>[-+]?\d*\.?\d+) Y(?<Y>[-+]?\d*\.?\d+) Z(?<Z>[-+]?\d*\.?\d+)");
Regex dwellRegex = new Regex(@"G04 F=(?<F>\d+)");
foreach (string line in lines)
{
Match match = regex.Match(line);
if (match.Success)
{
double x = double.Parse(match.Groups["X"].Value);
double y = double.Parse(match.Groups["Y"].Value);
double z = double.Parse(match.Groups["Z"].Value);
etalon_points.Add(new Point(x, y, z));
}
Match dwellMatch = dwellRegex.Match(line);
if (dwellMatch.Success)
{
int f = int.Parse(dwellMatch.Groups["F"].Value);
dwellTimes.Add(f);
}
}
// 输出解析结果
//Console.WriteLine("Points:");
//foreach (var point in etalon_points)
//{
// Console.WriteLine($"X: {point.X}, Y: {point.Y}, Z: {point.Z}");
//}
//Console.WriteLine("Dwell Times:");
//foreach (var dwellTime in dwellTimes)
//{
// Console.WriteLine($"F: {dwellTime}");
//}
//过滤点集
foreach (var point in etalon_points)
{
if (MainFrom.IsWithinLimit(point)) //判断点是否在行程范围内
{
filteredPoints.Add(point);
}
}
//打印过滤后的点集大小
DebugDfn.AddLogText("过滤后的点集大小:" + filteredPoints.Count);
PointScatterPlot(filteredPoints);//绘制散点图
return true;
}
private void PointScatterPlot(List<Point> points) //绘制散点图
{
comboColors.Enabled = true; // Some of the demos will disable this combobox
me_ColorScheme = (eColorScheme)comboColors.SelectedIndex;
checkMirrorX.Checked = editor3D.AxisX.Mirror;
checkMirrorY.Checked = editor3D.AxisY.Mirror;
// 3 pixels for line width and for circle radius
const int SIZE = 3;
cColorScheme i_Scheme = new cColorScheme(me_ColorScheme);
cScatterData i_ShapeData = new cScatterData(i_Scheme);
cLineData i_LineData = new cLineData(i_Scheme);
List<cPoint3D> i_Points = new List<cPoint3D>();
foreach (var point in points)
{
double d_X = point.X;
double d_Y = point.Y;
double d_Z = point.Z;
cPoint3D i_Point = new cPoint3D(d_X, d_Y, d_Z, "Scatter Point");
// You can store the returned shape in a variable and later modify it's properties
cShape3D i_Shape = i_ShapeData.AddShape(i_Point, eScatterShape.Circle, SIZE, null);
}
// You can store the returned lines in a variable and later modify their properties
cLine3D[] i_Lines = i_LineData.AddConnectedLines(i_Points, SIZE, null);
// Depending on your use case you can also specify MaintainXY or MaintainXYZ here
editor3D.Clear();
editor3D.Normalize = eNormalize.Separate;
editor3D.AddRenderData(i_ShapeData, i_LineData);
editor3D.Selection.HighlightColor = Color.FromArgb(90, 90, 90);
editor3D.Selection.Callback = OnSelectEvent;
editor3D.Selection.MultiSelect = true;
editor3D.Selection.Enabled = true;
editor3D.UndoBuffer.Enabled = true;
editor3D.Invalidate();
}
public class Point
{
public double X { get; }
public double Y { get; }
public double Z { get; }
public Point(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
}
private void btn_clear_Click(object sender, EventArgs e) //清空绘图
{
editor3D.Clear();
editor3D.Normalize = eNormalize.Separate;
editor3D.Invalidate();
}
private void btn_draw_test_Click(object sender, EventArgs e)
{
DemoScatterPlot(false);
}
private void OnAnimationTimer(object sender, EventArgs e)
{
cScatterData i_ShapeData = new cScatterData();
currentIndex = mainFrom.GetInPosCount();//获取当前点的数量
if (currentIndex < filteredPoints.Count)
{
// 更新点的颜色
for (int i = 0; i <= currentIndex; i++)
{
double d_X = filteredPoints[i].X;
double d_Y = filteredPoints[i].Y;
double d_Z = filteredPoints[i].Z;
cPoint3D i_Point = new cPoint3D(d_X, d_Y, d_Z, "Scatter Point");
SolidBrush i_brush = new SolidBrush(Color.Red);
// You can store the returned shape in a variable and later modify it's properties
cShape3D i_Shape = i_ShapeData.AddShape(i_Point, eScatterShape.Circle, 5, i_brush, null);
}
// 对于剩余部分的点,不做颜色更新
for (int i = currentIndex; i < filteredPoints.Count; i++)
{
double d_X = filteredPoints[i].X;
double d_Y = filteredPoints[i].Y;
double d_Z = filteredPoints[i].Z;
cPoint3D i_Point = new cPoint3D(d_X, d_Y, d_Z, "Scatter Point");
SolidBrush i_brush = new SolidBrush(Color.Gray);
// You can store the returned shape in a variable and later modify it's properties
cShape3D i_Shape = i_ShapeData.AddShape(i_Point, eScatterShape.Circle, 3, i_brush, null);
}
//打印 所有点的数量和 currentIndex
Console.WriteLine("所有点的数量:" + filteredPoints.Count + "当前点的数量:" + currentIndex);
}
editor3D.Clear();
editor3D.Normalize = eNormalize.Separate;
editor3D.AddRenderData(i_ShapeData);
editor3D.Invalidate();
}
}
}
-3
View File
@@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
+10
View File
@@ -210,6 +210,16 @@ namespace HexcalMC.Properties {
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap start {
get {
object obj = ResourceManager.GetObject("start", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
+10 -7
View File
@@ -121,6 +121,9 @@
<data name="about" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\about.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="etalon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\etalon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="motion" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\motion.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -139,6 +142,9 @@
<data name="Hexagon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Hexagon.ico;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="help" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="quick_location" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\quick_location.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -154,16 +160,13 @@
<data name="stop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\stop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="demo_show" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\demo_show.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="home" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\home.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="help" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="demo_show" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\demo_show.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="etalon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\etalon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="start" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\start.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
+1 -1
View File
@@ -21,7 +21,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>kjOJfgYi/k+pJ5FhmEfpQmK1QNF+Sr/rAs3Y4JuCvnE=</dsig:DigestValue>
<dsig:DigestValue>3I+Sdzke39z2xPBTFN2cGyU/DYa1hH93nKjBGpXTzUw=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
+2 -2
View File
@@ -55,14 +55,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="HexcalMC.exe" size="502272">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="HexcalMC.exe" size="508928">
<assemblyIdentity name="HexcalMC" version="0.0.3.0" language="neutral" processorArchitecture="amd64" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>Uv0oJrFdIL2ljwa9FK9n8TvSxO1qxvCPi6Z0wKBelNs=</dsig:DigestValue>
<dsig:DigestValue>Pllh2aI7tVRTnfFfbvwT2qdIQZ30ZwrhlbF820ogi8o=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
Binary file not shown.