| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619 |
- using OTSCommon.DBOperate;
- using OTSCommon.DBOperate.Model;
- using OTSIncAReportApp;
- using OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage;
- using OTSIncAReportApp._2_CommonFunction.CommonClass;
- using OTSIncAReportApp._3_ServiceCenter.DataOperation.DataAccess;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using OTSIncAReportApp.OTSRstMgrFunction;
- using OTSIncAReportApp.SysMgrTools;
- using OTSIncAReportGraph.Class;
- using OTSIncAReportGraph.Controls;
- using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
- using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
- using OTSIncAReportMailInterface;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using static OTSDataType.otsdataconst;
- namespace OTSIncAReportGrids
- {
- public partial class ParticlesGridDevidePage : UserControl
- {
- #region 变量定义
- private ParticlesGridDevidePageShowConfig m_particlesGridDevidePageShowConfig = null;
- //设置模拟数据表
- public DataTable m_dt = new DataTable();
- //底层操作类
- private SEMAndEDSOperate m_OTSIncAReportGridsFun = null;
- //进度条窗体
- public Frm_UserProgress m_frm_userprogress;
- //移动SEM到指定位置发生线程
- private Thread m_mythread;
- //记录线程是否已经运行完成的状态
- private bool m_mythread_state = false;
- //导出图像文件的路径
- private string m_imagefilepath = "";
- //显示元素列表
- public List<string> m_list_elementscolname = null;
- //单个数据源所拥有的列数,这里保存下来,供导出模块使用
- public int m_oneresult_columncount = 0;
- private OTSImageDisHelp m_ReportFun = null;
- public OTSImageDisHelp ReportFun
- {
- get => m_ReportFun;
- set => m_ReportFun = value;
- }
- /// <summary>
- /// 选择颗粒缓存表
- /// </summary>
- private List<Particle> Particleslist_selecttodisplay = new List<Particle>();
- //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
- public List<int> m_list_oneresult_columncount;
- //国际化
- private Language lan;
- public Hashtable table;
- //测量结果
- public ResultFile result = null;
- private frmReportConditionChoose m_condition;
- private FieldData fieldData;
- private DataTable particlesAll;
- private DataTable particlesFilter;
- public ParticleData Particledata;
- public UserSTDDbAccess userSTDDb;
- public FieldAndParticleImage fldImgAccess;
- private DataTable userSTDDbData;
- List<string> elementTypeSort;
- private readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- private enum SelItem
- {
- analyticalParticle = 0,
- otherParticles = 1,
- MergeParticles = 2,
- allParticles = 3
- }
- #region 分页器相关
- #region 分页字段和属性
- private string condition = "";
- public string FileName = null;
- private int pageIndex = 1;
- /// <summary>
- /// 当前页面
- /// </summary>
- public virtual int PageIndex
- {
- get { return pageIndex; }
- set { pageIndex = value; }
- }
- private int pageSize = 20;
- /// <summary>
- /// 每页记录数
- /// </summary>
- public virtual int PageSize
- {
- get { return pageSize; }
- set { pageSize = value; }
- }
- private int recordCount = 0;
- /// <summary>
- /// 总记录数
- /// </summary>
- public virtual int RecordCount
- {
- get { return recordCount; }
- set { recordCount = value; }
- }
- private int pageCount = 0;
- /// <summary>
- /// 总页数
- /// </summary>
- public int PageCount
- {
- get
- {
- pageCount = GetPageCount();
- return pageCount;
- }
- }
- /// <summary>
- /// 计算总页数
- /// </summary>
- /// <returns></returns>
- private int GetPageCount()
- {
- if (PageSize <= 0)
- {
- return 0;
- }
- return (RecordCount + PageSize - 1) / PageSize;
- }
- #endregion
- private frmReportApp m_ReportApp;
- #endregion
- #endregion
- #region UI层方法
- #region 初始化
- public ParticlesGridDevidePage(frmReportApp ReportApp)
- {
- m_ReportApp = ReportApp;
- m_condition = ReportApp.m_conditionChoose;
- string sou = m_condition.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
- if (sou.Contains("+"))
- {
- MessageBox.Show("This function does not support multiple samples!");
- result = m_ReportApp.m_rstDataMgr.ResultFilesList[0];
- }
- else
- {
- result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE)];
- }
- ReportFun = new OTSImageDisHelp(result);
- //设置窗体的双缓冲,以保证大数据时拖动不卡
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- InitializeComponent();
- //利用反射设置DataGridView的双缓冲
- Type dgvType = this.dgV_ParticlesDevidePage.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi?.SetValue(this.dgV_ParticlesDevidePage, true, null);
- this.control_XRayTable1 = new Control_XRayTable(null);
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.control_XRayTable1.GBInfoStr = "";
- this.control_XRayTable1.GoodChineseName = "";
- this.control_XRayTable1.MaterialName = "";
- this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.ShowSearchXray = false;
- this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
- this.control_XRayTable1.STDName = "";
- this.control_XRayTable1.Visible = false;
- this.control_XRayTable1.label_close.Visible = true;
- this.Controls.Add(this.control_XRayTable1);
- }
- private bool Init()
- {
- if (result == null)
- {
- return false;
- }
- try
- {
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- m_mythread_state = false;
- m_mythread = new Thread(new ParameterizedThreadStart(ControlThread_GO));
- fieldData = new FieldData(result.FilePath);
- Particledata = new ParticleData(result.FilePath);
- fldImgAccess = new FieldAndParticleImage(result.FilePath);
- var systype = m_ReportApp.m_RptConfigFile.Systype;
- if (systype == OTS_SysType_ID.TCCleannessA || systype == OTS_SysType_ID.BatteryCleannessA)
- {
- string str_STDDbName = result.GetSTDName();
- userSTDDb = new UserSTDDbAccess(str_STDDbName, result.FilePath + "\\");
-
- userSTDDbData = userSTDDb.GetSqlHelper() != null ?
- userSTDDb.GetSubAttributeFromDatabase() : null;
- }
- //初始化底层操作类
- m_OTSIncAReportGridsFun = new SEMAndEDSOperate();
- return true;
- }
- catch (Exception ex)
- {
- log.Error(ex.ToString());
- return false;
- }
- }
- private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
- {
- if (!Init())
- {
- return;
- }
- ProgressStart();
- if (!UpdateDataGrid())
- {
- return;
- }
- InitializePageSizeComboBox();
- InitializeTypeTextBox();
- dgV_ParticlesDevidePage.Focus();
- }
- private Dictionary<string, string> InitializeTable(ref string str_ElementsColName)
- {
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- var startFun = m_ReportApp.m_RptConfigFile.Systype;
- string str_DefaultComputedColName = ""; str_ElementsColName = "";
- DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData"); DataTable dt = ds.Tables["Member"];
- foreach (DataRow element in dt.Rows)
- {
- string regName = element["RegName"].ToString();
- if (regName == "DefaultComputedColName")
- {
- str_DefaultComputedColName = element["strValue"].ToString();
- }
- else if (regName == "ElementsColName")
- {
- str_ElementsColName = element["strValue"].ToString();
- }
- }
- string[] strs = str_DefaultComputedColName.Split(',');
- var keyValues = new Dictionary<string, string>
- {
- ["rowid"] = table["str4"].ToString(),
- ["TypeName"] = table["str6"].ToString(),
- ["ParticleImage"] = table["str5"].ToString(),
- ["FieldId"] = "FieldId",
- ["ParticleId"] = "ParticleId",
- ["SEMPosX"] = "SEMPosX",
- ["SEMPosY"] = "SEMPosY"
- };
- foreach (string str in strs)
- {
- switch (str)
- {
- case "ParticleCoordinate":
- keyValues["AbPosX"] = "PosX";
- keyValues["AbPosY"] = "PosY"; break;
- case "Area":
- keyValues["Area"] = table["str21"].ToString();
- break;
- case "EquivalentCircleDiameter":
- keyValues["Equivalent"] = table["str22"].ToString();
- break;
- case "MaxDiameter":
- keyValues["DMAX"] = table["str23"].ToString();
- break;
- case "MinDiameter":
- keyValues["DMIN"] = table["str24"].ToString();
- break;
- case "DiameterRatio":
- keyValues["DiameterRatio"] = table["str25"].ToString(); break;
- case "FerretDiameter":
- keyValues["DFERET"] = table["str26"].ToString();
- break;
- case "PERP":
- keyValues["DPERP"] = table["str27"].ToString();
- break;
- case "PERI":
- keyValues["PERIMETER"] = table["str28"].ToString();
- break;
- case "INSCR":
- keyValues["DINSCR"] = table["str29"].ToString();
- break;
- case "MEAN":
- keyValues["DMEAN"] = table["str30"].ToString();
- break;
- case "ELONG":
- keyValues["DELONG"] = table["str31"].ToString();
- break;
- case "ASPECT_ELONG":
- keyValues["ASPECT_ELONG"] = table["str32"].ToString();
- break;
- case "Orientation":
- keyValues["ORIENTATION"] = table["str33"].ToString();
- break;
- case "XRayDataCount":
- keyValues["XRayDataCount"] = "XRay计数";
- break;
- }
- if (startFun == OTS_SysType_ID.TCCleannessA || startFun == OTS_SysType_ID.BatteryCleannessA)
- {
- switch (str)
- {
- case "Hardness":
- keyValues["Hardness"] = table["str34"].ToString();
- break;
- case "Density":
- keyValues["Density"] = table["str35"].ToString();
- break;
- case "Electrical_conductivity":
- keyValues["Electrical_conductivity"] = table["str36"].ToString();
- break;
- }
- }
- }
- keyValues["Element"] = "Element";
- return keyValues;
- }
- private void InitializePageSizeComboBox()
- {
- cbB_PageSize.Items.AddRange(new object[] { "20", "100", "500", "1000", "5000", "All" });
- cbB_PageSize.SelectedIndex = 0;
- }
- private void InitializeTypeTextBox()
- {
- DataTable classificationTable = GetClassificationOfAllParticles();
- if (classificationTable?.Rows.Count > 0)
- {
- tbx_Type.Text = string.Join("$", classificationTable.AsEnumerable()
- .Select(row => row["TypeName"].ToString()));
- }
- }
- // 新增:为 userSTDDbData 建立索引以加速查找
- private Dictionary<string, DataRow> BuildUserStdLookup()
- {
- var dict = new Dictionary<string, DataRow>();
- if (userSTDDbData == null)
- return dict;
- foreach (DataRow r in userSTDDbData.Rows)
- {
- var key = Convert.ToString(r["STDId"]);
- if (!dict.ContainsKey(key))
- dict.Add(key, r);
- }
- return dict;
- }
- private void InitializeGridViewColumns(Dictionary<string, string> keyValues)
- {
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- foreach (var kvp in keyValues)
- {
- if (kvp.Key == "ParticleImage")
- {
- var iconColumn = new DataGridViewImageColumn
- {
- Name = kvp.Key,
- HeaderText = kvp.Value
- };
- dgV_ParticlesDevidePage.Columns.Add(iconColumn);
- }
- else if (kvp.Key != "Element")
- {
- dgV_ParticlesDevidePage.Columns.Add(kvp.Key, kvp.Value);
- if (IsNumericColumn(kvp.Key))
- {
- int id = dgV_ParticlesDevidePage.Columns.Count;
- dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
- }
- }
- }
- }
- #endregion
- #region 数据加载
- private DataTable GetParticleDataBySelection(int selection)
- {
- switch (selection)
- {
- case (int)SelItem.analyticalParticle:
- return Particledata.GetInfoForPartucleDevidePage_analyticalParticle(condition);
- case (int)SelItem.otherParticles:
- return Particledata.GetInfoForPartucleDevidePage_otherParticle(condition);
- case (int)SelItem.MergeParticles:
- return Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
- case (int)SelItem.allParticles:
- return Particledata.GetInfoForPartucleDevidePage_allParticles(condition);
- default:
- return new DataTable();
- }
- }
- private bool UpdateDataGrid()
- {
- int sel = m_ReportApp.m_conditionChoose.m_conditionData
- .GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- particlesAll = GetParticleDataBySelection(sel);
- if (particlesAll == null)
- {
- log.Error("There is an exception in the data of the database!");
- CloseProgressIfNeeded();
- return false;
- }
- // 添加必要列
- particlesAll.Columns.Add("Hardness");
- particlesAll.Columns.Add("Density");
- particlesAll.Columns.Add("Electrical_conductivity");
- // 使用字典索引 userSTDDbData,避免对每行使用 DataTable.Select(性能瓶颈)
- var userStdLookup = BuildUserStdLookup();
- UpdateHardnessDensityData(userStdLookup);
- btn_Sel.Enabled = true;
- DataTable elementchemistry = Particledata.GetElementChemistry();
- var elemIndex = BuildElementChemistryIndex(elementchemistry);
- UpdateElementData(elemIndex);
- particlesAll.Columns.Add("XRayDataCount");
- DataTable XRayData = Particledata.GetXRayData();
- var xrayIndex = BuildXRayDataIndex(XRayData);
- UpdateXRayDataCount(xrayIndex);
- return true;
- }
- private void UpdateHardnessDensityData(Dictionary<string, DataRow> userStdLookup)
- {
- string emptyValue = "";
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string key = Convert.ToString(particlesAll.Rows[i]["TypeId"]);
- if (userSTDDbData != null && userStdLookup.TryGetValue(key, out var dr))
- {
- particlesAll.Rows[i]["Hardness"] = dr["Hardness"].ToString();
- particlesAll.Rows[i]["Density"] = dr["Density"].ToString();
- particlesAll.Rows[i]["Electrical_conductivity"] = dr["Electrical_conductivity"].ToString();
- }
- else
- {
- particlesAll.Rows[i]["Hardness"] = emptyValue;
- particlesAll.Rows[i]["Density"] = emptyValue;
- particlesAll.Rows[i]["Electrical_conductivity"] = emptyValue;
- }
- }
- }
- private Dictionary<string, List<DataRow>> BuildElementChemistryIndex(DataTable elementchemistry)
- {
- var elemIndex = new Dictionary<string, List<DataRow>>();
- foreach (DataRow er in elementchemistry.Rows)
- {
- string key = $"XRayId = {er["XRayId"]} and fieldid = {er["fieldid"]}";
- if (!elemIndex.TryGetValue(key, out var list))
- {
- list = new List<DataRow>();
- elemIndex[key] = list;
- }
- list.Add(er);
- }
- return elemIndex;
- }
- private void UpdateElementData(Dictionary<string, List<DataRow>> elemIndex)
- {
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string key = $"XRayId = {particlesAll.Rows[i]["particleId"]} and fieldid = {particlesAll.Rows[i]["fieldid"]}";
- string concatenatedString = "";
- if (elemIndex.TryGetValue(key, out var drList))
- {
- concatenatedString = string.Join(";", drList.Select(dr => $"{dr["name"]}-{dr["Percentage"]}"));
- }
- particlesAll.Rows[i]["Element"] = concatenatedString;
- }
- }
- private Dictionary<string, byte[]> BuildXRayDataIndex(DataTable XRayData)
- {
- var xrayIndex = new Dictionary<string, byte[]>();
- foreach (DataRow xr in XRayData.Rows)
- {
- if (xr.ItemArray.Length >= 3 && xr[2] is byte[] b)
- {
- string key = $" XrayIndex= {xr[0]} and fieldid = {xr[1]}";
- if (!xrayIndex.ContainsKey(key))
- {
- xrayIndex[key] = b;
- }
- }
- }
- return xrayIndex;
- }
- private void UpdateXRayDataCount(Dictionary<string, byte[]> xrayIndex)
- {
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string subParticleString = Convert.ToString(particlesAll.Rows[i]["SubParticles"]);
- if (string.IsNullOrEmpty(subParticleString))
- {
- particlesAll.Rows[i]["XRayDataCount"] = 0;
- string str = $" XrayIndex= {particlesAll.Rows[i]["particleId"]} and fieldid = {particlesAll.Rows[i]["fieldid"]}";
- if (xrayIndex.TryGetValue(str, out var bytes))
- {
- uint xraycount = 0;
- int len = bytes.Length / 4;
- for (int j = 0; j < len; j++)
- {
- xraycount += BitConverter.ToUInt32(bytes, j * 4);
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- }
- else
- {
- particlesAll.Rows[i]["XRayDataCount"] = 0;
- DataRow dgvr = particlesAll.Rows[i];
- uint[] Analysis_xray = new uint[2000];
- Particledata.GetXrayByParticleTagIDAndFieldID_ForMergeParticle(
- Convert.ToInt32(dgvr["particleId"]),
- Convert.ToInt32(dgvr["fieldid"]),
- out Analysis_xray);
- uint xraycount = 0;
- for (int j = 0; j < Analysis_xray.Length; j++)
- {
- xraycount += Analysis_xray[j];
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- }
- }
- private void RefreshGridView()
- {
- dgV_ParticlesDevidePage.Visible = false;
- if (m_frm_userprogress == null || m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- string str_ElementsColName = null;
- Dictionary<string, string> keyValues = InitializeTable(ref str_ElementsColName);
- // 减少 UI 重绘开销
- dgV_ParticlesDevidePage.SuspendLayout();
-
- try
- {
- InitializeGridViewColumns(keyValues);
- if (PageSize <= 0)
- {
- PageSize = particlesAll?.Rows.Count ?? 0;
- }
- if (particlesAll == null)
- {
- return;
- }
- UpdatePageData();
- InitializeElementColumns(str_ElementsColName);
- LoadParticleData(keyValues);
- }
- finally
- {
- dgV_ParticlesDevidePage.ResumeLayout();
- dgV_ParticlesDevidePage.Visible = true;
- CloseProgress();
- }
- }
- private void UpdatePageData()
- {
- RecordCount = particlesAll.Rows.Count;
- particlesFilter = particlesAll.Clone();
- int startRow = (PageIndex - 1) * pageSize;
- int endRow = Math.Min(startRow + pageSize, RecordCount);
- for (int fi = startRow; fi < endRow; fi++)
- {
- particlesFilter.ImportRow(particlesAll.Rows[fi]);
- }
- }
- private void InitializeElementColumns(string str_ElementsColName)
- {
- elementTypeSort = string.IsNullOrEmpty(str_ElementsColName) ?
- new List<string>() :
- str_ElementsColName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
- .Distinct()
- .ToList();
- foreach (string element in elementTypeSort)
- {
- dgV_ParticlesDevidePage.Columns.Add(element, element);
- int id = dgV_ParticlesDevidePage.Columns.Count;
- dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
- }
- }
- private void LoadParticleData(Dictionary<string, string> keyValues)
- {
- if (particlesFilter?.Rows.Count == 0) return;
- double progressStep = particlesFilter.Rows.Count > 0 ? 95.0 / particlesFilter.Rows.Count : 95.0;
- string filePath = Path.Combine(result.FilePath, "FIELD_FILES");
- // 把 fieldpics 缓存提升到循环外,避免对同一 field 多次磁盘读取
- var fieldPics = new Dictionary<string, Bitmap>(StringComparer.OrdinalIgnoreCase);
- for (int i = 0; i < particlesFilter.Rows.Count; i++)
- {
- if (i % 10 == 0 && m_frm_userprogress != null && !m_frm_userprogress.IsDisposed)
- m_frm_userprogress.SetProgressValueAndText((int)(progressStep * i), "loading..");
- int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value =
- (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
- LoadParticleRowData(i, add_rowindex, keyValues, fieldPics);
-
- }
- }
- private void ProcessColumnData(int rowIndex, int gridRowIndex, int columnIndex, string columnName, Dictionary<string, Bitmap> fieldPics)
- {
- switch (columnName)
- {
- case "ParticleImage":
- ProcessParticleImageColumn(rowIndex, gridRowIndex, columnIndex, fieldPics);
- break;
- case "DiameterRatio":
- ProcessDiameterRatioColumn(rowIndex, gridRowIndex, columnIndex);
- break;
- case "ASPECT_ELONG":
- ProcessAspectElongColumn(rowIndex, gridRowIndex, columnIndex);
- break;
- case "Element":
- ProcessElementColumn(rowIndex, gridRowIndex);
- break;
- case "TypeName":
- ProcessTypeNameColumn(rowIndex, gridRowIndex, columnIndex);
- break;
- case "Equivalent":
- ProcessEquivalentColumn(rowIndex, gridRowIndex, columnIndex);
- break;
- case "Hardness":
- ProcessHardnessColumn(rowIndex, gridRowIndex, columnIndex);
- break;
- case "AbPosX":
- ProcessAbPosColumn(rowIndex, gridRowIndex);
- break;
- default:
- break;
- }
- AdjustTheFormatOfTheUnitValues(rowIndex, gridRowIndex, columnIndex, columnName);
- }
- private void ProcessParticleImageColumn(int rowIndex, int gridRowIndex, int columnIndex, Dictionary<string, Bitmap> fieldPics)
- {
- string subParticleString = Convert.ToString(particlesFilter.Rows[rowIndex]["SubParticles"]);
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Height = 70;
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Style.BackColor = Color.Azure;
- Bitmap bmap = null;
- if (!string.IsNullOrEmpty(subParticleString) && subParticleString != "IsSubParticle")
- {
- bmap = CreateMergedParticleImage(subParticleString);
- }
- else if (subParticleString != "IsSubParticle")
- {
- bmap = CreateSingleParticleImage(rowIndex, fieldPics);
- }
- bmap.Tag = new List<string>() { particlesFilter.Rows[rowIndex]["fieldid"].ToString(), particlesFilter.Rows[rowIndex]["ParticleId"].ToString() };
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = bmap;
- }
- private void LoadParticleRowData(int rowIndex, int gridRowIndex, Dictionary<string, string> keyValues, Dictionary<string, Bitmap> fieldPics)
- {
- foreach (var kvp in keyValues)
- {
- int columnIndex = dgV_ParticlesDevidePage.Columns.IndexOf(dgV_ParticlesDevidePage.Columns[kvp.Key]);
- //if (columnIndex < 0) continue;
- ProcessColumnData(rowIndex, gridRowIndex, columnIndex, kvp.Key, fieldPics);
- }
- }
- private void ProcessElementColumn(int rowIndex, int gridRowIndex)
- {
- List<string> elementtemp = new List<string>(elementTypeSort);
- string[] strcbo = particlesFilter.Rows[rowIndex]["Element"].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- if (elementTypeSort.Count == 0)
- {
- break;
- }
- string[] str = strcbo[j].Split('-');
- if (elementTypeSort.Contains(str[0]))
- { dgV_ParticlesDevidePage.Rows[rowIndex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
- elementtemp.Remove(str[0].ToString());
- }
- foreach (var ele in elementtemp)
- {
- dgV_ParticlesDevidePage.Rows[rowIndex].Cells[ele].Value = "0";
- }
- }
- private void ProcessTypeNameColumn(int rowIndex, int gridRowIndex, int columnIndex)
- {
- if (particlesFilter.Rows[rowIndex]["TypeId"].ToString() == "9")
- {
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = "Not Identified";
- }
- }
- private void ProcessEquivalentColumn(int rowIndex, int gridRowIndex, int columnIndex)
- {
- double dSize = Convert.ToDouble(particlesFilter.Rows[rowIndex]["Area"]);
- double diameter = Math.Sqrt(dSize / Math.PI) * 2;
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = Math.Round(diameter, 2);
- }
- private void ProcessHardnessColumn(int rowIndex, int gridRowIndex, int columnIndex)
- {
- string hardnessColor = ChangeHardnessColor(Convert.ToString(particlesFilter.Rows[rowIndex]["Hardness"]));
- if (hardnessColor == "#FF0000")
- {
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Style.ForeColor = Color.Red;
- }
- }
- private void ProcessAbPosColumn(int rowIndex, int gridRowIndex)
- {
- Point semPos = new Point(
- Convert.ToInt32(particlesFilter.Rows[rowIndex]["SEMPosX"]),
- Convert.ToInt32(particlesFilter.Rows[rowIndex]["SEMPosY"]));
- Point particlePos = new Point(
- Convert.ToInt32(particlesFilter.Rows[rowIndex]["PosX"]),
- Convert.ToInt32(particlesFilter.Rows[rowIndex]["PosY"]));
- Point point = CalculateParticleCenterPosition(result, semPos, particlePos);
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells["AbPosX"].Value = point.X;
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells["AbPosY"].Value = point.Y;
- }
- private void ProcessDiameterRatioColumn(int rowIndex, int gridRowIndex, int columnIndex)
- {
- double dmax = Convert.ToDouble(particlesFilter.Rows[rowIndex]["DMAX"]);
- double dmin = Convert.ToDouble(particlesFilter.Rows[rowIndex]["DMIN"]);
- double ratio = dmin != 0 ? dmax / dmin : 0;
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = Math.Round(ratio, 2);
- }
- private void ProcessAspectElongColumn(int rowIndex, int gridRowIndex, int columnIndex)
- {
- double delong = Convert.ToDouble(particlesFilter.Rows[rowIndex]["DELONG"]);
- double dmean = Convert.ToDouble(particlesFilter.Rows[rowIndex]["DMEAN"]);
- double ratio = dmean != 0 ? delong / dmean : 0;
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = Math.Round(ratio, 2);
- }
- /// <summary>
- /// 页面控件呈现
- /// </summary>
- private void DrawControl(bool callEvent)
- {
- RefreshGridView();
- lblTotalCount.Text = RecordCount.ToString();
- lblPageCount.Text = PageCount.ToString();
- txtPageNum.Text = PageIndex.ToString();
- SetFormCtrEnabled();
- if (PageCount == 0 || PageCount == 1) //有且仅有一页
- {
- lnkFirst.Enabled = false;
- lnkPrev.Enabled = false;
- lnkNext.Enabled = false;
- lnkLast.Enabled = false;
- btnGo.Enabled = false;
- }
- else if (PageIndex == 1) //第一页
- {
- lnkFirst.Enabled = false;
- lnkPrev.Enabled = false;
- }
- else if (PageIndex == PageCount) //最后一页
- {
- lnkNext.Enabled = false;
- lnkLast.Enabled = false;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private void DisplayData()
- {
- if (cbB_PageSize.SelectedItem?.ToString() == "All"){pageSize = -1;}
- else if (int.TryParse(cbB_PageSize.SelectedItem?.ToString(), out int parsedSize)){pageSize = parsedSize;}
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- #endregion
- #region 健壮性判断
- private bool IsNumericColumn(string columnName)
- {
- string[] numericColumns = {
- "Area", "EquivalentCircleDiameter", "MaxDiameter", "MinDiameter",
- "DiameterRatio", "FerretDiameter", "PERP", "PERI", "INSCR",
- "MEAN", "ELONG", "ASPECT_ELONG", "Orientation"
- };
- return numericColumns.Contains(columnName);
- }
- /// <summary>
- /// 判断条件输入 前<后
- /// </summary>
- /// <param name="min"></param>
- /// <param name="max"></param>
- /// <returns></returns>
- private bool CompareInput(string min, string max)
- {
- if (!double.TryParse(max, out double dmax))
- {
- if (!int.TryParse(max, out int imax))
- return false;
- dmax = imax;
- }
- if (!double.TryParse(min, out double dmin))
- {
- if (!int.TryParse(min, out int imin))
- return false;
- dmin = imin;
- }
- return dmin <= dmax;
- }
- private bool ValidateAndAddCondition(string value, string fieldName, string operatorSymbol)
- {
- if (string.IsNullOrWhiteSpace(value)) return true;
- if (double.TryParse(value, out double dnum) && dnum >= 0)
- {
- condition += $" and {fieldName} {operatorSymbol} {value}";
- return true;
- }
- if (int.TryParse(value, out int inum) && inum >= 0)
- {
- condition += $" and {fieldName} {operatorSymbol} {value}";
- return true;
- }
- ShowErrorMessage("str10");
- return false;
- }
- private bool ValidateIntegerField(string value, string fieldName)
- {
- if (string.IsNullOrWhiteSpace(value)) return true;
- if (int.TryParse(value, out _))
- {
- condition += $" and {fieldName} = {value}";
- return true;
- }
- ShowErrorMessage("str10");
- return false;
- }
- private bool ProcessECDConditions()
- {
- if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text))
- {
- if (double.TryParse(tbx_ECDMin.Text, out double dnum) && dnum >= 0)
- {
- double area = Math.PI * dnum / 2 * dnum / 2;
- condition += $" and Area > {area}";
- }
- else if (int.TryParse(tbx_ECDMin.Text, out int inum) && inum >= 0)
- {
- double area = Math.PI * inum / 2 * inum / 2;
- condition += $" and Area > {area}";
- }
- else
- {
- ShowErrorMessage("str10");
- return false;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
- {
- if (double.TryParse(tbx_ECDMax.Text, out double dnum) && dnum >= 0)
- {
- double area = Math.PI * dnum / 2 * dnum / 2;
- condition += $" and Area < {area}";
- }
- else if (int.TryParse(tbx_ECDMax.Text, out int inum) && inum >= 0)
- {
- double area = Math.PI * inum / 2 * inum / 2;
- condition += $" and Area < {area}";
- }
- else
- {
- ShowErrorMessage("str10");
- return false;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text) &&
- !string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
- {
- if (!CompareInput(tbx_ECDMin.Text, tbx_ECDMax.Text))
- {
- ShowErrorMessage("str11");
- return false;
- }
- }
- return true;
- }
- private void ShowErrorMessage(string resourceKey)
- {
- MessageBox.Show(table?[resourceKey].ToString() ?? "输入错误");
- }
- #endregion
- #region 数据处理
- private Bitmap CreateMergedParticleImage(string subParticleString)
- {
- double pix = result.GetPixelSize();
- int width = result.GetImageWidth();
- int height = result.GetImageHeight();
- string vs = "," + subParticleString.Replace(':', '-') + ",";
- DataTable dataTable = Particledata.GetParticleAllForBig(vs);
- var bmap1 = fldImgAccess.GetBitmapForMergedParticle(subParticleString, pix, height, width, dataTable);
- int cellWidth = dgV_ParticlesDevidePage.Columns["ParticleImage"].Width - 20;
- int cellHeight = dgV_ParticlesDevidePage.Rows[0].Height - 20;
- var ratioX = (double)cellWidth / bmap1.Width;
- var ratioY = (double)cellWidth / bmap1.Height;
- var ratio = Math.Min(ratioX, ratioY);
- var bmap = fldImgAccess.ScaleImageProportional(bmap1, ratio);
- return bmap;
- }
- private Bitmap CreateSingleParticleImage(int rowIndex, Dictionary<string, Bitmap> fieldPics)
- {
- string fid = Convert.ToString(particlesFilter.Rows[rowIndex]["fieldid"]);
- if (!fieldPics.ContainsKey(fid))
- {
- string imagePath = "Field" + fid + ".bmp";
- fieldPics[fid] = fldImgAccess.ReadImageFile(imagePath);
- }
- Rectangle rectangle = new Rectangle()
- {
- X = Convert.ToInt32(particlesFilter.Rows[rowIndex]["RectLeft"]),
- Y = Convert.ToInt32(particlesFilter.Rows[rowIndex]["RectTop"]),
- Width = Convert.ToInt32(particlesFilter.Rows[rowIndex]["RectWidth"]),
- Height = Convert.ToInt32(particlesFilter.Rows[rowIndex]["RectHeight"])
- };
- var src = fieldPics[fid];
-
- if (src != null)
- {
- var bmap1 = fldImgAccess.CapturePic(src, rectangle);
- int cellWidth = dgV_ParticlesDevidePage.Columns["ParticleImage"].Width - 20;
- int cellHeight = dgV_ParticlesDevidePage.Rows[0].Height - 20;
- var ratioX = (double)cellWidth / bmap1.Width;
- var ratioY = (double)cellWidth / bmap1.Height;
- var ratio = Math.Min(ratioX, ratioY);
- var bmap = fldImgAccess.ScaleImageProportional(bmap1, ratio);
- return bmap;
- }
- return null;
- }
- /// <summary>
- /// 计算颗粒中心的电镜坐标
- /// </summary>
- /// <param name="resultFile"></param>
- /// <param name="SEMPos"></param>
- /// <param name="ParticlePos"></param>
- /// <returns></returns>
- public static Point CalculateParticleCenterPosition(ResultFile resultFile, Point SEMPos, Point ParticlePos)
- {
- Point point = new Point();
- float scanFieldSizeX = resultFile.GetScanFieldSizeX();
- string leftOrRight = resultFile.GetXAxisDir();
- string downOrUp = resultFile.GetYAxisDir();
- float scanFieldSizeY = resultFile.GetScanFieldSizeY();
- float pixelSize = resultFile.GetPixelSize();
- if (leftOrRight == "RIGHT_TOWARD")
- {
- point.X = (int)(SEMPos.X - scanFieldSizeX / 2 + ParticlePos.X * pixelSize);
- }
- else
- {
- point.X = (int)(SEMPos.X + scanFieldSizeX / 2 - ParticlePos.X * pixelSize);
- }
- if (downOrUp == "UP_TOWARD")
- {
- point.Y = (int)(SEMPos.Y + scanFieldSizeY / 2 - ParticlePos.Y * pixelSize);
- }
- else
- {
- point.Y = (int)(SEMPos.Y - scanFieldSizeY / 2 + ParticlePos.Y * pixelSize);
- }
- return point;
- }
- /// <summary>
- /// 复制选择区域
- /// </summary>
- public void CopySelected()
- {
- //复制选择区域
- object clipboardContent = dgV_ParticlesDevidePage.GetClipboardContent();
- if (clipboardContent != null)
- Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
- }
- /// <summary>
- /// 复制所有
- /// </summary>
- public void CopyAll()
- {
- dgV_ParticlesDevidePage.SelectAll();
- Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
- }
- /// <summary>
- /// 以图像的方式将GridView进行截图
- /// </summary>
- public void CopyImage()
- {
- int width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
- int height = this.Height;
- using (Bitmap image = new Bitmap(width, height))
- {
- dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
- Clipboard.SetImage(image);
- }
- }
- private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
- {
- //排序中
- if (e.Column.Tag?.ToString() == "NumericType")
- {
- if (double.TryParse(e.CellValue1?.ToString(), out double val1) &&
- double.TryParse(e.CellValue2?.ToString(), out double val2))
- {
- e.SortResult = val1.CompareTo(val2);
- e.Handled = true;
- }
- }
- }
- private string ChangeHardnessColor(string hardness)
- {
- if (string.IsNullOrEmpty(hardness))
- return "";
- string str = System.Text.RegularExpressions.Regex.Replace(hardness, @"[^\d.\d]", "");
- return double.TryParse(str, out double hd) && hd >= 1000 ? "#FF0000" : "";
- }
- private void SaveParticleslist_select()
- {
- ParticleData fielddata = new ParticleData(result.FilePath);
- List<Particle> particles = fielddata.GetParticleAllList();
- Particleslist_selecttodisplay.Clear();
- for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
- {
- //从事先加载的Bitmap对象的Tag中取出List<string>
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particlesFilter.Select(str);
- DataRow row = drs[0];
- string subParticleString = row["SubParticles"].ToString();
- int i_ls_fieldid = -1; int i_ls_particleid = -1;
- if (subParticleString != "" && subParticleString != null)
- {
- string[] SubParticlesstrG = subParticleString.Split(',');
- if (SubParticlesstrG.Length > 1)
- {
- string fieldid1 = SubParticlesstrG[0].Split(':')[0];
- string pid1 = SubParticlesstrG[0].Split(':')[1];
- i_ls_fieldid = Convert.ToInt32(fieldid1);
- i_ls_particleid = Convert.ToInt32(pid1);
- }
- }
- else
- {
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- i_ls_fieldid = Convert.ToInt32(list_str[0]);
- i_ls_particleid = Convert.ToInt32(list_str[1]);
- }
- }
- foreach (Particle item in particles)
- {
- if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
- {
- Particleslist_selecttodisplay.Add(item);
- break;
- }
- }
- }
- }
- public List<Particle> GetParticleslist_select()
- {
- return Particleslist_selecttodisplay;
- }
- /// <summary>
- /// 获取所有颗粒的分类信息
- /// </summary>
- /// <returns></returns>
- public DataTable GetClassificationOfAllParticles()
- {
- string str = "";
- int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- if (sel == (int)SelItem.analyticalParticle)
- {
- str = "where xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4 and SubParticles is not 'IsSubParticle' ";
- }
- else if (sel == (int)SelItem.otherParticles)
- {
- str = "where SubParticles is not 'IsSubParticle'and(typeid =9 or typeid =-1 or typeid =4)";
- }
- else
- {
- }
- DataTable table = Particledata.GetClassificationOfAllParticles(str);
- return table;
- }
- #endregion
- #region 格式处理
- private void AdjustTheFormatOfTheUnitValues(int rowIndex, int gridRowIndex, int columnIndex, string columnName)
- {
- if (!particlesFilter.Columns.Contains(columnName)) return;
-
- if (columnName== "Element") return;
- var cellValue = particlesFilter.Rows[rowIndex][columnName];
- if (cellValue == null) return;
- if (double.TryParse(cellValue.ToString(), out double num))
- {
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = Math.Round(num, 2);
- }
- else
- {
- dgV_ParticlesDevidePage.Rows[gridRowIndex].Cells[columnIndex].Value = cellValue.ToString();
- }
- }
- private void SetFormCtrEnabled()
- {
- lnkFirst.Enabled = true;
- lnkPrev.Enabled = true;
- lnkNext.Enabled = true;
- lnkLast.Enabled = true;
- btnGo.Enabled = true;
- }
- /// <summary>
- /// 设置DataGridView样式
- /// </summary>
- private void SetDataGridViewStyle()
- {
- //用户不能调整标题的高度
- dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
- //点击选择整行
- dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- //居中显示
- DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle
- {
- Alignment = DataGridViewContentAlignment.MiddleCenter
- };
- dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
- dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- //再次重覆禁用拖动表头高度,居然有效果了
- dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //设置grid可以复制
- dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
- //设置每列的宽度
- if (dgV_ParticlesDevidePage.Columns.Count > 0)
- {
- dgV_ParticlesDevidePage.Columns[0].Width = 40; //第一列序号的宽度设置一下吧,要不太丑
- if (dgV_ParticlesDevidePage.Columns.Count > 1)
- dgV_ParticlesDevidePage.Columns[1].Width = 150;
- }
- //设置序号列不排序
- if (dgV_ParticlesDevidePage.Columns.Count > 0)
- {
- dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- if (dgV_ParticlesDevidePage.Columns.Count > 1)
- dgV_ParticlesDevidePage.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- }
- //设置序号列不可以设置宽度
- if (dgV_ParticlesDevidePage.Columns.Count > 0)
- dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
- dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
- }
- #endregion
- #region 进度条
- private void CloseProgress()
- {
- //加载完成设置鼠标为默认
- this.Cursor = Cursors.Default;
- string str8 = table?["str8"].ToString() ?? "完成";
- if (m_frm_userprogress != null && !m_frm_userprogress.IsDisposed)
- {
- m_frm_userprogress.SetProgressValueAndText(100, str8);
- m_frm_userprogress.Close();
- }
- }
- private void CloseProgressIfNeeded()
- {
- this.Cursor = Cursors.Default;
- if (m_frm_userprogress != null && !m_frm_userprogress.IsDisposed)
- m_frm_userprogress.Close();
- }
- private void ProgressStart()
- {
- #region 加载显示进度条部份
- this.Cursor = Cursors.WaitCursor;
- m_frm_userprogress = new Frm_UserProgress();
- Form ls_main_form = this.ParentForm?.ParentForm;//取出父窗体
- if (ls_main_form == null)
- {
- m_frm_userprogress.Visible = false;
- }
- else
- {
- m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
- m_frm_userprogress.Location = new Point(
- ls_main_form.Location.X + 80,
- ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
- m_frm_userprogress.Show();
- m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
- }
- #endregion
- }
- #endregion
- #region UI事件
- private void ToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- //复制整个表
- CopyAll();
- }
- private void ToolStripMenuItem2_Click(object sender, EventArgs e)
- {
- //复制选择区域
- CopySelected();
- }
- private void toolStripMenuItem4_Click(object sender, EventArgs e)
- {
- //对gridview进行截图
- CopyImage();
- }
- private void ToolStripMenuItem5_Click(object sender, EventArgs e)
- {
- /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
- //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
- if (dgV_ParticlesDevidePage.SelectedRows.Count == 0) return;
- string i_ls_fieldid = "";
- string i_ls_particleid = "";
- int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
- if (dgvr.Cells[2].Value is Bitmap ls_bp && ls_bp.Tag is List<string> list_str)
- {
- i_ls_fieldid = list_str[0];
- i_ls_particleid = list_str[1];
- }
- ParticleData particleData = new ParticleData(result.FilePath);
- Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
- //取得Field的Position,然后执行线程移动SEM到当前Field的位置
- if (m_mythread == null) return;
- if (m_mythread.ThreadState == ThreadState.Running ||
- m_mythread.ThreadState == ThreadState.WaitSleepJoin)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Stopped)
- {
- m_mythread = new Thread(new ParameterizedThreadStart(ControlThread_GO));
- }
- Point point = CalculateParticleCenterPosition(result,
- new Point(particle.SEMPosX, particle.SEMPosY),
- new Point(particle.PosX, particle.PosY));
- //改为线程调用,先判断线程状态
- m_mythread.Start(point);
- }
- private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
- {
- using (FolderBrowserDialog fbd = new FolderBrowserDialog())
- {
- if (fbd.ShowDialog() != DialogResult.OK) return;
- m_imagefilepath = fbd.SelectedPath;
- for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
- {
- if (dgV_ParticlesDevidePage.Rows[i].Cells[2].Value is Bitmap ls_bp)
- {
- string filePath = Path.Combine(m_imagefilepath, $"{(i + 1)}.jpg");
- ls_bp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- string str9 = table?["str9"].ToString() ?? "导出完成,共导出 ";
- MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
- }
- }
- private void testToolStripMenuItem_Click(object sender, EventArgs e)
- {
- // Empty method placeholder
- }
- private void btn_Sel_Click(object sender, EventArgs e)
- {
- condition = "";
- if (!ValidateAndAddCondition(tBx_AreaMin.Text, "Area", ">"))
- return;
- if (!ValidateAndAddCondition(Tbx_AreaMax.Text, "Area", "<"))
- return;
- if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) &&
- !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
- {
- if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
- {
- ShowErrorMessage("str11");
- return;
- }
- }
- if (!ValidateAndAddCondition(tbx_DmaxMin.Text, "DMAX", ">"))
- return;
- if (!ValidateAndAddCondition(tbx_DmaxMax.Text, "DMAX", "<"))
- return;
- if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) &&
- !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
- {
- if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
- {
- ShowErrorMessage("str11");
- return;
- }
- }
- if (!ValidateIntegerField(tB_FieldId.Text, "FieldId"))
- return;
- if (!ValidateIntegerField(tB_ParticleId.Text, "ParticleId"))
- return;
- if (!ValidateAndAddCondition(tbx_DferretMin.Text, "DFERET", ">"))
- return;
- if (!ValidateAndAddCondition(tbx_DferretMax.Text, "DFERET", "<"))
- return;
- if (!string.IsNullOrWhiteSpace(tbx_DferretMin.Text) &&
- !string.IsNullOrWhiteSpace(tbx_DferretMax.Text))
- {
- if (!CompareInput(tbx_DferretMin.Text, tbx_DferretMax.Text))
- {
- ShowErrorMessage("str11");
- return;
- }
- }
- if (!ProcessECDConditions())
- return;
- if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
- {
- string[] types = tbx_Type.Text.Split('$');
- condition += " and (";
- for (int i = 0; i < types.Length; i++)
- {
- if (i == 0)
- {
- condition += $" TypeName = '{types[i]}'";
- }
- else
- {
- condition += $" or TypeName = '{types[i]}'";
- }
- }
- condition += ")";
- }
- if (m_frm_userprogress?.IsDisposed != false)
- {
- ProgressStart();
- }
- UpdateDataGrid();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- /// <summary>
- /// 分页属性改变了。
- /// </summary>
- private void txtPageSize_TextChanged(object sender, EventArgs e)
- {
- if (!int.TryParse(txtPageNum.Text.Trim(), out int num) || num <= 0)
- {
- txtPageNum.Text = "1";
- }
- }
- private void lnkFirst_Click(object sender, EventArgs e)
- {
- PageIndex = 1;
- DrawControl(true);
- }
- private void lnkPrev_Click(object sender, EventArgs e)
- {
- PageIndex = Math.Max(1, PageIndex - 1);
- DrawControl(true);
- }
- private void lnkNext_Click(object sender, EventArgs e)
- {
- PageIndex = Math.Min(PageCount, PageIndex + 1);
- DrawControl(true);
- }
- private void lnkLast_Click(object sender, EventArgs e)
- {
- PageIndex = PageCount;
- DrawControl(true);
- }
- /// <summary>
- /// 跳转
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnGo_Click(object sender, EventArgs e)
- {
- if (int.TryParse(txtPageNum.Text.Trim(), out int num) && num > 0)
- {
- if (num > PageCount)
- {
- num = PageCount;
- txtPageNum.Text = PageCount.ToString();
- }
- PageIndex = num;
- DrawControl(true);
- }
- }
- private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- DisplayData();
- }
- private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
- {
- using (var sfd = new OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation())
- {
- if (sfd.ShowDialog() != DialogResult.OK) return;
-
- if (m_frm_userprogress?.IsDisposed != false)
- {
- ProgressStart();
- }
- try
- {
- ExcelExport excelExport=new ExcelExport(dgV_ParticlesDevidePage,particlesFilter,Particledata, m_frm_userprogress);
- excelExport.ExportToExcel(sfd);
- }
- finally
- {
- //加载完成,关闭进度条
- if (m_frm_userprogress != null && !m_frm_userprogress.IsDisposed)
- {
- m_frm_userprogress.SetProgressValueAndText(100, "导出完成");
- m_frm_userprogress.Close();
- }
- Cursor = Cursors.Default;
- //导出完成后,打开Excel文件
- if (File.Exists(sfd.FileName))
- {
- System.Diagnostics.Process.Start(sfd.FileName);
- }
- }
- }
- }
- private void ToolStripMenuItem3_Click(object sender, EventArgs e)
- {
- //如果没有选中颗粒退出
- if (dgV_ParticlesDevidePage.SelectedRows.Count == 0)
- {
- return;
- }
- string categoryName = GetSelectedCategoryName();
- var classificationData = GetClassificationData();
- using (var modifyCategoryForm = new ModifyCategoryForm(classificationData, categoryName))
- {
- if (modifyCategoryForm.ShowDialog() != DialogResult.OK ||
- !modifyCategoryForm.DoYouWantToModifyIt)
- {
- return;
- }
- var updateParams = GetUpdateParameters(modifyCategoryForm);
- HandleCategoryUpdate(updateParams);
- }
- }
- private void ToolStripMenuItem_Delete_Particle_Click(object sender, EventArgs e)
- {
- string path = result.FilePath;
- var fieldData = new ParticleData(result.FilePath);
- List<Particle> particles = fieldData.GetParticleAllList();
- DialogResult dr = MessageBox.Show("Remove all these particles permanently?",
- "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- DeleteSelectedParticles(particles);
- }
- }
- private void btn_particletypesel_Click(object sender, EventArgs e)
- {
- ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(this, tbx_Type.Text);
- DialogResult result = particleClassificationSelect.ShowDialog();
- if (result == DialogResult.OK)
- {
- condition = "";
- tbx_Type.Text = "";
- if (particleClassificationSelect.ParticleClassificationSelected != "")
- {
- tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
- btn_Sel_Click(null, null);
- }
- }
- }
- private void btn_showconfig_Click(object sender, EventArgs e)
- {
- var p = particlesFilter; List<string> ele = new List<string>();
- string elementsstr = "";
- foreach (DataRow row in particlesFilter.Rows)
- {
- string[] strcbo = row["Element"].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- string[] str = strcbo[j].Split('-');
- if (!ele.Contains(str[0]) && str[0] != "")
- {
- if (str[1] != "" && double.Parse(str[1]) != 0) //咨询demo后,元素含量返回值为零时一般去除此元素
- { ele.Add(str[0]); }
- }
- }
- }
- foreach (var el in ele)
- {
- elementsstr += el.ToString() + ',';
- }
- if (elementsstr != "")
- {
- elementsstr = elementsstr.Remove(elementsstr.Length - 1, 1);
- }
- m_particlesGridDevidePageShowConfig = new ParticlesGridDevidePageShowConfig(m_ReportApp.m_RptConfigFile.Systype, elementsstr);
- m_particlesGridDevidePageShowConfig.ShowDialog();
- if (m_particlesGridDevidePageShowConfig.DialogResult == DialogResult.OK)
- {
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- RefreshGridView();
- SetDataGridViewStyle();
- }
- }
- private void tbx_Type_Click(object sender, EventArgs e)
- {
- ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(this, tbx_Type.Text);
- DialogResult result = particleClassificationSelect.ShowDialog();
- if (result == DialogResult.OK)
- {
- condition = "";
- tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
- string[] tr = tbx_Type.Text.Split(',');
- condition += " and (";
- for (int i = 0; i < tr.Length; i++)
- {
- if (i == 0)
- {
- condition += " TypeName = '" + tr[i] + "'";
- }
- else
- {
- condition += " or TypeName = '" + tr[i] + "'";
- }
- }
- condition += ")";
- if (m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- UpdateDataGrid();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- }
- private void 根据相似度批量修改ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //如果没有选中颗粒退出
- if (dgV_ParticlesDevidePage.SelectedRows.Count != 1)
- {
- MessageBox.Show("Please select one row!");
- return;
- }
- var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- uint[] Analysis_xray = new uint[2000];
- int i_xray_id = 0;
- List<Element> list_celementchemistryclr = new List<Element>();
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particlesFilter.Select(str);
- DataRow row = drs[0];
- string subParticleString = row["SubParticles"].ToString();
- if (subParticleString != "" && subParticleString != null)
- {
- Particledata.GetXrayByParticleTagIDAndFieldID_ForMergeParticle(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Analysis_xray);
- }
- else
- {
- ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
- }
- ListOfSimilarParticles Form_listOfSimilarParticles = new ListOfSimilarParticles(this, Analysis_xray, m_ReportApp);
- DialogResult result3 = Form_listOfSimilarParticles.ShowDialog();
- if (result3 == DialogResult.OK)
- {
- UpdateDataGrid();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- DataTable table = GetClassificationOfAllParticles();
- if (table != null)
- {
- if (table.Rows.Count > 0)
- {
- foreach (DataRow rw in table.Rows)
- {
- tbx_Type.Text += rw["TypeName"].ToString() + '$';
- }
- }
- if (tbx_Type.Text != "")
- {
- tbx_Type.Text = tbx_Type.Text.Remove(tbx_Type.Text.Length - 1);
- }
- }
- dgV_ParticlesDevidePage.Focus();
- }
- else
- {
- }
- }
- private void dgV_ParticlesDevidePage_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Delete)
- {
- ToolStripMenuItem_Delete_Particle_Click(null, null);
- }
- }
- private void dgV_ParticlesDevidePage_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Down)
- {
- dgV_ParticlesDevidePage_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Up)
- {
- dgV_ParticlesDevidePage_MouseUp(null, null);
- }
- }
- private void dgV_ParticlesDevidePage_MouseUp(object sender, MouseEventArgs e)
- {
- ToolStripMenuItem_SimilarityReclassification.Enabled = false;
- var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- uint[] Analysis_xray = new uint[2000];
- Particle particle = new Particle();
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particlesFilter.Select(str);
- DataRow row = drs[0];
- string subParticleString = row["SubParticles"].ToString();
- particle = Particledata.GetXrayByParticleIDAndFieldID(subParticleString, Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Analysis_xray);
- List<ShowElementInfo> list_showelementinfo = Particledata.GetShowElementInfos(particle.ElementList);
- string str_IncAName = "";
- str_IncAName = Convert.ToString(dgvr.Cells[1].Value);
- if (particle == null)
- {
- return;
- }
- control_XRayTable1.SetParticleInfo("Area:" + Math.Round(particle.Area, 2) + " " + "DMAX:" + Math.Round(particle.DMAX, 2) + " " + "DELONG:" + Math.Round(particle.DELONG, 2) + " " + "DFERET:" + Math.Round(particle.DFERET, 2) + " " + "DINSCR:" + Math.Round(particle.DINSCR, 2) + "\n" + "DMEAN:" + Math.Round(particle.DMEAN, 2) + " " + "DMIN:" + Math.Round(particle.DMIN, 2) + " " + "DPERP:" + Math.Round(particle.DPERP, 2) + " " + "ORIENTATION:" + Math.Round(particle.ORIENTATION, 2) + " " + "PERIMETER:" + Math.Round(particle.PERIMETER, 2));
- control_XRayTable1.Visible = true;
- control_XRayTable1.SetXRayShowLineValue(Analysis_xray, list_showelementinfo);
- control_XRayTable1.GBInfoStr = "";
- control_XRayTable1.MaterialName = str_IncAName;
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- DataTable dataTable = new DataTable();
- double pix = result.GetPixelSize();
- int width = result.GetImageWidth();
- int height = result.GetImageHeight();
- Dictionary<string, List<Segment>> segsData = new Dictionary<string, List<Segment>>();
- if (subParticleString == "" || subParticleString == null)
- {
- int fldid = Convert.ToInt32(dgvr.Cells["fieldid"].Value);
- int partid = Convert.ToInt32(dgvr.Cells["particleId"].Value);
- var listseg = Particledata.GetSegmentData(fldid, partid);
- string key = fldid.ToString() + "_" + partid.ToString();
- segsData.Add(key, listseg);
- dataTable = particlesFilter.Clone();
- dataTable.ImportRow(row);
- }
- else
- {
- string vs = "," + subParticleString.Replace(':', '-') + ",";
- dataTable = Particledata.GetParticleAllForBig(vs);//组成拼接颗粒的子颗粒
- foreach (DataRow dow in dataTable.Rows)
- {
- int fldid = Convert.ToInt32(dow["fieldid"]);
- int partid = Convert.ToInt32(dow["particleId"]);
- var listseg = Particledata.GetSegmentData(fldid, partid);
- string key = dow["fieldid"].ToString() + "_" + dow["particleid"].ToString();
- segsData.Add(key, listseg);
- }
- }
- Bitmap bmap = fldImgAccess.GetBitmapForParticleAll(subParticleString, dataTable, pix, height, width);
- Bitmap bmap1 = fldImgAccess.GetBitmapForParticleAllWithBlackAndWhite(subParticleString, dataTable, segsData, pix, height, width);
- control_XRayTable1.SetBitmapOfPictureBox(bmap, bmap1);
- Invalidate();
- ToolStripMenuItem_SimilarityReclassification.Enabled = true;
- }
- SaveParticleslist_select();
- }
- }
- private void dgV_ParticlesDevidePage_MouseDown(object sender, MouseEventArgs e)
- {
- ToolStripMenuItemDelete_Particle.Visible = true;
- }
- #endregion
- #endregion
- #region 连接电镜相关
- /// <summary>
- /// 移动SEM到指定位置线程函数
- /// </summary>
- private void ControlThread_GO(object in_obj)
- {
- if (m_mythread_state) return;
- m_mythread_state = true;
- try
- {
- Point sem_point = (Point)in_obj;
- //第一步,连接电镜
- m_OTSIncAReportGridsFun?.Connection_ForParticlesGrid();
- Thread.Sleep(500);
- //第二步,移动到指定位置,先读取再设置
- if (m_OTSIncAReportGridsFun?.m_SEMConnectionState == true)
- {
- m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
- }
- Thread.Sleep(1500);
- }
- finally
- {
- m_mythread_state = false;
- }
- }
- #endregion
- #region 类别修改相关
- /// <summary>
- /// 读取标准库的ClassifySTD表
- /// </summary>
- /// <param name="a_address"></param>
- /// <returns></returns>
- private DataTable ReadClassification(string a_address, string STDName)
- {
- DataTable dt_STDGroups = new DataTable();
- DataTable dt_ClassifySTD = new DataTable();
- DataTable dt_IncAData = new DataTable();
- var systype = m_ReportApp.m_RptConfigFile.Systype;
- if (systype == OTS_SysType_ID.IncA)
- {
- dt_ClassifySTD.Columns.Add("STDId");
- dt_ClassifySTD.Columns.Add("StrName");
- dt_ClassifySTD.Columns.Add("Color");
- dt_ClassifySTD.Columns.Add("KeyElementList");
- dt_ClassifySTD.Columns.Add("SubElementList");
- dt_ClassifySTD.Columns.Add("UsingImgPropertyList");
- dt_ClassifySTD.Columns.Add("UsingOtherPropertyList");
- dt_ClassifySTD.Columns.Add("Expression");
- dt_ClassifySTD.Columns.Add("Hardness");
- dt_ClassifySTD.Columns.Add("Density");
- dt_ClassifySTD.Columns.Add("Electrical_conductivity");
- dt_ClassifySTD.Columns.Add("BSE");
- dt_ClassifySTD.Columns.Add("Formula");
- dt_ClassifySTD.Columns.Add("Element");
- dt_ClassifySTD.Columns.Add("IfElementAnalysis");
- dt_ClassifySTD.Columns.Add("ListNum");
- dt_ClassifySTD.Columns.Add("GroupId");
- dt_ClassifySTD.Columns.Add("GroupName");
- dt_ClassifySTD.Columns.Add("GroupColor");
- DataTable da = Particledata.GetParticleListForParticlSizeID("area", "");
- for (int i = 0; i < da.Rows.Count; i++)
- {
- if (Convert.ToInt64(da.Rows[i]["TypeId"]) > 9)
- {
- DataRow newRow = dt_ClassifySTD.NewRow();
- newRow["STDId"] = da.Rows[i]["TypeId"];
- newRow["StrName"] = da.Rows[i]["TypeName"];
- newRow["Color"] = da.Rows[i]["TypeColor"];
- newRow["GroupId"] = da.Rows[i]["GroupId"];
- newRow["GroupName"] = da.Rows[i]["GroupName"];
- newRow["GroupColor"] = da.Rows[i]["GroupColor"];
- dt_ClassifySTD.Rows.Add(newRow);
- }
- }
- }
- else
- {
- SqLiteHelper sh_STDGroups = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
- dt_STDGroups = sh_STDGroups.ExecuteQuery("select * from STDGroups");
- SqLiteHelper sh_ClassifySTD = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
- dt_ClassifySTD = sh_ClassifySTD.ExecuteQuery("select * from ClassifySTD");
- dt_ClassifySTD.Columns.Add("GroupName");
- dt_ClassifySTD.Columns.Add("GroupColor");
- for (int i = 0; i < dt_ClassifySTD.Rows.Count; i++)
- {
- for (int a = 0; a < dt_STDGroups.Rows.Count; a++)
- {
- if (dt_ClassifySTD.Rows[i]["GroupId"].ToString() == dt_STDGroups.Rows[a]["id"].ToString())
- {
- dt_ClassifySTD.Rows[i]["GroupName"] = dt_STDGroups.Rows[a]["name"].ToString();
- dt_ClassifySTD.Rows[i]["GroupColor"] = dt_STDGroups.Rows[a]["color"].ToString();
- continue;
- }
- }
- }
- SqLiteHelper sh_Inclusion = new SqLiteHelper("data source='" + a_address + "\\FIELD_FILES\\Inclusion.db" + "'");
- dt_IncAData = sh_Inclusion.ExecuteQuery("select * from IncAData");
- for (int i = 0; i < dt_IncAData.Rows.Count; i++)
- {
- if (Convert.ToInt64(dt_IncAData.Rows[i]["TypeId"]) > 50000)
- {
- DataRow newRow = dt_ClassifySTD.NewRow();
- newRow["STDId"] = dt_IncAData.Rows[i]["TypeId"];
- newRow["StrName"] = dt_IncAData.Rows[i]["TypeName"];
- newRow["Color"] = dt_IncAData.Rows[i]["TypeColor"];
- newRow["GroupId"] = dt_IncAData.Rows[i]["GroupId"];
- newRow["GroupName"] = dt_IncAData.Rows[i]["GroupName"];
- newRow["GroupColor"] = dt_IncAData.Rows[i]["GroupColor"];
- dt_ClassifySTD.Rows.Add(newRow);
- }
- }
- }
- DataRow newRowInvalid = dt_ClassifySTD.NewRow();
- newRowInvalid["STDId"] = -1;
- newRowInvalid["StrName"] = "Invalid";
- newRowInvalid["Color"] = "#000000";
- newRowInvalid["GroupId"] = -1;
- newRowInvalid["GroupName"] = "Invalid";
- newRowInvalid["GroupColor"] = "#000000";
- dt_ClassifySTD.Rows.Add(newRowInvalid);
- return dt_ClassifySTD;
- }
- private string GetSelectedCategoryName()
- {
- if (dgV_ParticlesDevidePage.SelectedRows.Count > 0)
- {
- DataGridViewRow lastRow = dgV_ParticlesDevidePage.SelectedRows[
- dgV_ParticlesDevidePage.SelectedRows.Count - 1];
- return lastRow.Cells[1].Value?.ToString() ?? "";
- }
- return "";
- }
- private DataTable GetClassificationData()
- {
- string[] resultParts = result.GetSTDName().Split('.');
- return ReadClassification(result.FilePath, resultParts[0]);
- }
- private List<string> GetUpdateParameters(ModifyCategoryForm form)
- {
- return new List<string>
- {
- form.OutTypeAndName[0], // TypeId
- form.OutTypeAndName[1], // TypeName
- form.OutTypeAndName[2], // TypeColor
- form.OutTypeAndName[3], // GroupName
- form.OutTypeAndName[4], // GroupID
- form.OutTypeAndName[5] // GroupColor
- };
- }
- private void HandleCategoryUpdate(List<string> updateParams)
- {
- if (dgV_ParticlesDevidePage.SelectedRows.Count == 1)
- {
- HandleSingleRowUpdate(updateParams);
- }
- else
- {
- HandleMultipleRowsUpdate(updateParams);
- }
- RefreshAfterUpdate();
- }
- private void HandleSingleRowUpdate(List<string> updateParams)
- {
- DialogResult result = MessageBox.Show("是否寻找相似颗粒并重命名?", "Tip",
- MessageBoxButtons.YesNo);
- if (result == DialogResult.Yes)
- {
- HandleSimilarParticleSearch(updateParams);
- }
- else
- {
- ExecuteBatchUpdate(updateParams);
- }
- }
- private void HandleSimilarParticleSearch(List<string> updateParams)
- {
- int sel = m_ReportApp.m_conditionChoose.m_conditionData
- .GetComboDownListIndexByItemName(
- OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- if (sel == (int)SelItem.MergeParticles)
- {
- ExecuteBatchUpdate(updateParams);
- return;
- }
- uint[] analysisXray = new uint[2000];
- if (dgV_ParticlesDevidePage.SelectedRows.Count == 1)
- {
- DataGridViewRow row = dgV_ParticlesDevidePage.SelectedRows[0];
- ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(
- Convert.ToInt32(row.Cells["particleId"].Value),
- Convert.ToInt32(row.Cells["fieldid"].Value),
- out analysisXray,
- out int _, // i_xray_id
- out List<Element> _); // list_celementchemistryclr
- }
- using (var form = new ListOfSimilarParticles(this, analysisXray, updateParams, m_ReportApp))
- {
- if (form.ShowDialog() != DialogResult.OK)
- {
- ExecuteBatchUpdate(updateParams);
- }
- }
- }
- private void HandleMultipleRowsUpdate(List<string> updateParams)
- {
- ExecuteBatchUpdate(updateParams);
- }
- private void ExecuteBatchUpdate(List<string> updateParams)
- {
- var cmdList = new List<KeyValuePair<string, SQLiteParameter[]>>();
- foreach (DataGridViewRow row in dgV_ParticlesDevidePage.SelectedRows)
- {
- UpdateGridRow(row, updateParams[1]); // TypeName
- if (row.Cells[2].Value is Bitmap bitmap && bitmap.Tag is List<string> tagList)
- {
- var particleIds = new List<int>
- {
- Convert.ToInt32(tagList[0]), // fieldId
- Convert.ToInt32(tagList[1]) // particleId
- };
- var cmd = Particledata.GetUpdataAIncACmd(particleIds, updateParams);
- cmdList.Add(cmd);
- }
- row.Cells[1].Value = updateParams[1]; // Update TypeName in grid
- }
- Particledata.ExecuteNonQueryBatch(cmdList);
- }
- private void UpdateGridRow(DataGridViewRow row, string typeName)
- {
- row.Cells[1].Value = typeName;
- }
- private void RefreshAfterUpdate()
- {
- UpdateDataGrid();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- UpdateTypeTextBox();
- dgV_ParticlesDevidePage.Focus();
- }
- private void UpdateTypeTextBox()
- {
- tbx_Type.Text = "";
- DataTable table = GetClassificationOfAllParticles();
- if (table?.Rows.Count > 0)
- {
- tbx_Type.Text = string.Join("$", table.AsEnumerable()
- .Select(row => row["TypeName"].ToString()));
- }
- }
- #endregion
- #region 删除颗粒相关\备份
- private void DeleteSelectedParticles(List<Particle> particles)
- {
- var deletedParticles = new List<Particle>();
- foreach (DataGridViewRow row in dgV_ParticlesDevidePage.SelectedRows)
- {
- if (row.Cells[2].Value is Bitmap bitmap && bitmap.Tag is List<string> tagList)
- {
- int fieldId = Convert.ToInt32(tagList[0]);
- int particleId = Convert.ToInt32(tagList[1]);
- Particle particleToDelete = particles.FirstOrDefault(p =>
- p.FieldId == fieldId && p.ParticleId == particleId);
- if (particleToDelete != null &&
- DeleteParticlesFromSTDDb(particleToDelete.ParticleId, particleToDelete.FieldId))
- {
- RemoveParticleFromDataTable(particleToDelete);
- deletedParticles.Add(particleToDelete);
- }
- else
- {
- MessageBox.Show("Delete failed");
- break;
- }
- }
- }
- UpdateUIAfterDeletion(deletedParticles.Count);
- //SynchronizeParticleDeletion(deletedParticles);
- }
- private void RemoveParticleFromDataTable(Particle particle)
- {
- for (int i = particlesAll.Rows.Count - 1; i >= 0; i--)
- {
- if (particlesAll.Rows[i]["Fieldid"].ToString() == particle.FieldId.ToString() &&
- particlesAll.Rows[i]["Particleid"].ToString() == particle.ParticleId.ToString())
- {
- particlesAll.Rows.RemoveAt(i);
- break;
- }
- }
- }
- private void UpdateUIAfterDeletion(int deletedCount)
- {
- RecordCount = recordCount - deletedCount;
- lblTotalCount.Text = RecordCount.ToString();
- // Remove rows from grid (in reverse order to avoid index issues)
- var rowsToRemove = dgV_ParticlesDevidePage.SelectedRows.Cast<DataGridViewRow>().ToList();
- foreach (var row in rowsToRemove)
- {
- dgV_ParticlesDevidePage.Rows.Remove(row);
- }
- if (dgV_ParticlesDevidePage.Rows.Count == 0)
- {
- DisplayData();
- }
- else
- {
- // Update row numbers
- for (int j = 0; j < dgV_ParticlesDevidePage.Rows.Count; j++)
- {
- dgV_ParticlesDevidePage.Rows[j].Cells[0].Value =
- (pageSize * (PageIndex - 1) + j + 1).ToString();
- }
- }
- }
- private void SynchronizeParticleDeletion(List<Particle> deletedParticles)
- {
- if (m_ReportApp.im_Control_DrawDistrbutionImageAndBSE != null)
- {
- m_ReportApp.im_Control_DrawDistrbutionImageAndBSE.DeletesParticlesSynchronously(deletedParticles);
- }
- else
- {
- using (var control = new OTSIncAReportGraph.Controls.Control_DrawDistrbutionImageAndBSE(m_ReportApp))
- {
- foreach (var particle in deletedParticles)
- {
- control.DeleteParticlesFromSTDDb(particle.ParticleId, particle.FieldId);
- }
- }
- }
- }
- private bool DeleteParticlesFromSTDDb(int particleId, int fieldId)
- {
- if (!CheckAndCreateBackup())
- return false;
- //防止为空校验判断
- if (result.GetList_OTSField() == null)
- return false;
- try
- {
- //Particle particle = result.GetList_OTSField()
- // .Find(x => x.FieldID == fieldId)?
- // .ParticleList.Find(x => x.ParticleId == particleId);
- //if (particle == null)
- // return false;
- var particleData = new ParticleData(result.FilePath);
- return particleData.DeleteFromData(
- Convert.ToString(fieldId),
- Convert.ToString(particleId));
- }
- catch (Exception ex)
- {
- log.Error($"Error deleting particle: {ex.Message}");
- return false;
- }
- }
- private bool CheckAndCreateBackup()
- {
- bool backupExists = Enumerable.Range(1, 200).Any(i =>
- Directory.Exists(Path.Combine(result.FilePath, "FIELD_FILES", "Backups" + i)));
- if (!backupExists)
- {
- return BackupDatabase();
- }
- return true;
- }
- private bool BackupDatabase()
- {
- try
- {
- //创建备份数据库文件夹
- string sourcePath = Path.Combine(result.FilePath, "FIELD_FILES", "Inclusion.db");
- string sourceName = "Inclusion.db";
- string folderPath = Path.Combine(result.FilePath, "FIELD_FILES", "Backups");
- string backupFolder = "";
- for (int i = 1; i <= 200; i++)
- {
- string currentPath = Path.Combine(folderPath, i.ToString());
- if (!Directory.Exists(currentPath))
- {
- Directory.CreateDirectory(currentPath);
- backupFolder = currentPath;
- break;
- }
- }
- if (string.IsNullOrEmpty(backupFolder))
- {
- return false;
- }
- //复制数据库文件
- string targetPath = Path.Combine(backupFolder, sourceName);
- File.Copy(sourcePath, targetPath, true);
- return true;
- }
- catch (Exception ex)
- {
- log.Error($"Error backing up database: {ex.Message}");
- return false;
- }
- }
- #endregion
- #region 报表输出
- /// <summary>
- ///
- /// </summary>
- /// <param name="str_resultPath"></param>
- /// <param name="dataTable"></param>
- /// <param name="vs"></param>
- /// <param name="dt_FIeld"></param>
- public void Out_MarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable,
- out List<string> vs, out DataTable dt_FIeld)
- {
- Init();
- var fieldIds = ExtractFieldIds(dataTable);
- string str_path_FIELD_FILES = Path.Combine(str_resultPath, "FIELD_FILES");
- dt_FIeld = new DataTable();
- vs = new List<string>();
- ResultFile resfile = m_ReportApp.m_rstDataMgr.ResultFilesList[
- m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
- float pixelSize = resfile.GetPixelSize();
- float scanFieldSizeX = resfile.GetScanFieldSizeX();
- int gauge = RulerSelection(scanFieldSizeX);
- float rulerPixels = gauge / pixelSize;
- var fieldData = new FieldData(resfile.FilePath);
- DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
- var directoryInfo = new DirectoryInfo(str_path_FIELD_FILES);
- if (directoryInfo.Exists)
- {
- ProcessFieldFiles(directoryInfo, fieldIds, dataTable, dt_AllParticle,
- rulerPixels, gauge, ref dt_FIeld, vs);
- }
- }
- private List<string> ExtractFieldIds(DataTable dataTable)
- {
- return dataTable.AsEnumerable()
- .Where(row => Convert.ToInt32(row["TypeId"]) > 9)
- .Take(10)
- .Select(row => row["Fieldid"].ToString())
- .Distinct()
- .ToList();
- }
- private void ProcessFieldFiles(DirectoryInfo directoryInfo, List<string> fieldIds,
- DataTable dataTable, DataTable allParticles, float rulerPixels, int gauge,
- ref DataTable dt_FIeld, List<string> vs)
- {
- var fieldFiles = directoryInfo.GetFiles("Field*.bmp")
- .ToDictionary(f => GetFieldIdFromFile(f.Name), f => f,
- StringComparer.OrdinalIgnoreCase);
- var resultTable = CreateFieldDataTable();
- foreach (string fieldId in fieldIds.Where(id => fieldFiles.ContainsKey(id)))
- {
- var file = fieldFiles[fieldId];
- int count = dataTable.AsEnumerable()
- .Count(row => row["fieldid"].ToString() == fieldId);
- DataRow dr = resultTable.NewRow();
- dr["fieldid"] = $" fieldid = {fieldId}";
- dr["cunt"] = count;
- dr["fieldName"] = file.Name;
- dr["fieldFullName"] = file.FullName;
- dr["id"] = fieldId;
- resultTable.Rows.Add(dr);
- }
- dt_FIeld = resultTable.Copy();
- dt_FIeld.Columns.Add("Field_pic", typeof(Bitmap));
- ProcessFieldImages(allParticles, rulerPixels, gauge, dt_FIeld, vs);
- }
- private string GetFieldIdFromFile(string fileName)
- {
- string nameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
- return nameWithoutExtension.Length > 5 ?
- nameWithoutExtension.Substring(5) : nameWithoutExtension;
- }
- private DataTable CreateFieldDataTable()
- {
- var dt = new DataTable();
- dt.Columns.Add("fieldid");
- dt.Columns.Add("id");
- dt.Columns.Add("fieldName");
- dt.Columns.Add("cunt", typeof(int));
- dt.Columns.Add("fieldFullName");
- return dt;
- }
- private void ProcessFieldImages(DataTable allParticles, float rulerPixels, int gauge,
- DataTable dt_FIeld, List<string> vs)
- {
- var particleGroups = allParticles.AsEnumerable()
- .GroupBy(row => row["fieldid"].ToString())
- .ToDictionary(g => g.Key, g => g.ToList());
- foreach (DataRow row in dt_FIeld.Rows.Cast<DataRow>().ToList())
- {
- string fieldId = row["id"].ToString();
- if (!particleGroups.ContainsKey(fieldId) ||
- particleGroups[fieldId].Count == 0)
- continue;
- vs.Add(fieldId);
- try
- {
- using (var img = Image.FromFile(row["fieldFullName"].ToString()))
- {
- using (var fieldBitmap = new Bitmap(img.Width, img.Height,
- System.Drawing.Imaging.PixelFormat.Format32bppArgb))
- {
- DrawBaseImage(img, fieldBitmap);
- MarkParticlesOnImage(particleGroups[fieldId], fieldBitmap,
- row, fieldId, rulerPixels, gauge);
- }
- }
- }
- catch (Exception ex)
- {
- log.Error($"Error processing field image: {ex.Message}");
- }
- }
- }
- private void DrawBaseImage(Image sourceImage, Bitmap targetBitmap)
- {
- using (Graphics g = Graphics.FromImage(targetBitmap))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
- g.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height));
- }
- }
- private void MarkParticlesOnImage(List<DataRow> particles, Bitmap fieldBitmap,
- DataRow fieldRow, string fieldId, float rulerPixels, int gauge)
- {
- foreach (DataRow particleRow in particles)
- {
- string particleId = particleRow["particleid"].ToString();
- var rectangle = new Rectangle(
- Convert.ToInt32(particleRow["RectLeft"]),
- Convert.ToInt32(particleRow["RectTop"]),
- Convert.ToInt32(particleRow["RectWidth"]),
- Convert.ToInt32(particleRow["RectHeight"])
- );
- MarkParticleOnImage(fieldBitmap, rectangle, fieldId, particleId);
- }
- using (var rulerBitmap = DrawRuler(fieldBitmap, (int)(rulerPixels / 2), 2,
- $"{gauge / 2}μm"))
- {
- fieldRow["Field_pic"] = new Bitmap(rulerBitmap);
- }
- }
- private void MarkParticleOnImage(Bitmap fieldBitmap, Rectangle rectangle,
- string fieldId, string particleId)
- {
- using (Graphics g = Graphics.FromImage(fieldBitmap))
- using (var pen = new Pen(Color.Aquamarine))
- {
- g.DrawRectangle(pen, rectangle);
- int textX = rectangle.X + rectangle.Width > fieldBitmap.Width - 10 ?
- rectangle.X - 10 : rectangle.X + rectangle.Width;
- using (var font = new Font("黑体", 8))
- using (var brush = new SolidBrush(Color.Aqua))
- {
- g.DrawString($"{fieldId} {particleId}", font, brush,
- new PointF(textX, rectangle.Y));
- }
- }
- }
- /// <summary>
- /// 在图片上绘制标尺
- /// </summary>
- /// <param name="bitmap">图片</param>
- /// <param name="lineLength">线长(像素)</param>
- /// <param name="lineWidth">线宽(像素)</param>
- /// <param name="text">显示文本</param>
- /// <returns></returns>
- private Bitmap DrawRuler(Bitmap bitmap, int lineLength, int lineWidth, string text)
- {
- if (bitmap == null)
- throw new ArgumentNullException(nameof(bitmap));
- var rgbBitmap = new Bitmap(bitmap.Width, bitmap.Height);
- using (Graphics graphics = Graphics.FromImage(rgbBitmap))
- {
- graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
- Color color = Color.LimeGreen;
- using (var pen = new Pen(color, lineWidth))
- using (var font = new Font("Arial", 20, GraphicsUnit.Pixel))
- using (var brush = new SolidBrush(color))
- {
- var stringFormat = new StringFormat
- {
- Alignment = StringAlignment.Center,
- LineAlignment = StringAlignment.Center
- };
- int startX = 20;
- int startY = bitmap.Height - 30;
- graphics.DrawLine(pen, startX, startY, startX + lineLength, startY);
- graphics.DrawString(text, font, brush,
- new PointF(startX + lineLength / 2, startY - 20), stringFormat);
- }
- }
- return rgbBitmap;
- }
- private int RulerSelection(float scanFieldSizeX)
- {
- // 根据扫描场尺寸选择合适的标尺单位
- if (scanFieldSizeX >= 1000) return 1000;
- if (scanFieldSizeX >= 500) return 500;
- if (scanFieldSizeX >= 200) return 200;
- if (scanFieldSizeX >= 100) return 100;
- if (scanFieldSizeX >= 50) return 50;
- if (scanFieldSizeX >= 20) return 20;
- if (scanFieldSizeX >= 10) return 10;
- if (scanFieldSizeX >= 5) return 5;
- if (scanFieldSizeX >= 2) return 2;
- return 1;
- }
- #endregion
- }
- }
|