12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace OTSMeasureApp
- {
-
- public class CRectangleGDIObject /*: CRectangleGDIObject */// 同样的方式可以从ADraggableGDIObject生成其它图形的继承角类,比如矩形,三形等等。。
- {
- public CRectangleGDIObject()
- {
-
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
- /// <summary>
- /// 创建图形
- /// </summary>
- /// <param name="startx">X位置</param>
- /// <param name="starty">Y位置</param>
- /// <param name="width">宽度</param>
- /// <param name="height">高度</param>
- /// <param name="cType">图形类型:createType=0 圆角矩形 createType=1 圆形 createType=2 文字</param>
- /// <param name="content">文字内容</param>
- public CRectangleGDIObject(float startx, float starty, float width, float height, CreateRectangleType cType, string content, string name)
- {
- var rec = new RectangleF(startx, starty, width, height);
- m_OrigineRegionF = rec;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- strContent = content;
- NameOrHoleName = name;
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
- public CRectangleGDIObject(RectangleF rect, CreateRectangleType cType)
- {
-
- m_OrigineRegionF = rect;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- ID = System.Guid.NewGuid().ToString();
- //startPoint = new PointF(rect.Left, rect.Top);
- //EndPoint = new PointF(rect.Right, rect.Bottom);
- OTSX = -1;
- OTSY = -1;
- }
- public CRectangleGDIObject(RectangleF rect, CreateRectangleType cType, string name)
- {
-
- m_OrigineRegionF = rect;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- NameOrHoleName = name;
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
-
- public CRectangleGDIObject(RectangleF rect, CreateRectangleType cType, ShapeType shape, string name, Color selColor)
- {
-
- m_OrigineRegionF = rect;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- NameOrHoleName = name;
- Shape = shape;
- SelColor = selColor;
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
- public CRectangleGDIObject(RectangleF rectMeasure, CreateRectangleType cType, ShapeType shape, string name, string sampleName, Color selColor)
- {
-
- m_OrigineRegionF = rectMeasure;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- NameOrHoleName = name;
- Shape = shape;
- SelColor = selColor;
-
- SampleName = sampleName;
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
- //绘制帧图
- public CRectangleGDIObject(RectangleF rectSingle, CreateRectangleType cType, string name, string sampleName, Color selColor)
- {
-
- m_OrigineRegionF = rectSingle;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- NameOrHoleName = name;
- Shape = 0;
- SelColor = selColor;
- SampleName = sampleName;
- ID = System.Guid.NewGuid().ToString();
- OTSX = -1;
- OTSY = -1;
- }
- //绘制帧图
- public CRectangleGDIObject(RectangleF rectField, int OTSx, int OTSy, CreateRectangleType cType, string name, string sampleName, Color selColor)
- {
-
- m_OrigineRegionF = rectField;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- NameOrHoleName = name;
- Shape = 0;
- SelColor = selColor;
- SampleName = sampleName;
- ID = System.Guid.NewGuid().ToString();
- OTSX = OTSx;
- OTSY = OTSy;
- }
- /// <summary>
- /// 获取样品孔中BSE图像
- /// </summary>
- /// <param name="rect">位置大小</param>
- /// <param name="sampleHoleName">所在样品孔名称</param>
- /// <param name="bseImage">图像信息</param>
- /// <param name="bseImageWitdh">图像宽度</param>
- /// <param name="bseImageHeight">图像高度</param>
- /// <param name="drawImageLocation">图像开始位置</param>
- /// <param name="cType">绘制类型</param>
- public CRectangleGDIObject(RectangleF rect, int OTSx, int OTSy, string sampleName, string sampleHoleName, float bseImageWitdh, float bseImageHeight, CreateRectangleType cType)
- {
-
- m_OrigineRegionF = rect;
- SetInitRegionF(m_OrigineRegionF);
- NameOrHoleName = sampleHoleName;
- SampleName = sampleName;
- //生成编号
- ID = System.Guid.NewGuid().ToString();
- //图像信息
- //BSEImage = bseImage;
- //图像宽度
- BSEImageWitdh = bseImageWitdh;
- //图像高度
- BSEImageHeight = bseImageHeight;
- //图像位置
- BSEImageLocation = rect.Location;
- OTSX = OTSx;
- OTSY = OTSy;
- //绘制类型
- CreateType = cType;
- }
- public CRectangleGDIObject(RectangleF rect, Point ImgPoint, float m_Multiple, CreateRectangleType cType)
- {
- m_OrigineRegionF = rect;
- SetInitRegionF(m_OrigineRegionF);
- CreateType = cType;
- ID = System.Guid.NewGuid().ToString();
-
- OTSX = -1;
- OTSY = -1;
- }
- /// <summary>
- /// 获取多边形点集合
- /// </summary>
- /// <param name="mPoint"></param>
- /// <param name="cType"></param>
- public CRectangleGDIObject(List<PointF> mPoint, CreateRectangleType cType, ShapeType shape, string name, string sampleName, Color selColor)
- {
- ID = System.Guid.NewGuid().ToString();
- this.SetOriginalPolygonPointFList(mPoint);
- NameOrHoleName = name;
- SampleName = sampleName;
- CreateType = cType;
- Shape = shape;
- SelColor = selColor;
-
- }
- #region 变量重写
- public virtual void OnPaint(PaintEventArgs e)
- {
- if (createType == CreateRectangleType.SampleBackGround_Rectangle)
- {
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.RoundRectangleColor);
- Color myColor = ColorTranslator.FromHtml(ColorStr);
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- GraphicsPath grPath = CreateRoundedRectanglePath(m_RegionF, 20);
- e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
- e.Graphics.FillPath(sampleBrush, grPath);
- e.Graphics.DrawPath(Pens.Black, grPath);
- }
- //样品台-圆形
- else if (createType == CreateRectangleType.SampleBackGround_Circle)
- {
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleBackGroundColor);
- Color myColor = ColorTranslator.FromHtml(ColorStr);
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- e.Graphics.FillEllipse(sampleBrush, m_RegionF);
- e.Graphics.DrawEllipse(Pens.Black, m_RegionF);
- }
- //圆形
- else if (createType == CreateRectangleType.Circle)
- {
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- e.Graphics.FillEllipse(sampleBrush, m_RegionF);
- e.Graphics.DrawEllipse(Pens.Black, m_RegionF);
- }
- //文字
- else if (createType == CreateRectangleType.Text)
- {
- //设置文字对齐方式
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- //文字颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FontColor);
- Color myColor = ColorTranslator.FromHtml(ColorStr);
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, Color.Black));
- //字体大小 根据样品孔Rectangle大小
- float fontSize = m_RegionF.Width / 4;
- Font font = new Font("宋体", fontSize, FontStyle.Regular);
- if (fontSize == 0)
- {
- font = new Font("宋体", 5, FontStyle.Regular);
- }
- //消除锯齿
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- //绘制文字阴影
- RectangleF rectFont = m_RegionF;
- rectFont.X += 2;
- rectFont.Y += 2;
- e.Graphics.DrawString(strContent, font, solidBrush, rectFont, sf);
- e.Graphics.DrawString(strContent, font, sampleBrush, m_RegionF, sf);
- }
- //矩形
- else if (createType == CreateRectangleType.Rectangle)
- {
- Color myColor = System.Drawing.Color.White;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- e.Graphics.FillRectangle(sampleBrush, m_RegionF);
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(Pens.Black, m_Region);
- }
- //选择样品台
- else if (createType == CreateRectangleType.SelectSample)
- {
- Color myColor = selColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.AssumeLinear;//再加一点
- if (Shape == 0)
- {
- e.Graphics.FillEllipse(sampleBrush, m_RegionF);
- e.Graphics.DrawEllipse(Pens.Black, m_RegionF);
- }
- else
- {
- e.Graphics.FillRectangle(sampleBrush, m_RegionF);
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(Pens.Black, m_Region);
- }
- }
- //测试区域
- else if (createType == CreateRectangleType.MeasureArea)
- {
- Color myColor = selColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen p = new Pen(myColor, 1);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- if (Shape == 0)
- {
- e.Graphics.DrawEllipse(p, m_RegionF);
- }
- else
- {
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(p, m_Region);
- }
- }
- //绘制帧图 直线
- else if (createType == CreateRectangleType.SingleLine)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
- Color myColor = ColorTranslator.FromHtml(ColorStr);
- //设置画笔
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(sampleBrush, 0.0001f);
- //未抗锯齿
- e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
- e.Graphics.InterpolationMode = InterpolationMode.Default;
- e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
- //设置直线位置与尺寸
- PointF startPointF = new PointF(startPoint.X, startPoint.Y);
- PointF endPointF = new PointF(endPoint.X, endPoint.Y);
- //度量单位
- e.Graphics.PageUnit = GraphicsUnit.Display;
- e.Graphics.DrawLine(pen, startPointF, endPointF);
- }
- //绘制标样
- else if (createType == CreateRectangleType.SpecimenRectangle)
- {
- Color myColor = System.Drawing.Color.Black;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(sampleBrush, 0.0001f);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(pen, m_Region);
- e.Graphics.FillRectangle(sampleBrush, m_Region);
- }
- //绘制标样
- else if (createType == CreateRectangleType.SpecimenCircle)
- {
- Color myColor = System.Drawing.Color.Black;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(sampleBrush, 0.0001f);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- e.Graphics.DrawEllipse(pen, m_RegionF);
- e.Graphics.FillEllipse(sampleBrush, m_RegionF);
- }
- //绘制帧图
- else if (createType == CreateRectangleType.FieldRectangle)
- {
- Color myColor = SelColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(sampleBrush, 0.01f);
- e.Graphics.SmoothingMode = SmoothingMode.Default;
- //设置直线位置与尺寸
- PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
- PointF endPointF = new PointF(m_RegionF.Right, m_RegionF.Bottom);
- float fontSize = m_RegionF.Width / 4;
- Font font;
- if (fontSize == 0)
- {
- font = new Font("宋体", 5, FontStyle.Regular);
- }
- else
- {
- font = new Font("宋体", fontSize, FontStyle.Regular);
- }
-
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- e.Graphics.DrawString(m_sequenceNum.ToString(), font, sampleBrush, m_RegionF, sf);
- //绘制帧图
- e.Graphics.DrawRectangle(pen, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
- }
- //绘制颗粒
- else if (createType == CreateRectangleType.ParticleLine)
- {
- Color myColor = LineColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(sampleBrush, 0.01f);
- e.Graphics.SmoothingMode = SmoothingMode.Default;
- //设置直线位置与长度
- PointF startPointF = LineStartPoint;
- float length = LineLength;
- PointF endPointF = new PointF(startPointF.X + length, startPointF.Y);
- e.Graphics.DrawLine(pen, startPointF, endPointF);
- }
- //矩形
- else if (createType == CreateRectangleType.ParticleAreaRectangle)
- {
- Color myColor = System.Drawing.Color.White;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(Pens.Black, m_Region);
- }
- //绘制样品孔BSE图像
- else if (createType == CreateRectangleType.DrawFrameOfHoleBSEImage)
- {
- Color myColor = System.Drawing.Color.White;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- //设置直线位置与尺寸
- PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
- PointF endPointF = new PointF(m_RegionF.Right + 2, m_RegionF.Bottom + 2);
- //绘制样品孔中图像信息
- if (BSEImage != null)
- {
- e.Graphics.DrawImage(BSEImage, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
- }
- }
- else if (createType == CreateRectangleType.DrawSEMCenterPoint)
- {
- Color myColor = System.Drawing.Color.Red;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- //X轴线
- PointF startPointX = semCenterPoint;
- startPointX.X = startPointX.X - 3;
- PointF endPointX = semCenterPoint;
- endPointX.X = endPointX.X + 3;
- //Y轴线
- PointF startPointY = semCenterPoint;
- startPointY.Y = startPointY.Y - 3;
- PointF endPointY = semCenterPoint;
- endPointY.Y = endPointY.Y + 3;
- //绘制XY轴交叉线+
- Pen pen = new Pen(sampleBrush, 0.0001f);
- e.Graphics.DrawLine(pen, startPointX, endPointX);
- e.Graphics.DrawLine(pen, startPointY, endPointY);
- }
- //绘制BSE标记
- else if (createType == CreateRectangleType.DrawBSEElementSignPoint)
- {
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- Pen pen = new Pen(sampleBrush, 2f);
- int X = (int)m_OrigineRegionF.X;
- int Y = (int)m_OrigineRegionF.Y;
- e.Graphics.DrawLine(pen, new Point(X - 8, Y), new Point(X + 8, Y));
- e.Graphics.DrawLine(pen, new Point(X, Y - 8), new Point(X, Y + 8));
- }
- //绘制多边形测量区域
- else if (createType == CreateRectangleType.Polygon)
- {
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- Color myColor = selColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen = new Pen(myColor, 1);
- if (GetPolygonPointFList().Count > 0)
- {
- List<PointF> PolygonPointF = new List<PointF>();
- foreach (var item in m_PolygonPoints)
- {
- PolygonPointF.Add(item);
- }
- if (PolygonDrawingEndPoint.X != 0 && PolygonDrawingEndPoint.Y != 0)
- {
- PolygonPointF.Add(PolygonDrawingEndPoint);
- }
- e.Graphics.DrawLines(pen, PolygonPointF.ToArray());
-
- }
- }//多边形测量区域完成标识
- else if (createType == CreateRectangleType.DrawPolygonFinish)
- {
- Color myColor = selColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- Pen pen = new Pen(myColor, 1);
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawRectangle(pen, m_Region);
- }
- //绘制多边形测量区域
- else if (createType == CreateRectangleType.CircleByThreePoints)
- {
- Color myColor = selColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen p = new Pen(myColor, 1);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- var m_Region = new Rectangle();
- m_Region.X = (int)m_RegionF.X;
- m_Region.Y = (int)m_RegionF.Y;
- m_Region.Width = (int)m_RegionF.Width;
- m_Region.Height = (int)m_RegionF.Height;
- e.Graphics.DrawEllipse(p, m_Region);
- }
- }
- public Image BSEImage
- {
- get { return bseImage; }
- set { bseImage = value; }
- }
- public float BSEImageWitdh
- {
- get { return bseImageWidth; }
- set { bseImageWidth = value; }
- }
- public float BSEImageHeight
- {
- get { return bseImageHeight; }
- set { bseImageHeight = value; }
- }
- public PointF BSEImageLocation
- {
- get { return bseImageLocation; }
- set { bseImageLocation = value; }
- }
- public Color LineColor
- {
- get { return lineColor; }
- set { lineColor = value; }
- }
- public float LineLength
- {
- get { return lineLength; }
- set { lineLength = value; }
- }
- public PointF LineStartPoint
- {
- get { return lineStartPoint; }
- set { lineStartPoint = value; }
- }
- //public PointF SEMCenterPoint
- //{
- // get { return semCenterPoint; }
- // set { semCenterPoint = value; }
- //}
- public int OTSX
- {
- get { return otsX; }
- set { otsX = value; }
- }
- public int OTSY
- {
- get { return otsY; }
- set { otsY = value; }
- }
- public CreateRectangleType CreateType
- {
- get { return createType; }
- set { createType = value; }
- }
- public ShapeType Shape
- {
- get { return shape; }
- set { shape = value; }
- }
- public Color SelColor
- {
- get { return selColor; }
- set { selColor = value; }
- }
- public string NameOrHoleName//holename when they are not field rectangle gdi object.
- {
- get { return nameOrHoleName; }
- set { nameOrHoleName = value; }
- }
- public string ID
- {
- get { return id; }
- set { id = value; }
- }
- public string SampleName
- {
- get { return sampleName; }
- set { sampleName = value; }
- }
- public int SampleCount
- {
- get { return sampleCount; }
- set { sampleCount = value; }
- }
- public string StrContent
- {
- get { return strContent; }
- set { strContent = value; }
- }
- public RectangleF GetZoomedRegion
- {
-
- get {
- var m_Region = new RectangleF();
- m_Region.X = m_RegionF.X;
- m_Region.Y = m_RegionF.Y;
- m_Region.Width = m_RegionF.Width;
- m_Region.Height = m_RegionF.Height;
- return m_Region;
- }
-
- }
- public List<PointF> GetVertexPoints()
- {
- List<PointF> vertexPoint = new List<PointF>();
- var region = this.GetZoomedRegionF();
- vertexPoint.Add(region.Location);
- vertexPoint.Add(new PointF(region.X, region.Y + region.Height));
- vertexPoint.Add(new PointF(region.X + region.Width, region.Y));
- vertexPoint.Add(new PointF(region.X + region.Width, region.Y + region.Height));
- return vertexPoint;
- }
- public RectangleF GetZoomedRegionF()
- {
- return m_RegionF;
- }
- public void SetInitRegionF(RectangleF OrigineRegionF)//not zoomed regine value
- {
-
- float x1, y1;
- x1 = OrigineRegionF.X * m_zoomNum + m_refPoint.X;
- y1 = OrigineRegionF.Y * m_zoomNum + m_refPoint.Y;
- float w1, h1;
- w1 = OrigineRegionF.Width * m_zoomNum;
- h1 = OrigineRegionF.Height * m_zoomNum;
- m_OrigineRegionF = OrigineRegionF;
- m_RegionF = new RectangleF(x1, y1, w1, h1);
- }
- internal void SetZoomedRegionF(RectangleF scaleRectangleF)
- {
- float x1, y1;
- x1 = (scaleRectangleF.X-m_refPoint.X) / m_zoomNum ;
- y1 = (scaleRectangleF.Y-m_refPoint.Y) / m_zoomNum ;
- float w1, h1;
- w1 = scaleRectangleF.Width / m_zoomNum;
- h1 = scaleRectangleF.Height / m_zoomNum;
- m_OrigineRegionF = new RectangleF(x1, y1, w1, h1);
- m_RegionF = scaleRectangleF;
- }
- private Rectangle GetMinRectangleOfPolygon(List<PointF> polygonPointList)
- {
- if (polygonPointList != null)
- {
- if (polygonPointList.Count > 0)
- {
- int pCount = polygonPointList.Count;
- float minX = polygonPointList[0].X;
- float minY = polygonPointList[0].Y;
- float maxX = polygonPointList[0].X;
- float maxY = polygonPointList[0].Y;
- //获取最小X,Y 最大X,Y
- for (int i = 0; i < pCount; i++)
- {
- minX = Math.Min(minX, polygonPointList[i].X);
- minY = Math.Min(minY, polygonPointList[i].Y);
- maxX = Math.Max(maxX, polygonPointList[i].X);
- maxY = Math.Max(maxY, polygonPointList[i].Y);
- }
- //创建外接矩形
- Rectangle rect = new Rectangle();
- rect.Location = new Point((int)minX, (int)minY);
- rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
- return rect;
- }
- }
- return new Rectangle();
- }
- public RectangleF GetOrigionalDrawRegionF()
- { return m_OrigineRegionF; }
- public List<PointF> GetOriginalPolygonPointFList()
- { return m_originalPolygonPoints; }
- public void SetOriginalPolygonPointFList(List<PointF> value)
- {
- if (m_zoomNum != 1)
- {
- var ps = new List<PointF>();
- foreach (var p in value)
- {
- var p1 = new PointF();
- p1.X = p.X * m_zoomNum+m_refPoint.X;
- p1.Y = p.Y *m_zoomNum+ m_refPoint.Y;
- ps.Add(p1);
- }
-
- m_PolygonPoints = ps;
- m_originalPolygonPoints = value;
- }
- else
- {
- m_originalPolygonPoints = value;
- m_PolygonPoints = value;
- }
-
- }
- public List<PointF> GetPolygonPointFList()
- { return m_PolygonPoints; }
- public void SetPolygonPointFList(List<PointF> value)
- {
- if (m_zoomNum != 1)
- {
- var ps = new List<PointF>();
- foreach (var p in value)
- {
- var p1 = new PointF();
- p1.X = (p.X - m_refPoint.X) / m_zoomNum;
- p1.Y = (p.Y - m_refPoint.Y) / m_zoomNum;
- ps.Add(p1);
- }
- m_originalPolygonPoints = ps;
- m_PolygonPoints = value;
- }
- else
- {
- m_originalPolygonPoints = value;
- m_PolygonPoints = value;
- }
- var region = GetMinRectangleOfPolygon(m_PolygonPoints);
- SetZoomedRegionF(region);
- }
- public GraphicsPath GetGPath()
- {
- var measureItem = this;
- //重新绘制测量区域路径
- GraphicsPath GPath = new GraphicsPath();
-
- if (measureItem.CreateType == CreateRectangleType.Polygon)
- {
- GraphicsPath PolygonMeasurePath = new GraphicsPath();
- PolygonMeasurePath.AddPolygon(measureItem.GetPolygonPointFList().ToArray());
- GPath = PolygonMeasurePath;
- }
- else if (measureItem.CreateType == CreateRectangleType.CircleByThreePoints)
- {
- GPath.AddEllipse(GetZoomedRegionF());
- }
- else
- {
- if (measureItem.Shape == (int)CreateRectangleType.Circle)
- {
- GPath.AddEllipse(GetZoomedRegionF());
- }
- else
- {
- GPath.AddRectangle(GetZoomedRegionF());
- }
- }
-
- return GPath;
- }
- public PointF PolygonDrawingEndPoint
- {
- get { return endPoint; }
- set { endPoint = value; }
- }
-
- public Point GetZoomedCenterPoint()
- {
- Point pCenterPoint = new Point();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = (int)(this.GetZoomedRegion.X + this.GetZoomedRegion.Width / 2);
- pCenterPoint.Y = (int)(this.GetZoomedRegion.Y + this.GetZoomedRegion.Height / 2);
- return pCenterPoint;
- }
- public PointF GetCenterPoint()
- {
- PointF pCenterPoint = new PointF();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = (this.GetOrigionalDrawRegionF().X + this.GetOrigionalDrawRegionF().Width / 2);
- pCenterPoint.Y = (this.GetOrigionalDrawRegionF().Y + this.GetOrigionalDrawRegionF().Height / 2);
- return pCenterPoint;
- }
- #endregion
-
- public bool IsDragging
- {
- get { return m_IsDragging; }
- set { m_IsDragging = value; }
- }
- public bool IsAltering// changing the size by gui operating.
- {
- get { return m_IsAlter; }
- set { m_IsAlter = value; }
- }
- public bool IsWorkSample
- {
- get { return m_IsWorkSample; }
- set { m_IsWorkSample = value; }
- }
- public PointF DraggingPoint
- {
- get { return m_DraggingPoint; }
- set {
-
- m_DraggingPoint = value;
- if (subItems.Count != 0)
- {
- foreach (var item in subItems)
- {
- item.DraggingPoint = m_DraggingPoint;
- }
-
- }
- }
- }
- public int SequenceNum { get => m_sequenceNum; set => m_sequenceNum = value; }
- public bool IsMoving { get => m_IsMoving; set => m_IsMoving = value; }
- public PointF GetDisplayRefPoint()
- { return m_refPoint; }
- public void SetDisplayRefPoint(PointF value)
- {
- m_refPoint = value;
- SetInitRegionF(m_OrigineRegionF);
- if (m_originalPolygonPoints.Count != 0)
- {
- this.SetPolygonPointFList(m_originalPolygonPoints);
- }
- }
- public float GetZoomNumber()
- { return m_zoomNum; }
- public void SetZoomNumber(float value)
- {
- m_zoomNum = value;
- SetInitRegionF(m_OrigineRegionF);
- if (m_originalPolygonPoints.Count != 0)
- {
- this.SetPolygonPointFList(m_originalPolygonPoints);
- }
- }
- #region 画圆角矩形
- internal static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadius)
- {
- GraphicsPath roundedRect = new GraphicsPath();
- roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
- roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
- roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
- roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
- roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
- roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
- roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
- roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
- roundedRect.CloseFigure();
- return roundedRect;
- }
- public bool IfZoomContains(Point mousePoint)
- {
- if (mousePoint.X > m_RegionF.Left && mousePoint.X < m_RegionF.Left + m_RegionF.Width)
- {
- if (mousePoint.Y > m_RegionF.Top && mousePoint.Y < m_RegionF.Top + m_RegionF.Height)
- {
- return true;
-
- }
-
-
- }
- return false;
- }
- public bool IfContains(PointF thePoint)
- {
- if (thePoint.X > m_OrigineRegionF.Left && thePoint.X < m_OrigineRegionF.Left + m_OrigineRegionF.Width)
- {
- if (thePoint.Y > m_OrigineRegionF.Top && thePoint.Y < m_OrigineRegionF.Top + m_OrigineRegionF.Height)
- {
- return true;
- }
- }
- return false;
- }
- public List<CRectangleGDIObject> SubItems()
- {
- if (subItems == null) subItems = new List<CRectangleGDIObject>();
- return subItems;
- }
- public void AddSubItems(CRectangleGDIObject item)
- {
- if (subItems == null) subItems = new List<CRectangleGDIObject>();
- subItems.Add(item);
- }
- public void ClearSubItems()
- {
- subItems.Clear();
- }
- public void Zoom(PointF mousePoint, float zoomNum)
- {
- float X1;
- float curZoom = m_zoomNum;
- float deltaZoom = zoomNum - curZoom;
- float Y1;
- if (zoomNum == 1)
- {
- m_zoomNum = 1;
- m_RegionF = m_OrigineRegionF;
- m_refPoint = new PointF(0, 0);
- m_PolygonPoints = m_originalPolygonPoints;
- }
- else
- {
-
- X1 = (m_RegionF.X - mousePoint.X) / curZoom * deltaZoom + m_RegionF.X;
- Y1 = (m_RegionF.Y - mousePoint.Y) / curZoom * deltaZoom + m_RegionF.Y;
- m_refPoint.X = (m_refPoint.X - mousePoint.X) / curZoom * deltaZoom + m_refPoint.X;
- m_refPoint.Y = (m_refPoint.Y - mousePoint.Y) / curZoom * deltaZoom + m_refPoint.Y;
- float Width = GetOrigionalDrawRegionF().Width * zoomNum;
- float Height = GetOrigionalDrawRegionF().Height * zoomNum;
- m_RegionF = new RectangleF(X1, Y1, Width, Height);
- m_zoomNum = zoomNum;
- }
-
-
- BSEImageWitdh = m_RegionF.Width;
- BSEImageHeight = m_RegionF.Height;
- BSEImageLocation = m_RegionF.Location;
- //SEMCenterPoint = m_RegionF.Location;
- var scalePs = new List<PointF>();
- foreach (var p in m_PolygonPoints)
- {
- float x, y;
- x = (p.X - mousePoint.X) / curZoom * deltaZoom + p.X;
- y = (p.Y - mousePoint.Y) / curZoom * deltaZoom + p.Y;
-
- scalePs.Add(new PointF(x, y));
- }
- m_PolygonPoints = scalePs;
-
- if (this.subItems.Count != 0)
- {
- foreach (var g in subItems)
- {
- g.Zoom(mousePoint,zoomNum);
- }
- }
- }
-
- public void Move(PointF location)
- {
-
- PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
- float X1;
- float Y1;
- X1 = (m_RegionF.X + offset.X);
- Y1 = (m_RegionF.Y + offset.Y);
- m_RegionF = new RectangleF(X1, Y1, m_RegionF.Width, m_RegionF.Height);
-
- m_refPoint.X = m_refPoint.X + offset.X;
- m_refPoint.Y = m_refPoint.Y + offset.Y;
- BSEImageWitdh = m_RegionF.Width;
- BSEImageHeight = m_RegionF.Height;
- BSEImageLocation = m_RegionF.Location;
- //SEMCenterPoint = m_RegionF.Location;
- LineStartPoint = m_RegionF.Location;
- m_DraggingPoint = new Point((int)location.X,(int)location.Y);
- var scalePs = new List<PointF>();
- foreach (var p in m_PolygonPoints)
- {
- float x, y;
- x = (p.X + offset.X);
- y = (p.Y + offset.Y);
- scalePs.Add(new PointF(x, y));
- }
- m_PolygonPoints = scalePs;
-
- if (this.subItems.Count != 0)
- {
- foreach (var g in subItems)
- {
- g.Move(location);
- }
-
-
- }
- }
- public void PositionAltering(PointF location,bool ifZoomCoord)
- {
- PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
- PointF realShift;
- if (ifZoomCoord)
- {
- realShift = new PointF(offset.X / m_zoomNum, offset.Y / m_zoomNum);
- }
- else
- {
- realShift = new PointF(offset.X , offset.Y );
- }
-
-
- m_OrigineRegionF = new RectangleF(m_OrigineRegionF.X+realShift.X, m_OrigineRegionF.Y+realShift.Y, m_OrigineRegionF.Width, m_OrigineRegionF.Height);
- SetInitRegionF(m_OrigineRegionF);
- BSEImageWitdh = m_RegionF.Width;
- BSEImageHeight = m_RegionF.Height;
- BSEImageLocation = m_RegionF.Location;
-
- LineStartPoint = m_RegionF.Location;
-
- var scalePs = new List<PointF>();
- var OriginalPs = new List<PointF>();
- foreach (var p in m_PolygonPoints)
- {
- float x, y;
- x = (p.X + offset.X);
- y = (p.Y + offset.Y);
- scalePs.Add(new PointF(x, y));
-
- }
- m_PolygonPoints = scalePs;
- foreach (var p in m_originalPolygonPoints)
- {
-
- OriginalPs.Add(new PointF(p.X + realShift.X, p.Y + realShift.Y));
- }
- m_originalPolygonPoints = OriginalPs;
- m_DraggingPoint = new Point((int)location.X, (int)location.Y);
- if (this.subItems.Count != 0)
- {
- foreach (var g in subItems)
- {
- g.PositionAltering(location,ifZoomCoord);
- }
- }
- }
- public CRectangleGDIObject Duplicate(CreateRectangleType newType)
- {
- CRectangleGDIObject r = new CRectangleGDIObject();
- r.NameOrHoleName = this.nameOrHoleName;
- r.SampleName = this.SampleName;
- r.m_OrigineRegionF = this.m_OrigineRegionF;
-
- r.IsWorkSample = this.IsWorkSample;
- r.m_RegionF = this.m_RegionF;
-
- r.m_refPoint = this.m_refPoint;
- r.m_zoomNum = this.m_zoomNum;
-
- r.shape = this.shape;
- r.createType = newType;
-
- return r;
- }
- virtual public bool ifRectangleIntersect(CRectangleGDIObject othergdi)
- {
- return true;
- }
- #endregion
- //是否设置为选择样品
- private bool m_IsAlter;
- //是否存在帧图信息
-
- //是否设置为拖动
- private bool m_IsDragging;
- private bool m_IsMoving;
- //是否为工作样品
- private bool m_IsWorkSample;
- private CreateRectangleType createType;
- private ShapeType shape;
- private string id;
- protected string nameOrHoleName="";
- public string sampleName="";
- //样品孔中样品的数量
- public int sampleCount = 0;
- public string strContent;
- private Color selColor;
- private PointF m_DraggingPoint;
- private int m_sequenceNum;
-
- protected RectangleF m_RegionF;
- //绘制时与移动缩放时记录的位置与尺寸
- protected RectangleF m_OrigineRegionF;
- //private GraphicsPath g_Path=new GraphicsPath();
- private PointF startPoint;
- private PointF endPoint;
-
- //绘制颗粒图
- private Color lineColor;
- private float lineLength;
- private PointF lineStartPoint;
- private int otsX;
- private int otsY;
- //绘制样品孔BSE图像
- private Image bseImage;
- //绘制样品孔BSE图像宽度
- private float bseImageWidth;
- //绘制样品孔BSE图像高度
- private float bseImageHeight;
- //绘制样品孔BSE图像位置
- private PointF bseImageLocation;
- //绘制SEM中心位置
- private PointF semCenterPoint;
-
-
- private List<PointF> m_PolygonPoints=new List<PointF>();
- //绘制时与移动缩放时记录的位置
- private List<PointF> m_originalPolygonPoints = new List<PointF>();
- private List<CRectangleGDIObject> subItems=new List<CRectangleGDIObject>();
-
- protected float m_zoomNum=1;
- private PointF m_refPoint=new PointF(0,0);
-
- }
- public enum SEMControlIndex
- {
- Magnification=0,
- WorkingDistance=1
- }
- public enum XYIndex
- {
- X = 0,
- Y = 1
- }
-
- public enum CreateRectangleType
- {
- //样品台-圆形
- SampleBackGround_Circle = -1,
- //圆形
- Circle = 0,
- //圆角矩形
- SampleBackGround_Rectangle = 1,
- //样品孔中的文字
- Text = 2,
- //矩形
- Rectangle = 3,
- //选择的样品
- SelectSample = 4,
- //测量区域
- MeasureArea = 5,
- //帧图-直线绘制方式
- SingleLine = 6,
- //表样-矩形
- SpecimenRectangle = 7,
- //表样-圆形
- SpecimenCircle = 8,
- //帧图-矩形绘制
- FieldRectangle = 9,
- //颗粒直线图
- ParticleLine = 10,
- //颗粒分布图 鼠标
- ParticleAreaRectangle = 11,
- //绘制拍摄样品孔BSE照片
- DrawFrameOfHoleBSEImage = 12,
- //绘制sem中心点+
- DrawSEMCenterPoint=13,
- //绘制BSE采集标记
- DrawBSEElementSignPoint = 14,
- //多边形
- Polygon = 15,
- //多边形完成标识
- DrawPolygonFinish = 16,
- //圆形三点法
- CircleByThreePoints=17,
- RingShape=18
- }
-
-
- public enum ColorType
- {
- SingleColor,//帧图fd8f8f
- RoundRectangleColor,//c8c8c8圆角矩形
- SampleBackGroundColor,//c0c0c0圆角矩形
- FontColor,//90ee90文字颜色
- SampleColor,//f4f4f4 样品未选择
- SampleSelColor//505050 样品选择后
- }
-
- public enum GrayLevel
- {
- Min=0,
- Max=255
- }
- }
|