12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205 |
- 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.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;
- using TUCAMAPI;
- using TUCamera;
- 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");
- 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");
- 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");
- 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;
- 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 TUCamera.TUCamera m_camera;
- protected CameraParamModel m_cameraParamModel;
- protected CameraConfigs m_cameraConfig;
- /// <summary>
- /// 当前拍摄图片
- /// </summary>
- protected Bitmap m_BitmapCurrent;
- public void UninitCamera()
- {
- if (m_camera != null)
- {
- m_camera.m_bufHandler -= CallbackDraw;
- m_camera.StopWaitForFrame();
- }
- if (m_BitmapCurrent != null)
- {
- m_BitmapCurrent.Dispose();
- }
- }
- /// <summary>
- /// 窗体打开后初始化相机
- /// </summary>
- protected void InitializeCamera()
- {
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- if (m_camera != null)
- {
- m_cameraConfig = CameraConfigs.GetInstance();
- m_cameraParamModel = m_cameraConfig.GetCurrentCameraParamModel();
- //m_cameraConfig.CameraParamInit();
- // 开启预览
- m_camera.m_bufHandler += CallbackDraw;
- m_camera.StartWaitForFrame();
- }
- Thread.Sleep(100);//相机开启缓冲时间
- initCameraSetting();
- }
- protected virtual void initCameraSetting()
- {
- }
- object _lockobj = new object();
- public void CallbackDraw(Bitmap bitmap)
- {
- lock (_lockobj)
- {
- try
- {
- VisionWidthPixel = bitmap.Width;
- VisionHeightPixel = bitmap.Height;
- m_documentWorkspace.CompositionSurface = null;
- if (bitmap.PixelFormat == PixelFormat.Format8bppIndexed)
- {
- var mat = BitmapConverter.ToMat(bitmap);
- m_documentWorkspace.Document = Document.FromByteArr(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");
- }
- }
- }
|