1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093 |
- 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;
- Point StageLTPointToSEMLocation = new Point(0, 0);
- Point StageRBPointToSEMLocation = new Point(0, 0);
-
- int m_VisualStageEdgeLength;
- int 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 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 = (Rectangle)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();
- Rectangle r = (Rectangle)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;
- Point xDomain = new Point(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top);
- Point yDomain = new Point(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom);
- //OTS宽度高度差值
- int widthDomain = Math.Abs(yDomain.X - xDomain.X);
- int 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].RegionF;
- //声明中心点变量
- 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;
- Point stageLeftTop = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
- Point stageRightBottom = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
-
- m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation);
- m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation);
- RectangleF Bourary;
-
- Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom);
- CreateRectangle CreateBourary;
- //0:圆角矩形 1:圆形 2:文字 3:矩形
- if (SData.bStageShape == (ShapeType.RECTANGLE))
- {
- CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.SampleBackGround_Rectangle);
- }
- else
- {
- CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.Circle);
- }
-
- //添加样品台 对象
- //设置路径
- GraphicsPath MeasurePath = new GraphicsPath();
- if (StageShape == (int)CreateRectangleType.Circle)
- {
- MeasurePath.AddEllipse(CreateBourary.Region);
- }
- else
- {
- MeasurePath.AddRectangle(CreateBourary.Region);
- }
- 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 Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
- var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
- //将微米转换为像素
- int widthHole = Math.Abs(yHole.X - xHole.X);
- int heightHole = Math.Abs(yHole.Y - xHole.Y);
- var RecF = GetCtrlCoordRectF(xHole, yHole);
- //获取矩形
- CreateRectangle CreateHole = null;
- //0:圆角矩形 1:圆形 2:文字 3:矩形
- if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
- {
- CreateHole = new CreateRectangle(RecF, CreateRectangleType.Rectangle);
- }
- else
- {
- CreateHole = new CreateRectangle(RecF, CreateRectangleType.Circle);
- }
-
- //绘制样品孔路径
- GraphicsPath HolePath = new GraphicsPath();
- if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
- {
- HolePath.AddEllipse(CreateHole.Region);
- }
- else
- {
- HolePath.AddRectangle(CreateHole.Region);
- }
- CreateHole.GPath = HolePath;
- CreateHole.Name= ChloeClrList[i].sSHoleName;
- m_SampleHoleGDIObjects.Add(CreateHole);
- //添加文字
- CreateRectangle CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", "");
- //类型 文字:2
- CreateContent.CreateType = CreateRectangleType.Text;
- CreateContent.Region = CreateContent.Region;
- CreateContent.strContent = ChloeClrList[i].sSHoleName;
- CreateContent.Name = ChloeClrList[i].sSHoleName;
- m_ContentGDIObjects.Add(CreateContent);
- }
- }
- //获取标样
- ShapeType StageShapes = SData.bStageShape;
- stageLeftTop = new Point(SData.SampleRect.Left, SData.SampleRect.Top);
- stageRightBottom = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);
- //获取矩形
- CreateRectangle 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.Region);
- }
- else
- {
- STDPath.AddRectangle(CreateSTD.Region);
- }
- CreateSTD.GPath = STDPath;
- m_SpecimenGDIObjects.Add(CreateSTD);
- return;
- }
- catch (Exception ex)
- {
- NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() );
- }
- }
- public CreateRectangle GetCtrlCoordRect(Point OTSLeftTop, Point OTSRightBottom, CreateRectangleType type, string content, string name)
- {
- try
- {
- //将微米信息 转换为 像素
- PointF xPoints = new Point();
- PointF yPoints = new Point();
- xPoints.X = (int)MillimetersToPixelsWidth(OTSLeftTop.X );
- xPoints.Y = (int)MillimetersToPixelsWidth( OTSLeftTop.Y );
- yPoints.X = (int)MillimetersToPixelsWidth( OTSRightBottom.X );
- yPoints.Y = (int)MillimetersToPixelsWidth(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 CreateRectangle(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
- }
- catch (Exception)
- {
- return new CreateRectangle(new Rectangle(), 0, "");
- }
- }
- public RectangleF GetCtrlCoordRectF(Point OTSLeftTop, Point OTSRightBottom)
- {
- try
- {
-
- //将微米信息 转换为 像素
- PointF leftTop = new PointF();
- PointF rightBottom = new PointF();
- leftTop.X = (float)MillimetersToPixelsWidth( OTSLeftTop.X);
- leftTop.Y = (float)MillimetersToPixelsWidth( OTSLeftTop.Y);
- rightBottom.X = (float)MillimetersToPixelsWidth( OTSRightBottom.X);
- rightBottom.Y = (float)MillimetersToPixelsWidth(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 screenWidth = m_totalCtrlWidth;
- int screenHeight = m_totalCtrlHeight;
- //获取屏幕中心点
- PointF pointXY = new PointF();
- PointF screenPoint = new PointF(screenWidth / 2, screenHeight / 2);
- pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
- pointXY.Y = screenPoint.Y - point.Y;
- return pointXY;
- }
-
- public double MillimetersToPixelsWidth( double PointVal)
- {
-
- var v = m_VisualStageEdgeLength;
- return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
- }
- internal void DecreaseSampleCount(string holeName)
- {
- foreach (var hole in m_SampleHoleGDIObjects)
- {
- if (hole.Name == holeName)
- {
- hole.SampleCount -= 1;
- }
- }
- }
- public bool AddSample(SampleMeasurePara SMeasurePara, float globalZoomNum, out CRectangleGDIObject SampleGDIObject,out CRectangleGDIObject MeasureGDIObject)
- {
- Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
- Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
-
- RectangleF SampleRectangleF =GetCtrlCoordRectF(xHole, yHole);
- CRectangleGDIObject m_SampleGDIObject = GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasurePara.iShape, "", "");
- m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
- m_SampleGDIObject.RegionF = SampleRectangleF;
- m_SampleGDIObject.DrawRegionF = SampleRectangleF;
- //测量区域名称 样品名称
- m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;
- //测量区域类型
- m_SampleGDIObject.CreateType = (CreateRectangleType)SMeasurePara.iShape;
- string SampleHoleName = SMeasurePara.sampleHoleName;
- string SampleName = SMeasurePara.sSampleName;
- CRectangleGDIObject m_MeasureGDIObject;
-
-
-
- //设置样品选择状态为非工作样品
-
- foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
- {
-
- if (item.Name == SampleHoleName)
- {
-
-
- //设置颜色
- string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
- Color selColor = ColorTranslator.FromHtml(ColorStr);
- CreateRectangle NewSample = new CreateRectangle(item.Region, CreateRectangleType.SelectSample, item.Shape, item.Name, selColor);
- //累加样品数量
- item.SampleCount += 1;
- item.IsWorkSample = true;
- NewSample.SampleName = SampleName;
- NewSample.Name = item.Name;
- //设置当前添加的样品为工作样品
- NewSample.IsWorkSample = true;
- // 获取样品孔的大小与初始大小
- NewSample.Region = item.Region;
- NewSample.RegionF = item.RegionF;
- NewSample.DrawRegionF = item.DrawRegionF;
- //绘制样品路径
- GraphicsPath NewSamplePath = new GraphicsPath();
- if (NewSample.Shape == (int)CreateRectangleType.Circle)
- {
- NewSamplePath.AddEllipse(NewSample.Region);
- }
- else
- {
- NewSamplePath.AddRectangle(NewSample.Region);
- }
- NewSample.GPath = NewSamplePath;
- SampleGDIObject = NewSample;
-
- //获取测量区域尺寸与位置
- m_MeasureGDIObject = GetSampleMeasureInfo(NewSample, m_SampleGDIObject, globalZoomNum);
- //设置样品孔名称
- m_MeasureGDIObject.Name = item.Name;
- //根据节点设置样品台窗口中所选择的样品名称
-
- //添加测量区域
- bool ret= AddMeasure(m_MeasureGDIObject,out MeasureGDIObject);
- return ret;
- }
- }
- SampleGDIObject = null;
- MeasureGDIObject = null;
- return false;
-
-
- }
- #region 根据样品位置 获取测量区域位置
- public CRectangleGDIObject GetSampleMeasureInfo(CRectangleGDIObject NewSample, CRectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
- {
- //根据样品位置 获取测量区域位置
- int MeasurePointX = (int)(NewSample.Region.Location.X + ((NewSample.Region.Size.Width - (m_MeasureGDIObjects.Region.Width * globalZoomNum)) / 2));
- int MeasurePointY = (int)(NewSample.Region.Location.Y + ((NewSample.Region.Size.Height - (m_MeasureGDIObjects.Region.Height * globalZoomNum)) / 2));
- int MeasureWidth = Convert.ToInt32(m_MeasureGDIObjects.Region.Width * globalZoomNum);
- int MeasureHeight = Convert.ToInt32(m_MeasureGDIObjects.Region.Height * globalZoomNum);
- float MeasureFPointX = (float)(NewSample.RegionF.Location.X + (NewSample.RegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
- float MeasureFPointY = (float)(NewSample.RegionF.Location.Y + (NewSample.RegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
- float MeasureFWidth = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Width);
- float MeasureFHeight = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Height);
- float MeasureDrawPointX = (float)(NewSample.DrawRegionF.Location.X + (NewSample.DrawRegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
- float MeasureDrawPointY = (float)(NewSample.DrawRegionF.Location.Y + (NewSample.DrawRegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
- float MeasureDrawWidth = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Width);
- float MeasureDrawHeight = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Height);
- m_MeasureGDIObjects.Region = new Rectangle(new Point(MeasurePointX, MeasurePointY), new Size(MeasureWidth, MeasureHeight));
- m_MeasureGDIObjects.RegionF = new RectangleF(new PointF(MeasureFPointX, MeasureFPointY), new SizeF(MeasureFWidth, MeasureFHeight));
- m_MeasureGDIObjects.DrawRegionF = new RectangleF(new PointF(MeasureDrawPointX, MeasureDrawPointY), new SizeF(MeasureDrawWidth, MeasureDrawHeight));
- return m_MeasureGDIObjects;
- }
- public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem)
- {
-
-
- //获取测量区域的OTS位置与尺寸
- SampleMeasurePara sampleMeasurePara = GetMeasureInfo(MeasureItem);
- //获取样品台 中心点
- PointF RectanglePointCenter = GetCenterPointF();
- //获取样品台中心点
- float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X );
- float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
- Rectangle sampleMeasureRect = new Rectangle();
- //根据样品台中心点获取开始点位置
- sampleMeasureRect.X = -((int)CenterX - sampleMeasurePara.MeasureRect.X);
- sampleMeasureRect.Y = (int)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 SampleMeasurePara GetMeasureInfo(CRectangleGDIObject item)
- {
- SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
-
- //设置测量区域位置与尺寸
- float left = 0;
- float Top = 0;
- float Right = 0;
- float Bottom = 0;
- float Widths = 0;
- float Height = 0;
- //设置测量区域位置与尺寸
- left = PixelConvertToMicron((int)item.RegionF.X);
- Top = PixelConvertToMicron((int)item.RegionF.Y);
- Right = PixelConvertToMicron((int)item.RegionF.Right);
- Bottom = PixelConvertToMicron((int)item.RegionF.Bottom);
- Widths = PixelConvertToMicron((int)item.RegionF.Width);
- Height = PixelConvertToMicron((int)item.RegionF.Height);
- //保存原位置
- RectangleF polygonRectPara = item.DrawRegionF;
- if (item.CreateType == CreateRectangleType.Polygon)
- {
- polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.DrawPolygonPointRegionF);
- //设置测量区域位置与尺寸
- left = PixelConvertToMicron((int)polygonRectPara.X);
- Top = PixelConvertToMicron((int)polygonRectPara.Y);
- Right = PixelConvertToMicron((int)polygonRectPara.Right);
- Bottom = PixelConvertToMicron((int)polygonRectPara.Bottom);
- Widths = PixelConvertToMicron((int)polygonRectPara.Width);
- Height = PixelConvertToMicron((int)polygonRectPara.Height);
- }
- //设置测量区域
- PointF startPoint = new PointF(left, Top);
- SizeF MeasureSize = new SizeF(Widths, Height);
- 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);
-
- 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 float PixelConvertToMicron(int Pixel)
- {
- return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
- }
- 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 AddMeasure( CRectangleGDIObject MeasureGDIObject,out CRectangleGDIObject outMeasureRect)
- {
-
- //添加测量区域
- CreateRectangleType shape = MeasureGDIObject.CreateType;// == 1 ? 1 : 0;
- GraphicsPath MeasurePath = new GraphicsPath();
- if (shape == CreateRectangleType.Rectangle)
- {
- MeasurePath.AddRectangle(MeasureGDIObject.Region);
- }
- else
- {
- MeasurePath.AddEllipse(MeasureGDIObject.Region);
- }
- //缩小与样品的尺寸
- Rectangle rectMeasure = MeasureGDIObject.Region;
- Color MeasureColor = Color.Red;
- CreateRectangle MeasureRect = new CreateRectangle(rectMeasure, CreateRectangleType.MeasureArea, MeasureGDIObject.Shape, MeasureGDIObject.Name, MeasureGDIObject.SampleName, MeasureColor);
- MeasureRect.GPath = MeasurePath;
- MeasureRect.sampleName = MeasureGDIObject.SampleName;
- MeasureRect.Name = MeasureGDIObject.Name;
- //获取缩放前尺寸与位置
- MeasureRect.RegionF = MeasureGDIObject.RegionF;
- MeasureRect.DrawRegionF = MeasureGDIObject.DrawRegionF;
-
- outMeasureRect = MeasureRect;
- return true;
-
- }
- #endregion
- public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
- {
- otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType;
- Rectangle pStageArea = m_StageEdgeGDIObjects[0].Region;
- 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);
- Point 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;
- Point rectLocation = m_StageEdgeGDIObjects[0].Region.Location;
- //样品台尺寸
- Size rectSize = m_StageEdgeGDIObjects[0].Region.Size;
- //鼠标在工作区域中的位置
- //OTS坐标中鼠标的位置
- int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
- int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
- //OTS坐标中鼠标的尺寸位置
- double OTSWidth = 0;
- double OTSHeight = 0;
- int width = m_VisualStageEdgeLength;
- int height = m_VisualStageEdgeLength;
- //获取样品台两个坐标点
- var XDomain = new Point(domain.Left, domain.Top);
- var YDomain = new Point(domain.Right, domain.Bottom);
- //转换类型
- Point xDomain = ((System.Drawing.Point)XDomain);
- Point yDomain = ((System.Drawing.Point)YDomain);
- //宽度
- int widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X);
- int heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)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 = 0;
- int m_StageCenterDiffY = 0;
- Point m_WorkMeasureCenterPoint = new Point();
- if (UpdateLocationGDIObject == null)
- {
- return false;
- }
- int diffNewX = 0;
- int diffNewY = 0;
- 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.RegionF = new RectangleF(new PointF(item.RegionF.X + (m_StageCenterDiffX + diffNewX), item.RegionF.Y + (m_StageCenterDiffY - diffNewY)), new SizeF(item.RegionF.Width, item.RegionF.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, List<CRectangleGDIObject> UpdateLocationGDIObject, float m_GlobalZoomNum)
- {
- //样品台中心点位置
- Point m_StageCenterPoint = GetCenterPoint();
- //当前与中心点相差距离
- int m_StageCenterDiffX = 0;
- int m_StageCenterDiffY = 0;
- int diffNewX = 0;
- int diffNewY = 0;
- Point m_UpdateCenterPoint = new Point();
- foreach (var item in UpdateLocationGDIObject)
- {
- if (item.IsWorkSample)
- {
- 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.RegionF = new RectangleF(new PointF(item.RegionF.X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.RegionF.Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.RegionF.Width, item.RegionF.Height));
- item.DrawRegionF = item.RegionF;
- //修改多边形的绘制点集合
- 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 = new SampleHolePara();
- //获取样品孔的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);
- Rectangle sampleHoleRect = new Rectangle();
- //根据样品台中心点获取开始点位置
- sampleHoleRect.X = -((int)CenterX - sampleHoleParas.SampleHoleRect.X);
- sampleHoleRect.Y = (int)CenterY - sampleHoleParas.SampleHoleRect.Bottom;
- sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
- sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
- return sampleHoleParas;
- }
- public Point GetCenterPoint(Rectangle rect)
- {
- //声明
- Point centerPoint = new Point();
- //设置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();
-
- //保存原位置
- Rectangle rectPara = item.Region;
- //设置测量区域
- sampleHolePara.SampleHoleRect = item.Region;
- //设置测量区域位置与尺寸
- float left = PixelConvertToMicron((int)item.RegionF.X);
- float Top = PixelConvertToMicron((int)item.RegionF.Y);
- float Right = PixelConvertToMicron((int)item.RegionF.Right);
- float Bottom = PixelConvertToMicron((int)item.RegionF.Bottom);
- float Widths = PixelConvertToMicron((int)item.RegionF.Width);
- float Height = PixelConvertToMicron((int)item.RegionF.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;
- }
- }
- }
|