VisualStage.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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.IfScaleContains(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. string stageName = GetOTSSampleStageData().sStageName;
  154. //获取样品台
  155. ShapeType StageShape = GetOTSSampleStageData().bStageShape;
  156. PointF xDomain = new PointF(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top);
  157. PointF yDomain = new PointF(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom);
  158. //OTS宽度高度差值
  159. float widthDomain = Math.Abs(yDomain.X - xDomain.X);
  160. float heightDomain = Math.Abs(yDomain.Y - xDomain.Y);
  161. //样品台转换在电镜位置的宽度与高度
  162. //设置样品台宽度
  163. m_OTSCoordStageEdgeLength = widthDomain;//the stage must be a square.So we can only memorize an edge length.this is millimeter usually.
  164. m_VisualStageEdgeLength = ctrlHeight > ctrlWidth ? ctrlWidth : ctrlHeight;//the stage must be a square.So we can memorize an edge length only.
  165. //记录添加帧图的尺寸 鼠标滚动时使用的原值
  166. m_totalCtrlWidth = ctrlWidth;
  167. m_totalCtrlHeight = ctrlHeight;
  168. return;
  169. }
  170. public PointF GetCenterPointF()
  171. {
  172. var item = m_StageEdgeGDIObjects[0].GetZoomedRegionF();
  173. //声明中心点变量
  174. PointF pCenterPoint = new Point();
  175. //获取在工作窗口中X,Y位置
  176. pCenterPoint.X = item.X + item.Width / 2;
  177. pCenterPoint.Y = item.Y + item.Height / 2;
  178. return pCenterPoint;
  179. }
  180. public Point GetCenterPoint()
  181. {
  182. return m_StageEdgeGDIObjects[0].GetCenterPoint();
  183. //声明中心点变量
  184. }
  185. public void DrawSampleStage()
  186. {
  187. StageDrawingData SData = GetOTSSampleStageData();
  188. try
  189. {
  190. if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0)
  191. {
  192. return;
  193. }
  194. string stageName = SData.sStageName;
  195. //获取样品台
  196. ShapeType StageShape = SData.bStageShape;
  197. PointF stageLeftTop = new PointF(SData.StageDomain.Left, SData.StageDomain.Top);
  198. PointF stageRightBottom = new PointF(SData.StageDomain.Right, SData.StageDomain.Bottom);
  199. m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation);
  200. m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation);
  201. RectangleF Bourary;
  202. Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom);
  203. CRectangleGDIObject CreateBourary;
  204. //0:圆角矩形 1:圆形 2:文字 3:矩形
  205. if (SData.bStageShape == (ShapeType.RECTANGLE))
  206. {
  207. CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.SampleBackGround_Rectangle);
  208. }
  209. else
  210. {
  211. CreateBourary = new CRectangleGDIObject(Bourary, CreateRectangleType.Circle);
  212. }
  213. //添加样品台 对象
  214. //设置路径
  215. //GraphicsPath MeasurePath = new GraphicsPath();
  216. //if (StageShape == (int)CreateRectangleType.Circle)
  217. //{
  218. // MeasurePath.AddEllipse(CreateBourary.GetZoomedRegion);
  219. //}
  220. //else
  221. //{
  222. // MeasurePath.AddRectangle(CreateBourary.GetZoomedRegion);
  223. //}
  224. //CreateBourary.GPath = MeasurePath;
  225. CreateBourary.Shape = StageShape;
  226. m_StageEdgeGDIObjects.Add(CreateBourary);
  227. //绘制后的样品台中心位置
  228. Point m_Region = GetCenterPoint();
  229. //获取绘制后的样品台中心位置
  230. if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y)
  231. {
  232. m_RegionStartCenterPoint = m_Region;
  233. }
  234. //获取样品孔
  235. System.Collections.Generic.List<OTSSampleHoleInfo> ChloeClrList = SData.sSHoleInfoList;
  236. if (ChloeClrList.Count > 0)
  237. {
  238. for (int i = 0; i < ChloeClrList.Count; i++)
  239. {
  240. //获取微米信息
  241. var xHole = new PointF(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top);
  242. var yHole = new PointF(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom);
  243. //将微米转换为像素
  244. float widthHole = Math.Abs(yHole.X - xHole.X);
  245. float heightHole = Math.Abs(yHole.Y - xHole.Y);
  246. var RecF = GetCtrlCoordRectF(xHole, yHole);
  247. //获取矩形
  248. CRectangleGDIObject CreateHole = null;
  249. //0:圆角矩形 1:圆形 2:文字 3:矩形
  250. if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle)
  251. {
  252. CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Rectangle);
  253. }
  254. else
  255. {
  256. CreateHole = new CRectangleGDIObject(RecF, CreateRectangleType.Circle);
  257. }
  258. CreateHole.Name= ChloeClrList[i].sSHoleName;
  259. m_SampleHoleGDIObjects.Add(CreateHole);
  260. //添加文字
  261. CRectangleGDIObject CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", "");
  262. //类型 文字:2
  263. CreateContent.CreateType = CreateRectangleType.Text;
  264. CreateContent.SetInitRegionF(CreateContent.GetZoomedRegionF());
  265. CreateContent.strContent = ChloeClrList[i].sSHoleName;
  266. CreateContent.Name = ChloeClrList[i].sSHoleName;
  267. m_ContentGDIObjects.Add(CreateContent);
  268. }
  269. }
  270. //获取标样
  271. ShapeType StageShapes = SData.bStageShape;
  272. stageLeftTop = new PointF(SData.SampleRect.Left, SData.SampleRect.Top);
  273. stageRightBottom = new PointF(SData.SampleRect.Right, SData.SampleRect.Bottom);
  274. //获取矩形
  275. CRectangleGDIObject CreateSTD;
  276. if (StageShapes == (int)CreateRectangleType.Circle)
  277. {
  278. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenCircle, "", "");
  279. }
  280. else
  281. {
  282. CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenRectangle, "", "");
  283. }
  284. m_SpecimenGDIObjects.Add(CreateSTD);
  285. return;
  286. }
  287. catch (Exception ex)
  288. {
  289. NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() );
  290. }
  291. }
  292. public CRectangleGDIObject GetCtrlCoordRect(PointF OTSLeftTop, PointF OTSRightBottom, CreateRectangleType type, string content, string name)
  293. {
  294. try
  295. {
  296. //将微米信息 转换为 像素
  297. PointF xPoints = new Point();
  298. PointF yPoints = new Point();
  299. xPoints.X =(float) MicronConvertToPixel(OTSLeftTop.X );
  300. xPoints.Y = (float)MicronConvertToPixel( OTSLeftTop.Y );
  301. yPoints.X = (float)MicronConvertToPixel( OTSRightBottom.X );
  302. yPoints.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  303. //计算位置
  304. xPoints = (PointF)CalculateLocationF(xPoints);
  305. yPoints = CalculateLocationF(yPoints);
  306. //获取图形四个点
  307. float realStartX = Math.Min(xPoints.X, yPoints.X);
  308. float realStartY = Math.Min(xPoints.Y, yPoints.Y);
  309. float realEndX = Math.Max(xPoints.X, yPoints.X);
  310. float realEndY = Math.Max(xPoints.Y, yPoints.Y);
  311. //创建矩形 并返回类型对象
  312. return new CRectangleGDIObject(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name);
  313. }
  314. catch (Exception)
  315. {
  316. return new CRectangleGDIObject(new Rectangle(), 0, "");
  317. }
  318. }
  319. public RectangleF GetCtrlCoordRectF(PointF OTSLeftTop, PointF OTSRightBottom)
  320. {
  321. try
  322. {
  323. //将微米信息 转换为 像素
  324. PointF leftTop = new PointF();
  325. PointF rightBottom = new PointF();
  326. leftTop.X = (float)MicronConvertToPixel( OTSLeftTop.X);
  327. leftTop.Y = (float)MicronConvertToPixel( OTSLeftTop.Y);
  328. rightBottom.X = (float)MicronConvertToPixel( OTSRightBottom.X);
  329. rightBottom.Y = (float)MicronConvertToPixel(OTSRightBottom.Y);
  330. //计算位置
  331. leftTop = CalculateLocationF(leftTop );
  332. rightBottom = CalculateLocationF(rightBottom);
  333. //获取图形四个点
  334. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  335. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  336. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  337. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  338. //创建矩形 并返回类型对象
  339. return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
  340. }
  341. catch (Exception)
  342. {
  343. return new RectangleF();
  344. }
  345. }
  346. public PointF CalculateLocationF(PointF point)
  347. {
  348. //获取窗体的高度与宽度
  349. int ctrlWidth = m_totalCtrlWidth;
  350. int ctrlHeight = m_totalCtrlHeight;
  351. //获取屏幕中心点
  352. PointF pointXY = new PointF();
  353. PointF screenPoint = new PointF(ctrlWidth / 2, ctrlHeight / 2);
  354. pointXY.X = screenPoint.X + point.X;
  355. pointXY.Y = screenPoint.Y - point.Y;//using minus because the coordinate system defference of OTS system and control system.
  356. return pointXY;
  357. }
  358. public double MicronConvertToPixel(double PointVal)
  359. {
  360. var v = m_VisualStageEdgeLength;
  361. return PointVal / ((double)m_OTSCoordStageEdgeLength / v);
  362. }
  363. public PointF OTSCoordToCtrlCoord(PointF point)
  364. {
  365. var x = MicronConvertToPixel(point.X);
  366. var y = MicronConvertToPixel(point.Y);
  367. return CalculateLocationF(new PointF((float)x, (float)y));
  368. }
  369. public PointF CtrlCoordToOTSCoord(PointF point)
  370. {
  371. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  372. var x = PixelConvertToMicron(point.X - ctrlcenter.X);
  373. var y = PixelConvertToMicron(-(point.Y - ctrlcenter.Y));
  374. return new PointF(x, y);
  375. }
  376. public RectangleF GetOTSCoordRegionF(PointF ctrlLeftTop, PointF ctrlRightBottom)
  377. {
  378. try
  379. {
  380. var ctrlcenter = m_StageEdgeGDIObjects[0].GetCenterPoint();
  381. //将微米信息 转换为 像素
  382. PointF leftTop = new PointF();
  383. PointF rightBottom = new PointF();
  384. leftTop.X = (float)PixelConvertToMicron(ctrlLeftTop.X-ctrlcenter.X);
  385. leftTop.Y = (float)PixelConvertToMicron((ctrlLeftTop.Y-ctrlcenter.Y));
  386. rightBottom.X = (float)PixelConvertToMicron(ctrlRightBottom.X-ctrlcenter.X);
  387. rightBottom.Y = (float)PixelConvertToMicron((ctrlRightBottom.Y-ctrlcenter.Y));
  388. //计算位置
  389. //leftTop = CalculateOTSLocation(leftTop);
  390. //rightBottom = CalculateOTSLocation(rightBottom);
  391. //获取OTS图形四个点
  392. float realStartX = Math.Min(leftTop.X, rightBottom.X);
  393. float realStartY = Math.Min(leftTop.Y, rightBottom.Y);
  394. float realEndX = Math.Max(leftTop.X, rightBottom.X);
  395. float realEndY = Math.Max(leftTop.Y, rightBottom.Y);
  396. //创建矩形 并返回类型对象
  397. return new RectangleF(realStartX, -realEndY, realEndX - realStartX, realEndY - realStartY);
  398. }
  399. catch (Exception)
  400. {
  401. return new RectangleF();
  402. }
  403. }
  404. public float PixelConvertToMicron(float Pixel)
  405. {
  406. return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength));
  407. }
  408. internal void DecreaseSampleCount(string sampleName)
  409. {
  410. foreach (var hole in m_SampleHoleGDIObjects)
  411. {
  412. if (hole.SampleName == sampleName)
  413. {
  414. hole.SampleCount -= 1;
  415. }
  416. }
  417. }
  418. private CRectangleGDIObject GetSampleHoleGdiobjByName(string holeName)
  419. {
  420. foreach (var hole in m_SampleHoleGDIObjects)
  421. {
  422. if (hole.Name == holeName)
  423. {
  424. return hole;
  425. }
  426. }
  427. return null;
  428. }
  429. public bool GetVisualSampleArea(SampleMeasurePara SMeasurePara, out CVisualSampleArea a_visualSample)
  430. {
  431. //设置样品选择状态为非工作样品
  432. string SampleHoleName = SMeasurePara.sampleHoleName;
  433. var item = GetSampleHoleGdiobjByName(SampleHoleName);
  434. if (item != null)
  435. {
  436. //设置颜色
  437. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  438. Color selColor = ColorTranslator.FromHtml(ColorStr);
  439. //累加样品数量
  440. item.SampleCount += 1;
  441. item.IsWorkSample = true;
  442. CRectangleGDIObject sampleGDIObject = item.Duplicate(CreateRectangleType.SelectSample);
  443. sampleGDIObject.sampleName = SMeasurePara.sSampleName;
  444. sampleGDIObject.SelColor = selColor;
  445. ;
  446. //add the default measure area from config file.
  447. CRectangleGDIObject newMeasureGDIObject;
  448. PointF xHole = new PointF(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top);
  449. PointF yHole = new PointF(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom);
  450. RectangleF SampleRectangleF = GetCtrlCoordRectF(xHole, yHole);
  451. GetMeasureGdiObject(sampleGDIObject, SampleRectangleF, out newMeasureGDIObject);
  452. var newsample = new CVisualSampleArea();
  453. newsample.SampleGDIObject = sampleGDIObject;
  454. newsample.MeasureGDIObject = newMeasureGDIObject;
  455. a_visualSample = newsample;
  456. return true;
  457. }
  458. a_visualSample = null;
  459. return false;
  460. }
  461. #region 根据样品位置 获取测量区域位置
  462. public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem)
  463. {
  464. var item = MeasureItem;
  465. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  466. var region = this.GetOTSCoordRegionF(item.GetOrigionalDrawRegionF().Location, new PointF(item.GetOrigionalDrawRegionF().Right, item.GetOrigionalDrawRegionF().Bottom));
  467. sampleMeasurePara.MeasureRect = region;
  468. //设置样品孔名称
  469. sampleMeasurePara.sampleHoleName = item.Name;
  470. //设置样品名称
  471. sampleMeasurePara.sSampleName = item.SampleName;
  472. //设置测量区域形状
  473. sampleMeasurePara.iShape = item.Shape;
  474. sampleMeasurePara.DrawPolygonPointList = ConvertPolygonPointToOTSPoint(item.OriginalPolygonPointFList);
  475. sampleMeasurePara.sSampleName = MeasureItem.SampleName ;
  476. sampleMeasurePara.sampleHoleName =MeasureItem.Name;
  477. return sampleMeasurePara;
  478. }
  479. public List<PointF> ConvertPolygonPointToOTSPoint(List<PointF> polygonPointList)
  480. {
  481. List<PointF> OTSPoint = new List<PointF>();
  482. if (polygonPointList != null)
  483. {
  484. foreach (var item in polygonPointList)
  485. {
  486. OTSPoint.Add(CtrlCoordToOTSCoord(item));
  487. }
  488. }
  489. return OTSPoint;
  490. }
  491. public List<Point> PointFConvertPoint(List<PointF> Points)
  492. {
  493. List<Point> PointFs = new List<Point>();
  494. if (Points != null)
  495. {
  496. foreach (var itemPoint in Points)
  497. {
  498. PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
  499. }
  500. }
  501. return PointFs;
  502. }
  503. public PointF[] PointConvertPointF(Point[] Points)
  504. {
  505. PointF[] PointFs = new PointF[Points.Length];
  506. if (Points != null)
  507. {
  508. for (int i = 0; i < Points.Length; i++)
  509. {
  510. PointFs[i] = Points[i];
  511. }
  512. }
  513. return PointFs;
  514. }
  515. public List<PointF> PointConvertPointF(List<Point> Points)
  516. {
  517. List<PointF> PointFs = new List<PointF>();
  518. if (Points != null)
  519. {
  520. foreach (var itemPoint in Points)
  521. {
  522. PointFs.Add(itemPoint);
  523. }
  524. }
  525. return PointFs;
  526. }
  527. #endregion
  528. #region 添加测量
  529. /// <summary>
  530. /// 添加测量
  531. /// </summary>
  532. /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
  533. /// <param name="sampleName">样品名称</param>
  534. /// <returns>是否成功</returns>
  535. public bool GetMeasureGdiObject( CRectangleGDIObject sampleGDIObject,RectangleF newRegion, out CRectangleGDIObject outMeasureRect)
  536. {
  537. //添加测量区域
  538. var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
  539. MeasureRect.SetInitRegionF(newRegion);
  540. MeasureRect.SelColor = Color.Red;
  541. outMeasureRect = MeasureRect;
  542. return true;
  543. }
  544. public bool GetMeasureGdiObject(CRectangleGDIObject sampleGDIObject, out CRectangleGDIObject outMeasureRect)
  545. {
  546. //添加测量区域
  547. CreateRectangleType shape = sampleGDIObject.CreateType;
  548. var MeasureRect = sampleGDIObject.Duplicate(CreateRectangleType.MeasureArea);
  549. //MeasureRect.GPath = MeasurePath;
  550. MeasureRect.SelColor = Color.Red;
  551. outMeasureRect = MeasureRect;
  552. return true;
  553. }
  554. #endregion
  555. public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea)
  556. {
  557. otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType;
  558. RectangleF pStageArea = m_StageEdgeGDIObjects[0].GetZoomedRegion;
  559. Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height);
  560. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  561. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  562. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  563. }
  564. public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm)
  565. {
  566. //鼠标在样品台中移动获取坐标
  567. Point mousePoint = GetMouseSEMLocation(mPoint);
  568. PointF SEMPoint = new Point();
  569. m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint);
  570. //将微米转换为毫米
  571. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  572. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  573. //将样品台坐标转换为Sem 坐标
  574. //编辑显示内容
  575. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  576. //显示XY轴
  577. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  578. }
  579. public Point GetMouseSEMLocation(Point mousePoint)
  580. {
  581. var domain = GetOTSSampleStageData().StageDomain;
  582. PointF rectLocation = m_StageEdgeGDIObjects[0].GetZoomedRegion.Location;
  583. //样品台尺寸
  584. SizeF rectSize = m_StageEdgeGDIObjects[0].GetZoomedRegion.Size;
  585. //鼠标在工作区域中的位置
  586. //OTS坐标中鼠标的位置
  587. float OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
  588. float OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
  589. //OTS坐标中鼠标的尺寸位置
  590. double OTSWidth = 0;
  591. double OTSHeight = 0;
  592. float width = m_VisualStageEdgeLength;
  593. float height = m_VisualStageEdgeLength;
  594. //获取样品台两个坐标点
  595. var XDomain = new PointF(domain.Left, domain.Top);
  596. var YDomain = new PointF(domain.Right, domain.Bottom);
  597. //转换类型
  598. PointF xDomain = (XDomain);
  599. PointF yDomain = (YDomain);
  600. //宽度
  601. float widthDomain = Math.Abs((yDomain).X - (xDomain).X);
  602. float heightDomain = Math.Abs((yDomain).Y - (xDomain).Y);
  603. //换算鼠标在OTS坐标中的位置
  604. OTSWidth = (OTSX * ((double)widthDomain / width));
  605. OTSHeight = (OTSY * ((double)widthDomain / height));
  606. Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(OTSWidth, 0)), Convert.ToInt32(Math.Round(OTSHeight, 0)));
  607. return OTSMousePosition;
  608. }
  609. public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem)
  610. {
  611. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  612. {
  613. if (item.IfScaleContains(mousePoint))
  614. {
  615. gdiItem = item;
  616. return true; ;
  617. }
  618. }
  619. gdiItem = null;
  620. return false;
  621. }
  622. public bool IfMouseInStage(Point mousePoint,out CRectangleGDIObject gdiobj)
  623. {
  624. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  625. {
  626. if (item.IfScaleContains(mousePoint))
  627. {
  628. gdiobj = item;
  629. return true;
  630. }
  631. }
  632. gdiobj = null;
  633. return false;
  634. }
  635. public bool IfMouseInStage(Point mousePoint )
  636. {
  637. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  638. {
  639. if (item.IfScaleContains(mousePoint))
  640. {
  641. return true;
  642. }
  643. }
  644. return false;
  645. }
  646. //public void OnMouseMove(CRectangleGDIObject item,MouseEventArgs e)
  647. //{
  648. // foreach (CRectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects)
  649. // {
  650. // //获取样品孔中心点
  651. // Point sampleHoleCenterPoint = sampleHoleItem.GetCenterPoint();
  652. // if (item.IfScaleContains(sampleHoleCenterPoint))
  653. // {
  654. // if (item.Name != sampleHoleItem.Name)
  655. // {
  656. // //获取颜色
  657. // string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  658. // item.SelColor = ColorTranslator.FromHtml(ColorStr);
  659. // break;
  660. // }
  661. // }
  662. // else
  663. // {
  664. // //获取颜色
  665. // string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  666. // item.SelColor = ColorTranslator.FromHtml(ColorStr);
  667. // }
  668. // }
  669. //}
  670. public void OnMouseMove( MouseEventArgs e)
  671. {
  672. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  673. {
  674. item.IsDragging = true;
  675. item.DraggingPoint = e.Location;
  676. }
  677. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  678. {
  679. item.IsDragging = true;
  680. item.DraggingPoint = e.Location;
  681. }
  682. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  683. {
  684. item.IsDragging = true;
  685. item.DraggingPoint = e.Location;
  686. }
  687. }
  688. public List<CRectangleGDIObject> GetAllGDIObject()
  689. {
  690. var allobj = new List<CRectangleGDIObject>();
  691. foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects)
  692. {
  693. allobj.Add(item);
  694. }
  695. foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects)
  696. {
  697. allobj.Add(item);
  698. }
  699. foreach (CRectangleGDIObject item in m_SpecimenGDIObjects)
  700. {
  701. allobj.Add(item);
  702. }
  703. foreach (CRectangleGDIObject item in m_ContentGDIObjects)
  704. {
  705. allobj.Add(item);
  706. }
  707. return allobj;
  708. }
  709. public bool NewLocationDrawSingleInfo( Point moveToSEMLocation, List<CRectangleGDIObject> UpdateLocationGDIObject, CRectangleGDIObject WorkMeasure)
  710. {
  711. //样品台中心点位置
  712. Point m_StageCenterPoint = GetCenterPoint();
  713. //当前与中心点相差距离
  714. int m_StageCenterDiffX ;
  715. int m_StageCenterDiffY;
  716. Point m_WorkMeasureCenterPoint ;
  717. if (UpdateLocationGDIObject == null)
  718. {
  719. return false;
  720. }
  721. int diffNewX ;
  722. int diffNewY ;
  723. bool IsOK = true;
  724. //diffNewX = moveToSEMLocation.X;
  725. //diffNewY = moveToSEMLocation.Y;
  726. if (IsOK)
  727. {
  728. foreach (var item in UpdateLocationGDIObject)
  729. {
  730. m_WorkMeasureCenterPoint = WorkMeasure.GetCenterPoint();
  731. m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum);
  732. m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum);
  733. diffNewX = (int)(moveToSEMLocation.X * GetZoomNum());
  734. diffNewY = (int)(moveToSEMLocation.Y * GetZoomNum());
  735. //根据鼠标_更改测量区域的位置
  736. //item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height));
  737. item.SetInitRegionF(new RectangleF(new PointF(item.GetZoomedRegionF().X + (m_StageCenterDiffX + diffNewX), item.GetZoomedRegionF().Y + (m_StageCenterDiffY - diffNewY)), new SizeF(item.GetZoomedRegionF().Width, item.GetZoomedRegionF().Height)));
  738. //item.DrawRegionF = new RectangleF(new PointF(item.DrawRegionF.X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawRegionF.Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.DrawRegionF.Width, item.DrawRegionF.Height));
  739. }
  740. }
  741. return IsOK;
  742. }
  743. public void NewLocationDrawMeasureInfo( Point moveToSEMLocation, CRectangleGDIObject UpdateLocationGDIObject)
  744. {
  745. //样品台中心点位置
  746. Point m_StageCenterPoint = GetCenterPoint();
  747. //当前与中心点相差距离
  748. int m_StageCenterDiffX ;
  749. int m_StageCenterDiffY ;
  750. int diffNewX ;
  751. int diffNewY ;
  752. Point m_UpdateCenterPoint ;
  753. var m_GlobalZoomNum = GetZoomNum();
  754. var item = UpdateLocationGDIObject;
  755. m_UpdateCenterPoint = item.GetCenterPoint();
  756. m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1);
  757. m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1);
  758. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  759. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  760. //根据鼠标_更改测量区域的位置
  761. //item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height));
  762. item.SetInitRegionF(new RectangleF(new PointF(item.GetZoomedRegionF().X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.GetZoomedRegionF().Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.GetZoomedRegionF().Width, item.GetZoomedRegionF().Height)));
  763. //item.DrawRegionF = item.GetRegionF();
  764. //修改多边形的绘制点集合
  765. if (item.CreateType == CreateRectangleType.Polygon)
  766. {
  767. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  768. {
  769. item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY);
  770. item.PolygonPointFList[i] = new PointF(item.PolygonPointFList[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointFList[i].Y + (m_StageCenterDiffY - diffNewY));
  771. item.PolygonPointFList[i] = new PointF(item.PolygonPointFList[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.PolygonPointFList[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum);
  772. }
  773. }
  774. }
  775. public SampleHolePara GetSampleHolePara(CRectangleGDIObject sampleHoleItem)
  776. {
  777. //int w = (IsWidth == 0 ? Width : Height);
  778. SampleHolePara sampleHoleParas ;
  779. //获取样品孔的OTS位置与尺寸
  780. sampleHoleParas = GetSampleHoleInfo(sampleHoleItem);
  781. //获取工作区域位置与尺寸
  782. //Rectangle WorkAreaRect = new Rectangle(0, 0, m_totalCtrlWidth, m_totalCtrlHeight);
  783. //获取工作区域 中心点
  784. //Point ScreenPointCenter = GetCenterPoint(WorkAreaRect);
  785. //获取样品台 中心点
  786. PointF RectanglePointCenter =GetCenterPoint();
  787. //获取屏幕中心点
  788. //float WorkAreaCenterPointX = PixelConvertToMicron(ScreenPointCenter.X);
  789. //float WorkAreaCenterPointY = PixelConvertToMicron(ScreenPointCenter.Y);
  790. //获取样品台中心点
  791. float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X);
  792. float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y);
  793. RectangleF sampleHoleRect = new RectangleF();
  794. //根据样品台中心点获取开始点位置
  795. sampleHoleRect.X = -(CenterX - sampleHoleParas.SampleHoleRect.X);
  796. sampleHoleRect.Y = CenterY - sampleHoleParas.SampleHoleRect.Bottom;
  797. sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
  798. sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
  799. return sampleHoleParas;
  800. }
  801. public PointF GetCenterPoint(RectangleF rect)
  802. {
  803. //声明
  804. PointF centerPoint = new PointF();
  805. //设置X,Y坐标
  806. centerPoint.X = rect.X + rect.Width / 2;
  807. centerPoint.Y = rect.Y + rect.Height / 2;
  808. return centerPoint;
  809. }
  810. public SampleHolePara GetSampleHoleInfo(CRectangleGDIObject item)
  811. {
  812. SampleHolePara sampleHolePara = new SampleHolePara();
  813. //保存原位置
  814. RectangleF rectPara = item.GetZoomedRegion;
  815. //设置测量区域
  816. sampleHolePara.SampleHoleRect = item.GetZoomedRegion;
  817. //设置测量区域位置与尺寸
  818. float left = PixelConvertToMicron(item.GetZoomedRegionF().X);
  819. float Top = PixelConvertToMicron(item.GetZoomedRegionF().Y);
  820. float Right = PixelConvertToMicron(item.GetZoomedRegionF().Right);
  821. float Bottom = PixelConvertToMicron(item.GetZoomedRegionF().Bottom);
  822. float Widths = PixelConvertToMicron(item.GetZoomedRegionF().Width);
  823. float Height = PixelConvertToMicron(item.GetZoomedRegionF().Height);
  824. PointF startPoint = new PointF(left, Top);
  825. SizeF sampleHoleSize = new SizeF(Widths, Height);
  826. sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
  827. //设置样品孔名称
  828. sampleHolePara.sHoleName = item.Name;
  829. //设置测量区域形状
  830. sampleHolePara.iShape = item.Shape;
  831. return sampleHolePara;
  832. }
  833. }
  834. }