VisualStage.cs 46 KB

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