123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
-
- using OTSCommon.Model;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using OTSIncAReportApp.OTSSampleReportInfo;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static OTSIncAReportApp.OTSReport_Export;
- namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration
- {
- /// <summary>
- /// 三元图
- /// </summary>
- class TernaryDiagram
- {
- /// <summary>
- /// 三元图列表
- /// </summary>
- List<string> TemplateList;
- frmReportConditionChoose m_condition;
- public int condition = -1;
- //绘制图例
- public Bitmap DrawATernaryDiagramLegend(List<Color> Color_list, OTSReport_Export m_otsreport_export, c_TemplateClass m_mbszclass)
- {
- Bitmap map = new Bitmap(260, 115);
- Graphics g = Graphics.FromImage(map);
- SolidBrush sbrush_White = new SolidBrush(Color.White);
- SolidBrush sbrush = new SolidBrush(Color.Black);
- g.FillRectangle(sbrush_White, 0, 0, 260, 115);
- Font myFont = new Font("Arial", 10, FontStyle.Regular);
- Font myFont2 = new Font("Arial", 10, FontStyle.Regular);
- g.DrawString("(length,μm)", myFont, sbrush, 88, 3);
- //legend(length,microns)
- Pen mypen = new Pen(Color.Black, 1);
- g.DrawLine(mypen, 70, 19, 170, 19);
- //设置标签名称
- List<string> listName = new List<string>();
- //获取粒级表
- string pathe = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_mbszclass.M_SYXT.str_cb_syxt_ljb.ToString();
- DataSet ds = XMLoperate.GetXml(pathe);
- string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
- for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
- {
- if (sizestr.Split(',')[i].Length > 0)
- {
- double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
- double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
- listName.Add(d1.ToString() + "~" + d2.ToString());
- }
- }
- double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
- listName.Add(d.ToString() + "~MAX");
- int PositionJeight = 27;
- //string str_unit = " μm";
- string str_unit = "";
- for (int i = 0; i < listName.Count; i = i + 3)
- {
- if (i < listName.Count)
- {
- SolidBrush sbrush_Color = new SolidBrush(Color_list[i]);
- g.DrawRectangle(mypen, 0, PositionJeight, 8, 8);
- g.FillRectangle(sbrush_Color, 1, PositionJeight + 1, 7, 7);
- g.DrawString(listName[i].ToString() + str_unit, myFont2, sbrush, 12, PositionJeight - 2);
- }
- if (i + 1 < listName.Count)
- {
- SolidBrush sbrush_Color = new SolidBrush(Color_list[i + 1]);
- g.DrawRectangle(mypen, 94, PositionJeight, 8, 8);
- g.FillRectangle(sbrush_Color, 95, PositionJeight + 1, 7, 7);
- g.DrawString(listName[i + 1].ToString() + str_unit, myFont2, sbrush, 106, PositionJeight - 2);
- }
- if (i + 2 < listName.Count)
- {
- SolidBrush sbrush_Color = new SolidBrush(Color_list[i + 2]);
- g.DrawRectangle(mypen, 188, PositionJeight, 8, 8);
- g.FillRectangle(sbrush_Color, 189, PositionJeight + 1, 7, 7);
- g.DrawString(listName[i + 2].ToString() + str_unit, myFont2, sbrush, 199, PositionJeight - 2);
- }
- PositionJeight = PositionJeight + 15;
- }
- return map;
- }
- public Bitmap DrawATernaryPicture(int selectindex, c_TemplateClass m_mbszclass, List<Color> Color_list,OTSReport_Export m_otsreport_export)
- {
- initialization(m_otsreport_export);
-
-
- ResultFile resultFile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()];
- string template = TemplateList[selectindex];
- if (template == "")
- { //三元相图模板
- template = m_condition.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.TRIO_CHART_TYPE).ToString();
- }
- //获取粒级表
- string pathtpfs = Application.StartupPath + "\\Config\\ProData\\DefaultTriTemplateFile.tpf";
- List<string> nameList = new List<string>();
- DataSet ds2 = XMLoperate.GetXmlData(pathtpfs, "XMLData");
- DataTable dt = ds2.Tables["Member"];
- string TemplateName = "";
- //遍历第一层节点
- foreach (DataRow element in dt.Rows)
- {
- TemplateName = element["TemplateName"].ToString();
- if (TemplateName == template)
- {
- string Element = element["Element"].ToString();
- nameList.Add(Element.Split('.')[0]);
- nameList.Add(Element.Split('.')[1]);
- nameList.Add(Element.Split('.')[2]);
- break;
- }
- }
- DataTable dt_point_sort = new DataTable();
- dt_point_sort.Columns.Add("X", typeof(double));
- dt_point_sort.Columns.Add("Y", typeof(double));
- dt_point_sort.Columns.Add("Color_position");
- DataTable particles = GetParticles(resultFile.FilePath, nameList, 0,m_otsreport_export,m_mbszclass);
- foreach (DataRow item in particles.Rows)
- {
- if (item["particleLocation"].ToString() == "0,0,0")
- {
- continue;
- }
- double top = Convert.ToDouble(item["top"]);
- double left = Convert.ToDouble(item["left"]);
- double right = Convert.ToDouble(item["right"]);
- //x=right+top/2,y=(√3/2)*top
- double Y = 0.866 * top * 500;
- double X = (right + top / 2) * 500;
- double[] point_ = { Math.Round(X, 2), Math.Round(Y) };
- DataRow dr = dt_point_sort.NewRow();
- dr["X"] = Math.Round(X, 2);
- dr["Y"] = Math.Round(Y);
- dr["Color_position"] = item["Color_position"];
- dt_point_sort.Rows.Add(dr);
- }
- #region 图形
- int Line = 500;
- Bitmap map = new Bitmap(530, 530);
- Graphics g = Graphics.FromImage(map);
- SolidBrush sbrush_White = new SolidBrush(Color.White);
- g.FillRectangle(sbrush_White, 0, 0, 530, 530);
- Pen mypen = new Pen(Color.Black, 1);
- g.DrawImage(map, 0, 0, map.Width, map.Height);
- g.DrawLine(mypen, new Point(Line + 10, Line), new Point(Line / 2 + 10, Convert.ToInt32(Line - (Line / 2 * 1.732))));//"\"
- g.DrawLine(mypen, new Point(Line / 2 + 10, Convert.ToInt32(Line - (Line / 2 * 1.732))), new Point(0 + 10, Line));//"/"
- g.DrawLine(mypen, new Point(0 + 10, Line), new Point(Line + 10, Line));//"_"
- mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
- mypen.DashPattern = new float[] { 2, 2 };
- mypen = new Pen(Color.FromArgb(212, 212, 212), 1);
- int point = Line / 10;
- for (int i = 1; i < 10; i++)
- {
- //"\"
- int x1_a = point / 2 + ((point / 2) * (i - 1));
- int x2_a = Line - (43 * i);
- int y1_a = point * i;
- g.DrawLine(mypen, new Point(x1_a + 10, x2_a), new Point(y1_a + 10, Line));
- //"/"
- int x1_b = Line - (point / 2 + ((point / 2) * (i - 1)));
- int x2_b = Line - (43 * i);
- int y1_b = Line - (point * i);
- g.DrawLine(mypen, new Point(x1_b + 10, x2_b), new Point(y1_b + 10, Line));
- //"_"
- int x1_c = point / 2 + ((point / 2) * (i - 1));
- int x2_c = Line - (43 * i);
- int y1_c = Line - (point / 2 + ((point / 2) * (i - 1)));
- int y2_c = Line - (43 * i);
- g.DrawLine(mypen, new Point(x1_c + 10, x2_c), new Point(y1_c + 10, y2_c));
- g.DrawLine(mypen, new Point(y1_a + 10, Line + 10), new Point(y1_a + 10, Line));
- g.DrawLine(mypen, new Point(x1_b + 10, x2_b), new Point(x1_b + 10 + 10, x2_b));
- g.DrawLine(mypen, new Point(x1_c + 10 - 10, x2_c), new Point(y1_c + 10, y2_c));
- g.DrawString((i * 10).ToString(), new Font("Arial Unicode MS", 8, FontStyle.Bold), new SolidBrush(Color.Black), new Point(x1_c - 20, x2_c - 5));
- g.DrawString((i * 10).ToString(), new Font("Arial Unicode MS", 8, FontStyle.Bold), new SolidBrush(Color.Black), new Point(y1_b, Line + 8));
- g.DrawString(((10 - i) * 10).ToString(), new Font("Arial Unicode MS", 8, FontStyle.Bold), new SolidBrush(Color.Black), new Point(x1_b + 20, x2_b - 5));
- }
- for (int i = 0; i < dt_point_sort.Rows.Count; i++)
- {
- mypen = new Pen(Color.Black, 1);
- SolidBrush mysbrush = new SolidBrush(Color_list[Convert.ToInt32(dt_point_sort.Rows[i]["Color_position"])]);
- g.FillRectangle(mysbrush, Convert.ToInt32(dt_point_sort.Rows[i]["X"]) + 8, 500 - Convert.ToInt32(dt_point_sort.Rows[i]["Y"]) - 2, 4, 5);
- g.DrawRectangle(mypen, Convert.ToInt32(dt_point_sort.Rows[i]["X"]) + 7, 500 - Convert.ToInt32(dt_point_sort.Rows[i]["Y"]) - 2, 5, 5);
- }
- Font myFont = new Font("Arial Unicode MS", 13, FontStyle.Bold);
- Font Font_features = new Font("Arial Unicode MS", 10, FontStyle.Bold);
- SolidBrush sbrush = new SolidBrush(Color.Black);
- g.DrawString("features:" + dt_point_sort.Rows.Count.ToString(), Font_features, sbrush, 400, 200);
- g.DrawString(TemplateName, myFont, sbrush, 265 - (TemplateName.Length * 10 / 2), 10);
- g.DrawString(TemplateName.Split('.')[0].ToString(), myFont, sbrush, 265 - (TemplateName.Split('.')[0].ToString().Length * 10 / 2), 45);//顶点名字
- g.DrawString(TemplateName.Split('.')[1].ToString(), myFont, sbrush, 0, 510);//左侧名字
- g.DrawString(TemplateName.Split('.')[2].ToString(), myFont, sbrush, 500 - (TemplateName.Split('.')[0].ToString().Length * 10), 510);//左侧名字
- #endregion
- return map;
- }
- private void initialization(OTSReport_Export m_otsreport_export)
- {
- //加载三元相图各项
- string pathtpf = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.TrigTemplateFileFolder + "\\" + m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.TriTempFile;// Application.StartupPath + "\\Config\\ProData\\DefaultTriTemplateFile.tpf";
- TemplateList = new List<string>();
- DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData");
- DataTable dt = ds.Tables["Member"];
- foreach (DataRow item in dt.Rows)
- {
- if (item["TemplateName"].ToString() != "")
- {
- TemplateList.Add(item["TemplateName"].ToString());
- }
- }
- m_condition = m_otsreport_export.m_ReportApp.m_conditionChoose;
- }
- private DataTable GetParticles(string filepath, List<string> nameList, int sel, OTSReport_Export m_otsreport_export, c_TemplateClass m_mbszclass)
- {
- ParticleData particledata = new ParticleData(filepath);
- //设置标签名称
- List<string> listName = new List<string>();
- //获取粒级表
- string pathe = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_mbszclass.M_SYXT.str_cb_syxt_ljb.ToString();
- DataSet ds = XMLoperate.GetXml(pathe);
- string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
- for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
- {
- if (sizestr.Split(',')[i].Length > 0)
- {
- double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
- double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
- listName.Add(d1.ToString() + "~" + d2.ToString());
- }
- }
- double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
- listName.Add(d.ToString() + "~MAX");
- string filedAndParticl = "";
-
- string po = "";
- string con = "";
- int row = m_condition.m_conditionData.ConditionItemList.Count;
- if (condition != -1)
- {
- List<string> li = new List<string>() { "DMAX", "DMIN", "Area", "FERET" };
- con = li[condition];
- }
- else
- {
- if (row < 4)
- {
- con = "DMAX";
- }
- else
- {
- con = m_condition.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
- }
- }
- switch (con)
- {
- case "DMAX":
- po = "DMAX";
- break;
- case "DMIN":
- po = "DMIN";
- break;
- case "ECD":
- po = "Area";
- break;
- case "FERET":
- po = "DFERET";
- break;
- }
- DataTable dtp = particledata.GetParticleAllHaveXray(filedAndParticl);
- for (int i = 0; i < dtp.Rows.Count; i++)
- {
- if (Convert.ToInt32(dtp.Rows[i]["TypeId"]) < 0 || dtp.Rows[i]["TypeName"].ToString() == "Invalid")
- {
- dtp.Rows[i].Delete();
- }
- }
- dtp.AcceptChanges();
- //创建一个临时表
- DataTable ret_dt = new DataTable();
- //然后额外存放三列,用于存放拆分后三个顶点的值
- ret_dt.Columns.Add("sizeLevel");
- ret_dt.Columns.Add("particleLocation");
- ret_dt.Columns.Add("top");
- ret_dt.Columns.Add("left");
- ret_dt.Columns.Add("right");
- ret_dt.Columns.Add("Color_position");
- for (int k = 0; k < listName.Count; k++)
- {
- string str = listName[k];
- string d1 = str.Split('~')[0];
- string d2 = str.Split('~')[1];
- if (d2 == "MAX")
- {
- d2 = "999";
- }
- DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
- foreach (var item in datas)
- {
- DataRow dr = ret_dt.NewRow();
- dr["sizeLevel"] = str;
- string element = item["Element"].ToString();
- string strRet = getStrRet(nameList, element);
- dr["particleLocation"] = strRet;
- dr["top"] = strRet.Split(',')[0];
- dr["left"] = strRet.Split(',')[1];
- dr["right"] = strRet.Split(',')[2];
- dr["Color_position"] = k.ToString();
- ret_dt.Rows.Add(dr);
- }
- }
- return ret_dt;
- }
- private string getWhere(string max, string min, string col)
- {
- return col + ">=" + min + " and " + col + "<=" + max;
- }
- private string getStrRet(List<string> template, string element)
- {
- List<string> name = new List<string>()
- { "h","he",
- "li","be","b","c","n","o","f","ne",
- "na","mg","al","si","p","s","cl","ar",
- "k","ca","sc","ti","v","cr","mn","fe","co","ni","cu","zn","ga","ge","as","se","br","kr",
- "rb","sr","y","zr","nb","mo","tc","ru","rh","pd","ag","cd","in","sn","sb","te","i","xe",
- "cs","ba","la",
- "ce","pr","nd","pm","sm","eu","gd","tb","dy","ho","er","tm","yb","lu",
- "hf","ta","w","re","os","ir","pt","au","hg","tl","pb","bi","po","at","rn",
- "fr","ra","ac",
- "th","pa","u","np","pu","am","cm","bk","cf","es","fm","md","no","lr"
- };
- List<double> value = new List<double>()
- { 1.008,4.003,
- 6.941,9.012,10.811,12.011,14.007,15.999,18.998,20.180,
- 22.990,24.305,26.982,28.086,30.974,32.066,35.453,39.948,
- 39.098,40.08,44.956,47.88,50.942,51.996,54.938,55.847,58.933,58.70,63.546,65.39,69.72,72.61,74.922,78.96,79.904,83.80,
- 85.468,87.62,88.906,91.22,92.906,95.94,98.00,101.07,102.906,106.42,107.868,112.41,114.82,118.71,121.76,127.60,126.905,131.29,
- 132.905,137.33,138.906,
- 140.12,140.908,144.24,145.0,150.36,151.97,157.25,158.925,162.50,64.93,167.26,168.934,173.04,174.967,
- 178.49,180.948,183.85,186.207,190.20,192.22,195.08,196.967,200.59,204.38,207.2,208.980,209.00,210.00,222.00,
- 223.00,226.025,227.028,
- 232.038,231.036,238.029,237.048,244.00,243.00,247.00,247.00,251.00,252.00,257.00,258.00,259.00,260.00
- };
- double d_ASum = 0;
- double d_BSum = 0;
- double d_CSum = 0;
- string aElements = template[0];
- string bElements = template[1];
- string cElements = template[2];
- foreach (var item in element.Split(';'))
- {
- if (item.Contains(aElements + "-"))
- {
- if (aElements != "")
- {
- d_ASum = Convert.ToDouble(item.Split('-')[1]) / value[name.IndexOf(aElements.ToLower())];
- }
- }
- for (int i = 0; i < bElements.Split(',').Length; i++)
- {
- string e = bElements.Split(',')[i];
- if (item.Contains(e + "-"))
- {
- d_BSum = d_BSum + Convert.ToDouble(item.Split('-')[1]) / value[name.IndexOf(e.ToLower())];
- }
- }
- if (item.Contains(cElements + "-"))
- {
- if (cElements != "")
- d_CSum = Convert.ToDouble(item.Split('-')[1]) / value[name.IndexOf(cElements.ToLower())];
- }
- }
- double allNums = d_ASum + d_BSum + d_CSum;
- string strRet = "";
- if ((allNums) == 0)
- {
- strRet = "0,0,0";
- }
- else
- {
- double aPercent = 0, bPercent = 0, cPercent = 0;
- if (d_ASum != 0)
- {
- aPercent = d_ASum / allNums;
- }
- if (d_BSum != 0)
- {
- bPercent = d_BSum / allNums;
- }
- if (d_CSum != 0)
- {
- cPercent = d_CSum / allNums;
- }
- strRet = aPercent.ToString() + "," + bPercent.ToString() + "," + cPercent.ToString();
- }
- return strRet;
- }
- }
- }
|