1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165 |
- 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;
-
- //记录绘制样品台时的中心位置
- Point m_RegionStartCenterPoint = new Point(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 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.Name == name)
- {
- return g;
- }
- }
- return null;
- }
- public CRectangleGDIObject GetHoleGDIByMousePoint(Point mousePoint)
- {
- foreach (var g in m_SampleHoleGDIObjects)
- {
- if (g.IfContains(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();
- string stageName = GetOTSSampleStageData().sStageName;
-
- //获取样品台
- ShapeType StageShape = GetOTSSampleStageData().bStageShape;
- 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);
- float heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
- //样品台转换在电镜位置的宽度与高度
- //设置样品台宽度
- 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 Point 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);
- }
-
- //添加样品台 对象
- //设置路径
- GraphicsPath MeasurePath = new GraphicsPath();
- if (StageShape == (int)CreateRectangleType.Circle)
- {
- MeasurePath.AddEllipse(CreateBourary.GetZoomedRegion);
- }
- else
- {
- MeasurePath.AddRectangle(CreateBourary.GetZoomedRegion);
- }
- CreateBourary.GPath = MeasurePath;
- CreateBourary.Shape = StageShape;
- m_StageEdgeGDIObjects.Add(CreateBourary);
- //绘制后的样品台中心位置
- Point 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);
- }
-
- //绘制样品孔路径
- //GraphicsPath HolePath = new GraphicsPath();
- //if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
- //{
- // HolePath.AddEllipse(CreateHole.GetZoomedRegion);
- //}
- //else
- //{
- // HolePath.AddRectangle(CreateHole.GetZoomedRegion);
- //}
- //CreateHole.GPath = HolePath;
- CreateHole.Name= 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.Name = 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, "", "");
- }
-
- //绘制标样路径
- //GraphicsPath STDPath = new GraphicsPath();
- //if (StageShapes == (int)CreateRectangleType.Circle)
- //{
- // STDPath.AddEllipse(CreateSTD.GetZoomedRegion);
- //}
- //else
- //{
- // STDPath.AddRectangle(CreateSTD.GetZoomedRegion);
- //}
- //CreateSTD.GPath = STDPath;
- 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();
- }
- }
- public PointF CalculateLocationF(PointF point)
- {
- //获取窗体的高度与宽度
- int ctrlWidth = m_totalCtrlWidth;
- int 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));
-
- //}
- public PointF CalculateOTSLocation(PointF p1)
- {
- float OTSWholeWidth = m_OTSCoordStageEdgeLength;
- float OTSWholeHeight = m_OTSCoordStageEdgeLength;
- //获取屏幕中心点
- PointF pointXY = new PointF();
- PointF centerPoint = new PointF(0, 0);
- pointXY.X = centerPoint.X + p1.X;
- pointXY.Y = centerPoint.Y + p1.Y;
- return pointXY;
- }
- 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));
- //计算位置
- leftTop = CalculateOTSLocation(leftTop);
- rightBottom = CalculateOTSLocation(rightBottom);
- //获取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;
- }
- }
- }
- private CRectangleGDIObject GetSampleHoleGdiobjByName(string holeName)
- {
- foreach (var hole in m_SampleHoleGDIObjects)
- {
- if (hole.Name == 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;
- ;
- //GraphicsPath NewSamplePath = new GraphicsPath();
- //if (sampleGDIObject.Shape == (int)CreateRectangleType.Circle)
- //{
- // NewSamplePath.AddEllipse(sampleGDIObject.GetZoomedRegion);
- //}
- //else
- //{
- // NewSamplePath.AddRectangle(sampleGDIObject.GetZoomedRegion);
- //}
- //sampleGDIObject.GPath = NewSamplePath;
- //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, SampleRectangleF, out newMeasureGDIObject);
- var newsample = new CVisualSampleArea();
- newsample.SampleGDIObject = sampleGDIObject;
- newsample.MeasureGDIObject = newMeasureGDIObject;
- a_visualSample = newsample;
- return true;
- }
-
-
- a_visualSample = null;
-
- return false;
-
-
- }
- #region 根据样品位置 获取测量区域位置
- public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem)
- {
- //获取测量区域的OTS位置与尺寸
- //SampleMeasurePara sampleMeasurePara = GetMeasureInfo(MeasureItem);
- var item = MeasureItem;
- SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
- //设置测量区域位置与尺寸
- float left = 0;
- float Top = 0;
- float Right = 0;
- float Bottom = 0;
- float Widths = 0;
- float Height = 0;
- //设置测量区域位置与尺寸
- //left = PixelConvertToMicron(item.OrigionalDrawRegionF.X);
- //Top = PixelConvertToMicron(item.OrigionalDrawRegionF.Y);
- //var p = CtrlCoordToOTSCoord(item.OrigionalDrawRegionF.Location);
- //Right = PixelConvertToMicron(item.OrigionalDrawRegionF.Right);
- //Bottom = PixelConvertToMicron(item.OrigionalDrawRegionF.Bottom);
- //Widths = PixelConvertToMicron(item.OrigionalDrawRegionF.Width);
- //Height = PixelConvertToMicron(item.OrigionalDrawRegionF.Height);
- var region = this.GetOTSCoordRegionF(item.OrigionalDrawRegionF.Location, new PointF(item.OrigionalDrawRegionF.Right, item.OrigionalDrawRegionF.Bottom));
- //保存原位置
- RectangleF polygonRectPara = item.OrigionalDrawRegionF;
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.DrawPolygonPointRegionF);
- //设置测量区域位置与尺寸
- left = PixelConvertToMicron(polygonRectPara.X);
- Top = PixelConvertToMicron(polygonRectPara.Y);
- Right = PixelConvertToMicron(polygonRectPara.Right);
- Bottom = PixelConvertToMicron(polygonRectPara.Bottom);
- Widths = PixelConvertToMicron(polygonRectPara.Width);
- Height = PixelConvertToMicron(polygonRectPara.Height);
- }
- //设置测量区域
- //PointF startPoint = p;
- //SizeF MeasureSize = new SizeF(Widths, Height);
- sampleMeasurePara.MeasureRect = region;
- //sampleMeasurePara.MeasureRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)MeasureSize.Width, (int)MeasureSize.Height));
- //设置样品孔名称
- sampleMeasurePara.sampleHoleName = item.Name;
- //设置样品名称
- sampleMeasurePara.sSampleName = item.SampleName;
- //设置测量区域形状
- sampleMeasurePara.iShape = item.Shape;
- //设置多边形点集合
- sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF));
- sampleMeasurePara.PolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF);
- sampleMeasurePara.DrawPolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.DrawPolygonPointRegionF);
- //获取样品台 中心点
- PointF RectanglePointCenter = GetCenterPointF();
- ////获取样品台中心点
- float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X);
- float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
- //RectangleF sampleMeasureRect = new Rectangle();
- ////根据样品台中心点获取开始点位置
- //sampleMeasureRect.X = -(CenterX - sampleMeasurePara.MeasureRect.X);
- //sampleMeasureRect.Y = CenterY - sampleMeasurePara.MeasureRect.Bottom;
- //sampleMeasurePara.MeasureRect.X = sampleMeasureRect.X;
- //sampleMeasurePara.MeasureRect.Y = sampleMeasureRect.Y;
- for (int i = 0; i < sampleMeasurePara.DrawPolygonPointRegionF.Count; i++)
- {
- int X = -((int)CenterX - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].X);
- int Y = (int)CenterY - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].Y;
- sampleMeasurePara.DrawPolygonPointRegionF[i] = new Point(X, Y);
- }
- sampleMeasurePara.sSampleName = MeasureItem.SampleName ;
- sampleMeasurePara.sampleHoleName =MeasureItem.Name;
- return sampleMeasurePara;
- }
-
- public List<PointF> ConvertPolygonPointToOTSPoint(List<PointF> polygonPointList)
- {
- List<PointF> OTSPoint = new List<PointF>();
- float X = 0;
- float Y = 0;
- if (polygonPointList != null)
- {
- foreach (var item in polygonPointList)
- {
- X = (float)(item.X * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
- Y = (float)(item.Y * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
- OTSPoint.Add(new PointF(X, Y));
- }
- }
- 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,RectangleF newRegion, out CRectangleGDIObject outMeasureRect)
- {
-
- //添加测量区域
-
-
- Color MeasureColor = Color.Red;
- var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
- MeasureRect.SetInitRegionF(newRegion);
-
- MeasureRect.SelColor = MeasureColor;
-
- outMeasureRect = MeasureRect;
- return true;
-
- }
- public bool GetMeasureGdiObject(CRectangleGDIObject sampleGDIObject, out CRectangleGDIObject outMeasureRect)
- {
- //添加测量区域
- CreateRectangleType shape = sampleGDIObject.CreateType;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(sampleGDIObject.GetZoomedRegion);
- }
- else
- {
- MeasurePath.AddEllipse(sampleGDIObject.GetZoomedRegion);
- }
-
- Color MeasureColor = Color.Red;
- var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
- MeasureRect.GPath = MeasurePath;
- MeasureRect.SelColor = MeasureColor;
-
- 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 = GetMouseSEMLocation(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 GetMouseSEMLocation(Point mousePoint)
- {
- var domain = GetOTSSampleStageData().StageDomain;
- PointF rectLocation = m_StageEdgeGDIObjects[0].GetZoomedRegion.Location;
- //样品台尺寸
- SizeF rectSize = m_StageEdgeGDIObjects[0].GetZoomedRegion.Size;
- //鼠标在工作区域中的位置
- //OTS坐标中鼠标的位置
- float OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
- float OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
- //OTS坐标中鼠标的尺寸位置
- double OTSWidth = 0;
- double OTSHeight = 0;
- float width = m_VisualStageEdgeLength;
- float height = m_VisualStageEdgeLength;
- //获取样品台两个坐标点
- var XDomain = new PointF(domain.Left, domain.Top);
- var YDomain = new PointF(domain.Right, domain.Bottom);
- //转换类型
- PointF xDomain = (XDomain);
- PointF yDomain = (YDomain);
- //宽度
- float widthDomain = Math.Abs((yDomain).X - (xDomain).X);
- float heightDomain = Math.Abs((yDomain).Y - (xDomain).Y);
- //换算鼠标在OTS坐标中的位置
- OTSWidth = (OTSX * ((double)widthDomain / width));
- OTSHeight = (OTSY * ((double)widthDomain / height));
- Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(OTSWidth, 0)), Convert.ToInt32(Math.Round(OTSHeight, 0)));
- return OTSMousePosition;
- }
- public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem)
- {
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
- if (item.IfContains(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.IfContains(mousePoint))
- {
- gdiobj = item;
- return true;
- }
- }
- gdiobj = null;
- return false;
- }
- public bool IfMouseInStage(Point mousePoint )
- {
- foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
- {
- if (item.IfContains(mousePoint))
- {
-
- return true;
- }
- }
-
- return false;
- }
- public void OnMouseMove(CRectangleGDIObject item,MouseEventArgs e)
- {
- foreach (CRectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
- {
- //获取样品孔中心点
- Point sampleHoleCenterPoint = sampleHoleItem.GetCenterPoint();
- if (item.IfContains(sampleHoleCenterPoint))
- {
- if (item.Name != sampleHoleItem.Name)
- {
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
- item.SelColor = ColorTranslator.FromHtml(ColorStr);
- break;
- }
- }
- else
- {
- //获取颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- item.SelColor = ColorTranslator.FromHtml(ColorStr);
- }
- }
- }
- 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 bool NewLocationDrawSingleInfo( Point moveToSEMLocation, List<CRectangleGDIObject> UpdateLocationGDIObject, CRectangleGDIObject WorkMeasure, float m_GlobalZoomNum)
- {
- //样品台中心点位置
- Point m_StageCenterPoint = GetCenterPoint();
- //当前与中心点相差距离
- int m_StageCenterDiffX ;
- int m_StageCenterDiffY;
- Point m_WorkMeasureCenterPoint ;
- if (UpdateLocationGDIObject == null)
- {
- return false;
- }
- int diffNewX ;
- int diffNewY ;
- bool IsOK = true;
- //diffNewX = moveToSEMLocation.X;
- //diffNewY = moveToSEMLocation.Y;
- if (IsOK)
- {
- foreach (var item in UpdateLocationGDIObject)
- {
- m_WorkMeasureCenterPoint = WorkMeasure.GetCenterPoint();
- m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum);
- m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum);
- diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
- diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
- //根据鼠标_更改测量区域的位置
- //item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height));
- item.SetInitRegionF(new RectangleF(new PointF(item.GetZoomedRegionF().X + (m_StageCenterDiffX + diffNewX), item.GetZoomedRegionF().Y + (m_StageCenterDiffY - diffNewY)), new SizeF(item.GetZoomedRegionF().Width, item.GetZoomedRegionF().Height)));
- //item.DrawRegionF = new RectangleF(new PointF(item.DrawRegionF.X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawRegionF.Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.DrawRegionF.Width, item.DrawRegionF.Height));
- }
- }
- return IsOK;
- }
- public void NewLocationDrawMeasureInfo( Point moveToSEMLocation, CRectangleGDIObject UpdateLocationGDIObject, float m_GlobalZoomNum)
- {
- //样品台中心点位置
- Point m_StageCenterPoint = GetCenterPoint();
- //当前与中心点相差距离
- int m_StageCenterDiffX ;
- int m_StageCenterDiffY ;
- int diffNewX ;
- int diffNewY ;
- Point m_UpdateCenterPoint ;
- var item = UpdateLocationGDIObject;
-
- m_UpdateCenterPoint = item.GetCenterPoint();
- m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1);
- m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1);
- diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
- diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
- //根据鼠标_更改测量区域的位置
- //item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height));
- item.SetInitRegionF(new RectangleF(new PointF(item.GetZoomedRegionF().X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.GetZoomedRegionF().Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.GetZoomedRegionF().Width, item.GetZoomedRegionF().Height)));
- //item.DrawRegionF = item.GetRegionF();
- //修改多边形的绘制点集合
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- for (int i = 0; i < item.PolygonPointRegion.Count; i++)
- {
- item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY);
- item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY));
- item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawPolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum);
- }
- }
-
- }
- public SampleHolePara GetSampleHolePara(CRectangleGDIObject sampleHoleItem)
- {
- //int w = (IsWidth == 0 ? Width : Height);
- SampleHolePara sampleHoleParas ;
- //获取样品孔的OTS位置与尺寸
- sampleHoleParas = GetSampleHoleInfo(sampleHoleItem);
- //获取工作区域位置与尺寸
- //Rectangle WorkAreaRect = new Rectangle(0, 0, m_totalCtrlWidth, m_totalCtrlHeight);
- //获取工作区域 中心点
- //Point ScreenPointCenter = GetCenterPoint(WorkAreaRect);
- //获取样品台 中心点
- PointF RectanglePointCenter =GetCenterPoint();
- //获取屏幕中心点
- //float WorkAreaCenterPointX = PixelConvertToMicron(ScreenPointCenter.X);
- //float WorkAreaCenterPointY = PixelConvertToMicron(ScreenPointCenter.Y);
- //获取样品台中心点
- float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X);
- float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
- RectangleF sampleHoleRect = new RectangleF();
- //根据样品台中心点获取开始点位置
- sampleHoleRect.X = -(CenterX - sampleHoleParas.SampleHoleRect.X);
- sampleHoleRect.Y = CenterY - sampleHoleParas.SampleHoleRect.Bottom;
- sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
- sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
- return sampleHoleParas;
- }
- 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();
-
- //保存原位置
- RectangleF rectPara = item.GetZoomedRegion;
- //设置测量区域
- sampleHolePara.SampleHoleRect = item.GetZoomedRegion;
- //设置测量区域位置与尺寸
- float left = PixelConvertToMicron(item.GetZoomedRegionF().X);
- float Top = PixelConvertToMicron(item.GetZoomedRegionF().Y);
- float Right = PixelConvertToMicron(item.GetZoomedRegionF().Right);
- float Bottom = PixelConvertToMicron(item.GetZoomedRegionF().Bottom);
- float Widths = PixelConvertToMicron(item.GetZoomedRegionF().Width);
- float Height = PixelConvertToMicron(item.GetZoomedRegionF().Height);
- PointF startPoint = new PointF(left, Top);
- SizeF sampleHoleSize = new SizeF(Widths, Height);
- sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
- //设置样品孔名称
- sampleHolePara.sHoleName = item.Name;
- //设置测量区域形状
- sampleHolePara.iShape = item.Shape;
-
- return sampleHolePara;
- }
- }
- }
|