VisualStage.cs 32 KB

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