DlgStageEdit.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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 Stage;
  21. StageDisplayHelp stageDisplayHelp;
  22. OTSCommon.Language lan;
  23. System.Collections.Hashtable hashtable;
  24. List<string> StageNames = new List<string>();
  25. string StageN = "";
  26. public DlgStageEdit(List<string> a_StageNames)
  27. {
  28. InitializeComponent();
  29. StageNames = a_StageNames;
  30. }
  31. public DlgStageEdit(CStage a_Stage,List<string> a_StageNames)
  32. {
  33. InitializeComponent();
  34. Stage = a_Stage;
  35. StageNames = a_StageNames;
  36. }
  37. ComboBox cmb_Temp = new ComboBox();
  38. private void DlgStageEdit_Load(object sender, EventArgs e)
  39. {
  40. lan = new OTSCommon.Language(this);
  41. hashtable = lan.GetNameTable(this.Name);
  42. radioButton_OTS.Checked = true;
  43. radioButton_BoundarySquare.Checked = true;
  44. radioButton_StandardsampleSqare.Checked = true;
  45. string str = hashtable["str1"].ToString();
  46. dataGridView_Holes.Columns.Add("HoleName", str);
  47. str = hashtable["str2"].ToString();
  48. dataGridView_Holes.Columns.Add("HoleShape", str);
  49. str = hashtable["str3"].ToString();
  50. dataGridView_Holes.Columns.Add("CenterCoordinatesX", str);
  51. str = hashtable["str4"].ToString();
  52. dataGridView_Holes.Columns.Add("CenterCoordinatesY", str);
  53. str = hashtable["str5"].ToString();
  54. dataGridView_Holes.Columns.Add("Param1", str);
  55. str = hashtable["str6"].ToString();
  56. dataGridView_Holes.Columns.Add("Param2", str);
  57. str = hashtable["str7"].ToString();
  58. dataGridView_Holes.Rows.Add("1", str, -4250, -16000, 12000, 0);
  59. cmb_Temp.Visible = false;
  60. cmb_Temp.Items.Add(str);
  61. str = hashtable["str8"].ToString();
  62. cmb_Temp.Items.Add(str);
  63. cmb_Temp.SelectedIndexChanged += new EventHandler(cmb_Temp_SelectedIndexChanged);
  64. dataGridView_Holes.Controls.Add(cmb_Temp);
  65. stageDisplayHelp = new StageDisplayHelp();
  66. if(Stage!=null)
  67. {
  68. LoadStageData(Stage);
  69. }
  70. else
  71. {
  72. btn_new.Visible = false;
  73. }
  74. SetHelp();
  75. StageNames.Remove(tStageName.Text);
  76. }
  77. void SetHelp()
  78. {
  79. string str = hashtable["str9"].ToString();
  80. helpProvider1.SetHelpString(label1, "样品台名不能为空字串,不能含\',\'字符!");
  81. helpProvider1.SetHelpString(groupBox1, "样品台边框行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0");
  82. helpProvider1.SetHelpString(groupBox2, "标样信息行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0");
  83. helpProvider1.SetHelpString(groupBox3, "样品孔信息行有6个数值参数,1个字符串参数,5个数值参数。1个字符串参数为样品孔名。5个数值参数为形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0。");
  84. }
  85. void LoadStageData(CStage cStage)
  86. {
  87. tStageName.Text = Stage.GetName();
  88. if(Stage.GetBoundary().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND)
  89. {
  90. radioButton_BoundaryCircle.Checked = true;
  91. tBoundaryWide.Text = Stage.GetBoundary().GetDiameter().ToString();
  92. tBoundaryHeight.Enabled = false;
  93. tBoundaryHeight.Text = "0";
  94. }
  95. else
  96. {
  97. radioButton_BoundarySquare.Checked = true;
  98. tBoundaryWide.Text = Stage.GetBoundary().GetRectDomain().Width.ToString();
  99. tBoundaryHeight.Enabled = true;
  100. tBoundaryHeight.Text = Stage.GetBoundary().GetRectDomain().Height.ToString();
  101. }
  102. tBoundaryX.Text= Stage.GetBoundary().GetDomainCenter().X.ToString();
  103. tBoundaryY.Text = Stage.GetBoundary().GetDomainCenter().Y.ToString();
  104. if(Stage.GetSTD().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND)
  105. {
  106. radioButton_StandardsampleCircle.Checked = true;
  107. tStandardsampleHeight.Enabled = false;
  108. tStandardsampleWide.Text = Stage.GetSTD().GetDiameter().ToString();
  109. }
  110. else
  111. {
  112. radioButton_StandardsampleSqare.Checked = true;
  113. tStandardsampleHeight.Enabled =true;
  114. tStandardsampleWide.Text = Stage.GetSTD().GetRectDomain().Width.ToString();
  115. }
  116. tStandardsampleX.Text = Stage.GetSTD().GetDomainCenter().X.ToString();
  117. tStandardsampleY.Text = Stage.GetSTD().GetDomainCenter().Y.ToString();
  118. tStandardsampleHeight.Text = Stage.GetSTD().GetRectDomain().Height.ToString();
  119. dataGridView_Holes.Rows[0].Cells[0].Value = Stage.GetHoleList()[0].GetName();
  120. if (Stage.GetHoleList()[0].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND)
  121. {
  122. dataGridView_Holes.Rows[0].Cells[1].Value = "圆形";
  123. dataGridView_Holes.Rows[0].Cells[4].Value = Stage.GetHoleList()[0].GetDiameter().ToString();
  124. dataGridView_Holes.Rows[0].Cells[5].Value = "0";
  125. }
  126. else
  127. {
  128. dataGridView_Holes.Rows[0].Cells[1].Value = "方形";
  129. dataGridView_Holes.Rows[0].Cells[4].Value = Stage.GetHoleList()[0].GetRectDomain().Width.ToString();
  130. dataGridView_Holes.Rows[0].Cells[5].Value = Stage.GetHoleList()[0].GetRectDomain().Height.ToString();
  131. }
  132. dataGridView_Holes.Rows[0].Cells[2].Value = Stage.GetHoleList()[0].GetDomainCenter().X.ToString();
  133. dataGridView_Holes.Rows[0].Cells[3].Value = Stage.GetHoleList()[0].GetDomainCenter().Y.ToString();
  134. for (int i=1;i< Stage.GetHoleList().Count;i++)
  135. {
  136. string sr = "";
  137. string pra1 = "";
  138. string pra2 = "";
  139. if (Stage.GetHoleList()[i].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND)
  140. {
  141. sr= "圆形";
  142. pra1 = Stage.GetHoleList()[i].GetDiameter().ToString();
  143. pra2 = "0";
  144. }
  145. else
  146. {
  147. sr= "方形";
  148. pra1 = Stage.GetHoleList()[i].GetRectDomain().Width.ToString();
  149. pra2 = Stage.GetHoleList()[i].GetRectDomain().Height.ToString();
  150. }
  151. dataGridView_Holes.Rows.Add(Stage.GetHoleList()[i].GetName(), sr, Stage.GetHoleList()[i].GetDomainCenter().X.ToString(), Stage.GetHoleList()[i].GetDomainCenter().Y.ToString(), pra1, pra2);
  152. }
  153. }
  154. private void radioButton_BoundaryCircle_Click(object sender, EventArgs e)
  155. {
  156. label8.Enabled = false;
  157. tBoundaryHeight.Enabled = false;
  158. tBoundaryHeight.Text = "0";
  159. label7.Text = "直径:";
  160. }
  161. private void radioButton_BoundarySquare_Click(object sender, EventArgs e)
  162. {
  163. label8.Enabled = true;
  164. tBoundaryHeight.Enabled = true;
  165. label7.Text = "宽度:";
  166. }
  167. private void radioButton_StandardsampleCircle_Click(object sender, EventArgs e)
  168. {
  169. label9.Enabled = false;
  170. tStandardsampleHeight.Enabled = false;
  171. tStandardsampleHeight.Text = "0";
  172. label10.Text = "直径:";
  173. }
  174. private void radioButton__StandardsampleSqare_Click(object sender, EventArgs e)
  175. {
  176. label9.Enabled = true;
  177. tStandardsampleHeight.Enabled = true;
  178. label10.Text = "宽度:";
  179. }
  180. private void dataGridView_Holes_CurrentCellChanged(object sender, EventArgs e)
  181. {
  182. if(dataGridView_Holes.CurrentRow==null)
  183. {
  184. return;
  185. }
  186. if(dataGridView_Holes.CurrentCell.ColumnIndex==1)
  187. {
  188. Rectangle rect = dataGridView_Holes.GetCellDisplayRectangle(dataGridView_Holes.CurrentCell.ColumnIndex, dataGridView_Holes.CurrentCell.RowIndex, false);
  189. string HoleShape = dataGridView_Holes.CurrentCell.Value.ToString();
  190. cmb_Temp.Left = rect.Left;
  191. cmb_Temp.Top = rect.Top;
  192. cmb_Temp.Width = rect.Width;
  193. cmb_Temp.SelectedIndex = 0;
  194. cmb_Temp.Visible = true;
  195. }
  196. else
  197. {
  198. cmb_Temp.Visible = false;
  199. }
  200. }
  201. void cmb_Temp_SelectedIndexChanged(object sender ,EventArgs e)
  202. {
  203. if (dataGridView_Holes.CurrentRow == null)
  204. {
  205. return;
  206. }
  207. if (((ComboBox)sender).SelectedIndex == 0)
  208. {
  209. dataGridView_Holes.CurrentCell.Value = "圆形";
  210. dataGridView_Holes.CurrentRow.Cells[5].Value = 0;
  211. }
  212. else
  213. {
  214. dataGridView_Holes.CurrentCell.Value = "方形";
  215. dataGridView_Holes.CurrentRow.Cells[5].Value = "";
  216. }
  217. }
  218. private void dataGridView_Holes_Scroll(object sender, ScrollEventArgs e)
  219. {
  220. this.cmb_Temp.Visible = false;
  221. }
  222. bool CheckAndSetStage()
  223. {
  224. if(StageNames.Contains(StageN))
  225. {
  226. MessageBox.Show("Already exist " + tStageName.Text.Trim() + "!", "Error");
  227. return false;
  228. }
  229. if (!CheckParams())
  230. {
  231. //this.button_Ok.Enabled = false;
  232. MessageBox.Show("Please check Params!");
  233. return false;
  234. }
  235. if (tBoundaryWide.Text == "1" || tBoundaryHeight.Text == "1" || tStandardsampleWide.Text == "1" || tStandardsampleHeight.Text == "1")
  236. {
  237. //this.button_Ok.Enabled = false;
  238. MessageBox.Show("The length value cannot be 1!");
  239. return false;
  240. }
  241. for (int i = 0; i < dataGridView_Holes.Rows.Count; i++)
  242. {
  243. for (int j = 4; j <= 5; j++)
  244. {
  245. if (dataGridView_Holes.Rows[i].Cells[j].Value.ToString() == "1")
  246. {
  247. //this.button_Ok.Enabled = false;
  248. MessageBox.Show("The length value cannot be 1!");
  249. return false;
  250. }
  251. }
  252. }
  253. CSEMStageData a_pCSEMStageData = new CSEMStageData();
  254. //获取配置文件中 StageData 内容
  255. COTSDefaultParam m_DefaultParam = new COTSDefaultParam();
  256. m_DefaultParam.LoadInfoFromProgMgrFile();
  257. a_pCSEMStageData = m_DefaultParam.GetStageDataParam();
  258. Stage = new CStage();
  259. Stage.SetName(StageN);
  260. // boundary
  261. string strValue = "";
  262. if(radioButton_BoundaryCircle.Checked)
  263. {
  264. strValue += "0";
  265. tBoundaryHeight.Text="0";
  266. }
  267. else
  268. {
  269. strValue += "1";
  270. }
  271. strValue += "," + tBoundaryX.Text+","+tBoundaryY.Text+","+tBoundaryWide.Text+","+ tBoundaryHeight.Text;
  272. CDomain pBoundary = stageDisplayHelp.GetDomain(strValue);
  273. // STD
  274. strValue = "";
  275. if(radioButton_StandardsampleCircle.Checked)
  276. {
  277. strValue += "0";
  278. tStandardsampleHeight.Text = "0";
  279. }
  280. else
  281. {
  282. strValue += "1";
  283. }
  284. strValue += "," + tStandardsampleX.Text + "," + tStandardsampleY.Text + "," + tStandardsampleWide.Text + "," + tStandardsampleHeight.Text;
  285. CDomain pSTD = stageDisplayHelp.GetDomain(strValue);
  286. // coordinate system
  287. CStageParam.COORDINATE_SYSTEM_SETTING nCoodrSysSetting = CStageParam.COORDINATE_SYSTEM_SETTING.INVALID;
  288. if(radioButton_OTS.Checked)
  289. {
  290. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)0;
  291. }
  292. else
  293. {
  294. nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)1;
  295. }
  296. // Holes list
  297. List<CHole> listHoles = new List<CHole>();
  298. for(int i=0;i<dataGridView_Holes.Rows.Count;i++)
  299. {
  300. strValue = "";
  301. if(dataGridView_Holes.Rows[i].Cells[1].Value.ToString()=="圆形")
  302. {
  303. strValue += "0";
  304. }
  305. else
  306. {
  307. strValue += "1";
  308. }
  309. 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;
  310. CDomain pDomain = stageDisplayHelp.GetDomain(strValue);
  311. //add holes
  312. listHoles.Add(new CHole(dataGridView_Holes.Rows[i].Cells[0].Value.ToString(), pDomain));
  313. }
  314. // check stage components
  315. // name should be ok
  316. if (pBoundary == null)
  317. {
  318. return false;
  319. }
  320. if (pBoundary.IsInvalid())
  321. {
  322. // boundary is invalid
  323. return false;
  324. }
  325. if (pSTD != null)
  326. {
  327. // STD has to be inside of the boundary由于计算准确性问题,此项暂时去除
  328. //if (!pBoundary.DomainInDomain(pSTD))
  329. //{
  330. // MessageBox.Show("STD is over the boundary!");
  331. // return false;
  332. //}
  333. }
  334. else
  335. {
  336. return false;
  337. }
  338. // hole has to be inside of the boundary and can't have common part with STD and each other
  339. List<CHole> listStageHoles = new List<CHole>();
  340. foreach (var pHole in listHoles)
  341. {
  342. if (!pBoundary.DomainInDomain(pHole))
  343. {
  344. MessageBox.Show(pHole.GetName() + "is over the boundary, jump over!");
  345. continue;
  346. }
  347. //else if (pSTD.IntersectDomain(pHole))
  348. //{
  349. // MessageBox.Show(pHole.GetName() + " has common part with STD, jump over!");
  350. // continue;
  351. //}
  352. bool bHasCommonPart = false;
  353. foreach (var pStageHole in listStageHoles)
  354. {
  355. if (pStageHole.IntersectDomain(pHole))
  356. {
  357. MessageBox.Show(pHole.GetName() + " has common part with a hole already on the stage!");
  358. bHasCommonPart = true;
  359. break;
  360. }
  361. }
  362. if (bHasCommonPart)
  363. {
  364. // this hole has common part with a hole already on the stage, jump over
  365. continue;
  366. }
  367. // the hole is ok, add it into stage holes list
  368. listStageHoles.Add(pHole);
  369. }
  370. if (listStageHoles.Count == 0)
  371. {
  372. // no hole at all
  373. return false;
  374. }
  375. // the stage is in SEM coordinate system, convert all components to OTS system
  376. if (nCoodrSysSetting == CStageParam.COORDINATE_SYSTEM_SETTING.SEM)
  377. {
  378. if (!a_pCSEMStageData.ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles))
  379. {
  380. return false;
  381. }
  382. }
  383. Stage.SetBoundary(pBoundary);
  384. Stage.SetSTD(pSTD);
  385. Stage.SetHoleList(listStageHoles, true);
  386. return true;
  387. }
  388. private void button_Generate_Click(object sender, EventArgs e)
  389. {
  390. if(!CheckAndSetStage())
  391. {
  392. return;
  393. }
  394. DrawStage();
  395. btn_reght90.Enabled = true;
  396. btn_left90.Enabled = true;
  397. this.button_Ok.Enabled = true;
  398. btn_new.Enabled = true;
  399. }
  400. public void DrawStage()
  401. {
  402. Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  403. //Rectangle re = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  404. int pWnd = otsdataconst.IDC_PIC_STAGE;
  405. int nWidth = (int)rc.Width;
  406. int nHeight = (int)rc.Height;
  407. Object pDC = new Object();
  408. //bool DeleteObject = false;
  409. //paint the DC with white
  410. Brush pOldBrush = new SolidBrush(Color.FromArgb(50, Color.White));
  411. m_ctrlStagePicture.Refresh();
  412. //Image img = (Image)new Bitmap(m_ctrlStagePicture.Width, m_ctrlStagePicture.Height);
  413. //Graphics graphics = m_ctrlStagePicture.CreateGraphics();// Graphics.FromImage(img);
  414. //graphics.FillRectangle(new SolidBrush(Color.Beige), re);
  415. pDC = m_ctrlStagePicture.CreateGraphics();
  416. //消除锯齿
  417. ((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  418. ((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  419. ((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点
  420. //get stage information
  421. CDomain pBoundery = Stage.GetBoundary();// GetBoundary();
  422. System.Drawing.RectangleF BounderyRect = pBoundery.GetDomainRect();
  423. int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 )
  424. int nBounderyHeight = 0;
  425. if (pBoundery.GetShape() == otsdataconst.DOMAIN_SHAPE.RECTANGLE)
  426. {nBounderyHeight = (int)(BounderyRect.Height);}
  427. else
  428. {
  429. nBounderyHeight = (int)(BounderyRect.Width);
  430. }
  431. double PixSize = 0;
  432. double coordinateSystemEndpoint /*= 0*/;
  433. if (nBounderyWidth > nBounderyHeight)
  434. {
  435. PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2));
  436. coordinateSystemEndpoint = nBounderyWidth/2;
  437. }
  438. else
  439. {
  440. PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2));
  441. coordinateSystemEndpoint = nBounderyHeight/2;
  442. }
  443. //draw boundery
  444. Brush pLTGrayBrush = new SolidBrush(Color.FromArgb(255, 0, 0));
  445. stageDisplayHelp.DrawStageBoundery(Stage, nWidth, nHeight, pDC, PixSize);
  446. //draw STD
  447. Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0));
  448. stageDisplayHelp.DrawStageSTD(Stage, nWidth, nHeight, pDC, PixSize);
  449. ////draw holes
  450. //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ;
  451. stageDisplayHelp.DrawStageHole(Stage, nWidth, nHeight, pDC, PixSize);
  452. // draw ratio
  453. stageDisplayHelp.DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc);
  454. if (button_Coordinate.Text == "坐标系关闭")
  455. {
  456. double coordinateSystemEndpointX = nBounderyWidth / 2;
  457. double coordinateSystemEndpointY = nBounderyHeight / 2;
  458. stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpointX, coordinateSystemEndpointY);
  459. }
  460. pLTGrayBrush.Dispose();
  461. //pBlackBrush.Dispose();
  462. //pWriteBrush.Dispose();
  463. //graphics.Dispose();
  464. //((Graphics)pDC).Dispose();
  465. pOldBrush.Dispose();
  466. }
  467. private void button_Ok_Click(object sender, EventArgs e)
  468. {
  469. if (!CheckAndSetStage())
  470. {
  471. return;
  472. }
  473. this.DialogResult = DialogResult.OK;
  474. this.Close();
  475. }
  476. private void button_AddHole_Click(object sender, EventArgs e)
  477. {
  478. dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0);
  479. }
  480. private void button_DelHole_Click(object sender, EventArgs e)
  481. {
  482. if(dataGridView_Holes.Rows.Count<1)
  483. {
  484. return;
  485. }
  486. int index = dataGridView_Holes.CurrentCell.RowIndex;
  487. dataGridView_Holes.Rows.RemoveAt(index);
  488. }
  489. bool CheckParams()
  490. {
  491. double dout;
  492. if (!double.TryParse(tBoundaryX.Text,out dout))
  493. {
  494. return false;
  495. }
  496. if (!double.TryParse(tBoundaryY.Text, out dout))
  497. {
  498. return false;
  499. }
  500. if (!double.TryParse(tBoundaryWide.Text, out dout))
  501. {
  502. return false;
  503. }
  504. if (!double.TryParse(tBoundaryHeight.Text, out dout))
  505. {
  506. return false;
  507. }
  508. if (!double.TryParse(tStandardsampleX.Text, out dout))
  509. {
  510. return false;
  511. }
  512. if (!double.TryParse(tStandardsampleY.Text, out dout))
  513. {
  514. return false;
  515. }
  516. if (!double.TryParse(tStandardsampleWide.Text, out dout))
  517. {
  518. return false;
  519. }
  520. if (!double.TryParse(tStandardsampleHeight.Text, out dout))
  521. {
  522. return false;
  523. }
  524. for (int i=0;i<dataGridView_Holes.Rows.Count;i++)
  525. {
  526. for(int j=2;j<=5;j++)
  527. {
  528. if (!double.TryParse(dataGridView_Holes.Rows[i].Cells[j].Value.ToString(), out dout))
  529. {
  530. return false;
  531. }
  532. }
  533. }
  534. if (radioButton_BoundarySquare.Checked)
  535. {
  536. if (double.Parse(tBoundaryHeight.Text) == 0)
  537. {
  538. return false;
  539. }
  540. }
  541. if (radioButton_StandardsampleSqare.Checked)
  542. {
  543. if (double.Parse(tStandardsampleHeight.Text) == 0)
  544. {
  545. return false;
  546. }
  547. }
  548. return true;
  549. }
  550. private void m_ctrlStagePicture_Paint(object sender, PaintEventArgs e)
  551. {
  552. }
  553. private void DlgStageEdit_Paint(object sender, PaintEventArgs e)
  554. {
  555. }
  556. private void DlgStageEdit_HelpButtonClicked(object sender, CancelEventArgs e)
  557. {
  558. 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);
  559. }
  560. private void button_Coordinate_Click(object sender, EventArgs e)
  561. {
  562. if (button_Coordinate.Text == "坐标系显示")
  563. {
  564. Object pDC = new Object();
  565. pDC = m_ctrlStagePicture.CreateGraphics();
  566. Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size);
  567. int nWidth = (int)rc.Width;
  568. int nHeight = (int)rc.Height;
  569. double nBounderyWidth = 0;//um,,pixle is (nWidth - PIC_EDGE * 2 )
  570. double nBounderyHeight = 0;
  571. if(double.TryParse(tBoundaryWide.Text,out nBounderyWidth))
  572. {
  573. nBounderyWidth = double.Parse(tBoundaryWide.Text);
  574. }
  575. else
  576. {
  577. nBounderyWidth = 50000;
  578. }
  579. if (double.TryParse(tBoundaryHeight.Text, out nBounderyHeight))
  580. {
  581. nBounderyHeight = double.Parse(tBoundaryHeight.Text);
  582. }
  583. else
  584. {
  585. nBounderyHeight = 50000;
  586. }
  587. double PixSize = 0;
  588. double coordinateSystemEndpointX = nBounderyWidth / 2;
  589. double coordinateSystemEndpointY= nBounderyHeight / 2;
  590. if(radioButton_BoundaryCircle.Checked)
  591. {
  592. coordinateSystemEndpointY = coordinateSystemEndpointX;
  593. }
  594. if (nBounderyWidth > nBounderyHeight)
  595. {
  596. PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2));
  597. }
  598. else
  599. {
  600. PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2));
  601. }
  602. stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpointX,coordinateSystemEndpointY);
  603. button_Coordinate.Text = "坐标系关闭";
  604. }
  605. else
  606. {
  607. button_Coordinate.Text = "坐标系显示";
  608. if(Stage != null)
  609. {
  610. DrawStage();
  611. }
  612. else
  613. {
  614. m_ctrlStagePicture.Refresh();
  615. }
  616. }
  617. }
  618. private void btn_reght90_Click(object sender, EventArgs e)
  619. {
  620. double it = 0;
  621. for (int i = 0; i < dataGridView_Holes.Rows.Count; i++)
  622. {
  623. it = Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[3].Value);
  624. dataGridView_Holes.Rows[i].Cells[3].Value= -Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[2].Value);
  625. dataGridView_Holes.Rows[i].Cells[2].Value = it;
  626. }
  627. dataGridView_Holes.Refresh();
  628. button_Generate_Click(null, null);
  629. }
  630. private void btn_left90_Click(object sender, EventArgs e)
  631. {
  632. double it = 0;
  633. for (int i = 0; i < dataGridView_Holes.Rows.Count; i++)
  634. {
  635. it = -Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[3].Value);
  636. dataGridView_Holes.Rows[i].Cells[3].Value = Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[2].Value);
  637. dataGridView_Holes.Rows[i].Cells[2].Value = it;
  638. }
  639. dataGridView_Holes.Refresh();
  640. button_Generate_Click(null, null);
  641. }
  642. private void btn_new_Click(object sender, EventArgs e)
  643. {
  644. StageNameSaveAs stageNameSaveAs = new StageNameSaveAs();
  645. DialogResult dialogResult = stageNameSaveAs.ShowDialog();
  646. if (dialogResult == DialogResult.OK)
  647. {
  648. if (tStageName.Text == stageNameSaveAs.StageNamewhichSaveAs)
  649. {
  650. MessageBox.Show("Already exist " + tStageName.Text.Trim() + "!", "Error");
  651. return;
  652. }
  653. StageN = stageNameSaveAs.StageNamewhichSaveAs;
  654. if (!CheckAndSetStage())
  655. {
  656. return;
  657. }
  658. this.DialogResult = DialogResult.No;
  659. this.Close();
  660. }
  661. }
  662. private void tStageName_TextChanged(object sender, EventArgs e)
  663. {
  664. StageN = tStageName.Text;
  665. }
  666. }
  667. }