/// <summary> /// 转换重心剪裁对象为SyswareDataObejct /// </summary> /// <param name="cpdList"></param> /// <returns></returns> private static List <SyswareDataObject> transFormCoreEnvelopeCutToDataObject(IList cpdList) { List <SyswareDataObject> sdoList = new List <SyswareDataObject>(); foreach (object o in cpdList) { CorePointData cpd = o as CorePointData; SyswareDataObject nSdo = new SyswareDataObject(); nSdo.name = cpd.pointName; SyswareDataObject xSdo = new SyswareDataObject(); xSdo.name = "横坐标"; xSdo.value = Math.Round(Convert.ToDouble(cpd.pointXValue), 6).ToString(); xSdo.unit = "Millimeter"; nSdo.children.Add(xSdo); SyswareDataObject ySdo = new SyswareDataObject(); ySdo.name = "纵坐标"; ySdo.value = Math.Round(Convert.ToDouble(cpd.pointYValue), 6).ToString(); ySdo.unit = "Kilogram"; nSdo.children.Add(ySdo); sdoList.Add(nSdo); } return(sdoList); }
public static CorePointExt corePointDataToCorePoinExt(CorePointData cpd) { CorePointExt cpe = new CorePointExt(); var cpdType = typeof(CorePointData); foreach (var propertie in cpdType.GetProperties()) { propertie.SetValue(cpe, propertie.GetValue(cpd, null), null); } return(cpe); }
/// <summary> /// 添加节点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddNode_Click(object sender, EventArgs e) { string strPtName = txtPtName.Text; string strErroInfo = PageVerificationInfo(); if (strErroInfo != string.Empty) { XLog.Write(strErroInfo); return; } else { bool IsExit = false; if (lstCorePointData != null && lstCorePointData.Count > 0) { foreach (CorePointData data in lstCorePointData) { if (data.pointName == strPtName) { XLog.Write("坐标点名称:" + strPtName + "已存在"); IsExit = true; return; } } } if (IsExit == false) { if (lstCorePointData == null) { lstCorePointData = new List <CorePointData>(); } CorePointData pt = new CorePointData(); pt.pointName = strPtName; lstCorePointData.Add(pt); } BindTreeList(lstCorePointData); } }
/// <summary> /// 获取从字符串转换成重心数据List /// </summary> /// <param name="str"></param> /// <returns></returns> private List<CorePointData> GetStringToListCorePointData(string strCoreEnvelope) { List<CorePointData> lstCorePt = null; if (strCoreEnvelope != null && strCoreEnvelope != string.Empty) { lstCorePt = new List<CorePointData>(); string[] strArray = strCoreEnvelope.Split('|'); string strNodeName = string.Empty; foreach (string strCore in strArray) { if (strCore != string.Empty) { int index = strCore.IndexOf(":"); strNodeName = strCore.Substring(0, index); string[] strCoreArray = strCore.Split('、'); CorePointData data = new CorePointData(); data.pointName = strNodeName; data.pointXValue = Convert.ToDouble(strCoreArray[2]); data.pointYValue = Convert.ToDouble(strCoreArray[3]); lstCorePt.Add(data); } } } return lstCorePt; }
private List<CorePointData> GetExcelListCorePointData(string strFilePath) { List<CorePointData> lstCorePtData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstCorePtData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; //列标题重复 table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { lstCorePtData = new List<CorePointData>(); for (int i = 0; i < table.Rows.Count; i++) { CorePointData pt = new CorePointData(); pt.pointName = table.Rows[i][0].ToString(); pt.pointXValue = Convert.ToDouble(table.Rows[i][3].ToString()); pt.pointYValue = Convert.ToDouble(table.Rows[i][4].ToString()); lstCorePtData.Add(pt); } } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return lstCorePtData; }
private List<CorePointData> GetCurrentCorePoint() { List<CorePointData> lstCorePt = null; if (gridCoreEnvelope.Rows.Count > 0) { lstCorePt = new List<CorePointData>(); for (int i = 1; i < gridCoreEnvelope.ColumnCount; i++) { CorePointData pt = new CorePointData(); pt.pointName = gridCoreEnvelope.Columns[i].HeaderText; pt.pointXValue = Convert.ToDouble(gridCoreEnvelope.Rows[0].Cells[i].Value); pt.pointYValue = Convert.ToDouble(gridCoreEnvelope.Rows[1].Cells[i].Value); lstCorePt.Add(pt); } } return lstCorePt; }
private List<CorePointData> GetXmlListCorePointData(string strFilePath) { List<CorePointData> lstCorePointData = null; try { if (!File.Exists(strFilePath)) { return lstCorePointData; } string path = string.Empty; XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strFilePath); //重量列表 path = "重心数据/重心坐标列表"; node = doc.SelectSingleNode(path); XmlNodeList nodeList = node.ChildNodes; if (nodeList.Count > 0) { lstCorePointData = new List<CorePointData>(); foreach (XmlNode childNode in nodeList) { CorePointData pt = new CorePointData(); pt.pointName = childNode.ChildNodes[0].InnerText; pt.pointXValue = Convert.ToDouble(childNode.ChildNodes[3].InnerText); pt.pointYValue = Convert.ToDouble(childNode.ChildNodes[4].InnerText); lstCorePointData.Add(pt); } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return lstCorePointData; }
public static CorePointExt corePointDataToCorePoinExt(CorePointData cpd) { CorePointExt cpe = new CorePointExt(); var cpdType = typeof(CorePointData); foreach (var propertie in cpdType.GetProperties()) { propertie.SetValue(cpe, propertie.GetValue(cpd, null), null); } return cpe; }
private void buttonImportFromDesignData_Click(object sender, EventArgs e) { //此处加入导入数据代码,把包线存入 data.lstBasicCoreEnvelope if (mainForm.designProjectData.lstCoreEnvelopeDesign == null || mainForm.designProjectData.lstCoreEnvelopeDesign.Count == 0) { MessageBox.Show("当前重心包线没有数据"); return; } //Todo SelectCoreCutForm cutForm = new SelectCoreCutForm(this, mainForm, "CoreEnvelope"); cutForm.ShowDialog(); if (coreEnvelopeDesign != null) { if (coreEnvelopeDesign.FormulaList != null && coreEnvelopeDesign.FormulaList.Count > 0) { if (data.lstBasicCoreEnvelope!=null&&data.lstBasicCoreEnvelope.Count>0) { data.lstBasicCoreEnvelope.Clear(); } foreach (XCommon.NodeFormula formula in coreEnvelopeDesign.FormulaList) { if (data.lstBasicCoreEnvelope == null) { data.lstBasicCoreEnvelope = new List<CorePointData>(); } CorePointData pt = new CorePointData(); pt.pointName = formula.NodeName; pt.pointXValue = Math.Round(formula.XFormula.Value, 6); pt.pointYValue = Math.Round(formula.YFormula.Value, 6); data.lstBasicCoreEnvelope.Add(pt); } XCommon.XLog.Write("成功从当前设计数据导入\"" + coreEnvelopeDesign.DataName + "\"数据!"); } else { return; } } else { return; } //成功后,执行以下代码 UpdateCoreEnvelopeData(); 剪裁ToolStripMenuItem.Enabled = true; }
private void buttonImportFromCutData_Click(object sender, EventArgs e) { //此处加入导入数据代码,把包线存入 data.lstBasicCoreEnvelope //Todo if (mainForm.designProjectData.lstCutResultData == null || mainForm.designProjectData.lstCutResultData.Count == 0) { MessageBox.Show("当前重心包线剪裁没有数据"); return; } SelectCoreCutForm cutForm = new SelectCoreCutForm(this, mainForm, "CoreCut"); cutForm.ShowDialog(); if (coreEnvelopeCut != null && coreEnvelopeCut != null && coreEnvelopeCut.lstBasicCoreEnvelope.Count > 0 && coreEnvelopeCut.lstCutEnvelopeCore.Count == 0) { if (data.lstBasicCoreEnvelope == null) { data.lstBasicCoreEnvelope = new List<CorePointData>(); } data.lstBasicCoreEnvelope.Clear(); foreach (CorePointData pt in coreEnvelopeCut.lstBasicCoreEnvelope) { CorePointData core = new CorePointData(); core.pointName = pt.pointName; core.pointXValue = pt.pointXValue; core.pointYValue = pt.pointYValue; data.lstBasicCoreEnvelope.Add(core); } XCommon.XLog.Write("当前剪裁结果无剪裁数据,导入\"" + coreEnvelopeCut.cutResultName + "\"基准数据!"); } if (coreEnvelopeCut != null && coreEnvelopeCut != null && coreEnvelopeCut.lstBasicCoreEnvelope.Count > 0 && coreEnvelopeCut.lstCutEnvelopeCore.Count > 0) { if (data.lstBasicCoreEnvelope == null) { data.lstBasicCoreEnvelope = new List<CorePointData>(); } data.lstBasicCoreEnvelope.Clear(); foreach (CorePointData pt in coreEnvelopeCut.lstCutEnvelopeCore) { CorePointData core = new CorePointData(); core.pointName = pt.pointName; core.pointXValue = pt.pointXValue; core.pointYValue = pt.pointYValue; data.lstBasicCoreEnvelope.Add(core); } XCommon.XLog.Write("成功从当前剪裁数据导入\"" + coreEnvelopeCut.cutResultName + "\"数据!"); } //成功后,执行以下代码 UpdateCoreEnvelopeData(); 剪裁ToolStripMenuItem.Enabled = true; }
private bool ImportExcelToPointList(List<CorePointData> ptlst, string strfilename) { ptlst.Clear(); Excel.Application app = new Excel.ApplicationClass(); try { Object missing = System.Reflection.Missing.Value; app.Visible = false; Excel.Workbook wBook = app.Workbooks.Open(strfilename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet; if (wSheet.Rows.Count > 1) { for (int i = 2; i <= wSheet.Rows.Count; ++i) { string cellid = "A" + i.ToString(); Excel.Range DataCell = wSheet.get_Range(cellid, cellid); string ParaName = (string)DataCell.Text; DataCell = DataCell.Next.Next.Next; if ((string)DataCell.Text == "") { break; } ParaName = ParaName.Trim(); CorePointData node = new CorePointData(ParaName); node.pointXValue = (double)DataCell.Value2; node.pointYValue = (double)DataCell.Next.Value2; ptlst.Add(node); } } app.Quit(); app = null; XCommon.XLog.Write("成功从文件\"" + strfilename + "\"导入数据!"); } catch (Exception err) { MessageBox.Show("导入Excel出错!错误原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } return true; }
private List<int> GetXmlListCoreEvaluationData(string strFilePath) { lstCoreEvaluationData = null; List<int> lstCoreEvaluation = null; if (!File.Exists(strFilePath)) { return lstCoreEvaluation; } string path = string.Empty; XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strFilePath); path = "重心离散点评估数据/离散点评估数据列表"; node = doc.SelectSingleNode(path); if (node == null) { return lstCoreEvaluation; } XmlNodeList nodeList = node.ChildNodes; if (nodeList.Count > 0) { lstCoreEvaluationData = new List<CorePointData>(); lstCoreEvaluation = new List<int>(); int t = -1; foreach (XmlNode childNode in nodeList) { CorePointData pt = new CorePointData(); pt.pointName = childNode.ChildNodes[0].InnerText; pt.pointXValue = Convert.ToDouble(childNode.ChildNodes[3].InnerText); pt.pointYValue = Convert.ToDouble(childNode.ChildNodes[4].InnerText); t = Convert.ToInt32(childNode.ChildNodes[5].InnerText); lstCoreEvaluation.Add(t); lstCoreEvaluationData.Add(pt); } } return lstCoreEvaluation; }
private bool GetLeftRightEnvelope() { lstLeftEnvelope = null; lstRightEnvelope = null; if (data.lstBasicCoreEnvelope.Count == 0) { MessageBox.Show("没有输入基础包线数据!"); return false; } if (data.lstFuelCore.Count == 0) { MessageBox.Show("没有输入燃油数据!"); return false; } List<CorePointData> originleft = new List<CorePointData>(data.lstBasicCoreEnvelope); int ishiftbase = 0; double fminweight = originleft[0].pointYValue; for (int i = 1; i < originleft.Count; ++i) { if ((fminweight > originleft[i].pointYValue) || (Math.Abs(fminweight - originleft[i].pointYValue) < 1e-5) && (originleft[ishiftbase].pointXValue > originleft[i].pointXValue)) { fminweight = originleft[i].pointYValue; ishiftbase = i; } } // if (ishiftbase != 0) { for (int i = 0; i < ishiftbase; ++i) { originleft.Add(originleft[i]); } originleft.RemoveRange(0, ishiftbase); } if (Math.Abs(fminweight - originleft[originleft.Count - 1].pointYValue) < 1e-5) { for (int i = 2; i < originleft.Count - 1; ++i) { if (Math.Abs(fminweight - originleft[i].pointYValue) < 1e-5) { originleft.RemoveRange(i + 1, originleft.Count - i - 1); break; } } } else { originleft.Add(originleft[0]); } int nsmax = 1; int nemax = 1; double fmaxweight = originleft[1].pointYValue; for (int i = 2; i < originleft.Count; ++i) { if (fmaxweight < originleft[i].pointYValue) { fmaxweight = originleft[i].pointYValue; nsmax = i; nemax = i; } else if ((Math.Abs(fmaxweight - originleft[i].pointYValue) < 1e-5) && (originleft[nemax].pointXValue < originleft[i].pointXValue)) { nemax = i; } } List<CorePointData> originright = new List<CorePointData>(originleft); originright.RemoveRange(0, nemax); originleft.RemoveRange(nsmax + 1, originleft.Count - nsmax - 1); // lstLeftEnvelope = new List<CorePointData>(); lstRightEnvelope = new List<CorePointData>(); double fMinWeight = originleft[0].pointYValue; CorePointData addionalfuel = new CorePointData(fuellist[fuellist.Count - 1].pointXValue, fuellist[fuellist.Count - 1].pointYValue + 0.1); fuellist.Add(addionalfuel); foreach (CorePointData pt in originleft) { lstLeftEnvelope.Add(new CorePointData(pt)); } foreach (CorePointData pt in originright) { lstRightEnvelope.Add(new CorePointData(pt)); } foreach (CorePointData pt in lstLeftEnvelope) { if (pt.pointYValue > fBaseWeight) { for (int i = 1; i < fuellist.Count; ++i) { if (fuellist[i].pointYValue > pt.pointYValue) { double dy1 = pt.pointYValue - fuellist[i - 1].pointYValue; double dy2 = fuellist[i].pointYValue - pt.pointYValue; double fx = (fuellist[i - 1].pointXValue * dy2 + fuellist[i].pointXValue * dy1) / (dy1 + dy2); double newfx = (pt.pointXValue * fBaseWeight + fx * (pt.pointYValue - fBaseWeight)) / pt.pointYValue; if (pt.pointXValue < newfx) { pt.pointXValue = newfx; } break; } } } } foreach (CorePointData pt in lstRightEnvelope) { if (pt.pointYValue > fBaseWeight) { for (int i = 1; i < fuellist.Count; ++i) { if (fuellist[i].pointYValue > pt.pointYValue) { double dy1 = pt.pointYValue - fuellist[i - 1].pointYValue; double dy2 = fuellist[i].pointYValue - pt.pointYValue; double fx = (fuellist[i - 1].pointXValue * dy2 + fuellist[i].pointXValue * dy1) / (dy1 + dy2); double newfx = (pt.pointXValue * fBaseWeight + fx * (pt.pointYValue - fBaseWeight)) / pt.pointYValue; if (pt.pointXValue > newfx) { pt.pointXValue = newfx; } break; } } } } fuellist.RemoveAt(fuellist.Count - 1); // int nsFuelPt = 0; for (; nsFuelPt < fuellist.Count; ++nsFuelPt) { if (fuellist[nsFuelPt].pointYValue > fMinWeight) { break; } } // for (int i = nsFuelPt; i < fuellist.Count - 1; ++i) { double fxs = 0; double fxe = 0; CorePointData pt1 = new CorePointData(fuellist[i]); CorePointData pt2 = new CorePointData(fuellist[i]); for (int j = 1; j < originleft.Count; ++j) { if (originleft[j].pointYValue > pt1.pointYValue) { double dy1 = pt1.pointYValue - originleft[j - 1].pointYValue; double dy2 = originleft[j].pointYValue - pt1.pointYValue; fxs = (originleft[j - 1].pointXValue * dy2 + originleft[j].pointXValue * dy1) / (dy1 + dy2); if (fxs < pt1.pointXValue) { pt1.pointXValue = (pt1.pointXValue * (pt1.pointYValue - fBaseWeight) + fxs * fBaseWeight) / pt1.pointYValue; } else { pt1.pointXValue = fxs; } break; } } for (int j = originright.Count - 2; j >= 0; --j) { if (originright[j].pointYValue > pt2.pointYValue) { double dy1 = pt2.pointYValue - originright[j + 1].pointYValue; double dy2 = originright[j].pointYValue - pt2.pointYValue; fxe = (originright[j + 1].pointXValue * dy2 + originright[j].pointXValue * dy1) / (dy1 + dy2); if (fxe > pt2.pointXValue) { pt2.pointXValue = (pt2.pointXValue * (pt2.pointYValue - fBaseWeight) + fxe * fBaseWeight) / pt2.pointYValue; } else { pt2.pointXValue = fxe; } break; } } // for (int k = 0; k < lstLeftEnvelope.Count; ++k) { if (pt1.pointYValue < lstLeftEnvelope[k].pointYValue) { lstLeftEnvelope.Insert(k, pt1); break; } } for (int k = lstRightEnvelope.Count - 1; k >= 0; --k) { if (pt2.pointYValue < lstRightEnvelope[k].pointYValue) { lstRightEnvelope.Insert(k + 1, pt2); break; } } } lstRightEnvelope.Reverse(); return true; }
/// <summary> /// 获取离散评估数据 /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> private List<int> GetExcelCoreEvaluationData(string strFilePath) { lstCoreEvaluationData = null; //评估数据 List<int> lstCoreEvaluation = null; if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstCoreEvaluation; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; //列标题重复 table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { lstCoreEvaluationData = new List<CorePointData>(); lstCoreEvaluation = new List<int>(); int t = -1; for (int i = 0; i < table.Rows.Count; i++) { CorePointData pt = new CorePointData(); pt.pointName = table.Rows[i][0].ToString(); pt.pointXValue = Convert.ToDouble(table.Rows[i][3].ToString()); pt.pointYValue = Convert.ToDouble(table.Rows[i][4].ToString()); t = Convert.ToInt32(table.Rows[i][5].ToString()); lstCoreEvaluation.Add(t); lstCoreEvaluationData.Add(pt); } } } return lstCoreEvaluation; }
/// <summary> /// 添加节点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddNode_Click(object sender, EventArgs e) { string strPtName = txtPtName.Text; string strErroInfo = PageVerificationInfo(); if (strErroInfo != string.Empty) { XLog.Write(strErroInfo); return; } else { bool IsExit = false; if (lstCorePointData != null && lstCorePointData.Count > 0) { foreach (CorePointData data in lstCorePointData) { if (data.pointName == strPtName) { XLog.Write("坐标点名称:" + strPtName + "已存在"); IsExit = true; return; } } } if (IsExit == false) { if (lstCorePointData == null) { lstCorePointData = new List<CorePointData>(); } CorePointData pt = new CorePointData(); pt.pointName = strPtName; lstCorePointData.Add(pt); } BindTreeList(lstCorePointData); } }