123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using PaintDotNet;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.DedicatedAnalysis.DuctileIron.Common;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Metis.AutoAnalysis
- {
- class ReportExporter
- {
- public RulerModel rulerModel;//标尺样式信息
- public int lineLength = 1;//标尺长度
- public bool getLengthFromConfig = true;//是否从配置文件获取长度
- private Form m_form;
- public Form form
- {
- set
- {
- m_form = value;
- }
- }
- //标志
- public mic_rulers xmlSaveModel;//存储标尺信息(xml或者预览拍摄选中标尺)
- /// <summary>
- /// 换算完的标尺信息,包含所有系统内得单位
- /// </summary>
- public Dictionary<MeasurementUnit, double> rules = new Dictionary<MeasurementUnit, double>();
-
- public ReportExporter()
- {
- InitRulerInfo();
- }
- private void InitRulerInfo()
- {
- this.rulerModel = Startup.instance.rulerModel;
- this.xmlSaveModel = Startup.instance.ruleDB;
- List<mic_rulers> mic_rulersAll = new List<mic_rulers>();
- if (this.xmlSaveModel == null && mic_rulersAll.Count > 0)
- this.xmlSaveModel = mic_rulersAll[0];
- this.rules.Clear();
- if (this.xmlSaveModel != null && this.xmlSaveModel.pixel_length != 0)
- {
- //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
- double unitLength = (double)(this.xmlSaveModel.physical_length / (decimal)this.xmlSaveModel.pixel_length);
- switch (this.xmlSaveModel.ruler_units)
- {
- case (int)MeasurementUnit.Inch://英寸
- this.rules.Add(MeasurementUnit.Inch, unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, 1000 * unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, 2.54 * unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, 25.4 * unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, 25400 * unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, 25400000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Mil://米尔
- this.rules.Add(MeasurementUnit.Inch, 0.001 * unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, 0.00254 * unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, 0.0254 * unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, 25.4 * unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, 25400 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Centimeter://厘米
- this.rules.Add(MeasurementUnit.Inch, 0.3937008 * unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, 393.7008 * unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, 10 * unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, 10000 * unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, 10000000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Millimeter://毫米
- this.rules.Add(MeasurementUnit.Inch, 0.0393701 * unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, 39.3701 * unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, 0.1 * unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, 1000 * unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, 1000000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Micron://微米
- this.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Nano://纳米
- this.rules.Add(MeasurementUnit.Inch, 3.9370e-8 * unitLength); //英寸
- this.rules.Add(MeasurementUnit.Mil, 3.9370e-5 * unitLength); //米尔
- this.rules.Add(MeasurementUnit.Centimeter, 1e-7 * unitLength); //厘米
- this.rules.Add(MeasurementUnit.Millimeter, 1e-6 * unitLength); //毫米
- this.rules.Add(MeasurementUnit.Micron, 0.001 * unitLength); //微米
- this.rules.Add(MeasurementUnit.Nano, unitLength); //纳米
- break;
- default:
- this.xmlSaveModel = null;
- break;
- }
- }
- }
- public void CreateGrainReport(List<AutoAnalyzeSettingModel> lstModel, List<List<Bitmap>> bitmapList,string lblResult)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- if (lstModel.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
- return;
- }
- var m = lstModel[0];
- if (string.IsNullOrEmpty(m.savePath))
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
- return;
- }
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- //当前图片微米标尺(点距计算用毫米)
- double unitLength = 0;
- //当前图片放大倍数
- double pointPitch = 0;
- this.rules.TryGetValue(MeasurementUnit.Micron, out unitLength);
- //获取当前图片放大倍数
- pointPitch = (double)this.xmlSaveModel.gain_multiple;
- bool isNeedZoom = true;
- if (unitLength == 0)
- unitLength = 1;
- try
- {
- int count = lstModel.Count;
- for (int i = 0; i < count; i++)
- {
- var model = lstModel[i];
- var bitLit = bitmapList[i];
- OfficeFileOperater.CreateAnalysisReport(model, new List<List<string>>(), bitLit, new Dictionary<string, string>(), isNeedZoom, pointPitch, unitLength, this.xmlSaveModel.gain_multiple, lblResult, null, null, null);
- }
-
- procClass.DismissProgressAction(this.m_form);
- //MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
- }
- finally
- {
- procClass.DismissProgressAction(this.m_form);
- }
- };
- procClass.StartProgressAutoAction(this.m_form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
- }
- public void CreateAnalysisReport(AutoAnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
- Dictionary<string, string> tagPositionDic, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
- {
- AppCommon appCommon = new AppCommon();
- if (!appCommon.isExcelInstalled())
- {
- MessageBox.Show(PdnResources.GetString("office.Message"));
- return;
- }
- if (analyzeSettingModel == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
- return;
- }
- if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
- {
- MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
- return;
- }
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- //当前图片微米标尺(点距计算用毫米)
- double unitLength = 0;
- //当前图片放大倍数
- double pointPitch = 0;
- this.rules.TryGetValue(MeasurementUnit.Micron, out unitLength);
- //获取当前图片放大倍数
- pointPitch = (double)this.xmlSaveModel.gain_multiple;
- bool isNeedZoom = true;
- if (unitLength == 0)
- unitLength = 1;
- try
- {
- OfficeFileOperater.CreateAnalysisReport(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, this.xmlSaveModel.gain_multiple,"", dictPath, pNames, content2List);
- procClass.DismissProgressAction(this.m_form);
- //MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
- }
- finally
- {
- procClass.DismissProgressAction(this.m_form);
- }
- };
- procClass.StartProgressAutoAction(this.m_form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
- }
- }
- }
|