123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using OpenCvSharp;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation.Measure;
- using PaintDotNet.Annotation.relationModel;
- using PaintDotNet.Base.CommTool;
- using static PaintDotNet.Annotation.relationModel.MeasureRelationModel;
- using Point = System.Drawing.Point;
- /// <summary>
- /// 光密度
- /// </summary>
- namespace PaintDotNet.Measuring
- {
- partial class OpticalDensityDialog : FloatingToolForm
- {
- #region 控件
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeLanguageText()
- {
- this.button1.Text = PdnResources.GetString("Menu.measuring.text");
- this.button2.Text = PdnResources.GetString("Menu.Imagement.Opticaldensity.Dataoutput.text");
- this.button3.Text = PdnResources.GetString("Menu.Imagement.Opticaldensity.imageexport.text");
- this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.display.text");
- this.Text = PdnResources.GetString("Menu.MeasureAction.OpticalDensity.Text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.panel1 = new PaintDotNet.PanelEx();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(161, 29);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 4;
- this.button1.Text = "测量";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(243, 29);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 5;
- this.button2.Text = "数据导出";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(325, 29);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 6;
- this.button3.Text = "图片导出";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.button1);
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Controls.Add(this.button3);
- this.groupBox1.Location = new System.Drawing.Point(27, 13);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(420, 75);
- this.groupBox1.TabIndex = 4;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "操作";
- //
- // panel1
- //
- this.panel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.panel1.BackColor = System.Drawing.SystemColors.ControlLightLight;
- this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panel1.HideHScroll = false;
- this.panel1.HideVScroll = false;
- this.panel1.IgnoreSetFocus = false;
- this.panel1.Location = new System.Drawing.Point(3, 17);
- this.panel1.Name = "panel1";
- this.panel1.ScrollPosition = new System.Drawing.Point(0, 0);
- this.panel1.Size = new System.Drawing.Size(414, 315);
- this.panel1.TabIndex = 0;
- this.panel1.TabStop = true;
- this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint_1);
- this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown_1);
- this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove_1);
- this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
- //
- // groupBox2
- //
- this.groupBox2.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.groupBox2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.groupBox2.BackColor = System.Drawing.SystemColors.Control;
- this.groupBox2.Controls.Add(this.panel1);
- this.groupBox2.Location = new System.Drawing.Point(27, 94);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(420, 335);
- this.groupBox2.TabIndex = 5;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "显示";
- //
- // OpticalDensityDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.BackColor = System.Drawing.SystemColors.Control;
- this.ClientSize = new System.Drawing.Size(471, 441);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.MaximumSize = new System.Drawing.Size(487, 480);
- this.MinimumSize = new System.Drawing.Size(487, 480);
- this.Name = "OpticalDensityDialog";
- this.Text = "光密度";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OpticalDensityDialog_FormClosing);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.GroupBox groupBox1;
- private PanelEx panel1;
- private System.Windows.Forms.GroupBox groupBox2;
- #endregion
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 关系数据
- /// </summary>
- private static List<MeasureRelationModel> list;
- /// <summary>
- /// 横坐标比例
- /// </summary>
- private float proportion;
- /// <summary>
- /// 灰度值点数
- /// </summary>
- private int pointNumber;
- private Rectangle sRect;
- private PointF StartPoint = new Point(70, 10);
- private Rectangle eRect;
- private PointF EndPoint = new Point(350, 10);
- Pen pe = new Pen(Color.YellowGreen, 4);
- private bool sCanMove;
- private bool eCanMove;
- private PointF startPoint;
- private PointF endPoint;
- private string unitString;
- private string unit;
- /// <summary>
- /// 步长 初始值1,依次增加
- /// </summary>
- private string stepLength = "00" + Startup.instance.step_length;
- public OpticalDensityDialog(AppWorkspace appWorkspace)
- {
- if (list == null)
- {
- list = InvariantData.GetMeasureRelations();
- }
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- }
- /// <summary>
- /// 刷新光密度画面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void RefreshOpticalDensity(object sender, EventArgs e)
- {
- this.panel1.Refresh();
- }
-
- /// <summary>
- /// 绘制绿线
- /// </summary>
- /// <param name="graphics"></param>
- private void drawRect(Graphics graphics)
- {
- graphics.DrawLine(pe, EndPoint, new PointF(EndPoint.X, EndPoint.Y + 260));
- graphics.DrawLine(pe, StartPoint, new PointF(StartPoint.X, StartPoint.Y + 260));
- }
- private void means(Graphics graphics)
- {
- sRect = new Rectangle((int)StartPoint.X, (int)StartPoint.Y, 5, 260);
- eRect = new Rectangle((int)EndPoint.X, (int)EndPoint.Y, 5, 260);
- StartPoint = sRect.Location;
- EndPoint = eRect.Location;
- //graphics.DrawLine(pe, new Point((int)StartPoint.X, 270), new Point((int)StartPoint.X, 10));
- //graphics.DrawLine(pe, new Point((int)EndPoint.X, 270), new Point((int)EndPoint.X, 10));
- }
- /// <summary>
- /// 绘制截线
- /// </summary>
- private void DrawInMainScreen()
- {
- double kS = (StartPoint.X - 70) / 280;
- double kE = (350 - EndPoint.X) / 280;
- if (this.appWorkspace.ActiveDocumentWorkspace != null)
- this.DrawInMainScreen(kS, kE);
- }
- public void DrawInMainScreen(double kS, double kE)
- {
- //循环所有测量
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList != null
- && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
- {
- int count = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count;
- for (int i = 0; i < count; i++)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].objectType == DrawClass.Other)
- {
- ((MeasureDrawObject)(this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i])).kS = kS;
- ((MeasureDrawObject)(this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i])).kE = kE;
- }
- }
- }
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- /// <summary>
- /// 绘制刻度
- /// </summary>
- private void Setscale(Graphics graphics)
- {
- Font textfont = new Font(Font, FontStyle.Regular);
- Brush textbrush = new SolidBrush(Color.Black);
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(70, 270), new Point(350, 270));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(70, 270), new Point(70, 10));
- // 纵坐标刻度
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 270), new Point(70, 270));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 220), new Point(70, 220));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 170), new Point(350, 170));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 120), new Point(70, 120));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 70), new Point(350, 70));
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(63, 20), new Point(70, 20));
- graphics.DrawString("0", textfont, textbrush, new Point(42, 263));
- graphics.DrawString("100", textfont, textbrush, new Point(42, 163));
- graphics.DrawString("200", textfont, textbrush, new Point(42, 63));
-
- graphics.DrawString(PdnResources.GetString("Menu.MeasureAction.MeasureDistanceLine.Text") +"(" + unitString + ")", textfont, textbrush, new Point(180, 300));
- graphics.DrawString(PdnResources.GetString("Menu.Imagement.Opticaldensity.Linecontour.text"), textfont, textbrush, new Point(180, 0));
- graphics.DrawString(PdnResources.GetString("Menu.strong.Text") + "\r\n" + " " + "\r\n" + PdnResources.GetString("Menu.degree.Text"), textfont, textbrush, new Point(20, 5));
- // 横坐标刻度
- int n;
- int growth = 70;
- int scale = 0;
- graphics.DrawString(scale.ToString(), textfont, textbrush, new Point(65, 280));
- if (this.pointNumber <= 200)
- {
- n = this.pointNumber / 10;
- for (int i = 0; i < n; i++)
- {
- scale = scale + 10;
- growth = growth + 280 / n;
- if ((i + 1) % 2 == 0)
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 10), new Point(growth, 277));
- graphics.DrawString(scale.ToString(), textfont, textbrush, new Point(growth, 277));
- }
- else
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 270), new Point(growth, 277));
- }
- }
- }
- else if (this.pointNumber > 200 && this.pointNumber <= 1000)
- {
- n = this.pointNumber / 100;
- for (int i = 0; i < n; i++)
- {
- scale = scale + 50;
- growth = growth + 280 / n;
- if ((i + 1) % 2 == 0)
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 10), new Point(growth, 277));
- graphics.DrawString(scale.ToString(), textfont, textbrush, new Point(growth, 277));
- }
- else
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 270), new Point(growth, 277));
- }
- }
- }
- else if (this.pointNumber > 1000)
- {
- int length1 = Convert.ToInt32(BasicCalculationHelper.GetDistance(startPoint, endPoint, 2));
- int f = 280 / 50;
- for (int i = 0; i < f; i++)
- {
- int scale1 = (int)(1000 * i * 50 / 280);
- //if ((i + 1) % 2 == 0)
- {
- //graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 10), new Point(growth, 277));
- graphics.DrawString(scale1.ToString(), textfont, textbrush, new Point(50 * i + 70, 277));
- }
- //else
- {
- //graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 270), new Point(growth, 277));
- }
- }
- /* n = this.pointNumber / 200;
- for (int i = 0; i < n; i++)
- {
- scale = scale + 100;
- growth = growth + 280 / n;
- if ((i + 1) % 2 == 0)
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 10), new Point(growth, 277));
- graphics.DrawString(scale.ToString(), textfont, textbrush, new Point(growth, 277));
- }
- else
- {
- graphics.DrawLine(new Pen(Color.Black, 2), new Point(growth, 270), new Point(growth, 277));
- }
- }*/
- }
- }
- /// <summary>
- /// 绘制灰度图像
- /// </summary>
- private void DrawGrayScale(Graphics graphics)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace != null
- && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList != null
- && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
- {
- int count = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count;
- for (int i = 0; i < count; i++)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].objectType == DrawClass.Other)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].drawToolType == DrawToolType.OpticalDensityLine)
- {
- startPoint = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].startPoint;
- endPoint = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].endPoint;
- OpenCvSharp.Mat mat = PaintDotNet.Camera.Tools.ToMat(
- this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- //定义线上的点
- List<Point> linePoint = new List<Point>();
- Color color = Color.Blue;
- Pen pen = new Pen(color, 1);
- double k = 0;
- double y = 0;
- double x = 0;
- if (startPoint.X != endPoint.X)
- {
- // 计算斜率
- k = ((double)(startPoint.Y - endPoint.Y)) / (startPoint.X - endPoint.X);
- // 循环x坐标
- double maxPointX;
- double minPointX;
- if (startPoint.X > endPoint.X)
- {
- maxPointX = startPoint.X;
- minPointX = endPoint.X;
- }
- else
- {
- maxPointX = endPoint.X;
- minPointX = startPoint.X;
- }
- if (Math.Abs(startPoint.X - endPoint.X) > Math.Abs(startPoint.Y - endPoint.Y))
- {
- for (int j = (int)(minPointX) + 1; j < maxPointX; j++)
- {
- if (k == 0 && startPoint.Y == endPoint.Y)
- {
- y = startPoint.Y;
- }
- else
- {
- // 根据斜率,计算y坐标
- y = k * (j - startPoint.X) + startPoint.Y;
- }
- linePoint.Add(new Point(j, (int)y));
- }
- }
- else
- {
- if (startPoint.Y > endPoint.Y)
- {
- maxPointX = startPoint.Y;
- minPointX = endPoint.Y;
- }
- else
- {
- maxPointX = endPoint.Y;
- minPointX = startPoint.Y;
- }
- for (int j = (int)(minPointX) + 1; j < maxPointX; j++)
- {
- if (k == 0 && startPoint.Y == endPoint.Y)
- {
- y = startPoint.Y;
- }
- else
- {
- // 根据斜率,计算y坐标
- x = -((startPoint.Y - j) / k - startPoint.X);
- }
- linePoint.Add(new Point((int)x, j));
- }
- }
- }
- else
- {
- double maxPointY;
- double minPointY;
- if (startPoint.Y > endPoint.Y)
- {
- maxPointY = startPoint.Y;
- minPointY = endPoint.Y;
- }
- else
- {
- maxPointY = endPoint.Y;
- minPointY = startPoint.Y;
- }
- // 循环y坐标
- for (int j = (int)(minPointY) + 1; j < maxPointY; j++)
- {
- // 根据斜率,计算y坐标
- y = j;
- linePoint.Add(new Point((int)startPoint.X, (int)y));
- }
- }
- // 灰度值数据
- List<int> list0 = new List<int>();
- List<int> list1 = new List<int>();
- List<int> list2 = new List<int>();
- foreach (var point in linePoint)
- {
- if(point.X < mat.Width && point.Y < mat.Height && point.Y >= 0 && point.X >= 0)
- {
- Vec3b vec3B = new Vec3b();
- byte a;
- if (mat.Type() == MatType.CV_8UC1)
- {
- a = mat.At<byte>(point.Y, point.X);
- list0.Add(a);
- }
- else
- {
- vec3B = mat.At<Vec3b>(point.Y, point.X);
- list0.Add(vec3B.Item0);
- list1.Add(vec3B.Item1);
- list2.Add(vec3B.Item2);
- }
- }
- }
- // 灰度图绘制坐标点
- List<PointF> pointList = new List<PointF>();
- List<PointF> pointList1 = new List<PointF>();
- List<PointF> pointList2 = new List<PointF>();
- this.pointNumber = list0.Count;
- this.proportion = 280 / (float)list0.Count;
- float px;
- if (mat.Type() == MatType.CV_8UC1)
- {
- px = 70;
- foreach (var item in list0)
- {
- pointList.Add(new PointF(px, 270 - item));
- px = px + this.proportion;
- }
- if (pointList.Count > 0)
- {
- color = Color.Blue;
- pen = new Pen(color, 1);
- graphics.DrawLines(pen, pointList.ToArray());
- }
- }
- else
- {
- px = 70;
- foreach (var item in list0)
- {
- pointList.Add(new PointF(px, 270 - item));
- px = px + this.proportion;
- }
- if (pointList.Count > 0)
- {
- color = Color.Blue;
- pen = new Pen(color, 1);
- graphics.DrawLines(pen, pointList.ToArray());
- }
- px = 70;
- foreach (var item in list1)
- {
- pointList1.Add(new PointF(px, 270 - item));
- px = px + this.proportion;
- }
- if (pointList1.Count > 0)
- {
- color = Color.Green;
- pen = new Pen(color, 1);
- graphics.DrawLines(pen, pointList1.ToArray());
- }
- px = 70;
- foreach (var item in list2)
- {
- pointList2.Add(new PointF(px, 270 - item));
- px = px + this.proportion;
- }
- if (pointList2.Count > 0)
- {
- color = Color.Red;
- pen = new Pen(color, 1);
- graphics.DrawLines(pen, pointList2.ToArray());
- }
- }
- pen.Dispose();
- }
- }
- }
- }
- }
- private void ExportEcxel()
- {
- string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + PdnResources.GetString("Menu.pticaldensitydata.Text");
- SaveFileDialog exe = new SaveFileDialog();
- exe.Filter = "Execl files (*.xlsx)|*.xlsx";
- exe.FilterIndex = 0;
- exe.RestoreDirectory = true;
- //exe.CreatePrompt = true;
- exe.Title = "Export Excel File";
- exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- exe.FileName = fileName;
-
- DialogResult dr = exe.ShowDialog();
- if (dr != DialogResult.OK)
- {
- return;
- }
- double length = BasicCalculationHelper.GetDistance(this.startPoint, this.endPoint, 2);
- double length2 =Math.Round(length * (Math.Abs(this.StartPoint.X - this.EndPoint.X) / 280), 2);
- DataTable dtb = new DataTable();
- dtb.Columns.Add(PdnResources.GetString("Menu.Measuringpointdistance.Text"));
- dtb.Columns.Add(PdnResources.GetString("Menu.Measurinlinedistance.Text"));
- dtb.Columns.Add(PdnResources.GetString("Menu.unit.text"));
- DataRow dataRow = dtb.NewRow();
- dataRow[PdnResources.GetString("Menu.Measuringpointdistance.Text")] = (length * Convert.ToDouble(unit)).ToString();
- dataRow[PdnResources.GetString("Menu.Measurinlinedistance.Text")] = (length2 * Convert.ToDouble(unit)).ToString();
- dataRow[PdnResources.GetString("Menu.unit.text")] = unitString;
- dtb.Rows.Add(dataRow);
- List<DataTable> list = new List<DataTable>();
- list.Add(dtb);
- this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, false,false, true);
- }
- /// <summary>
- /// 测量按钮按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count == 0)
- {
- if (appWorkspace.ActiveDocumentWorkspace != null)
- {
- appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.OpticalDensityLine;
- }
- }
- else
- {
- bool other = false;
- int count = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count;
- for (int i = 0; i < count; i++)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].objectType == DrawClass.Other
- && this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].drawToolType == DrawToolType.OpticalDensityLine)
- {
- other = true;
- this.button1.Tag = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i];
- }
- }
- if(!other)
- {
- if (appWorkspace.ActiveDocumentWorkspace != null)
- {
- appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.OpticalDensityLine;
- }
- }
- else
- {
- if (this.button1.Tag != null)
- {
- var senderGrid = (Button)sender;
- DrawObject dObject;
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- dObject = (DrawObject)senderGrid.Tag;
- dObject.Selected = true;
- }
- }
-
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- this.panel1.Focus();
- }
- /// <summary>
- /// 数据导出按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- this.ExportEcxel();
- }
- /// <summary>
- /// 绘制事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_Paint_1(object sender, PaintEventArgs e)
- {
- unitString = this.appWorkspace.GetPxPerUnit()[1];
- unit = this.appWorkspace.GetPxPerUnit()[3];
- this.DrawGrayScale(e.Graphics);
- this.Setscale(e.Graphics);
- this.DrawGrayScale(e.Graphics);
- this.means(e.Graphics);
- this.drawRect(e.Graphics);
- DrawInMainScreen();
- }
- /// <summary>
- /// 鼠标移动事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_MouseMove_1(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left && (sCanMove == true || eCanMove == true))
- {
- if (sCanMove == true && eCanMove == true)
- eCanMove = false;
- if (sCanMove == true)
- sRect.Offset((int)(e.X - StartPoint.X), 0);
- if (eCanMove == true)
- eRect.Offset((int)(e.X - EndPoint.X), 0);
- if (sRect.X < 70)
- sRect.X = 70;
- if (sRect.X > 350)
- sRect.X = 350;
- if (eRect.X < 70)
- eRect.X = 70;
- if (eRect.X > 350)
- eRect.X = 350;
- StartPoint = new Point(sRect.X, sRect.Y);
- EndPoint = new Point(eRect.X, eRect.Y);
- this.panel1.Refresh();
- }
- }
- /// <summary>
- /// 鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_MouseDown_1(object sender, MouseEventArgs e)
- {
- if (sRect.Contains(e.Location))
- {
- sCanMove = true;
- }
- if (eRect.Contains(e.Location))
- {
- eCanMove = true;
- }
- }
- /// <summary>
- /// 鼠标抬起事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_MouseUp(object sender, MouseEventArgs e)
- {
- sCanMove = false;
- eCanMove = false;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
- panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
- DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(Camera.Tools.ToMat(bmp));
- dw.Document = document;
- dw.xmlSaveModel = Startup.instance.ruleDB;
- dw.InitRulerInfo();
- dw.fileText = this.Text + "-" + stepLength;
- appWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- stepLength = "00" + Startup.instance.step_length;
- }
- private void OpticalDensityDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace != null)
- {
- this.appWorkspace.toolBar.RefreshBtnSelect(false, "OpticalDensity");
- this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "OpticalDensity");
- for (int i = 0; i < this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count; i++)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].drawToolType == DrawToolType.OpticalDensityLine)
- {
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.RemoveAt(i);
- this.appWorkspace.Refresh();
- }
- }
- }
- }
- }
- }
|