12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982 |
- using OpenCvSharp;
- using OpenCvSharp.Extensions;
- using OpenCvSharp.ImgHash;
- using PaintDotNet.Adjust;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.ImageCollect.CameraManager;
- using PaintDotNet.ImageCollect.CameraPreviewComponent;
- using PaintDotNet.ImageCollect.CameraPreviewComponent.Properties;
- using PaintDotNet.Instrument;
- using PaintDotNet.Measuring;
- using PaintDotNet.Menus;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.SystemLayer;
- using StageController;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Windows.Forms;
- using TUCAMAPI;
- using TUCamera;
- using PaintDotNet.Adjust.BaseImage;
- using PaintDotNet.Annotation.Measure;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation;
- using Point = System.Drawing.Point;
- using StageController.M3H;
- using System.Threading.Tasks;
- using System.Linq;
- using Metis.AutoAnalysis;
- namespace PaintDotNet.ImageCollect
- {
- internal class CameraPreviewDialog : FloatingToolForm, IStageEvent
- {
- /// <summary>
- /// [原图取色]设置是否生效
- /// </summary>
- public bool o_use = false;
- //private Bitmap m_bitmat;
- ////private Mat m_mat; // [区域选择]白平衡结果存储
- /// <summary>
- /// [区域选择]设置是否生效(,设置到相机)
- /// </summary>
- public bool m_use = false;
- public Point m_startP; //画框的起始点
- private bool m_blnDraw = false;
- private Rectangle m_rect;//初始设置一个拖拽的显示框
- SolidBrush m_brush = new SolidBrush(Color.Black);
- int m_handle = 0;
- public bool isLeave = false;//鼠标是否离开窗体
- public static CameraPreviewDialog cameraPreviewDialog;
- private AppWorkspace appWorkspace;
- public DocumentWorkspaceWindow documentWorkspace;
- private GroupBox groupBox2;
- private GroupBox groupBox3;
- private GroupBox groupBox4;
- private ProgressBar progressBar1;
- private Button btnRestStep;
- public ComboBox comboBox1;
- private Panel panel1;
- private Panel panel2;
- private GroupBox groupBox1;
- private Panel panel3;
- private BaseActionsStrip baseActionsStrip;
- private ShootActionsStrip shootActionsStrip;
- private TheoreticalScaleStrip theoreticalScaleStrip;
- //private Mat m_mat;
- public static Mat m_matClone;
- public static Mat m_matOrig;
- private Document document;
- private ComboBox cmbConfigs;
- private Button btnConfigDel;
- private TextBox gainNumbertxt;
- private string picturePath = Application.StartupPath + "\\Picture\\";
- /// <summary>
- /// 显示图像
- /// </summary>
- private TUCamera.TUCamera m_camera;
- private CameraParamModel m_cameraParamModel;
- private CameraConfigs m_cameraConfig;
- private AxisController m_Stage;
- PropertiesSettingDialog fmSetting;
- private bool maxAndMinButtonEnable = false;//最大最小按钮点击状态
- private bool bestButtonEnable = false;//最佳按钮点击状态
- private bool gamma45ButtonEnable = false;//伽马45按钮点击状态
- private int trackBar1Value = -50;//亮度
- private int trackBar2Value = 100;//对比度
- private int trackBar3Value = 100;//gamma值
- //用法为:
- //label5.Text = (trackBar1.Value / 100.0).ToString("f2");
- //label6.Text = (trackBar2.Value / 100.0).ToString("f2");
- //label7.Text = (trackBar3.Value / 100.0).ToString("f2");
- private bool underexposedButtonEnable = false;//曝光不足按钮点击状态
- private bool overexposedButton = false;//过曝光按钮点击状态
- private double micronRatio;//每像素多少微米
- private CheckBox checkBox1;
- private bool isFitToWindow = false;//辅助判断当前尺寸是否为适应大小
- private TheoreticalScaleDialog theoreticalScaleDialog;//理论比例尺窗口
- private Dictionary<string, mic_rulers> micRulersDictonary;//标尺下拉菜单绑定数据
- private BindingSource bs;//绑定combobox的数据源
- private System.Windows.Forms.Timer tmrUpdate;
- private System.ComponentModel.IContainer components;
- private Panel panelZ;
- private Label lblZPos;
- private Button btnZClear;
- private Button btuZDown;
- private Button btnZUp;
- private NumericUpDown numZLen;
- /// <summary>
- /// 预览属性
- /// </summary>
- // ScriptEditDialog histogramDialog;
- //public bool comboBox_Change = false;
- public string comboBox_Value = string.Empty;
- public CameraPreviewDialog(AppWorkspace appWorkspace)
- {
- cameraPreviewDialog = this;
- this.DoubleBuffered = true;//设置本窗体
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- SetStyle(ControlStyles.UserPaint, true);
- SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
- SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
- this.appWorkspace = appWorkspace;
- this.appWorkspace.cameraPreviewDialog = this;
- this.Text = PdnResources.GetString("Menu.ImageCollection.PreviewExtraction.Text");
- //this.FormBorderStyle = FormBorderStyle.FixedSingle;
- this.MinimizeBox = false;
- this.MaximizeBox = true;
- m_cameraParamModel = Startup.instance.cameraParamModel;
- m_cameraConfig = CameraConfigs.GetInstance();
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- m_camera.m_bufHandler += CallbackDraw;
- m_camera.StartWaitForFrame();
- // BIN
- if (m_camera.IsSupportBinng())
- {
- //m_camera.SetBinningSum((BinningSum)m_cameraParamModel.parame.BinningSumation);
- }
- InitStage();
- InitializeComponent();
- InitializeLanguageText();
- InitializeBaseTool();
- InitializeShootTool();
- InitializeTheoreticalScaleStripTool();
- // 加载配置文件列表
- initCmbConfigs();
- InitializeImage();
- // 分辨率 非2448 * 2048的时, ROI在StartWaitForFrame后设置
- if (m_camera.GetResolutionId() != 0)
- {
- }
- //m_showThread = new Thread(new ThreadStart(ShowFrameThreadEntry));
- //m_showThread.IsBackground = true;
- // m_showThread.Start();
- this.Resize += new EventHandler(Form_Resize);
- BindingRule();
- getRulerMicronRatio();//计算每像素多少微米
- this.MinimumSize = new System.Drawing.Size(748, 656);//设置窗口最小尺寸
- comboBox_Value = comboBox1.Text;//获取下拉值
- CurrentImage = () => { return BitmapConverter.ToBitmap(m_matClone); };
- }
- private void InitStage()
- {
- try
- {
- m_Stage = AxisController.GetInstance();
- m_Stage.AddApp(this);
- }
- catch { }
- }
- /// <summary>
- /// 绑定标尺
- /// </summary>
- public void BindingRule()
- {
- this.comboBox1.Items.Clear();
- //绑定标尺下拉菜单
- List<mic_rulers> list = Startup.instance.mic_rulersAll;
- string rulerName = "";
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- int rulid = rule.id;
- if (rulid == Startup.instance.configModel.RulerId)
- {
- rulerName = rule.ruler_name;
- }
- this.comboBox1.Items.Add(rule.ruler_name);
- }
- }
- for (int i = 0; i < this.comboBox1.Items.Count; i++)
- {
- if (rulerName.Equals(this.comboBox1.Items[i].ToString()))
- {
- this.comboBox1.SelectedIndex = i;
- }
- }
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void InitializeData()
- {
- m_cameraParamModel = Startup.instance.cameraParamModel;
- m_cameraConfig.CameraParamInit();
- }
- /// <summary>
- /// 加载配置文件列表
- /// </summary>
- public void initCmbConfigs()
- {
- string selected = "";
- this.cmbConfigs.Items.Clear();
- List<string> fileNames = CameraConfigs.GetInstance().GetAllConfigFiles();
- foreach (string fileName in fileNames)
- {
- this.cmbConfigs.Items.Add(fileName);
- if (fileName.Equals(CameraConfigs.GetInstance().CurrentConfigFileName))
- {
- selected = fileName;
- }
- }
- if (selected.Equals("") && fileNames.Count > 0)
- {
- selected = fileNames[0];
- }
- this.cmbConfigs.SelectedItem = selected;
- }
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Ruler.text");
- this.checkBox1.Text = PdnResources.GetString("Menu.imagecapture.Previewwindow.Shootingruler.text");
- this.groupBox4.Text = PdnResources.GetString("Menu.ImageCollection.CameraSetting.Text");
- this.btnRestStep.Text = PdnResources.GetString("Menu.reset.Text");
- }
- /// <summary>
- /// 实例化预览窗口同期组件
- /// </summary>
- public void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.panel2 = new System.Windows.Forms.Panel();
- this.panel1 = new System.Windows.Forms.Panel();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.panelZ = new System.Windows.Forms.Panel();
- this.lblZPos = new System.Windows.Forms.Label();
- this.btnZClear = new System.Windows.Forms.Button();
- this.btuZDown = new System.Windows.Forms.Button();
- this.btnZUp = new System.Windows.Forms.Button();
- this.numZLen = new System.Windows.Forms.NumericUpDown();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.panel3 = new System.Windows.Forms.Panel();
- this.checkBox1 = new System.Windows.Forms.CheckBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.btnConfigDel = new System.Windows.Forms.Button();
- this.cmbConfigs = new System.Windows.Forms.ComboBox();
- this.progressBar1 = new System.Windows.Forms.ProgressBar();
- this.btnRestStep = new System.Windows.Forms.Button();
- this.tmrUpdate = new System.Windows.Forms.Timer(this.components);
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.panelZ.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numZLen)).BeginInit();
- this.groupBox3.SuspendLayout();
- this.groupBox4.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.panel2);
- this.groupBox1.Controls.Add(this.panel1);
- this.groupBox1.Location = new System.Drawing.Point(20, 20);
- this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox1.Size = new System.Drawing.Size(1060, 662);
- this.groupBox1.TabIndex = 1;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "预览";
- //
- // panel2
- //
- this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel2.Location = new System.Drawing.Point(10, 32);
- this.panel2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(1026, 552);
- this.panel2.TabIndex = 2;
- //
- // panel1
- //
- this.panel1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
- this.panel1.Location = new System.Drawing.Point(10, 592);
- this.panel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(1026, 60);
- this.panel1.TabIndex = 1;
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.panelZ);
- this.groupBox2.Location = new System.Drawing.Point(20, 690);
- this.groupBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox2.Size = new System.Drawing.Size(1060, 82);
- this.groupBox2.TabIndex = 2;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "操作";
- //
- // panelZ
- //
- this.panelZ.Controls.Add(this.lblZPos);
- this.panelZ.Controls.Add(this.btnZClear);
- this.panelZ.Controls.Add(this.btuZDown);
- this.panelZ.Controls.Add(this.btnZUp);
- this.panelZ.Controls.Add(this.numZLen);
- this.panelZ.Dock = System.Windows.Forms.DockStyle.Right;
- this.panelZ.Location = new System.Drawing.Point(765, 25);
- this.panelZ.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.panelZ.Name = "panelZ";
- this.panelZ.Size = new System.Drawing.Size(291, 53);
- this.panelZ.TabIndex = 0;
- this.panelZ.Visible = false;
- //
- // lblZPos
- //
- this.lblZPos.BackColor = System.Drawing.SystemColors.ButtonHighlight;
- this.lblZPos.Dock = System.Windows.Forms.DockStyle.Fill;
- this.lblZPos.Location = new System.Drawing.Point(198, 0);
- this.lblZPos.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
- this.lblZPos.Name = "lblZPos";
- this.lblZPos.Size = new System.Drawing.Size(93, 53);
- this.lblZPos.TabIndex = 3;
- this.lblZPos.Text = "0000";
- this.lblZPos.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // btnZClear
- //
- this.btnZClear.Dock = System.Windows.Forms.DockStyle.Left;
- this.btnZClear.Location = new System.Drawing.Point(150, 0);
- this.btnZClear.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.btnZClear.Name = "btnZClear";
- this.btnZClear.Size = new System.Drawing.Size(48, 53);
- this.btnZClear.TabIndex = 2;
- this.btnZClear.Text = "C";
- this.btnZClear.UseVisualStyleBackColor = true;
- this.btnZClear.Click += new System.EventHandler(this.btnZClear_Click);
- //
- // btuZDown
- //
- this.btuZDown.Dock = System.Windows.Forms.DockStyle.Left;
- this.btuZDown.Location = new System.Drawing.Point(102, 0);
- this.btuZDown.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.btuZDown.Name = "btuZDown";
- this.btuZDown.Size = new System.Drawing.Size(48, 53);
- this.btuZDown.TabIndex = 1;
- this.btuZDown.Text = "↓";
- this.btuZDown.UseVisualStyleBackColor = true;
- this.btuZDown.Click += new System.EventHandler(this.btuZDown_Click);
- //
- // btnZUp
- //
- this.btnZUp.Dock = System.Windows.Forms.DockStyle.Left;
- this.btnZUp.Location = new System.Drawing.Point(57, 0);
- this.btnZUp.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.btnZUp.Name = "btnZUp";
- this.btnZUp.Size = new System.Drawing.Size(45, 53);
- this.btnZUp.TabIndex = 0;
- this.btnZUp.Text = "↑";
- this.btnZUp.UseVisualStyleBackColor = true;
- this.btnZUp.Click += new System.EventHandler(this.btnZUp_Click);
- //
- // numZLen
- //
- this.numZLen.Dock = System.Windows.Forms.DockStyle.Left;
- this.numZLen.Font = new System.Drawing.Font("Calibri", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.numZLen.Location = new System.Drawing.Point(0, 0);
- this.numZLen.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.numZLen.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numZLen.Name = "numZLen";
- this.numZLen.Size = new System.Drawing.Size(57, 33);
- this.numZLen.TabIndex = 4;
- this.numZLen.Value = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- //
- // groupBox3
- //
- this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox3.Controls.Add(this.panel3);
- this.groupBox3.Controls.Add(this.checkBox1);
- this.groupBox3.Controls.Add(this.comboBox1);
- this.groupBox3.Location = new System.Drawing.Point(20, 783);
- this.groupBox3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox3.Size = new System.Drawing.Size(662, 82);
- this.groupBox3.TabIndex = 3;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "标尺";
- //
- // panel3
- //
- this.panel3.BackColor = System.Drawing.Color.Transparent;
- this.panel3.Location = new System.Drawing.Point(435, 28);
- this.panel3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(166, 36);
- this.panel3.TabIndex = 2;
- //
- // checkBox1
- //
- this.checkBox1.AutoSize = true;
- this.checkBox1.Location = new System.Drawing.Point(288, 36);
- this.checkBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(106, 22);
- this.checkBox1.TabIndex = 1;
- this.checkBox1.Text = "拍摄标尺";
- this.checkBox1.UseVisualStyleBackColor = true;
- this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click);
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(10, 32);
- this.comboBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(226, 26);
- this.comboBox1.TabIndex = 0;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted);
- //
- // groupBox4
- //
- this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox4.Controls.Add(this.btnConfigDel);
- this.groupBox4.Controls.Add(this.cmbConfigs);
- this.groupBox4.Location = new System.Drawing.Point(690, 783);
- this.groupBox4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.groupBox4.Size = new System.Drawing.Size(390, 82);
- this.groupBox4.TabIndex = 4;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "相机设置";
- //
- // btnConfigDel
- //
- this.btnConfigDel.Location = new System.Drawing.Point(320, 30);
- this.btnConfigDel.Name = "btnConfigDel";
- this.btnConfigDel.Size = new System.Drawing.Size(46, 27);
- this.btnConfigDel.TabIndex = 1;
- this.btnConfigDel.Text = "Del";
- this.btnConfigDel.UseVisualStyleBackColor = true;
- this.btnConfigDel.Click += new System.EventHandler(this.btnConfigDel_Click);
- //
- // cmbConfigs
- //
- this.cmbConfigs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbConfigs.FormattingEnabled = true;
- this.cmbConfigs.Location = new System.Drawing.Point(15, 32);
- this.cmbConfigs.Name = "cmbConfigs";
- this.cmbConfigs.Size = new System.Drawing.Size(276, 26);
- this.cmbConfigs.TabIndex = 0;
- this.cmbConfigs.SelectedIndexChanged += new System.EventHandler(this.cmbConfigs_SelectedIndexChanged);
- //
- // progressBar1
- //
- this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.progressBar1.Location = new System.Drawing.Point(20, 876);
- this.progressBar1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.progressBar1.Name = "progressBar1";
- this.progressBar1.Size = new System.Drawing.Size(962, 34);
- this.progressBar1.TabIndex = 5;
- //
- // btnRestStep
- //
- this.btnRestStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.btnRestStep.Location = new System.Drawing.Point(992, 876);
- this.btnRestStep.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
- this.btnRestStep.Name = "btnRestStep";
- this.btnRestStep.Size = new System.Drawing.Size(88, 34);
- this.btnRestStep.TabIndex = 6;
- this.btnRestStep.Text = "复位";
- this.btnRestStep.UseVisualStyleBackColor = true;
- this.btnRestStep.Click += new System.EventHandler(this.btnRestStep_Click);
- //
- // tmrUpdate
- //
- this.tmrUpdate.Interval = 1000;
- this.tmrUpdate.Tick += new System.EventHandler(this.tmrUpdate_Tick);
- //
- // CameraPreviewDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
- this.ClientSize = new System.Drawing.Size(1098, 927);
- this.Controls.Add(this.btnRestStep);
- this.Controls.Add(this.progressBar1);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
- this.Name = "CameraPreviewDialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraPreviewDialog_FormClosing);
- this.Load += new System.EventHandler(this.CameraPreviewDialog_Load);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.Controls.SetChildIndex(this.progressBar1, 0);
- this.Controls.SetChildIndex(this.btnRestStep, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.panelZ.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.numZLen)).EndInit();
- this.groupBox3.ResumeLayout(false);
- this.groupBox3.PerformLayout();
- this.groupBox4.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- public void InitializeImage()
- {
- m_rect = new Rectangle();
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.panel.MouseDown += DocumentWorkspace_MouseDown;
- this.documentWorkspace.panel.MouseMove += PictureBox1_MouseMove;
- this.documentWorkspace.panel.MouseUp += PictureBox1_MouseUp;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.refueshZoomTrackValue = false;
- Bitmap bitmap = new Bitmap(m_cameraParamModel.parame.previewRectW, m_cameraParamModel.parame.previewRectH);
- document = Document.FromImage(bitmap);
- //if (bitmap.Width > 3 && bitmap.Height > 3)
- //{
- // m_rect.X = Math.Min(10, bitmap.Width / 2 - 1);
- // m_rect.Y = Math.Min(10, bitmap.Height / 2 - 1);
- // m_rect.Width = bitmap.Width - 2 * m_rect.X;
- // m_rect.Height = bitmap.Height - 2 * m_rect.Y;
- // Console.WriteLine(m_rect);
- //}
- //else
- {
- m_rect.X = 0;
- m_rect.Y = 0;
- m_rect.Width = 0;
- m_rect.Height = 0;
- }
- this.documentWorkspace.AppWorkspaceTop = this.appWorkspace;
- this.documentWorkspace.Visible = true;
- //this.documentWorkspace.PanelBottom.Visible = false;
- this.documentWorkspace.Dock = DockStyle.Fill;
- //this.documentWorkspace.RulersEnabled = true;
- this.panel2.Controls.Add(this.documentWorkspace);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.ScaleFactorChanged += new EventHandler(DocumentWorkspace_ScaleFactorChanged);
- if (this.documentWorkspace.oldDrawTreeView == null && MeasureListDialog.drawNodes != null)
- {
- this.documentWorkspace.oldDrawTreeView = MeasureListDialog.drawNodes;
- //this.documentWorkspace.previewMeasure = true;
- this.documentWorkspace.rules = Startup.instance.rules;
- }
- }
- private void Panel_Paint(object sender, PaintEventArgs e)
- {
- if (m_use && documentWorkspace.CompositionSurface.Width != 0 && documentWorkspace.CompositionSurface.Height != 0)
- {
- if (m_rect.Width > 0 && m_rect.Height > 0)
- {
- //
- // 以下是计算绘制图片的位置和大小并绘制图片
- //
- Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
- int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
- int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
- int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
- int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
- //if (m_mat != null)
- //{
- // oldMPatch.Dispose();
- // oldMPatch = m_mat;
- //}
- //m_mat = new Data.Action.Action5012().PerformProcess(BitmapConverter.ToMat(m_bitmap).Clone(new Rect(m_rect.X, m_rect.Y, m_rect.Width, m_rect.Height)));
- ////
- //// 以下是绘制网格、标注、测量、视场等开始
- ////
- e.Graphics.TranslateTransform(x, y);
- e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
- //if (m_bitmat != null)
- //{
- // e.Graphics.DrawImage(m_bitmat, m_rect.X, m_rect.Y, m_rect.Width, m_rect.Height);
- //}
- if (!m_blnDraw)
- {
- e.Graphics.DrawRectangle(new Pen(Color.Black/*Red*/, 2), m_rect);//重新绘制颜色为红色
- for (int i = 1; i <= 8; i++)
- {
- e.Graphics.FillRectangle(m_brush, GetHandleRectangle(i));
- }
- }
- e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
- e.Graphics.TranslateTransform(-x, -y);
- }
- }
- else
- {
- m_rect.Width = 0;
- m_rect.Height = 0;
- }
- }
- private void DocumentWorkspace_MouseDown(object sender, MouseEventArgs e)
- {
- if (!m_use && !o_use)
- return;
- // 换算后的点
- Point point1 = documentWorkspace.GetScalePoint(e.Location);//PointF
- m_handle = HitTest(point1);
- if (m_handle < 0)
- {
- if (m_rect.Contains(point1))//判断鼠标按下的坐标是否在红框中,确定是否拖动的红框
- {
- m_handle = 9;
- }
- }
- this.Cursor = GetHandleCursor(m_handle);
- m_startP = point1;
- Invalidate();
- m_blnDraw = true;
- }
- private void PictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- if (!m_use)
- return;
- if (m_handle > 0 ||/*&&*/ m_blnDraw)
- {
- if (e.Button != MouseButtons.Left)//判断是否按下左键
- return;
- MoveHandleTo(documentWorkspace.GetScalePoint(e.Location), m_handle);
- }
- }
- private void PictureBox1_MouseUp(object sender, MouseEventArgs e)
- {
- if (!m_use)
- return;
- m_blnDraw = false; //结束绘制
- this.Cursor = Cursors.Default;
- SetROI();
- this.documentWorkspace/*pictureBox1*/.Refresh();
- }
- private void SetROI()
- {
- if (m_use)
- {
- //m_camera.SetROI(ref m_targetX, ref m_targetY, ref m_targetWidth, ref m_targetHeight);
- //this.m_cameraParamModel.parame.previewRectX = m_targetX;
- //this.m_cameraParamModel.parame.previewRectY = m_targetY;
- //this.m_cameraParamModel.parame.previewRectW = m_targetWidth;
- //this.m_cameraParamModel.parame.previewRectH = m_targetHeight;
- }
- }
- public Rectangle GetHandleRectangle(int handleNumber)
- {
- Point point = GetHandle(handleNumber);
- return new Rectangle(point.X - 4, point.Y - 4, 8, 8);
- }
- public int HitTest(Point point)
- {
- for (int i = 1; i <= 8; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- return i;
- }
- return -1;
- }
- public Point GetHandle(int handleNumber)
- {
- int x, y, xCenter, yCenter;
- xCenter = m_rect.X + m_rect.Width / 2;
- yCenter = m_rect.Y + m_rect.Height / 2;
- x = m_rect.X;
- y = m_rect.Y;
- switch (handleNumber)
- {
- case 1:
- x = m_rect.X;
- y = m_rect.Y;
- break;
- case 2:
- x = xCenter;
- y = m_rect.Y;
- break;
- case 3:
- x = m_rect.Right;
- y = m_rect.Y;
- break;
- case 4:
- x = m_rect.Right;
- y = yCenter;
- break;
- case 5:
- x = m_rect.Right;
- y = m_rect.Bottom;
- break;
- case 6:
- x = xCenter;
- y = m_rect.Bottom;
- break;
- case 7:
- x = m_rect.X;
- y = m_rect.Bottom;
- break;
- case 8:
- x = m_rect.X;
- y = yCenter;
- break;
- }
- return new Point(x, y);
- }
- public Cursor GetHandleCursor(int handleNumber)
- {
- switch (handleNumber)
- {
- case 1:
- return Cursors.SizeNWSE;
- case 2:
- return Cursors.SizeNS;
- case 3:
- return Cursors.SizeNESW;
- case 4:
- return Cursors.SizeWE;
- case 5:
- return Cursors.SizeNWSE;
- case 6:
- return Cursors.SizeNS;
- case 7:
- return Cursors.SizeNESW;
- case 8:
- return Cursors.SizeWE;
- default:
- return Cursors.Default;
- }
- }
- public void MoveHandleTo(Point point, int handleNumber)
- {
- if (point.X > this.documentWorkspace.CompositionSurface/*pictureBox1*/.Width)
- {
- point.X = documentWorkspace.CompositionSurface/*pictureBox1*/.Width;
- }
- if (point.X < 0)
- {
- point.X = 0;
- }
- if (point.Y < 0)
- {
- point.Y = 0;
- }
- if (point.Y > documentWorkspace.CompositionSurface/*pictureBox1*/.Height)
- {
- point.Y = documentWorkspace.CompositionSurface/*pictureBox1*/.Height;
- }
- Point point1 = new Point(m_startP.X, m_startP.Y);
- if (point1.X > this.documentWorkspace.CompositionSurface/*pictureBox1*/.Width)
- {
- point1.X = documentWorkspace.CompositionSurface/*pictureBox1*/.Width;
- }
- if (point1.X < 0)
- {
- point1.X = 0;
- }
- if (point1.Y < 0)
- {
- point1.Y = 0;
- }
- if (point1.Y > documentWorkspace.CompositionSurface/*pictureBox1*/.Height)
- {
- point1.Y = documentWorkspace.CompositionSurface/*pictureBox1*/.Height;
- }
- m_rect.X = Math.Min(point.X, point1.X);
- m_rect.Y = Math.Min(point.Y, point1.Y);
- m_rect.Width = Math.Abs(point.X - point1.X);
- m_rect.Height = Math.Abs(point.Y - point1.Y);
- return;
- }
- /// <summary>
- /// 接收相机frame
- /// </summary>
- /// <param name="frame"></param>
- /// <param name="obj"></param>
- public void CallbackDraw(Bitmap bitmap)
- {
- try
- {
- var mat = BitmapConverter.ToMat(bitmap);
- m_matClone = mat.Clone();
- if (!this.IsShown)
- {
- return;
- }
- if (fmSetting != null)
- {
- m_matOrig = mat.Clone();
- try
- {
- trackBar1Value = fmSetting.displayCameraControl.trackBar1Value;
- trackBar2Value = fmSetting.displayCameraControl.trackBar2Value;
- trackBar3Value = fmSetting.displayCameraControl.trackBar3Value;
- }
- catch (Exception e)
- {
- System.Console.WriteLine("nullException can be catched here:" + e.Message);
- }
- }
- if (trackBar1Value != -50 || trackBar2Value != 100 || trackBar3Value != 100)
- {
- mat = PaintDotNet.Setting.LabelComponent.DisplayCameraControl.scrollMethod(mat, (trackBar1Value / 100.0).ToString("f2"), (trackBar2Value / 100.0).ToString("f2"), (trackBar3Value / 100.0).ToString("f2"));
- }
- else if (bestButtonEnable || maxAndMinButtonEnable || gamma45ButtonEnable)
- {
- if (bestButtonEnable)//最佳
- mat = AdjustIntent.CalHistMethod(mat, 1, gamma45ButtonEnable);
- if (maxAndMinButtonEnable)//最大最小
- mat = AdjustIntent.CalHistMethod(mat, 2, gamma45ButtonEnable);
- if (!bestButtonEnable && !maxAndMinButtonEnable)//仅伽马0.45
- mat = AdjustIntent.CalHistMethod(mat, 0, gamma45ButtonEnable);
- }
- if (underexposedButtonEnable)//曝光不足
- mat = ExposedIntent.UnderExposed(mat, 30, 0.5f);
- if (overexposedButton)//过曝光
- mat = ExposedIntent.OverExposed(mat, 225, 0.5f);
- //17461
- if (m_cameraParamModel.parame.ShadingCorrection == 1)//阴影矫正
- mat = AdjustIntent.ShadingCorrection(mat);
- ShowFrameThreadEntry(mat);
- //this.appWorkspace.UpdatePixelTracking(mat.Clone());
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- private void ShowFrameThreadEntry(Mat matClone)
- {
- try
- {
- Bitmap m_bitmap = BitmapConverter.ToBitmap(matClone);
- if (o_use && m_startP.X >= 0 && m_startP.Y >= 0)
- {
- int x = m_startP.X;
- int y = m_startP.Y;
- if (x >= 0 && y >= 0 && x < m_bitmap.Width && y < m_bitmap.Height)
- {
- OpenCvSharp.Mat srt = OpenCvSharp.Extensions.BitmapConverter.ToMat(m_bitmap);
- OpenCvSharp.Vec3b bgr = srt.At<OpenCvSharp.Vec3b>(y, x);
- Color color = Color.FromArgb(bgr[2], bgr[1], bgr[0]);
- /// <summary>
- /// 当前处理的程序
- /// </summary>
- Data.Param.ParamObject action = new Data.Action.Action5012();
- //重新初始化选项列表
- Base.Args args = action.Lists[0];
- args.value = 3;
- for (int j = 0; j < args.choiseList.Count; j++)
- {
- Data.Param.BooleanObject argsChoise = args.choiseList[j] as Data.Param.BooleanObject;
- if (argsChoise.Lists.Count > 0)
- {
- Data.Param.ColorNumber phaseColor = argsChoise.Lists[0] as Data.Param.ColorNumber;
- if (phaseColor.Key.Equals("imageColor"))//原图取色
- {
- phaseColor.Value = color.ToArgb();// this.panel3.BackColor.ToArgb();
- }
- }
- }
- OpenCvSharp.Mat mat = action.PerformProcess(srt);
- //string filename2 = "E:\\show1" + (misshow++) + ".jpg";
- //Cv2.ImWrite(filename2, mat);
- this.documentWorkspace.Document = Document.FromByteArr(mat);
- }
- }
- else if (m_use && m_rect.Width > 0 && m_rect.Height > 0)
- {
- Mat m_mat = new Data.Action.Action5012().PerformProcess(matClone.Clone(new Rect(m_rect.X, m_rect.Y, m_rect.Width, m_rect.Height)));
- //复制用户选中的区域到原图像
- //Mat mask0 = m_matClone.CvtColor(ColorConversionCodes.RGBA2GRAY);
- Mat pos0 = new Mat(matClone, new Rect(m_rect.X, m_rect.Y, m_rect.Width, m_rect.Height));
- m_mat.CopyTo(pos0, m_mat);
- this.documentWorkspace.Document = Document.FromImage(BitmapConverter.ToBitmap(matClone));
- m_mat.Dispose();
- }
- else
- this.documentWorkspace.Document = Document.FromByteArr(matClone/*BitmapConverter.ToBitmap(m_matClone)*/);
- if (fmSetting != null && m_matOrig != null)
- {
- this.BeginInvoke(new Action(() => { fmSetting?.resetMat(m_matOrig); }));
- }
- }
- catch (Exception)
- {
- }
- }
- /// <summary>
- /// 初始化基础工具
- /// </summary>
- public void InitializeBaseTool()
- {
- this.baseActionsStrip = new BaseActionsStrip();
- //十字线按钮点击
- this.baseActionsStrip.crossButton.Click += new System.EventHandler(this.crossButton_Click);
- //网格按钮点击
- this.baseActionsStrip.gridButton.Click += new System.EventHandler(this.gridButton_Click);
- //方形按钮点击
- this.baseActionsStrip.squareButton.Click += new System.EventHandler(this.squareButton_Click);
- //圆形按钮点击
- this.baseActionsStrip.roundButton.Click += new System.EventHandler(this.roundButton_Click);
- //实际大小按钮点击
- this.baseActionsStrip.actualSizeButton.Click += new System.EventHandler(this.actualSizeButton_Click);
- //合适大小按钮点击
- this.baseActionsStrip.zoomToWindowButton.Click += new System.EventHandler(this.zoomToWindowButton_Click);
- //全屏按钮点击
- this.baseActionsStrip.fullScreenButton.Click += new System.EventHandler(this.fullScreenButton_Click);
- //缩小按钮点击
- this.baseActionsStrip.zoomOutButton.Click += new System.EventHandler(this.zoomOutButton_Click);
- //放大按钮点击
- this.baseActionsStrip.zoomInButton.Click += new System.EventHandler(this.zoomInButton_Click);
- this.baseActionsStrip.GripStyle = ToolStripGripStyle.Hidden;
- this.baseActionsStrip.Dock = DockStyle.None;
- this.baseActionsStrip.Location = new System.Drawing.Point(136, 0);
- this.panel1.Controls.Add(baseActionsStrip);
- this.gainNumbertxt = new TextBox();
- this.gainNumbertxt.Location = new System.Drawing.Point(554, 8);
- this.gainNumbertxt.Size = new System.Drawing.Size(62, 22);
- this.gainNumbertxt.Anchor = AnchorStyles.Left;
- this.gainNumbertxt.Text = PdnResources.GetString("Menu.nothing.Text");
- this.gainNumbertxt.ReadOnly = true;
- this.panel1.Controls.Add(this.gainNumbertxt);
- }
- /// <summary>
- /// 初始化快捷工具
- /// </summary>
- public void InitializeShootTool()
- {
- this.shootActionsStrip = new ShootActionsStrip();
- //拍摄按钮点击
- this.shootActionsStrip.shootButton.Click += new System.EventHandler(this.camera_Click);
- //单次拍摄按钮点击
- this.shootActionsStrip.aloneShootButton.Click += new System.EventHandler(this.aloneShootButton_Click);
- //速度按钮点击
- this.shootActionsStrip.speedButton.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(CopyDetail_DropDownItemClicked);
- //曝光时间点击事件
- this.shootActionsStrip.exposureTimeButton.Click += new System.EventHandler(this.exposureTimeButton_Click);
- //白平衡点击事件
- this.shootActionsStrip.whiteBalanceButton.Click += new System.EventHandler(this.whiteBalance_Click);
- //最佳点击事件
- this.shootActionsStrip.bestButton.Click += new System.EventHandler(this.bestButton_Click);
- //最小最大点击事件
- this.shootActionsStrip.maxAndMinButton.Click += new System.EventHandler(this.maxAndMinButton_Click);
- //原始状态事件
- this.shootActionsStrip.originalStateButton.Click += new System.EventHandler(this.originalStateButton_Click);
- //伽马0.45事件
- this.shootActionsStrip.gamma45Button.Click += new System.EventHandler(this.gamma45Button_Click);
- //曝光不足事件
- this.shootActionsStrip.underexposedButton.Click += new System.EventHandler(this.underexposedButton_Click);
- //过曝光事件
- this.shootActionsStrip.overexposedButton.Click += new System.EventHandler(this.overexposedButton_Click);
- //预览属性事件
- this.shootActionsStrip.propertiesButton.Click += new System.EventHandler(this.propertiesButton_Click);
- //自动聚焦事件
- this.shootActionsStrip.autoFocusButton.Click += new System.EventHandler(this.autoFocusButton_Click);
- this.shootActionsStrip.GripStyle = ToolStripGripStyle.Hidden;
- shootActionsStrip.Dock = DockStyle.Fill;
- this.groupBox2.Controls.Add(this.shootActionsStrip);
- }
- /// <summary>
- /// 理论比例尺初始化
- /// </summary>
- private void InitializeTheoreticalScaleStripTool()
- {
- this.theoreticalScaleStrip = new TheoreticalScaleStrip();
- this.theoreticalScaleStrip.theoreticalScaleButton.Click += new System.EventHandler(this.theoreticalScaleButton_Click);
- this.theoreticalScaleStrip.GripStyle = ToolStripGripStyle.Hidden;
- this.theoreticalScaleStrip.Dock = DockStyle.None;
- this.theoreticalScaleStrip.BackColor = Color.Transparent;
- this.panel3.Controls.Add(theoreticalScaleStrip);
- }
- /// <summary>
- /// 拍照按钮被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void camera_Click(object sender, EventArgs e)
- {
- Capture1();
- }
- /// <summary>
- /// 单次拍摄被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void aloneShootButton_Click(object sender, EventArgs e)
- {
- Capture1();
- this.Close();
- }
- public void Capture1()
- {
- var bitmap = documentWorkspace.CompositionSurface.CreateAliasedBitmap();
- var mode = Startup.instance.configModel.CaptureSaveMode;
- var r = appWorkspace.DisplayShoot(bitmap, this.documentWorkspace.GraphicsList, Startup.instance.configModel.CaptureHasRoler, mode);
- if (!r) return;
- }
- /// <summary>
- /// 白平衡点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void whiteBalance_Click(object sender, EventArgs e)
- {
- m_camera.SetWhiteBalanceMode(WhiteBalanceMode.AUTO);
- }
- /// <summary>
- /// 速度点击
- /// </summary>
- void CopyDetail_DropDownItemClicked(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e)
- {
- foreach (ToolStripMenuItem item in shootActionsStrip.speedButton.DropDownItems)
- {
- if (item.Name != e.ClickedItem.Name)
- {
- item.Checked = false;
- }
- else
- {
- item.Checked = true;
- this.shootActionsStrip.speedButton.Text = e.ClickedItem.Text;
- }
- }
- }
- /// <summary>
- /// 曝光时间被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void exposureTimeButton_Click(object sender, EventArgs e)
- {
- m_camera.SetExposureMode(ExposureMode.AUTO);
- }
- /// <summary>
- /// 最佳被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void bestButton_Click(object sender, EventArgs e)
- {
- if (this.shootActionsStrip == null || this.shootActionsStrip.bestButton == null)
- return;
- // TUCamAPI.TUCAM_Capa_SetValue(m5pro.m_opCamList[m5pro.m_indexCam].hIdxTUCam, (int)TUCAM_IDCAPA.TUIDC_ATEXPOSURE_MODE, 0);
- // TUCamAPI.TUCAM_Prop_SetValue(m5pro.m_opCamList[m5pro.m_indexCam].hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_EXPOSURETM, (double)(20000000 / 1000.0f), 0);
- //MessageBox.Show("临时调整曝光时长为20000000us");
- bestButtonEnable = !bestButtonEnable;
- var button = this.shootActionsStrip.bestButton;
- button.Checked = !button.Checked;
- if (maxAndMinButtonEnable)
- {
- maxAndMinButtonEnable = !maxAndMinButtonEnable;
- this.shootActionsStrip.maxAndMinButton.Checked = false;
- }
- }
- /// <summary>
- /// 最大最小被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void maxAndMinButton_Click(object sender, EventArgs e)
- {
- if (this.shootActionsStrip == null || this.shootActionsStrip.maxAndMinButton == null)
- return;
- // TUCamAPI.TUCAM_Capa_SetValue(m5pro.m_opCamList[m5pro.m_indexCam].hIdxTUCam, (int)TUCAM_IDCAPA.TUIDC_ATWBALANCE, 0);
- // TUCamAPI.TUCAM_Prop_SetValue(m5pro.m_opCamList[m5pro.m_indexCam].hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_CHNLGAIN, 1220.0, 2);
- //MessageBox.Show("最大最小被点击临时变绿色");
- maxAndMinButtonEnable = !maxAndMinButtonEnable;
- var button = this.shootActionsStrip.maxAndMinButton;
- button.Checked = !button.Checked;
- if (bestButtonEnable)
- {
- bestButtonEnable = !bestButtonEnable;
- this.shootActionsStrip.bestButton.Checked = false;
- }
- }
- /// <summary>
- /// 原始状态被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void originalStateButton_Click(object sender, EventArgs e)
- {
- if (this.shootActionsStrip == null || this.shootActionsStrip.originalStateButton == null)//1012###19464
- return;
- bestButtonEnable = false;
- maxAndMinButtonEnable = false;
- gamma45ButtonEnable = false;
- this.shootActionsStrip.bestButton.Checked = false;
- this.shootActionsStrip.maxAndMinButton.Checked = false;
- this.shootActionsStrip.gamma45Button.Checked = false;
- }
- /// <summary>
- /// 伽马0.45被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void gamma45Button_Click(object sender, EventArgs e)
- {
- if (this.shootActionsStrip == null || this.shootActionsStrip.gamma45Button == null)
- return;
- gamma45ButtonEnable = !gamma45ButtonEnable;
- var button = this.shootActionsStrip.gamma45Button;
- button.Checked = !button.Checked;
- }
- /// <summary>
- /// 曝光不足被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void underexposedButton_Click(object sender, EventArgs e)
- {
- underexposedButtonEnable = !underexposedButtonEnable;
- //if (overexposedButton)
- //{
- // overexposedButton = !overexposedButton;
- // this.shootActionsStrip.overexposedButton.Checked = false;
- //}
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- /// <summary>
- /// 预览属性按钮被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void propertiesButton_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["PropertiesSettingDialog"];//尝试获取已经弹出的窗口对象
- if (form == null || form.IsDisposed)
- {
- if (fmSetting != null)
- {
- fmSetting.Dispose();
- fmSetting = null;
- }
- form = null;
- fmSetting = new PropertiesSettingDialog(this);
- //最佳事件
- fmSetting.displayCameraControl.button2.Click += new System.EventHandler(this.bestButton_Click);
- //最小最大点击事件
- fmSetting.displayCameraControl.button3.Click += new System.EventHandler(this.maxAndMinButton_Click);
- //原始状态事件
- fmSetting.displayCameraControl.button5.Click += new System.EventHandler(this.originalStateButton_Click);
- //伽马0.45事件
- fmSetting.displayCameraControl.button4.Click += new System.EventHandler(this.gamma45Button_Click);
- fmSetting.FormClosing += Fm_FormClosing;
- //fm.ShowDialog();
- FloatingFormMethod.ShowFloatForm(form, form == null ? fmSetting/*没有弹出的窗口对象则创建*/ : null, this.appWorkspace);
- }
- else
- {
- form.Activate();
- form.WindowState = FormWindowState.Normal;
- }
- }
- private void Fm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (fmSetting != null)//0915###避免引起异常问题
- {
- fmSetting.Dispose();
- fmSetting = null;
- }
- }
- /// <summary>
- /// 过曝光被点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void overexposedButton_Click(object sender, EventArgs e)
- {
- overexposedButton = !overexposedButton;
- //if (underexposedButtonEnable)
- //{
- // underexposedButtonEnable = !underexposedButtonEnable;
- // this.shootActionsStrip.underexposedButton.Checked = false;
- //}
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- /// <summary>
- /// 十字线按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void crossButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace != null)
- {
- this.documentWorkspace.GridCrossCurveEnabled = !this.documentWorkspace.GridCrossCurveEnabled;
- this.documentWorkspace.Refresh();
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- }
- /// <summary>
- /// 网格按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void gridButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace != null)
- {
- this.documentWorkspace.GridLineEnabled = !this.documentWorkspace.GridLineEnabled;
- this.documentWorkspace.Refresh();
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- }
- /// <summary>
- /// 方形按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void squareButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace != null)
- {
- this.documentWorkspace.GridRectangleEnabled = !this.documentWorkspace.GridRectangleEnabled;
- this.documentWorkspace.Refresh();
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- }
- /// <summary>
- /// 圆形按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void roundButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace != null)
- {
- this.documentWorkspace.GridRoundEnabled = !this.documentWorkspace.GridRoundEnabled;
- this.documentWorkspace.Refresh();
- var button = (ToolStripButton)sender;
- button.Checked = !button.Checked;
- }
- }
- /// <summary>
- /// 实际大小按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void actualSizeButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- this.isFitToWindow = false;
- }
- }
- /// <summary>
- /// 合适大小按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- this.documentWorkspace.ZoomToWindow();
- this.isFitToWindow = true;
- }
- }
- /// <summary>
- /// 全屏显示按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void fullScreenButton_Click(object sender, EventArgs e)
- {
- var button = (ToolStripButton)sender;
- if (this.WindowState == FormWindowState.Normal)
- {
- this.WindowState = FormWindowState.Maximized;
- button.Checked = true;
- }
- else
- {
- this.WindowState = FormWindowState.Normal;
- button.Checked = false;
- }
- if (isFitToWindow && this.documentWorkspace.CompositionSurface != null)
- this.documentWorkspace.ZoomToWindow();
- this.Invalidate();
- }
- /// <summary>
- /// 缩小按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void zoomOutButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- this.documentWorkspace.ZoomOut();
- }
- }
- /// <summary>
- /// 放大按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void zoomInButton_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- this.documentWorkspace.ZoomIn();
- }
- }
- private void CameraPreviewDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- AutoFocusWorkflow.Stop();
- Thread.Sleep(50);
- Dispose();
- tmrUpdate.Enabled = false;
- }
- public new void Dispose()
- {
- //m_Stage.Close();
- m_Stage.RemoveApp(this);
- m_camera.m_bufHandler -= CallbackDraw;
- m_camera.StopWaitForFrame();
- if (m_matClone != null)
- {
- m_matClone.Dispose();
- }
- if (fmSetting != null)
- fmSetting.Close();
- if (this.documentWorkspace != null && !this.documentWorkspace.IsDisposed)
- this.documentWorkspace.Dispose();
- if (this.document != null)
- this.document.Dispose();
- base.Dispose();
- GC.Collect();
- }
- /// <summary>
- /// 判断颜色灰度值 如果是true 则设置为灰色
- /// </summary>
- /// <param name="isGray"></param>
- public void SetColorModel(bool isGray)
- {
- //m5pro.SetColorModel(isGray);
- }
- /// <summary>
- /// 选择相机设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cmbConfigs_SelectedIndexChanged(object sender, EventArgs e)
- {
- ComboBox cb = (ComboBox)sender;
- Startup.instance.cameraParamModel = m_cameraConfig.GetCameraParamModel(cb.SelectedItem.ToString());
- m_cameraParamModel = Startup.instance.cameraParamModel;
- m_cameraConfig.CameraParamInit();
- }
- /// <summary>
- /// 删除相机设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnConfigDel_Click(object sender, EventArgs e)
- {
- if (this.cmbConfigs.SelectedItem != null)
- {
- if (this.cmbConfigs.SelectedItem.ToString().Equals("CameraParam"))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hedefaultconfiguratallowdeletion.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- DialogResult result = MessageBox.Show(PdnResources.GetString("Menu.suredeletit.Text") + "?", PdnResources.GetString("Menu.Tips.text"), MessageBoxButtons.OKCancel);
- if (result == DialogResult.OK)
- {
- CameraConfigs.GetInstance().Delete();
- initCmbConfigs();
- }
- }
- }
- /// <summary>
- /// 用于修改全屏按钮状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Form_Resize(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Normal)
- {
- baseActionsStrip.fullScreenButton.Checked = false;
- }
- else
- {
- baseActionsStrip.fullScreenButton.Checked = true;
- }
- if (isFitToWindow && this.documentWorkspace.CompositionSurface != null)
- this.documentWorkspace.ZoomToWindow();
- this.Invalidate();
- }
- /// <summary>
- /// 获取当前标尺并换算为微米
- /// </summary>
- public void getRulerMicronRatio()
- {
- Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out this.micronRatio);
- this.documentWorkspace.MicronRatio = this.micronRatio;
- }
- /// <summary>
- /// 标尺下拉菜单选项改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
- {
- //getRulerMicronRatio();
- //this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 理论比例尺按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void theoreticalScaleButton_Click(object sender, EventArgs e)
- {
- if (theoreticalScaleDialog == null)
- {
- theoreticalScaleDialog = new TheoreticalScaleDialog(this.appWorkspace, MeasureActionMenu.ArrayList1, MeasureActionMenu.ArrayList2,
- MeasureActionMenu.ArrayList3);
- theoreticalScaleDialog.button7.Click += new EventHandler(button7_Click);
- //theoreticalScaleDialog.FormClosing += new FormClosingEventHandler(theoreticalScaleDialog_FormClosing);
- }
- theoreticalScaleDialog.StartPosition = FormStartPosition.CenterParent;
- theoreticalScaleDialog.ShowDialog();
- }
- /// <summary>
- /// 理论比例尺窗口关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void theoreticalScaleDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- int selectedNum = this.comboBox1.SelectedIndex;
- this.comboBox1.DataSource = null;
- bs = new BindingSource();
- bs.DataSource = micRulersDictonary;
- this.comboBox1.DataSource = bs;
- this.comboBox1.DisplayMember = "Key";
- this.comboBox1.ValueMember = "Value";
- this.comboBox1.SelectedIndex = selectedNum;
- this.comboBox1.Refresh();
- }
- /// <summary>
- /// 理论比例尺保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- }
- private double GrayHistogramArea(Bitmap bitmap)
- {
- Mat image = BitmapConverter.ToMat(bitmap);
- if (image.Channels() == 3)
- {
- Cv2.CvtColor(image, image, ColorConversionCodes.BGR2GRAY);
- }
- int[] list = new int[256];
- var date = image.ToBytes();
- foreach (int value in date)
- {
- list[value]++;
- }
- return 0;
- }
- public static Mat ToGrayMat(Bitmap bitmap)
- {
- Mat image = BitmapConverter.ToMat(bitmap);
- if (image.Channels() == 3)
- {
- Cv2.CvtColor(image, image, ColorConversionCodes.BGR2GRAY);
- }
- return image;
- }
- /// <summary>
- /// 高斯距离
- /// </summary>
- /// <param name="im"></param>
- public static double GaussianDiff(Mat im)
- {
- if (im.Channels() == 3)
- {
- Cv2.CvtColor(im, im, ColorConversionCodes.BGR2GRAY);
- }
- Mat blurred = new Mat();
- Cv2.GaussianBlur(im, blurred, new OpenCvSharp.Size(7, 7), 1.66);
- Cv2.Absdiff(im, blurred, blurred);
- return Cv2.Mean(blurred)[0];
- }
- public static double Sobel(Bitmap bitmap)
- {
- var graymat = ToGrayMat(bitmap);
- Mat imageSobel = new Mat();
- Cv2.Sobel(graymat, imageSobel, 2, 1, 1);
- return Cv2.Mean(imageSobel)[0];
- }
- /// <summary>
- /// 获取输入图片的清晰度
- /// </summary>
- /// <param name="bitmap"></param>
- /// <returns></returns>
- private static double getMeanValueOfBitmap(Bitmap bitmap)
- {
- Mat converted = BitmapConverter.ToMat(bitmap);
- Mat imageGrey = new Mat();
- Mat imageSobel = new Mat();
- try
- {
- Cv2.CvtColor(converted, imageGrey, ColorConversionCodes.RGB2GRAY);
- }
- catch (Exception)
- {
- imageGrey = converted;
- }
- Mat meanValueImage = new Mat();
- Mat meanStdValueImage = new Mat();
- //求灰度图像的标准差 值越大越好
- OpenCvSharp.Cv2.MeanStdDev(imageGrey, meanValueImage, meanStdValueImage);
- return meanStdValueImage.At<double>(0, 0);
- }
- #region AutoFocus
- private static bool _focusing;
- public static Func<Bitmap> CurrentImage;
- private void autoFocusButton_Click(object sender, EventArgs e)
- {
- m_camera.SetExposureMode(ExposureMode.MANUAL);
- _focusing = true;
- new Thread(new ThreadStart(() =>
- {
- var result = AutoFocusWorkflow.AutoFocus(m_Stage, CurrentImage);
- if (string.IsNullOrEmpty(result))
- {
- MessageBox.Show("聚焦成功");
- }
- else
- {
- MessageBox.Show(result);
- }
- _focusing = false;
- })).Start();
- }
- bool _cameraDown = false;
- private void tmrUpdate_Tick(object sender, EventArgs e)
- {
- if (_cameraDown)
- {
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- if (m_camera != null && m_camera.IsOpen())
- {
- m_camera.m_bufHandler += CallbackDraw;
- m_camera.StartWaitForFrame();
- _cameraDown = false;
- }
- }
- else if (!m_camera.IsOpen())
- {
- _cameraDown = true;
- //MessageBox.Show("相机已断开");
- //this.Close();
- }
- // label1.Text = m_CurrentValue.ToString("F2");
- if (_focusing)
- progressBar1.Value = (int)(Math.Min(AutoFocusWorkflow.CurrentValue, progressBar1.Maximum));
- else progressBar1.Value = 0;
- // setBarValue((int)m_MeanValue);
- }
- private static double m_resetStep1 = 0;
- private void btnRestStep_Click(object sender, EventArgs e)
- {
- if (_focusing) return;
- if (m_resetStep1 != 0)
- {
- m_Stage.UpTo(m_resetStep1);
- m_resetStep1 = 0;
- }
- }
- #endregion
- private void DocumentWorkspace_ScaleFactorChanged(object sender, EventArgs e)
- {
- this.gainNumbertxt.Text = Math.Round((this.documentWorkspace.ScaleRatio * 100), 2) + "%";
- }
- public void RefreshDrawNodes()
- {
- TreeView drawTreeView = this.documentWorkspace.oldDrawTreeView;
- if (drawTreeView != null)
- {
- for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
- {
- if (this.documentWorkspace.GraphicsList[i].objectType == DrawClass.Measure)
- {
- int count1 = drawTreeView.Nodes.Count;
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).drawingProperties.Clear();
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Clear();
- for (int k = 0; k < count1; k++)
- {
- int count2 = drawTreeView.Nodes[k].Nodes.Count;
- for (int j = 0; j < count2; j++)
- {
- if (this.documentWorkspace.GraphicsList[i].drawToolType == (DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name))
- {
- bool drawb = false;
- if (drawTreeView.Nodes[k].Nodes[j].Nodes.Count == 0)
- {
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).drawingProperties.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), new string[] { "nothing" });
- if (this.documentWorkspace.oldDrawTreeView != null)
- {
- if (this.documentWorkspace.oldDrawTreeView.Nodes[k].Nodes[j].Nodes.Count != 0)
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
- }
- else
- {
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
- }
- }
- else
- {
- int a = 0;
- string[] arr = new string[drawTreeView.Nodes[k].Nodes[j].Nodes.Count];
- foreach (TreeNode node2 in drawTreeView.Nodes[k].Nodes[j].Nodes)
- {
- arr[a] = node2.Name;
- a++;
- }
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).drawingProperties.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), arr);
- if (this.documentWorkspace.oldDrawTreeView != null)
- {
- if (drawTreeView.Nodes[k].Nodes[j].Nodes.Count != this.documentWorkspace.oldDrawTreeView.Nodes[k].Nodes[j].Nodes.Count)
- {
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
- }
- else
- {
- foreach (TreeNode oldNode in this.documentWorkspace.oldDrawTreeView.Nodes[k].Nodes[j].Nodes)
- {
- /*if (!arr.Contains(oldNode.Name))
- {
- drawb = true;
- }*/
- }
- if (drawb)
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), drawb);
- }
- }
- else
- {
- ((MeasureDrawObject)(this.documentWorkspace.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
- }
- }
- this.documentWorkspace.Refresh();
- }
- }
- }
- }
- }
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (((ComboBox)sender).SelectedItem != null)
- {
- if (comboBox_Value != ((ComboBox)sender).SelectedItem.ToString())
- {
- comboBox_Value = ((ComboBox)sender).SelectedItem.ToString();
- //comboBox_Change = true;
- List<mic_rulers> list = Startup.instance.mic_rulersAll;
- if (list != null)
- {
- for (int ruleI = 0; ruleI < list.Count; ruleI++)
- {
- mic_rulers rule = list[ruleI];
- if (rule.ruler_name.Equals(((ComboBox)sender).SelectedItem.ToString()))
- {
- int rulid = rule.id;
- string rulerName2 = rule.ruler_name;
- if (rulid != Startup.instance.configModel.RulerId)
- {
- //设置当前选中标尺
- this.appWorkspace.SetActiveRulerIndex(((ComboBox)sender).SelectedIndex);
- //comboBox_Change = false;
- this.documentWorkspace.rules = Startup.instance.rules;
- }
- break;
- }
- }
- }
- }
- getRulerMicronRatio();
- this.documentWorkspace.Refresh();
- }
- }
- public void OnUpdatePosition()
- {
- try
- {
- this.Invoke(new Action(() =>
- {
- lblZPos.Text = m_Stage.Z.ToString("f2");
- }));
- }
- catch { }
- }
- public void OnTimeoutConnect()
- {
- MessageBox.Show(PdnResources.GetString("Menu.Theconsoleresponsetimeout.Text"));
- }
- public void OnErrorSend()
- {
- MessageBox.Show(PdnResources.GetString("Menu.Replydataarsingerror.Text"));
- }
- private void CameraPreviewDialog_Load(object sender, EventArgs e)
- {
- tmrUpdate.Enabled = true;
- progressBar1.Maximum = 65;
- checkBox1.Checked = Startup.instance.configModel.CaptureHasRoler;
- }
- private void btnZUp_Click(object sender, EventArgs e)
- {
- var value = (double)numZLen.Value;
- m_Stage.Up(value);
- }
- private void btuZDown_Click(object sender, EventArgs e)
- {
- var value = (double)numZLen.Value;
- m_Stage.Up(-value);
- }
- private void btnZClear_Click(object sender, EventArgs e)
- {
- m_Stage.FreeZ();
- m_Stage.ClearPosZ();
- }
- private void checkBox1_Click(object sender, EventArgs e)
- {
- Startup.instance.configModel.CaptureHasRoler = checkBox1.Checked;
- }
- /// <summary>
- /// 判断鼠标是否在预览窗口内
- /// </summary>
- /// <returns></returns>
- public bool IsLeave()
- {
- try
- {
- Point point = this.PointToClient(Control.MousePosition);
- isLeave = point.X > this.ClientSize.Width || point.X < 0 || point.Y > this.ClientSize.Height || point.Y < 0 ? false : true;
- }
- catch (Exception)
- {
- isLeave = false;
- }
- return isLeave;
- }
- }
- }
|