CVisualStage.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. using OTSDataType;
  2. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel.VisualGDIObjects;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  8. {
  9. public class CVisualStage
  10. {
  11. //original data
  12. CStage m_SStage;
  13. CSEMStageData m_SEMStageData;
  14. //interchange object
  15. StageDrawingData m_OTSSampleStageData;
  16. PointF StageLTPointToSEMLocation = new Point(0, 0);
  17. PointF StageRBPointToSEMLocation = new Point(0, 0);
  18. float m_VisualStageEdgeLength;
  19. float m_OTSCoordStageEdgeLength = 0;
  20. int m_totalCtrlWidth;
  21. int m_totalCtrlHeight;
  22. //记录绘制样品台时的中心位置
  23. PointF m_RegionStartCenterPoint = new PointF(0, 0);
  24. //样品台存在的List集合 the rectangle on the edge of stage ,usually one.
  25. private List<CDisplayGDIObject> m_StageEdgeGDIObjects;
  26. //标样存在的List集合 usually it is a samll circle.
  27. private List<CDisplayGDIObject> m_SpecimenGDIObjects;
  28. private List<CDisplayGDIObject> m_SampleHoleGDIObjects;// the hole gdi of the stage
  29. //文字内容
  30. private List<CDisplayGDIObject> m_ContentGDIObjects;//the text that will display in the hole.
  31. private List<CDisplayGDIObject> frameOfHoleGDIObjects;// record all the position of the sampleHole image
  32. public List<CDisplayGDIObject> FrameOfHoleGDIObjects { get => frameOfHoleGDIObjects; set => frameOfHoleGDIObjects = value; }
  33. public StageDrawingData GetOTSSampleStageData()
  34. {
  35. return m_OTSSampleStageData;
  36. }
  37. public void SetOTSSampleStageData(StageDrawingData value)
  38. {
  39. m_OTSSampleStageData = value;
  40. }
  41. public CVisualStage(StageDrawingData oTSSampleStageData)
  42. {
  43. //样品台
  44. m_StageEdgeGDIObjects = new List<CDisplayGDIObject>();
  45. //标样
  46. m_SpecimenGDIObjects = new List<CDisplayGDIObject>();
  47. //样品孔
  48. m_SampleHoleGDIObjects = new List<CDisplayGDIObject>();
  49. //样品孔文字内容
  50. m_ContentGDIObjects = new List<CDisplayGDIObject>();
  51. m_OTSSampleStageData = oTSSampleStageData;
  52. frameOfHoleGDIObjects = new List<CDisplayGDIObject>();
  53. }
  54. public CVisualStage()
  55. {
  56. //样品台
  57. m_StageEdgeGDIObjects = new List<CDisplayGDIObject>();
  58. //标样
  59. m_SpecimenGDIObjects = new List<CDisplayGDIObject>();
  60. //样品孔
  61. m_SampleHoleGDIObjects = new List<CDisplayGDIObject>();
  62. //样品孔文字内容
  63. m_ContentGDIObjects = new List<CDisplayGDIObject>();
  64. m_OTSSampleStageData = new StageDrawingData();
  65. frameOfHoleGDIObjects = new List<CDisplayGDIObject>();
  66. }
  67. public void clear()
  68. {
  69. m_StageEdgeGDIObjects.Clear();
  70. m_SpecimenGDIObjects.Clear();
  71. m_SampleHoleGDIObjects.Clear();
  72. m_ContentGDIObjects.Clear();
  73. }
  74. public CDisplayGDIObject GetEdgeGDIObj()
  75. {
  76. return m_StageEdgeGDIObjects[0];
  77. }
  78. public float GetZoomNum() { return m_StageEdgeGDIObjects[0].GetZoomNumber(); }
  79. public PointF GetDisplayRefPoint() { return m_StageEdgeGDIObjects[0].GetDisplayRefPoint(); }
  80. public CDisplayGDIObject GetHoleGDIBySampleName(string name)
  81. {
  82. foreach (var g in m_SampleHoleGDIObjects)
  83. {
  84. if (g.SampleName == name)
  85. {
  86. return g;
  87. }
  88. }
  89. return null;
  90. }
  91. public CDisplayGDIObject GetHoleGDIByHoleName(string name)
  92. {
  93. foreach (var g in m_SampleHoleGDIObjects)
  94. {
  95. if (g.NameOrHoleName == name)
  96. {
  97. return g;
  98. }
  99. }
  100. return null;
  101. }
  102. public CDisplayGDIObject GetHoleGDIByMousePoint(Point mousePoint)
  103. {
  104. foreach (var g in m_SampleHoleGDIObjects)
  105. {
  106. if (g.IfZoomContains(mousePoint))
  107. {
  108. return g;
  109. }
  110. }
  111. return null;
  112. }
  113. public void cleargdiobj()
  114. {
  115. m_StageEdgeGDIObjects.Clear();
  116. m_SpecimenGDIObjects.Clear();
  117. m_SampleHoleGDIObjects.Clear();
  118. m_ContentGDIObjects.Clear();
  119. }
  120. public void InitSampleStageData(CStage SStage, CSEMStageData SEMStageData, int ctrlWidth, int ctrlHeight)
  121. {
  122. //获取样品台信息
  123. if (null == SStage)
  124. {
  125. return;
  126. }
  127. m_SStage = SStage;
  128. m_SEMStageData = SEMStageData;
  129. //获得样品台数据
  130. GetOTSSampleStageData().sStageName = SStage.GetName();
  131. GetOTSSampleStageData().bStageShape = (ShapeType)SStage.GetBoundary().GetShape();
  132. GetOTSSampleStageData().StageDomain = SStage.GetBoundary().GetRectDomain();
  133. GetOTSSampleStageData().bSampleShape = (ShapeType)SStage.GetSTD().GetShape();
  134. GetOTSSampleStageData().SampleRect = SStage.GetSTD().GetRectDomain();
  135. int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数
  136. if (GetOTSSampleStageData().sSHoleInfoList.Count > 0)
  137. {
  138. GetOTSSampleStageData().sSHoleInfoList.Clear();
  139. }
  140. var holeLst = SStage.GetHoleList();
  141. for (int i = 0; i < iSHoleCount; i++)
  142. {
  143. CHole d = holeLst[i];
  144. SampleHolePara SHoleInfo = new SampleHolePara();
  145. //获取样品口的名称,形状,坐标
  146. SHoleInfo.sHoleName = d.GetName();
  147. SHoleInfo.iShape = (ShapeType)d.GetShape();
  148. RectangleF r = d.GetRectDomain();
  149. SHoleInfo.SampleHoleRect = r;
  150. GetOTSSampleStageData().sSHoleInfoList.Add(SHoleInfo);
  151. }
  152. //获取SEMData 绘制样品
  153. GetOTSSampleStageData().iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸
  154. GetOTSSampleStageData().iXAxisDir = (int)SEMStageData.GetXAxisDir();
  155. GetOTSSampleStageData().iYAxisDir = (int)SEMStageData.GetYAxisDir();
  156. GetOTSSampleStageData().iXAxisStartVal = SEMStageData.GetXAxis().GetStart();
  157. GetOTSSampleStageData().iXAxisEndVal = SEMStageData.GetXAxis().GetEnd();
  158. GetOTSSampleStageData().iYAxisStartVal = SEMStageData.GetYAxis().GetStart();
  159. GetOTSSampleStageData().iYAxisEndVal = SEMStageData.GetYAxis().GetEnd();
  160. PointF xDomain = new PointF(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top);
  161. PointF yDomain = new PointF(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom);
  162. //OTS宽度高度差值
  163. float widthDomain = Math.Abs(yDomain.X - xDomain.X);
  164. //设置样品台宽度
  165. m_OTSCoordStageEdgeLength = widthDomain;//the stage must be a square.So we can only memorize an edge length.this is millimeter usually.
  166. m_VisualStageEdgeLength = ctrlHeight > ctrlWidth ? ctrlWidth : ctrlHeight;//the stage must be a square.So we can memorize an edge length only.
  167. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  168. m_totalCtrlWidth = ctrlWidth;
  169. m_totalCtrlHeight = ctrlHeight;
  170. return;
  171. }
  172. public PointF GetCenterPointF()
  173. {
  174. var item = m_StageEdgeGDIObjects[0].GetZoomedRegionF();
  175. //声明中心点变量
  176. PointF pCenterPoint = new Point();
  177. //获取在工作窗口中X,Y位置
  178. pCenterPoint.X = item.X + item.Width / 2;
  179. pCenterPoint.Y = item.Y + item.Height / 2;
  180. return pCenterPoint;
  181. }
  182. public PointF GetCenterPoint()
  183. {
  184. return m_StageEdgeGDIObjects[0].GetCenterPoint();
  185. //声明中心点变量
  186. }
  187. public void DrawSampleStage()
  188. {
  189. StageDrawingData SData = GetOTSSampleStageData();
  190. try
  191. {
  192. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  193. {
  194. return;
  195. }
  196. string stageName = SData.sStageName;
  197. //获取样品台
  198. ShapeType StageShape = SData.bStageShape;
  199. PointF stageLeftTop = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);
  200. PointF stageRightBottom = new PointF(SData.StageDomain.Right, SData.StageDomain.Bottom);
  201. m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation);
  202. m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation);
  203. RectangleF Bourary;
  204. Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom);
  205. //sampleHoleImageBuffer = new Bitmap((int)Bourary.Width, (int)Bourary.Height);
  206. CDisplayGDIObject CreateBourary;
  207. //0:圆角矩形 1:圆形 2:文字 3:矩形
  208. if (SData.bStageShape == (ShapeType.RECTANGLE))
  209. {
  210. CreateBourary = new CDisplayGDIObject(Bourary, GDIType.StageBoundary_RoundedRectangle);
  211. }
  212. else
  213. {
  214. CreateBourary = new CDisplayGDIObject(Bourary, GDIType.StageBoundary_Circle);
  215. }
  216. //CreateBourary.Shape = StageShape;
  217. m_StageEdgeGDIObjects.Add(CreateBourary);
  218. //绘制后的样品台中心位置
  219. PointF m_Region = GetCenterPoint();
  220. //获取绘制后的样品台中心位置
  221. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  222. {
  223. m_RegionStartCenterPoint = m_Region;
  224. }
  225. //获取样品孔
  226. System.Collections.Generic.List<SampleHolePara> ChloeClrList = SData.sSHoleInfoList;
  227. if (ChloeClrList.Count > 0)
  228. {
  229. for (int i = 0; i < ChloeClrList.Count; i++)
  230. {
  231. //获取微米信息
  232. var xHole = new PointF(ChloeClrList[i].SampleHoleRect.Left, ChloeClrList[i].SampleHoleRect.Top);
  233. var yHole = new PointF(ChloeClrList[i].SampleHoleRect.Right, ChloeClrList[i].SampleHoleRect.Bottom);
  234. //将微米转换为像素
  235. float widthHole = Math.Abs(yHole.X - xHole.X);
  236. float heightHole = Math.Abs(yHole.Y - xHole.Y);
  237. var RecF = GetCtrlCoordRectF(xHole, yHole);
  238. //获取矩形
  239. CDisplayGDIObject CreateHole = null;
  240. //0:圆角矩形 1:圆形 2:文字 3:矩形
  241. if (ChloeClrList[i].iShape == ShapeType.RECTANGLE)
  242. {
  243. CreateHole = new CDisplayGDIObject(RecF, GDIType.Rectangle);
  244. }
  245. else
  246. {
  247. CreateHole = new CDisplayGDIObject(RecF, GDIType.StageBoundary_Circle);
  248. }
  249. CreateHole.NameOrHoleName = ChloeClrList[i].sHoleName;
  250. m_SampleHoleGDIObjects.Add(CreateHole);
  251. //添加文字
  252. CDisplayGDIObject CreateContent = GetCtrlCoordRect(xHole, yHole, GDIType.Rectangle, "", "");
  253. //类型 文字:2
  254. CreateContent.GDIType = GDIType.Text;
  255. CreateContent.SetInitRegionF(CreateContent.GetZoomedRegionF());
  256. CreateContent.strContent = ChloeClrList[i].sHoleName;
  257. CreateContent.NameOrHoleName = ChloeClrList[i].sHoleName;
  258. m_ContentGDIObjects.Add(CreateContent);
  259. }
  260. }
  261. //获取标样
  262. ShapeType StageShapes = SData.bStageShape;
  263. stageLeftTop = new PointF(SData.SampleRect.Left, SData.SampleRect.Top);
  264. stageRightBottom = new PointF(SData.SampleRect.Right, SData.SampleRect.Bottom);
  265. //获取矩形
  266. CDisplayGDIObject CreateSTD;
  267. if (StageShapes == (int)GDIType.StageBoundary_Circle)
  268. {
  269. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, GDIType.SpecimenCircle, "", "");
  270. }
  271. else
  272. {
  273. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, GDIType.SpecimenRectangle, "", "");
  274. }
  275. m_SpecimenGDIObjects.Add(CreateSTD);
  276. return;
  277. }
  278. catch (Exception ex)
  279. {
  280. NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
  281. }
  282. }
  283. public CDisplayGDIObject GetCtrlCoordRect(PointF OTSLeftTop, PointF OTSRightBottom, GDIType type, string content, string name)
  284. {
  285. try
  286. {
  287. //将微米信息 转换为 像素
  288. PointF xPoints = new Point();
  289. PointF yPoints = new Point();
  290. xPoints.X = (float)MicronConvertToPixel(OTSLeftTop.X);
  291. xPoints.Y = (float)MicronConvertToPixel(OTSLeftTop.Y);
  292. yPoints.X = (float)MicronConvertToPixel(OTSRightBottom.X);
  293. yPoints.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  294. //计算位置
  295. xPoints = (PointF)CalculateLocationF(xPoints);
  296. yPoints = CalculateLocationF(yPoints);
  297. //获取图形四个点
  298. float realStartX = Math.Min(xPoints.X, yPoints.X);
  299. float realStartY = Math.Min(xPoints.Y, yPoints.Y);
  300. float realEndX = Math.Max(xPoints.X, yPoints.X);
  301. float realEndY = Math.Max(xPoints.Y, yPoints.Y);
  302. //创建矩形 并返回类型对象
  303. return new CDisplayGDIObject(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
  304. }
  305. catch (Exception)
  306. {
  307. return new CDisplayGDIObject(new Rectangle(), 0, "");
  308. }
  309. }
  310. public RectangleF GetCtrlCoordRectF(PointF OTSLeftTop, PointF OTSRightBottom)
  311. {
  312. try
  313. {
  314. //将微米信息 转换为 像素
  315. PointF leftTop = new PointF();
  316. PointF rightBottom = new PointF();
  317. leftTop.X = (float)MicronConvertToPixel(OTSLeftTop.X);
  318. leftTop.Y = (float)MicronConvertToPixel(OTSLeftTop.Y);
  319. rightBottom.X = (float)MicronConvertToPixel(OTSRightBottom.X);
  320. rightBottom.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  321. //计算位置
  322. leftTop = CalculateLocationF(leftTop);
  323. rightBottom = CalculateLocationF(rightBottom);
  324. //获取图形四个点
  325. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  326. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  327. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  328. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  329. //创建矩形 并返回类型对象
  330. return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
  331. }
  332. catch (Exception)
  333. {
  334. return new RectangleF();
  335. }
  336. }
  337. private PointF CalculateLocationF(PointF point)
  338. {
  339. //获取窗体的高度与宽度
  340. float ctrlWidth = m_totalCtrlWidth;
  341. float ctrlHeight = m_totalCtrlHeight;
  342. //获取屏幕中心点
  343. PointF pointXY = new PointF();
  344. PointF screenPoint = new PointF(ctrlWidth / 2, ctrlHeight / 2);
  345. pointXY.X = screenPoint.X + point.X;
  346. pointXY.Y = screenPoint.Y - point.Y;//using minus because the coordinate system defference of OTS system and control system.
  347. return pointXY;
  348. }
  349. public double MicronConvertToPixel(double PointVal)
  350. {
  351. var v = m_VisualStageEdgeLength;
  352. return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
  353. }
  354. public PointF OTSCoordToCtrlCoord(PointF point)
  355. {
  356. var x = MicronConvertToPixel(point.X);
  357. var y = MicronConvertToPixel(point.Y);
  358. return CalculateLocationF(new PointF((float)x, (float)y));
  359. }
  360. public PointF CtrlCoordToOTSCoord(PointF point)
  361. {
  362. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  363. var x = PixelConvertToMicron(point.X - ctrlcenter.X);
  364. var y = PixelConvertToMicron(-(point.Y - ctrlcenter.Y));
  365. return new PointF(x, y);
  366. }
  367. public RectangleF GetOTSCoordRegionF(PointF ctrlLeftTop, PointF ctrlRightBottom)
  368. {
  369. try
  370. {
  371. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  372. //将微米信息 转换为 像素
  373. PointF leftTop = new PointF();
  374. PointF rightBottom = new PointF();
  375. leftTop.X = (float)PixelConvertToMicron(ctrlLeftTop.X - ctrlcenter.X);
  376. leftTop.Y = (float)PixelConvertToMicron((ctrlLeftTop.Y - ctrlcenter.Y));
  377. rightBottom.X = (float)PixelConvertToMicron(ctrlRightBottom.X - ctrlcenter.X);
  378. rightBottom.Y = (float)PixelConvertToMicron((ctrlRightBottom.Y - ctrlcenter.Y));
  379. //获取OTS图形四个点
  380. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  381. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  382. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  383. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  384. //创建矩形 并返回类型对象
  385. return new RectangleF(realStartX, -realEndY, realEndX - realStartX, realEndY - realStartY);
  386. }
  387. catch (Exception)
  388. {
  389. return new RectangleF();
  390. }
  391. }
  392. public float PixelConvertToMicron(float Pixel)
  393. {
  394. return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  395. }
  396. internal void DecreaseSampleCount(string sampleName)
  397. {
  398. foreach (var hole in m_SampleHoleGDIObjects)
  399. {
  400. if (hole.SampleName == sampleName)
  401. {
  402. hole.SampleCount -= 1;
  403. }
  404. }
  405. }
  406. public CDisplayGDIObject GetSampleHoleGdiobjByName(string holeName)
  407. {
  408. foreach (var hole in m_SampleHoleGDIObjects)
  409. {
  410. if (hole.NameOrHoleName == holeName)
  411. {
  412. return hole;
  413. }
  414. }
  415. return null;
  416. }
  417. public bool GetVisualSampleArea(SampleMeasurePara SMeasurePara, out CVisualSampleArea a_visualSample)
  418. {
  419. //设置样品选择状态为非工作样品
  420. string SampleHoleName = SMeasurePara.sampleHoleName;
  421. var item = GetSampleHoleGdiobjByName(SampleHoleName);
  422. if (item != null)
  423. {
  424. //设置颜色
  425. Color selColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  426. //累加样品数量
  427. item.SampleCount += 1;
  428. item.IsWorkSample = true;
  429. CDisplayGDIObject sampleGDIObject = item.Duplicate();
  430. sampleGDIObject.sampleName = SMeasurePara.sSampleName;
  431. sampleGDIObject.SelColor = selColor;
  432. //add the default measure area from config file.
  433. CMeasureArea newMeasureGDIObject;
  434. PointF xHole = new PointF(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  435. PointF yHole = new PointF(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  436. RectangleF SampleRectangleF = GetCtrlCoordRectF(xHole, yHole);
  437. GetMeasureGdiObject(sampleGDIObject, SMeasurePara.iShape, SampleRectangleF, out newMeasureGDIObject);
  438. var newsample = new CVisualSampleArea();
  439. newsample.SetSampleGDIObject(sampleGDIObject);
  440. newsample.SetMeasureGDIObject(newMeasureGDIObject);
  441. a_visualSample = newsample;
  442. return true;
  443. }
  444. a_visualSample = null;
  445. return false;
  446. }
  447. #region 根据样品位置 获取测量区域位置
  448. public SampleMeasurePara GetSampleMeasurePara(CMeasureArea MeasureItem)
  449. {
  450. var item = MeasureItem;
  451. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  452. var region = this.GetOTSCoordRegionF(item.GetOrigionalDrawRegionF().Location, new PointF(item.GetOrigionalDrawRegionF().Right, item.GetOrigionalDrawRegionF().Bottom));
  453. sampleMeasurePara.MeasureRect = region;
  454. //设置样品孔名称
  455. sampleMeasurePara.sampleHoleName = item.NameOrHoleName;
  456. //设置样品名称
  457. sampleMeasurePara.sSampleName = item.SampleName;
  458. //设置测量区域形状
  459. sampleMeasurePara.iShape = item.Myshape;
  460. sampleMeasurePara.DrawPolygonPointList = ConvertPolygonPointToOTSPoint(item.GetOriginalPolygonPointFList());
  461. sampleMeasurePara.sSampleName = MeasureItem.SampleName;
  462. sampleMeasurePara.sampleHoleName = MeasureItem.NameOrHoleName;
  463. return sampleMeasurePara;
  464. }
  465. public List<PointF> ConvertPolygonPointToOTSPoint(List<PointF> polygonPointList)
  466. {
  467. List<PointF> OTSPoint = new List<PointF>();
  468. if (polygonPointList != null)
  469. {
  470. foreach (var item in polygonPointList)
  471. {
  472. OTSPoint.Add(CtrlCoordToOTSCoord(item));
  473. }
  474. }
  475. return OTSPoint;
  476. }
  477. public List<Point> PointFConvertPoint(List<PointF> Points)
  478. {
  479. List<Point> PointFs = new List<Point>();
  480. if (Points != null)
  481. {
  482. foreach (var itemPoint in Points)
  483. {
  484. PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
  485. }
  486. }
  487. return PointFs;
  488. }
  489. public PointF[] PointConvertPointF(Point[] Points)
  490. {
  491. PointF[] PointFs = new PointF[Points.Length];
  492. if (Points != null)
  493. {
  494. for (int i = 0; i < Points.Length; i++)
  495. {
  496. PointFs[i] = Points[i];
  497. }
  498. }
  499. return PointFs;
  500. }
  501. public List<PointF> PointConvertPointF(List<Point> Points)
  502. {
  503. List<PointF> PointFs = new List<PointF>();
  504. if (Points != null)
  505. {
  506. foreach (var itemPoint in Points)
  507. {
  508. PointFs.Add(itemPoint);
  509. }
  510. }
  511. return PointFs;
  512. }
  513. #endregion
  514. #region 添加测量
  515. public bool GetMeasureGdiObject(CDisplayGDIObject sampleGDIObject, ShapeType newShape, RectangleF newRegion, out CMeasureArea outMeasureRect)
  516. {
  517. CMeasureArea r = new CMeasureArea();
  518. r.NameOrHoleName = sampleGDIObject.NameOrHoleName;
  519. r.SampleName = sampleGDIObject.SampleName;
  520. r.SetInitRegionF(sampleGDIObject.GetOrigionalDrawRegionF());
  521. r.IsWorkSample = sampleGDIObject.IsWorkSample;
  522. r.SetZoomedRegionF(sampleGDIObject.GetZoomedRegionF());
  523. r.SetDisplayRefPoint(this.GetDisplayRefPoint());
  524. r.SetZoomNumber(sampleGDIObject.GetZoomNumber());
  525. r.SetInitRegionF(newRegion);
  526. r.Myshape = newShape;
  527. r.SelColor = Color.Red;
  528. outMeasureRect = r;
  529. return true;
  530. }
  531. public bool GetMeasureGdiObjectFromSampleGdi(CDisplayGDIObject sampleGDIObject, out CMeasureArea outMeasureRect)
  532. {
  533. //添加测量区域
  534. GDIType shape = sampleGDIObject.GDIType;
  535. var Measuregdi = sampleGDIObject.Duplicate();
  536. //MeasureRect.GPath = MeasurePath;
  537. Measuregdi.SelColor = Color.Red;
  538. outMeasureRect = (CMeasureArea)Measuregdi;
  539. return true;
  540. }
  541. #endregion
  542. public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
  543. {
  544. otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].GDIType;
  545. RectangleF pStageArea = m_StageEdgeGDIObjects[0].GetZoomedRegion;
  546. Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height);
  547. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  548. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  549. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  550. }
  551. public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm)
  552. {
  553. //鼠标在样品台中移动获取坐标
  554. Point mousePoint = GetMouseOTSLocation(mPoint);
  555. PointF SEMPoint = new Point();
  556. m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint);
  557. //将微米转换为毫米
  558. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  559. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  560. //将样品台坐标转换为Sem 坐标
  561. //编辑显示内容
  562. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  563. //显示XY轴
  564. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  565. }
  566. public Point GetMouseOTSLocation(Point mousePoint)
  567. {
  568. var offsetX = mousePoint.X - this.GetDisplayRefPoint().X;
  569. var offsetY = mousePoint.Y - this.GetDisplayRefPoint().Y;
  570. PointF ctrlPoint = new PointF(offsetX / this.GetZoomNum(), offsetY / this.GetZoomNum());
  571. PointF otsPoint = this.CtrlCoordToOTSCoord(ctrlPoint);
  572. Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(otsPoint.X, 0)), Convert.ToInt32(Math.Round(otsPoint.Y, 0)));
  573. return OTSMousePosition;
  574. }
  575. public bool IfMouseInSampleHole(Point mousePoint, out CDisplayGDIObject gdiItem)
  576. {
  577. foreach (CDisplayGDIObject item in m_SampleHoleGDIObjects)
  578. {
  579. if (item.IfZoomContains(mousePoint))
  580. {
  581. gdiItem = item;
  582. return true; ;
  583. }
  584. }
  585. gdiItem = null;
  586. return false;
  587. }
  588. public bool IfMouseInStage(Point mousePoint, out CDisplayGDIObject gdiobj)
  589. {
  590. foreach (CDisplayGDIObject item in m_StageEdgeGDIObjects)
  591. {
  592. if (item.IfZoomContains(mousePoint))
  593. {
  594. gdiobj = item;
  595. return true;
  596. }
  597. }
  598. gdiobj = null;
  599. return false;
  600. }
  601. public bool IfMouseInStage(Point mousePoint)
  602. {
  603. foreach (CDisplayGDIObject item in m_StageEdgeGDIObjects)
  604. {
  605. if (item.IfZoomContains(mousePoint))
  606. {
  607. return true;
  608. }
  609. }
  610. return false;
  611. }
  612. public void OnMouseMove(MouseEventArgs e)
  613. {
  614. foreach (CDisplayGDIObject item in m_ContentGDIObjects)
  615. {
  616. item.IsDragging = true;
  617. item.DraggingPoint = e.Location;
  618. }
  619. foreach (CDisplayGDIObject item in m_SampleHoleGDIObjects)
  620. {
  621. item.IsDragging = true;
  622. item.DraggingPoint = e.Location;
  623. }
  624. foreach (CDisplayGDIObject item in m_SpecimenGDIObjects)
  625. {
  626. item.IsDragging = true;
  627. item.DraggingPoint = e.Location;
  628. }
  629. }
  630. public List<CDisplayGDIObject> GetAllGDIObject()
  631. {
  632. var allobj = new List<CDisplayGDIObject>();
  633. foreach (CDisplayGDIObject item in m_StageEdgeGDIObjects)
  634. {
  635. allobj.Add(item);
  636. }
  637. foreach (CDisplayGDIObject item in m_SampleHoleGDIObjects)
  638. {
  639. allobj.Add(item);
  640. }
  641. foreach (CDisplayGDIObject item in m_SpecimenGDIObjects)
  642. {
  643. allobj.Add(item);
  644. }
  645. foreach (CDisplayGDIObject item in m_ContentGDIObjects)
  646. {
  647. allobj.Add(item);
  648. }
  649. return allobj;
  650. }
  651. public PointF GetCenterPoint(RectangleF rect)
  652. {
  653. //声明
  654. PointF centerPoint = new PointF();
  655. //设置X,Y坐标
  656. centerPoint.X = rect.X + rect.Width / 2;
  657. centerPoint.Y = rect.Y + rect.Height / 2;
  658. return centerPoint;
  659. }
  660. }
  661. }