VisualStage.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. using OTSDataType;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  11. {
  12. public class CVisualStage
  13. {
  14. //original data
  15. CStage m_SStage;
  16. CSEMStageData m_SEMStageData;
  17. //interchange object
  18. StageDrawingData m_OTSSampleStageData;
  19. Point StageLTPointToSEMLocation = new Point(0, 0);
  20. Point StageRBPointToSEMLocation = new Point(0, 0);
  21. int m_VisualStageEdgeLength;
  22. int m_OTSCoordStageEdgeLength = 0;
  23. int m_totalCtrlWidth;
  24. int m_totalCtrlHeight;
  25. //记录绘制样品台时的中心位置
  26. Point m_RegionStartCenterPoint = new Point(0, 0);
  27. //样品台存在的List集合 the rectangle on the edge of stage ,usually one.
  28. private List<CRectangleGDIObject> m_StageEdgeGDIObjects;
  29. //标样存在的List集合 usually it is a samll circle.
  30. private List<CRectangleGDIObject> m_SpecimenGDIObjects;
  31. private List<CRectangleGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage
  32. //文字内容
  33. private List<CRectangleGDIObject> m_ContentGDIObjects;//the text that will display in the hole.
  34. public StageDrawingData GetOTSSampleStageData()
  35. {
  36. return m_OTSSampleStageData;
  37. }
  38. public void SetOTSSampleStageData(StageDrawingData value)
  39. {
  40. m_OTSSampleStageData = value;
  41. }
  42. public CVisualStage(StageDrawingData oTSSampleStageData)
  43. {
  44. //样品台
  45. m_StageEdgeGDIObjects = new List<CRectangleGDIObject>();
  46. //标样
  47. m_SpecimenGDIObjects = new List<CRectangleGDIObject>();
  48. //样品孔
  49. m_SampleHoleGDIObjects = new List<CRectangleGDIObject>();
  50. //样品孔文字内容
  51. m_ContentGDIObjects = new List<CRectangleGDIObject>();
  52. m_OTSSampleStageData = new StageDrawingData();
  53. SetOTSSampleStageData(oTSSampleStageData ?? throw new ArgumentNullException(nameof(oTSSampleStageData)));
  54. }
  55. public CVisualStage()
  56. {
  57. //样品台
  58. m_StageEdgeGDIObjects = new List<CRectangleGDIObject>();
  59. //标样
  60. m_SpecimenGDIObjects = new List<CRectangleGDIObject>();
  61. //样品孔
  62. m_SampleHoleGDIObjects = new List<CRectangleGDIObject>();
  63. //样品孔文字内容
  64. m_ContentGDIObjects = new List<CRectangleGDIObject>();
  65. m_OTSSampleStageData = new StageDrawingData();
  66. }
  67. public CRectangleGDIObject GetEdgeGDIObj()
  68. {
  69. return m_StageEdgeGDIObjects[0];
  70. }
  71. public CRectangleGDIObject GetHoleGDIBySampleName(string name)
  72. {
  73. foreach (var g in m_SampleHoleGDIObjects)
  74. {
  75. if (g.SampleName == name)
  76. {
  77. return g;
  78. }
  79. }
  80. return null;
  81. }
  82. public CRectangleGDIObject GetHoleGDIByHoleName(string name)
  83. {
  84. foreach (var g in m_SampleHoleGDIObjects)
  85. {
  86. if (g.Name == name)
  87. {
  88. return g;
  89. }
  90. }
  91. return null;
  92. }
  93. public CRectangleGDIObject GetHoleGDIByMousePoint(Point mousePoint)
  94. {
  95. foreach (var g in m_SampleHoleGDIObjects)
  96. {
  97. if (g.IfContains(mousePoint))
  98. {
  99. return g;
  100. }
  101. }
  102. return null;
  103. }
  104. public void cleargdiobj()
  105. {
  106. m_StageEdgeGDIObjects.Clear();
  107. m_SpecimenGDIObjects.Clear();
  108. m_SampleHoleGDIObjects.Clear();
  109. m_ContentGDIObjects.Clear();
  110. }
  111. public void InitSampleStageData(CStage SStage, CSEMStageData SEMStageData, int ctrlWidth, int ctrlHeight)
  112. {
  113. //获取样品台信息
  114. if (null == SStage)
  115. {
  116. return;
  117. }
  118. m_SStage = SStage;
  119. m_SEMStageData = SEMStageData;
  120. //获得样品台数据
  121. GetOTSSampleStageData().sStageName = SStage.GetName();
  122. GetOTSSampleStageData().bStageShape = (ShapeType)SStage.GetBoundary().GetShape();
  123. GetOTSSampleStageData().StageDomain = SStage.GetBoundary().GetRectDomain();
  124. GetOTSSampleStageData().bSampleShape = (ShapeType)SStage.GetSTD().GetShape();
  125. GetOTSSampleStageData().SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain();
  126. int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
  127. if (GetOTSSampleStageData().sSHoleInfoList.Count > 0)
  128. {
  129. GetOTSSampleStageData().sSHoleInfoList.Clear();
  130. }
  131. var holeLst = SStage.GetHoleList();
  132. for (int i = 0; i < iSHoleCount; i++)
  133. {
  134. CHole d = holeLst[i];
  135. OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
  136. //获取样品口的名称,形状,坐标
  137. SHoleInfo.sSHoleName = d.GetName();
  138. SHoleInfo.iSHoleShape = (int)d.GetShape();
  139. Rectangle r = (Rectangle)d.GetRectDomain();
  140. SHoleInfo.HoleRect = r;
  141. GetOTSSampleStageData().sSHoleInfoList.Add(SHoleInfo);
  142. }
  143. //获取SEMData 绘制样品
  144. GetOTSSampleStageData().iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
  145. GetOTSSampleStageData().iXAxisDir = (int)SEMStageData.GetXAxisDir();
  146. GetOTSSampleStageData().iYAxisDir = (int)SEMStageData.GetYAxisDir();
  147. GetOTSSampleStageData().iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
  148. GetOTSSampleStageData().iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
  149. GetOTSSampleStageData().iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
  150. GetOTSSampleStageData().iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
  151. string stageName = GetOTSSampleStageData().sStageName;
  152. //获取样品台
  153. ShapeType StageShape = GetOTSSampleStageData().bStageShape;
  154. Point xDomain = new Point(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top);
  155. Point yDomain = new Point(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom);
  156. //OTS宽度高度差值
  157. int widthDomain = Math.Abs(yDomain.X - xDomain.X);
  158. int heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
  159. //样品台转换在电镜位置的宽度与高度
  160. //设置样品台宽度
  161. m_OTSCoordStageEdgeLength = widthDomain;//the stage must be a square.So we can only memorize an edge length.this is millimeter usually.
  162. m_VisualStageEdgeLength = ctrlHeight > ctrlWidth ? ctrlWidth : ctrlHeight;//the stage must be a square.So we can memorize an edge length only.
  163. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  164. m_totalCtrlWidth = ctrlWidth;
  165. m_totalCtrlHeight = ctrlHeight;
  166. return;
  167. }
  168. public PointF GetCenterPointF()
  169. {
  170. var item = m_StageEdgeGDIObjects[0].RegionF;
  171. //声明中心点变量
  172. PointF pCenterPoint = new Point();
  173. //获取在工作窗口中X,Y位置
  174. pCenterPoint.X = item.X + item.Width / 2;
  175. pCenterPoint.Y = item.Y + item.Height / 2;
  176. return pCenterPoint;
  177. }
  178. public Point GetCenterPoint()
  179. {
  180. return m_StageEdgeGDIObjects[0].GetCenterPoint();
  181. //声明中心点变量
  182. }
  183. public void DrawSampleStage()
  184. {
  185. StageDrawingData SData = GetOTSSampleStageData();
  186. try
  187. {
  188. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  189. {
  190. return;
  191. }
  192. string stageName = SData.sStageName;
  193. //获取样品台
  194. ShapeType StageShape = SData.bStageShape;
  195. Point stageLeftTop = new Point(SData.StageDomain.Left, SData.StageDomain.Top);
  196. Point stageRightBottom = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom);
  197. m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation);
  198. m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation);
  199. RectangleF Bourary;
  200. Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom);
  201. CreateRectangle CreateBourary;
  202. //0:圆角矩形 1:圆形 2:文字 3:矩形
  203. if (SData.bStageShape == (ShapeType.RECTANGLE))
  204. {
  205. CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.SampleBackGround_Rectangle);
  206. }
  207. else
  208. {
  209. CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.Circle);
  210. }
  211. //添加样品台 对象
  212. //设置路径
  213. GraphicsPath MeasurePath = new GraphicsPath();
  214. if (StageShape == (int)CreateRectangleType.Circle)
  215. {
  216. MeasurePath.AddEllipse(CreateBourary.Region);
  217. }
  218. else
  219. {
  220. MeasurePath.AddRectangle(CreateBourary.Region);
  221. }
  222. CreateBourary.GPath = MeasurePath;
  223. CreateBourary.Shape = StageShape;
  224. m_StageEdgeGDIObjects.Add(CreateBourary);
  225. //绘制后的样品台中心位置
  226. Point m_Region = GetCenterPoint();
  227. //获取绘制后的样品台中心位置
  228. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  229. {
  230. m_RegionStartCenterPoint = m_Region;
  231. }
  232. //获取样品孔
  233. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  234. if (ChloeClrList.Count > 0)
  235. {
  236. for (int i = 0; i < ChloeClrList.Count; i++)
  237. {
  238. //获取微米信息
  239. var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  240. var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  241. //将微米转换为像素
  242. int widthHole = Math.Abs(yHole.X - xHole.X);
  243. int heightHole = Math.Abs(yHole.Y - xHole.Y);
  244. var RecF = GetCtrlCoordRectF(xHole, yHole);
  245. //获取矩形
  246. CreateRectangle CreateHole = null;
  247. //0:圆角矩形 1:圆形 2:文字 3:矩形
  248. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  249. {
  250. CreateHole = new CreateRectangle(RecF, CreateRectangleType.Rectangle);
  251. }
  252. else
  253. {
  254. CreateHole = new CreateRectangle(RecF, CreateRectangleType.Circle);
  255. }
  256. //绘制样品孔路径
  257. GraphicsPath HolePath = new GraphicsPath();
  258. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle)
  259. {
  260. HolePath.AddEllipse(CreateHole.Region);
  261. }
  262. else
  263. {
  264. HolePath.AddRectangle(CreateHole.Region);
  265. }
  266. CreateHole.GPath = HolePath;
  267. CreateHole.Name= ChloeClrList[i].sSHoleName;
  268. m_SampleHoleGDIObjects.Add(CreateHole);
  269. //添加文字
  270. CreateRectangle CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", "");
  271. //类型 文字:2
  272. CreateContent.CreateType = CreateRectangleType.Text;
  273. CreateContent.Region = CreateContent.Region;
  274. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  275. CreateContent.Name = ChloeClrList[i].sSHoleName;
  276. m_ContentGDIObjects.Add(CreateContent);
  277. }
  278. }
  279. //获取标样
  280. ShapeType StageShapes = SData.bStageShape;
  281. stageLeftTop = new Point(SData.SampleRect.Left, SData.SampleRect.Top);
  282. stageRightBottom = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom);
  283. //获取矩形
  284. CreateRectangle CreateSTD;
  285. if (StageShapes == (int)CreateRectangleType.Circle)
  286. {
  287. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenCircle, "", "");
  288. }
  289. else
  290. {
  291. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenRectangle, "", "");
  292. }
  293. //绘制标样路径
  294. GraphicsPath STDPath = new GraphicsPath();
  295. if (StageShapes == (int)CreateRectangleType.Circle)
  296. {
  297. STDPath.AddEllipse(CreateSTD.Region);
  298. }
  299. else
  300. {
  301. STDPath.AddRectangle(CreateSTD.Region);
  302. }
  303. CreateSTD.GPath = STDPath;
  304. m_SpecimenGDIObjects.Add(CreateSTD);
  305. return;
  306. }
  307. catch (Exception ex)
  308. {
  309. NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() );
  310. }
  311. }
  312. public CreateRectangle GetCtrlCoordRect(Point OTSLeftTop, Point OTSRightBottom, CreateRectangleType type, string content, string name)
  313. {
  314. try
  315. {
  316. //将微米信息 转换为 像素
  317. PointF xPoints = new Point();
  318. PointF yPoints = new Point();
  319. xPoints.X = (int)MillimetersToPixelsWidth(OTSLeftTop.X );
  320. xPoints.Y = (int)MillimetersToPixelsWidth( OTSLeftTop.Y );
  321. yPoints.X = (int)MillimetersToPixelsWidth( OTSRightBottom.X );
  322. yPoints.Y = (int)MillimetersToPixelsWidth(OTSRightBottom.Y);
  323. //计算位置
  324. xPoints = (PointF)CalculateLocationF(xPoints);
  325. yPoints = CalculateLocationF(yPoints);
  326. //获取图形四个点
  327. float realStartX = Math.Min(xPoints.X, yPoints.X);
  328. float realStartY = Math.Min(xPoints.Y, yPoints.Y);
  329. float realEndX = Math.Max(xPoints.X, yPoints.X);
  330. float realEndY = Math.Max(xPoints.Y, yPoints.Y);
  331. //创建矩形 并返回类型对象
  332. return new CreateRectangle(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
  333. }
  334. catch (Exception)
  335. {
  336. return new CreateRectangle(new Rectangle(), 0, "");
  337. }
  338. }
  339. public RectangleF GetCtrlCoordRectF(Point OTSLeftTop, Point OTSRightBottom)
  340. {
  341. try
  342. {
  343. //将微米信息 转换为 像素
  344. PointF leftTop = new PointF();
  345. PointF rightBottom = new PointF();
  346. leftTop.X = (float)MillimetersToPixelsWidth( OTSLeftTop.X);
  347. leftTop.Y = (float)MillimetersToPixelsWidth( OTSLeftTop.Y);
  348. rightBottom.X = (float)MillimetersToPixelsWidth( OTSRightBottom.X);
  349. rightBottom.Y = (float)MillimetersToPixelsWidth(OTSRightBottom.Y);
  350. //计算位置
  351. leftTop = CalculateLocationF(leftTop );
  352. rightBottom = CalculateLocationF(rightBottom);
  353. //获取图形四个点
  354. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  355. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  356. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  357. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  358. //创建矩形 并返回类型对象
  359. return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
  360. }
  361. catch (Exception)
  362. {
  363. return new RectangleF();
  364. }
  365. }
  366. public PointF CalculateLocationF(PointF point)
  367. {
  368. //获取窗体的高度与宽度
  369. int screenWidth = m_totalCtrlWidth;
  370. int screenHeight = m_totalCtrlHeight;
  371. //获取屏幕中心点
  372. PointF pointXY = new PointF();
  373. PointF screenPoint = new PointF(screenWidth / 2, screenHeight / 2);
  374. pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
  375. pointXY.Y = screenPoint.Y - point.Y;
  376. return pointXY;
  377. }
  378. public double MillimetersToPixelsWidth( double PointVal)
  379. {
  380. var v = m_VisualStageEdgeLength;
  381. return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
  382. }
  383. internal void DecreaseSampleCount(string holeName)
  384. {
  385. foreach (var hole in m_SampleHoleGDIObjects)
  386. {
  387. if (hole.Name == holeName)
  388. {
  389. hole.SampleCount -= 1;
  390. }
  391. }
  392. }
  393. public bool AddSample(SampleMeasurePara SMeasurePara, float globalZoomNum, out CRectangleGDIObject SampleGDIObject,out CRectangleGDIObject MeasureGDIObject)
  394. {
  395. Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  396. Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  397. RectangleF SampleRectangleF =GetCtrlCoordRectF(xHole, yHole);
  398. CRectangleGDIObject m_SampleGDIObject = GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasurePara.iShape, "", "");
  399. m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height);
  400. m_SampleGDIObject.RegionF = SampleRectangleF;
  401. m_SampleGDIObject.DrawRegionF = SampleRectangleF;
  402. //测量区域名称 样品名称
  403. m_SampleGDIObject.SampleName = SMeasurePara.sSampleName;
  404. //测量区域类型
  405. m_SampleGDIObject.CreateType = (CreateRectangleType)SMeasurePara.iShape;
  406. string SampleHoleName = SMeasurePara.sampleHoleName;
  407. string SampleName = SMeasurePara.sSampleName;
  408. CRectangleGDIObject m_MeasureGDIObject;
  409. //设置样品选择状态为非工作样品
  410. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  411. {
  412. if (item.Name == SampleHoleName)
  413. {
  414. //设置颜色
  415. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  416. Color selColor = ColorTranslator.FromHtml(ColorStr);
  417. CreateRectangle NewSample = new CreateRectangle(item.Region, CreateRectangleType.SelectSample, item.Shape, item.Name, selColor);
  418. //累加样品数量
  419. item.SampleCount += 1;
  420. item.IsWorkSample = true;
  421. NewSample.SampleName = SampleName;
  422. NewSample.Name = item.Name;
  423. //设置当前添加的样品为工作样品
  424. NewSample.IsWorkSample = true;
  425. // 获取样品孔的大小与初始大小
  426. NewSample.Region = item.Region;
  427. NewSample.RegionF = item.RegionF;
  428. NewSample.DrawRegionF = item.DrawRegionF;
  429. //绘制样品路径
  430. GraphicsPath NewSamplePath = new GraphicsPath();
  431. if (NewSample.Shape == (int)CreateRectangleType.Circle)
  432. {
  433. NewSamplePath.AddEllipse(NewSample.Region);
  434. }
  435. else
  436. {
  437. NewSamplePath.AddRectangle(NewSample.Region);
  438. }
  439. NewSample.GPath = NewSamplePath;
  440. SampleGDIObject = NewSample;
  441. //获取测量区域尺寸与位置
  442. m_MeasureGDIObject = GetSampleMeasureInfo(NewSample, m_SampleGDIObject, globalZoomNum);
  443. //设置样品孔名称
  444. m_MeasureGDIObject.Name = item.Name;
  445. //根据节点设置样品台窗口中所选择的样品名称
  446. //添加测量区域
  447. bool ret= AddMeasure(m_MeasureGDIObject,out MeasureGDIObject);
  448. return ret;
  449. }
  450. }
  451. SampleGDIObject = null;
  452. MeasureGDIObject = null;
  453. return false;
  454. }
  455. #region 根据样品位置 获取测量区域位置
  456. public CRectangleGDIObject GetSampleMeasureInfo(CRectangleGDIObject NewSample, CRectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
  457. {
  458. //根据样品位置 获取测量区域位置
  459. int MeasurePointX = (int)(NewSample.Region.Location.X + ((NewSample.Region.Size.Width - (m_MeasureGDIObjects.Region.Width * globalZoomNum)) / 2));
  460. int MeasurePointY = (int)(NewSample.Region.Location.Y + ((NewSample.Region.Size.Height - (m_MeasureGDIObjects.Region.Height * globalZoomNum)) / 2));
  461. int MeasureWidth = Convert.ToInt32(m_MeasureGDIObjects.Region.Width * globalZoomNum);
  462. int MeasureHeight = Convert.ToInt32(m_MeasureGDIObjects.Region.Height * globalZoomNum);
  463. float MeasureFPointX = (float)(NewSample.RegionF.Location.X + (NewSample.RegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
  464. float MeasureFPointY = (float)(NewSample.RegionF.Location.Y + (NewSample.RegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
  465. float MeasureFWidth = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Width);
  466. float MeasureFHeight = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Height);
  467. float MeasureDrawPointX = (float)(NewSample.DrawRegionF.Location.X + (NewSample.DrawRegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
  468. float MeasureDrawPointY = (float)(NewSample.DrawRegionF.Location.Y + (NewSample.DrawRegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
  469. float MeasureDrawWidth = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Width);
  470. float MeasureDrawHeight = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Height);
  471. m_MeasureGDIObjects.Region = new Rectangle(new Point(MeasurePointX, MeasurePointY), new Size(MeasureWidth, MeasureHeight));
  472. m_MeasureGDIObjects.RegionF = new RectangleF(new PointF(MeasureFPointX, MeasureFPointY), new SizeF(MeasureFWidth, MeasureFHeight));
  473. m_MeasureGDIObjects.DrawRegionF = new RectangleF(new PointF(MeasureDrawPointX, MeasureDrawPointY), new SizeF(MeasureDrawWidth, MeasureDrawHeight));
  474. return m_MeasureGDIObjects;
  475. }
  476. public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem)
  477. {
  478. //获取测量区域的OTS位置与尺寸
  479. SampleMeasurePara sampleMeasurePara = GetMeasureInfo(MeasureItem);
  480. //获取样品台 中心点
  481. PointF RectanglePointCenter = GetCenterPointF();
  482. //获取样品台中心点
  483. float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X );
  484. float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
  485. Rectangle sampleMeasureRect = new Rectangle();
  486. //根据样品台中心点获取开始点位置
  487. sampleMeasureRect.X = -((int)CenterX - sampleMeasurePara.MeasureRect.X);
  488. sampleMeasureRect.Y = (int)CenterY - sampleMeasurePara.MeasureRect.Bottom;
  489. sampleMeasurePara.MeasureRect.X = sampleMeasureRect.X;
  490. sampleMeasurePara.MeasureRect.Y = sampleMeasureRect.Y;
  491. for (int i = 0; i < sampleMeasurePara.DrawPolygonPointRegionF.Count; i++)
  492. {
  493. int X = -((int)CenterX - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].X);
  494. int Y = (int)CenterY - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].Y;
  495. sampleMeasurePara.DrawPolygonPointRegionF[i] = new Point(X, Y);
  496. }
  497. sampleMeasurePara.sSampleName = MeasureItem.SampleName ;
  498. sampleMeasurePara.sampleHoleName =MeasureItem.Name;
  499. return sampleMeasurePara;
  500. }
  501. public SampleMeasurePara GetMeasureInfo(CRectangleGDIObject item)
  502. {
  503. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  504. //设置测量区域位置与尺寸
  505. float left = 0;
  506. float Top = 0;
  507. float Right = 0;
  508. float Bottom = 0;
  509. float Widths = 0;
  510. float Height = 0;
  511. //设置测量区域位置与尺寸
  512. left = PixelConvertToMicron((int)item.RegionF.X);
  513. Top = PixelConvertToMicron((int)item.RegionF.Y);
  514. Right = PixelConvertToMicron((int)item.RegionF.Right);
  515. Bottom = PixelConvertToMicron((int)item.RegionF.Bottom);
  516. Widths = PixelConvertToMicron((int)item.RegionF.Width);
  517. Height = PixelConvertToMicron((int)item.RegionF.Height);
  518. //保存原位置
  519. RectangleF polygonRectPara = item.DrawRegionF;
  520. if (item.CreateType == CreateRectangleType.Polygon)
  521. {
  522. polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.DrawPolygonPointRegionF);
  523. //设置测量区域位置与尺寸
  524. left = PixelConvertToMicron((int)polygonRectPara.X);
  525. Top = PixelConvertToMicron((int)polygonRectPara.Y);
  526. Right = PixelConvertToMicron((int)polygonRectPara.Right);
  527. Bottom = PixelConvertToMicron((int)polygonRectPara.Bottom);
  528. Widths = PixelConvertToMicron((int)polygonRectPara.Width);
  529. Height = PixelConvertToMicron((int)polygonRectPara.Height);
  530. }
  531. //设置测量区域
  532. PointF startPoint = new PointF(left, Top);
  533. SizeF MeasureSize = new SizeF(Widths, Height);
  534. sampleMeasurePara.MeasureRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)MeasureSize.Width, (int)MeasureSize.Height));
  535. //设置样品孔名称
  536. sampleMeasurePara.sampleHoleName = item.Name;
  537. //设置样品名称
  538. sampleMeasurePara.sSampleName = item.SampleName;
  539. //设置测量区域形状
  540. sampleMeasurePara.iShape = item.Shape;
  541. //设置多边形点集合
  542. sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF));
  543. sampleMeasurePara.PolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF);
  544. sampleMeasurePara.DrawPolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.DrawPolygonPointRegionF);
  545. return sampleMeasurePara;
  546. }
  547. public List<PointF> ConvertPolygonPointToOTSPoint(List<PointF> polygonPointList)
  548. {
  549. List<PointF> OTSPoint = new List<PointF>();
  550. float X = 0;
  551. float Y = 0;
  552. if (polygonPointList != null)
  553. {
  554. foreach (var item in polygonPointList)
  555. {
  556. X = (float)(item.X * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  557. Y = (float)(item.Y * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  558. OTSPoint.Add(new PointF(X, Y));
  559. }
  560. }
  561. return OTSPoint;
  562. }
  563. public float PixelConvertToMicron(int Pixel)
  564. {
  565. return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  566. }
  567. public List<Point> PointFConvertPoint(List<PointF> Points)
  568. {
  569. List<Point> PointFs = new List<Point>();
  570. if (Points != null)
  571. {
  572. foreach (var itemPoint in Points)
  573. {
  574. PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
  575. }
  576. }
  577. return PointFs;
  578. }
  579. public PointF[] PointConvertPointF(Point[] Points)
  580. {
  581. PointF[] PointFs = new PointF[Points.Length];
  582. if (Points != null)
  583. {
  584. for (int i = 0; i < Points.Length; i++)
  585. {
  586. PointFs[i] = Points[i];
  587. }
  588. }
  589. return PointFs;
  590. }
  591. public List<PointF> PointConvertPointF(List<Point> Points)
  592. {
  593. List<PointF> PointFs = new List<PointF>();
  594. if (Points != null)
  595. {
  596. foreach (var itemPoint in Points)
  597. {
  598. PointFs.Add(itemPoint);
  599. }
  600. }
  601. return PointFs;
  602. }
  603. #endregion
  604. #region 添加测量
  605. /// <summary>
  606. /// 添加测量
  607. /// </summary>
  608. /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
  609. /// <param name="sampleName">样品名称</param>
  610. /// <returns>是否成功</returns>
  611. public bool AddMeasure( CRectangleGDIObject MeasureGDIObject,out CRectangleGDIObject outMeasureRect)
  612. {
  613. //添加测量区域
  614. CreateRectangleType shape = MeasureGDIObject.CreateType;// == 1 ? 1 : 0;
  615. GraphicsPath MeasurePath = new GraphicsPath();
  616. if (shape == CreateRectangleType.Rectangle)
  617. {
  618. MeasurePath.AddRectangle(MeasureGDIObject.Region);
  619. }
  620. else
  621. {
  622. MeasurePath.AddEllipse(MeasureGDIObject.Region);
  623. }
  624. //缩小与样品的尺寸
  625. Rectangle rectMeasure = MeasureGDIObject.Region;
  626. Color MeasureColor = Color.Red;
  627. CreateRectangle MeasureRect = new CreateRectangle(rectMeasure, CreateRectangleType.MeasureArea, MeasureGDIObject.Shape, MeasureGDIObject.Name, MeasureGDIObject.SampleName, MeasureColor);
  628. MeasureRect.GPath = MeasurePath;
  629. MeasureRect.sampleName = MeasureGDIObject.SampleName;
  630. MeasureRect.Name = MeasureGDIObject.Name;
  631. //获取缩放前尺寸与位置
  632. MeasureRect.RegionF = MeasureGDIObject.RegionF;
  633. MeasureRect.DrawRegionF = MeasureGDIObject.DrawRegionF;
  634. outMeasureRect = MeasureRect;
  635. return true;
  636. }
  637. #endregion
  638. public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
  639. {
  640. otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType;
  641. Rectangle pStageArea = m_StageEdgeGDIObjects[0].Region;
  642. Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height);
  643. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  644. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  645. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  646. }
  647. public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm)
  648. {
  649. //鼠标在样品台中移动获取坐标
  650. Point mousePoint = GetMouseSEMLocation(mPoint);
  651. Point SEMPoint = new Point();
  652. m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint);
  653. //将微米转换为毫米
  654. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  655. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  656. //将样品台坐标转换为Sem 坐标
  657. //编辑显示内容
  658. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  659. //显示XY轴
  660. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  661. }
  662. public Point GetMouseSEMLocation(Point mousePoint)
  663. {
  664. var domain = GetOTSSampleStageData().StageDomain;
  665. Point rectLocation = m_StageEdgeGDIObjects[0].Region.Location;
  666. //样品台尺寸
  667. Size rectSize = m_StageEdgeGDIObjects[0].Region.Size;
  668. //鼠标在工作区域中的位置
  669. //OTS坐标中鼠标的位置
  670. int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
  671. int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
  672. //OTS坐标中鼠标的尺寸位置
  673. double OTSWidth = 0;
  674. double OTSHeight = 0;
  675. int width = m_VisualStageEdgeLength;
  676. int height = m_VisualStageEdgeLength;
  677. //获取样品台两个坐标点
  678. var XDomain = new Point(domain.Left, domain.Top);
  679. var YDomain = new Point(domain.Right, domain.Bottom);
  680. //转换类型
  681. Point xDomain = ((System.Drawing.Point)XDomain);
  682. Point yDomain = ((System.Drawing.Point)YDomain);
  683. //宽度
  684. int widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X);
  685. int heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)xDomain).Y);
  686. //换算鼠标在OTS坐标中的位置
  687. OTSWidth = (OTSX * ((double)widthDomain / width));
  688. OTSHeight = (OTSY * ((double)widthDomain / height));
  689. Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(OTSWidth, 0)), Convert.ToInt32(Math.Round(OTSHeight, 0)));
  690. return OTSMousePosition;
  691. }
  692. public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem)
  693. {
  694. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  695. {
  696. if (item.IfContains(mousePoint))
  697. {
  698. gdiItem = item;
  699. return true; ;
  700. }
  701. }
  702. gdiItem = null;
  703. return false;
  704. }
  705. public bool IfMouseInStage(Point mousePoint,out CRectangleGDIObject gdiobj)
  706. {
  707. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  708. {
  709. if (item.IfContains(mousePoint))
  710. {
  711. gdiobj = item;
  712. return true;
  713. }
  714. }
  715. gdiobj = null;
  716. return false;
  717. }
  718. public bool IfMouseInStage(Point mousePoint )
  719. {
  720. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  721. {
  722. if (item.IfContains(mousePoint))
  723. {
  724. return true;
  725. }
  726. }
  727. return false;
  728. }
  729. public void OnMouseMove(CRectangleGDIObject item,MouseEventArgs e)
  730. {
  731. foreach (CRectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  732. {
  733. //获取样品孔中心点
  734. Point sampleHoleCenterPoint = sampleHoleItem.GetCenterPoint();
  735. if (item.IfContains(sampleHoleCenterPoint))
  736. {
  737. if (item.Name != sampleHoleItem.Name)
  738. {
  739. //获取颜色
  740. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  741. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  742. break;
  743. }
  744. }
  745. else
  746. {
  747. //获取颜色
  748. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  749. item.SelColor = ColorTranslator.FromHtml(ColorStr);
  750. }
  751. }
  752. }
  753. public void OnMouseMove( MouseEventArgs e)
  754. {
  755. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  756. {
  757. item.IsDragging = true;
  758. item.DraggingPoint = e.Location;
  759. }
  760. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  761. {
  762. item.IsDragging = true;
  763. item.DraggingPoint = e.Location;
  764. }
  765. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  766. {
  767. item.IsDragging = true;
  768. item.DraggingPoint = e.Location;
  769. }
  770. }
  771. public List<CRectangleGDIObject> GetAllGDIObject()
  772. {
  773. var allobj = new List<CRectangleGDIObject>();
  774. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  775. {
  776. allobj.Add(item);
  777. }
  778. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  779. {
  780. allobj.Add(item);
  781. }
  782. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  783. {
  784. allobj.Add(item);
  785. }
  786. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  787. {
  788. allobj.Add(item);
  789. }
  790. return allobj;
  791. }
  792. public bool NewLocationDrawSingleInfo( Point moveToSEMLocation, List<CRectangleGDIObject> UpdateLocationGDIObject, CRectangleGDIObject WorkMeasure, float m_GlobalZoomNum)
  793. {
  794. //样品台中心点位置
  795. Point m_StageCenterPoint = GetCenterPoint();
  796. //当前与中心点相差距离
  797. int m_StageCenterDiffX = 0;
  798. int m_StageCenterDiffY = 0;
  799. Point m_WorkMeasureCenterPoint = new Point();
  800. if (UpdateLocationGDIObject == null)
  801. {
  802. return false;
  803. }
  804. int diffNewX = 0;
  805. int diffNewY = 0;
  806. bool IsOK = true;
  807. diffNewX = moveToSEMLocation.X;
  808. diffNewY = moveToSEMLocation.Y;
  809. if (IsOK)
  810. {
  811. foreach (var item in UpdateLocationGDIObject)
  812. {
  813. m_WorkMeasureCenterPoint = WorkMeasure.GetCenterPoint();
  814. m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum);
  815. m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum);
  816. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  817. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  818. //根据鼠标_更改测量区域的位置
  819. 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));
  820. 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));
  821. 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));
  822. }
  823. }
  824. return IsOK;
  825. }
  826. public void NewLocationDrawMeasureInfo( Point moveToSEMLocation, List<CRectangleGDIObject> UpdateLocationGDIObject, float m_GlobalZoomNum)
  827. {
  828. //样品台中心点位置
  829. Point m_StageCenterPoint = GetCenterPoint();
  830. //当前与中心点相差距离
  831. int m_StageCenterDiffX = 0;
  832. int m_StageCenterDiffY = 0;
  833. int diffNewX = 0;
  834. int diffNewY = 0;
  835. Point m_UpdateCenterPoint = new Point();
  836. foreach (var item in UpdateLocationGDIObject)
  837. {
  838. if (item.IsWorkSample)
  839. {
  840. m_UpdateCenterPoint = item.GetCenterPoint();
  841. m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1);
  842. m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1);
  843. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  844. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  845. //根据鼠标_更改测量区域的位置
  846. 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));
  847. 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));
  848. item.DrawRegionF = item.RegionF;
  849. //修改多边形的绘制点集合
  850. if (item.CreateType == CreateRectangleType.Polygon)
  851. {
  852. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  853. {
  854. item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY);
  855. item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY));
  856. item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawPolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum);
  857. }
  858. }
  859. }
  860. }
  861. }
  862. public SampleHolePara GetSampleHolePara(CRectangleGDIObject sampleHoleItem)
  863. {
  864. //int w = (IsWidth == 0 ? Width : Height);
  865. SampleHolePara sampleHoleParas = new SampleHolePara();
  866. //获取样品孔的OTS位置与尺寸
  867. sampleHoleParas = GetSampleHoleInfo(sampleHoleItem);
  868. //获取工作区域位置与尺寸
  869. Rectangle WorkAreaRect = new Rectangle(0, 0, m_totalCtrlWidth, m_totalCtrlHeight);
  870. //获取工作区域 中心点
  871. Point ScreenPointCenter = GetCenterPoint(WorkAreaRect);
  872. //获取样品台 中心点
  873. PointF RectanglePointCenter =GetCenterPoint();
  874. //获取屏幕中心点
  875. float WorkAreaCenterPointX = PixelConvertToMicron(ScreenPointCenter.X);
  876. float WorkAreaCenterPointY = PixelConvertToMicron(ScreenPointCenter.Y);
  877. //获取样品台中心点
  878. float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X);
  879. float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
  880. Rectangle sampleHoleRect = new Rectangle();
  881. //根据样品台中心点获取开始点位置
  882. sampleHoleRect.X = -((int)CenterX - sampleHoleParas.SampleHoleRect.X);
  883. sampleHoleRect.Y = (int)CenterY - sampleHoleParas.SampleHoleRect.Bottom;
  884. sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
  885. sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
  886. return sampleHoleParas;
  887. }
  888. public Point GetCenterPoint(Rectangle rect)
  889. {
  890. //声明
  891. Point centerPoint = new Point();
  892. //设置X,Y坐标
  893. centerPoint.X = rect.X + rect.Width / 2;
  894. centerPoint.Y = rect.Y + rect.Height / 2;
  895. return centerPoint;
  896. }
  897. public SampleHolePara GetSampleHoleInfo(CRectangleGDIObject item)
  898. {
  899. SampleHolePara sampleHolePara = new SampleHolePara();
  900. //保存原位置
  901. Rectangle rectPara = item.Region;
  902. //设置测量区域
  903. sampleHolePara.SampleHoleRect = item.Region;
  904. //设置测量区域位置与尺寸
  905. float left = PixelConvertToMicron((int)item.RegionF.X);
  906. float Top = PixelConvertToMicron((int)item.RegionF.Y);
  907. float Right = PixelConvertToMicron((int)item.RegionF.Right);
  908. float Bottom = PixelConvertToMicron((int)item.RegionF.Bottom);
  909. float Widths = PixelConvertToMicron((int)item.RegionF.Width);
  910. float Height = PixelConvertToMicron((int)item.RegionF.Height);
  911. PointF startPoint = new PointF(left, Top);
  912. SizeF sampleHoleSize = new SizeF(Widths, Height);
  913. sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
  914. //设置样品孔名称
  915. sampleHolePara.sHoleName = item.Name;
  916. //设置测量区域形状
  917. sampleHolePara.iShape = item.Shape;
  918. return sampleHolePara;
  919. }
  920. }
  921. }