123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902 |
- using OTSDataType;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
- {
- public class CVisualStage
- {
- //original data
- CStage m_SStage;
- CSEMStageData m_SEMStageData;
- //interchange object
- StageDrawingData m_OTSSampleStageData;
- PointF StageLTPointToSEMLocation = new Point(0, 0);
- PointF StageRBPointToSEMLocation = new Point(0, 0);
-
- float m_VisualStageEdgeLength;
- float m_OTSCoordStageEdgeLength = 0;
- int m_totalCtrlWidth;
- int m_totalCtrlHeight;
-
- //记录绘制样品台时的中心位置
- PointF m_RegionStartCenterPoint = new PointF(0, 0);
-
- //样品台存在的List集合 the rectangle on the edge of stage ,usually one.
- private List<CRectangleGDIObject> m_StageEdgeGDIObjects;
- //标样存在的List集合 usually it is a samll circle.
- private List<CRectangleGDIObject> m_SpecimenGDIObjects;
- private List<CRectangleGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage
- //文字内容
- private List<CRectangleGDIObject> m_ContentGDIObjects;//the text that will display in the hole.
- public StageDrawingData GetOTSSampleStageData()
- {
- return m_OTSSampleStageData;
- }
- public void SetOTSSampleStageData(StageDrawingData value)
- {
- m_OTSSampleStageData = value;
- }
- public CVisualStage(StageDrawingData oTSSampleStageData)
- {
- //样品台
- m_StageEdgeGDIObjects = new List<CRectangleGDIObject>();
- //标样
- m_SpecimenGDIObjects = new List<CRectangleGDIObject>();
- //样品孔
- m_SampleHoleGDIObjects = new List<CRectangleGDIObject>();
- //样品孔文字内容
- m_ContentGDIObjects = new List<CRectangleGDIObject>();
- m_OTSSampleStageData = new StageDrawingData();
- SetOTSSampleStageData(oTSSampleStageData ?? throw new ArgumentNullException(nameof(oTSSampleStageData)));
- }
- public CVisualStage()
- {
- //样品台
- m_StageEdgeGDIObjects = new List<CRectangleGDIObject>();
- //标样
- m_SpecimenGDIObjects = new List<CRectangleGDIObject>();
- //样品孔
- m_SampleHoleGDIObjects = new List<CRectangleGDIObject>();
- //样品孔文字内容
- m_ContentGDIObjects = new List<CRectangleGDIObject>();
- m_OTSSampleStageData = new StageDrawingData();
- }
- public void clear()
- {
- m_StageEdgeGDIObjects.Clear();
- m_SpecimenGDIObjects.Clear();
- m_SampleHoleGDIObjects.Clear();
- m_ContentGDIObjects.Clear();
- }
- public CRectangleGDIObject GetEdgeGDIObj()
- {
- return m_StageEdgeGDIObjects[0];
- }
- public float GetZoomNum() { return m_StageEdgeGDIObjects[0].GetZoomNumber(); }
- public PointF GetDisplayRefPoint() { return m_StageEdgeGDIObjects[0].GetDisplayRefPoint(); }
- public CRectangleGDIObject GetHoleGDIBySampleName(string name)
- {
- foreach (var g in m_SampleHoleGDIObjects)
- {
- if (g.SampleName == name)
- {
- return g;
- }
-
- }
- return null;
-
- }
- public CRectangleGDIObject GetHoleGDIByHoleName(string name)
- {
- foreach (var g in m_SampleHoleGDIObjects)
- {
- if (g.NameOrHoleName == name)
- {
- return g;
- }
- }
- return null;
- }
- public CRectangleGDIObject GetHoleGDIByMousePoint(Point mousePoint)
- {
- foreach (var g in m_SampleHoleGDIObjects)
- {
- if (g.IfZoomContains(mousePoint))
- {
- return g;
- }
- }
- return null;
- }
- public void cleargdiobj()
- {
- m_StageEdgeGDIObjects.Clear();
- m_SpecimenGDIObjects.Clear();
- m_SampleHoleGDIObjects.Clear();
- m_ContentGDIObjects.Clear();
- }
- public void InitSampleStageData(CStage SStage, CSEMStageData SEMStageData, int ctrlWidth, int ctrlHeight)
- {
- //获取样品台信息
- if (null == SStage)
- {
- return;
- }
- m_SStage = SStage;
- m_SEMStageData = SEMStageData;
- //获得样品台数据
- GetOTSSampleStageData().sStageName = SStage.GetName();
- GetOTSSampleStageData().bStageShape = (ShapeType)SStage.GetBoundary().GetShape();
- GetOTSSampleStageData().StageDomain = SStage.GetBoundary().GetRectDomain();
- GetOTSSampleStageData().bSampleShape = (ShapeType)SStage.GetSTD().GetShape();
- GetOTSSampleStageData().SampleRect = SStage.GetSTD().GetRectDomain();
- int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
- if (GetOTSSampleStageData().sSHoleInfoList.Count > 0)
- {
- GetOTSSampleStageData().sSHoleInfoList.Clear();
- }
- var holeLst = SStage.GetHoleList();
- for (int i = 0; i < iSHoleCount; i++)
- {
- CHole d = holeLst[i];
- OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
- //获取样品口的名称,形状,坐标
- SHoleInfo.sSHoleName = d.GetName();
- SHoleInfo.iSHoleShape = (int)d.GetShape();
- RectangleF r = d.GetRectDomain();
- SHoleInfo.HoleRect = r;
- GetOTSSampleStageData().sSHoleInfoList.Add(SHoleInfo);
- }
- //获取SEMData 绘制样品
- GetOTSSampleStageData().iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
- GetOTSSampleStageData().iXAxisDir = (int)SEMStageData.GetXAxisDir();
- GetOTSSampleStageData().iYAxisDir = (int)SEMStageData.GetYAxisDir();
- GetOTSSampleStageData().iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
- GetOTSSampleStageData().iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
- GetOTSSampleStageData().iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
- GetOTSSampleStageData().iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
- PointF xDomain = new PointF(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top);
- PointF yDomain = new PointF(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom);
- //OTS宽度高度差值
- float widthDomain = Math.Abs(yDomain.X - xDomain.X);
-
- //设置样品台宽度
- m_OTSCoordStageEdgeLength = widthDomain;//the stage must be a square.So we can only memorize an edge length.this is millimeter usually.
- m_VisualStageEdgeLength = ctrlHeight > ctrlWidth ? ctrlWidth : ctrlHeight;//the stage must be a square.So we can memorize an edge length only.
- //记录添加帧图的尺寸 鼠标滚动时使用的原值
- m_totalCtrlWidth = ctrlWidth;
- m_totalCtrlHeight = ctrlHeight;
-
- return;
- }
- public PointF GetCenterPointF()
- {
- var item = m_StageEdgeGDIObjects[0].GetZoomedRegionF();
- //声明中心点变量
- PointF pCenterPoint = new Point();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = item.X + item.Width / 2;
- pCenterPoint.Y = item.Y + item.Height / 2;
- return pCenterPoint;
- }
- public PointF GetCenterPoint()
- {
- return m_StageEdgeGDIObjects[0].GetCenterPoint();
- //声明中心点变量
-
- }
- public void DrawSampleStage()
- {
- StageDrawingData SData = GetOTSSampleStageData();
- try
- {
- if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
- {
- return;
- }
- string stageName = SData.sStageName;
-
- //获取样品台
- ShapeType StageShape = SData.bStageShape;
- PointF stageLeftTop = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);
- PointF stageRightBottom = new PointF(SData.StageDomain.Right, SData.StageDomain.Bottom);
- m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation);
- m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation);
- RectangleF Bourary;
-
- Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom);
- CRectangleGDIObject CreateBourary;
- //0:圆角矩形 1:圆形 2:文字 3:矩形
- if (SData.bStageShape == (ShapeType.RECTANGLE))
- {
- CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.SampleBackGround_Rectangle);
- }
- else
- {
- CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.Circle);
- }
-
- CreateBourary.Shape = StageShape;
- m_StageEdgeGDIObjects.Add(CreateBourary);
- //绘制后的样品台中心位置
- PointF m_Region = GetCenterPoint();
- //获取绘制后的样品台中心位置
- if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
- {
- m_RegionStartCenterPoint = m_Region;
- }
-
- //获取样品孔
- System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
- if (ChloeClrList.Count > 0)
- {
- for (int i = 0; i < ChloeClrList.Count; i++)
- {
- //获取微米信息
- var xHole = new PointF(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
- var yHole = new PointF(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
- //将微米转换为像素
- float widthHole = Math.Abs(yHole.X - xHole.X);
- float heightHole = Math.Abs(yHole.Y - xHole.Y);
- var RecF = GetCtrlCoordRectF(xHole, yHole);
- //获取矩形
- CRectangleGDIObject CreateHole = null;
- //0:圆角矩形 1:圆形 2:文字 3:矩形
- if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
- {
- CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Rectangle);
- }
- else
- {
- CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Circle);
- }
-
-
- CreateHole.NameOrHoleName= ChloeClrList[i].sSHoleName;
- m_SampleHoleGDIObjects.Add(CreateHole);
- //添加文字
- CRectangleGDIObject CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", "");
- //类型 文字:2
- CreateContent.CreateType = CreateRectangleType.Text;
- CreateContent.SetInitRegionF(CreateContent.GetZoomedRegionF());
- CreateContent.strContent = ChloeClrList[i].sSHoleName;
- CreateContent.NameOrHoleName = ChloeClrList[i].sSHoleName;
- m_ContentGDIObjects.Add(CreateContent);
- }
- }
- //获取标样
- ShapeType StageShapes = SData.bStageShape;
- stageLeftTop = new PointF(SData.SampleRect.Left, SData.SampleRect.Top);
- stageRightBottom = new PointF(SData.SampleRect.Right, SData.SampleRect.Bottom);
- //获取矩形
- CRectangleGDIObject CreateSTD;
- if (StageShapes == (int)CreateRectangleType.Circle)
- {
- CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenCircle, "", "");
- }
- else
- {
- CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenRectangle, "", "");
- }
-
-
- m_SpecimenGDIObjects.Add(CreateSTD);
- return;
- }
- catch (Exception ex)
- {
- NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() );
- }
- }
- public CRectangleGDIObject GetCtrlCoordRect(PointF OTSLeftTop, PointF OTSRightBottom, CreateRectangleType type, string content, string name)
- {
- try
- {
- //将微米信息 转换为 像素
- PointF xPoints = new Point();
- PointF yPoints = new Point();
- xPoints.X =(float) MicronConvertToPixel(OTSLeftTop.X );
- xPoints.Y = (float)MicronConvertToPixel( OTSLeftTop.Y );
- yPoints.X = (float)MicronConvertToPixel( OTSRightBottom.X );
- yPoints.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
- //计算位置
- xPoints = (PointF)CalculateLocationF(xPoints);
- yPoints = CalculateLocationF(yPoints);
- //获取图形四个点
- float realStartX = Math.Min(xPoints.X, yPoints.X);
- float realStartY = Math.Min(xPoints.Y, yPoints.Y);
- float realEndX = Math.Max(xPoints.X, yPoints.X);
- float realEndY = Math.Max(xPoints.Y, yPoints.Y);
- //创建矩形 并返回类型对象
- return new CRectangleGDIObject(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
- }
- catch (Exception)
- {
- return new CRectangleGDIObject(new Rectangle(), 0, "");
- }
- }
- public RectangleF GetCtrlCoordRectF(PointF OTSLeftTop, PointF OTSRightBottom)
- {
- try
- {
- //将微米信息 转换为 像素
- PointF leftTop = new PointF();
- PointF rightBottom = new PointF();
- leftTop.X = (float)MicronConvertToPixel( OTSLeftTop.X);
- leftTop.Y = (float)MicronConvertToPixel( OTSLeftTop.Y);
- rightBottom.X = (float)MicronConvertToPixel( OTSRightBottom.X);
- rightBottom.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
- //计算位置
- leftTop = CalculateLocationF(leftTop );
- rightBottom = CalculateLocationF(rightBottom);
- //获取图形四个点
- float realStartX = Math.Min(leftTop.X, rightBottom.X);
- float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
- float realEndX = Math.Max(leftTop.X, rightBottom.X);
- float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
- //创建矩形 并返回类型对象
- return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
-
- }
- catch (Exception)
- {
- return new RectangleF();
- }
- }
- private PointF CalculateLocationF(PointF point)
- {
- //获取窗体的高度与宽度
- float ctrlWidth = m_totalCtrlWidth;
- float ctrlHeight = m_totalCtrlHeight;
- //获取屏幕中心点
- PointF pointXY = new PointF();
- PointF screenPoint = new PointF(ctrlWidth / 2, ctrlHeight / 2);
- pointXY.X = screenPoint.X + point.X;
- pointXY.Y = screenPoint.Y - point.Y;//using minus because the coordinate system defference of OTS system and control system.
- return pointXY;
- }
-
- public double MicronConvertToPixel(double PointVal)
- {
-
- var v = m_VisualStageEdgeLength;
- return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
- }
- public PointF OTSCoordToCtrlCoord(PointF point)
- {
- var x = MicronConvertToPixel(point.X);
- var y = MicronConvertToPixel(point.Y);
- return CalculateLocationF(new PointF((float)x, (float)y));
- }
- public PointF CtrlCoordToOTSCoord(PointF point)
- {
- var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
- var x = PixelConvertToMicron(point.X - ctrlcenter.X);
- var y = PixelConvertToMicron(-(point.Y - ctrlcenter.Y));
- return new PointF(x, y);
- }
-
- public RectangleF GetOTSCoordRegionF(PointF ctrlLeftTop, PointF ctrlRightBottom)
- {
- try
- {
- var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
-
- //将微米信息 转换为 像素
- PointF leftTop = new PointF();
- PointF rightBottom = new PointF();
- leftTop.X = (float)PixelConvertToMicron(ctrlLeftTop.X-ctrlcenter.X);
- leftTop.Y = (float)PixelConvertToMicron((ctrlLeftTop.Y-ctrlcenter.Y));
- rightBottom.X = (float)PixelConvertToMicron(ctrlRightBottom.X-ctrlcenter.X);
- rightBottom.Y = (float)PixelConvertToMicron((ctrlRightBottom.Y-ctrlcenter.Y));
-
- //获取OTS图形四个点
- float realStartX = Math.Min(leftTop.X, rightBottom.X);
- float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
- float realEndX = Math.Max(leftTop.X, rightBottom.X);
- float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
- //创建矩形 并返回类型对象
- return new RectangleF(realStartX, -realEndY, realEndX - realStartX, realEndY - realStartY);
- }
- catch (Exception)
- {
- return new RectangleF();
- }
- }
- public float PixelConvertToMicron(float Pixel)
- {
- return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
- }
- internal void DecreaseSampleCount(string sampleName)
- {
- foreach (var hole in m_SampleHoleGDIObjects)
- {
- if (hole.SampleName == sampleName)
- {
- hole.SampleCount -= 1;
- }
- }
- }
- public CRectangleGDIObject GetSampleHoleGdiobjByName(string holeName)
- {
- foreach (var hole in m_SampleHoleGDIObjects)
- {
- if (hole.NameOrHoleName == holeName)
- {
- return hole;
- }
- }
- return null;
- }
- public bool GetVisualSampleArea(SampleMeasurePara SMeasurePara, out CVisualSampleArea a_visualSample)
- {
-
- //设置样品选择状态为非工作样品
- string SampleHoleName = SMeasurePara.sampleHoleName;
- var item = GetSampleHoleGdiobjByName(SampleHoleName);
- if (item != null)
- {
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
-
- //累加样品数量
- item.SampleCount += 1;
- item.IsWorkSample = true;
-
- CRectangleGDIObject sampleGDIObject = item.Duplicate(CreateRectangleType.SelectSample);
- sampleGDIObject.sampleName = SMeasurePara.sSampleName;
- sampleGDIObject.SelColor = selColor;
- //add the default measure area from config file.
- CRectangleGDIObject newMeasureGDIObject;
- PointF xHole = new PointF(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
- PointF yHole = new PointF(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
- RectangleF SampleRectangleF = GetCtrlCoordRectF(xHole, yHole);
- GetMeasureGdiObject(sampleGDIObject,SMeasurePara.iShape, SampleRectangleF, out newMeasureGDIObject);
- var newsample = new CVisualSampleArea();
- newsample.SetSampleGDIObject(sampleGDIObject);
- newsample.SetMeasureGDIObject(newMeasureGDIObject);
- a_visualSample = newsample;
- return true;
- }
-
-
- a_visualSample = null;
-
- return false;
-
-
- }
- #region 根据样品位置 获取测量区域位置
- public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem)
- {
- var item = MeasureItem;
- SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
-
- var region = this.GetOTSCoordRegionF(item.GetOrigionalDrawRegionF().Location, new PointF(item.GetOrigionalDrawRegionF().Right, item.GetOrigionalDrawRegionF().Bottom));
-
- sampleMeasurePara.MeasureRect = region;
-
- //设置样品孔名称
- sampleMeasurePara.sampleHoleName = item.NameOrHoleName;
- //设置样品名称
- sampleMeasurePara.sSampleName = item.SampleName;
- //设置测量区域形状
- sampleMeasurePara.iShape = item.Shape;
-
- sampleMeasurePara.DrawPolygonPointList = ConvertPolygonPointToOTSPoint(item.GetOriginalPolygonPointFList());
- sampleMeasurePara.sSampleName = MeasureItem.SampleName ;
- sampleMeasurePara.sampleHoleName =MeasureItem.NameOrHoleName;
- return sampleMeasurePara;
- }
-
- public List<PointF> ConvertPolygonPointToOTSPoint(List<PointF> polygonPointList)
- {
- List<PointF> OTSPoint = new List<PointF>();
-
- if (polygonPointList != null)
- {
- foreach (var item in polygonPointList)
- {
-
- OTSPoint.Add(CtrlCoordToOTSCoord(item));
- }
- }
- return OTSPoint;
- }
-
- public List<Point> PointFConvertPoint(List<PointF> Points)
- {
- List<Point> PointFs = new List<Point>();
- if (Points != null)
- {
- foreach (var itemPoint in Points)
- {
- PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
- }
- }
- return PointFs;
- }
- public PointF[] PointConvertPointF(Point[] Points)
- {
- PointF[] PointFs = new PointF[Points.Length];
- if (Points != null)
- {
- for (int i = 0; i < Points.Length; i++)
- {
- PointFs[i] = Points[i];
- }
- }
- return PointFs;
- }
- public List<PointF> PointConvertPointF(List<Point> Points)
- {
- List<PointF> PointFs = new List<PointF>();
- if (Points != null)
- {
- foreach (var itemPoint in Points)
- {
- PointFs.Add(itemPoint);
- }
- }
- return PointFs;
- }
- #endregion
- #region 添加测量
- /// <summary>
- /// 添加测量
- /// </summary>
- /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns>是否成功</returns>
- public bool GetMeasureGdiObject( CRectangleGDIObject sampleGDIObject,ShapeType newShape, RectangleF newRegion, out CRectangleGDIObject outMeasureRect)
- {
-
- var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
- MeasureRect.SetInitRegionF(newRegion);
-
- MeasureRect.SelColor = Color.Red;
- MeasureRect.Shape = newShape;
- outMeasureRect = MeasureRect;
- return true;
-
- }
- public bool GetMeasureGdiObjectFromSampleGdi(CRectangleGDIObject sampleGDIObject, out CRectangleGDIObject outMeasureRect)
- {
- //添加测量区域
- CreateRectangleType shape = sampleGDIObject.CreateType;
-
-
-
- var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
- //MeasureRect.GPath = MeasurePath;
- MeasureRect.SelColor = Color.Red;
-
- outMeasureRect = MeasureRect;
- return true;
- }
- #endregion
- public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
- {
- otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType;
- RectangleF pStageArea = m_StageEdgeGDIObjects[0].GetZoomedRegion;
- Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height);
-
- CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
- CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
- return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
- }
-
- public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm)
- {
- //鼠标在样品台中移动获取坐标
- Point mousePoint = GetMouseOTSLocation(mPoint);
- PointF SEMPoint = new Point();
- m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint);
- //将微米转换为毫米
- float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
- float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
- //将样品台坐标转换为Sem 坐标
- //编辑显示内容
- string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
- //显示XY轴
- m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
- }
- public Point GetMouseOTSLocation(Point mousePoint)
- {
- var offsetX = mousePoint.X - this.GetDisplayRefPoint().X;
- var offsetY = mousePoint.Y - this.GetDisplayRefPoint().Y;
- PointF ctrlPoint = new PointF(offsetX / this.GetZoomNum(), offsetY / this.GetZoomNum());
- PointF otsPoint = this.CtrlCoordToOTSCoord(ctrlPoint);
-
- Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(otsPoint.X, 0)), Convert.ToInt32(Math.Round(otsPoint.Y, 0)));
- return OTSMousePosition;
- }
- public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem)
- {
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
- if (item.IfZoomContains(mousePoint))
- {
- gdiItem = item;
- return true; ;
- }
- }
- gdiItem = null;
- return false;
- }
- public bool IfMouseInStage(Point mousePoint,out CRectangleGDIObject gdiobj)
- {
- foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
- {
- if (item.IfZoomContains(mousePoint))
- {
- gdiobj = item;
- return true;
- }
- }
- gdiobj = null;
- return false;
- }
- public bool IfMouseInStage(Point mousePoint )
- {
- foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
- {
- if (item.IfZoomContains(mousePoint))
- {
-
- return true;
- }
- }
-
- return false;
- }
- public void OnMouseMove( MouseEventArgs e)
- {
- foreach (CRectangleGDIObject item in m_ContentGDIObjects)
- {
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- }
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- }
- foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
- {
- item.IsDragging = true;
- item.DraggingPoint = e.Location;
- }
- }
- public List<CRectangleGDIObject> GetAllGDIObject()
- {
- var allobj = new List<CRectangleGDIObject>();
- foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
- {
- allobj.Add(item);
- }
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
- allobj.Add(item);
- }
- foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
- {
- allobj.Add(item);
- }
- foreach (CRectangleGDIObject item in m_ContentGDIObjects)
- {
- allobj.Add(item);
- }
- return allobj;
- }
- public List<CRectangleGDIObject> GetAllGDIObjectWithoutHoleNameStr()
- {
- var allobj = new List<CRectangleGDIObject>();
- foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
- {
- allobj.Add(item);
- }
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
- allobj.Add(item);
- }
- foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
- {
- allobj.Add(item);
- }
-
- return allobj;
- }
- public PointF GetCenterPoint(RectangleF rect)
- {
- //声明
- PointF centerPoint = new PointF();
- //设置X,Y坐标
- centerPoint.X = rect.X + rect.Width / 2;
- centerPoint.Y = rect.Y + rect.Height / 2;
- return centerPoint;
- }
- public SampleHolePara GetSampleHoleInfo(CRectangleGDIObject item)
- {
- SampleHolePara sampleHolePara = new SampleHolePara();
-
-
- //设置测量区域
- sampleHolePara.SampleHoleRect = item.GetZoomedRegion;
- //设置测量区域位置与尺寸
- float left = PixelConvertToMicron(item.GetZoomedRegionF().X);
- float Top = PixelConvertToMicron(item.GetZoomedRegionF().Y);
- float Width = PixelConvertToMicron(item.GetZoomedRegionF().Width);
- float Height = PixelConvertToMicron(item.GetZoomedRegionF().Height);
- PointF startPoint = new PointF(left, Top);
- SizeF sampleHoleSize = new SizeF(Width, Height);
- sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
- //设置样品孔名称
- sampleHolePara.sHoleName = item.NameOrHoleName;
- //设置测量区域形状
- sampleHolePara.iShape = item.Shape;
-
- return sampleHolePara;
- }
- }
- }
|