CVisualStage.cs 31 KB

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