ReportExporter.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using PaintDotNet;
  2. using PaintDotNet.Base.Functionodel;
  3. using PaintDotNet.Base.SettingModel;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using PaintDotNet.DedicatedAnalysis.DuctileIron.Common;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace Metis.AutoAnalysis
  14. {
  15. class ReportExporter
  16. {
  17. public RulerModel rulerModel;//标尺样式信息
  18. public int lineLength = 1;//标尺长度
  19. public bool getLengthFromConfig = true;//是否从配置文件获取长度
  20. private Form m_form;
  21. public Form form
  22. {
  23. set
  24. {
  25. m_form = value;
  26. }
  27. }
  28. //标志
  29. public mic_rulers xmlSaveModel;//存储标尺信息(xml或者预览拍摄选中标尺)
  30. /// <summary>
  31. /// 换算完的标尺信息,包含所有系统内得单位
  32. /// </summary>
  33. public Dictionary<MeasurementUnit, double> rules = new Dictionary<MeasurementUnit, double>();
  34. public ReportExporter()
  35. {
  36. InitRulerInfo();
  37. }
  38. private void InitRulerInfo()
  39. {
  40. this.rulerModel = Startup.instance.rulerModel;
  41. this.xmlSaveModel = Startup.instance.ruleDB;
  42. List<mic_rulers> mic_rulersAll = new List<mic_rulers>();
  43. if (this.xmlSaveModel == null && mic_rulersAll.Count > 0)
  44. this.xmlSaveModel = mic_rulersAll[0];
  45. this.rules.Clear();
  46. if (this.xmlSaveModel != null && this.xmlSaveModel.pixel_length != 0)
  47. {
  48. //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  49. double unitLength = (double)(this.xmlSaveModel.physical_length / (decimal)this.xmlSaveModel.pixel_length);
  50. switch (this.xmlSaveModel.ruler_units)
  51. {
  52. case (int)MeasurementUnit.Inch://英寸
  53. this.rules.Add(MeasurementUnit.Inch, unitLength); //英寸
  54. this.rules.Add(MeasurementUnit.Mil, 1000 * unitLength); //米尔
  55. this.rules.Add(MeasurementUnit.Centimeter, 2.54 * unitLength); //厘米
  56. this.rules.Add(MeasurementUnit.Millimeter, 25.4 * unitLength); //毫米
  57. this.rules.Add(MeasurementUnit.Micron, 25400 * unitLength); //微米
  58. this.rules.Add(MeasurementUnit.Nano, 25400000 * unitLength); //纳米
  59. break;
  60. case (int)MeasurementUnit.Mil://米尔
  61. this.rules.Add(MeasurementUnit.Inch, 0.001 * unitLength); //英寸
  62. this.rules.Add(MeasurementUnit.Mil, unitLength); //米尔
  63. this.rules.Add(MeasurementUnit.Centimeter, 0.00254 * unitLength); //厘米
  64. this.rules.Add(MeasurementUnit.Millimeter, 0.0254 * unitLength); //毫米
  65. this.rules.Add(MeasurementUnit.Micron, 25.4 * unitLength); //微米
  66. this.rules.Add(MeasurementUnit.Nano, 25400 * unitLength); //纳米
  67. break;
  68. case (int)MeasurementUnit.Centimeter://厘米
  69. this.rules.Add(MeasurementUnit.Inch, 0.3937008 * unitLength); //英寸
  70. this.rules.Add(MeasurementUnit.Mil, 393.7008 * unitLength); //米尔
  71. this.rules.Add(MeasurementUnit.Centimeter, unitLength); //厘米
  72. this.rules.Add(MeasurementUnit.Millimeter, 10 * unitLength); //毫米
  73. this.rules.Add(MeasurementUnit.Micron, 10000 * unitLength); //微米
  74. this.rules.Add(MeasurementUnit.Nano, 10000000 * unitLength); //纳米
  75. break;
  76. case (int)MeasurementUnit.Millimeter://毫米
  77. this.rules.Add(MeasurementUnit.Inch, 0.0393701 * unitLength); //英寸
  78. this.rules.Add(MeasurementUnit.Mil, 39.3701 * unitLength); //米尔
  79. this.rules.Add(MeasurementUnit.Centimeter, 0.1 * unitLength); //厘米
  80. this.rules.Add(MeasurementUnit.Millimeter, unitLength); //毫米
  81. this.rules.Add(MeasurementUnit.Micron, 1000 * unitLength); //微米
  82. this.rules.Add(MeasurementUnit.Nano, 1000000 * unitLength); //纳米
  83. break;
  84. case (int)MeasurementUnit.Micron://微米
  85. this.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  86. this.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
  87. this.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  88. this.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  89. this.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  90. this.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  91. break;
  92. case (int)MeasurementUnit.Nano://纳米
  93. this.rules.Add(MeasurementUnit.Inch, 3.9370e-8 * unitLength); //英寸
  94. this.rules.Add(MeasurementUnit.Mil, 3.9370e-5 * unitLength); //米尔
  95. this.rules.Add(MeasurementUnit.Centimeter, 1e-7 * unitLength); //厘米
  96. this.rules.Add(MeasurementUnit.Millimeter, 1e-6 * unitLength); //毫米
  97. this.rules.Add(MeasurementUnit.Micron, 0.001 * unitLength); //微米
  98. this.rules.Add(MeasurementUnit.Nano, unitLength); //纳米
  99. break;
  100. default:
  101. this.xmlSaveModel = null;
  102. break;
  103. }
  104. }
  105. }
  106. public void CreateGrainReport(List<AutoAnalyzeSettingModel> lstModel, List<List<Bitmap>> bitmapList,string lblResult)
  107. {
  108. AppCommon appCommon = new AppCommon();
  109. if (!appCommon.isExcelInstalled())
  110. {
  111. MessageBox.Show(PdnResources.GetString("office.Message"));
  112. return;
  113. }
  114. if (lstModel.Count == 0)
  115. {
  116. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  117. return;
  118. }
  119. var m = lstModel[0];
  120. if (string.IsNullOrEmpty(m.savePath))
  121. {
  122. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  123. return;
  124. }
  125. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  126. System.Threading.ThreadStart copyThreadProc =
  127. delegate ()
  128. {
  129. //当前图片微米标尺(点距计算用毫米)
  130. double unitLength = 0;
  131. //当前图片放大倍数
  132. double pointPitch = 0;
  133. this.rules.TryGetValue(MeasurementUnit.Micron, out unitLength);
  134. //获取当前图片放大倍数
  135. pointPitch = (double)this.xmlSaveModel.gain_multiple;
  136. bool isNeedZoom = true;
  137. if (unitLength == 0)
  138. unitLength = 1;
  139. try
  140. {
  141. int count = lstModel.Count;
  142. for (int i = 0; i < count; i++)
  143. {
  144. var model = lstModel[i];
  145. var bitLit = bitmapList[i];
  146. OfficeFileOperater.CreateAnalysisReport(model, new List<List<string>>(), bitLit, new Dictionary<string, string>(), isNeedZoom, pointPitch, unitLength, this.xmlSaveModel.gain_multiple, lblResult, null, null, null);
  147. }
  148. procClass.DismissProgressAction(this.m_form);
  149. //MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  150. }
  151. catch (Exception)
  152. {
  153. MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
  154. }
  155. finally
  156. {
  157. procClass.DismissProgressAction(this.m_form);
  158. }
  159. };
  160. procClass.StartProgressAutoAction(this.m_form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
  161. }
  162. public void CreateAnalysisReport(AutoAnalyzeSettingModel analyzeSettingModel, List<List<string>> contentList, List<Bitmap> bitmapList,
  163. Dictionary<string, string> tagPositionDic, string dictPath = null, Dictionary<string, string> pNames = null, List<List<string>> content2List = null)
  164. {
  165. AppCommon appCommon = new AppCommon();
  166. if (!appCommon.isExcelInstalled())
  167. {
  168. MessageBox.Show(PdnResources.GetString("office.Message"));
  169. return;
  170. }
  171. if (analyzeSettingModel == null)
  172. {
  173. MessageBox.Show(PdnResources.GetString("Menu.setthetemplate.Text"));
  174. return;
  175. }
  176. if (string.IsNullOrEmpty(analyzeSettingModel.savePath))
  177. {
  178. MessageBox.Show(PdnResources.GetString("Menu.setthepath.Text"));
  179. return;
  180. }
  181. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  182. System.Threading.ThreadStart copyThreadProc =
  183. delegate ()
  184. {
  185. //当前图片微米标尺(点距计算用毫米)
  186. double unitLength = 0;
  187. //当前图片放大倍数
  188. double pointPitch = 0;
  189. this.rules.TryGetValue(MeasurementUnit.Micron, out unitLength);
  190. //获取当前图片放大倍数
  191. pointPitch = (double)this.xmlSaveModel.gain_multiple;
  192. bool isNeedZoom = true;
  193. if (unitLength == 0)
  194. unitLength = 1;
  195. try
  196. {
  197. OfficeFileOperater.CreateAnalysisReport(analyzeSettingModel, contentList, bitmapList, tagPositionDic, isNeedZoom, pointPitch, unitLength, this.xmlSaveModel.gain_multiple,"", dictPath, pNames, content2List);
  198. procClass.DismissProgressAction(this.m_form);
  199. //MessageBox.Show(PdnResources.GetString("Menu.Analysisreporfoldertoview.text"));
  200. }
  201. catch (Exception)
  202. {
  203. MessageBox.Show(PdnResources.GetString("Menu.newdefit.Text"));
  204. }
  205. finally
  206. {
  207. procClass.DismissProgressAction(this.m_form);
  208. }
  209. };
  210. procClass.StartProgressAutoAction(this.m_form, new System.Threading.ThreadStart(copyThreadProc), PdnResources.GetString("Menu.Tools.CreateReport.Text"));
  211. }
  212. }
  213. }