CVisualStage.cs 31 KB

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