PolyphaseContentDialog.cs 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. using OpenCvSharp;
  2. using OpenCvSharp.Extensions;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.CustomControl;
  5. using PaintDotNet.Data.Param;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Windows.Forms;
  12. using PaintDotNet.DbOpreate.DbBll;
  13. using PaintDotNet.DbOpreate.DbModel;
  14. using PaintDotNet.Base.CommTool;
  15. using System.Data;
  16. using System.IO;
  17. using PaintDotNet.Instrument;
  18. using Metis.ParameterSet;
  19. using PaintDotNet.Base;
  20. namespace PaintDotNet.GeneralAnalysis
  21. {
  22. /// <summary>
  23. /// 两相面积含量
  24. /// </summary>
  25. internal class PolyphaseContentDialog : PdnBaseForm
  26. {
  27. /// <summary>
  28. /// 主空间
  29. /// </summary>
  30. private AppWorkspace appWorkspace;
  31. /// <summary>
  32. /// 图像面板
  33. /// </summary>
  34. private DocumentWorkspaceWindow documentWorkspace;
  35. private DocumentWorkspaceWindow tmpDocumentWorkspace;
  36. /// <summary>
  37. /// 选中图片的mat
  38. /// </summary>
  39. private Mat imageMat;
  40. private List<PolyphaseAnalysisResult> polyphaseAnalysisResults = new List<PolyphaseAnalysisResult>();
  41. private List<PolyphaseAnalysisResult> viewPolyphaseAnalysisResults = new List<PolyphaseAnalysisResult>();
  42. private List<PolyphaseAnalysisResult> mainPolyphaseAnalysisResults = new List<PolyphaseAnalysisResult>();
  43. /// <summary>
  44. /// 处理程序
  45. /// </summary>
  46. private ParamObject action = new Data.Action.Action901();
  47. /// <summary>
  48. /// 当前选择的图片index
  49. /// </summary>
  50. int selectIndex = 0;
  51. int decnum = 2;
  52. private CommonControlButtons commonControlButtons;
  53. private int is_all = 0;
  54. private List<Bitmap> bitList = new List<Bitmap>();
  55. private Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
  56. private int imgIndex = -1;
  57. private GeneralAnalysisModel generalAnalysisModel = new GeneralAnalysisModel();
  58. private bool isExportResults = false;
  59. private bool isExportReports = false;
  60. private bool isExportProjects = false;
  61. /// <summary>
  62. /// 是否脚本运行
  63. /// </summary>
  64. private Boolean initScriptValues = false;
  65. private int menuId;
  66. private string menuName;
  67. #region 控件
  68. private System.Windows.Forms.GroupBox groupBox4;
  69. private System.Windows.Forms.ListView listView1;
  70. private System.Windows.Forms.GroupBox groupBox1;
  71. private System.Windows.Forms.Button button2;
  72. private System.Windows.Forms.CheckBox checkBox1;
  73. private System.Windows.Forms.Button button1;
  74. private System.Windows.Forms.GroupBox groupBox2;
  75. private System.Windows.Forms.GroupBox groupBox_review;
  76. private System.Windows.Forms.GroupBox groupBox5;
  77. private System.Windows.Forms.GroupBox groupBox6;
  78. private System.Windows.Forms.GroupBox groupBox7;
  79. private System.Windows.Forms.Label label1;
  80. private System.Windows.Forms.Button button4;
  81. private System.Windows.Forms.Button button3;
  82. private System.Windows.Forms.DataGridView dataGridView1;
  83. private System.Windows.Forms.ImageList imageList1;
  84. private GroupBox groupBox3;
  85. private Label label5;
  86. private Label label4;
  87. private Label label3;
  88. private DataGridView dataGridView_results;
  89. private Label lbl_content;
  90. private Label lbl_area;
  91. private Label lbl_rate;
  92. private Button button_remove;
  93. private Button button_all;
  94. private Button button5;
  95. private NumericUpDown numericUpDown1;
  96. private DataGridViewTextBoxColumn Column1;
  97. private DataGridViewTextBoxColumn Column2;
  98. private DataGridViewTextBoxColumn Column3;
  99. private DataGridViewTextBoxColumn Column4;
  100. private Button button9;
  101. private CheckedListBox listBox_analysisResult;
  102. private DataGridViewTextBoxColumn Column5;
  103. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
  104. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
  105. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
  106. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
  107. private IContainer components;
  108. #endregion
  109. public PolyphaseContentDialog()
  110. {
  111. InitializeComponent();
  112. }
  113. public PolyphaseContentDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem)
  114. {
  115. InitializeComponent();
  116. InitializeLanguageText();
  117. this.appWorkspace = appWorkspace;
  118. this.menuId = menuItem.MenuId;
  119. this.menuName = menuItem.Text;
  120. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  121. this.documentWorkspace.Dock = DockStyle.Fill;
  122. this.documentWorkspace.HookMouseEvents();
  123. this.documentWorkspace.AuxiliaryLineEnabled = false;
  124. this.documentWorkspace.Visible = false;
  125. tmpDocumentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  126. this.groupBox_review.Controls.Add(documentWorkspace);
  127. this.commonControlButtons = new CommonControlButtons();
  128. this.commonControlButtons.Dock = DockStyle.Top;
  129. this.commonControlButtons.Height = 30;
  130. this.commonControlButtons.HideZoomToWindowAndActualSize();
  131. this.groupBox_review.Controls.Add(commonControlButtons);
  132. InitPicList();
  133. CalcProcess();
  134. this.listView1.SelectedIndexChanged += new EventHandler(this.ListViewSelectedIndexChanged);
  135. SetAnalyzeModelFromXml("Template.Manager.item2.PolyphaseContent");
  136. SetStyle(ControlStyles.UserPaint, true);
  137. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  138. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
  139. InitCommonButtonEvent();
  140. this.Shown += showImg;
  141. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData);
  142. }
  143. private void showImg(object sender, EventArgs e)
  144. {
  145. listView1.Focus();
  146. if (this.imgIndex != -1)
  147. {
  148. //滚动到指定的行位置
  149. this.listView1.EnsureVisible(this.imgIndex);
  150. this.listView1.Items[imgIndex].Focused = true;
  151. this.listView1.Items[imgIndex].Selected = true;
  152. //如果是脚本执行,将参数带入
  153. if (appWorkspace.ScriptRunning && appWorkspace.ScriptCurrentParam != null)
  154. {
  155. this.initScriptValues = true;//ScriptAutomatic
  156. //Boolean initScriptValues = true;
  157. ////在这里反射出对应功能的参数类
  158. string className = InvariantData.path_Action + ".Action" + menuId;
  159. ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  160. foreach (Args arg in param.Lists)
  161. {
  162. Args param1 = appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
  163. if (param1.value != null)
  164. arg.Value = param1.value;
  165. getValue(arg.key, arg.Value);
  166. }
  167. appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
  168. }
  169. else
  170. {//读取上次关闭窗口时保存的参数
  171. getLastData();
  172. }
  173. if (this.initScriptValues && this.appWorkspace.ScriptAutomatic)
  174. this.startScriptAutomaticAction();
  175. }
  176. }
  177. /// <summary>
  178. /// 获取上次操作参数
  179. /// </summary>
  180. private void getLastData()
  181. {
  182. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
  183. if (!System.IO.File.Exists(filePath))
  184. {
  185. generalAnalysisModel = new GeneralAnalysisModel();
  186. generalAnalysisModel.PolyphaseMutiAreaContentModels = new GeneralAnalysisModel.PolyphaseMutiAreaContentModel();
  187. generalAnalysisModel.PolyphaseCounterAnalysisModels = new GeneralAnalysisModel.PolyphaseCounterAnalysisModel();
  188. generalAnalysisModel.TwoPhaseScaleModels = new GeneralAnalysisModel.TwoPhaseScaleModel();
  189. generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel();
  190. generalAnalysisModel.PolyphaseDistanceModels = new GeneralAnalysisModel.PolyphaseDistanceModel();
  191. generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel();
  192. generalAnalysisModel.CountNumberAnalysisModels = new GeneralAnalysisModel.CountNumberAnalysisModel();
  193. generalAnalysisModel.PolyphaseMutiAreaContentModels.hasUsed = false;
  194. generalAnalysisModel.PolyphaseCounterAnalysisModels.hasUsed = false;
  195. generalAnalysisModel.TwoPhaseScaleModels.hasUsed = false;
  196. generalAnalysisModel.PolyphaseContentModels.hasUsed = false;
  197. generalAnalysisModel.PolyphaseDistanceModels.hasUsed = false;
  198. generalAnalysisModel.DebrisSelectionModels.hasUsed = false;
  199. generalAnalysisModel.CountNumberAnalysisModels.hasUsed = false;
  200. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<GeneralAnalysisModel>(generalAnalysisModel);
  201. Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\");
  202. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew);
  203. }
  204. else
  205. {
  206. generalAnalysisModel = XmlSerializeHelper.DESerializer<GeneralAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  207. if (generalAnalysisModel.PolyphaseContentModels == null) {
  208. generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel();
  209. }
  210. if (generalAnalysisModel.PolyphaseContentModels.hasUsed)
  211. {
  212. numericUpDown1.Value = generalAnalysisModel.PolyphaseContentModels.parameter1;
  213. checkBox1.Checked = generalAnalysisModel.PolyphaseContentModels.parameter2;
  214. }
  215. }
  216. }
  217. /// <summary>
  218. /// 保存上次操作参数
  219. /// </summary>
  220. private void saveLastData(object sender, EventArgs e)
  221. {
  222. #region [开启脚本录制]
  223. if (appWorkspace.startScriptRecording)
  224. {
  225. getScriptRecording();
  226. }
  227. #endregion
  228. if (generalAnalysisModel.PolyphaseContentModels == null)
  229. {
  230. generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel();
  231. }
  232. generalAnalysisModel.PolyphaseContentModels.hasUsed = true;
  233. generalAnalysisModel.PolyphaseContentModels.parameter1 = (int)numericUpDown1.Value;
  234. generalAnalysisModel.PolyphaseContentModels.parameter2 = checkBox1.Checked;
  235. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
  236. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<GeneralAnalysisModel>(generalAnalysisModel);
  237. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create);
  238. }
  239. private void PolyphaseContentDialog_Load(object sender, EventArgs e)
  240. {
  241. }
  242. #region 公共按钮
  243. private void InitCommonButtonEvent()
  244. {
  245. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  246. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  247. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  248. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  249. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  250. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  251. }
  252. private void zoomInButton_Click(object sender, EventArgs e)
  253. {
  254. if(this.imageMat != null)
  255. this.documentWorkspace.ZoomIn();
  256. }
  257. private void zoomOutButton_Click(object sender, EventArgs e)
  258. {
  259. if (this.imageMat != null)
  260. this.documentWorkspace.ZoomOut();
  261. }
  262. private void zoomToWindowButton_Click(object sender, EventArgs e)
  263. {
  264. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  265. }
  266. private void actualSizeButton_Click(object sender, EventArgs e)
  267. {
  268. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  269. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  270. }
  271. private void pointerButton_Click(object sender, EventArgs e)
  272. {
  273. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  274. }
  275. private void mobileModeButton_Click(object sender, EventArgs e)
  276. {
  277. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  278. }
  279. #endregion
  280. /// <summary>
  281. /// 初始化图片列表数据
  282. /// </summary>
  283. //public void InitPicList()
  284. //{
  285. // //初始化图片列表
  286. // for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  287. // {
  288. // this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  289. // this.listView1.Items.Add("", i);
  290. // this.listView1.Items[i].ImageIndex = i;
  291. // this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  292. // this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  293. // }
  294. //}
  295. public void InitPicList()
  296. {
  297. //初始化图片列表
  298. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  299. {
  300. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail);
  301. this.listView1.Items.Add("", i);
  302. this.listView1.Items[i].ImageIndex = i;
  303. String imageName = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  304. if (listView1.Items.Find(imageName, false).Count() > 0)
  305. {
  306. if (imageName.Split('.').Count() > 1)
  307. {
  308. imageName = imageName.Split('.')[0] + "(" + listView1.Items.Find(imageName, false).Count() + ")." + imageName.Split('.')[1];
  309. }
  310. }
  311. this.listView1.Items[i].Text = imageName;
  312. this.listView1.Items[i].Name = imageName;
  313. if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  314. {
  315. this.imgIndex = i;
  316. }
  317. }
  318. }
  319. /// <summary>
  320. /// ListView图片选择改变事件
  321. /// </summary>
  322. /// <param name="sender"></param>
  323. /// <param name="e"></param>
  324. private void ListViewSelectedIndexChanged(object sender, EventArgs e)
  325. {
  326. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  327. {
  328. this.imageMat = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat();
  329. Document document = Document.FromImageMat(imageMat.Clone());
  330. this.documentWorkspace.Document = document;
  331. this.documentWorkspace.Visible = true;
  332. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList;
  333. this.documentWorkspace.phaseModels = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].phaseModels;
  334. //tmpDocumentWorkspace.Document = document;
  335. //tmpDocumentWorkspace.Visible = true;
  336. //tmpDocumentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList;
  337. //tmpDocumentWorkspace.phaseModels = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].phaseModels;
  338. this.applyButtonImpl(sender, e);
  339. //获取显示直方图
  340. //pdnRegion = new PdnRegion(AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].Document.Bounds);
  341. //this.histogramControl1.Histogram.UpdateHistogram(AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].SurfaceBox.Surface, pdnRegion);
  342. }
  343. }
  344. private void CalcProcess()
  345. {
  346. //for (int selectIndex = 0; selectIndex < this.appWorkspace.DocumentWorkspaces.Count(); selectIndex++)
  347. //{
  348. //}
  349. }
  350. /// <summary>
  351. /// 参数改变时,重新处理图像
  352. /// </summary>
  353. /// <param name="sender"></param>
  354. /// <param name="e"></param>
  355. private void applyButtonImpl(object sender, EventArgs e)
  356. {
  357. //double pxPerUnit = Startup.instance.rules[MeasurementUnit.Micron];
  358. double pxPerUnit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  359. if (this.listView1.FocusedItem != null)
  360. {
  361. dataGridView1.Rows.Clear();
  362. mainPolyphaseAnalysisResults.Clear();
  363. selectIndex = this.listView1.FocusedItem.Index;
  364. //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理
  365. if (this.appWorkspace.DocumentWorkspaces[selectIndex].GraphicsList.IsExsitView())
  366. {
  367. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels.Count; i++)
  368. {
  369. PhaseModel pModel = this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels[i];
  370. if (pModel.choise)
  371. {
  372. Color pColor = new Color();
  373. pColor = Color.FromArgb(pModel.color);
  374. Mat front = pModel.mat;
  375. //相总面积
  376. int phaseAmount = AnalysisTools.GetPointsFromMat(front);
  377. //视图中相面积
  378. Bitmap frontTarget = this.documentWorkspace.GetFullSizeWithRegion(front.ToBitmap());
  379. //frontTarget.Save("D:\\1-1.bmp");
  380. //获取视图中相的点合计
  381. //int frontAmount = AnalysisTools.GetPointsFromMat(PaintDotNet.Camera.Tools.ToMat(frontTarget));
  382. Mat background = this.imageMat.Clone();
  383. Mat roi = new Mat(background, new Rect(0, 0, background.Width, background.Height));
  384. Mat mask = Mat.FromImageData(front.ToBytes(), ImreadModes.Grayscale);
  385. front.CopyTo(roi, mask);
  386. Bitmap target = this.documentWorkspace.GetFullSizeWithRegion(background.ToBitmap());
  387. Mat targetMat = PaintDotNet.Camera.Tools.ToMat(target);
  388. targetMat.SaveImage("D:\\2.bmp");
  389. //获取合并后视场内的点合计
  390. int allAmount = AnalysisTools.GetPointsFromMat(targetMat);
  391. int picAmount = AnalysisTools.GetPointsFromMat(background);
  392. double cRate = 0f;
  393. //计算比例
  394. //视场内部存在相
  395. //if (viewAmount > 0)
  396. //{
  397. //}
  398. //else
  399. //{
  400. // //视场内部不存在相
  401. // cRate = (double)phaseAmount / allAmount;
  402. //}
  403. cRate = (double)phaseAmount / allAmount;
  404. //计算面积
  405. double cArea = phaseAmount;
  406. //计算相含量
  407. double fRate = (double)phaseAmount / picAmount;
  408. //dataGridView1.Rows.Add(this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels[i].name, cArea, cRate, fRate);
  409. PolyphaseAnalysisResult pResult = new PolyphaseAnalysisResult();
  410. pResult.GraphName = this.listView1.FocusedItem.Text;
  411. pResult.PolyphaseName = this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels[i].name;
  412. pResult.PolyphaseArea = cArea * pxPerUnit * pxPerUnit;
  413. pResult.PolyphaseRate = cRate * 100;
  414. pResult.PolyphaseAllRate = fRate * 100;
  415. mainPolyphaseAnalysisResults.Add(pResult);
  416. dataGridView1.Rows.Add(pResult.PolyphaseName, AnalysisTools.GetDecNum(pResult.PolyphaseArea, decnum) , AnalysisTools.GetDecNum(pResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseAllRate, decnum));
  417. }
  418. }
  419. }
  420. else
  421. {
  422. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels.Count; i++)
  423. {
  424. PhaseModel pModel = this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels[i];
  425. if (pModel.choise)
  426. {
  427. Color pColor = new Color();
  428. pColor = Color.FromArgb(pModel.color);
  429. int phaseArea = AnalysisTools.GetPointsFromMat(pModel.mat);
  430. Mat sourceMat = this.imageMat.Clone();
  431. int picAmount = AnalysisTools.GetPointsFromMat(sourceMat);
  432. //计算面积
  433. double cRate = (double)phaseArea / picAmount;
  434. PolyphaseAnalysisResult pResult = new PolyphaseAnalysisResult();
  435. pResult.GraphName = this.listView1.FocusedItem.Text;
  436. pResult.PolyphaseName = this.appWorkspace.DocumentWorkspaces[selectIndex].phaseModels[i].name;
  437. pResult.PolyphaseArea = phaseArea * pxPerUnit * pxPerUnit;
  438. pResult.PolyphaseRate = cRate * 100;
  439. pResult.PolyphaseAllRate = cRate * 100;
  440. mainPolyphaseAnalysisResults.Add(pResult);
  441. dataGridView1.Rows.Add(pResult.PolyphaseName, AnalysisTools.GetDecNum(pResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseAllRate, decnum));
  442. }
  443. }
  444. }
  445. show_avg();
  446. }
  447. }
  448. #region InitializeComponent
  449. private void InitializeLanguageText()
  450. {
  451. this.Column2.HeaderText = PdnResources.GetString("Menu.Phasearea.text");
  452. this.Column3.HeaderText = PdnResources.GetString("Menu.proportion.text") + "%";
  453. this.Column4.HeaderText = PdnResources.GetString("Menu.Phasecontent.text") + "%";
  454. this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text");
  455. this.groupBox5.Text = PdnResources.GetString("Menu.Analysisresult.text");
  456. this.button_remove.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  457. this.button_all.Text = PdnResources.GetString("Menu.Showall.text");
  458. this.Column5.HeaderText = PdnResources.GetString("Menu.picture.Text");
  459. this.dataGridViewTextBoxColumn1.HeaderText = PdnResources.GetString("Menu.Phasename.text");
  460. this.label4.Text = PdnResources.GetString("Menu.Phasearea.text") + ":";
  461. this.label3.Text = PdnResources.GetString("Menu.proportion.text") + "% :";
  462. this.Text = PdnResources.GetString("Menu.GeneralAnalysis.TwoPhaseArea.Text");
  463. this.dataGridViewTextBoxColumn2.HeaderText = PdnResources.GetString("Menu.Phasearea.text");
  464. this.dataGridViewTextBoxColumn3.HeaderText = PdnResources.GetString("Menu.proportion.text") + "%";
  465. this.dataGridViewTextBoxColumn4.HeaderText = PdnResources.GetString("Menu.Phasecontent.text") + "%";
  466. this.button9.Text = PdnResources.GetString("Menu.Tools.OpenProject.Text");
  467. this.label1.Text = PdnResources.GetString("Menu.Decimal.text");
  468. this.button4.Text = PdnResources.GetString("Menu.Exportresults.text");
  469. this.button3.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
  470. this.groupBox3.Text = PdnResources.GetString("Menu.Averageresult.text");
  471. this.label5.Text = PdnResources.GetString("Menu.Phasecontent.text") + "% :";
  472. this.groupBox4.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  473. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  474. this.button5.Text = PdnResources.GetString("Menu.File.Close.Text");
  475. this.button2.Text = PdnResources.GetString("Menu.Saveresult.text");
  476. this.checkBox1.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
  477. this.button1.Text = PdnResources.GetString("Menu.Setting.Text");
  478. this.groupBox2.Text = PdnResources.GetString("Menu.Resultspreview.text");
  479. this.Column1.HeaderText = PdnResources.GetString("Menu.Phasename.text");
  480. }
  481. private void InitializeComponent()
  482. {
  483. this.components = new System.ComponentModel.Container();
  484. this.groupBox4 = new System.Windows.Forms.GroupBox();
  485. this.listView1 = new System.Windows.Forms.ListView();
  486. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  487. this.groupBox1 = new System.Windows.Forms.GroupBox();
  488. this.button5 = new System.Windows.Forms.Button();
  489. this.button2 = new System.Windows.Forms.Button();
  490. this.checkBox1 = new System.Windows.Forms.CheckBox();
  491. this.button1 = new System.Windows.Forms.Button();
  492. this.groupBox2 = new System.Windows.Forms.GroupBox();
  493. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  494. this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  495. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  496. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  497. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  498. this.groupBox_review = new System.Windows.Forms.GroupBox();
  499. this.groupBox5 = new System.Windows.Forms.GroupBox();
  500. this.listBox_analysisResult = new System.Windows.Forms.CheckedListBox();
  501. this.button_remove = new System.Windows.Forms.Button();
  502. this.button_all = new System.Windows.Forms.Button();
  503. this.groupBox6 = new System.Windows.Forms.GroupBox();
  504. this.dataGridView_results = new System.Windows.Forms.DataGridView();
  505. this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  506. this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  507. this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  508. this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  509. this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  510. this.groupBox7 = new System.Windows.Forms.GroupBox();
  511. this.button9 = new System.Windows.Forms.Button();
  512. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  513. this.label1 = new System.Windows.Forms.Label();
  514. this.button4 = new System.Windows.Forms.Button();
  515. this.button3 = new System.Windows.Forms.Button();
  516. this.groupBox3 = new System.Windows.Forms.GroupBox();
  517. this.lbl_content = new System.Windows.Forms.Label();
  518. this.lbl_area = new System.Windows.Forms.Label();
  519. this.lbl_rate = new System.Windows.Forms.Label();
  520. this.label5 = new System.Windows.Forms.Label();
  521. this.label4 = new System.Windows.Forms.Label();
  522. this.label3 = new System.Windows.Forms.Label();
  523. this.groupBox4.SuspendLayout();
  524. this.groupBox1.SuspendLayout();
  525. this.groupBox2.SuspendLayout();
  526. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  527. this.groupBox5.SuspendLayout();
  528. this.groupBox6.SuspendLayout();
  529. ((System.ComponentModel.ISupportInitialize)(this.dataGridView_results)).BeginInit();
  530. this.groupBox7.SuspendLayout();
  531. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  532. this.groupBox3.SuspendLayout();
  533. this.SuspendLayout();
  534. //
  535. // groupBox4
  536. //
  537. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  538. | System.Windows.Forms.AnchorStyles.Left)));
  539. this.groupBox4.Controls.Add(this.listView1);
  540. this.groupBox4.Location = new System.Drawing.Point(13, 72);
  541. this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
  542. this.groupBox4.Name = "groupBox4";
  543. this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
  544. this.groupBox4.Size = new System.Drawing.Size(158, 483);
  545. this.groupBox4.TabIndex = 9;
  546. this.groupBox4.TabStop = false;
  547. this.groupBox4.Text = "图像索引";
  548. //
  549. // listView1
  550. //
  551. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  552. | System.Windows.Forms.AnchorStyles.Left)
  553. | System.Windows.Forms.AnchorStyles.Right)));
  554. this.listView1.HideSelection = false;
  555. this.listView1.LargeImageList = this.imageList1;
  556. this.listView1.Location = new System.Drawing.Point(8, 26);
  557. this.listView1.Margin = new System.Windows.Forms.Padding(4);
  558. this.listView1.MultiSelect = false;
  559. this.listView1.Name = "listView1";
  560. this.listView1.Size = new System.Drawing.Size(140, 449);
  561. this.listView1.TabIndex = 0;
  562. this.listView1.UseCompatibleStateImageBehavior = false;
  563. this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  564. //
  565. // imageList1
  566. //
  567. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  568. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  569. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  570. //
  571. // groupBox1
  572. //
  573. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  574. | System.Windows.Forms.AnchorStyles.Right)));
  575. this.groupBox1.Controls.Add(this.button5);
  576. this.groupBox1.Controls.Add(this.button2);
  577. this.groupBox1.Controls.Add(this.checkBox1);
  578. this.groupBox1.Controls.Add(this.button1);
  579. this.groupBox1.Location = new System.Drawing.Point(20, 12);
  580. this.groupBox1.Name = "groupBox1";
  581. this.groupBox1.Size = new System.Drawing.Size(1145, 53);
  582. this.groupBox1.TabIndex = 10;
  583. this.groupBox1.TabStop = false;
  584. this.groupBox1.Text = "操作";
  585. //
  586. // button5
  587. //
  588. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  589. this.button5.Location = new System.Drawing.Point(956, 21);
  590. this.button5.Name = "button5";
  591. this.button5.Size = new System.Drawing.Size(75, 23);
  592. this.button5.TabIndex = 3;
  593. this.button5.Text = "关闭";
  594. this.button5.UseVisualStyleBackColor = true;
  595. this.button5.Click += new System.EventHandler(this.button5_Click);
  596. //
  597. // button2
  598. //
  599. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  600. this.button2.Location = new System.Drawing.Point(1053, 21);
  601. this.button2.Name = "button2";
  602. this.button2.Size = new System.Drawing.Size(75, 23);
  603. this.button2.TabIndex = 2;
  604. this.button2.Text = "保存结果";
  605. this.button2.UseVisualStyleBackColor = true;
  606. this.button2.Click += new System.EventHandler(this.button2_Click);
  607. //
  608. // checkBox1
  609. //
  610. this.checkBox1.AutoSize = true;
  611. this.checkBox1.Location = new System.Drawing.Point(98, 24);
  612. this.checkBox1.Name = "checkBox1";
  613. this.checkBox1.Size = new System.Drawing.Size(132, 16);
  614. this.checkBox1.TabIndex = 1;
  615. this.checkBox1.Text = "生成报告时打开设置";
  616. this.checkBox1.UseVisualStyleBackColor = true;
  617. //
  618. // button1
  619. //
  620. this.button1.Location = new System.Drawing.Point(6, 24);
  621. this.button1.Name = "button1";
  622. this.button1.Size = new System.Drawing.Size(75, 23);
  623. this.button1.TabIndex = 0;
  624. this.button1.Text = "设置";
  625. this.button1.UseVisualStyleBackColor = true;
  626. this.button1.Click += new System.EventHandler(this.button1_Click);
  627. //
  628. // groupBox2
  629. //
  630. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  631. | System.Windows.Forms.AnchorStyles.Left)));
  632. this.groupBox2.Controls.Add(this.dataGridView1);
  633. this.groupBox2.Location = new System.Drawing.Point(178, 72);
  634. this.groupBox2.Name = "groupBox2";
  635. this.groupBox2.Size = new System.Drawing.Size(406, 347);
  636. this.groupBox2.TabIndex = 11;
  637. this.groupBox2.TabStop = false;
  638. this.groupBox2.Text = "结果预览";
  639. //
  640. // dataGridView1
  641. //
  642. this.dataGridView1.AllowUserToAddRows = false;
  643. this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
  644. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  645. this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  646. this.Column1,
  647. this.Column2,
  648. this.Column3,
  649. this.Column4});
  650. this.dataGridView1.Location = new System.Drawing.Point(6, 26);
  651. this.dataGridView1.Name = "dataGridView1";
  652. this.dataGridView1.RowHeadersVisible = false;
  653. this.dataGridView1.RowHeadersWidth = 51;
  654. this.dataGridView1.RowTemplate.Height = 27;
  655. this.dataGridView1.Size = new System.Drawing.Size(394, 444);
  656. this.dataGridView1.TabIndex = 0;
  657. //
  658. // Column1
  659. //
  660. this.Column1.MinimumWidth = 6;
  661. this.Column1.Name = "Column1";
  662. this.Column1.Width = 70;
  663. //
  664. // Column2
  665. //
  666. this.Column2.MinimumWidth = 6;
  667. this.Column2.Name = "Column2";
  668. this.Column2.Width = 90;
  669. //
  670. // Column3
  671. //
  672. this.Column3.MinimumWidth = 6;
  673. this.Column3.Name = "Column3";
  674. this.Column3.Width = 125;
  675. //
  676. // Column4
  677. //
  678. this.Column4.MinimumWidth = 6;
  679. this.Column4.Name = "Column4";
  680. this.Column4.Width = 125;
  681. //
  682. // groupBox_review
  683. //
  684. this.groupBox_review.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  685. | System.Windows.Forms.AnchorStyles.Left)
  686. | System.Windows.Forms.AnchorStyles.Right)));
  687. this.groupBox_review.Location = new System.Drawing.Point(590, 72);
  688. this.groupBox_review.Name = "groupBox_review";
  689. this.groupBox_review.Size = new System.Drawing.Size(575, 483);
  690. this.groupBox_review.TabIndex = 12;
  691. this.groupBox_review.TabStop = false;
  692. this.groupBox_review.Text = "预览";
  693. //
  694. // groupBox5
  695. //
  696. this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  697. this.groupBox5.Controls.Add(this.listBox_analysisResult);
  698. this.groupBox5.Controls.Add(this.button_remove);
  699. this.groupBox5.Controls.Add(this.button_all);
  700. this.groupBox5.Location = new System.Drawing.Point(12, 562);
  701. this.groupBox5.Name = "groupBox5";
  702. this.groupBox5.Size = new System.Drawing.Size(224, 165);
  703. this.groupBox5.TabIndex = 13;
  704. this.groupBox5.TabStop = false;
  705. this.groupBox5.Text = "分析结果";
  706. //
  707. // listBox_analysisResult
  708. //
  709. this.listBox_analysisResult.CheckOnClick = true;
  710. this.listBox_analysisResult.FormattingEnabled = true;
  711. this.listBox_analysisResult.HorizontalScrollbar = true;
  712. this.listBox_analysisResult.Location = new System.Drawing.Point(11, 53);
  713. this.listBox_analysisResult.Name = "listBox_analysisResult";
  714. this.listBox_analysisResult.Size = new System.Drawing.Size(202, 100);
  715. this.listBox_analysisResult.TabIndex = 10;
  716. this.listBox_analysisResult.SelectedIndexChanged += new System.EventHandler(this.listBox_analysisResult_SelectedIndexChanged);
  717. //
  718. // button_remove
  719. //
  720. this.button_remove.Location = new System.Drawing.Point(130, 24);
  721. this.button_remove.Name = "button_remove";
  722. this.button_remove.Size = new System.Drawing.Size(75, 23);
  723. this.button_remove.TabIndex = 8;
  724. this.button_remove.Text = "删除";
  725. this.button_remove.UseVisualStyleBackColor = true;
  726. this.button_remove.Click += new System.EventHandler(this.button_remove_Click);
  727. //
  728. // button_all
  729. //
  730. this.button_all.Location = new System.Drawing.Point(14, 24);
  731. this.button_all.Name = "button_all";
  732. this.button_all.Size = new System.Drawing.Size(75, 23);
  733. this.button_all.TabIndex = 1;
  734. this.button_all.Text = "全部显示";
  735. this.button_all.UseVisualStyleBackColor = true;
  736. this.button_all.Click += new System.EventHandler(this.button_all_Click);
  737. //
  738. // groupBox6
  739. //
  740. this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  741. | System.Windows.Forms.AnchorStyles.Right)));
  742. this.groupBox6.Controls.Add(this.dataGridView_results);
  743. this.groupBox6.Location = new System.Drawing.Point(257, 562);
  744. this.groupBox6.Name = "groupBox6";
  745. this.groupBox6.Size = new System.Drawing.Size(678, 165);
  746. this.groupBox6.TabIndex = 14;
  747. this.groupBox6.TabStop = false;
  748. //
  749. // dataGridView_results
  750. //
  751. this.dataGridView_results.AllowUserToAddRows = false;
  752. this.dataGridView_results.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  753. | System.Windows.Forms.AnchorStyles.Right)));
  754. this.dataGridView_results.BorderStyle = System.Windows.Forms.BorderStyle.None;
  755. this.dataGridView_results.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  756. this.dataGridView_results.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  757. this.Column5,
  758. this.dataGridViewTextBoxColumn1,
  759. this.dataGridViewTextBoxColumn2,
  760. this.dataGridViewTextBoxColumn3,
  761. this.dataGridViewTextBoxColumn4});
  762. this.dataGridView_results.Location = new System.Drawing.Point(16, 29);
  763. this.dataGridView_results.Name = "dataGridView_results";
  764. this.dataGridView_results.RowHeadersVisible = false;
  765. this.dataGridView_results.RowHeadersWidth = 51;
  766. this.dataGridView_results.RowTemplate.Height = 27;
  767. this.dataGridView_results.Size = new System.Drawing.Size(645, 130);
  768. this.dataGridView_results.TabIndex = 1;
  769. //
  770. // Column5
  771. //
  772. this.Column5.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  773. this.Column5.HeaderText = "Column5";
  774. this.Column5.MinimumWidth = 6;
  775. this.Column5.Name = "Column5";
  776. //
  777. // dataGridViewTextBoxColumn1
  778. //
  779. this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  780. this.dataGridViewTextBoxColumn1.HeaderText = "dataGridViewTextBoxColumn1";
  781. this.dataGridViewTextBoxColumn1.MinimumWidth = 6;
  782. this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
  783. //
  784. // dataGridViewTextBoxColumn2
  785. //
  786. this.dataGridViewTextBoxColumn2.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  787. this.dataGridViewTextBoxColumn2.HeaderText = "dataGridViewTextBoxColumn2";
  788. this.dataGridViewTextBoxColumn2.MinimumWidth = 6;
  789. this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
  790. //
  791. // dataGridViewTextBoxColumn3
  792. //
  793. this.dataGridViewTextBoxColumn3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  794. this.dataGridViewTextBoxColumn3.HeaderText = "dataGridViewTextBoxColumn3";
  795. this.dataGridViewTextBoxColumn3.MinimumWidth = 6;
  796. this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
  797. //
  798. // dataGridViewTextBoxColumn4
  799. //
  800. this.dataGridViewTextBoxColumn4.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  801. this.dataGridViewTextBoxColumn4.HeaderText = "dataGridViewTextBoxColumn4";
  802. this.dataGridViewTextBoxColumn4.MinimumWidth = 6;
  803. this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
  804. //
  805. // groupBox7
  806. //
  807. this.groupBox7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  808. this.groupBox7.Controls.Add(this.button9);
  809. this.groupBox7.Controls.Add(this.numericUpDown1);
  810. this.groupBox7.Controls.Add(this.label1);
  811. this.groupBox7.Controls.Add(this.button4);
  812. this.groupBox7.Controls.Add(this.button3);
  813. this.groupBox7.Location = new System.Drawing.Point(941, 562);
  814. this.groupBox7.Name = "groupBox7";
  815. this.groupBox7.Size = new System.Drawing.Size(224, 165);
  816. this.groupBox7.TabIndex = 15;
  817. this.groupBox7.TabStop = false;
  818. this.groupBox7.Enter += new System.EventHandler(this.groupBox7_Enter);
  819. //
  820. // button9
  821. //
  822. this.button9.Location = new System.Drawing.Point(19, 88);
  823. this.button9.Name = "button9";
  824. this.button9.Size = new System.Drawing.Size(141, 23);
  825. this.button9.TabIndex = 9;
  826. this.button9.Text = "项目工程";
  827. this.button9.UseVisualStyleBackColor = true;
  828. this.button9.Click += new System.EventHandler(this.button9_Click);
  829. //
  830. // numericUpDown1
  831. //
  832. this.numericUpDown1.Location = new System.Drawing.Point(66, 122);
  833. this.numericUpDown1.Maximum = new decimal(new int[] {
  834. 10,
  835. 0,
  836. 0,
  837. 0});
  838. this.numericUpDown1.Name = "numericUpDown1";
  839. this.numericUpDown1.Size = new System.Drawing.Size(94, 21);
  840. this.numericUpDown1.TabIndex = 4;
  841. this.numericUpDown1.Value = new decimal(new int[] {
  842. 2,
  843. 0,
  844. 0,
  845. 0});
  846. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  847. //
  848. // label1
  849. //
  850. this.label1.AutoSize = true;
  851. this.label1.Location = new System.Drawing.Point(17, 126);
  852. this.label1.Name = "label1";
  853. this.label1.Size = new System.Drawing.Size(41, 12);
  854. this.label1.TabIndex = 3;
  855. this.label1.Text = "小数:";
  856. //
  857. // button4
  858. //
  859. this.button4.Location = new System.Drawing.Point(19, 54);
  860. this.button4.Name = "button4";
  861. this.button4.Size = new System.Drawing.Size(141, 23);
  862. this.button4.TabIndex = 1;
  863. this.button4.Text = "导出结果";
  864. this.button4.UseVisualStyleBackColor = true;
  865. this.button4.Click += new System.EventHandler(this.button4_Click);
  866. //
  867. // button3
  868. //
  869. this.button3.Location = new System.Drawing.Point(19, 20);
  870. this.button3.Name = "button3";
  871. this.button3.Size = new System.Drawing.Size(141, 23);
  872. this.button3.TabIndex = 0;
  873. this.button3.Text = "生成报告";
  874. this.button3.UseVisualStyleBackColor = true;
  875. this.button3.Click += new System.EventHandler(this.button3_Click);
  876. //
  877. // groupBox3
  878. //
  879. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  880. this.groupBox3.Controls.Add(this.lbl_content);
  881. this.groupBox3.Controls.Add(this.lbl_area);
  882. this.groupBox3.Controls.Add(this.lbl_rate);
  883. this.groupBox3.Controls.Add(this.label5);
  884. this.groupBox3.Controls.Add(this.label4);
  885. this.groupBox3.Controls.Add(this.label3);
  886. this.groupBox3.Location = new System.Drawing.Point(184, 439);
  887. this.groupBox3.Name = "groupBox3";
  888. this.groupBox3.Size = new System.Drawing.Size(394, 116);
  889. this.groupBox3.TabIndex = 16;
  890. this.groupBox3.TabStop = false;
  891. //
  892. // lbl_content
  893. //
  894. this.lbl_content.AutoSize = true;
  895. this.lbl_content.Location = new System.Drawing.Point(239, 60);
  896. this.lbl_content.Name = "lbl_content";
  897. this.lbl_content.Size = new System.Drawing.Size(0, 12);
  898. this.lbl_content.TabIndex = 7;
  899. //
  900. // lbl_area
  901. //
  902. this.lbl_area.AutoSize = true;
  903. this.lbl_area.Location = new System.Drawing.Point(76, 26);
  904. this.lbl_area.Name = "lbl_area";
  905. this.lbl_area.Size = new System.Drawing.Size(0, 12);
  906. this.lbl_area.TabIndex = 6;
  907. //
  908. // lbl_rate
  909. //
  910. this.lbl_rate.AutoSize = true;
  911. this.lbl_rate.Location = new System.Drawing.Point(73, 60);
  912. this.lbl_rate.Name = "lbl_rate";
  913. this.lbl_rate.Size = new System.Drawing.Size(0, 12);
  914. this.lbl_rate.TabIndex = 5;
  915. //
  916. // label5
  917. //
  918. this.label5.AutoSize = true;
  919. this.label5.Location = new System.Drawing.Point(179, 61);
  920. this.label5.Name = "label5";
  921. this.label5.Size = new System.Drawing.Size(0, 12);
  922. this.label5.TabIndex = 3;
  923. //
  924. // label4
  925. //
  926. this.label4.AutoSize = true;
  927. this.label4.Location = new System.Drawing.Point(16, 26);
  928. this.label4.Name = "label4";
  929. this.label4.Size = new System.Drawing.Size(0, 12);
  930. this.label4.TabIndex = 2;
  931. //
  932. // label3
  933. //
  934. this.label3.AutoSize = true;
  935. this.label3.Location = new System.Drawing.Point(16, 61);
  936. this.label3.Name = "label3";
  937. this.label3.Size = new System.Drawing.Size(0, 12);
  938. this.label3.TabIndex = 1;
  939. //
  940. // PolyphaseContentDialog
  941. //
  942. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  943. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  944. this.ClientSize = new System.Drawing.Size(1177, 744);
  945. this.Controls.Add(this.groupBox3);
  946. this.Controls.Add(this.groupBox7);
  947. this.Controls.Add(this.groupBox6);
  948. this.Controls.Add(this.groupBox5);
  949. this.Controls.Add(this.groupBox_review);
  950. this.Controls.Add(this.groupBox2);
  951. this.Controls.Add(this.groupBox1);
  952. this.Controls.Add(this.groupBox4);
  953. this.Name = "PolyphaseContentDialog";
  954. this.Text = "两相面积含量";
  955. this.Load += new System.EventHandler(this.PolyphaseContentDialog_Load);
  956. this.Controls.SetChildIndex(this.groupBox4, 0);
  957. this.Controls.SetChildIndex(this.groupBox1, 0);
  958. this.Controls.SetChildIndex(this.groupBox2, 0);
  959. this.Controls.SetChildIndex(this.groupBox_review, 0);
  960. this.Controls.SetChildIndex(this.groupBox5, 0);
  961. this.Controls.SetChildIndex(this.groupBox6, 0);
  962. this.Controls.SetChildIndex(this.groupBox7, 0);
  963. this.Controls.SetChildIndex(this.groupBox3, 0);
  964. this.groupBox4.ResumeLayout(false);
  965. this.groupBox1.ResumeLayout(false);
  966. this.groupBox1.PerformLayout();
  967. this.groupBox2.ResumeLayout(false);
  968. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  969. this.groupBox5.ResumeLayout(false);
  970. this.groupBox6.ResumeLayout(false);
  971. ((System.ComponentModel.ISupportInitialize)(this.dataGridView_results)).EndInit();
  972. this.groupBox7.ResumeLayout(false);
  973. this.groupBox7.PerformLayout();
  974. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  975. this.groupBox3.ResumeLayout(false);
  976. this.groupBox3.PerformLayout();
  977. this.ResumeLayout(false);
  978. }
  979. #endregion
  980. private void show_avg()
  981. {
  982. if (listView1.FocusedItem != null)
  983. {
  984. var results = mainPolyphaseAnalysisResults.Where(p => p.GraphName.Equals(listView1.FocusedItem.Text));
  985. if (results.Count() > 0)
  986. {
  987. lbl_area.Text = AnalysisTools.GetDecNum(results.Average(item => item.PolyphaseArea), decnum);
  988. lbl_rate.Text = AnalysisTools.GetDecNum(results.Average(item => item.PolyphaseRate), decnum);
  989. lbl_content.Text = AnalysisTools.GetDecNum(results.Average(item => item.PolyphaseAllRate), decnum);
  990. }
  991. }
  992. }
  993. private void button2_Click(object sender, EventArgs e)
  994. {
  995. if (listView1.SelectedItems.Count == 0)
  996. {
  997. MessageBox.Show(PdnResources.GetString("Menu.seselecttheimagethatyouwanttoan.Text")+"!");
  998. return;
  999. }
  1000. if (dataGridView1.Rows.Count == 0)
  1001. {
  1002. MessageBox.Show("结果为空!");
  1003. return;
  1004. }
  1005. String tag = listView1.FocusedItem.Text;
  1006. List<Bitmap> tempBit = new List<Bitmap>();
  1007. if (listView1.FocusedItem != null)
  1008. {
  1009. if (polyphaseAnalysisResults.FindAll(item => item.GraphName.Equals(listView1.FocusedItem.Text)).Count == 0)
  1010. {
  1011. listBox_analysisResult.Items.Add(this.listView1.FocusedItem.Text);
  1012. listBox_analysisResult.SetItemChecked(listBox_analysisResult.Items.Count - 1, true);
  1013. for (int i = 0; i < mainPolyphaseAnalysisResults.Count; i++)
  1014. {
  1015. PolyphaseAnalysisResult aResult = mainPolyphaseAnalysisResults[i];
  1016. polyphaseAnalysisResults.Add(aResult);
  1017. viewPolyphaseAnalysisResults.Add(aResult);
  1018. dataGridView_results.Rows.Add(aResult.GraphName, aResult.PolyphaseName, AnalysisTools.GetDecNum(aResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseAllRate, decnum));
  1019. }
  1020. }
  1021. else
  1022. {
  1023. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Form.OkButton.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1024. if (dr != DialogResult.OK)
  1025. {
  1026. return;
  1027. }
  1028. viewPolyphaseAnalysisResults.RemoveAll(u => u.GraphName == listView1.FocusedItem.Text);
  1029. polyphaseAnalysisResults.RemoveAll(u => u.GraphName == listView1.FocusedItem.Text);
  1030. polyphaseAnalysisResults.AddRange(mainPolyphaseAnalysisResults);
  1031. viewPolyphaseAnalysisResults.AddRange(mainPolyphaseAnalysisResults);
  1032. List<string> list = new List<string>();
  1033. foreach (var s in this.listBox_analysisResult.Items)
  1034. {
  1035. list.Add(s.ToString());
  1036. }
  1037. this.listBox_analysisResult.Items.Clear();
  1038. foreach (var s in list)
  1039. {
  1040. this.listBox_analysisResult.Items.Add(s);
  1041. }
  1042. var thisindex = this.listBox_analysisResult.Items.IndexOf(listView1.FocusedItem.Text);
  1043. this.dataGridView_results.Rows.Clear();
  1044. listBox_analysisResult.SetItemChecked(thisindex, true);
  1045. for (int i = 0; i < mainPolyphaseAnalysisResults.Count; i++)
  1046. {
  1047. PolyphaseAnalysisResult aResult = mainPolyphaseAnalysisResults[i];
  1048. dataGridView_results.Rows.Add(aResult.GraphName, aResult.PolyphaseName, AnalysisTools.GetDecNum(aResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseAllRate, decnum));
  1049. }
  1050. }
  1051. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1052. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1053. originalBit.Tag = pantographRatio;
  1054. tempBit.Add(originalBit);
  1055. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1056. Graphics graphics = Graphics.FromImage(newBit);
  1057. Draw(graphics);
  1058. newBit.Tag = pantographRatio;
  1059. tempBit.Add(newBit);
  1060. if (bitDic.ContainsKey(tag))
  1061. {
  1062. bitDic[tag].Clear();
  1063. bitDic[tag] = tempBit;
  1064. }
  1065. else
  1066. {
  1067. bitDic.Add(tag, tempBit);
  1068. }
  1069. }
  1070. }
  1071. private void Draw(Graphics graphics)
  1072. {
  1073. if (this.documentWorkspace.phaseModels.Count > 0)
  1074. {
  1075. foreach (PhaseModel model in this.documentWorkspace.phaseModels)
  1076. {
  1077. if (model.choise && model.mat != null)
  1078. {
  1079. Bitmap map = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(model.mat);
  1080. graphics.DrawImage(map, 0, 0, map.Width, map.Height);
  1081. }
  1082. }
  1083. }
  1084. }
  1085. private void button_all_Click(object sender, EventArgs e)
  1086. {
  1087. dataGridView_results.Rows.Clear();
  1088. if (this.is_all % 2 == 0)
  1089. {
  1090. for (int i = 0; i < listBox_analysisResult.Items.Count; i++)
  1091. {
  1092. listBox_analysisResult.SetItemChecked(i, false);
  1093. }
  1094. }
  1095. else {
  1096. for (int i = 0; i < listBox_analysisResult.Items.Count; i++)
  1097. {
  1098. listBox_analysisResult.SetItemChecked(i, true);
  1099. }
  1100. viewPolyphaseAnalysisResults.Clear();
  1101. viewPolyphaseAnalysisResults.AddRange(polyphaseAnalysisResults);
  1102. for (int i = 0; i < viewPolyphaseAnalysisResults.Count; i++)
  1103. {
  1104. PolyphaseAnalysisResult aResult = viewPolyphaseAnalysisResults[i];
  1105. dataGridView_results.Rows.Add(aResult.GraphName, aResult.PolyphaseName, aResult.PolyphaseArea, AnalysisTools.GetDecNum(aResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseAllRate, decnum));
  1106. }
  1107. }
  1108. this.is_all += 1;
  1109. }
  1110. private void button_remove_Click(object sender, EventArgs e)
  1111. {
  1112. var removeList = new List<string>();
  1113. if (listBox_analysisResult.CheckedItems != null && listBox_analysisResult.CheckedItems.Count > 0)
  1114. {
  1115. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.ertodeletetheselectedanalysisres.Text")+"?", PdnResources.GetString("Menu.Edit.Delete.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1116. if (dr == DialogResult.OK)
  1117. {
  1118. dataGridView_results.Rows.Clear();
  1119. foreach (var s in listBox_analysisResult.CheckedItems)
  1120. {
  1121. polyphaseAnalysisResults.RemoveAll(u => u.GraphName == s.ToString());
  1122. viewPolyphaseAnalysisResults.RemoveAll(u => u.GraphName == s.ToString());
  1123. removeList.Add(s.ToString());
  1124. }
  1125. for (int i = 0; i < viewPolyphaseAnalysisResults.Count; i++)
  1126. {
  1127. PolyphaseAnalysisResult aResult = viewPolyphaseAnalysisResults[i];
  1128. dataGridView_results.Rows.Add(aResult.GraphName, aResult.PolyphaseName, aResult.PolyphaseArea, AnalysisTools.GetDecNum(aResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseAllRate, decnum));
  1129. }
  1130. foreach (var m in removeList)
  1131. {
  1132. listBox_analysisResult.Items.Remove(m);
  1133. }
  1134. }
  1135. }
  1136. else
  1137. {
  1138. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecttheimagetodelete.Text")+"!");
  1139. }
  1140. }
  1141. private void listBox_analysisResult_SelectedIndexChanged(object sender, EventArgs e)
  1142. {
  1143. dataGridView_results.Rows.Clear();
  1144. if (listBox_analysisResult.CheckedItems != null && listBox_analysisResult.CheckedItems.Count > 0)
  1145. {
  1146. foreach (var s in listBox_analysisResult.CheckedItems)
  1147. {
  1148. List<PolyphaseAnalysisResult> findResults = polyphaseAnalysisResults.FindAll(item => item.GraphName.Equals(s.ToString()));
  1149. viewPolyphaseAnalysisResults.Clear();
  1150. viewPolyphaseAnalysisResults.AddRange(findResults);
  1151. for (int i = 0; i < viewPolyphaseAnalysisResults.Count; i++)
  1152. {
  1153. PolyphaseAnalysisResult aResult = viewPolyphaseAnalysisResults[i];
  1154. dataGridView_results.Rows.Add(aResult.GraphName, aResult.PolyphaseName, AnalysisTools.GetDecNum(aResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(aResult.PolyphaseAllRate, decnum));
  1155. }
  1156. }
  1157. }
  1158. }
  1159. private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
  1160. {
  1161. }
  1162. private void button5_Click(object sender, EventArgs e)
  1163. {
  1164. this.Close();
  1165. }
  1166. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  1167. {
  1168. }
  1169. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  1170. {
  1171. decnum = (int)numericUpDown1.Value;
  1172. refeshGrids();
  1173. }
  1174. private void refeshGrids()
  1175. {
  1176. dataGridView1.Rows.Clear();
  1177. for (int i = 0; i < mainPolyphaseAnalysisResults.Count; i++)
  1178. {
  1179. PolyphaseAnalysisResult pResult = mainPolyphaseAnalysisResults[i];
  1180. dataGridView1.Rows.Add(pResult.PolyphaseName, AnalysisTools.GetDecNum(pResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseAllRate, decnum));
  1181. }
  1182. dataGridView_results.Rows.Clear();
  1183. for (int i = 0; i < polyphaseAnalysisResults.Count; i++)
  1184. {
  1185. PolyphaseAnalysisResult pResult = polyphaseAnalysisResults[i];
  1186. dataGridView_results.Rows.Add(pResult.GraphName, pResult.PolyphaseName, AnalysisTools.GetDecNum(pResult.PolyphaseArea, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseRate, decnum), AnalysisTools.GetDecNum(pResult.PolyphaseAllRate, decnum));
  1187. }
  1188. show_avg();
  1189. }
  1190. private void button1_Click(object sender, EventArgs e)
  1191. {
  1192. AnalyzeSettingDialog recombinationRateSetDialog = new AnalyzeSettingDialog(this, "Template.Manager.item2.PolyphaseContent");
  1193. if (recombinationRateSetDialog.hasModule)
  1194. {
  1195. recombinationRateSetDialog.StartPosition = FormStartPosition.CenterScreen;
  1196. recombinationRateSetDialog.ShowDialog();
  1197. }
  1198. else
  1199. {
  1200. recombinationRateSetDialog = null;
  1201. }
  1202. }
  1203. private void button3_Click(object sender, EventArgs e)
  1204. {
  1205. if (checkBox1.Checked)
  1206. {
  1207. AnalyzeSettingDialog recombinationRateSetDialog = new AnalyzeSettingDialog(this, "Template.Manager.item2.PolyphaseContent");
  1208. if (recombinationRateSetDialog.hasModule)
  1209. {
  1210. recombinationRateSetDialog.StartPosition = FormStartPosition.CenterScreen;
  1211. recombinationRateSetDialog.ShowDialog();
  1212. }
  1213. else
  1214. {
  1215. recombinationRateSetDialog = null;
  1216. }
  1217. }
  1218. bitList.Clear();
  1219. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  1220. {
  1221. //获取word书签与excel单元格的关系,以字典方式存储
  1222. List<mic_module_infos> mic_module_infos = mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  1223. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1224. if (mic_module_infos != null && mic_module_infos.Count > 0)
  1225. {
  1226. foreach (mic_module_infos info in mic_module_infos)
  1227. {
  1228. tagInfos.Add(info.tag_name, info.cell_position);
  1229. }
  1230. }
  1231. List<List<string>> analysisContent = new List<List<string>>();
  1232. for (int i = 0; i < this.dataGridView_results.Rows.Count; i++)
  1233. {
  1234. List<string> content1 = new List<string>();
  1235. if (i == 0)
  1236. {
  1237. content1.Add(this.dataGridView_results.Columns[0].HeaderText);
  1238. content1.Add(this.dataGridView_results.Columns[1].HeaderText);
  1239. content1.Add(this.dataGridView_results.Columns[2].HeaderText);
  1240. content1.Add(this.dataGridView_results.Columns[3].HeaderText);
  1241. content1.Add(this.dataGridView_results.Columns[4].HeaderText);
  1242. analysisContent.Add(content1);
  1243. }
  1244. content1 = new List<string>();
  1245. content1.Add(this.dataGridView_results.Rows[i].Cells[0].Value.ToString());
  1246. content1.Add(this.dataGridView_results.Rows[i].Cells[1].Value.ToString());
  1247. content1.Add(this.dataGridView_results.Rows[i].Cells[2].Value.ToString());
  1248. content1.Add(this.dataGridView_results.Rows[i].Cells[3].Value.ToString());
  1249. content1.Add(this.dataGridView_results.Rows[i].Cells[4].Value.ToString());
  1250. analysisContent.Add(content1);
  1251. string tag = this.dataGridView_results.Rows[i].Cells[0].Value.ToString();
  1252. if (bitDic.ContainsKey(tag))
  1253. {
  1254. bitList.Add(bitDic[tag][0]);
  1255. bitList.Add(bitDic[tag][1]);
  1256. }
  1257. }
  1258. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  1259. }
  1260. else
  1261. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  1262. }
  1263. private void groupBox7_Enter(object sender, EventArgs e)
  1264. {
  1265. }
  1266. private void button4_Click(object sender, EventArgs e)
  1267. {
  1268. if (this.dataGridView_results.Rows.Count > 0)
  1269. {
  1270. SaveFileDialog exe = new SaveFileDialog();
  1271. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1272. exe.FilterIndex = 0;
  1273. exe.RestoreDirectory = true;
  1274. exe.Title = "Export Excel File";
  1275. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1276. exe.FileName = PdnResources.GetString("Menu.GeneralAnalysis.TwoPhaseArea.Text")+ PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddhhmmss");
  1277. DialogResult dr = exe.ShowDialog();
  1278. if (dr == DialogResult.OK)
  1279. {
  1280. DataTable dtb = new DataTable();
  1281. foreach (DataGridViewColumn c in this.dataGridView_results.Columns)
  1282. {
  1283. dtb.Columns.Add(c.HeaderText);
  1284. }
  1285. for (int r = 0; r < this.dataGridView_results.Rows.Count; r++)
  1286. {
  1287. DataRow dataRow = dtb.NewRow();
  1288. for (int c = 0; c < this.dataGridView_results.Rows[r].Cells.Count; c++)
  1289. {
  1290. dataRow[this.dataGridView_results.Columns[c].HeaderText] = this.dataGridView_results.Rows[r].Cells[c].Value;
  1291. }
  1292. dtb.Rows.Add(dataRow);
  1293. }
  1294. List<DataTable> list = new List<DataTable>();
  1295. list.Add(dtb);
  1296. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")+"!");
  1302. }
  1303. }
  1304. private void button9_Click(object sender, EventArgs e)
  1305. {
  1306. if (this.dataGridView_results.Rows.Count == 0)
  1307. {
  1308. MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  1309. return;
  1310. }
  1311. if (this.analyzeSettingModel == null)
  1312. {
  1313. MessageBox.Show(PdnResources.GetString("Menu.Pleasesetiirst.Text"));
  1314. return;
  1315. }
  1316. //获取项目工程内的文件夹路径
  1317. ProjectEngineering.NodeItem item = this.appWorkspace.GetInsertProjectPath(2, "Menu.GeneralAnalysis.TwoPhaseArea.Text", this.analyzeSettingModel.savePath);
  1318. if (item != null)
  1319. {
  1320. //向文件夹内保存图片和报告
  1321. if (!string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  1322. {
  1323. //获取word书签与excel单元格的关系,以字典方式存储
  1324. List<mic_module_infos> mic_module_infos = mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  1325. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1326. if (mic_module_infos != null && mic_module_infos.Count > 0)
  1327. {
  1328. foreach (mic_module_infos info in mic_module_infos)
  1329. {
  1330. tagInfos.Add(info.tag_name, info.cell_position);
  1331. }
  1332. }
  1333. List<List<string>> analysisContent = new List<List<string>>();
  1334. List<List<string>> inclusionList = new List<List<string>>();
  1335. List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
  1336. List<Bitmap> bitImgList = new List<Bitmap>();
  1337. List<string> titleContent = new List<string>();
  1338. for (int i = 0; i < this.dataGridView_results.Rows.Count; i++)
  1339. {
  1340. List<string> content1 = new List<string>();
  1341. if (i == 0)
  1342. {
  1343. content1.Add(this.dataGridView_results.Columns[0].HeaderText);
  1344. content1.Add(this.dataGridView_results.Columns[1].HeaderText);
  1345. content1.Add(this.dataGridView_results.Columns[2].HeaderText);
  1346. content1.Add(this.dataGridView_results.Columns[3].HeaderText);
  1347. content1.Add(this.dataGridView_results.Columns[4].HeaderText);
  1348. analysisContent.Add(content1);
  1349. titleContent.AddRange(content1);
  1350. }
  1351. content1 = new List<string>();
  1352. content1.Add(this.dataGridView_results.Rows[i].Cells[0].Value.ToString());
  1353. content1.Add(this.dataGridView_results.Rows[i].Cells[1].Value.ToString());
  1354. content1.Add(this.dataGridView_results.Rows[i].Cells[2].Value.ToString());
  1355. content1.Add(this.dataGridView_results.Rows[i].Cells[3].Value.ToString());
  1356. content1.Add(this.dataGridView_results.Rows[i].Cells[4].Value.ToString());
  1357. analysisContent.Add(content1);
  1358. string tag = this.dataGridView_results.Rows[i].Cells[0].Value.ToString();
  1359. var export = exportModel.Where(m => m.picName == tag).FirstOrDefault();
  1360. if (export == null)
  1361. {
  1362. ExportProjectModel exportProjectModel = new ExportProjectModel();
  1363. exportProjectModel.dataList = new List<List<string>>();
  1364. exportProjectModel.dataList.Add(titleContent);
  1365. exportProjectModel.dataList.Add(content1);
  1366. exportProjectModel.picName = tag;
  1367. exportProjectModel.tagName = PdnResources.GetString("Menu.GeneralAnalysis.TwoPhaseArea.Text");
  1368. exportModel.Add(exportProjectModel);
  1369. }
  1370. else
  1371. {
  1372. exportModel[exportModel.IndexOf(export)].dataList.Add(content1);
  1373. }
  1374. if (bitDic.ContainsKey(tag))
  1375. {
  1376. bitImgList.Add(bitDic[tag][0]);
  1377. bitImgList.Add(bitDic[tag][1]);
  1378. }
  1379. }
  1380. try
  1381. {
  1382. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitImgList, tagInfos, item.path, item.code);
  1383. }
  1384. catch (Exception ex)
  1385. {
  1386. MessageBox.Show(ex.Message);
  1387. }
  1388. }
  1389. else
  1390. {
  1391. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  1392. return;
  1393. }
  1394. //保存项目信息到数据库
  1395. this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, item);
  1396. }
  1397. }
  1398. private void getValue(string key, Object value)
  1399. {
  1400. switch (key)
  1401. {
  1402. case "OpenWhileExportReport":
  1403. checkBox1.Checked = Convert.ToBoolean(value);
  1404. break;
  1405. case "CalculatorDecimalDigits":
  1406. numericUpDown1.Value = Convert.ToDecimal(value);
  1407. break;
  1408. case "ExportResults":
  1409. isExportResults = Convert.ToBoolean(value);
  1410. break;
  1411. case "ExportReports":
  1412. isExportReports = Convert.ToBoolean(value);
  1413. break;
  1414. case "ExportProjects":
  1415. isExportProjects = Convert.ToBoolean(value);
  1416. break;
  1417. }
  1418. }
  1419. #region [应用全部保存全部-私有方法]
  1420. /// <summary>
  1421. /// 应用全部私有方法
  1422. /// </summary>
  1423. private void applyAll()
  1424. {
  1425. }
  1426. /// <summary>
  1427. /// 保存全部私有方法
  1428. /// </summary>
  1429. private void saveAll()
  1430. {
  1431. for (int i = 0; i < listView1.Items.Count; i++)
  1432. {
  1433. this.listView1.EnsureVisible(i);
  1434. this.listView1.Items[i].Focused = true;
  1435. this.listView1.Items[i].Selected = true;
  1436. this.button2.PerformClick();
  1437. }
  1438. }
  1439. /// <summary>
  1440. /// 执行脚本自动化的步骤
  1441. /// </summary>
  1442. private void startScriptAutomaticAction()
  1443. {
  1444. saveAll();
  1445. if (isExportResults)//导出结果
  1446. this.button4.PerformClick();
  1447. if (isExportReports)//生成报告
  1448. this.button3.PerformClick();
  1449. if (isExportProjects)//导出项目
  1450. this.button9.PerformClick();
  1451. this.appWorkspace.ScriptAutomatic = false;
  1452. this.Close();
  1453. }
  1454. #endregion
  1455. #region [脚本录制]
  1456. private void getScriptRecording()
  1457. {
  1458. string className = InvariantData.path_Action + ".Action" + menuId;
  1459. ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  1460. List<Args> args = param.Lists;
  1461. foreach (var item in args)
  1462. {
  1463. item.value = setScriptRecording(item.key);
  1464. }
  1465. appWorkspace.SetScriptStartRecording(this.menuId, menuName, args);
  1466. }
  1467. private object setScriptRecording(string key)
  1468. {
  1469. object value = null;
  1470. switch (key)
  1471. {
  1472. case "OpenWhileExportReport":
  1473. value = checkBox1.Checked;
  1474. break;
  1475. case "CalculatorDecimalDigits":
  1476. value = numericUpDown1.Value;
  1477. break;
  1478. case "ExportResults":
  1479. value = isExportResults;
  1480. break;
  1481. case "ExportReports":
  1482. value = isExportReports;
  1483. break;
  1484. case "ExportProjects":
  1485. value = isExportProjects;
  1486. break;
  1487. }
  1488. return value;
  1489. }
  1490. #endregion
  1491. }
  1492. }