DlgStageEdit.cs 27 KB

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