VisualStage.cs 47 KB

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