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 Stage; StageDisplayHelp stageDisplayHelp; OTSCommon.Language lan; System.Collections.Hashtable hashtable; List StageNames = new List(); string StageN = ""; public DlgStageEdit(List a_StageNames) { InitializeComponent(); StageNames = a_StageNames; } public DlgStageEdit(CStage a_Stage,List a_StageNames) { InitializeComponent(); Stage = a_Stage; StageNames = a_StageNames; } ComboBox cmb_Temp = new ComboBox(); private void DlgStageEdit_Load(object sender, EventArgs e) { lan = new OTSCommon.Language(this); hashtable = lan.GetNameTable(this.Name); radioButton_OTS.Checked = true; radioButton_BoundarySquare.Checked = true; radioButton_StandardsampleSqare.Checked = true; string str = hashtable["str1"].ToString(); dataGridView_Holes.Columns.Add("HoleName", str); str = hashtable["str2"].ToString(); dataGridView_Holes.Columns.Add("HoleShape", str); str = hashtable["str3"].ToString(); dataGridView_Holes.Columns.Add("CenterCoordinatesX", str); str = hashtable["str4"].ToString(); dataGridView_Holes.Columns.Add("CenterCoordinatesY", str); str = hashtable["str5"].ToString(); dataGridView_Holes.Columns.Add("Param1", str); str = hashtable["str6"].ToString(); dataGridView_Holes.Columns.Add("Param2", str); str = hashtable["str7"].ToString(); dataGridView_Holes.Rows.Add("1", str, -4250, -16000, 12000, 0); cmb_Temp.Visible = false; cmb_Temp.Items.Add(str); str = hashtable["str8"].ToString(); cmb_Temp.Items.Add(str); cmb_Temp.SelectedIndexChanged += new EventHandler(cmb_Temp_SelectedIndexChanged); dataGridView_Holes.Controls.Add(cmb_Temp); stageDisplayHelp = new StageDisplayHelp(); if(Stage!=null) { LoadStageData(Stage); } else { btn_new.Visible = false; } SetHelp(); StageNames.Remove(tStageName.Text); } void SetHelp() { string str = hashtable["str9"].ToString(); 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 = Stage.GetName(); if(Stage.GetBoundary().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND) { radioButton_BoundaryCircle.Checked = true; tBoundaryWide.Text = Stage.GetBoundary().GetDiameter().ToString(); tBoundaryHeight.Enabled = false; tBoundaryHeight.Text = "0"; } else { radioButton_BoundarySquare.Checked = true; tBoundaryWide.Text = Stage.GetBoundary().GetRectDomain().Width.ToString(); tBoundaryHeight.Enabled = true; tBoundaryHeight.Text = Stage.GetBoundary().GetRectDomain().Height.ToString(); } tBoundaryX.Text= Stage.GetBoundary().GetDomainCenter().X.ToString(); tBoundaryY.Text = Stage.GetBoundary().GetDomainCenter().Y.ToString(); if(Stage.GetSTD().GetShape()== otsdataconst.DOMAIN_SHAPE.ROUND) { radioButton_StandardsampleCircle.Checked = true; tStandardsampleHeight.Enabled = false; tStandardsampleWide.Text = Stage.GetSTD().GetDiameter().ToString(); } else { radioButton_StandardsampleSqare.Checked = true; tStandardsampleHeight.Enabled =true; tStandardsampleWide.Text = Stage.GetSTD().GetRectDomain().Width.ToString(); } tStandardsampleX.Text = Stage.GetSTD().GetDomainCenter().X.ToString(); tStandardsampleY.Text = Stage.GetSTD().GetDomainCenter().Y.ToString(); tStandardsampleHeight.Text = Stage.GetSTD().GetRectDomain().Height.ToString(); dataGridView_Holes.Rows[0].Cells[0].Value = Stage.GetHoleList()[0].GetName(); if (Stage.GetHoleList()[0].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND) { dataGridView_Holes.Rows[0].Cells[1].Value = "圆形"; dataGridView_Holes.Rows[0].Cells[4].Value = Stage.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 = Stage.GetHoleList()[0].GetRectDomain().Width.ToString(); dataGridView_Holes.Rows[0].Cells[5].Value = Stage.GetHoleList()[0].GetRectDomain().Height.ToString(); } dataGridView_Holes.Rows[0].Cells[2].Value = Stage.GetHoleList()[0].GetDomainCenter().X.ToString(); dataGridView_Holes.Rows[0].Cells[3].Value = Stage.GetHoleList()[0].GetDomainCenter().Y.ToString(); for (int i=1;i< Stage.GetHoleList().Count;i++) { string sr = ""; string pra1 = ""; string pra2 = ""; if (Stage.GetHoleList()[i].GetShape() == otsdataconst.DOMAIN_SHAPE.ROUND) { sr= "圆形"; pra1 = Stage.GetHoleList()[i].GetDiameter().ToString(); pra2 = "0"; } else { sr= "方形"; pra1 = Stage.GetHoleList()[i].GetRectDomain().Width.ToString(); pra2 = Stage.GetHoleList()[i].GetRectDomain().Height.ToString(); } dataGridView_Holes.Rows.Add(Stage.GetHoleList()[i].GetName(), sr, Stage.GetHoleList()[i].GetDomainCenter().X.ToString(), Stage.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; } bool CheckAndSetStage() { if(StageNames.Contains(StageN)) { MessageBox.Show("Already exist " + tStageName.Text.Trim() + "!", "Error"); return false; } if (!CheckParams()) { //this.button_Ok.Enabled = false; MessageBox.Show("Please check Params!"); return false; } if (tBoundaryWide.Text == "1" || tBoundaryHeight.Text == "1" || tStandardsampleWide.Text == "1" || tStandardsampleHeight.Text == "1") { //this.button_Ok.Enabled = false; MessageBox.Show("The length value cannot be 1!"); return false; } for (int i = 0; i < dataGridView_Holes.Rows.Count; i++) { for (int j = 4; j <= 5; j++) { if (dataGridView_Holes.Rows[i].Cells[j].Value.ToString() == "1") { //this.button_Ok.Enabled = false; MessageBox.Show("The length value cannot be 1!"); return false; } } } CSEMStageData a_pCSEMStageData = new CSEMStageData(); //获取配置文件中 StageData 内容 COTSDefaultParam m_DefaultParam = new COTSDefaultParam(); m_DefaultParam.LoadInfoFromProgMgrFile(); a_pCSEMStageData = m_DefaultParam.GetStageDataParam(); Stage = new CStage(); Stage.SetName(StageN); // 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)) { MessageBox.Show(pHole.GetName() + "is over the boundary, jump over!"); continue; } //else if (pSTD.IntersectDomain(pHole)) //{ // MessageBox.Show(pHole.GetName() + " has common part with STD, jump over!"); // continue; //} bool bHasCommonPart = false; foreach (var pStageHole in listStageHoles) { if (pStageHole.IntersectDomain(pHole)) { MessageBox.Show(pHole.GetName() + " 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 false; } // 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 false; } } Stage.SetBoundary(pBoundary); Stage.SetSTD(pSTD); Stage.SetHoleList(listStageHoles, true); return true; } private void button_Generate_Click(object sender, EventArgs e) { if(!CheckAndSetStage()) { return; } DrawStage(); btn_reght90.Enabled = true; btn_left90.Enabled = true; this.button_Ok.Enabled = true; btn_new.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 = Stage.GetBoundary();// GetBoundary(); System.Drawing.RectangleF BounderyRect = pBoundery.GetDomainRect(); int nBounderyWidth = (int)(BounderyRect.Width);//um,,pixle is (nWidth - PIC_EDGE * 2 ) int nBounderyHeight = 0; if (pBoundery.GetShape() == otsdataconst.DOMAIN_SHAPE.RECTANGLE) {nBounderyHeight = (int)(BounderyRect.Height);} else { nBounderyHeight = (int)(BounderyRect.Width); } 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(Stage, nWidth, nHeight, pDC, PixSize); //draw STD Brush pBlackBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); stageDisplayHelp.DrawStageSTD(Stage, nWidth, nHeight, pDC, PixSize); ////draw holes //Brush pWriteBrush = new SolidBrush(Color.FromArgb(255, 0, 0)); ; stageDisplayHelp.DrawStageHole(Stage, nWidth, nHeight, pDC, PixSize); // draw ratio stageDisplayHelp.DrawRatio(nBounderyWidth, nWidth, nHeight, pDC, (IntPtr)pWnd, rc); if (button_Coordinate.Text == "坐标系关闭") { double coordinateSystemEndpointX = nBounderyWidth / 2; double coordinateSystemEndpointY = nBounderyHeight / 2; stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpointX, coordinateSystemEndpointY); } pLTGrayBrush.Dispose(); //pBlackBrush.Dispose(); //pWriteBrush.Dispose(); //graphics.Dispose(); //((Graphics)pDC).Dispose(); pOldBrush.Dispose(); } private void button_Ok_Click(object sender, EventArgs e) { if (!CheckAndSetStage()) { return; } 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 nBounderyHeight) { PixSize = (long)((double)nBounderyWidth / (double)(nWidth - StageDisplayHelp.PIC_EDGE * 2)); } else { PixSize = (long)((double)nBounderyHeight / (double)(nHeight - StageDisplayHelp.PIC_EDGE * 2)); } stageDisplayHelp.DrawXY(pDC, m_ctrlStagePicture.Width, m_ctrlStagePicture.Height, PixSize, coordinateSystemEndpointX,coordinateSystemEndpointY); button_Coordinate.Text = "坐标系关闭"; } else { button_Coordinate.Text = "坐标系显示"; if(Stage != null) { DrawStage(); } else { m_ctrlStagePicture.Refresh(); } } } private void btn_reght90_Click(object sender, EventArgs e) { double it = 0; for (int i = 0; i < dataGridView_Holes.Rows.Count; i++) { it = Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[3].Value); dataGridView_Holes.Rows[i].Cells[3].Value= -Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[2].Value); dataGridView_Holes.Rows[i].Cells[2].Value = it; } dataGridView_Holes.Refresh(); button_Generate_Click(null, null); } private void btn_left90_Click(object sender, EventArgs e) { double it = 0; for (int i = 0; i < dataGridView_Holes.Rows.Count; i++) { it = -Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[3].Value); dataGridView_Holes.Rows[i].Cells[3].Value = Convert.ToDouble(dataGridView_Holes.Rows[i].Cells[2].Value); dataGridView_Holes.Rows[i].Cells[2].Value = it; } dataGridView_Holes.Refresh(); button_Generate_Click(null, null); } private void btn_new_Click(object sender, EventArgs e) { StageNameSaveAs stageNameSaveAs = new StageNameSaveAs(); DialogResult dialogResult = stageNameSaveAs.ShowDialog(); if (dialogResult == DialogResult.OK) { if (tStageName.Text == stageNameSaveAs.StageNamewhichSaveAs) { MessageBox.Show("Already exist " + tStageName.Text.Trim() + "!", "Error"); return; } StageN = stageNameSaveAs.StageNamewhichSaveAs; if (!CheckAndSetStage()) { return; } this.DialogResult = DialogResult.No; this.Close(); } } private void tStageName_TextChanged(object sender, EventArgs e) { StageN = tStageName.Text; } } }