/// <summary> /// 保存所有托盘对象参数到文件 /// </summary> /// <param name="strPath">文件名,以.ini结尾</param> /// <returns>返回保存状态</returns> public static bool SaveTrayFactory(string strPath) { var bResult = true; foreach (KeyValuePair <string, Tray> m_tray in TrayDictionary) { Tray tray = m_tray.Value; var strSection = m_tray.Key; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Id", tray.Type.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Name", tray.Name, strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Row", tray.Row.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Column", tray.Column.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "StartPose", tray.StartPose.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Direction", tray.Direction.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "ChangeLineType", tray.ChangeLineType.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "Empty", tray.Empty, strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "IsCalibration", tray.IsCalibration.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "RowXoffset", tray.RowXoffset.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "RowYoffset", tray.RowYoffset.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "ColumnXoffset", tray.ColumnXoffset.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "ColumnYoffset", tray.ColumnYoffset.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "BaseIndex", tray.BaseIndex.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "BasePosition", tray.BasePosition.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "RowIndex", tray.RowIndex.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "RowPosition", tray.RowPosition.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "ColumnIndex", tray.ColumnIndex.ToString(), strPath) != 0; bResult &= System.ToolKit.Helpers.IniHelper.WriteValue(strSection, "ColumnPosition", tray.ColumnPosition.ToString(), strPath) != 0; } return(bResult); }
public void TestTray_Load(object sender, EventArgs e) { //var i = 1; var Keys = TrayFactory.GetTrayDict.Keys; var count = Keys.Count; foreach (var key in Keys) { cmbId.Items.Add(key); } cmbStart.SelectedIndex = 0; cmbDirect.SelectedIndex = 0; cmbChangeLine.SelectedIndex = 0; tp = new TrayPanel(); tp.Dock = DockStyle.Fill; panel1.Controls.Add(tp); if (count > 0) { cmbId.SelectedIndex = 0; } else { return; } tray = TrayFactory.GetTrayFactory(cmbId.Text); tp.SetTrayObj(tray, Color.Gray); initControls(); chShow.Checked = true; timer1.Enabled = true; }
public void SetTrayObj(Tray tray, Color initColor) { t = tray; Row = t.Row; Col = t.Column; SetLayout(initColor); }
/// <summary> /// 设置或添加对象 /// </summary> /// <param name="key">托盘对应的字符串</param> /// <param name="tray">托盘对象</param> public static void SetTray(string key, Tray tray) { if (TrayDictionary.ContainsKey(key)) { TrayDictionary[key] = tray; } else { TrayDictionary.Add(key, tray); } }
private void btnCreate_Click(object sender, EventArgs e) { if (cmbId.Items.Count <= 0) { return; } cbUnregular1.Checked = false; cbUnregular2.Checked = false; chShow.Checked = false; tray = new Tray(cmbId.Text, txtName.Text, (int)nudRow.Value, (int)nudCol.Value); tp.SetTrayObj(tray, Color.Blue); }
private void btnSelect_Click(object sender, EventArgs e) { var cout = cmbId.Items.Count; if (cout <= 0) { return; } tray = TrayFactory.GetTrayFactory(cmbId.Text); tp.SetTrayObj(tray, Color.Gray); initControls(); chShow.Checked = true; }
/// <summary> /// 标定计算 /// </summary> /// <param name="key">键</param> /// <returns></returns> public static bool Calibration(string key) { Tray tray = TrayFactory.GetTrayFactory(key); if (tray == null) { throw new Exception("托盘不存在!"); } var retR12 = (tray.dic_Index[tray.RowIndex].Row - tray.dic_Index[tray.BaseIndex].Row) != 0; var retC12 = (tray.dic_Index[tray.RowIndex].Col - tray.dic_Index[tray.BaseIndex].Col) != 0; var retR13 = (tray.dic_Index[tray.ColumnIndex].Row - tray.dic_Index[tray.BaseIndex].Row) != 0; var retC13 = (tray.dic_Index[tray.ColumnIndex].Col - tray.dic_Index[tray.BaseIndex].Col) != 0; if ((retR12 == retR13) || (retC12 == retC13)) { throw new Exception("三点重合,或者三点再同一直线上!"); } if ((retR12 == retC12) || (retR13 == retC13)) { throw new Exception("三点无法形成直角坐标系,非有效点!"); } var iRow = 0; var iColumn = 0; double detaRowX, detaRowY, detaColX, detaColY; if (retR12 && !retR13) { iRow = tray.dic_Index[tray.RowIndex].Row - tray.dic_Index[tray.BaseIndex].Row; iColumn = tray.dic_Index[tray.ColumnIndex].Col - tray.dic_Index[tray.BaseIndex].Col; detaRowX = tray.RowPosition.X - tray.BasePosition.X; detaRowY = tray.RowPosition.Y - tray.BasePosition.Y; detaColX = tray.ColumnPosition.X - tray.BasePosition.X; detaColY = tray.ColumnPosition.Y - tray.BasePosition.Y; } else { iRow = tray.dic_Index[tray.ColumnIndex].Row - tray.dic_Index[tray.BaseIndex].Row; iColumn = tray.dic_Index[tray.RowIndex].Col - tray.dic_Index[tray.BaseIndex].Col; detaColX = tray.RowPosition.X - tray.BasePosition.X; detaColY = tray.RowPosition.Y - tray.BasePosition.Y; detaRowX = tray.ColumnPosition.X - tray.BasePosition.X; detaRowY = tray.ColumnPosition.Y - tray.BasePosition.Y; } tray.RowXoffset = detaRowX / iRow; tray.RowYoffset = detaRowY / iRow; tray.ColumnXoffset = detaColX / iColumn; tray.ColumnYoffset = detaColY / iColumn; tray.IsCalibration = true; return(true); }
/// <summary> /// 读取文件初始化对象 /// </summary> /// <param name="strPath"></param> public static void LoadTrayFactory(string strPath) { TrayDictionary.Clear(); var sectionList = System.ToolKit.Helpers.IniHelper.GetAllSectionNames(strPath); foreach (var section in sectionList) { var type = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Id", strPath, "1"); var strName = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Name", strPath, "托盘" + section); var Row = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Row", strPath, 10); var Column = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Column", strPath, 10); var strStart = System.ToolKit.Helpers.IniHelper.ReadValue(section, "StartPose", strPath, "左上角"); var strDirect = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Direction", strPath, "行"); var strChangeLineType = System.ToolKit.Helpers.IniHelper.ReadValue(section, "ChangeLineType", strPath, "Z"); var strEmpty = System.ToolKit.Helpers.IniHelper.ReadValue(section, "Empty", strPath, ""); var bIsCalibration = System.ToolKit.Helpers.IniHelper.ReadValue(section, "IsCalibration", strPath, false); var iRowXoffset = System.ToolKit.Helpers.IniHelper.ReadValue(section, "RowXoffset", strPath, 0.0); var iRowYoffset = System.ToolKit.Helpers.IniHelper.ReadValue(section, "RowYoffset", strPath, 0.0); var iColumnXoffset = System.ToolKit.Helpers.IniHelper.ReadValue(section, "ColumnXoffset", strPath, 0.0); var iColumnYoffset = System.ToolKit.Helpers.IniHelper.ReadValue(section, "ColumnYoffset", strPath, 0.0); var iBaseIndex = System.ToolKit.Helpers.IniHelper.ReadValue(section, "BaseIndex", strPath, 1); var iBasePosition = Point3D <double> .Parse(System.ToolKit.Helpers.IniHelper.ReadValue(section, "BasePosition", strPath, "0,0,0")); var iRowIndex = System.ToolKit.Helpers.IniHelper.ReadValue(section, "RowIndex", strPath, 1); var iRowPosition = Point3D <double> .Parse(System.ToolKit.Helpers.IniHelper.ReadValue(section, "RowPosition", strPath, "0,0,0")); var iColumnIndex = System.ToolKit.Helpers.IniHelper.ReadValue(section, "ColumnIndex", strPath, 1); var iColumnPosition = Point3D <double> .Parse(System.ToolKit.Helpers.IniHelper.ReadValue(section, "ColumnPosition", strPath, "0,0,0")); var tray = new Tray(type, strName, Row, Column) { IsCalibration = bIsCalibration, RowXoffset = iRowXoffset, RowYoffset = iRowYoffset, ColumnXoffset = iColumnXoffset, ColumnYoffset = iColumnYoffset, BaseIndex = iBaseIndex, BasePosition = iBasePosition, RowIndex = iRowIndex, RowPosition = iRowPosition, ColumnIndex = iColumnIndex, ColumnPosition = iColumnPosition }; tray.InitTray(strStart, strDirect, strChangeLineType, strEmpty); SetTray(section, tray); } }
private void btnAdd_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("是否新建托盘型号?", "新建托盘型号", MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return; } var strType = txtNewPlateType.Text.Trim(); if (strType == "") { MessageBox.Show("输入的字符为空!"); return; } if (!IsDigitOrNumber(strType)) { MessageBox.Show("输入的字符不是0-9,a-z,A-Z"); return; } var Keys = TrayFactory.GetTrayDict.Keys; var count = Keys.Count; foreach (var key in Keys) { if (strType == key) { MessageBox.Show("输入的型号已存在!"); return; } } var m_tray = new Tray(strType, "", 5, 5); TrayFactory.SetTray(strType, m_tray); cmbId.Items.Add(strType); cmbId.SelectedIndex = cmbId.Items.Count - 1; tray = TrayFactory.GetTrayFactory(cmbId.Text); tp.SetTrayObj(tray, Color.Gray); initControls(); chShow.Checked = true; }
private void btnDelete_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("是否删除当前托盘型号?", "删除托盘型号", MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return; } IniHelper.EraseSection(cmbId.Text, ConfigTrayName); cmbId.Items.Remove(cmbId.Text); TrayFactory.RemoveTray(cmbId.Text); if (cmbId.Items.Count <= 0) { return; } cmbId.SelectedIndex = 0; tray = TrayFactory.GetTrayFactory(cmbId.Text); tp.SetTrayObj(tray, Color.Gray); initControls(); chShow.Checked = true; }