VisualStage.cs 30 KB

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