#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
+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>