| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158 | using OpenCvSharp;using PaintDotNet.Adjust;using PaintDotNet.Base.Functionodel;using PaintDotNet.CustomControl;using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Windows.Forms;using Point = System.Drawing.Point;using PaintDotNet.Annotation;namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.IntegrationClass{    internal class MetalsHoleAreaEditingDialog : Form    {        /// <summary>        /// 公共按钮        /// </summary>        private CommonControlButtons commonControlButtons;        /// <summary>        /// 主控件        /// </summary>        private AppWorkspace appWorkspace;        private DocumentWorkspaceWindow documentWorkspace;        /// <summary>        /// 外接矩形,或者是计算的矩形        /// </summary>        protected RectangleF rectangle = new RectangleF();        /// <summary>        /// 选中图片的bitmap        /// </summary>        private Bitmap bitmap;        ///// <summary>        ///// 用于get处理后的图像        ///// </summary>        //private Mat phaseMat;        ///// <summary>        ///// 辅助线集成        ///// </summary>        //private GrainSizeGuideClass guideClass;        //public object SelectedItem;        Color phaseColor;        Mat phaseMatCopy = new Mat();        ///// <summary>        ///// 当前处理的程序        ///// </summary>        //private Data.Action.Action911 action = new Data.Action.Action911();        ///( 0,没有操作   1,折线添加 2,直线添加)                /// <summary>        /// 操作类型        /// 0,没有操作   21,多边形添加 22,圆形添加 23,矩形添加 24,椭圆添加        /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除        /// </summary>        private int pointKtype = 0;        /// <summary>        /// 起始点        /// </summary>        private Point startPoint = new Point(-1, -1);        /// <summary>        /// 是否绘制了起始点        /// </summary>        private bool drawedStartPoint = false;        /// <summary>        /// 结束点        /// </summary>        private Point endPoint = new Point(-1, -1);        /// <summary>        /// 折线点的集合        /// </summary>        public List<Point> pointArray = new List<Point>();        /// <summary>        /// 是否显示视场        /// </summary>        Boolean ShowDrawClassView = true;        private GroupBox groupBox1;        private GroupBox groupBox2;        private Button button2;        private Button button1;        private Button button3;        private Button button4;        private Button button32;        private Button button42;        private Button button8;        private Button button7;        private Button button6;        private Button button5;        private TriangleTrackBar trackBar2;        private TextBox textBox1;        private Label label1;        private TrackBar trackBar1;        private Button button9;        private GroupBox groupBox7;        //public GrainSizeGuideClass GuideClass        //{        //    set        //    {        //        this.guideClass = value;        //    }        //}        public MetalsHoleAreaEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, Mat analyzeMat, Boolean ShowDrawClassView = true)        {            this.ShowDrawClassView = ShowDrawClassView;            this.appWorkspace = appWorkspace;            InitializeComponent();            InitializeLanguageText();            //            //初始化图像控件            //            this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);            this.documentWorkspace.Dock = DockStyle.Fill;            this.documentWorkspace.HookMouseEvents();            this.documentWorkspace.AuxiliaryLineEnabled = false;            this.documentWorkspace.Visible = false;            this.documentWorkspace.panel.MouseDown += OnMouseDown;            this.documentWorkspace.panel.Paint += Panel_Paint;            this.documentWorkspace.panel.MouseMove += onMouseMove;            this.documentWorkspace.panel.MouseUp += onMouseUp;            this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);            this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动            this.groupBox7.Controls.Add(documentWorkspace);            //            //初始化操作按钮            //            this.commonControlButtons = new CommonControlButtons();            this.commonControlButtons.Dock = DockStyle.Top;            this.commonControlButtons.Height = 30;            this.commonControlButtons.HideZoomToWindowAndActualSize();            this.groupBox7.Controls.Add(commonControlButtons);            this.phaseColor = phaseColor;            {                //                //初始化相                //                PhaseModel model = new PhaseModel();                model.choise = true;                model.mat = null;                model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();                model.position = this.documentWorkspace.PhaseModels.Count + 1;                model.name = PdnResources.GetString("Menu.Binarization.text");                this.documentWorkspace.PhaseModels.Add(model);            }            this.documentWorkspace.PhaseModels[0].mat = analyzeMat;// phaseMat;            this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);            this.documentWorkspace.Refresh();            this.bitmap = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreateAliasedBitmap();            Document document = Document.FromImage(bitmap);            this.documentWorkspace.Document = document;            this.documentWorkspace.Visible = true;            if (ShowDrawClassView)            {                this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;            }            else            {                GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;                GraphicsList graphicsList = new GraphicsList();                for (int j = 0; j < itemGraphicsList.Count; j++)                {                    if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View)                        graphicsList.Add(itemGraphicsList[j]);                }                this.documentWorkspace.GraphicsList = graphicsList;            }            InitCommonButtonEvent();        }        #region 矩形拖动        /// <summary>        /// 鼠标按下        /// </summary>        /// <param name="drawArea"></param>        /// <param name="e"></param>        private void OnMouseDown(object sender, MouseEventArgs e)        {            // 换算后的点            PointF point1 = documentWorkspace.GetScalePoint(e.Location);            if (point1.X <= this.documentWorkspace.CompositionSurface.Width             && point1.X >= 0             && point1.Y >= 0             && point1.Y <= this.documentWorkspace.CompositionSurface.Height)            {                if (e.Button == MouseButtons.Left/* && e.Clicks == 1*/&& this.pointKtype >= 1)                {                    if (!drawedStartPoint)                    {                        drawedStartPoint = true;                        startPoint = new Point((int)point1.X, (int)point1.Y);                        return;                    }                }            }            else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12                || this.pointKtype == 24 || this.pointKtype == 23 || this.pointKtype == 22)            {                if (!drawedStartPoint)                {                    drawedStartPoint = true;                    startPoint = new Point((int)point1.X, (int)point1.Y);                    return;                }            }            else                return;            // 右键完成操作            if (e.Button == MouseButtons.Right)            {            }        }        /// <summary>        /// 移动        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void onMouseMove(object sender, MouseEventArgs e)        {            // 换算后的点            PointF point1 = documentWorkspace.GetScalePoint(e.Location);            if (e.Button == MouseButtons.Left)            {                // 椭圆删除/圆形删除                if ((this.pointKtype == 14 || this.pointKtype == 12                    || this.pointKtype == 24 || this.pointKtype == 22) && drawedStartPoint)                {                    endPoint = new Point((int)point1.X, (int)point1.Y);                    if (this.startPoint.X < this.endPoint.X)                    {                        this.rectangle.X = this.startPoint.X;                        this.rectangle.Width = this.endPoint.X - this.startPoint.X;                    }                    else                    {                        this.rectangle.X = this.endPoint.X;                        this.rectangle.Width = this.startPoint.X - this.endPoint.X;                    }                    if (this.startPoint.Y < this.endPoint.Y)                    {                        this.rectangle.Y = this.startPoint.Y;                        this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;                    }                    else                    {                        this.rectangle.Y = this.endPoint.Y;                        this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;                    }                    this.documentWorkspace.Refresh();                }                // 矩形删除                if ((this.pointKtype == 13 || this.pointKtype == 23) && drawedStartPoint)                {                    endPoint = new Point((int)point1.X, (int)point1.Y);                    if (this.startPoint.X < this.endPoint.X)                    {                        this.rectangle.X = this.startPoint.X;                        this.rectangle.Width = this.endPoint.X - this.startPoint.X;                    }                    else                    {                        this.rectangle.X = this.endPoint.X;                        this.rectangle.Width = this.startPoint.X - this.endPoint.X;                    }                    if (this.startPoint.Y < this.endPoint.Y)                    {                        this.rectangle.Y = this.startPoint.Y;                        this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;                    }                    else                    {                        this.rectangle.Y = this.endPoint.Y;                        this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;                    }                    this.documentWorkspace.Refresh();                }                //// 直线添加                //if (this.pointKtype == 2 && drawedStartPoint)                //{                //    endPoint = new Point((int)point1.X, (int)point1.Y);                //    this.documentWorkspace.Refresh();                //}            }        }        /// <summary>        /// 鼠标抬起        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void onMouseUp(object sender, MouseEventArgs e)        {            // 换算后的点            PointF point1 = documentWorkspace.GetScalePoint(e.Location);            if (point1.X <= this.documentWorkspace.CompositionSurface.Width            && point1.X >= 0            && point1.Y >= 0            && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }            else            {                if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12                    || this.pointKtype == 24 || this.pointKtype == 23 || this.pointKtype == 22)                {                    //if (point1.X >= this.documentWorkspace.CompositionSurface.Width)                    //    point1.X = this.documentWorkspace.CompositionSurface.Width - 1;                    //if (point1.X < 0)                    //    point1.X = 0;                    //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height)                    //    point1.Y = this.documentWorkspace.CompositionSurface.Height - 1;                    //if (point1.Y < 0)                    //    point1.Y = 0;                }                else                    return;            }            if (e.Button == MouseButtons.Right)            {                // 折线删除                if ((this.pointKtype == 11 || this.pointKtype == 21) && pointArray.Count > 1)                {                    pointArray.Add(new Point((int)point1.X, (int)point1.Y));                    endPoint = new Point((int)point1.X, (int)point1.Y);                    List<PointF> pointFArray = new List<PointF>();                    foreach (var item in pointArray)                    {                        pointFArray.Add(new PointF(item.X, item.Y));                    }                    if (this.pointKtype == 21)                        this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonAdd(this.documentWorkspace.PhaseModels[0].mat, phaseColor.ToArgb(), pointFArray);                    else                        this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFArray);                    this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);                    ////保存处理后的图片                    //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);                    //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);                    //Graphics graphics = Graphics.FromImage(newBit);                    //Draw(graphics);                    //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);                    this.rectangle.X = -1;                    this.rectangle.Y = -1;                    this.rectangle.Width = 0;                    this.rectangle.Height = 0;                    pointArray.Clear();                    startPoint = new Point(-1, -1);                    drawedStartPoint = false;                    endPoint = new Point(-1, -1);                    this.pointKtype = 0;                    this.documentWorkspace.Refresh();                }                //// 折线添加                //if (this.pointKtype == 1 && pointArray.Count > 1)                //{                //    pointArray.Add(new Point((int)point1.X, (int)point1.Y));                //    endPoint = new Point((int)point1.X, (int)point1.Y);                //    //List<Point> alPoints = this.findAllPoints(pointArray);                //    //if (alPoints.Count > 1)                //    //    analyzePoints.Add(alPoints.ToArray());                //    //保存处理后的图片                //    Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);                //    Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);                //    Graphics graphics = Graphics.FromImage(newBit);                //    Draw(graphics);                //    this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);                //    this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);                //    pointArray.Clear();                //    startPoint = new Point(-1, -1);                //    drawedStartPoint = false;                //    endPoint = new Point(-1, -1);                //    this.pointKtype = 0;                //    this.documentWorkspace.Refresh();                //}            }            if (e.Button == MouseButtons.Left)            {                // 圆形删除/椭圆删除                if ((this.pointKtype == 14 || this.pointKtype == 12                    || this.pointKtype == 24 || this.pointKtype == 22) && drawedStartPoint)                {                    endPoint = new Point((int)point1.X, (int)point1.Y);                    if (this.startPoint.X < this.endPoint.X)                    {                        this.rectangle.X = this.startPoint.X;                        this.rectangle.Width = this.endPoint.X - this.startPoint.X;                    }                    else                    {                        this.rectangle.X = this.endPoint.X;                        this.rectangle.Width = this.startPoint.X - this.endPoint.X;                    }                    if (this.startPoint.Y < this.endPoint.Y)                    {                        this.rectangle.Y = this.startPoint.Y;                        this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;                    }                    else                    {                        this.rectangle.Y = this.endPoint.Y;                        this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;                    }                    if (this.pointKtype == 14 || this.pointKtype == 24)                        if (this.pointKtype == 24)                            this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.EllipseAdd(this.documentWorkspace.PhaseModels[0].mat, phaseColor.ToArgb(), this.rectangle);                        else                            this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);                    else                    {                        if (this.pointKtype == 22)                            this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.EllipseAdd(this.documentWorkspace.PhaseModels[0].mat, phaseColor.ToArgb()                                     , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));                        else                            this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat                                     , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));                    }                    this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);                    this.rectangle.X = -1;                    this.rectangle.Y = -1;                    this.rectangle.Width = 0;                    this.rectangle.Height = 0;                    startPoint = new Point(-1, -1);                    drawedStartPoint = false;                    endPoint = new Point(-1, -1);                    this.pointKtype = 0;                    this.documentWorkspace.Refresh();                }                // 矩形删除                if ((this.pointKtype == 13 || this.pointKtype == 23) && drawedStartPoint)                {                    endPoint = new Point((int)point1.X, (int)point1.Y);                    if (this.startPoint.X < this.endPoint.X)                    {                        this.rectangle.X = this.startPoint.X;                        this.rectangle.Width = this.endPoint.X - this.startPoint.X;                    }                    else                    {                        this.rectangle.X = this.endPoint.X;                        this.rectangle.Width = this.startPoint.X - this.endPoint.X;                    }                    if (this.startPoint.Y < this.endPoint.Y)                    {                        this.rectangle.Y = this.startPoint.Y;                        this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;                    }                    else                    {                        this.rectangle.Y = this.endPoint.Y;                        this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;                    }                    if (this.pointKtype == 23)                        this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleAdd(this.documentWorkspace.PhaseModels[0].mat, phaseColor.ToArgb(), this.rectangle);                    else                        this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);                    this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);                    ////保存处理后的图片                    //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);                    //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);                    //Graphics graphics = Graphics.FromImage(newBit);                    //Draw(graphics);                    //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);                    this.rectangle.X = -1;                    this.rectangle.Y = -1;                    this.rectangle.Width = 0;                    this.rectangle.Height = 0;                    startPoint = new Point(-1, -1);                    drawedStartPoint = false;                    endPoint = new Point(-1, -1);                    this.pointKtype = 0;                    this.documentWorkspace.Refresh();                }                // 折线添加/折线删除                if (this.pointKtype == 1 || this.pointKtype == 11 || this.pointKtype == 21)                {                    pointArray.Add(new Point((int)point1.X, (int)point1.Y));                    if (!drawedStartPoint)                    {                        drawedStartPoint = true;                        startPoint = new Point((int)point1.X, (int)point1.Y);                    }                    this.documentWorkspace.Refresh();                }                //// 直线添加                //if (this.pointKtype == 2 && drawedStartPoint)                //{                //    endPoint = new Point((int)point1.X, (int)point1.Y);                //    //保存处理后的图片                //    Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);                //    Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);                //    Graphics graphics = Graphics.FromImage(newBit);                //    Draw(graphics);                //    this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);                //    this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);                //    startPoint = new Point(-1, -1);                //    drawedStartPoint = false;                //    endPoint = new Point(-1, -1);                //    this.pointKtype = 0;                //    this.documentWorkspace.Refresh();                //}            }        }        #endregion        /// <summary>        /// surfaceBox双击事件        /// 目前是参考AxioVision        /// 应该是把每次选的点都取最高和最低的BGR        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private unsafe void pictureBox1_Click(object sender, EventArgs e)        {        }        /// <summary>        /// 画布绘制        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Panel_Paint(object sender, PaintEventArgs e)        {            if (this.documentWorkspace.CompositionSurface != null)            {                //                // 以下是计算绘制图片的位置和大小并绘制图片                //                System.Drawing.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;                //                // 以下是绘制网格、标注、测量、视场等开始                //                e.Graphics.TranslateTransform(x, y);                e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);                //if (this.checkBox4_0.Checked)//显示网格                Draw(e.Graphics);                e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);                e.Graphics.TranslateTransform(-x, -y);            }        }        /// <summary>        /// 绘制        /// </summary>        private void Draw(Graphics g)        {            // 抗锯齿            g.SmoothingMode = SmoothingMode.AntiAlias;            //圆形删除/椭圆删除            if ((this.pointKtype == 14 || this.pointKtype == 12                || this.pointKtype == 24 || this.pointKtype == 22) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))            {                Pen pen = new Pen(Color.FromArgb(255, 255 - this.phaseColor.R, 255 - this.phaseColor.G, 255 - this.phaseColor.B), 1);                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;                if (this.pointKtype == 14 || this.pointKtype == 24)                    g.DrawEllipse(pen, this.rectangle);                else                    g.DrawEllipse(pen, new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));                pen.Dispose();            }            //矩形删除            if ((this.pointKtype == 13 || this.pointKtype == 23) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))            {                Pen pen = new Pen(Color.FromArgb(255, 255 - this.phaseColor.R, 255 - this.phaseColor.G, 255 - this.phaseColor.B), 1);                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;                g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));                pen.Dispose();            }            // 折线删除            if ((this.pointKtype == 11 || this.pointKtype == 21) && pointArray.Count >= 2)            {                Pen pen = new Pen(Color.FromArgb(255, 255 - this.phaseColor.R, 255 - this.phaseColor.G, 255 - this.phaseColor.B), 1);                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;                g.DrawPolygon(pen, pointArray.ToArray());                pen.Dispose();            }            //// 直线添加            //if (this.pointKtype == 2 && drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)            //{            //    Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);            //    //pen.DashStyle = DashStyle.Dash;            //    g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);            //    pen.Dispose();            //}            //// 折线添加            //if (this.pointKtype == 1 && pointArray.Count >= 2)            //{            //    Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);            //    g.DrawLines(pen, pointArray.ToArray());            //    pen.Dispose();            //}        }        private void InitializeLanguageText()        {            this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");            this.button9.Text = PdnResources.GetString("CommonAction.Undo");            this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");            this.button1.Text = PdnResources.GetString("Form.OkButton.Text");            this.groupBox2.Text = "操作按钮";// PdnResources.GetString("Menu.BinaryAction.Text");            this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");            this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");            this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");            this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");            this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";            this.button4.Text = "圆形添加";// PdnResources.GetString("Menu.Lineadd.text");            this.button3.Text = "多边形添加";// PdnResources.GetString("Menu.Polylineadd.text");            this.button42.Text = "椭圆添加";// PdnResources.GetString("Menu.Lineadd.text");            this.button32.Text = "矩形添加";// PdnResources.GetString("Menu.Polylineadd.text");            this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");            this.Text = "修改孔隙";// PdnResources.GetString("Menu.filter.text");        }        private void InitializeComponent()        {            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.button9 = new System.Windows.Forms.Button();            this.button2 = new System.Windows.Forms.Button();            this.button1 = new System.Windows.Forms.Button();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.button8 = new System.Windows.Forms.Button();            this.trackBar1 = new System.Windows.Forms.TrackBar();            this.button7 = new System.Windows.Forms.Button();            this.trackBar2 = new PaintDotNet.CustomControl.TriangleTrackBar();            this.button6 = new System.Windows.Forms.Button();            this.textBox1 = new System.Windows.Forms.TextBox();            this.button5 = new System.Windows.Forms.Button();            this.label1 = new System.Windows.Forms.Label();            this.button4 = new System.Windows.Forms.Button();            this.button3 = new System.Windows.Forms.Button();            this.button42 = new System.Windows.Forms.Button();            this.button32 = new System.Windows.Forms.Button();            this.groupBox7 = new System.Windows.Forms.GroupBox();            this.groupBox1.SuspendLayout();            this.groupBox2.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();            this.SuspendLayout();            //             // groupBox1            //             this.groupBox1.Controls.Add(this.button9);            this.groupBox1.Controls.Add(this.button2);            this.groupBox1.Controls.Add(this.button1);            this.groupBox1.Location = new System.Drawing.Point(12, 12);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(808, 45);            this.groupBox1.TabIndex = 0;            this.groupBox1.TabStop = false;            //             // button9            //             this.button9.Location = new System.Drawing.Point(468, 13);            this.button9.Name = "button9";            this.button9.Size = new System.Drawing.Size(91, 26);            this.button9.TabIndex = 3;            this.button9.UseVisualStyleBackColor = true;            this.button9.Visible = false;            //             // button2            //             this.button2.Location = new System.Drawing.Point(694, 13);            this.button2.Name = "button2";            this.button2.Size = new System.Drawing.Size(91, 26);            this.button2.TabIndex = 1;            this.button2.UseVisualStyleBackColor = true;            this.button2.Click += new System.EventHandler(this.button2_Click);            //             // button1            //             this.button1.Location = new System.Drawing.Point(582, 13);            this.button1.Name = "button1";            this.button1.Size = new System.Drawing.Size(91, 26);            this.button1.TabIndex = 0;            this.button1.UseVisualStyleBackColor = true;            this.button1.Click += new System.EventHandler(this.button1_Click);            //             // groupBox2            //             this.groupBox2.Controls.Add(this.button8);            this.groupBox2.Controls.Add(this.trackBar1);            this.groupBox2.Controls.Add(this.button7);            this.groupBox2.Controls.Add(this.trackBar2);            this.groupBox2.Controls.Add(this.button6);            this.groupBox2.Controls.Add(this.textBox1);            this.groupBox2.Controls.Add(this.button5);            this.groupBox2.Controls.Add(this.label1);            this.groupBox2.Controls.Add(this.button4);            this.groupBox2.Controls.Add(this.button3);            this.groupBox2.Controls.Add(this.button42);            this.groupBox2.Controls.Add(this.button32);            this.groupBox2.Location = new System.Drawing.Point(12, 63);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(233, 199);            this.groupBox2.TabIndex = 1;            this.groupBox2.TabStop = false;            //             // button8            //             this.button8.Location = new System.Drawing.Point(134, 151);            this.button8.Name = "button8";            this.button8.Size = new System.Drawing.Size(73, 26);            this.button8.TabIndex = 7;            this.button8.UseVisualStyleBackColor = true;            this.button8.Click += new System.EventHandler(this.button8_Click);            //             // trackBar1            //             this.trackBar1.AutoSize = false;            this.trackBar1.Location = new System.Drawing.Point(107, 69);            this.trackBar1.Maximum = 50;            this.trackBar1.Minimum = 1;            this.trackBar1.Name = "trackBar1";            this.trackBar1.Size = new System.Drawing.Size(104, 31);            this.trackBar1.TabIndex = 21;            this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;            this.trackBar1.Value = 1;            this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);            this.trackBar1.Visible = false;            //             // button7            //             this.button7.Location = new System.Drawing.Point(27, 151);            this.button7.Name = "button7";            this.button7.Size = new System.Drawing.Size(73, 26);            this.button7.TabIndex = 6;            this.button7.UseVisualStyleBackColor = true;            this.button7.Click += new System.EventHandler(this.button7_Click);            //             // trackBar2            //             this.trackBar2.Location = new System.Drawing.Point(108, 69);            this.trackBar2.Maximum = 50;            this.trackBar2.Minimum = 1;            this.trackBar2.Name = "trackBar2";            this.trackBar2.Size = new System.Drawing.Size(102, 24);            this.trackBar2.TabIndex = 20;            this.trackBar2.Value = 1;            this.trackBar2.Visible = false;            //             // button6            //             this.button6.Location = new System.Drawing.Point(134, 117);            this.button6.Name = "button6";            this.button6.Size = new System.Drawing.Size(73, 26);            this.button6.TabIndex = 5;            this.button6.UseVisualStyleBackColor = true;            this.button6.Click += new System.EventHandler(this.button6_Click);            //             // textBox1            //             this.textBox1.Location = new System.Drawing.Point(68, 69);            this.textBox1.Name = "textBox1";            this.textBox1.Size = new System.Drawing.Size(32, 21);            this.textBox1.TabIndex = 19;            this.textBox1.Text = "1";            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);            this.textBox1.Visible = false;            //             // button5            //             this.button5.Location = new System.Drawing.Point(27, 117);            this.button5.Name = "button5";            this.button5.Size = new System.Drawing.Size(73, 26);            this.button5.TabIndex = 4;            this.button5.UseVisualStyleBackColor = true;            this.button5.Click += new System.EventHandler(this.button5_Click);            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(28, 73);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(0, 12);            this.label1.TabIndex = 18;            this.label1.Visible = false;            //             // button4            //             this.button4.Location = new System.Drawing.Point(135, 31);            this.button4.Name = "button4";            this.button4.Size = new System.Drawing.Size(73, 26);            this.button4.TabIndex = 3;            this.button4.UseVisualStyleBackColor = true;            this.button4.Click += new System.EventHandler(this.button4_Click);            //             // button3            //             this.button3.Location = new System.Drawing.Point(28, 31);            this.button3.Name = "button3";            this.button3.Size = new System.Drawing.Size(73, 26);            this.button3.TabIndex = 2;            this.button3.UseVisualStyleBackColor = true;            this.button3.Click += new System.EventHandler(this.button3_Click);            //             // button42            //             this.button42.Location = new System.Drawing.Point(135, 69);            this.button42.Name = "button42";            this.button42.Size = new System.Drawing.Size(73, 26);            this.button42.TabIndex = 32;            this.button42.UseVisualStyleBackColor = true;            this.button42.Click += new System.EventHandler(this.button42_Click);            //             // button32            //             this.button32.Location = new System.Drawing.Point(28, 69);            this.button32.Name = "button32";            this.button32.Size = new System.Drawing.Size(73, 26);            this.button32.TabIndex = 22;            this.button32.UseVisualStyleBackColor = true;            this.button32.Click += new System.EventHandler(this.button32_Click);            //             // groupBox7            //             this.groupBox7.Location = new System.Drawing.Point(251, 63);            this.groupBox7.Name = "groupBox7";            this.groupBox7.Size = new System.Drawing.Size(569, 502);            this.groupBox7.TabIndex = 1;            this.groupBox7.TabStop = false;            //             // MetalsHoleAreaEditingDialog            //             this.ClientSize = new System.Drawing.Size(832, 577);            this.Controls.Add(this.groupBox2);            this.Controls.Add(this.groupBox7);            this.Controls.Add(this.groupBox1);            this.MaximizeBox = false;            this.MinimizeBox = false;            this.Name = "MetalsHoleAreaEditingDialog";            this.groupBox1.ResumeLayout(false);            this.groupBox2.ResumeLayout(false);            this.groupBox2.PerformLayout();            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();            this.ResumeLayout(false);        }        /// <summary>        /// 多边形添加        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button3_Click(object sender, EventArgs e)        {            pointArray.Clear();            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 21;            this.documentWorkspace.Refresh();            //pointArray.Clear();            //startPoint = new Point(-1, -1);            //drawedStartPoint = false;            //endPoint = new Point(-1, -1);            //pointKtype = 21;            //this.documentWorkspace.Refresh();        }        /// <summary>        /// 圆线添加        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button4_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 22;            this.documentWorkspace.Refresh();        }        /// <summary>        /// 矩形添加        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button32_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 23;            this.documentWorkspace.Refresh();        }        /// <summary>        /// 椭圆添加        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button42_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 24;            this.documentWorkspace.Refresh();        }        ///// <summary>        ///// 折线添加        ///// </summary>        ///// <param name="sender"></param>        ///// <param name="e"></param>        //private void button3_Click(object sender, EventArgs e)        //{        //    pointArray.Clear();        //    startPoint = new Point(-1, -1);        //    drawedStartPoint = false;        //    endPoint = new Point(-1, -1);        //    pointKtype = 1;        //    this.documentWorkspace.Refresh();        //}        ///// <summary>        ///// 直线添加        ///// </summary>        ///// <param name="sender"></param>        ///// <param name="e"></param>        //private void button4_Click(object sender, EventArgs e)        //{        //    startPoint = new Point(-1, -1);        //    drawedStartPoint = false;        //    endPoint = new Point(-1, -1);        //    pointKtype = 2;        //    this.documentWorkspace.Refresh();        //}        private void InitCommonButtonEvent()        {            this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);            this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);            this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);            this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);            this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);            this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);        }        private void zoomInButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomIn();        }        private void zoomOutButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomOut();        }        private void zoomToWindowButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;        }        private void actualSizeButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;            this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;        }        private void pointerButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;            this.documentWorkspace.Cursor = Cursors.Default;        }        private void mobileModeButton_Click(object sender, EventArgs e)        {            this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;        }        //确定按钮点击事件        private void button1_Click(object sender, EventArgs e)        {            this.phaseMatCopy = this.documentWorkspace.PhaseModels[0].mat;            this.DialogResult = DialogResult.OK;            this.Close();        }        /// <summary>        /// 用于get处理后的图像        /// </summary>        public Mat PhaseMat        {            get            {                return this.phaseMatCopy;            }            //set            //{            //    this.phaseMatCopy = value;            //}        }        /// <summary>        /// 矩形删除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button7_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 13;            this.documentWorkspace.Refresh();        }        /// <summary>        /// 椭圆删除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button8_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 14;            this.documentWorkspace.Refresh();        }        /// <summary>        /// 圆形删除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button6_Click(object sender, EventArgs e)        {            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 12;            this.documentWorkspace.Refresh();        }        /// <summary>        /// 多边形删除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button5_Click(object sender, EventArgs e)        {            pointArray.Clear();            startPoint = new Point(-1, -1);            drawedStartPoint = false;            endPoint = new Point(-1, -1);            this.rectangle.X = -1;            this.rectangle.Y = -1;            this.rectangle.Width = 0;            this.rectangle.Height = 0;            this.pointKtype = 11;            this.documentWorkspace.Refresh();        }        private void button2_Click(object sender, EventArgs e)        {            this.Close();        }        /// <summary>        /// 线宽改变        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox1_TextChanged(object sender, EventArgs e)        {            int valueT;            if (!int.TryParse(textBox1.Text, out valueT))                return;            if (this.trackBar1.Minimum > valueT)                valueT = this.trackBar1.Minimum;            if (this.trackBar1.Maximum < valueT)                valueT = this.trackBar1.Maximum;            this.trackBar1.Value = valueT;            //this.textBox1.Text = valueT + "";            this.documentWorkspace.Refresh();        }        private void trackBar1_Scroll(object sender, EventArgs e)        {            this.textBox1.Text = this.trackBar1.Value + "";            this.documentWorkspace.Refresh();        }    }}
 |