DlgStageEdit.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using OTSDataType;
  2. using OTSModelSharp;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using OTSModelSharp.Measure.GetStageInfo;
  14. namespace OTSMeasureApp._7_OTSProgMgrInfo.Stage
  15. {
  16. public partial class DlgStageEdit : Form
  17. {
  18. // stage file
  19. CStageParam m_pStageFile;
  20. public CStage m_pStage;
  21. StageDisplayHelp stageDisplayHelp;
  22. public DlgStageEdit()
  23. {
  24. InitializeComponent();
  25. }
  26. public DlgStageEdit(CStage cStage)
  27. {
  28. InitializeComponent();
  29. m_pStage = cStage;
  30. }
  31. ComboBox cmb_Temp = new ComboBox();
  32. private void DlgStageEdit_Load(object sender, EventArgs e)
  33. {
  34. radioButton_OTS.Checked = true;
  35. radioButton_BoundarySquare.Checked = true;
  36. radioButton_StandardsampleSqare.Checked = true;
  37. dataGridView_Holes.Columns.Add("HoleName", "样品孔名称");
  38. dataGridView_Holes.Columns.Add("HoleShape", "样品孔形状");
  39. dataGridView_Holes.Columns.Add("CenterCoordinatesX", "中心x坐标");
  40. dataGridView_Holes.Columns.Add("CenterCoordinatesY", "中心y坐标");
  41. dataGridView_Holes.Columns.Add("Param1", "宽度或直径");
  42. dataGridView_Holes.Columns.Add("Param2", "高度或0");
  43. dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0);
  44. //SetDataGridViewStyle();
  45. cmb_Temp.Visible = false;
  46. cmb_Temp.Items.Add("圆形");
  47. cmb_Temp.Items.Add("方形");
  48. cmb_Temp.SelectedIndexChanged += new EventHandler(cmb_Temp_SelectedIndexChanged);
  49. dataGridView_Holes.Controls.Add(cmb_Temp);
  50. stageDisplayHelp = new StageDisplayHelp();
  51. if(m_pStage!=null)
  52. {
  53. LoadStageData(m_pStage);
  54. }
  55. SetHelp();
  56. //Object pDC = new Object();
  57. //pDC = m_ctrlStagePicture.CreateGraphics();
  58. ////消除锯齿
  59. //((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  60. //((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  61. //((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点
  62. }
  63. void SetHelp()
  64. {
  65. helpProvider1.SetHelpString(label1, "样品台名不能为空字串,不能含\',\'字符!");
  66. helpProvider1.SetHelpString(groupBox1, "样品台边框行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0");
  67. helpProvider1.SetHelpString(groupBox2, "标样信息行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0");
  68. helpProvider1.SetHelpString(groupBox3, "样品孔信息行有6个数值参数,1个字符串参数,5个数值参数。1个字符串参数为样品孔名。5个数值参数为形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0。");
  69. }
  70. void LoadStageData(CStage cStage)
  71. {
  72. tStageName.Text = m_pStage.GetName();
  73. if(m_pStage.GetBoundary().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND)
  74. {
  75. radioButton_BoundaryCircle.Checked = true;
  76. tBoundaryWide.Text = m_pStage.GetBoundary().GetDiameter().ToString();
  77. tBoundaryHeight.Text = "0";
  78. }
  79. else
  80. {
  81. radioButton_BoundarySquare.Checked = true;
  82. tBoundaryWide.Text = m_pStage.GetBoundary().GetRectDomain().Width.ToString();
  83. tBoundaryHeight.Text = m_pStage.GetBoundary().GetRectDomain().Height.ToString();
  84. }
  85. tBoundaryX.Text= m_pStage.GetBoundary().GetDomainCenter().X.ToString();
  86. tBoundaryY.Text = m_pStage.GetBoundary().GetDomainCenter().Y.ToString();
  87. if(m_pStage.GetSTD().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND)
  88. {
  89. radioButton_StandardsampleCircle.Checked = true;
  90. tStandardsampleWide.Text = m_pStage.GetSTD().GetDiameter().ToString();
  91. }
  92. else
  93. {
  94. radioButton_StandardsampleSqare.Checked = true;
  95. tStandardsampleWide.Text = m_pStage.GetSTD().GetRectDomain().Width.ToString();
  96. }
  97. tStandardsampleX.Text = m_pStage.GetSTD().GetDomainCenter().X.ToString();
  98. tStandardsampleY.Text = m_pStage.GetSTD().GetDomainCenter().Y.ToString();
  99. tStandardsampleHeight.Text = m_pStage.GetSTD().GetRectDomain().Height.ToString();
  100. dataGridView_Holes.Rows[0].Cells[0].Value = m_pStage.GetHoleList()[0].GetName();
  101. if (m_pStage.GetHoleList()[0].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND)
  102. {
  103. dataGridView_Holes.Rows[0].Cells[1].Value = "圆形";
  104. dataGridView_Holes.Rows[0].Cells[4].Value = m_pStage.GetHoleList()[0].GetDiameter().ToString();
  105. dataGridView_Holes.Rows[0].Cells[5].Value = "0";
  106. }
  107. else
  108. {
  109. dataGridView_Holes.Rows[0].Cells[1].Value = "方形";
  110. dataGridView_Holes.Rows[0].Cells[4].Value = m_pStage.GetHoleList()[0].GetRectDomain().Width.ToString();
  111. dataGridView_Holes.Rows[0].Cells[5].Value = m_pStage.GetHoleList()[0].GetRectDomain().Height.ToString();
  112. }
  113. dataGridView_Holes.Rows[0].Cells[2].Value = m_pStage.GetHoleList()[0].GetDomainCenter().X.ToString();
  114. dataGridView_Holes.Rows[0].Cells[3].Value = m_pStage.GetHoleList()[0].GetDomainCenter().Y.ToString();
  115. for (int i=1;i< m_pStage.GetHoleList().Count;i++)
  116. {
  117. string sr = "";
  118. string pra1 = "";
  119. string pra2 = "";
  120. if (m_pStage.GetHoleList()[i].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND)
  121. {
  122. sr= "圆形";
  123. pra1 = m_pStage.GetHoleList()[i].GetDiameter().ToString();
  124. pra2 = "0";
  125. }
  126. else
  127. {
  128. sr= "方形";
  129. pra1 = m_pStage.GetHoleList()[i].GetRectDomain().Width.ToString();
  130. pra2 = m_pStage.GetHoleList()[i].GetRectDomain().Height.ToString();
  131. }
  132. dataGridView_Holes.Rows.Add(m_pStage.GetHoleList()[i].GetName(), sr, m_pStage.GetHoleList()[i].GetDomainCenter().X.ToString(), m_pStage.GetHoleList()[i].GetDomainCenter().Y.ToString(), pra1, pra2);
  133. }
  134. }
  135. private void radioButton_BoundaryCircle_Click(object sender, EventArgs e)
  136. {
  137. label8.Enabled = false;
  138. tBoundaryHeight.Enabled = false;
  139. tBoundaryHeight.Text = "0";
  140. label7.Text = "半径:";
  141. }
  142. private void radioButton_BoundarySquare_Click(object sender, EventArgs e)
  143. {
  144. label8.Enabled = true;
  145. tBoundaryHeight.Enabled = true;
  146. label7.Text = "宽度:";
  147. }
  148. private void radioButton_StandardsampleCircle_Click(object sender, EventArgs e)
  149. {
  150. label9.Enabled = false;
  151. tStandardsampleHeight.Enabled = false;
  152. tStandardsampleHeight.Text = "0";
  153. label10.Text = "半径:";
  154. }
  155. private void radioButton__StandardsampleSqare_Click(object sender, EventArgs e)
  156. {
  157. label9.Enabled = true;
  158. tStandardsampleHeight.Enabled = true;
  159. label10.Text = "宽度:";
  160. }
  161. private void dataGridView_Holes_CurrentCellChanged(object sender, EventArgs e)
  162. {
  163. if(dataGridView_Holes.CurrentRow==null)
  164. {
  165. return;
  166. }
  167. if(dataGridView_Holes.CurrentCell.ColumnIndex==1)
  168. {
  169. Rectangle rect = dataGridView_Holes.GetCellDisplayRectangle(dataGridView_Holes.CurrentCell.ColumnIndex, dataGridView_Holes.CurrentCell.RowIndex, false);
  170. string HoleShape = dataGridView_Holes.CurrentCell.Value.ToString();
  171. cmb_Temp.Left = rect.Left;
  172. cmb_Temp.Top = rect.Top;
  173. cmb_Temp.Width = rect.Width;
  174. cmb_Temp.SelectedIndex = 0;
  175. cmb_Temp.Visible = true;
  176. }
  177. else
  178. {
  179. cmb_Temp.Visible = false;
  180. }
  181. }
  182. void cmb_Temp_SelectedIndexChanged(object sender ,EventArgs e)
  183. {
  184. if (dataGridView_Holes.CurrentRow == null)
  185. {
  186. return;
  187. }
  188. if (((ComboBox)sender).SelectedIndex == 0)
  189. {
  190. dataGridView_Holes.CurrentCell.Value = "圆形";
  191. dataGridView_Holes.CurrentRow.Cells[5].Value = 0;
  192. }
  193. else
  194. {
  195. dataGridView_Holes.CurrentCell.Value = "方形";
  196. dataGridView_Holes.CurrentRow.Cells[5].Value = "";
  197. }
  198. }
  199. private void dataGridView_Holes_Scroll(object sender, ScrollEventArgs e)
  200. {
  201. this.cmb_Temp.Visible = false;
  202. }
  203. private void button_Generate_Click(object sender, EventArgs e)
  204. {
  205. if (!CheckParams())
  206. {
  207. this.button_Ok.Enabled = false;
  208. MessageBox.Show("Please check Params!");
  209. return;
  210. }
  211. CSEMStageData a_pCSEMStageData = new CSEMStageData();
  212. //获取配置文件中 StageData 内容
  213. COTSDefaultParam m_DefaultParam = new COTSDefaultParam();
  214. m_DefaultParam.LoadInfoFromProgMgrFile();
  215. a_pCSEMStageData = m_DefaultParam.GetStageDataParam();
  216. m_pStage = new CStage();
  217. m_pStage.SetName(tStageName.Text);
  218. // boundary
  219. string strValue = "";
  220. if(radioButton_BoundaryCircle.Checked)
  221. {
  222. strValue += "0";
  223. tBoundaryHeight.Text="0";
  224. }
  225. else
  226. {
  227. strValue += "1";
  228. }
  229. strValue += "," + tBoundaryX.Text+","+tBoundaryY.Text+","+tBoundaryWide.Text+","+ tBoundaryHeight.Text;
  230. CDomain pBoundary = stageDisplayHelp.GetDomain(strValue);
  231. // STD
  232. strValue = "";
  233. if(radioButton_StandardsampleCircle.Checked)
  234. {
  235. strValue += "0";
  236. tStandardsampleHeight.Text = "0";
  237. }
  238. else
  239. {
  240. strValue += "1";
  241. }
  242. strValue += "," + tStandardsampleX.Text + "," + tStandardsampleY.Text + "," + tStandardsampleWide.Text + "," + tStandardsampleHeight.Text;
  243. CDomain pSTD = stageDisplayHelp.GetDomain(strValue);
  244. // coordinate system
  245. CStageParam.COORDINATE_SYSTEM_SETTING nCoodrSysSetting = CStageParam.COORDINATE_SYSTEM_SETTING.INVALID;
  246. if(radioButton_OTS.Checked)
  247. {
  248. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)0;
  249. }
  250. else
  251. {
  252. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)1;
  253. }
  254. // Holes list
  255. List<CHole> listHoles = new List<CHole>();
  256. for(int i=0;i<dataGridView_Holes.Rows.Count;i++)
  257. {
  258. strValue = "";
  259. if(dataGridView_Holes.Rows[i].Cells[1].Value=="圆形")
  260. {
  261. strValue += "0";
  262. }
  263. else
  264. {
  265. strValue += "1";
  266. }
  267. strValue += ","+ dataGridView_Holes.Rows[i].Cells[2].Value + "," + dataGridView_Holes.Rows[i].Cells[3].Value + "," + dataGridView_Holes.Rows[i].Cells[4].Value + "," + dataGridView_Holes.Rows[i].Cells[5].Value;
  268. CDomain pDomain = stageDisplayHelp.GetDomain(strValue);
  269. //add holes
  270. listHoles.Add(new CHole(dataGridView_Holes.Rows[i].Cells[0].Value.ToString(), pDomain));
  271. }
  272. // check stage components
  273. // name should be ok
  274. if (pBoundary == null)
  275. {
  276. return ;
  277. }
  278. if (pBoundary.IsInvalid())
  279. {
  280. // boundary is invalid
  281. return ;
  282. }
  283. if (pSTD != null)
  284. {
  285. // STD has to be inside of the boundary
  286. if (!pBoundary.DomainInDomain(pSTD))
  287. {
  288. // STD is over the boundary
  289. return ;
  290. }
  291. }
  292. else
  293. {
  294. return ;
  295. }
  296. // hole has to be inside of the boundary and can't have common part with STD and each other
  297. List<CHole> listStageHoles = new List<CHole>();
  298. foreach (var pHole in listHoles)
  299. {
  300. if (!pBoundary.DomainInDomain(pHole))
  301. {
  302. // this hole is over the boundary, jump over
  303. continue;
  304. }
  305. else if (pSTD.IntersectDomain(pHole))
  306. {
  307. // this hole has common part with STD, jump over
  308. continue;
  309. }
  310. bool bHasCommonPart = false;
  311. foreach (var pStageHole in listStageHoles)
  312. {
  313. if (pStageHole.IntersectDomain(pHole))
  314. {
  315. // this hole has common part with a hole already on the stage
  316. bHasCommonPart = true;
  317. break;
  318. }
  319. }
  320. if (bHasCommonPart)
  321. {
  322. // this hole has common part with a hole already on the stage, jump over
  323. continue;
  324. }
  325. // the hole is ok, add it into stage holes list
  326. listStageHoles.Add(pHole);
  327. }
  328. if (listStageHoles.Count == 0)
  329. {
  330. // no hole at all
  331. return ;
  332. }
  333. // the stage is in SEM coordinate system, convert all components to OTS system
  334. if (nCoodrSysSetting == CStageParam.COORDINATE_SYSTEM_SETTING.SEM)
  335. {
  336. if (!a_pCSEMStageData.ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles))
  337. {
  338. return ;
  339. }
  340. }
  341. m_pStage.SetBoundary(pBoundary);
  342. m_pStage.SetSTD(pSTD);
  343. m_pStage.SetHoleList(listStageHoles, true);
  344. DrawStage();
  345. this.button_Ok.Enabled = true;
  346. }
  347. public void DrawStage()
  348. {
  349. Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  350. Rectangle re = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  351. int pWnd = otsdataconst.IDC_PIC_STAGE;
  352. int nWidth = (int)rc.Width;
  353. int nHeight = (int)rc.Height;
  354. Object pDC = new Object();
  355. bool DeleteObject = false;
  356. //paint the DC with white
  357. Brush pOldBrush = new SolidBrush(Color.FromArgb(50, Color.White));
  358. m_ctrlStagePicture.Refresh();
  359. //Image img = (Image)new Bitmap(m_ctrlStagePicture.Width, m_ctrlStagePicture.Height);
  360. //Graphics graphics = m_ctrlStagePicture.CreateGraphics();// Graphics.FromImage(img);
  361. //graphics.FillRectangle(new SolidBrush(Color.Beige), re);
  362. pDC = m_ctrlStagePicture.CreateGraphics();
  363. //消除锯齿
  364. ((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  365. ((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  366. ((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点
  367. //get stage information
  368. CDomain pBoundery = m_pStage.GetBoundary();// GetBoundary();
  369. System.Drawing.Rectangle BounderyRect = pBoundery.GetDomainRect();
  370. int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 )
  371. int nBounderyHeight = (int)(BounderyRect.Height);
  372. double PixSize = 0;
  373. double coordinateSystemEndpoint = 0;
  374. if (nBounderyWidth > nBounderyHeight)
  375. {
  376. PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2));
  377. coordinateSystemEndpoint = nBounderyWidth/2;
  378. }
  379. else
  380. {
  381. PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2));
  382. coordinateSystemEndpoint = nBounderyHeight/2;
  383. }
  384. //draw boundery
  385. Brush pLTGrayBrush = new SolidBrush(Color.FromArgb(255, 0, 0));
  386. stageDisplayHelp.DrawStageBoundery(m_pStage, nWidth, nHeight, pDC, PixSize);
  387. ////draw STD
  388. //Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  389. //DrawStageSTD(m_pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize);
  390. ////draw holes
  391. //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  392. stageDisplayHelp.DrawStageHole(m_pStage, nWidth, nHeight, pDC, PixSize);
  393. // draw ratio
  394. stageDisplayHelp.DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc);
  395. stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpoint);
  396. pLTGrayBrush.Dispose();
  397. //pBlackBrush.Dispose();
  398. //pWriteBrush.Dispose();
  399. //graphics.Dispose();
  400. //((Graphics)pDC).Dispose();
  401. pOldBrush.Dispose();
  402. }
  403. private void button_Ok_Click(object sender, EventArgs e)
  404. {
  405. this.DialogResult = DialogResult.OK;
  406. this.Close();
  407. }
  408. private void button_AddHole_Click(object sender, EventArgs e)
  409. {
  410. dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0);
  411. }
  412. private void button_DelHole_Click(object sender, EventArgs e)
  413. {
  414. if(dataGridView_Holes.Rows.Count<1)
  415. {
  416. return;
  417. }
  418. int index = dataGridView_Holes.CurrentCell.RowIndex;
  419. dataGridView_Holes.Rows.RemoveAt(index);
  420. }
  421. bool CheckParams()
  422. {
  423. double dout;
  424. if (!double.TryParse(tBoundaryX.Text,out dout))
  425. {
  426. return false;
  427. }
  428. if (!double.TryParse(tBoundaryY.Text, out dout))
  429. {
  430. return false;
  431. }
  432. if (!double.TryParse(tBoundaryWide.Text, out dout))
  433. {
  434. return false;
  435. }
  436. if (!double.TryParse(tBoundaryHeight.Text, out dout))
  437. {
  438. return false;
  439. }
  440. if (!double.TryParse(tStandardsampleX.Text, out dout))
  441. {
  442. return false;
  443. }
  444. if (!double.TryParse(tStandardsampleY.Text, out dout))
  445. {
  446. return false;
  447. }
  448. if (!double.TryParse(tStandardsampleWide.Text, out dout))
  449. {
  450. return false;
  451. }
  452. if (!double.TryParse(tStandardsampleHeight.Text, out dout))
  453. {
  454. return false;
  455. }
  456. for (int i=0;i<dataGridView_Holes.Rows.Count;i++)
  457. {
  458. for(int j=2;j<=5;j++)
  459. {
  460. if (!double.TryParse(dataGridView_Holes.Rows[i].Cells[j].Value.ToString(), out dout))
  461. {
  462. return false;
  463. }
  464. }
  465. }
  466. return true;
  467. }
  468. private void m_ctrlStagePicture_Paint(object sender, PaintEventArgs e)
  469. {
  470. }
  471. private void DlgStageEdit_Paint(object sender, PaintEventArgs e)
  472. {
  473. }
  474. private void DlgStageEdit_HelpButtonClicked(object sender, CancelEventArgs e)
  475. {
  476. MessageBox.Show("样品台文件说明\n样品台名行只能有一个字符串参数。样品台名不能为空字串,不能含\',\'字符\n样品台边框行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0\n标样信息行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0\n样品孔信息行有6个数值参数,1个字符串参数,5个数值参数。1个字符串参数为样品孔名。5个数值参数为形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0。", "Help",MessageBoxButtons.OK,MessageBoxIcon.Information);
  477. }
  478. }
  479. }