using OTSDataType; using OTSModelSharp; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using OTSModelSharp.Measure.GetStageInfo; namespace OTSMeasureApp._7_OTSProgMgrInfo.Stage { public partial class DlgStageEdit : Form { // stage file CStageParam m_pStageFile; public CStage m_pStage; StageDisplayHelp stageDisplayHelp; public DlgStageEdit() { InitializeComponent(); } public DlgStageEdit(CStage cStage) { InitializeComponent(); m_pStage = cStage; } ComboBox cmb_Temp = new ComboBox(); private void DlgStageEdit_Load(object sender, EventArgs e) { radioButton_OTS.Checked = true; radioButton_BoundarySquare.Checked = true; radioButton_StandardsampleSqare.Checked = true; dataGridView_Holes.Columns.Add("HoleName", "样品孔名称"); dataGridView_Holes.Columns.Add("HoleShape", "样品孔形状"); dataGridView_Holes.Columns.Add("CenterCoordinatesX", "中心x坐标"); dataGridView_Holes.Columns.Add("CenterCoordinatesY", "中心y坐标"); dataGridView_Holes.Columns.Add("Param1", "宽度或直径"); dataGridView_Holes.Columns.Add("Param2", "高度或0"); dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0); //SetDataGridViewStyle(); cmb_Temp.Visible = false; cmb_Temp.Items.Add("圆形"); cmb_Temp.Items.Add("方形"); cmb_Temp.SelectedIndexChanged += new EventHandler(cmb_Temp_SelectedIndexChanged); dataGridView_Holes.Controls.Add(cmb_Temp); stageDisplayHelp = new StageDisplayHelp(); if(m_pStage!=null) { LoadStageData(m_pStage); } SetHelp(); //Object pDC = new Object(); //pDC = m_ctrlStagePicture.CreateGraphics(); ////消除锯齿 //((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择 //((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量 //((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点 } void SetHelp() { helpProvider1.SetHelpString(label1, "样品台名不能为空字串,不能含\',\'字符!"); helpProvider1.SetHelpString(groupBox1, "样品台边框行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0"); helpProvider1.SetHelpString(groupBox2, "标样信息行有5个数值参数。形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0"); helpProvider1.SetHelpString(groupBox3, "样品孔信息行有6个数值参数,1个字符串参数,5个数值参数。1个字符串参数为样品孔名。5个数值参数为形状参数,中心x坐标,中心y坐标,宽度或直径,高度或0。"); } void LoadStageData(CStage cStage) { tStageName.Text = m_pStage.GetName(); if(m_pStage.GetBoundary().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND) { radioButton_BoundaryCircle.Checked = true; tBoundaryWide.Text = m_pStage.GetBoundary().GetDiameter().ToString(); tBoundaryHeight.Text = "0"; } else { radioButton_BoundarySquare.Checked = true; tBoundaryWide.Text = m_pStage.GetBoundary().GetRectDomain().Width.ToString(); tBoundaryHeight.Text = m_pStage.GetBoundary().GetRectDomain().Height.ToString(); } tBoundaryX.Text= m_pStage.GetBoundary().GetDomainCenter().X.ToString(); tBoundaryY.Text = m_pStage.GetBoundary().GetDomainCenter().Y.ToString(); if(m_pStage.GetSTD().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND) { radioButton_StandardsampleCircle.Checked = true; tStandardsampleWide.Text = m_pStage.GetSTD().GetDiameter().ToString(); } else { radioButton_StandardsampleSqare.Checked = true; tStandardsampleWide.Text = m_pStage.GetSTD().GetRectDomain().Width.ToString(); } tStandardsampleX.Text = m_pStage.GetSTD().GetDomainCenter().X.ToString(); tStandardsampleY.Text = m_pStage.GetSTD().GetDomainCenter().Y.ToString(); tStandardsampleHeight.Text = m_pStage.GetSTD().GetRectDomain().Height.ToString(); dataGridView_Holes.Rows[0].Cells[0].Value = m_pStage.GetHoleList()[0].GetName(); if (m_pStage.GetHoleList()[0].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND) { dataGridView_Holes.Rows[0].Cells[1].Value = "圆形"; dataGridView_Holes.Rows[0].Cells[4].Value = m_pStage.GetHoleList()[0].GetDiameter().ToString(); dataGridView_Holes.Rows[0].Cells[5].Value = "0"; } else { dataGridView_Holes.Rows[0].Cells[1].Value = "方形"; dataGridView_Holes.Rows[0].Cells[4].Value = m_pStage.GetHoleList()[0].GetRectDomain().Width.ToString(); dataGridView_Holes.Rows[0].Cells[5].Value = m_pStage.GetHoleList()[0].GetRectDomain().Height.ToString(); } dataGridView_Holes.Rows[0].Cells[2].Value = m_pStage.GetHoleList()[0].GetDomainCenter().X.ToString(); dataGridView_Holes.Rows[0].Cells[3].Value = m_pStage.GetHoleList()[0].GetDomainCenter().Y.ToString(); for (int i=1;i< m_pStage.GetHoleList().Count;i++) { string sr = ""; string pra1 = ""; string pra2 = ""; if (m_pStage.GetHoleList()[i].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND) { sr= "圆形"; pra1 = m_pStage.GetHoleList()[i].GetDiameter().ToString(); pra2 = "0"; } else { sr= "方形"; pra1 = m_pStage.GetHoleList()[i].GetRectDomain().Width.ToString(); pra2 = m_pStage.GetHoleList()[i].GetRectDomain().Height.ToString(); } 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); } } private void radioButton_BoundaryCircle_Click(object sender, EventArgs e) { label8.Enabled = false; tBoundaryHeight.Enabled = false; tBoundaryHeight.Text = "0"; label7.Text = "半径:"; } private void radioButton_BoundarySquare_Click(object sender, EventArgs e) { label8.Enabled = true; tBoundaryHeight.Enabled = true; label7.Text = "宽度:"; } private void radioButton_StandardsampleCircle_Click(object sender, EventArgs e) { label9.Enabled = false; tStandardsampleHeight.Enabled = false; tStandardsampleHeight.Text = "0"; label10.Text = "半径:"; } private void radioButton__StandardsampleSqare_Click(object sender, EventArgs e) { label9.Enabled = true; tStandardsampleHeight.Enabled = true; label10.Text = "宽度:"; } private void dataGridView_Holes_CurrentCellChanged(object sender, EventArgs e) { if(dataGridView_Holes.CurrentRow==null) { return; } if(dataGridView_Holes.CurrentCell.ColumnIndex==1) { Rectangle rect = dataGridView_Holes.GetCellDisplayRectangle(dataGridView_Holes.CurrentCell.ColumnIndex, dataGridView_Holes.CurrentCell.RowIndex, false); string HoleShape = dataGridView_Holes.CurrentCell.Value.ToString(); cmb_Temp.Left = rect.Left; cmb_Temp.Top = rect.Top; cmb_Temp.Width = rect.Width; cmb_Temp.SelectedIndex = 0; cmb_Temp.Visible = true; } else { cmb_Temp.Visible = false; } } void cmb_Temp_SelectedIndexChanged(object sender ,EventArgs e) { if (dataGridView_Holes.CurrentRow == null) { return; } if (((ComboBox)sender).SelectedIndex == 0) { dataGridView_Holes.CurrentCell.Value = "圆形"; dataGridView_Holes.CurrentRow.Cells[5].Value = 0; } else { dataGridView_Holes.CurrentCell.Value = "方形"; dataGridView_Holes.CurrentRow.Cells[5].Value = ""; } } private void dataGridView_Holes_Scroll(object sender, ScrollEventArgs e) { this.cmb_Temp.Visible = false; } private void button_Generate_Click(object sender, EventArgs e) { if (!CheckParams()) { this.button_Ok.Enabled = false; MessageBox.Show("Please check Params!"); return; } CSEMStageData a_pCSEMStageData = new CSEMStageData(); //获取配置文件中 StageData 内容 COTSDefaultParam m_DefaultParam = new COTSDefaultParam(); m_DefaultParam.LoadInfoFromProgMgrFile(); a_pCSEMStageData = m_DefaultParam.GetStageDataParam(); m_pStage = new CStage(); m_pStage.SetName(tStageName.Text); // boundary string strValue = ""; if(radioButton_BoundaryCircle.Checked) { strValue += "0"; tBoundaryHeight.Text="0"; } else { strValue += "1"; } strValue += "," + tBoundaryX.Text+","+tBoundaryY.Text+","+tBoundaryWide.Text+","+ tBoundaryHeight.Text; CDomain pBoundary = stageDisplayHelp.GetDomain(strValue); // STD strValue = ""; if(radioButton_StandardsampleCircle.Checked) { strValue += "0"; tStandardsampleHeight.Text = "0"; } else { strValue += "1"; } strValue += "," + tStandardsampleX.Text + "," + tStandardsampleY.Text + "," + tStandardsampleWide.Text + "," + tStandardsampleHeight.Text; CDomain pSTD = stageDisplayHelp.GetDomain(strValue); // coordinate system CStageParam.COORDINATE_SYSTEM_SETTING nCoodrSysSetting = CStageParam.COORDINATE_SYSTEM_SETTING.INVALID; if(radioButton_OTS.Checked) { nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)0; } else { nCoodrSysSetting = (CStageParam.COORDINATE_SYSTEM_SETTING)1; } // Holes list List listHoles = new List(); for(int i=0;i listStageHoles = new List(); foreach (var pHole in listHoles) { if (!pBoundary.DomainInDomain(pHole)) { // this hole is over the boundary, jump over continue; } else if (pSTD.IntersectDomain(pHole)) { // this hole has common part with STD, jump over continue; } bool bHasCommonPart = false; foreach (var pStageHole in listStageHoles) { if (pStageHole.IntersectDomain(pHole)) { // this hole has common part with a hole already on the stage bHasCommonPart = true; break; } } if (bHasCommonPart) { // this hole has common part with a hole already on the stage, jump over continue; } // the hole is ok, add it into stage holes list listStageHoles.Add(pHole); } if (listStageHoles.Count == 0) { // no hole at all return ; } // the stage is in SEM coordinate system, convert all components to OTS system if (nCoodrSysSetting == CStageParam.COORDINATE_SYSTEM_SETTING.SEM) { if (!a_pCSEMStageData.ConverSEMToOTSSystem(pBoundary, pSTD, listStageHoles)) { return ; } } m_pStage.SetBoundary(pBoundary); m_pStage.SetSTD(pSTD); m_pStage.SetHoleList(listStageHoles, true); DrawStage(); this.button_Ok.Enabled = true; } public void DrawStage() { Rectangle rc = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size); Rectangle re = new Rectangle(m_ctrlStagePicture.Location, m_ctrlStagePicture.Size); int pWnd = otsdataconst.IDC_PIC_STAGE; int nWidth = (int)rc.Width; int nHeight = (int)rc.Height; Object pDC = new Object(); bool DeleteObject = false; //paint the DC with white Brush pOldBrush = new SolidBrush(Color.FromArgb(50, Color.White)); m_ctrlStagePicture.Refresh(); //Image img = (Image)new Bitmap(m_ctrlStagePicture.Width, m_ctrlStagePicture.Height); //Graphics graphics = m_ctrlStagePicture.CreateGraphics();// Graphics.FromImage(img); //graphics.FillRectangle(new SolidBrush(Color.Beige), re); pDC = m_ctrlStagePicture.CreateGraphics(); //消除锯齿 ((Graphics)pDC).SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择 ((Graphics)pDC).InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量 ((Graphics)pDC).CompositingQuality = CompositingQuality.HighQuality;//再加一点 //get stage information CDomain pBoundery = m_pStage.GetBoundary();// GetBoundary(); System.Drawing.Rectangle BounderyRect = pBoundery.GetDomainRect(); int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 ) int nBounderyHeight = (int)(BounderyRect.Height); double PixSize = 0; double coordinateSystemEndpoint = 0; if (nBounderyWidth > nBounderyHeight) { PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2)); coordinateSystemEndpoint = nBounderyWidth/2; } else { PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2)); coordinateSystemEndpoint = nBounderyHeight/2; } //draw boundery Brush pLTGrayBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); stageDisplayHelp.DrawStageBoundery(m_pStage, nWidth, nHeight, pDC, PixSize); ////draw STD //Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ; //DrawStageSTD(m_pStage[m_nListBoxStageListIndex], nWidth, nHeight, pDC, PixSize); ////draw holes //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ; stageDisplayHelp.DrawStageHole(m_pStage, nWidth, nHeight, pDC, PixSize); // draw ratio stageDisplayHelp.DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc); stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpoint); pLTGrayBrush.Dispose(); //pBlackBrush.Dispose(); //pWriteBrush.Dispose(); //graphics.Dispose(); //((Graphics)pDC).Dispose(); pOldBrush.Dispose(); } private void button_Ok_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } private void button_AddHole_Click(object sender, EventArgs e) { dataGridView_Holes.Rows.Add("1", "圆形", -4250, -16000, 12000, 0); } private void button_DelHole_Click(object sender, EventArgs e) { if(dataGridView_Holes.Rows.Count<1) { return; } int index = dataGridView_Holes.CurrentCell.RowIndex; dataGridView_Holes.Rows.RemoveAt(index); } bool CheckParams() { double dout; if (!double.TryParse(tBoundaryX.Text,out dout)) { return false; } if (!double.TryParse(tBoundaryY.Text, out dout)) { return false; } if (!double.TryParse(tBoundaryWide.Text, out dout)) { return false; } if (!double.TryParse(tBoundaryHeight.Text, out dout)) { return false; } if (!double.TryParse(tStandardsampleX.Text, out dout)) { return false; } if (!double.TryParse(tStandardsampleY.Text, out dout)) { return false; } if (!double.TryParse(tStandardsampleWide.Text, out dout)) { return false; } if (!double.TryParse(tStandardsampleHeight.Text, out dout)) { return false; } for (int i=0;i