VisualStage.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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. PointF m_RegionStartCenterPoint = new PointF(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 void clear()
  68. {
  69. m_StageEdgeGDIObjects.Clear();
  70. m_SpecimenGDIObjects.Clear();
  71. m_SampleHoleGDIObjects.Clear();
  72. m_ContentGDIObjects.Clear();
  73. }
  74. public CRectangleGDIObject 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 CRectangleGDIObject 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 CRectangleGDIObject 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 CRectangleGDIObject 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. OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo();
  145. //获取样品口的名称,形状,坐标
  146. SHoleInfo.sSHoleName = d.GetName();
  147. SHoleInfo.iSHoleShape = (int)d.GetShape();
  148. RectangleF r = d.GetRectDomain();
  149. SHoleInfo.HoleRect = 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. CRectangleGDIObject CreateBourary;
  206. //0:圆角矩形 1:圆形 2:文字 3:矩形
  207. if (SData.bStageShape == (ShapeType.RECTANGLE))
  208. {
  209. CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.SampleBackGround_Rectangle);
  210. }
  211. else
  212. {
  213. CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.Circle);
  214. }
  215. CreateBourary.Shape = StageShape;
  216. m_StageEdgeGDIObjects.Add(CreateBourary);
  217. //绘制后的样品台中心位置
  218. PointF m_Region = GetCenterPoint();
  219. //获取绘制后的样品台中心位置
  220. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  221. {
  222. m_RegionStartCenterPoint = m_Region;
  223. }
  224. //获取样品孔
  225. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  226. if (ChloeClrList.Count > 0)
  227. {
  228. for (int i = 0; i < ChloeClrList.Count; i++)
  229. {
  230. //获取微米信息
  231. var xHole = new PointF(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  232. var yHole = new PointF(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  233. //将微米转换为像素
  234. float widthHole = Math.Abs(yHole.X - xHole.X);
  235. float heightHole = Math.Abs(yHole.Y - xHole.Y);
  236. var RecF = GetCtrlCoordRectF(xHole, yHole);
  237. //获取矩形
  238. CRectangleGDIObject CreateHole = null;
  239. //0:圆角矩形 1:圆形 2:文字 3:矩形
  240. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  241. {
  242. CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Rectangle);
  243. }
  244. else
  245. {
  246. CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Circle);
  247. }
  248. CreateHole.NameOrHoleName= ChloeClrList[i].sSHoleName;
  249. m_SampleHoleGDIObjects.Add(CreateHole);
  250. //添加文字
  251. CRectangleGDIObject CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", "");
  252. //类型 文字:2
  253. CreateContent.CreateType = CreateRectangleType.Text;
  254. CreateContent.SetInitRegionF(CreateContent.GetZoomedRegionF());
  255. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  256. CreateContent.NameOrHoleName = ChloeClrList[i].sSHoleName;
  257. m_ContentGDIObjects.Add(CreateContent);
  258. }
  259. }
  260. //获取标样
  261. ShapeType StageShapes = SData.bStageShape;
  262. stageLeftTop = new PointF(SData.SampleRect.Left, SData.SampleRect.Top);
  263. stageRightBottom = new PointF(SData.SampleRect.Right, SData.SampleRect.Bottom);
  264. //获取矩形
  265. CRectangleGDIObject CreateSTD;
  266. if (StageShapes == (int)CreateRectangleType.Circle)
  267. {
  268. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenCircle, "", "");
  269. }
  270. else
  271. {
  272. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenRectangle, "", "");
  273. }
  274. m_SpecimenGDIObjects.Add(CreateSTD);
  275. return;
  276. }
  277. catch (Exception ex)
  278. {
  279. NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() );
  280. }
  281. }
  282. public CRectangleGDIObject GetCtrlCoordRect(PointF OTSLeftTop, PointF OTSRightBottom, CreateRectangleType type, string content, string name)
  283. {
  284. try
  285. {
  286. //将微米信息 转换为 像素
  287. PointF xPoints = new Point();
  288. PointF yPoints = new Point();
  289. xPoints.X =(float) MicronConvertToPixel(OTSLeftTop.X );
  290. xPoints.Y = (float)MicronConvertToPixel( OTSLeftTop.Y );
  291. yPoints.X = (float)MicronConvertToPixel( OTSRightBottom.X );
  292. yPoints.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  293. //计算位置
  294. xPoints = (PointF)CalculateLocationF(xPoints);
  295. yPoints = CalculateLocationF(yPoints);
  296. //获取图形四个点
  297. float realStartX = Math.Min(xPoints.X, yPoints.X);
  298. float realStartY = Math.Min(xPoints.Y, yPoints.Y);
  299. float realEndX = Math.Max(xPoints.X, yPoints.X);
  300. float realEndY = Math.Max(xPoints.Y, yPoints.Y);
  301. //创建矩形 并返回类型对象
  302. return new CRectangleGDIObject(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
  303. }
  304. catch (Exception)
  305. {
  306. return new CRectangleGDIObject(new Rectangle(), 0, "");
  307. }
  308. }
  309. public RectangleF GetCtrlCoordRectF(PointF OTSLeftTop, PointF OTSRightBottom)
  310. {
  311. try
  312. {
  313. //将微米信息 转换为 像素
  314. PointF leftTop = new PointF();
  315. PointF rightBottom = new PointF();
  316. leftTop.X = (float)MicronConvertToPixel( OTSLeftTop.X);
  317. leftTop.Y = (float)MicronConvertToPixel( OTSLeftTop.Y);
  318. rightBottom.X = (float)MicronConvertToPixel( OTSRightBottom.X);
  319. rightBottom.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  320. //计算位置
  321. leftTop = CalculateLocationF(leftTop );
  322. rightBottom = CalculateLocationF(rightBottom);
  323. //获取图形四个点
  324. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  325. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  326. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  327. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  328. //创建矩形 并返回类型对象
  329. return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
  330. }
  331. catch (Exception)
  332. {
  333. return new RectangleF();
  334. }
  335. }
  336. private PointF CalculateLocationF(PointF point)
  337. {
  338. //获取窗体的高度与宽度
  339. float ctrlWidth = m_totalCtrlWidth;
  340. float ctrlHeight = m_totalCtrlHeight;
  341. //获取屏幕中心点
  342. PointF pointXY = new PointF();
  343. PointF screenPoint = new PointF(ctrlWidth / 2, ctrlHeight / 2);
  344. pointXY.X = screenPoint.X + point.X;
  345. pointXY.Y = screenPoint.Y - point.Y;//using minus because the coordinate system defference of OTS system and control system.
  346. return pointXY;
  347. }
  348. public double MicronConvertToPixel(double PointVal)
  349. {
  350. var v = m_VisualStageEdgeLength;
  351. return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
  352. }
  353. public PointF OTSCoordToCtrlCoord(PointF point)
  354. {
  355. var x = MicronConvertToPixel(point.X);
  356. var y = MicronConvertToPixel(point.Y);
  357. return CalculateLocationF(new PointF((float)x, (float)y));
  358. }
  359. public PointF CtrlCoordToOTSCoord(PointF point)
  360. {
  361. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  362. var x = PixelConvertToMicron(point.X - ctrlcenter.X);
  363. var y = PixelConvertToMicron(-(point.Y - ctrlcenter.Y));
  364. return new PointF(x, y);
  365. }
  366. public RectangleF GetOTSCoordRegionF(PointF ctrlLeftTop, PointF ctrlRightBottom)
  367. {
  368. try
  369. {
  370. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  371. //将微米信息 转换为 像素
  372. PointF leftTop = new PointF();
  373. PointF rightBottom = new PointF();
  374. leftTop.X = (float)PixelConvertToMicron(ctrlLeftTop.X-ctrlcenter.X);
  375. leftTop.Y = (float)PixelConvertToMicron((ctrlLeftTop.Y-ctrlcenter.Y));
  376. rightBottom.X = (float)PixelConvertToMicron(ctrlRightBottom.X-ctrlcenter.X);
  377. rightBottom.Y = (float)PixelConvertToMicron((ctrlRightBottom.Y-ctrlcenter.Y));
  378. //获取OTS图形四个点
  379. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  380. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  381. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  382. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  383. //创建矩形 并返回类型对象
  384. return new RectangleF(realStartX, -realEndY, realEndX - realStartX, realEndY - realStartY);
  385. }
  386. catch (Exception)
  387. {
  388. return new RectangleF();
  389. }
  390. }
  391. public float PixelConvertToMicron(float Pixel)
  392. {
  393. return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  394. }
  395. internal void DecreaseSampleCount(string sampleName)
  396. {
  397. foreach (var hole in m_SampleHoleGDIObjects)
  398. {
  399. if (hole.SampleName == sampleName)
  400. {
  401. hole.SampleCount -= 1;
  402. }
  403. }
  404. }
  405. public CRectangleGDIObject GetSampleHoleGdiobjByName(string holeName)
  406. {
  407. foreach (var hole in m_SampleHoleGDIObjects)
  408. {
  409. if (hole.NameOrHoleName == holeName)
  410. {
  411. return hole;
  412. }
  413. }
  414. return null;
  415. }
  416. public bool GetVisualSampleArea(SampleMeasurePara SMeasurePara, out CVisualSampleArea a_visualSample)
  417. {
  418. //设置样品选择状态为非工作样品
  419. string SampleHoleName = SMeasurePara.sampleHoleName;
  420. var item = GetSampleHoleGdiobjByName(SampleHoleName);
  421. if (item != null)
  422. {
  423. //设置颜色
  424. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  425. Color selColor = ColorTranslator.FromHtml(ColorStr);
  426. //累加样品数量
  427. item.SampleCount += 1;
  428. item.IsWorkSample = true;
  429. CRectangleGDIObject sampleGDIObject = item.Duplicate(CreateRectangleType.SelectSample);
  430. sampleGDIObject.sampleName = SMeasurePara.sSampleName;
  431. sampleGDIObject.SelColor = selColor;
  432. //add the default measure area from config file.
  433. CRectangleGDIObject 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(CRectangleGDIObject 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.Shape;
  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. /// <summary>
  516. /// 添加测量
  517. /// </summary>
  518. /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
  519. /// <param name="sampleName">样品名称</param>
  520. /// <returns>是否成功</returns>
  521. public bool GetMeasureGdiObject( CRectangleGDIObject sampleGDIObject,ShapeType newShape, RectangleF newRegion, out CRectangleGDIObject outMeasureRect)
  522. {
  523. var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
  524. MeasureRect.SetInitRegionF(newRegion);
  525. MeasureRect.SelColor = Color.Red;
  526. MeasureRect.Shape = newShape;
  527. outMeasureRect = MeasureRect;
  528. return true;
  529. }
  530. public bool GetMeasureGdiObjectFromSampleGdi(CRectangleGDIObject sampleGDIObject, out CRectangleGDIObject outMeasureRect)
  531. {
  532. //添加测量区域
  533. CreateRectangleType shape = sampleGDIObject.CreateType;
  534. var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
  535. //MeasureRect.GPath = MeasurePath;
  536. MeasureRect.SelColor = Color.Red;
  537. outMeasureRect = MeasureRect;
  538. return true;
  539. }
  540. #endregion
  541. public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
  542. {
  543. otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType;
  544. RectangleF pStageArea = m_StageEdgeGDIObjects[0].GetZoomedRegion;
  545. Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height);
  546. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  547. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  548. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  549. }
  550. public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm)
  551. {
  552. //鼠标在样品台中移动获取坐标
  553. Point mousePoint = GetMouseOTSLocation(mPoint);
  554. PointF SEMPoint = new Point();
  555. m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint);
  556. //将微米转换为毫米
  557. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  558. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  559. //将样品台坐标转换为Sem 坐标
  560. //编辑显示内容
  561. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  562. //显示XY轴
  563. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  564. }
  565. public Point GetMouseOTSLocation(Point mousePoint)
  566. {
  567. var offsetX = mousePoint.X - this.GetDisplayRefPoint().X;
  568. var offsetY = mousePoint.Y - this.GetDisplayRefPoint().Y;
  569. PointF ctrlPoint = new PointF(offsetX / this.GetZoomNum(), offsetY / this.GetZoomNum());
  570. PointF otsPoint = this.CtrlCoordToOTSCoord(ctrlPoint);
  571. Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(otsPoint.X, 0)), Convert.ToInt32(Math.Round(otsPoint.Y, 0)));
  572. return OTSMousePosition;
  573. }
  574. public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem)
  575. {
  576. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  577. {
  578. if (item.IfZoomContains(mousePoint))
  579. {
  580. gdiItem = item;
  581. return true; ;
  582. }
  583. }
  584. gdiItem = null;
  585. return false;
  586. }
  587. public bool IfMouseInStage(Point mousePoint,out CRectangleGDIObject gdiobj)
  588. {
  589. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  590. {
  591. if (item.IfZoomContains(mousePoint))
  592. {
  593. gdiobj = item;
  594. return true;
  595. }
  596. }
  597. gdiobj = null;
  598. return false;
  599. }
  600. public bool IfMouseInStage(Point mousePoint )
  601. {
  602. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  603. {
  604. if (item.IfZoomContains(mousePoint))
  605. {
  606. return true;
  607. }
  608. }
  609. return false;
  610. }
  611. public void OnMouseMove( MouseEventArgs e)
  612. {
  613. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  614. {
  615. item.IsDragging = true;
  616. item.DraggingPoint = e.Location;
  617. }
  618. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  619. {
  620. item.IsDragging = true;
  621. item.DraggingPoint = e.Location;
  622. }
  623. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  624. {
  625. item.IsDragging = true;
  626. item.DraggingPoint = e.Location;
  627. }
  628. }
  629. public List<CRectangleGDIObject> GetAllGDIObject()
  630. {
  631. var allobj = new List<CRectangleGDIObject>();
  632. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  633. {
  634. allobj.Add(item);
  635. }
  636. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  637. {
  638. allobj.Add(item);
  639. }
  640. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  641. {
  642. allobj.Add(item);
  643. }
  644. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  645. {
  646. allobj.Add(item);
  647. }
  648. return allobj;
  649. }
  650. public List<CRectangleGDIObject> GetAllGDIObjectWithoutHoleNameStr()
  651. {
  652. var allobj = new List<CRectangleGDIObject>();
  653. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  654. {
  655. allobj.Add(item);
  656. }
  657. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  658. {
  659. allobj.Add(item);
  660. }
  661. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  662. {
  663. allobj.Add(item);
  664. }
  665. return allobj;
  666. }
  667. public PointF GetCenterPoint(RectangleF rect)
  668. {
  669. //声明
  670. PointF centerPoint = new PointF();
  671. //设置X,Y坐标
  672. centerPoint.X = rect.X + rect.Width / 2;
  673. centerPoint.Y = rect.Y + rect.Height / 2;
  674. return centerPoint;
  675. }
  676. public SampleHolePara GetSampleHoleInfo(CRectangleGDIObject item)
  677. {
  678. SampleHolePara sampleHolePara = new SampleHolePara();
  679. //设置测量区域
  680. sampleHolePara.SampleHoleRect = item.GetZoomedRegion;
  681. //设置测量区域位置与尺寸
  682. float left = PixelConvertToMicron(item.GetZoomedRegionF().X);
  683. float Top = PixelConvertToMicron(item.GetZoomedRegionF().Y);
  684. float Width = PixelConvertToMicron(item.GetZoomedRegionF().Width);
  685. float Height = PixelConvertToMicron(item.GetZoomedRegionF().Height);
  686. PointF startPoint = new PointF(left, Top);
  687. SizeF sampleHoleSize = new SizeF(Width, Height);
  688. sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
  689. //设置样品孔名称
  690. sampleHolePara.sHoleName = item.NameOrHoleName;
  691. //设置测量区域形状
  692. sampleHolePara.iShape = item.Shape;
  693. return sampleHolePara;
  694. }
  695. }
  696. }