1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204 |
- using OpenCvSharp;
- using OpenCvSharp.Extensions;
- using PaintDotNet.Adjust.BaseImage;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation.ImageCollect;
- using PaintDotNet.Annotation.Measure;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Camera;
- using PaintDotNet.CustomControl;
- using PaintDotNet.ImageCollect;
- using StageController;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.IO;
- using System.IO.Ports;
- using System.Linq;
- using System.Management;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Interop;
- namespace PaintDotNet.Hardware
- {
- internal class HardwareBaseDialog : FloatingToolForm, IStageEvent
- {
- protected AppWorkspace m_appWorkspace;
- #region 声明组件
- protected GroupBox gboxXYspeed;
- protected GroupBox gboxZspeed;
- protected DocumentPreview m_documentWorkspace;
- protected Label lblXPosition;
- protected Label lblYPosition;
- protected Label lblZPosition;
- protected Label lblXDistance;
- protected Label lblYDistance;
- protected Label lblLDistance;
- protected Button btnFreeloadstage;
- protected Button btnStoploadstage;
- protected Button btnResetloadstage;
- protected Button btnCenterloadstage;
- protected Button btnInloadstage;
- protected Button btnOutloadstage;
- protected Button btnZStop;
- protected Button btnZFree;
- protected TextBox txtXStep;
- protected TextBox txtYStep;
- protected TextBox txtZStep;
- protected ComboBox cmbXYStepUnit;
- protected ComboBox cmbZStepUnit;
- protected Button btnContinuityLower;
- protected Button btnContinuityUp;
- protected Button btnFixedLower;
- protected Button btnFixedUp;
- protected Button btnCenterDisplay;
- protected Button btnStopall;
- protected Button btnDsRocker;
- protected Button btnSetting;
- #endregion
- #region Axis Fields
- protected AxisController m_Stage;
- protected LoadingStageModel m_loadingStageModel;
- protected List<LoadingStageModel.Item> m_speedLists = new List<LoadingStageModel.Item>();
- /// <summary>
- /// X轴單次长度
- /// </summary>
- protected virtual double StepLenthX
- {
- get
- {
- string text = txtXStep.Text.Trim();
- if (string.IsNullOrEmpty(text))
- {
- throw new Exception("X" + PdnResources.GetString("Menu.TheXaxismovestepannotbeempty0.Text"));
- }
- var value = double.Parse(text);
- if (cmbXYStepUnit.SelectedItem.ToString().Equals("mm"))
- {
- value *= 1000;
- }
- return value;
- }
- }
- /// <summary>
- /// Y轴單次进长度
- /// </summary>
- protected virtual double StepLenthY
- {
- get
- {
- string text = txtYStep.Text.Trim();
- if (string.IsNullOrEmpty(text))
- {
- throw new Exception("Y" + PdnResources.GetString("Menu.TheXaxismovestepannotbeempty0.Text"));
- }
- var value = double.Parse(text);
- if (cmbXYStepUnit.SelectedItem.ToString().Equals("mm"))
- {
- value *= 1000;
- }
- return value;
- }
- }
- /// <summary>
- /// Z轴步进长度
- /// </summary>
- protected virtual double StepLenthZ
- {
- get
- {
- string text = txtZStep.Text.Trim();
- if (string.IsNullOrEmpty(text))
- {
- throw new Exception("Z" + PdnResources.GetString("Menu.TheXaxismovestepannotbeempty0.Text"));
- }
- var value = double.Parse(text);
- if (cmbZStepUnit.SelectedItem.ToString().Equals("mm"))
- {
- value *= 1000;
- }
- return value;
- }
- }
- protected virtual bool IsSpeedHarmonize
- {
- get;
- }
- public static int m_xyspeed = 0;//xy轴运行速度
- public static int m_zspeed = 0; //z轴运行速度
- protected double m_initStepX = 0; //清零时X轴所在位置
- protected double m_initStepY = 0; //清零时Y轴所在位置
- protected double m_stageWidth; // 行程X(操作台高度)
- protected double m_stageHeight; // 行程Y(操作台宽度)
- #endregion Axis Fields
- #region Camera Fields
- /// <summary>
- /// 视场宽度
- /// </summary>
- protected virtual double VisionWidth => m_viewWidth * m_PxLength;
- /// <summary>
- /// 视场高度
- /// </summary>
- protected virtual double VisionHeight => m_viewHeight * m_PxLength;
- protected int m_viewWidth; // 视场宽(像素)
- protected int m_viewHeight; // 视场高(像素)
- protected int VisionWidthPixel
- {
- get => m_viewWidth;
- set
- {
- if (value == m_viewWidth)
- return;
- m_documentWorkspace.ViewWidth = value;
- m_viewWidth = value;
- }
- }
- protected int VisionHeightPixel
- {
- get => m_viewHeight;
- set
- {
- if (value == m_viewHeight)
- return;
- m_documentWorkspace.ViewHeigth = value;
- m_viewHeight = value;
- }
- }
- /// <summary>
- /// 平台是否复位
- /// </summary>
- protected bool m_isReset;
- //标尺比例
- protected double m_PxLength;
- #endregion
- protected string[] m_unit = new string[] { "mm", "um" };
- protected bool m_isShowCenter = false;
- private System.Windows.Forms.Timer timerStageUpdate;
- private IContainer components;
- // 窗口缩小比例
- protected int m_docspaceScale = 1;
- public HardwareBaseDialog()
- {
- InitializeComponent();
- }
- public HardwareBaseDialog(AppWorkspace appWorkspace)
- {
- m_appWorkspace = appWorkspace;
- Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out m_PxLength);
- InitializeComponent();
- InitializeButtonBackgroundImage();
- m_documentWorkspace = new DocumentPreview();
- m_documentWorkspace.AppWorkspaceTop = appWorkspace;
- m_documentWorkspace.Visible = true;
- m_documentWorkspace.RulersEnabled = true;
- m_documentWorkspace.Units = MeasurementUnit.Micron;
- m_docspaceScale = 10;
- VisionWidthPixel = 2448;
- VisionHeightPixel = 2048;
- Bitmap bitmap = new Bitmap(m_viewWidth, m_viewHeight);
- m_documentWorkspace.Document = Document.FromImage(bitmap);
- m_documentWorkspace.Dock = DockStyle.Fill;
- m_documentWorkspace.ScaleFactor = new ScaleFactor(1, m_docspaceScale);
- m_documentWorkspace.SetViewPoint(0, 0);
- ToolPointer.GetMouseLeftClickPoint += GetMouseLeftClickPoint;
- Load += OnLoad;
- FormClosing += OnFormClosing;
- }
- private void OnFormClosing(object sender, FormClosingEventArgs e)
- {
- UninitCamera();
- UninitStage();
- UninitDocumentWorkspace();
- ToolPointer.GetMouseLeftClickPoint -= GetMouseLeftClickPoint;
- GC.Collect();
- base.Dispose();
- }
- private void OnLoad(object sender, EventArgs e)
- {
- m_loadingStageModel = Startup.instance.loadingStageModel;
- InitializeCamera();
- InitStage();
- ReloadingStageParam(m_loadingStageModel);
- timerStageUpdate.Start();
- }
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.gboxXYspeed = new System.Windows.Forms.GroupBox();
- this.gboxZspeed = new System.Windows.Forms.GroupBox();
- this.lblYPosition = new System.Windows.Forms.Label();
- this.lblXPosition = new System.Windows.Forms.Label();
- this.lblZPosition = new System.Windows.Forms.Label();
- this.lblLDistance = new System.Windows.Forms.Label();
- this.lblYDistance = new System.Windows.Forms.Label();
- this.lblXDistance = new System.Windows.Forms.Label();
- this.btnFreeloadstage = new System.Windows.Forms.Button();
- this.btnStoploadstage = new System.Windows.Forms.Button();
- this.btnResetloadstage = new System.Windows.Forms.Button();
- this.btnCenterloadstage = new System.Windows.Forms.Button();
- this.btnInloadstage = new System.Windows.Forms.Button();
- this.btnOutloadstage = new System.Windows.Forms.Button();
- this.btnZFree = new System.Windows.Forms.Button();
- this.btnZStop = new System.Windows.Forms.Button();
- this.btnFixedLower = new System.Windows.Forms.Button();
- this.btnFixedUp = new System.Windows.Forms.Button();
- this.btnContinuityLower = new System.Windows.Forms.Button();
- this.btnContinuityUp = new System.Windows.Forms.Button();
- this.btnCenterDisplay = new System.Windows.Forms.Button();
- this.btnStopall = new System.Windows.Forms.Button();
- this.btnDsRocker = new System.Windows.Forms.Button();
- this.btnSetting = new System.Windows.Forms.Button();
- this.txtXStep = new System.Windows.Forms.TextBox();
- this.txtYStep = new System.Windows.Forms.TextBox();
- this.txtZStep = new System.Windows.Forms.TextBox();
- this.cmbZStepUnit = new System.Windows.Forms.ComboBox();
- this.cmbXYStepUnit = new System.Windows.Forms.ComboBox();
- this.timerStageUpdate = new System.Windows.Forms.Timer(this.components);
- this.SuspendLayout();
- //
- // gboxXYspeed
- //
- this.gboxXYspeed.Location = new System.Drawing.Point(0, 0);
- this.gboxXYspeed.Name = "gboxXYspeed";
- this.gboxXYspeed.Size = new System.Drawing.Size(200, 100);
- this.gboxXYspeed.TabIndex = 0;
- this.gboxXYspeed.TabStop = false;
- //
- // gboxZspeed
- //
- this.gboxZspeed.Location = new System.Drawing.Point(0, 0);
- this.gboxZspeed.Name = "gboxZspeed";
- this.gboxZspeed.Size = new System.Drawing.Size(200, 100);
- this.gboxZspeed.TabIndex = 0;
- this.gboxZspeed.TabStop = false;
- //
- // lblYPosition
- //
- this.lblYPosition.Location = new System.Drawing.Point(0, 0);
- this.lblYPosition.Name = "lblYPosition";
- this.lblYPosition.Size = new System.Drawing.Size(100, 23);
- this.lblYPosition.TabIndex = 0;
- //
- // lblXPosition
- //
- this.lblXPosition.Location = new System.Drawing.Point(0, 0);
- this.lblXPosition.Name = "lblXPosition";
- this.lblXPosition.Size = new System.Drawing.Size(100, 23);
- this.lblXPosition.TabIndex = 0;
- //
- // lblZPosition
- //
- this.lblZPosition.Location = new System.Drawing.Point(0, 0);
- this.lblZPosition.Name = "lblZPosition";
- this.lblZPosition.Size = new System.Drawing.Size(100, 23);
- this.lblZPosition.TabIndex = 0;
- //
- // lblLDistance
- //
- this.lblLDistance.Location = new System.Drawing.Point(0, 0);
- this.lblLDistance.Name = "lblLDistance";
- this.lblLDistance.Size = new System.Drawing.Size(100, 23);
- this.lblLDistance.TabIndex = 0;
- //
- // lblYDistance
- //
- this.lblYDistance.Location = new System.Drawing.Point(0, 0);
- this.lblYDistance.Name = "lblYDistance";
- this.lblYDistance.Size = new System.Drawing.Size(100, 23);
- this.lblYDistance.TabIndex = 0;
- //
- // lblXDistance
- //
- this.lblXDistance.Location = new System.Drawing.Point(0, 0);
- this.lblXDistance.Name = "lblXDistance";
- this.lblXDistance.Size = new System.Drawing.Size(100, 23);
- this.lblXDistance.TabIndex = 0;
- //
- // btnFreeloadstage
- //
- this.btnFreeloadstage.Location = new System.Drawing.Point(0, 0);
- this.btnFreeloadstage.Name = "btnFreeloadstage";
- this.btnFreeloadstage.Size = new System.Drawing.Size(75, 23);
- this.btnFreeloadstage.TabIndex = 0;
- this.btnFreeloadstage.Click += new System.EventHandler(this.btnLockXY_Click);
- //
- // btnStoploadstage
- //
- this.btnStoploadstage.Location = new System.Drawing.Point(0, 0);
- this.btnStoploadstage.Name = "btnStoploadstage";
- this.btnStoploadstage.Size = new System.Drawing.Size(75, 23);
- this.btnStoploadstage.TabIndex = 0;
- this.btnStoploadstage.Click += new System.EventHandler(this.btnStopXY_Click);
- //
- // btnResetloadstage
- //
- this.btnResetloadstage.Location = new System.Drawing.Point(0, 0);
- this.btnResetloadstage.Name = "btnResetloadstage";
- this.btnResetloadstage.Size = new System.Drawing.Size(75, 23);
- this.btnResetloadstage.TabIndex = 0;
- this.btnResetloadstage.Click += new System.EventHandler(this.btnResetloadstage_Click);
- //
- // btnCenterloadstage
- //
- this.btnCenterloadstage.Location = new System.Drawing.Point(0, 0);
- this.btnCenterloadstage.Name = "btnCenterloadstage";
- this.btnCenterloadstage.Size = new System.Drawing.Size(75, 23);
- this.btnCenterloadstage.TabIndex = 0;
- this.btnCenterloadstage.Click += new System.EventHandler(this.btnCenterloadstage_Click);
- //
- // btnInloadstage
- //
- this.btnInloadstage.Location = new System.Drawing.Point(0, 0);
- this.btnInloadstage.Name = "btnInloadstage";
- this.btnInloadstage.Size = new System.Drawing.Size(75, 23);
- this.btnInloadstage.TabIndex = 0;
- this.btnInloadstage.Click += new System.EventHandler(this.btnInloadstage_Click);
- //
- // btnOutloadstage
- //
- this.btnOutloadstage.Location = new System.Drawing.Point(0, 0);
- this.btnOutloadstage.Name = "btnOutloadstage";
- this.btnOutloadstage.Size = new System.Drawing.Size(75, 23);
- this.btnOutloadstage.TabIndex = 0;
- this.btnOutloadstage.Click += new System.EventHandler(this.btnOutloadstage_Click);
- //
- // btnZFree
- //
- this.btnZFree.Location = new System.Drawing.Point(0, 0);
- this.btnZFree.Name = "btnZFree";
- this.btnZFree.Size = new System.Drawing.Size(75, 23);
- this.btnZFree.TabIndex = 0;
- this.btnZFree.Click += new System.EventHandler(this.btnZLock_Click);
- //
- // btnZStop
- //
- this.btnZStop.Location = new System.Drawing.Point(0, 0);
- this.btnZStop.Name = "btnZStop";
- this.btnZStop.Size = new System.Drawing.Size(75, 23);
- this.btnZStop.TabIndex = 0;
- this.btnZStop.Click += new System.EventHandler(this.btnZStop_Click);
- //
- // btnFixedLower
- //
- this.btnFixedLower.Location = new System.Drawing.Point(0, 0);
- this.btnFixedLower.Name = "btnFixedLower";
- this.btnFixedLower.Size = new System.Drawing.Size(75, 23);
- this.btnFixedLower.TabIndex = 0;
- btnFixedLower.Click += btnFixedLower_Click;
- //
- // btnFixedUp
- //
- this.btnFixedUp.Location = new System.Drawing.Point(0, 0);
- this.btnFixedUp.Name = "btnFixedUp";
- this.btnFixedUp.Size = new System.Drawing.Size(75, 23);
- this.btnFixedUp.TabIndex = 0;
- btnFixedUp.Click += btnFixedUp_Click;
- //
- // btnContinuityLower
- //
- this.btnContinuityLower.Location = new System.Drawing.Point(0, 0);
- this.btnContinuityLower.Name = "btnContinuityLower";
- this.btnContinuityLower.Size = new System.Drawing.Size(75, 23);
- this.btnContinuityLower.TabIndex = 0;
- btnContinuityLower.MouseDown += btnContinuityLower_Start;
- btnContinuityLower.MouseUp += btnZStop_Click;
- //
- // btnContinuityUp
- //
- this.btnContinuityUp.Location = new System.Drawing.Point(0, 0);
- this.btnContinuityUp.Name = "btnContinuityUp";
- this.btnContinuityUp.Size = new System.Drawing.Size(75, 23);
- this.btnContinuityUp.TabIndex = 0;
- btnContinuityUp.MouseDown += btnContinuityUp_Start;
- btnContinuityUp.MouseUp += btnZStop_Click;
- //
- // btnCenterDisplay
- //
- this.btnCenterDisplay.Location = new System.Drawing.Point(0, 0);
- this.btnCenterDisplay.Name = "btnCenterDisplay";
- this.btnCenterDisplay.Size = new System.Drawing.Size(75, 23);
- this.btnCenterDisplay.TabIndex = 0;
- this.btnCenterDisplay.Click += new System.EventHandler(this.btnCenteDisplay_Click);
- //
- // btnStopall
- //
- this.btnStopall.Location = new System.Drawing.Point(0, 0);
- this.btnStopall.Name = "btnStopall";
- this.btnStopall.Size = new System.Drawing.Size(75, 23);
- this.btnStopall.TabIndex = 0;
- //
- // btnDsRocker
- //
- this.btnDsRocker.Location = new System.Drawing.Point(0, 0);
- this.btnDsRocker.Name = "btnDsRocker";
- this.btnDsRocker.Size = new System.Drawing.Size(75, 23);
- this.btnDsRocker.TabIndex = 0;
- //
- // btnSetting
- //
- this.btnSetting.Location = new System.Drawing.Point(0, 0);
- this.btnSetting.Name = "btnSetting";
- this.btnSetting.Size = new System.Drawing.Size(75, 23);
- this.btnSetting.TabIndex = 0;
- this.btnSetting.Click += btnSetting_Click;
- //
- // txtXStep
- //
- this.txtXStep.Location = new System.Drawing.Point(0, 0);
- this.txtXStep.Name = "txtXStep";
- this.txtXStep.Size = new System.Drawing.Size(100, 21);
- this.txtXStep.TabIndex = 0;
- this.txtXStep.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckInputIsNumeric);
- this.txtXStep.Leave += new System.EventHandler(this.txtStep_Leave);
- //
- // txtYStep
- //
- this.txtYStep.Location = new System.Drawing.Point(0, 0);
- this.txtYStep.Name = "txtYStep";
- this.txtYStep.Size = new System.Drawing.Size(100, 21);
- this.txtYStep.TabIndex = 0;
- this.txtYStep.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckInputIsNumeric);
- this.txtYStep.Leave += new System.EventHandler(this.txtStep_Leave);
- //
- // txtZStep
- //
- this.txtZStep.Location = new System.Drawing.Point(0, 0);
- this.txtZStep.Name = "txtZStep";
- this.txtZStep.Size = new System.Drawing.Size(100, 21);
- this.txtZStep.TabIndex = 0;
- this.txtZStep.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckInputIsNumeric);
- this.txtZStep.Leave += new System.EventHandler(this.txtStep_Leave);
- //
- // cmbZStepUnit
- //
- this.cmbZStepUnit.Location = new System.Drawing.Point(0, 0);
- this.cmbZStepUnit.Name = "cmbZStepUnit";
- this.cmbZStepUnit.Size = new System.Drawing.Size(121, 20);
- this.cmbZStepUnit.TabIndex = 0;
- //
- // cmbXYStepUnit
- //
- this.cmbXYStepUnit.Location = new System.Drawing.Point(0, 0);
- this.cmbXYStepUnit.Name = "cmbXYStepUnit";
- this.cmbXYStepUnit.Size = new System.Drawing.Size(121, 20);
- this.cmbXYStepUnit.TabIndex = 0;
- //
- // timerStageUpdate
- //
- this.timerStageUpdate.Interval = 15;
- this.timerStageUpdate.Tick += new System.EventHandler(this.timerStageUpdate_Tick);
- //
- // HardwareBaseDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(292, 271);
- this.Location = new System.Drawing.Point(0, 0);
- this.Name = "HardwareBaseDialog";
- this.ResumeLayout(false);
- }
- protected void InitializeLanguageText()
- {
- btnFreeloadstage.Text = "自由";// PdnResources.GetString("Menu.freeing.text");
- btnFreeloadstage.Enabled = AxisController.GetInstance().FreeOrLockXYEnabled;
- btnStoploadstage.Text = PdnResources.GetString("Menu.stop.text");
- btnResetloadstage.Text = PdnResources.GetString("Menu.reset.Text");
- btnCenterloadstage.Text = PdnResources.GetString("Menu.center.text");
- btnInloadstage.Text = PdnResources.GetString("Menu.enterfilm.text");
- btnOutloadstage.Text = PdnResources.GetString("Menu.outslice.text");
- btnZFree.Text = "自由";// PdnResources.GetString("Menu.locking.text");
- btnZFree.Enabled = AxisController.GetInstance().FreeOrLockZEnabled;
- btnZStop.Text = PdnResources.GetString("Menu.stop.text");
- btnCenterDisplay.Text = PdnResources.GetString("Menu.Centerdisplay.text");
- btnStopall.Text = PdnResources.GetString("Menu.Stopall.text");
- btnDsRocker.Text = PdnResources.GetString("Menu.Disabletherocker.text");
- btnDsRocker.Enabled = AxisController.GetInstance().FreeOrLockZEnabled;
- btnSetting.Text = PdnResources.GetString("Menu.SerialportSettings.Text");
- }
- private void InitializeButtonBackgroundImage()
- {
- btnContinuityUp.FlatStyle = FlatStyle.Flat;
- btnContinuityUp.FlatAppearance.BorderSize = 0;
- btnContinuityUp.BackgroundImageLayout = ImageLayout.Zoom;
- btnContinuityUp.BackgroundImage = PdnResources.GetImageResource("Images.ButtonUp.png").Reference;
- btnContinuityLower.FlatStyle = FlatStyle.Flat;
- btnContinuityLower.FlatAppearance.BorderSize = 0;
- btnContinuityLower.BackgroundImageLayout = ImageLayout.Zoom;
- btnContinuityLower.BackgroundImage = PdnResources.GetImageResource("Images.ButtonDown.png").Reference;
- btnFixedUp.FlatStyle = FlatStyle.Flat;
- btnFixedUp.FlatAppearance.BorderSize = 0;
- btnFixedUp.BackgroundImageLayout = ImageLayout.Zoom;
- btnFixedUp.BackgroundImage = PdnResources.GetImageResource("Images.ButtonUp.png").Reference;
- btnFixedLower.FlatStyle = FlatStyle.Flat;
- btnFixedLower.FlatAppearance.BorderSize = 0;
- btnFixedLower.BackgroundImageLayout = ImageLayout.Zoom;
- btnFixedLower.BackgroundImage = PdnResources.GetImageResource("Images.ButtonDown.png").Reference;
- }
- public void InitStage()
- {
- m_Stage = AxisController.GetInstance();
- if (!m_Stage.IsOpen)
- {
- MessageBox.Show(PdnResources.GetString("Message.AxisController.NotConnected"));
- }
- m_Stage.AddApp(this);
- }
- #region Dispose
- public void UninitStage()
- {
- m_Stage.RemoveApp(this);
- }
- public void UninitDocumentWorkspace()
- {
- if (m_documentWorkspace != null && !m_documentWorkspace.IsDisposed)
- {
- m_documentWorkspace.Dispose();
- }
- }
- #endregion
- /// <summary>
- /// 视场模式操作台
- /// </summary>
- public CircleControl initViewCircal(int size)
- {
- var circleControl = new CircleControl(size);
- circleControl.mouseDown += new EventHandler(visionClick);
- return circleControl;
- }
- /// <summary>
- /// 运动模式操作台
- /// </summary>
- public CircleControl initSportCircal(int size)
- {
- var circleSportControl = new CircleControl(size);
- circleSportControl.mouseUp += new EventHandler(sportMouseUp);
- circleSportControl.mouseDown += new EventHandler(sportMouseDown);
- return circleSportControl;
- }
- /// <summary>
- /// 初始化设置信息
- /// </summary>
- /// <param name="loadingStageModel"></param>
- public void ReloadingStageParam(LoadingStageModel loadingStageModel)
- {
- m_loadingStageModel = loadingStageModel;
- m_stageWidth = double.Parse(m_loadingStageModel.TripX);
- m_stageHeight = double.Parse(m_loadingStageModel.TripY);
- ReinitSpeedUI();
- }
- #region Speed
- /// <summary>
- /// gboxzspeed gboxxyspeed初始化
- /// </summary>
- protected virtual void ReinitSpeedUI()
- {
- InitGroupSpeed(gboxXYspeed, XSpeed_CheckedChanged);
- InitGroupSpeed(gboxZspeed, ZSpeed_CheckedChanged);
- if (gboxXYspeed.Controls.Count == 0 || gboxZspeed.Controls.Count == 0) return;
- m_Stage.SetSpeedXY(m_speedLists[0].LSpeed);
- m_Stage.SetSpeedZ(m_speedLists[0].ZSpeed);
- }
- protected virtual void InitGroupSpeed(Control group, Action<object, EventArgs> action)
- {
- m_speedLists = m_loadingStageModel.items;
- int pw = (group.Width - 20) / 3;
- group.Controls.Clear();
- for (int i = 0; i < m_speedLists.Count; ++i)
- {
- if (m_speedLists[i].SChecked == 1)
- {
- var radioButton = new RadioButton();
- radioButton.Text = (i + 1).ToString();
- radioButton.AutoSize = true;
- radioButton.Checked = i == 0;
- radioButton.CheckedChanged += new System.EventHandler(action);
- radioButton.Tag = i;
- radioButton.Location = new System.Drawing.Point(18 + (i % 3) * pw, 21 + (i / 3) * 25);
- group.Controls.Add(radioButton);
- }
- }
- }
- // 速度选择按钮
- protected virtual void XSpeed_CheckedChanged(object sender, EventArgs e)
- {
- RadioButton radio = (RadioButton)sender;
- if (radio.Checked)
- {
- int index = (int)radio.Tag;
- m_Stage.SetSpeedXY(m_speedLists[index].LSpeed);
- // 联动调速
- if (IsSpeedHarmonize)
- {
- int count = gboxZspeed.Controls.Count;
- for (int i = 0; i < count; ++i)
- {
- ((RadioButton)gboxZspeed.Controls[i]).Checked = i == index;
- }
- }
- }
- }
- protected virtual void ZSpeed_CheckedChanged(object sender, EventArgs e)
- {
- RadioButton radio = (RadioButton)sender;
- if (!radio.Checked) return;
- int index = (int)radio.Tag;
- m_Stage.SetSpeedZ(m_speedLists[index].ZSpeed);
- // 联动调速
- if (IsSpeedHarmonize)
- {
- int count = gboxXYspeed.Controls.Count;
- for (int i = 0; i < count; ++i)
- {
- ((RadioButton)gboxXYspeed.Controls[i]).Checked = i == index;
- }
- }
- }
- #endregion
- protected int ConvertUMToPX(double length)
- {
- // if (length < 0) length = -length;
- return (int)(length / m_PxLength);
- }
- protected double ConvertPXToUm(double length)
- {
- return length * m_PxLength;
- }
- #region Position Update
- public void OnUpdatePosition()
- {
- try
- {
- SetViewLocation(m_Stage.X, m_Stage.Y, m_Stage.Z); // 移动视图
- ChangeDistanceAndCheckStop(m_Stage.X, m_Stage.Y);
- //if (m_Stage.StateX == 0 || m_Stage.StateY == 0) ; // 平台电机自由后需要重新复位
- // m_isReset = false;
- }
- catch
- { }
- }
- /// <summary>
- /// 设置视场的位置
- /// </summary>
- /// <param name="position"></param>
- protected virtual void SetViewLocation(double x, double y, double z)
- {
- var b = this.IsDisposed;
- Invoke(new Action(() => UpdatePositionDisplay(x, y, z)));
- x = x < 0 ? 0 : x;
- y = y < 0 ? 0 : y;
- this.BeginInvoke(new Action(() =>
- {
- m_documentWorkspace.SetViewPoint(ConvertUMToPX(x), ConvertUMToPX(y));
- }));
- }
- protected virtual void UpdatePositionDisplay(double x, double y, double z)
- {
- lblXPosition.Text = x.ToString();
- lblYPosition.Text = y.ToString();
- lblZPosition.Text = z.ToString();
- }
- protected virtual void ChangeDistanceAndCheckStop(double x, double y)
- {
- var distanceX = x - m_initStepX;
- var distanceY = y - m_initStepY;
- var distanceL = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);
- Invoke(new Action(() =>
- {
- lblXDistance.Text = "X:" + distanceX.ToString("0");
- lblYDistance.Text = "Y:" + distanceY.ToString("0");
- lblLDistance.Text = "L:" + distanceL.ToString("0");
- }));
- }
- #endregion
- #region 视场圆环
- // 视场圆环按钮被点击
- protected virtual void visionClick(object sender, EventArgs e)
- {
- var circleSportControl = (CircleControl)sender;
- var p = circleSportControl._position;
- if (p < 0 || p > 15) return;
- var map = circleSportControl.positionMap[p % 8];
- if (p < 8)
- m_Stage.Move(VisionWidth * map[0] / 2, VisionHeight * map[1] / 2);
- else
- m_Stage.Move(VisionWidth * map[0], VisionHeight * map[1]);
- }
- #endregion
- #region 运动圆环
- protected virtual void sportMouseDown(object sender, EventArgs e)
- {
- var circleSportControl = (CircleControl)sender;
- if (circleSportControl._position < 8)
- {
- var p = circleSportControl._position;
- if (p < 0 || p > 7)
- return;
- var map = circleSportControl.positionMap[p];
- m_Stage.Move(StepLenthX * map[0], StepLenthY * map[1]);
- }
- else
- {
- var direction = circleSportControl._position - 8;
- m_Stage.Split(direction);
- }
- }
- protected virtual void sportMouseUp(object sender, EventArgs e)
- {
- var circleSportControl = (CircleControl)sender;
- if (circleSportControl._position > 7)
- btnStopXY_Click(null, null);
- }
- #endregion
- //参数设置按钮点击
- protected virtual void btnSetting_Click(object sender, EventArgs e)
- {
- //参数设置按钮点击弹窗
- using (ParamSetingDialog af = new ParamSetingDialog(this))
- {
- af.Setted += ReloadingStageParam;
- af.ShowDialog();
- }
- }
- #region Z 运动
- /// <summary>
- /// Z轴连续向上移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnContinuityUp_Start(object sender, EventArgs e)
- {
- m_Stage.GoTop(true);
- }
- /// <summary>
- /// Z轴连续向下移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnContinuityLower_Start(object sender, EventArgs e)
- {
- m_Stage.GoTop(false);
- }
- /// <summary>
- /// Z轴定长向上移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnFixedUp_Click(object sender, EventArgs e)
- {
- m_Stage.Up(StepLenthZ);
- }
- /// <summary>
- /// Z轴定长向下移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnFixedLower_Click(object sender, EventArgs e)
- {
- m_Stage.Up(-StepLenthZ);
- }
- #endregion
- protected virtual void CheckInputIsNumeric(object sender, KeyPressEventArgs e)
- {
- var text = ((TextBox)sender).Text;
- var key = (int)e.KeyChar;
- if ((key < 48 || key > 57) && key != 8 && key != 46)
- e.Handled = true;
- if (key == 46) //小数点
- {
- if (text.Length <= 0)
- e.Handled = true; //小数点不能在第一位
- else
- {
- float f, oldf;
- var b1 = float.TryParse(text, out oldf);
- var b2 = float.TryParse(text + key.ToString(), out f);
- if (!b2 && b1)
- e.Handled = true;
- }
- }
- }
- #region Axis Stop
- /// <summary>
- /// Z轴自由
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnZLock_Click(object sender, EventArgs e)
- {
- m_Stage.FreeZ();
- }
- /// <summary>
- /// Z轴停止
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnZStop_Click(object sender, EventArgs e)
- {
- m_Stage.FreeZ();
- }
- /// <summary>
- /// XY轴自由
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnLockXY_Click(object sender, EventArgs e)
- {
- m_Stage.FreeStage();
- }
- /// <summary>
- /// XY轴停止
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnStopXY_Click(object sender, EventArgs e)
- {
- m_Stage.LockStage();
- }
- /// <summary>
- /// 全部停止
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnStopall_Click(object sender, EventArgs e)
- {
- btnZStop_Click(null, null);
- btnStopXY_Click(null, null);
- }
- #endregion Axis Stop
- /// <summary>
- /// 禁用摇杆
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnDsRocker_Click(object sender, EventArgs e)
- {
- m_Stage.SetRockerEnabel(false);
- }
- protected virtual void GetMouseLeftClickPoint(object sender, EventArgs e)
- {
- if (!m_isReset)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseresetfirst.Text"));
- return;
- }
- PointF pointF = (PointF)sender;
- List<DrawObject> graphicsList = m_documentWorkspace.GraphicsList.GetDrawClassList(DrawClass.Stitch);
- int count = graphicsList.Count;
- var x = ConvertPXToUm((int)(pointF.X));
- var y = ConvertPXToUm((int)(pointF.Y));
- for (int i = 0; i < count; i++)
- {
- List<Dictionary<int, object>> points = ((DrawStithchingBase)graphicsList[i]).GetViewPoints();
- for (int j = 0; j < points.Count; j++)
- {
- Dictionary<int, object> point = points[j];
- RectangleF rectangleF = new RectangleF((PointF)point[0], new SizeF(m_viewWidth, m_viewHeight));
- if (rectangleF.Contains(pointF))
- {
- pointF = (PointF)point[0];
- x = ConvertPXToUm((int)(pointF.X));
- y = ConvertPXToUm((int)(pointF.Y));
- m_Stage.To(x, y); return;
- }
- }
- }
- m_Stage.To(x, y);
- }
- #region Moveflow
- /// <summary>
- /// 复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnResetloadstage_Click(object sender, EventArgs e)
- {
- var dialog = TransferProgressDialog.CreatDialog("平台复位", "复位中...", OnProgressCancel, "Stop");
- m_Stage.ResetStage(
- () =>
- {
- m_isReset = true;// AxisController.GetInstance().NeedSaveResetStageStatus;
- this.Invoke(new Action(dialog.Close));
- });
- if (!m_isReset)
- dialog.ShowDialog();
- }
- protected virtual void OnProgressCancel(object sender, EventArgs e)
- {
- btnStopall_Click(null, null);
- }
- /// <summary>
- /// 出片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnOutloadstage_Click(object sender, EventArgs e)
- {
- m_Stage.Split(1);
- }
- /// <summary>
- /// 进片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnInloadstage_Click(object sender, EventArgs e)
- {
- m_Stage.Split(3);
- }
- /// <summary>
- /// 中心
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void btnCenterloadstage_Click(object sender, EventArgs e)
- {
- m_Stage.ToCenter();
- }
- /// <summary>
- /// 中心显示
- /// </summary>
- protected virtual void btnCenteDisplay_Click(object sender, EventArgs e)
- {
- m_isShowCenter = !m_isShowCenter;
- m_documentWorkspace.SetCenter(m_isShowCenter);
- if (m_isShowCenter)
- {
- (sender as Control).Text = PdnResources.GetString("Menu.Cancelcenter.text");
- }
- else
- {
- (sender as Control).Text = PdnResources.GetString("Menu.Centerdisplay.text");
- }
- }
- protected virtual void DepthMerge() { }
- #endregion
- protected virtual void txtStep_Leave(object sender, EventArgs e)
- {
- var tbx = sender as TextBox;
- if (string.IsNullOrEmpty(tbx.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Step-sizbeempty.text"));
- tbx.Text = "0";
- }
- }
- public void OnTimeoutConnect()
- {
- MessageBox.Show("平台连接超时");
- }
- public void OnErrorSend()
- {
- MessageBox.Show("平台连接异常");
- }
- #region Camera
- protected ICamera m_camera => CameraManager.CurrentCamera;
- protected CameraParamModel m_cameraParamModel;
- protected CameraConfigs m_cameraConfig;
- /// <summary>
- /// 当前拍摄图片
- /// </summary>
- protected Bitmap m_BitmapCurrent;
- public void UninitCamera()
- {
- CameraManager.FrameCallback += CallbackDraw;
- if (m_BitmapCurrent != null)
- {
- m_BitmapCurrent.Dispose();
- }
- }
- /// <summary>
- /// 窗体打开后初始化相机
- /// </summary>
- protected void InitializeCamera()
- {
- if (m_camera != null)
- {
- m_cameraConfig = CameraConfigs.GetInstance();
- m_cameraParamModel = m_cameraConfig.GetCurrentCameraParamModel();
- //m_cameraConfig.CameraParamInit();
- // 开启预览
- }
- CameraManager.FrameCallback += CallbackDraw;
- Thread.Sleep(100);//相机开启缓冲时间
- initCameraSetting();
- }
- protected virtual void initCameraSetting()
- {
- }
- object _lockobj = new object();
- public void CallbackDraw(Bitmap bitmap)
- {
- lock (_lockobj)
- {
- try
- {
- if (bitmap == null) return;
- VisionWidthPixel = bitmap.Width;
- VisionHeightPixel = bitmap.Height;
- m_documentWorkspace.CompositionSurface = null;
- if (bitmap.PixelFormat == PixelFormat.Format8bppIndexed)
- {
- var mat = PaintDotNet.Camera.Tools.ToMat(bitmap);
- m_documentWorkspace.Document = Document.FromMat(mat);
- }
- else
- {
- m_documentWorkspace.Document = Document.FromByteArr(bitmap.ToByteArray(), bitmap.Width, bitmap.Height);
- }
- m_BitmapCurrent = bitmap;
- }
- catch (Exception)
- {
- }
- }
- }
- #endregion
- private void timerStageUpdate_Tick(object sender, EventArgs e)
- {
- var x = Math.Round(m_Stage.X, 2);
- var y = Math.Round(m_Stage.Y, 2);
- var z = Math.Round(m_Stage.Z, 2);
- lblXPosition.Text = x.ToString();
- lblYPosition.Text = y.ToString();
- lblZPosition.Text = z.ToString();
- m_documentWorkspace.SetViewPoint(ConvertUMToPX(x), ConvertUMToPX(y));
- var distanceX = x - m_initStepX;
- var distanceY = y - m_initStepY;
- var distanceL = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);
- lblXDistance.Text = "X:" + distanceX.ToString("0");
- lblYDistance.Text = "Y:" + distanceY.ToString("0");
- lblLDistance.Text = "L:" + distanceL.ToString("0");
- }
- }
- }
|