DlgStageEdit.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. return;
  209. }
  210. CSEMStageData a_pCSEMStageData = new CSEMStageData();
  211. //获取配置文件中 StageData 内容
  212. COTSDefaultParam m_DefaultParam = new COTSDefaultParam();
  213. m_DefaultParam.LoadInfoFromProgMgrFile();
  214. a_pCSEMStageData = m_DefaultParam.GetStageDataParam();
  215. m_pStage = new CStage();
  216. m_pStage.SetName(tStageName.Text);
  217. // boundary
  218. string strValue = "";
  219. if(radioButton_BoundaryCircle.Checked)
  220. {
  221. strValue += "0";
  222. tBoundaryHeight.Text="0";
  223. }
  224. else
  225. {
  226. strValue += "1";
  227. }
  228. strValue += "," + tBoundaryX.Text+","+tBoundaryY.Text+","+tBoundaryWide.Text+","+ tBoundaryHeight.Text;
  229. CDomain pBoundary = stageDisplayHelp.GetDomain(strValue);
  230. // STD
  231. strValue = "";
  232. if(radioButton_StandardsampleCircle.Checked)
  233. {
  234. strValue += "0";
  235. tStandardsampleHeight.Text = "0";
  236. }
  237. else
  238. {
  239. strValue += "1";
  240. }
  241. strValue += "," + tStandardsampleX.Text + "," + tStandardsampleY.Text + "," + tStandardsampleWide.Text + "," + tStandardsampleHeight.Text;
  242. CDomain pSTD = stageDisplayHelp.GetDomain(strValue);
  243. // coordinate system
  244. CStageParam.COORDINATE_SYSTEM_SETTING nCoodrSysSetting = CStageParam.COORDINATE_SYSTEM_SETTING.INVALID;
  245. if(radioButton_OTS.Checked)
  246. {
  247. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)0;
  248. }
  249. else
  250. {
  251. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)1;
  252. }
  253. // Holes list
  254. List<CHole> listHoles = new List<CHole>();
  255. for(int i=0;i<dataGridView_Holes.Rows.Count;i++)
  256. {
  257. strValue = "";
  258. if(dataGridView_Holes.Rows[i].Cells[1].Value=="圆形")
  259. {
  260. strValue += "0";
  261. }
  262. else
  263. {
  264. strValue += "1";
  265. }
  266. 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;
  267. CDomain pDomain = stageDisplayHelp.GetDomain(strValue);
  268. //add holes
  269. listHoles.Add(new CHole(dataGridView_Holes.Rows[i].Cells[0].Value.ToString(), pDomain));
  270. }
  271. // check stage components
  272. // name should be ok
  273. if (pBoundary == null)
  274. {
  275. return ;
  276. }
  277. if (pBoundary.IsInvalid())
  278. {
  279. // boundary is invalid
  280. return ;
  281. }
  282. if (pSTD != null)
  283. {
  284. // STD has to be inside of the boundary
  285. if (!pBoundary.DomainInDomain(pSTD))
  286. {
  287. // STD is over the boundary
  288. return ;
  289. }
  290. }
  291. else
  292. {
  293. return ;
  294. }
  295. // hole has to be inside of the boundary and can't have common part with STD and each other
  296. List<CHole> listStageHoles = new List<CHole>();
  297. foreach (var pHole in listHoles)
  298. {
  299. if (!pBoundary.DomainInDomain(pHole))
  300. {
  301. // this hole is over the boundary, jump over
  302. continue;
  303. }
  304. else if (pSTD.IntersectDomain(pHole))
  305. {
  306. // this hole has common part with STD, jump over
  307. continue;
  308. }
  309. bool bHasCommonPart = false;
  310. foreach (var pStageHole in listStageHoles)
  311. {
  312. if (pStageHole.IntersectDomain(pHole))
  313. {
  314. // this hole has common part with a hole already on the stage
  315. bHasCommonPart = true;
  316. break;
  317. }
  318. }
  319. if (bHasCommonPart)
  320. {
  321. // this hole has common part with a hole already on the stage, jump over
  322. continue;
  323. }
  324. // the hole is ok, add it into stage holes list
  325. listStageHoles.Add(pHole);
  326. }
  327. if (listStageHoles.Count == 0)
  328. {
  329. // no hole at all
  330. return ;
  331. }
  332. // the stage is in SEM coordinate system, convert all components to OTS system
  333. if (nCoodrSysSetting == CStageParam.COORDINATE_SYSTEM_SETTING.SEM)
  334. {
  335. if (!a_pCSEMStageData.ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles))
  336. {
  337. return ;
  338. }
  339. }
  340. m_pStage.SetBoundary(pBoundary);
  341. m_pStage.SetSTD(pSTD);
  342. m_pStage.SetHoleList(listStageHoles, true);
  343. DrawStage();
  344. this.button_Ok.Enabled = true;
  345. }
  346. public void DrawStage()
  347. {
  348. Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  349. Rectangle re = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  350. int pWnd = otsdataconst.IDC_PIC_STAGE;
  351. int nWidth = (int)rc.Width;
  352. int nHeight = (int)rc.Height;
  353. Object pDC = new Object();
  354. bool DeleteObject = false;
  355. //paint the DC with white
  356. Brush pOldBrush = new SolidBrush(Color.FromArgb(50, Color.White));
  357. m_ctrlStagePicture.Refresh();
  358. //Image img = (Image)new Bitmap(m_ctrlStagePicture.Width, m_ctrlStagePicture.Height);
  359. //Graphics graphics = m_ctrlStagePicture.CreateGraphics();// Graphics.FromImage(img);
  360. //graphics.FillRectangle(new SolidBrush(Color.Beige), re);
  361. pDC = m_ctrlStagePicture.CreateGraphics();
  362. //消除锯齿
  363. ((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  364. ((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  365. ((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点
  366. //get stage information
  367. CDomain pBoundery = m_pStage.GetBoundary();// GetBoundary();
  368. System.Drawing.Rectangle BounderyRect = pBoundery.GetDomainRect();
  369. int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 )
  370. int nBounderyHeight = (int)(BounderyRect.Height);
  371. double PixSize = 0;
  372. if (nBounderyWidth > nBounderyHeight)
  373. {
  374. PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2));
  375. }
  376. else
  377. {
  378. PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2));
  379. }
  380. //draw boundery
  381. Brush pLTGrayBrush = new SolidBrush(Color.FromArgb(255, 0, 0));
  382. stageDisplayHelp.DrawStageBoundery(m_pStage, nWidth, nHeight, pDC, PixSize);
  383. ////draw STD
  384. //Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  385. //DrawStageSTD(m_pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize);
  386. ////draw holes
  387. //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  388. stageDisplayHelp.DrawStageHole(m_pStage, nWidth, nHeight, pDC, PixSize);
  389. // draw ratio
  390. stageDisplayHelp.DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc);
  391. stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize);
  392. pLTGrayBrush.Dispose();
  393. //pBlackBrush.Dispose();
  394. //pWriteBrush.Dispose();
  395. //graphics.Dispose();
  396. //((Graphics)pDC).Dispose();
  397. pOldBrush.Dispose();
  398. }
  399. private void button_Ok_Click(object sender, EventArgs e)
  400. {
  401. this.DialogResult = DialogResult.OK;
  402. this.Close();
  403. }
  404. private void button_AddHole_Click(object sender, EventArgs e)
  405. {
  406. dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0);
  407. }
  408. private void button_DelHole_Click(object sender, EventArgs e)
  409. {
  410. if(dataGridView_Holes.Rows.Count<1)
  411. {
  412. return;
  413. }
  414. int index = dataGridView_Holes.CurrentCell.RowIndex;
  415. dataGridView_Holes.Rows.RemoveAt(index);
  416. }
  417. bool CheckParams()
  418. {
  419. double dout;
  420. if (!double.TryParse(tBoundaryX.Text,out dout))
  421. {
  422. return false;
  423. }
  424. if (!double.TryParse(tBoundaryY.Text, out dout))
  425. {
  426. return false;
  427. }
  428. if (!double.TryParse(tBoundaryWide.Text, out dout))
  429. {
  430. return false;
  431. }
  432. if (!double.TryParse(tBoundaryHeight.Text, out dout))
  433. {
  434. return false;
  435. }
  436. if (!double.TryParse(tStandardsampleX.Text, out dout))
  437. {
  438. return false;
  439. }
  440. if (!double.TryParse(tStandardsampleY.Text, out dout))
  441. {
  442. return false;
  443. }
  444. if (!double.TryParse(tStandardsampleWide.Text, out dout))
  445. {
  446. return false;
  447. }
  448. if (!double.TryParse(tStandardsampleHeight.Text, out dout))
  449. {
  450. return false;
  451. }
  452. for (int i=0;i<dataGridView_Holes.Rows.Count;i++)
  453. {
  454. for(int j=2;j<=5;j++)
  455. {
  456. if (!double.TryParse(dataGridView_Holes.Rows[i].Cells[j].Value.ToString(), out dout))
  457. {
  458. return false;
  459. }
  460. }
  461. }
  462. return true;
  463. }
  464. private void m_ctrlStagePicture_Paint(object sender, PaintEventArgs e)
  465. {
  466. }
  467. private void DlgStageEdit_Paint(object sender, PaintEventArgs e)
  468. {
  469. //DrawXY(m_ctrlStagePicture);
  470. }
  471. private void DlgStageEdit_HelpButtonClicked(object sender, CancelEventArgs e)
  472. {
  473. 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);
  474. Cursor = Cursors.Default;
  475. }
  476. }
  477. }