CStageManage.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6. namespace OTSMeasureApp
  7. {
  8. public class CStageManage
  9. {
  10. #region 添加样品
  11. /// <summary>
  12. /// 添加样品
  13. /// </summary>
  14. /// <param name="IsSelect"></param>
  15. /// <param name="SampleHoleName"></param>
  16. /// <param name="SampleName"></param>
  17. /// <param name="oTSSamplespaceWindow"></param>
  18. /// <returns></returns>
  19. public static bool AddSample(string SampleHoleName, string SampleName, ARectangleGDIObject m_MeasureGDIObjects, OTSSamplespaceWindow oTSSamplespaceWindow,float globalZoomNum)
  20. {
  21. try
  22. {
  23. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
  24. {
  25. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
  26. {
  27. ARectangleGDIObject itemAdd = null;
  28. //设置样品选择状态为非工作样品
  29. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  30. {
  31. //设置颜色
  32. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  33. itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
  34. itemSample.IsWorkSample = false;
  35. }
  36. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  37. {
  38. itemAdd = items;
  39. if (items.Name == SampleHoleName)
  40. {
  41. //获取样品台类型
  42. int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
  43. //设置颜色
  44. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  45. Color selColor = ColorTranslator.FromHtml(ColorStr);
  46. CreateRectangle NewSample = new CreateRectangle(items.Region, (int)CreateRectangleType.SelectSample, shape, items.Name, selColor);
  47. //累加样品数量
  48. items.SampleCount += 1;
  49. items.IsWorkSample = true;
  50. NewSample.SampleName = SampleName;
  51. NewSample.Name = itemAdd.Name;
  52. //设置当前添加的样品为工作样品
  53. NewSample.IsWorkSample = true;
  54. // 获取样品孔的大小与初始大小
  55. NewSample.Region = items.Region;
  56. NewSample.RegionF = items.RegionF;
  57. NewSample.DrawRegionF = items.DrawRegionF;
  58. //绘制样品路径
  59. GraphicsPath NewSamplePath = new GraphicsPath();
  60. if (NewSample.Shape == (int)CreateRectangleType.Circle)
  61. {
  62. NewSamplePath.AddEllipse(NewSample.Region);
  63. }
  64. else
  65. {
  66. NewSamplePath.AddRectangle(NewSample.Region);
  67. }
  68. NewSample.GPath = NewSamplePath;
  69. OTSSamplespaceWindow.m_SampleGDIObjects.Add(NewSample);
  70. //获取测量区域尺寸与位置
  71. m_MeasureGDIObjects = GetSampleMeasureInfo(NewSample, m_MeasureGDIObjects, globalZoomNum);
  72. //设置样品孔名称
  73. m_MeasureGDIObjects.Name = items.Name;
  74. //根据节点设置样品台窗口中所选择的样品名称
  75. OTSSamplespaceWindow.m_SampleSelectName = SampleName;
  76. //添加测量区域
  77. return AddMeasure(m_MeasureGDIObjects.CreateType, m_MeasureGDIObjects);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. catch (Exception)
  84. {
  85. }
  86. return false;
  87. }
  88. #region 根据样品位置 获取测量区域位置
  89. public static ARectangleGDIObject GetSampleMeasureInfo(ARectangleGDIObject NewSample, ARectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
  90. {
  91. //根据样品位置 获取测量区域位置
  92. int MeasurePointX = (int)(NewSample.Region.Location.X + ((NewSample.Region.Size.Width - (m_MeasureGDIObjects.Region.Width * globalZoomNum)) / 2));
  93. int MeasurePointY = (int)(NewSample.Region.Location.Y + ((NewSample.Region.Size.Height - (m_MeasureGDIObjects.Region.Height * globalZoomNum)) / 2));
  94. int MeasureWidth = Convert.ToInt32(m_MeasureGDIObjects.Region.Width * globalZoomNum);
  95. int MeasureHeight = Convert.ToInt32(m_MeasureGDIObjects.Region.Height * globalZoomNum);
  96. float MeasureFPointX = (float)(NewSample.RegionF.Location.X + (NewSample.RegionF.Size.Width - m_MeasureGDIObjects.Region.Width ) / 2);
  97. float MeasureFPointY = (float)(NewSample.RegionF.Location.Y + (NewSample.RegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
  98. float MeasureFWidth = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Width);
  99. float MeasureFHeight = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Height);
  100. float MeasureDrawPointX = (float)(NewSample.DrawRegionF.Location.X + (NewSample.DrawRegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2);
  101. float MeasureDrawPointY = (float)(NewSample.DrawRegionF.Location.Y + (NewSample.DrawRegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2);
  102. float MeasureDrawWidth = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Width);
  103. float MeasureDrawHeight = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Height);
  104. m_MeasureGDIObjects.Region = new Rectangle(new Point(MeasurePointX, MeasurePointY), new Size(MeasureWidth, MeasureHeight));
  105. m_MeasureGDIObjects.RegionF = new RectangleF(new PointF(MeasureFPointX, MeasureFPointY), new SizeF(MeasureFWidth, MeasureFHeight));
  106. m_MeasureGDIObjects.DrawRegionF = new RectangleF(new PointF(MeasureDrawPointX, MeasureDrawPointY), new SizeF(MeasureDrawWidth, MeasureDrawHeight));
  107. return m_MeasureGDIObjects;
  108. }
  109. #endregion
  110. /// <summary>
  111. /// 添加样品
  112. /// </summary>
  113. /// <param name="IsSelect"></param>
  114. /// <param name="SampleHoleName"></param>
  115. /// <param name="SampleName"></param>
  116. /// <param name="oTSSamplespaceWindow"></param>
  117. /// <returns></returns>
  118. public static bool AddOnlySample(string SampleHoleName, string SampleName, OTSSamplespaceWindow oTSSamplespaceWindow)
  119. {
  120. try
  121. {
  122. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
  123. {
  124. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
  125. {
  126. ARectangleGDIObject itemAdd = null;
  127. //设置样品选择状态为非工作样品
  128. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  129. {
  130. //设置颜色
  131. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  132. itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
  133. itemSample.IsWorkSample = false;
  134. }
  135. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  136. {
  137. itemAdd = items;
  138. if (items.Name == SampleHoleName)
  139. {
  140. //获取样品台类型
  141. int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
  142. //设置颜色
  143. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  144. Color selColor = ColorTranslator.FromHtml(ColorStr);
  145. CreateRectangle AddSample = new CreateRectangle(items.Region, (int)CreateRectangleType.SelectSample, shape, items.Name, selColor);
  146. //累加样品数量
  147. items.SampleCount += 1;
  148. items.IsWorkSample = true;
  149. AddSample.SampleName = SampleName;
  150. AddSample.Name = itemAdd.Name;
  151. //绘制测量区域路径
  152. GraphicsPath AddSamplePath = new GraphicsPath();
  153. AddSamplePath.AddRectangle(AddSample.Region);
  154. AddSample.GPath = AddSamplePath;
  155. OTSSamplespaceWindow.m_SampleGDIObjects.Add(AddSample);
  156. return true;
  157. }
  158. }
  159. }
  160. }
  161. return false;
  162. }
  163. catch (Exception)
  164. {
  165. }
  166. return false;
  167. }
  168. #endregion
  169. #region 删除样品
  170. /// <summary>
  171. /// 删除样品
  172. /// </summary>
  173. /// <param name="IsIsDragging">是否选择样品孔 0:未选择 1:选择</param>
  174. /// <param name="stageName">样品孔名称</param>
  175. /// <returns>是否成功</returns>
  176. public static bool DeleteStage(int IsSelect, string SampleName)
  177. {
  178. try
  179. {
  180. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
  181. {
  182. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
  183. {
  184. ARectangleGDIObject itemAdd = null;
  185. if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
  186. {
  187. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
  188. {
  189. itemAdd = items;
  190. if (IsSelect > 0)
  191. {
  192. if (items.SampleName == SampleName)
  193. {
  194. foreach (ARectangleGDIObject itemSampleHole in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  195. {
  196. if (itemSampleHole.Name == itemAdd.Name)
  197. {
  198. itemSampleHole.SampleCount -= 1;
  199. break;
  200. }
  201. }
  202. //将样品孔恢复未拖动状态
  203. items.IsSelect = false;
  204. OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
  205. return true;
  206. }
  207. }
  208. else
  209. {
  210. //删除样品测量
  211. if (items.SampleName == SampleName)
  212. {
  213. //将样品孔恢复未拖动状态
  214. items.IsSelect = false;
  215. OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
  216. return true;
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. catch (Exception)
  225. {
  226. }
  227. return false;
  228. }
  229. #endregion
  230. #region 通过样品名称 删除样品
  231. /// <summary>
  232. /// 删除样品
  233. /// </summary>
  234. /// <param name="stageName">样品孔名称</param>
  235. /// <returns>是否成功</returns>
  236. public static bool DeleteSample(string SampleName)
  237. {
  238. try
  239. {
  240. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects != null)
  241. {
  242. if (OTSSamplespaceWindow.m_SampleHoleGDIObjects.Count > 0)
  243. {
  244. ARectangleGDIObject itemAdd = null;
  245. if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
  246. {
  247. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
  248. {
  249. itemAdd = items;
  250. if (items.SampleName == SampleName)
  251. {
  252. foreach (ARectangleGDIObject itemSampleHole in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  253. {
  254. if (itemSampleHole.Name == itemAdd.Name)
  255. {
  256. itemSampleHole.SampleCount -= 1;
  257. break;
  258. }
  259. }
  260. //将样品孔恢复未拖动状态
  261. items.IsSelect = false;
  262. OTSSamplespaceWindow.m_SampleGDIObjects.Remove(items);
  263. if (DeleteMeasure(SampleName))
  264. {
  265. return true;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. catch (Exception)
  274. {
  275. }
  276. return false;
  277. }
  278. #endregion
  279. #region 修改测量区域选择状态
  280. public static void SetMeasureState(Color setColor)
  281. {
  282. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
  283. {
  284. items.SelColor = setColor;
  285. }
  286. }
  287. #endregion
  288. #region 修改样品选择状态
  289. public static void SetSampleState(Color setColor)
  290. {
  291. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
  292. {
  293. if (items.IsDragging)
  294. {
  295. //设置颜色
  296. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  297. items.SelColor = ColorTranslator.FromHtml(ColorStr);
  298. }
  299. else
  300. {
  301. items.SelColor = setColor;
  302. }
  303. }
  304. }
  305. #endregion
  306. #region 添加测量
  307. /// <summary>
  308. /// 添加测量
  309. /// </summary>
  310. /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
  311. /// <param name="sampleName">样品名称</param>
  312. /// <returns>是否成功</returns>
  313. public static bool AddMeasure(int IsSelect, string sampleName)
  314. {
  315. try
  316. {
  317. if (OTSSamplespaceWindow.m_SampleGDIObjects != null)
  318. {
  319. if (OTSSamplespaceWindow.m_SampleGDIObjects.Count > 0)
  320. {
  321. ARectangleGDIObject itemAdd = null;
  322. if (IsSelect > 0)
  323. {
  324. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_SampleGDIObjects)
  325. {
  326. //判断是否与传递的样品名称相同
  327. itemAdd = items;
  328. if (items.Name == sampleName)
  329. {
  330. //添加测量区域
  331. //获取样品台类型
  332. int shape = itemAdd.CreateType;// == (int)CreateRectangleType.Rectangle ? (int)CreateRectangleType.Rectangle: (int)CreateRectangleType.Ellipse;
  333. GraphicsPath MeasurePath = new GraphicsPath();
  334. if (shape == (int)CreateRectangleType.Rectangle)
  335. {
  336. MeasurePath.AddRectangle(itemAdd.Region);
  337. }
  338. else
  339. {
  340. MeasurePath.AddEllipse(itemAdd.Region);
  341. }
  342. //缩小与样品的尺寸
  343. Rectangle rectMeasure = items.Region;
  344. rectMeasure.X = rectMeasure.X + 5;
  345. rectMeasure.Y = rectMeasure.Y + 5;
  346. rectMeasure.Width = rectMeasure.Width - 10;
  347. rectMeasure.Height = rectMeasure.Height - 10;
  348. //与样品中心相差的距离
  349. Point sampleCenterDifferPoint = new Point();
  350. //获取测量区域中心与样品中心相差的距离
  351. sampleCenterDifferPoint = OTSSamplespaceGraphicsPanelFun.GetSampleCenterDifferCenterPoint(rectMeasure, items.Region);
  352. //创建测量区域
  353. //设置颜色
  354. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  355. CreateRectangle selectState = new CreateRectangle(rectMeasure, sampleCenterDifferPoint, (int)CreateRectangleType.MeasureArea, shape, items.Name, items.Name, ColorTranslator.FromHtml(ColorStr));
  356. selectState.GPath = MeasurePath;
  357. OTSSamplespaceWindow.m_MeasureGDIObjects.Add(selectState);
  358. return true;
  359. }
  360. }
  361. }
  362. else
  363. {
  364. //默认添加测量
  365. itemAdd = OTSSamplespaceWindow.m_SampleGDIObjects[0];
  366. CreateRectangle selectState = new CreateRectangle(itemAdd.Region, (int)CreateRectangleType.MeasureArea, sampleName);
  367. GraphicsPath MeasurePath = new GraphicsPath();
  368. if (selectState.Shape == (int)CreateRectangleType.Rectangle)
  369. {
  370. MeasurePath.AddRectangle(itemAdd.Region);
  371. }
  372. else
  373. {
  374. MeasurePath.AddEllipse(itemAdd.Region);
  375. }
  376. selectState.GPath = MeasurePath;
  377. OTSSamplespaceWindow.m_MeasurePathGDIObjects.Add(selectState);
  378. return true;
  379. }
  380. }
  381. }
  382. }
  383. catch (Exception)
  384. {
  385. throw;
  386. }
  387. return false;
  388. }
  389. #endregion
  390. #region 添加测量
  391. /// <summary>
  392. /// 添加测量
  393. /// </summary>
  394. /// <param name="IsIsDragging">是否选择样品 0:未选择 1:选择</param>
  395. /// <param name="sampleName">样品名称</param>
  396. /// <returns>是否成功</returns>
  397. public static bool AddMeasure(int CreateType, ARectangleGDIObject m_MeasureGDIObjects)
  398. {
  399. try
  400. {
  401. //添加测量区域
  402. int shape = CreateType;// == 1 ? 1 : 0;
  403. GraphicsPath MeasurePath = new GraphicsPath();
  404. if (shape == (int)CreateRectangleType.Rectangle)
  405. {
  406. MeasurePath.AddRectangle(m_MeasureGDIObjects.Region);
  407. }
  408. else
  409. {
  410. MeasurePath.AddEllipse(m_MeasureGDIObjects.Region);
  411. }
  412. //缩小与样品的尺寸
  413. Rectangle rectMeasure = m_MeasureGDIObjects.Region;
  414. Color MeasureColor = Color.Red;
  415. CreateRectangle MeasureRect = new CreateRectangle(rectMeasure, m_MeasureGDIObjects.SampleCenterDifferCenterPoint, (int)CreateRectangleType.MeasureArea, shape, m_MeasureGDIObjects.Name, m_MeasureGDIObjects.SampleName, MeasureColor);
  416. MeasureRect.GPath = MeasurePath;
  417. MeasureRect.sampleName = m_MeasureGDIObjects.SampleName;
  418. MeasureRect.Name = m_MeasureGDIObjects.Name;
  419. //获取缩放前尺寸与位置
  420. MeasureRect.RegionF = m_MeasureGDIObjects.RegionF;
  421. MeasureRect.DrawRegionF = m_MeasureGDIObjects.DrawRegionF;
  422. OTSSamplespaceWindow.m_MeasureGDIObjects.Add(MeasureRect);
  423. return true;
  424. }
  425. catch (Exception)
  426. {
  427. return false;
  428. }
  429. }
  430. #endregion
  431. #region 复位测量
  432. /// <summary>
  433. /// 复位测量
  434. /// </summary>
  435. /// <param name="CreateType">是否选择样品 0:圆形 3:矩形</param>
  436. /// <param name="m_MeasureGDIObjects">测量区域</param>
  437. /// <returns>是否成功</returns>
  438. public static ARectangleGDIObject ResetMeasure(int CreateType, ARectangleGDIObject m_SampleGDIObjects, ARectangleGDIObject m_MeasureGDIObjects, float globalZoomNum)
  439. {
  440. try
  441. {
  442. //复位测量
  443. int shape = CreateType;
  444. GraphicsPath MeasurePath = new GraphicsPath();
  445. if (shape == (int)CreateRectangleType.Rectangle)
  446. {
  447. MeasurePath.AddRectangle(m_SampleGDIObjects.Region);
  448. }
  449. else
  450. {
  451. MeasurePath.AddEllipse(m_SampleGDIObjects.Region);
  452. }
  453. //缩小与样品的尺寸
  454. Rectangle rectMeasure = m_SampleGDIObjects.Region;
  455. Color MeasureColor = Color.Red;
  456. return GetSampleMeasureInfo(m_SampleGDIObjects, m_MeasureGDIObjects, globalZoomNum);
  457. }
  458. catch (Exception)
  459. {
  460. return null;
  461. }
  462. }
  463. #endregion
  464. #region 通过样品名称 删除测量
  465. /// <summary>
  466. /// 通过样品名称 删除测量
  467. /// </summary>
  468. /// <param name="measureName">测量名称</param>
  469. /// <returns>是否成功</returns>
  470. public static bool DeleteMeasure(string sampleName)
  471. {
  472. try
  473. {
  474. if (OTSSamplespaceWindow.m_MeasureGDIObjects.Count > 0)
  475. {
  476. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
  477. {
  478. //删除样品测量
  479. if (items.SampleName == sampleName)
  480. {
  481. //将样品孔恢复未拖动状态
  482. items.IsSelect = false;
  483. OTSSamplespaceWindow.m_MeasureGDIObjects.Remove(items);
  484. //设置样品与测量区域
  485. //设置颜色
  486. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  487. SetSampleState(ColorTranslator.FromHtml(ColorStr));
  488. SetMeasureState(ColorTranslator.FromHtml(ColorStr));
  489. OTSSamplespaceWindow.m_IsMeasure = false;
  490. foreach (ARectangleGDIObject sampleItem in OTSSamplespaceWindow.m_SampleGDIObjects)
  491. {
  492. if (sampleItem.SampleName == items.SampleName)
  493. {
  494. sampleItem.IsWorkSample = true;
  495. //设置颜色
  496. string SampleSelColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  497. sampleItem.SelColor = ColorTranslator.FromHtml(SampleSelColor);
  498. }
  499. }
  500. return true;
  501. }
  502. }
  503. }
  504. }
  505. catch (Exception)
  506. {
  507. }
  508. return false;
  509. }
  510. #endregion
  511. #region 删除测量
  512. /// <summary>
  513. /// 删除测量
  514. /// </summary>
  515. /// <param name="IsIsDragging">是否选择测量 0:未选择 1:选择</param>
  516. /// <param name="measureName">测量名称</param>
  517. /// <returns>是否成功</returns>
  518. public static bool DeleteMeasure(int IsSelect, string sampleName)
  519. {
  520. try
  521. {
  522. if (OTSSamplespaceWindow.m_MeasureGDIObjects.Count > 0)
  523. {
  524. foreach (ARectangleGDIObject items in OTSSamplespaceWindow.m_MeasureGDIObjects)
  525. {
  526. //删除样品测量
  527. if (items.SampleName == sampleName)
  528. {
  529. //将样品孔恢复未拖动状态
  530. items.IsSelect = false;
  531. OTSSamplespaceWindow.m_MeasureGDIObjects.Remove(items);
  532. //设置样品与测量区域
  533. //设置颜色
  534. string SampleColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  535. SetSampleState(ColorTranslator.FromHtml(SampleColor));
  536. SetMeasureState(ColorTranslator.FromHtml(SampleColor));
  537. OTSSamplespaceWindow.m_IsMeasure = false;
  538. foreach (ARectangleGDIObject sampleItem in OTSSamplespaceWindow.m_SampleGDIObjects)
  539. {
  540. if (sampleItem.Name == items.SampleName)
  541. {
  542. //设置颜色
  543. string SampleSelColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  544. sampleItem.IsWorkSample = true;
  545. sampleItem.SelColor = ColorTranslator.FromHtml(SampleSelColor);
  546. }
  547. }
  548. return true;
  549. }
  550. }
  551. }
  552. }
  553. catch (Exception)
  554. {
  555. }
  556. return false;
  557. }
  558. #endregion
  559. #region 更换样品名称
  560. /// <summary>
  561. /// 更换样品名称
  562. /// </summary>
  563. /// <param name="sampleName">新样品名称</param>
  564. public static void ChangeSampleName(string sampleName)
  565. {
  566. //循环 样品与测量区域的名称修改为新名称
  567. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  568. {
  569. if (itemSample.IsWorkSample)
  570. {
  571. foreach (ARectangleGDIObject measureItemSample in OTSSamplespaceWindow.m_MeasureGDIObjects)
  572. {
  573. if (measureItemSample.SampleName == itemSample.SampleName)
  574. {
  575. measureItemSample.SampleName = sampleName;
  576. itemSample.SampleName = sampleName;
  577. return;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. #endregion
  584. #region 更换样品形状
  585. /// <summary>
  586. /// 更换样品形状
  587. /// </summary>
  588. /// <param name="iShape">形状</param>
  589. public static bool ChangeSampleShape(int iShape)
  590. {
  591. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  592. {
  593. if (itemSample.IsWorkSample)
  594. {
  595. foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
  596. {
  597. if (itemSample.SampleName == itemMeasure.SampleName)
  598. {
  599. if (itemMeasure.Shape != iShape)
  600. {
  601. //改变大小
  602. itemMeasure.Region = new Rectangle(itemMeasure.Region.X, itemMeasure.Region.Y, itemMeasure.Region.Height, itemMeasure.Region.Height);
  603. itemMeasure.RegionF = new RectangleF(itemMeasure.RegionF.X, itemMeasure.RegionF.Y, itemMeasure.RegionF.Height, itemMeasure.RegionF.Height);
  604. itemMeasure.DrawRegionF = new RectangleF(itemMeasure.DrawRegionF.X, itemMeasure.DrawRegionF.Y, itemMeasure.DrawRegionF.Height, itemMeasure.DrawRegionF.Height);
  605. itemMeasure.Shape = iShape;
  606. GraphicsPath NewMeasurePath = new GraphicsPath();
  607. if (itemMeasure.Shape == (int)CreateRectangleType.Circle)
  608. {
  609. NewMeasurePath.AddEllipse(itemMeasure.Region);
  610. }
  611. else
  612. {
  613. NewMeasurePath.AddRectangle(itemMeasure.Region);
  614. }
  615. itemMeasure.GPath = NewMeasurePath;
  616. return true;
  617. }
  618. return false;
  619. }
  620. }
  621. }
  622. }
  623. return false;
  624. }
  625. #endregion
  626. #region 设置工作样品
  627. /// <summary>
  628. /// 设置工作样品与测量区域
  629. /// </summary>
  630. /// <param name="sampleName">样品名称</param>
  631. public static void SetWorkSampleAndWorkMeasure(string sampleName)
  632. {
  633. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  634. {
  635. if (itemSample.SampleName == sampleName)
  636. {
  637. itemSample.IsWorkSample = true;
  638. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor);
  639. itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
  640. }
  641. else
  642. {
  643. itemSample.IsWorkSample = false;
  644. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor);
  645. itemSample.SelColor = ColorTranslator.FromHtml(ColorStr);
  646. }
  647. }
  648. foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
  649. {
  650. if (itemMeasure.SampleName == sampleName)
  651. {
  652. itemMeasure.IsWorkSample = true;
  653. itemMeasure.SelColor = Color.Red;
  654. }
  655. else
  656. {
  657. itemMeasure.IsWorkSample = false;
  658. itemMeasure.SelColor = Color.Transparent;
  659. }
  660. }
  661. //修改测量区域集合 索引 (添加样品或者切换样品时,将当前工作样品显示在样品孔的最上)
  662. OTSSamplespaceWindow.m_MeasureGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectMeasureIndexIsTop(OTSSamplespaceWindow.m_MeasureGDIObjects, sampleName);
  663. //修改样品集合 索引
  664. OTSSamplespaceWindow.m_SampleGDIObjects = OTSSamplespaceGraphicsPanelFun.SelectSampleIndexIsTop(OTSSamplespaceWindow.m_SampleGDIObjects, sampleName);
  665. }
  666. #endregion
  667. public static void SetShowCMStrip(int IsSelectType, ContextMenuStrip cmStrip, bool IsTrue)
  668. {
  669. //鼠标右键选择的类型 0:样品台 1:样品 2:测量区域
  670. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = (int)MessageState.ShotBSEPicture;
  671. switch (IsSelectType)
  672. {
  673. case (int)ContextMenuType.SampleHoleMenu:
  674. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  675. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
  676. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
  677. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  678. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  679. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  680. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  681. cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
  682. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
  683. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  684. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
  685. break;
  686. case (int)ContextMenuType.SampleMenu:
  687. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  688. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  689. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  690. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  691. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = false;
  692. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = false;
  693. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  694. cmStrip.Items[(int)MenuIndex.SEMStripSeparator].Enabled = false;
  695. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  696. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  697. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  698. break;
  699. case (int)ContextMenuType.MeasureMenu:
  700. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  701. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  702. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  703. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  704. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
  705. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
  706. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  707. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  708. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = IsTrue;
  709. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  710. //cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Text = str2;
  711. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
  712. break;
  713. case (int)ContextMenuType.SingleMenu:
  714. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  715. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = true;
  716. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = true;
  717. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = true;
  718. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = true;
  719. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = true;
  720. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  721. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = true;
  722. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  723. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = true;
  724. //cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Text = str2;
  725. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Tag = MessageState.MeasureBSEPicture;
  726. break;
  727. case (int)ContextMenuType.ThreadRunMenu:
  728. for (int i = 0; i < cmStrip.Items.Count; i++)
  729. {
  730. cmStrip.Items[i].Enabled = false;
  731. }
  732. break;
  733. case (int)ContextMenuType.SampleStateMenu:
  734. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = false;
  735. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = false;
  736. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = false;
  737. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = false;
  738. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
  739. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
  740. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  741. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = false;
  742. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = false;
  743. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = false;
  744. break;
  745. case (int)ContextMenuType.SampleHoleBSEImage:
  746. cmStrip.Items[(int)MenuIndex.AddSample].Enabled = true;
  747. cmStrip.Items[(int)MenuIndex.DeleteSample].Enabled = IsTrue;
  748. cmStrip.Items[(int)MenuIndex.ReadSEMData].Enabled = IsTrue;
  749. cmStrip.Items[(int)MenuIndex.SetSemData].Enabled = IsTrue;
  750. cmStrip.Items[(int)MenuIndex.SetSEMCenterLocation].Enabled = IsTrue;
  751. cmStrip.Items[(int)MenuIndex.DriveSEMToCenterLocation].Enabled = IsTrue;
  752. cmStrip.Items[(int)MenuIndex.DriveSEMToCurrentLocation].Enabled = true;
  753. cmStrip.Items[(int)MenuIndex.ShootBSEPicture].Enabled = IsTrue;
  754. cmStrip.Items[(int)MenuIndex.DeleteBSEPicture].Enabled = true;
  755. cmStrip.Items[(int)MenuIndex.SlopFocus].Enabled = IsTrue;
  756. break;
  757. }
  758. }
  759. }
  760. }