NonFMetalsStandardDialog.cs 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. using OpenCvSharp;
  2. using PaintDotNet.Base.Functionodel;
  3. using PaintDotNet.CustomControl;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using PaintDotNet.Instrument;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Drawing.Drawing2D;
  12. using System.Windows.Forms;
  13. namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals
  14. {
  15. internal class NonFMetalsStandardDialog : PdnBaseForm
  16. {
  17. #region 属性
  18. //是否进行了结果(厚度)计算
  19. protected bool calculate1d = false;
  20. /// <summary>
  21. /// 计算结果的表格集合
  22. /// </summary>
  23. private List<DataTable> resultTableList = new List<DataTable>();
  24. protected Panel panelC;
  25. /// <summary>
  26. /// 调色板
  27. /// </summary>
  28. private ColorsForm colorsFormGrid;
  29. /// <summary>
  30. /// 主控件
  31. /// </summary>
  32. protected AppWorkspace appWorkspace;
  33. //二值化集成1
  34. protected BinaryClass binaryClass;
  35. protected int menuId;
  36. /// <summary>
  37. /// 公共按钮
  38. /// </summary>
  39. private CommonControlButtons commonControlButtons;
  40. /// <summary>
  41. /// 图像面板
  42. /// </summary>
  43. protected DocumentWorkspaceWindow documentWorkspace;
  44. /// <summary>
  45. /// 当前选择的图片
  46. /// </summary>
  47. protected Mat imageMat;
  48. /// <summary>
  49. /// 当前选择的图片
  50. /// </summary>
  51. protected Mat matOrg;
  52. ///// <summary>
  53. ///// 当前选择的图片
  54. ///// </summary>
  55. //private Mat mat;
  56. protected string oldSelectItem;
  57. public bool comboboxChange = true;
  58. /// <summary>
  59. /// 图形上所有的点
  60. /// </summary>
  61. protected List<PointF> linePointList = new List<PointF>();
  62. /// <summary>
  63. /// 直线图形上所有的点
  64. /// </summary>
  65. protected List<List<PointF>> straightLinePointList = new List<List<PointF>>();
  66. /// <summary>
  67. /// 圆圈图形上所有的点,其中第一个点为圆心坐标
  68. /// </summary>
  69. protected List<List<PointF>> roundLinePointList = new List<List<PointF>>();
  70. /// <summary>
  71. /// 是否选择了图片
  72. /// </summary>
  73. protected int selectPicture = -1;
  74. /// <summary>
  75. /// 用于编号的坐标点集合,value为: Nx5 matrix (CV_32S) of statistics: x0, y0, width0, height0, area0 + [1内部 0外部] + [label]
  76. /// </summary>
  77. protected Dictionary<Point2d, List<int>> massLabelPoints = new Dictionary<Point2d, List<int>>();
  78. /// <summary>
  79. /// 矩形内的连通域
  80. /// </summary>
  81. protected int within = 0;
  82. /// <summary>
  83. /// 保存用于生成报告的图片
  84. /// </summary>
  85. protected List<Bitmap> bitList;
  86. /// <summary>
  87. /// 储存点击保存结果后的所有原图与分析图
  88. /// </summary>
  89. protected Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
  90. /// <summary>
  91. /// 中间数据
  92. /// </summary>
  93. protected List<ExportProjectModel> tempDataModel = new List<ExportProjectModel>();
  94. /// <summary>
  95. /// 分析结果暂存
  96. /// </summary>
  97. protected List<System.Data.DataTable> dataTable_Totals = new List<System.Data.DataTable>();
  98. /// <summary>
  99. /// 详细分析结果暂存
  100. /// </summary>
  101. protected List<System.Data.DataTable> dataTables = new List<System.Data.DataTable>();
  102. /// <summary>
  103. /// 全部显示
  104. /// </summary>
  105. protected bool allShow = false;
  106. /// <summary>
  107. /// 详细列表需要求和的index集合
  108. /// </summary>
  109. protected List<int> IndexChangedFromIndex = new List<int>();
  110. /// <summary>
  111. /// 列表需要求和的index集合,value值为:1 求和 2:平均 3:级别计算 + [输入数据index位置,-1则需要调用自定义方法进行计算]
  112. /// </summary>
  113. protected Dictionary<int, int[]> IndexChangedToIndex = new Dictionary<int, int[]>();
  114. #endregion
  115. #region 组件
  116. private GroupBox groupBox_operating;
  117. protected GroupBox groupBox_img;
  118. protected ListView lstView_img;
  119. private ImageList imageList_img;
  120. private IContainer components;
  121. protected GroupBox groupBox_review;
  122. protected GroupBox groupBox_report;
  123. private Label label_resultPrecision;
  124. private Button button_exportResults;
  125. private Button button_generateReport;
  126. protected GroupBox groupBox6groupBox_analysisResult2;
  127. protected GroupBox groupBox_analysisResult1;
  128. private Button button_setting;
  129. protected CheckBox checkBox_generateReport_opensetting;
  130. protected DataGridView dataGridView2;
  131. protected ListView listView2;
  132. private Button button16;
  133. private Button button12;
  134. private Button button11;
  135. protected NumericUpDown numericUpDown1_0;
  136. private Button button1;
  137. private BinaryControlSmaller bc;
  138. protected DataGridView dataGridView_Total;
  139. private Button button2;
  140. private Button btn_saveresult;
  141. #endregion
  142. #region 构造函数
  143. public NonFMetalsStandardDialog(AppWorkspace appWorkspace, int menuId)
  144. {
  145. this.appWorkspace = appWorkspace;
  146. this.Icon = PdnInfo.AppIcon;
  147. this.Load += new System.EventHandler(this.NonFMetalsStandardDialog_Load);
  148. InitializeComponent();
  149. InitializeCustomControl();
  150. InitializeLanguageText();
  151. this.menuId = menuId;
  152. this.binaryClass = new BinaryClass(menuId);
  153. Initialize();
  154. SubclassInitialize();
  155. //初始化头
  156. this.listView2.View = View.Details;
  157. ColumnHeader header0 = new ColumnHeader();
  158. header0.Text = "";
  159. header0.Width = 180;
  160. this.listView2.Columns.Add(header0);
  161. //二值化集成2
  162. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  163. binaryClass.createDocumentItemsSmaller(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") }
  164. , this.bc, this.appWorkspace, this.documentWorkspace, this.lstView_img);//初始化相的工作结构
  165. //##############################################
  166. binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件
  167. this.button11.Visible = true;
  168. this.button16.Visible = false;
  169. //
  170. //初始化色板
  171. //
  172. this.colorsFormGrid = new ColorsForm();
  173. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  174. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  175. SetAnalyzeModelFromXml(getTemplateName());
  176. this.Shown += new EventHandler(this.ShownChoiseItemAndInitData);
  177. }
  178. private void Dialog_FormClosing(object sender, FormClosingEventArgs e)
  179. {
  180. binaryClass.saveParams();
  181. }
  182. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  183. {
  184. if (index > -1)
  185. {
  186. //滚动到指定的行位置
  187. this.lstView_img.EnsureVisible(index);
  188. if (this.lstView_img.SelectedItems != null && this.lstView_img.SelectedItems.Count > 0)
  189. {
  190. if (this.selectPicture == this.lstView_img.SelectedItems[0].Index)
  191. return;
  192. this.imageMat = this.appWorkspace.DocumentWorkspaces[this.lstView_img.SelectedItems[0].Index].CompositionSurface.CreatedAliasedMat();
  193. if (this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count)
  194. binaryClass.saveMat(this.imageList_img.Images.Keys[this.selectPicture]);
  195. //二值化集成4
  196. binaryClass.listView1_SelectedIndexChanged(this.imageMat.Clone(), getCurrentWorkTag());
  197. binaryClass.RefreshHistogramControl1Values();
  198. bool existViewFlag = this.appWorkspace.DocumentWorkspaces[this.lstView_img.SelectedItems[0].Index].GraphicsList.IsExsitView();
  199. if (!existViewFlag)
  200. matOrg = imageMat.Clone();
  201. else
  202. matOrg = PaintDotNet.Camera.Tools.ToMat(this.appWorkspace.DocumentWorkspaces[this.lstView_img.SelectedItems[0].Index].GetFullSizeWithRegion());
  203. this.selectPicture = this.lstView_img.SelectedItems[0].Index;
  204. //this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
  205. //AddRectangleToRectangleFCaps(); this.documentWorkspace.Refresh();
  206. calculate1d = false;
  207. refreshWhileImgChanged();
  208. //this.commonControlButtons.Visible = true;//0914###18449
  209. this.documentWorkspace.Refresh();
  210. }
  211. }
  212. //// 初始化数据
  213. //this.bitmap = this.appWorkspace.DocumentWorkspaces[index].CompositionSurface.CreateAliasedBitmap();
  214. //Document document = Document.FromImage(bitmap);
  215. //this.documentWorkspace.Document = document;
  216. //this.documentWorkspace.Visible = true;
  217. //this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[index].GraphicsList;
  218. //this.applyButtonImpl(null, null);
  219. ////显示直方图
  220. //this.histogramControl1.CreateHistogram(this.bitmap, true, 339, 130, 0);
  221. }
  222. public NonFMetalsStandardDialog()
  223. {
  224. InitializeComponent();
  225. }
  226. #endregion
  227. #region 初始化组件
  228. private void InitializeLanguageText()
  229. {
  230. this.groupBox_operating.Text = PdnResources.GetString("Menu.operation.text");
  231. this.button2.Text = PdnResources.GetString("Menu.reckoning.text");
  232. this.checkBox_generateReport_opensetting.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
  233. this.button_setting.Text = PdnResources.GetString("Menu.Setting.Text");
  234. this.btn_saveresult.Text = PdnResources.GetString("Menu.Saveresult.text");
  235. this.groupBox_img.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  236. this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text");
  237. this.button1.Text = PdnResources.GetString("Menu.Exportproject.text");
  238. this.label_resultPrecision.Text = PdnResources.GetString("Menu.Decimal.text");
  239. this.button_exportResults.Text = PdnResources.GetString("Menu.Exportresults.text");
  240. this.button_generateReport.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
  241. this.groupBox_analysisResult1.Text = PdnResources.GetString("Menu.Analysisresult.text");
  242. this.button11.Text = PdnResources.GetString("Menu.Showall.text");
  243. this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text");
  244. this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  245. }
  246. private void InitializeCustomControl()
  247. {
  248. //
  249. // bc
  250. //
  251. this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
  252. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  253. this.bc.BinaryChecked = false;
  254. this.bc.BinaryStyle = 1;
  255. this.bc.Location = new System.Drawing.Point(176, 70);
  256. this.bc.Name = "bc";
  257. this.bc.OriginChecked = false;
  258. this.bc.scope1End = 0D;
  259. this.bc.scope1Start = 0D;
  260. this.bc.scope2End = 0D;
  261. this.bc.scope2Start = 0D;
  262. this.bc.scope3End = 0D;
  263. this.bc.scope3Start = 0D;
  264. this.bc.Size = new System.Drawing.Size(360, 247);
  265. this.bc.TabIndex = 38;
  266. this.Controls.Add(this.bc);
  267. this.Controls.SetChildIndex(this.bc, 0);
  268. }
  269. private void InitializeComponent()
  270. {
  271. this.components = new System.ComponentModel.Container();
  272. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  273. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  274. this.groupBox_operating = new System.Windows.Forms.GroupBox();
  275. this.button2 = new System.Windows.Forms.Button();
  276. this.checkBox_generateReport_opensetting = new System.Windows.Forms.CheckBox();
  277. this.button_setting = new System.Windows.Forms.Button();
  278. this.btn_saveresult = new System.Windows.Forms.Button();
  279. this.groupBox_img = new System.Windows.Forms.GroupBox();
  280. this.lstView_img = new System.Windows.Forms.ListView();
  281. this.imageList_img = new System.Windows.Forms.ImageList(this.components);
  282. this.groupBox_review = new System.Windows.Forms.GroupBox();
  283. this.groupBox_report = new System.Windows.Forms.GroupBox();
  284. this.button1 = new System.Windows.Forms.Button();
  285. this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
  286. this.label_resultPrecision = new System.Windows.Forms.Label();
  287. this.button_exportResults = new System.Windows.Forms.Button();
  288. this.button_generateReport = new System.Windows.Forms.Button();
  289. this.groupBox6groupBox_analysisResult2 = new System.Windows.Forms.GroupBox();
  290. this.dataGridView_Total = new System.Windows.Forms.DataGridView();
  291. this.dataGridView2 = new System.Windows.Forms.DataGridView();
  292. this.groupBox_analysisResult1 = new System.Windows.Forms.GroupBox();
  293. this.button11 = new System.Windows.Forms.Button();
  294. this.listView2 = new System.Windows.Forms.ListView();
  295. this.button16 = new System.Windows.Forms.Button();
  296. this.button12 = new System.Windows.Forms.Button();
  297. this.groupBox_operating.SuspendLayout();
  298. this.groupBox_img.SuspendLayout();
  299. this.groupBox_report.SuspendLayout();
  300. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  301. this.groupBox6groupBox_analysisResult2.SuspendLayout();
  302. ((System.ComponentModel.ISupportInitialize)(this.dataGridView_Total)).BeginInit();
  303. ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
  304. this.groupBox_analysisResult1.SuspendLayout();
  305. this.SuspendLayout();
  306. //
  307. // groupBox_operating
  308. //
  309. this.groupBox_operating.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  310. | System.Windows.Forms.AnchorStyles.Right)));
  311. this.groupBox_operating.Controls.Add(this.button2);
  312. this.groupBox_operating.Controls.Add(this.checkBox_generateReport_opensetting);
  313. this.groupBox_operating.Controls.Add(this.button_setting);
  314. this.groupBox_operating.Controls.Add(this.btn_saveresult);
  315. this.groupBox_operating.Location = new System.Drawing.Point(13, 12);
  316. this.groupBox_operating.Name = "groupBox_operating";
  317. this.groupBox_operating.Size = new System.Drawing.Size(1102, 53);
  318. this.groupBox_operating.TabIndex = 12;
  319. this.groupBox_operating.TabStop = false;
  320. //
  321. // button2
  322. //
  323. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  324. this.button2.Location = new System.Drawing.Point(911, 20);
  325. this.button2.Name = "button2";
  326. this.button2.Size = new System.Drawing.Size(75, 23);
  327. this.button2.TabIndex = 7;
  328. this.button2.UseVisualStyleBackColor = true;
  329. this.button2.Click += new System.EventHandler(this.buttonCalculate_Click);
  330. //
  331. // checkBox_generateReport_opensetting
  332. //
  333. this.checkBox_generateReport_opensetting.AutoSize = true;
  334. this.checkBox_generateReport_opensetting.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
  335. this.checkBox_generateReport_opensetting.Location = new System.Drawing.Point(91, 24);
  336. this.checkBox_generateReport_opensetting.Name = "checkBox_generateReport_opensetting";
  337. this.checkBox_generateReport_opensetting.Size = new System.Drawing.Size(132, 16);
  338. this.checkBox_generateReport_opensetting.TabIndex = 6;
  339. this.checkBox_generateReport_opensetting.UseVisualStyleBackColor = true;
  340. //
  341. // button_setting
  342. //
  343. this.button_setting.Location = new System.Drawing.Point(6, 20);
  344. this.button_setting.Name = "button_setting";
  345. this.button_setting.Size = new System.Drawing.Size(75, 23);
  346. this.button_setting.TabIndex = 4;
  347. this.button_setting.UseVisualStyleBackColor = true;
  348. this.button_setting.Click += new System.EventHandler(this.button_setting_Click);
  349. //
  350. // btn_saveresult
  351. //
  352. this.btn_saveresult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  353. this.btn_saveresult.Location = new System.Drawing.Point(998, 20);
  354. this.btn_saveresult.Name = "btn_saveresult";
  355. this.btn_saveresult.Size = new System.Drawing.Size(75, 23);
  356. this.btn_saveresult.TabIndex = 2;
  357. this.btn_saveresult.UseVisualStyleBackColor = true;
  358. this.btn_saveresult.Click += new System.EventHandler(this.btn_saveresult_Click);
  359. //
  360. // groupBox_img
  361. //
  362. this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  363. | System.Windows.Forms.AnchorStyles.Left)));
  364. this.groupBox_img.Controls.Add(this.lstView_img);
  365. this.groupBox_img.Location = new System.Drawing.Point(13, 72);
  366. this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);
  367. this.groupBox_img.Name = "groupBox_img";
  368. this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);
  369. this.groupBox_img.Size = new System.Drawing.Size(158, 514);
  370. this.groupBox_img.TabIndex = 13;
  371. this.groupBox_img.TabStop = false;
  372. //
  373. // lstView_img
  374. //
  375. this.lstView_img.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  376. | System.Windows.Forms.AnchorStyles.Left)
  377. | System.Windows.Forms.AnchorStyles.Right)));
  378. this.lstView_img.HideSelection = false;
  379. this.lstView_img.LargeImageList = this.imageList_img;
  380. this.lstView_img.Location = new System.Drawing.Point(8, 26);
  381. this.lstView_img.Margin = new System.Windows.Forms.Padding(4);
  382. this.lstView_img.MultiSelect = false;
  383. this.lstView_img.Name = "lstView_img";
  384. this.lstView_img.Size = new System.Drawing.Size(140, 480);
  385. this.lstView_img.TabIndex = 0;
  386. this.lstView_img.UseCompatibleStateImageBehavior = false;
  387. this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged);
  388. //
  389. // imageList_img
  390. //
  391. this.imageList_img.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  392. this.imageList_img.ImageSize = new System.Drawing.Size(64, 64);
  393. this.imageList_img.TransparentColor = System.Drawing.Color.Transparent;
  394. //
  395. // groupBox_review
  396. //
  397. this.groupBox_review.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  398. | System.Windows.Forms.AnchorStyles.Left)
  399. | System.Windows.Forms.AnchorStyles.Right)));
  400. this.groupBox_review.Location = new System.Drawing.Point(541, 72);
  401. this.groupBox_review.Name = "groupBox_review";
  402. this.groupBox_review.Size = new System.Drawing.Size(575, 514);
  403. this.groupBox_review.TabIndex = 30;
  404. this.groupBox_review.TabStop = false;
  405. //
  406. // groupBox_report
  407. //
  408. this.groupBox_report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  409. this.groupBox_report.Controls.Add(this.button1);
  410. this.groupBox_report.Controls.Add(this.numericUpDown1_0);
  411. this.groupBox_report.Controls.Add(this.label_resultPrecision);
  412. this.groupBox_report.Controls.Add(this.button_exportResults);
  413. this.groupBox_report.Controls.Add(this.button_generateReport);
  414. this.groupBox_report.Location = new System.Drawing.Point(974, 592);
  415. this.groupBox_report.Name = "groupBox_report";
  416. this.groupBox_report.Size = new System.Drawing.Size(142, 218);
  417. this.groupBox_report.TabIndex = 33;
  418. this.groupBox_report.TabStop = false;
  419. //
  420. // button1
  421. //
  422. this.button1.Location = new System.Drawing.Point(29, 112);
  423. this.button1.Name = "button1";
  424. this.button1.Size = new System.Drawing.Size(75, 23);
  425. this.button1.TabIndex = 23;
  426. this.button1.UseVisualStyleBackColor = true;
  427. this.button1.Click += new System.EventHandler(this.button1_Click);
  428. //
  429. // numericUpDown1_0
  430. //
  431. this.numericUpDown1_0.Location = new System.Drawing.Point(63, 165);
  432. this.numericUpDown1_0.Maximum = new decimal(new int[] {
  433. 10,
  434. 0,
  435. 0,
  436. 0});
  437. this.numericUpDown1_0.Name = "numericUpDown1_0";
  438. this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
  439. this.numericUpDown1_0.TabIndex = 22;
  440. this.numericUpDown1_0.Value = new decimal(new int[] {
  441. 2,
  442. 0,
  443. 0,
  444. 0});
  445. this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
  446. //
  447. // label_resultPrecision
  448. //
  449. this.label_resultPrecision.AutoSize = true;
  450. this.label_resultPrecision.Location = new System.Drawing.Point(26, 169);
  451. this.label_resultPrecision.Name = "label_resultPrecision";
  452. this.label_resultPrecision.Size = new System.Drawing.Size(29, 12);
  453. this.label_resultPrecision.TabIndex = 3;
  454. //
  455. // button_exportResults
  456. //
  457. this.button_exportResults.Location = new System.Drawing.Point(29, 73);
  458. this.button_exportResults.Name = "button_exportResults";
  459. this.button_exportResults.Size = new System.Drawing.Size(75, 23);
  460. this.button_exportResults.TabIndex = 1;
  461. this.button_exportResults.UseVisualStyleBackColor = true;
  462. this.button_exportResults.Click += new System.EventHandler(this.button_exportResults_Click);
  463. //
  464. // button_generateReport
  465. //
  466. this.button_generateReport.Location = new System.Drawing.Point(29, 34);
  467. this.button_generateReport.Name = "button_generateReport";
  468. this.button_generateReport.Size = new System.Drawing.Size(75, 23);
  469. this.button_generateReport.TabIndex = 0;
  470. this.button_generateReport.UseVisualStyleBackColor = true;
  471. this.button_generateReport.Click += new System.EventHandler(this.button_generateReport_Click);
  472. //
  473. // groupBox6groupBox_analysisResult2
  474. //
  475. this.groupBox6groupBox_analysisResult2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  476. | System.Windows.Forms.AnchorStyles.Right)));
  477. this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView_Total);
  478. this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView2);
  479. this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 592);
  480. this.groupBox6groupBox_analysisResult2.Name = "groupBox6groupBox_analysisResult2";
  481. this.groupBox6groupBox_analysisResult2.Size = new System.Drawing.Size(719, 218);
  482. this.groupBox6groupBox_analysisResult2.TabIndex = 32;
  483. this.groupBox6groupBox_analysisResult2.TabStop = false;
  484. //
  485. // dataGridView_Total
  486. //
  487. this.dataGridView_Total.AllowUserToAddRows = false;
  488. this.dataGridView_Total.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  489. | System.Windows.Forms.AnchorStyles.Right)));
  490. this.dataGridView_Total.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  491. this.dataGridView_Total.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  492. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  493. dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
  494. dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F);
  495. dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
  496. dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  497. dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  498. dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  499. this.dataGridView_Total.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
  500. this.dataGridView_Total.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  501. this.dataGridView_Total.Location = new System.Drawing.Point(13, 144);
  502. this.dataGridView_Total.Name = "dataGridView_Total";
  503. this.dataGridView_Total.ReadOnly = true;
  504. this.dataGridView_Total.RowHeadersVisible = false;
  505. this.dataGridView_Total.RowTemplate.Height = 23;
  506. this.dataGridView_Total.Size = new System.Drawing.Size(693, 68);
  507. this.dataGridView_Total.TabIndex = 17;
  508. //
  509. // dataGridView2
  510. //
  511. this.dataGridView2.AllowUserToAddRows = false;
  512. this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  513. | System.Windows.Forms.AnchorStyles.Right)));
  514. this.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  515. this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  516. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  517. dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
  518. dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F);
  519. dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
  520. dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  521. dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  522. dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  523. this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
  524. this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  525. this.dataGridView2.Location = new System.Drawing.Point(13, 12);
  526. this.dataGridView2.Name = "dataGridView2";
  527. this.dataGridView2.ReadOnly = true;
  528. this.dataGridView2.RowHeadersVisible = false;
  529. this.dataGridView2.RowTemplate.Height = 23;
  530. this.dataGridView2.Size = new System.Drawing.Size(693, 128);
  531. this.dataGridView2.TabIndex = 16;
  532. //
  533. // groupBox_analysisResult1
  534. //
  535. this.groupBox_analysisResult1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  536. this.groupBox_analysisResult1.Controls.Add(this.button11);
  537. this.groupBox_analysisResult1.Controls.Add(this.listView2);
  538. this.groupBox_analysisResult1.Controls.Add(this.button16);
  539. this.groupBox_analysisResult1.Controls.Add(this.button12);
  540. this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 592);
  541. this.groupBox_analysisResult1.Name = "groupBox_analysisResult1";
  542. this.groupBox_analysisResult1.Size = new System.Drawing.Size(224, 218);
  543. this.groupBox_analysisResult1.TabIndex = 31;
  544. this.groupBox_analysisResult1.TabStop = false;
  545. //
  546. // button11
  547. //
  548. this.button11.BackColor = System.Drawing.SystemColors.Control;
  549. this.button11.Location = new System.Drawing.Point(19, 22);
  550. this.button11.Name = "button11";
  551. this.button11.Size = new System.Drawing.Size(63, 26);
  552. this.button11.TabIndex = 27;
  553. this.button11.UseVisualStyleBackColor = false;
  554. this.button11.Click += new System.EventHandler(this.button11_Click);
  555. //
  556. // listView2
  557. //
  558. this.listView2.FullRowSelect = true;
  559. this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
  560. this.listView2.HideSelection = false;
  561. this.listView2.Location = new System.Drawing.Point(19, 58);
  562. this.listView2.Name = "listView2";
  563. this.listView2.Size = new System.Drawing.Size(182, 149);
  564. this.listView2.TabIndex = 26;
  565. this.listView2.UseCompatibleStateImageBehavior = false;
  566. this.listView2.SelectedIndexChanged += new System.EventHandler(this.listview2_SelectedIndexChanged);
  567. //
  568. // button16
  569. //
  570. this.button16.BackColor = System.Drawing.SystemColors.Control;
  571. this.button16.Location = new System.Drawing.Point(19, 21);
  572. this.button16.Name = "button16";
  573. this.button16.Size = new System.Drawing.Size(93, 26);
  574. this.button16.TabIndex = 25;
  575. this.button16.UseVisualStyleBackColor = false;
  576. this.button16.Click += new System.EventHandler(this.button16_Click);
  577. //
  578. // button12
  579. //
  580. this.button12.BackColor = System.Drawing.SystemColors.Control;
  581. this.button12.Location = new System.Drawing.Point(149, 21);
  582. this.button12.Name = "button12";
  583. this.button12.Size = new System.Drawing.Size(52, 26);
  584. this.button12.TabIndex = 24;
  585. this.button12.UseVisualStyleBackColor = false;
  586. this.button12.Click += new System.EventHandler(this.button12_Click);
  587. //
  588. // NonFMetalsStandardDialog
  589. //
  590. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  591. this.ClientSize = new System.Drawing.Size(1127, 822);
  592. this.Controls.Add(this.groupBox_report);
  593. this.Controls.Add(this.groupBox6groupBox_analysisResult2);
  594. this.Controls.Add(this.groupBox_analysisResult1);
  595. this.Controls.Add(this.groupBox_review);
  596. this.Controls.Add(this.groupBox_img);
  597. this.Controls.Add(this.groupBox_operating);
  598. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  599. this.Name = "NonFMetalsStandardDialog";
  600. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Dialog_FormClosing);
  601. this.Shown += new System.EventHandler(this.ShownChoiseItemAndInitData);
  602. this.Controls.SetChildIndex(this.groupBox_operating, 0);
  603. this.Controls.SetChildIndex(this.groupBox_img, 0);
  604. this.Controls.SetChildIndex(this.groupBox_review, 0);
  605. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  606. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  607. this.Controls.SetChildIndex(this.groupBox_report, 0);
  608. this.groupBox_operating.ResumeLayout(false);
  609. this.groupBox_operating.PerformLayout();
  610. this.groupBox_img.ResumeLayout(false);
  611. this.groupBox_report.ResumeLayout(false);
  612. this.groupBox_report.PerformLayout();
  613. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  614. this.groupBox6groupBox_analysisResult2.ResumeLayout(false);
  615. ((System.ComponentModel.ISupportInitialize)(this.dataGridView_Total)).EndInit();
  616. ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
  617. this.groupBox_analysisResult1.ResumeLayout(false);
  618. this.ResumeLayout(false);
  619. }
  620. int index = -1;
  621. public void Initialize()
  622. {
  623. //初始化图片列表
  624. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  625. {
  626. this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail);//.CreateAliasedBitmap()
  627. this.lstView_img.Items.Add("", i);
  628. this.lstView_img.Items[i].ImageIndex = i;
  629. this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  630. this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  631. if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  632. {
  633. index = i;
  634. }
  635. }
  636. //
  637. // 初始化选中的数据
  638. //
  639. if (index > -1 && index < this.lstView_img.Items.Count)
  640. this.lstView_img.Items[index].Selected = true; //选中行
  641. ////初始化图片列表
  642. //for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  643. //{
  644. // this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  645. // this.lstView_img.Items.Add("", i);
  646. // this.lstView_img.Items[i].ImageIndex = i;
  647. // this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  648. // this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  649. //}
  650. //
  651. //初始化图像控件
  652. //
  653. this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
  654. this.documentWorkspace.Cursor = Cursors.Default;
  655. this.documentWorkspace.Dock = DockStyle.Fill;
  656. this.documentWorkspace.HookMouseEvents();
  657. this.documentWorkspace.AuxiliaryLineEnabled = false;
  658. this.documentWorkspace.Visible = true;
  659. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  660. this.documentWorkspace.panel.Paint += Panel_Paint;
  661. this.documentWorkspace.panel.MouseMove += onMouseMove;
  662. this.documentWorkspace.panel.MouseUp += onMouseUp;
  663. this.groupBox_review.Controls.Add(this.documentWorkspace);
  664. //
  665. //初始化操作按钮
  666. //
  667. this.commonControlButtons = new CommonControlButtons();
  668. this.commonControlButtons.Dock = DockStyle.Top;
  669. this.commonControlButtons.Height = 30;
  670. this.commonControlButtons.HideZoomToWindowAndActualSize();
  671. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  672. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  673. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  674. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  675. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  676. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  677. groupBox_review.Controls.Add(this.commonControlButtons);
  678. }
  679. #endregion
  680. #region 二值化相关方法
  681. /// <summary>
  682. /// 参数改变时,重新处理图像
  683. /// </summary>
  684. /// <param name="sender"></param>
  685. /// <param name="e"></param>
  686. private void bClassBinaryImplFinishAction(object sender, EventArgs e)
  687. {
  688. this.documentWorkspace.Refresh();
  689. }
  690. //二值化集成3
  691. /// <summary>
  692. /// 添加参数改变的监听
  693. /// </summary>
  694. /// <param name="sender"></param>
  695. /// <param name="e"></param>
  696. private void NonFMetalsStandardDialog_Load(object sender, EventArgs e)
  697. {
  698. this.binaryClass.loadParams();
  699. //this.lstView_img.Select();
  700. }
  701. private bool bcBinaryChecked()
  702. {
  703. return bc != null && bc.BinaryChecked;
  704. }
  705. protected bool bcOriginChecked()
  706. {
  707. return bc != null && bc.OriginChecked;
  708. }
  709. /// <summary>
  710. /// 显示原图/原图+二值图
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. private void bcOriginCheckedChanged(object sender, EventArgs e)
  715. {
  716. if (!bcOriginChecked())
  717. {
  718. if (bcBinaryChecked())
  719. this.documentWorkspace.PhaseModels[0].choise = true;
  720. }
  721. else
  722. {
  723. this.documentWorkspace.PhaseModels[0].choise = false;
  724. }
  725. this.documentWorkspace.Refresh();
  726. }
  727. #endregion
  728. #region 内部方法
  729. /// <summary>
  730. /// PanelC的调色板颜色改变
  731. /// </summary>
  732. /// <param name="sender"></param>
  733. /// <param name="e"></param>
  734. protected virtual void gridColorChanged(object sender, EventArgs e)
  735. {
  736. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  737. //更改背景色,触发事件
  738. this.panelC.BackColor = color;
  739. this.documentWorkspace.Refresh();
  740. //关闭色板
  741. this.colorsFormGrid.Close();
  742. }
  743. /// <summary>
  744. /// 设置按钮
  745. /// </summary>
  746. /// <param name="sender"></param>
  747. /// <param name="e"></param>
  748. private void button_setting_Click(object sender, EventArgs e)
  749. {
  750. string templateName = getTemplateName();
  751. AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName);
  752. if (metallographicMethodSetDialog.hasModule)
  753. {
  754. metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
  755. metallographicMethodSetDialog.ShowDialog();
  756. }
  757. else
  758. {
  759. metallographicMethodSetDialog = null;
  760. }
  761. }
  762. private void btn_saveresult_Click(object sender, EventArgs e)
  763. {
  764. buildListBox_analysisResult();
  765. }
  766. private void lstView_img_SelectedIndexChanged(object sender, EventArgs e)
  767. {
  768. if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected)
  769. {
  770. if (this.selectPicture == this.lstView_img.FocusedItem.Index)
  771. return;
  772. this.imageMat = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreatedAliasedMat();
  773. if (this.selectPicture >= 0 && this.selectPicture < this.imageList_img.Images.Keys.Count)
  774. binaryClass.saveMat(this.imageList_img.Images.Keys[this.selectPicture]);
  775. //二值化集成4
  776. binaryClass.listView1_SelectedIndexChanged(this.imageMat.Clone(), getCurrentWorkTag());
  777. bool existViewFlag = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GraphicsList.IsExsitView();
  778. if (!existViewFlag)
  779. matOrg = imageMat.Clone();
  780. else
  781. matOrg = PaintDotNet.Camera.Tools.ToMat(this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetFullSizeWithRegion());
  782. this.selectPicture = this.lstView_img.FocusedItem.Index;
  783. //this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
  784. //AddRectangleToRectangleFCaps(); this.documentWorkspace.Refresh();
  785. calculate1d = false;
  786. refreshWhileImgChanged();
  787. bool BinaryChecked = false;
  788. if (getCurrentWorkTag() != null)
  789. BinaryChecked = (binaryClass.getModelMat(getCurrentWorkTag()) != null);
  790. //this.commonControlButtons.Visible = true;//0914###18449
  791. this.documentWorkspace.Refresh();
  792. }
  793. }
  794. /// <summary>
  795. /// 导出项目
  796. /// </summary>
  797. /// <param name="sender"></param>
  798. /// <param name="e"></param>
  799. private void button1_Click(object sender, EventArgs e)
  800. {
  801. if (this.listView2.Items.Count == 0)
  802. {
  803. MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  804. return;
  805. }
  806. if (this.checkBox_generateReport_opensetting.Checked)
  807. this.button_setting.PerformClick();
  808. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  809. {
  810. //获取项目工程内的文件夹路径
  811. ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, getProjectEngineeringName(), this.analyzeSettingModel.savePath);
  812. if (nodeItem == null) return;
  813. //获取word书签与excel单元格的关系,以字典方式存储
  814. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  815. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  816. if (mic_module_infos != null && mic_module_infos.Count > 0)
  817. {
  818. foreach (mic_module_infos info in mic_module_infos)
  819. {
  820. tagInfos.Add(info.tag_name, info.cell_position);
  821. }
  822. }
  823. //分析结果
  824. List<List<string>> analysisContent = new List<List<string>>();
  825. {
  826. List<string> contentHeaderText = new List<string>();
  827. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  828. {
  829. contentHeaderText.Add(c.HeaderText);
  830. }
  831. analysisContent.Add(contentHeaderText);
  832. foreach (DataGridViewRow item in this.dataGridView2.Rows)//################################
  833. {
  834. List<string> content = new List<string>();
  835. for (int i = 0; i < contentHeaderText.Count; i++)
  836. {
  837. content.Add(item.Cells[i].Value.ToString());
  838. }
  839. analysisContent.Add(content);
  840. }
  841. }
  842. {
  843. List<string> contentHeaderText = new List<string>();
  844. foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
  845. {
  846. contentHeaderText.Add(c.HeaderText);
  847. }
  848. analysisContent.Add(contentHeaderText);
  849. foreach (DataGridViewRow item in this.dataGridView_Total.Rows)
  850. {
  851. List<string> content = new List<string>();
  852. for (int i = 0; i < contentHeaderText.Count; i++)
  853. {
  854. content.Add(item.Cells[i].Value.ToString());
  855. }
  856. analysisContent.Add(content);
  857. }
  858. }
  859. //图片
  860. bitList = new List<Bitmap>();
  861. //中间数据
  862. List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
  863. if (this.allShow)
  864. {
  865. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  866. {
  867. bitList.Add(kv.Value[0]);
  868. bitList.Add(kv.Value[1]);
  869. }
  870. //中间数据
  871. foreach (ExportProjectModel model in this.tempDataModel)
  872. {
  873. ExportProjectModel tempModel = new ExportProjectModel();
  874. tempModel.tagName = model.tagName;
  875. tempModel.picName = model.picName;
  876. tempModel.dataList = model.dataList;
  877. exportModel.Add(tempModel);
  878. }
  879. }
  880. else
  881. {
  882. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  883. {
  884. foreach (ListViewItem item in this.listView2.SelectedItems)
  885. {
  886. if (bitDic.ContainsKey(item.Name))
  887. {
  888. bitList.Add(bitDic[item.Name][0]);
  889. bitList.Add(bitDic[item.Name][1]);
  890. }
  891. else if (bitDic.ContainsKey(item.Tag.ToString()))
  892. {
  893. bitList.Add(bitDic[item.Tag.ToString()][0]);
  894. bitList.Add(bitDic[item.Tag.ToString()][1]);
  895. }
  896. }
  897. //中间数据
  898. foreach (ListViewItem rowItem in this.listView2.SelectedItems)
  899. {
  900. foreach (ExportProjectModel model in this.tempDataModel)
  901. {
  902. if (model.tagName.Equals(rowItem.Name))
  903. {
  904. ExportProjectModel tempModel = new ExportProjectModel();
  905. tempModel.tagName = model.tagName;
  906. tempModel.picName = model.picName;
  907. tempModel.dataList = model.dataList;
  908. exportModel.Add(tempModel);
  909. break;
  910. }
  911. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  912. {
  913. ExportProjectModel tempModel = new ExportProjectModel();
  914. tempModel.tagName = model.tagName;
  915. tempModel.picName = model.picName;
  916. tempModel.dataList = model.dataList;
  917. exportModel.Add(tempModel);
  918. break;
  919. }
  920. }
  921. }
  922. }
  923. else if (this.listView2.Items.Count > 0)
  924. {
  925. ListViewItem rowItem = this.listView2.Items[0];
  926. if (bitDic.ContainsKey(rowItem.Name))
  927. {
  928. bitList.Add(bitDic[rowItem.Name][0]);
  929. bitList.Add(bitDic[rowItem.Name][1]);
  930. }
  931. else if (bitDic.ContainsKey(rowItem.Tag.ToString()))
  932. {
  933. bitList.Add(bitDic[rowItem.Tag.ToString()][0]);
  934. bitList.Add(bitDic[rowItem.Tag.ToString()][1]);
  935. }
  936. //中间数据
  937. foreach (ExportProjectModel model in this.tempDataModel)
  938. {
  939. if (model.tagName.Equals(rowItem.Name))
  940. {
  941. ExportProjectModel tempModel = new ExportProjectModel();
  942. tempModel.tagName = model.tagName;
  943. tempModel.picName = model.picName;
  944. tempModel.dataList = model.dataList;
  945. exportModel.Add(tempModel);
  946. break;
  947. }
  948. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  949. {
  950. ExportProjectModel tempModel = new ExportProjectModel();
  951. tempModel.tagName = model.tagName;
  952. tempModel.picName = model.picName;
  953. tempModel.dataList = model.dataList;
  954. exportModel.Add(tempModel);
  955. break;
  956. }
  957. }
  958. }
  959. }
  960. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code);
  961. //保存项目信息到数据库
  962. this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem);
  963. }
  964. else
  965. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  966. }
  967. /// <summary>
  968. /// 导出结果
  969. /// </summary>
  970. /// <param name="sender"></param>
  971. /// <param name="e"></param>
  972. private void button_exportResults_Click(object sender, EventArgs e)
  973. {
  974. if (this.listView2.Items.Count > 0)
  975. {
  976. //for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  977. //{
  978. // System.Data.DataRow dataRow = table1.NewRow();
  979. // if (r == 0)
  980. // {
  981. // for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  982. // {
  983. // dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Columns[c].HeaderText;
  984. // }
  985. // table1.Rows.Add(dataRow);
  986. // }
  987. // dataRow = table1.NewRow();
  988. // for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  989. // {
  990. // dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
  991. // }
  992. // table1.Rows.Add(dataRow);
  993. //}
  994. //System.Data.DataTable table2 = new System.Data.DataTable();
  995. //table2.TableName = PdnResources.GetString("Menu.statisaatics.text");
  996. //foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
  997. //{
  998. // table2.Columns.Add(c.HeaderText);
  999. //}
  1000. //for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
  1001. //{
  1002. // System.Data.DataRow dataRow = table2.NewRow();
  1003. // if (r == 0)
  1004. // {
  1005. // for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
  1006. // {
  1007. // dataRow[this.dataGridView_Total.Columns[c].HeaderText] = this.dataGridView_Total.Columns[c].HeaderText;
  1008. // }
  1009. // table2.Rows.Add(dataRow);
  1010. // }
  1011. // dataRow = table2.NewRow();
  1012. // for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
  1013. // {
  1014. // dataRow[this.dataGridView_Total.Columns[c].HeaderText] = this.dataGridView_Total.Rows[r].Cells[c].Value;
  1015. // }
  1016. // table2.Rows.Add(dataRow);
  1017. //}
  1018. //if (table1.Rows.Count > 0) ds.Tables.Add(table1);
  1019. //if (table2.Rows.Count > 0) ds.Tables.Add(table2);
  1020. //if (ds.Tables.Count > 0)
  1021. // DataToExcle(ds);
  1022. }
  1023. else
  1024. {
  1025. MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")+"!");
  1026. return;
  1027. }
  1028. if (this.listView2.Items.Count > 0)
  1029. {
  1030. List<System.Data.DataTable> list = new List<System.Data.DataTable>();
  1031. System.Data.DataTable table1 = new System.Data.DataTable();
  1032. table1.TableName = PdnResources.GetString("Menu.breakdown.text");
  1033. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  1034. {
  1035. table1.Columns.Add(/*HeaderTextUsable ? */c.HeaderText/* : c.Name*/);
  1036. }
  1037. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1038. {
  1039. System.Data.DataRow dataRow = table1.NewRow();
  1040. if (r == 0)
  1041. {
  1042. for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  1043. {
  1044. dataRow[/*HeaderTextUsable ? */this.dataGridView2.Columns[c].HeaderText/* : this.dataGridView2.Columns[c].Name*/] = this.dataGridView2.Columns[c].HeaderText;
  1045. }
  1046. table1.Rows.Add(dataRow);
  1047. }
  1048. dataRow = table1.NewRow();
  1049. for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  1050. {
  1051. dataRow[/*HeaderTextUsable ? */this.dataGridView2.Columns[c].HeaderText/* : this.dataGridView2.Columns[c].Name*/] = this.dataGridView2.Rows[r].Cells[c].Value;
  1052. }
  1053. table1.Rows.Add(dataRow);
  1054. }
  1055. System.Data.DataTable table2 = new System.Data.DataTable();
  1056. table2.TableName = PdnResources.GetString("Menu.statisaatics.text");
  1057. foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
  1058. {
  1059. table2.Columns.Add(/*HeaderTextUsable ? */c.HeaderText/* : c.Name*/);
  1060. }
  1061. for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
  1062. {
  1063. System.Data.DataRow dataRow = table2.NewRow();
  1064. if (r == 0)
  1065. {
  1066. for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
  1067. {
  1068. dataRow[/*HeaderTextUsable ? */this.dataGridView_Total.Columns[c].HeaderText/* : this.dataGridView_Total.Columns[c].Name*/] = this.dataGridView_Total.Columns[c].HeaderText;
  1069. }
  1070. table2.Rows.Add(dataRow);
  1071. }
  1072. dataRow = table2.NewRow();
  1073. for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
  1074. {
  1075. dataRow[/*HeaderTextUsable ? */this.dataGridView_Total.Columns[c].HeaderText/* : this.dataGridView_Total.Columns[c].Name*/] = this.dataGridView_Total.Rows[r].Cells[c].Value;
  1076. }
  1077. table2.Rows.Add(dataRow);
  1078. }
  1079. if (table1.Rows.Count > 0) list.Add(table1);
  1080. if (table2.Rows.Count > 0) list/*ds.Tables*/.Add(table2);
  1081. //if (table1.Rows.Count > 0) ds.Tables.Add(table1);
  1082. //if (table2.Rows.Count > 0) ds.Tables.Add(table2);
  1083. //if (ds.Tables.Count > 0)
  1084. // DataToExcle(ds);
  1085. if (list.Count == 0)
  1086. {
  1087. MessageBox.Show(PdnResources.GetString("Menu.Nonedata.Text") + "!");
  1088. return;
  1089. }
  1090. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1091. saveFileDialog.DefaultExt = "xlsx";
  1092. saveFileDialog.Title = PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text");
  1093. saveFileDialog.FileName = this.Text + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddhhmmss");
  1094. saveFileDialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx";
  1095. saveFileDialog.RestoreDirectory = true;
  1096. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  1097. this.appWorkspace.ExportDataToExcelWithProgress(list, saveFileDialog.FileName, true/*HeaderTextUsable*/, false, true);
  1098. }
  1099. else
  1100. MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text") + "!");
  1101. }
  1102. /// <summary>
  1103. /// 画布绘制
  1104. /// </summary>
  1105. /// <param name="sender"></param>
  1106. /// <param name="e"></param>
  1107. private void Panel_Paint(object sender, PaintEventArgs e)
  1108. {
  1109. if (this.documentWorkspace.CompositionSurface != null)
  1110. {
  1111. //
  1112. // 以下是计算绘制图片的位置和大小并绘制图片
  1113. //
  1114. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  1115. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  1116. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  1117. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  1118. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  1119. //
  1120. // 以下是绘制网格、标注、测量、视场等开始
  1121. //
  1122. e.Graphics.TranslateTransform(x, y);
  1123. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  1124. Draw(e.Graphics);
  1125. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  1126. e.Graphics.TranslateTransform(-x, -y);
  1127. }
  1128. }
  1129. /// <summary>
  1130. /// 绘制
  1131. /// </summary>
  1132. private void Draw(Graphics graphics)
  1133. {
  1134. // 抗锯齿
  1135. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1136. drawSubclass(graphics);
  1137. }
  1138. /// <summary>
  1139. /// 取消全部显示
  1140. /// </summary>
  1141. /// <param name="sender"></param>
  1142. /// <param name="e"></param>
  1143. private void button16_Click(object sender, EventArgs e)
  1144. {
  1145. this.button11.Visible = true;
  1146. this.button16.Visible = false;
  1147. this.button11.Focus();
  1148. this.allShow = false;
  1149. if (this.listView2.Items.Count <= 0 && this.listView2.SelectedItems.Count <= 0)
  1150. return;
  1151. RefreshDataGridView2();
  1152. //double value_1 = 0;
  1153. //double small_l = 0;
  1154. //this.dataGridView2.Rows.Clear();
  1155. //for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1156. //{
  1157. // System.Data.DataTable dataTable1 = new System.Data.DataTable();
  1158. // foreach (var dataTable in this.dataTables)
  1159. // {
  1160. // if (this.listView2.SelectedItems.Count > 0)
  1161. // {
  1162. // if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  1163. // {
  1164. // dataTable1 = dataTable;
  1165. // DataGridViewRow dgvr = new DataGridViewRow();
  1166. // foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  1167. // {
  1168. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1169. // }
  1170. // for (int c = 0; c < dataTable1.Columns.Count; c++)
  1171. // {
  1172. // dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  1173. // small_l += double.Parse(dataTable1.Rows[0][c].ToString());
  1174. // }
  1175. // this.dataGridView2.Rows.Add(dgvr);
  1176. // }
  1177. // }
  1178. // else
  1179. // {
  1180. // if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
  1181. // {
  1182. // dataTable1 = dataTable;
  1183. // DataGridViewRow dgvr = new DataGridViewRow();
  1184. // foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  1185. // {
  1186. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1187. // }
  1188. // for (int c = 0; c < dataTable1.Columns.Count; c++)
  1189. // {
  1190. // dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  1191. // small_l += double.Parse(dataTable1.Rows[0][c].ToString());
  1192. // }
  1193. // this.dataGridView2.Rows.Add(dgvr);
  1194. // }
  1195. // }
  1196. // }
  1197. //}
  1198. //double grainNumber = 0;
  1199. //this.dataGridView_Total.Rows.Clear();
  1200. //for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1201. //{
  1202. // System.Data.DataTable dataTable1 = new System.Data.DataTable();
  1203. // foreach (var dataTable in this.dataTable_Totals)
  1204. // {
  1205. // if (this.listView2.SelectedItems.Count > 0)
  1206. // {
  1207. // if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  1208. // dataTable1 = dataTable;
  1209. // }
  1210. // else
  1211. // {
  1212. // if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
  1213. // dataTable1 = dataTable;
  1214. // }
  1215. // }
  1216. // grainNumber += double.Parse(dataTable1.Rows[0][0].ToString());
  1217. //}
  1218. //{
  1219. // DataGridViewRow dgvr = new DataGridViewRow();
  1220. // foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
  1221. // {
  1222. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1223. // }
  1224. // dgvr.Cells[0].Value = (grainNumber).ToString();
  1225. // dgvr.Cells[1].Value = (small_l).ToString();
  1226. // small_l = small_l / value_1;
  1227. // dgvr.Cells[2].Value = small_l.ToString();
  1228. // dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
  1229. // this.dataGridView_Total.Rows.Add(dgvr);
  1230. //}
  1231. ////##
  1232. //this.RefreshDataGridView4();
  1233. }
  1234. /// <summary>
  1235. /// 切换分析结果
  1236. /// </summary>
  1237. /// <param name="sender"></param>
  1238. /// <param name="e"></param>
  1239. private void listview2_SelectedIndexChanged(object sender, EventArgs e)
  1240. {
  1241. if (!this.allShow)
  1242. {
  1243. RefreshDataGridView2();
  1244. //if (this.listView2.SelectedItems.Count <= 0)
  1245. // return;
  1246. //double value_1 = 0;
  1247. //double small_l = 0;
  1248. //this.dataGridView2.Rows.Clear();
  1249. //for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1250. //{
  1251. // System.Data.DataTable dataTable1 = new System.Data.DataTable();
  1252. // foreach (var dataTable in this.dataTables)
  1253. // {
  1254. // if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  1255. // {
  1256. // dataTable1 = dataTable;
  1257. // DataGridViewRow dgvr = new DataGridViewRow();
  1258. // foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  1259. // {
  1260. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1261. // }
  1262. // for (int c = 0; c < dataTable1.Columns.Count; c++)
  1263. // {
  1264. // dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  1265. // small_l += double.Parse(dataTable1.Rows[0][c].ToString());
  1266. // }
  1267. // this.dataGridView2.Rows.Add(dgvr);
  1268. // }
  1269. // }
  1270. //}
  1271. //double grainNumber = 0;
  1272. //this.dataGridView_Total.Rows.Clear();
  1273. //for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1274. //{
  1275. // System.Data.DataTable dataTable1 = new System.Data.DataTable();
  1276. // foreach (var dataTable in this.dataTable_Totals)
  1277. // {
  1278. // if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  1279. // dataTable1 = dataTable;
  1280. // }
  1281. // grainNumber += double.Parse(dataTable1.Rows[0][0].ToString());
  1282. //}
  1283. //{
  1284. // DataGridViewRow dgvr = new DataGridViewRow();
  1285. // foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
  1286. // {
  1287. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1288. // }
  1289. // dgvr.Cells[0].Value = (grainNumber).ToString();
  1290. // dgvr.Cells[1].Value = (small_l).ToString();
  1291. // small_l = small_l / value_1;
  1292. // dgvr.Cells[2].Value = small_l.ToString();
  1293. // dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
  1294. // this.dataGridView_Total.Rows.Add(dgvr);
  1295. //}
  1296. ////##
  1297. //this.RefreshDataGridView4();
  1298. }
  1299. }
  1300. /// <summary>
  1301. /// 全部显示
  1302. /// </summary>
  1303. /// <param name="sender"></param>
  1304. /// <param name="e"></param>
  1305. private void button11_Click(object sender, EventArgs e)
  1306. {
  1307. //if (this.button6.Text == PdnResources.GetString("Menu.Showall.text"))
  1308. //{
  1309. // this.button6.Text = PdnResources.GetString("Menu.Cancelshowall.text");
  1310. // this.showAll = true;
  1311. // RefreshDataGridView2();
  1312. //}
  1313. //else if (this.button6.Text == PdnResources.GetString("Menu.Cancelshowall.text"))
  1314. //{
  1315. // this.button6.Text = PdnResources.GetString("Menu.Showall.text");
  1316. // this.showAll = false;
  1317. // RefreshDataGridView2();
  1318. //}
  1319. if (this.listView2.Items.Count > 0)
  1320. {
  1321. this.button11.Visible = false;
  1322. this.button16.Visible = true;
  1323. this.button16.Focus();
  1324. this.allShow = true;
  1325. RefreshDataGridView2();
  1326. //double value_1 = 0;
  1327. //double small_l = 0;
  1328. //this.dataGridView2.Rows.Clear();
  1329. //for (int i = 0; i < this.dataTables.Count; i++)
  1330. //{
  1331. // DataGridViewRow dgvr = new DataGridViewRow();
  1332. // foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  1333. // {
  1334. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1335. // }
  1336. // for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
  1337. // {
  1338. // dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
  1339. // small_l += double.Parse(this.dataTables[i].Rows[0][c].ToString());
  1340. // }
  1341. // this.dataGridView2.Rows.Add(dgvr);
  1342. //}
  1343. //double grainNumber = 0;
  1344. //this.dataGridView_Total.Rows.Clear();
  1345. //for (int i = 0; i < this.dataTable_Totals.Count; i++)
  1346. //{
  1347. // grainNumber += double.Parse(this.dataTable_Totals[i].Rows[0][0].ToString());
  1348. //}
  1349. //{
  1350. // DataGridViewRow dgvr = new DataGridViewRow();
  1351. // foreach (DataGridViewColumn Column in this.dataGridView_Total.Columns)
  1352. // {
  1353. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1354. // }
  1355. // dgvr.Cells[0].Value = (grainNumber).ToString();
  1356. // dgvr.Cells[1].Value = (small_l).ToString();
  1357. // small_l = small_l / value_1;
  1358. // dgvr.Cells[2].Value = small_l.ToString();
  1359. // dgvr.Cells[3].Value = (-6.643856 * Math.Log10(small_l * 0.001) - 3.288).ToString();
  1360. // this.dataGridView_Total.Rows.Add(dgvr);
  1361. //}
  1362. //this.RefreshDataGridView4();
  1363. }
  1364. else
  1365. {
  1366. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  1367. }
  1368. }
  1369. /// <summary>
  1370. /// 分析结果删除
  1371. /// </summary>
  1372. /// <param name="sender"></param>
  1373. /// <param name="e"></param>
  1374. private void button12_Click(object sender, EventArgs e)
  1375. {
  1376. if (this.listView2.Items.Count > 0)
  1377. {
  1378. if (this.listView2.SelectedItems.Count > 0)
  1379. {
  1380. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1381. if (dr == DialogResult.OK)
  1382. {
  1383. if (this.listView2.SelectedItems.Count <= 0)
  1384. return;
  1385. for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--)
  1386. {
  1387. int selectIndex = this.listView2.SelectedItems[i].Index;
  1388. foreach (var dataTable in this.dataTable_Totals)
  1389. {
  1390. if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag))
  1391. {
  1392. this.dataTable_Totals.Remove(dataTable);
  1393. break;
  1394. }
  1395. }
  1396. foreach (DataTable dt in resultTableList)
  1397. {
  1398. if (dt.TableName.Equals(this.listView2.SelectedItems[i].Tag))
  1399. {
  1400. resultTableList.Remove(dt);
  1401. break;
  1402. }
  1403. }
  1404. for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
  1405. {
  1406. System.Data.DataTable dataTable1 = dataTables[dataTableI];
  1407. if (dataTable1.TableName.Equals(this.listView2.SelectedItems[i].Tag/*tag*/))
  1408. dataTables.RemoveAt(dataTableI);
  1409. }
  1410. if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag))
  1411. bitDic.Remove((string)this.listView2.SelectedItems[i].Tag);
  1412. foreach (ExportProjectModel model in this.tempDataModel)
  1413. {
  1414. if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag))
  1415. {
  1416. this.tempDataModel.Remove(model);
  1417. break;
  1418. }
  1419. }
  1420. this.listView2.Items.RemoveAt(selectIndex);
  1421. }
  1422. if (this.listView2.Items.Count == 0)
  1423. {
  1424. this.dataGridView_Total.Rows.Clear();
  1425. this.dataGridView2.Rows.Clear();
  1426. }
  1427. else
  1428. RefreshDataGridView2();
  1429. //RefreshDataGridView4();
  1430. }
  1431. }
  1432. else
  1433. {
  1434. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
  1435. }
  1436. }
  1437. else
  1438. {
  1439. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  1440. }
  1441. }
  1442. /// <summary>
  1443. /// 小数位数
  1444. /// </summary>
  1445. /// <param name="sender"></param>
  1446. /// <param name="e"></param>
  1447. private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
  1448. {
  1449. if (this.numericUpDown1_0.Value > this.numericUpDown1_0.Maximum)
  1450. this.numericUpDown1_0.Value = this.numericUpDown1_0.Maximum;
  1451. if (this.numericUpDown1_0.Value < this.numericUpDown1_0.Minimum)
  1452. this.numericUpDown1_0.Value = this.numericUpDown1_0.Minimum;
  1453. RefreshDataGridView1();
  1454. RefreshDataGridView2();
  1455. }
  1456. /// <summary>
  1457. /// 生成报告
  1458. /// </summary>
  1459. /// <param name="sender"></param>
  1460. /// <param name="e"></param>
  1461. private void button_generateReport_Click(object sender, EventArgs e)
  1462. {
  1463. //if (this.listView2.Items.Count == 0)
  1464. //{
  1465. // MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  1466. // return;
  1467. //}
  1468. //if (this.checkBox_generateReport_opensetting.Checked)
  1469. // this.button_setting.PerformClick();
  1470. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  1471. {
  1472. ////获取word书签与excel单元格的关系,以字典方式存储
  1473. //List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  1474. //Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1475. //if (mic_module_infos != null && mic_module_infos.Count > 0)
  1476. //{
  1477. // foreach (mic_module_infos info in mic_module_infos)
  1478. // {
  1479. // tagInfos.Add(info.tag_name, info.cell_position);
  1480. // }
  1481. //}
  1482. ////分析结果
  1483. //List<List<string>> analysisContent = new List<List<string>>();
  1484. //List<string> contentHeaderText = new List<string>();
  1485. //foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  1486. //{
  1487. // contentHeaderText.Add(c.HeaderText);
  1488. //}
  1489. //analysisContent.Add(contentHeaderText);
  1490. //foreach (DataGridViewRow item in this.dataGridView2.Rows)//##########################
  1491. //{
  1492. // List<string> content = new List<string>();
  1493. // for (int i = 0; i < contentHeaderText.Count; i++)
  1494. // {
  1495. // content.Add(item.Cells[i].Value.ToString());
  1496. // }
  1497. // analysisContent.Add(content);
  1498. //}
  1499. ////图片
  1500. //bitList = new List<Bitmap>();
  1501. //if (this.allShow)
  1502. //{
  1503. // foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  1504. // {
  1505. // bitList.Add(kv.Value[0]);
  1506. // bitList.Add(kv.Value[1]);
  1507. // }
  1508. //}
  1509. //else
  1510. //{
  1511. // if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  1512. // {
  1513. // foreach (ListViewItem item in this.listView2.SelectedItems)
  1514. // {
  1515. // if (bitDic.ContainsKey(item.Name))
  1516. // {
  1517. // bitList.Add(bitDic[item.Name][0]);
  1518. // bitList.Add(bitDic[item.Name][1]);
  1519. // }
  1520. // else if (bitDic.ContainsKey(item.Tag.ToString()))
  1521. // {
  1522. // bitList.Add(bitDic[item.Tag.ToString()][0]);
  1523. // bitList.Add(bitDic[item.Tag.ToString()][1]);
  1524. // }
  1525. // }
  1526. // }
  1527. // else if (this.listView2.Items.Count > 0)
  1528. // {
  1529. // ListViewItem item = this.listView2.Items[0];
  1530. // if (bitDic.ContainsKey(item.Name))
  1531. // {
  1532. // bitList.Add(bitDic[item.Name][0]);
  1533. // bitList.Add(bitDic[item.Name][1]);
  1534. // }
  1535. // else if (bitDic.ContainsKey(item.Tag.ToString()))
  1536. // {
  1537. // bitList.Add(bitDic[item.Tag.ToString()][0]);
  1538. // bitList.Add(bitDic[item.Tag.ToString()][1]);
  1539. // }
  1540. // }
  1541. //}
  1542. //this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  1543. }
  1544. //else
  1545. // MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  1546. if (this.listView2.Items.Count == 0)
  1547. {
  1548. MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  1549. return;
  1550. }
  1551. if (this.checkBox_generateReport_opensetting.Checked)
  1552. this.button_setting.PerformClick();
  1553. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  1554. {
  1555. //获取word书签与excel单元格的关系,以字典方式存储
  1556. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  1557. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1558. if (mic_module_infos != null && mic_module_infos.Count > 0)
  1559. {
  1560. foreach (mic_module_infos info in mic_module_infos)
  1561. {
  1562. tagInfos.Add(info.tag_name, info.cell_position);
  1563. }
  1564. }
  1565. //分析结果
  1566. List<List<string>> analysisContent = new List<List<string>>();
  1567. List<string> contentHeaderText = new List<string>();
  1568. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  1569. {
  1570. contentHeaderText.Add(c.HeaderText);
  1571. }
  1572. analysisContent.Add(contentHeaderText);
  1573. foreach (DataGridViewRow item in this.dataGridView2.Rows)//##########################
  1574. {
  1575. List<string> content = new List<string>();
  1576. for (int i = 0; i < contentHeaderText.Count; i++)
  1577. {
  1578. content.Add(item.Cells[i].Value.ToString());
  1579. }
  1580. analysisContent.Add(content);
  1581. }
  1582. List<string> contentHeaderText2 = new List<string>();
  1583. foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
  1584. {
  1585. contentHeaderText2.Add(c.HeaderText);
  1586. }
  1587. analysisContent.Add(contentHeaderText2);
  1588. foreach (DataGridViewRow item in this.dataGridView_Total.Rows)//##########################
  1589. {
  1590. List<string> content = new List<string>();
  1591. for (int i = 0; i < contentHeaderText2.Count; i++)
  1592. {
  1593. content.Add(item.Cells[i].Value.ToString());
  1594. }
  1595. analysisContent.Add(content);
  1596. }
  1597. //图片
  1598. bitList = new List<Bitmap>();
  1599. if (this.allShow)
  1600. {
  1601. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  1602. {
  1603. bitList.Add(kv.Value[0]);
  1604. bitList.Add(kv.Value[1]);
  1605. }
  1606. }
  1607. else
  1608. {
  1609. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  1610. {
  1611. foreach (ListViewItem item in this.listView2.SelectedItems)
  1612. {
  1613. if (bitDic.ContainsKey(item.Name))
  1614. {
  1615. bitList.Add(bitDic[item.Name][0]);
  1616. bitList.Add(bitDic[item.Name][1]);
  1617. }
  1618. else if (bitDic.ContainsKey(item.Tag.ToString()))
  1619. {
  1620. bitList.Add(bitDic[item.Tag.ToString()][0]);
  1621. bitList.Add(bitDic[item.Tag.ToString()][1]);
  1622. }
  1623. }
  1624. }
  1625. else if (this.listView2.Items.Count > 0)
  1626. {
  1627. ListViewItem item = this.listView2.Items[0];
  1628. if (bitDic.ContainsKey(item.Name))
  1629. {
  1630. bitList.Add(bitDic[item.Name][0]);
  1631. bitList.Add(bitDic[item.Name][1]);
  1632. }
  1633. else if (bitDic.ContainsKey(item.Tag.ToString()))
  1634. {
  1635. bitList.Add(bitDic[item.Tag.ToString()][0]);
  1636. bitList.Add(bitDic[item.Tag.ToString()][1]);
  1637. }
  1638. }
  1639. }
  1640. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  1641. }
  1642. else
  1643. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text") + "!");
  1644. }
  1645. /// <summary>
  1646. /// 导出多 Sheet 报表
  1647. /// </summary>
  1648. /// <param name="ds">要导出的数据</param>
  1649. public void DataToExcle(System.Data.DataSet ds)
  1650. {
  1651. try
  1652. {
  1653. if (ds.Tables == null || ds.Tables.Count == 0)
  1654. {
  1655. MessageBox.Show(PdnResources.GetString("Menu.Nonedata.Text")+"!");
  1656. return;
  1657. }
  1658. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1659. saveFileDialog.DefaultExt = "xlsx";
  1660. saveFileDialog.Title = PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text");
  1661. saveFileDialog.FileName = this.Text + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddhhmmss");
  1662. saveFileDialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx";
  1663. saveFileDialog.RestoreDirectory = true;
  1664. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  1665. {
  1666. List<System.Data.DataTable> list = new List<System.Data.DataTable>();
  1667. foreach (System.Data.DataTable itemTable in ds.Tables)
  1668. list.Add(itemTable);
  1669. this.appWorkspace.ExportDataToExcelWithProgress(list, saveFileDialog.FileName, true, false, true);
  1670. }
  1671. }
  1672. catch (Exception e)
  1673. {
  1674. throw e;
  1675. }
  1676. }
  1677. /// <summary>
  1678. /// 刷新分析结果表
  1679. /// </summary>
  1680. private void RefreshDataGridView2()
  1681. {
  1682. this.dataGridView2.Rows.Clear();
  1683. double dValue;
  1684. List<double> totalValueList = new List<double>();
  1685. for (int i = 0; i < this.dataGridView_Total.Columns.Count; i++)
  1686. {
  1687. totalValueList.Add(0.0);
  1688. }
  1689. int startFromIndex = 1;
  1690. if (IndexChangedFromIndex.Count > 0)
  1691. startFromIndex = IndexChangedFromIndex[0];
  1692. if (this.allShow)
  1693. {
  1694. foreach (DataTable dt in resultTableList)
  1695. for (int i = 0; i < dt.Rows.Count; i++)
  1696. {
  1697. DataGridViewRow row = new DataGridViewRow();
  1698. row.Height = 30;
  1699. for (int rowJ = 0; rowJ < startFromIndex; rowJ++)
  1700. row.Cells.Add(CreateTextBoxCell(dt.Rows[i][rowJ].ToString(), ""));
  1701. for (int rowJ = startFromIndex; rowJ < dt.Rows[i].ItemArray.Length; rowJ++)
  1702. {
  1703. row.Cells.Add(CreateTextBoxCell(this.resShow(dt.Rows[i][rowJ].ToString()), ""));
  1704. if (double.TryParse(dt.Rows[i][rowJ].ToString(), out dValue))
  1705. totalValueList[rowJ - startFromIndex] = totalValueList[rowJ - startFromIndex] + dValue;
  1706. }
  1707. this.dataGridView2.Rows.Add(row);
  1708. }
  1709. }
  1710. else
  1711. {
  1712. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  1713. {
  1714. for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1715. foreach (DataTable dt in resultTableList)
  1716. if (dt.TableName.Equals((string)this.listView2.SelectedItems[i].Tag))
  1717. for (int j = 0; j < dt.Rows.Count; j++)
  1718. {
  1719. DataGridViewRow row = new DataGridViewRow();
  1720. row.Height = 30;
  1721. for (int rowJ = 0; rowJ < startFromIndex; rowJ++)
  1722. row.Cells.Add(CreateTextBoxCell(dt.Rows[i][rowJ].ToString(), ""));
  1723. for (int rowJ = startFromIndex; rowJ < dt.Rows[j].ItemArray.Length; rowJ++)
  1724. {
  1725. row.Cells.Add(CreateTextBoxCell(this.resShow(dt.Rows[j][rowJ].ToString()), ""));
  1726. if (double.TryParse(dt.Rows[j][rowJ].ToString(), out dValue))
  1727. totalValueList[rowJ - startFromIndex] = totalValueList[rowJ - startFromIndex] + dValue;
  1728. }
  1729. this.dataGridView2.Rows.Add(row);
  1730. }
  1731. }
  1732. else if (this.listView2.Items.Count > 0)
  1733. {
  1734. string tableName = (string)this.listView2.Items[0].Tag;
  1735. foreach (DataTable dt in resultTableList)
  1736. if (dt.TableName.Equals(tableName))
  1737. for (int j = 0; j < dt.Rows.Count; j++)
  1738. {
  1739. DataGridViewRow row = new DataGridViewRow();
  1740. row.Height = 30;
  1741. for (int rowJ = 0; rowJ < startFromIndex; rowJ++)
  1742. row.Cells.Add(CreateTextBoxCell(dt.Rows[j][rowJ].ToString(), ""));
  1743. for (int rowJ = startFromIndex; rowJ < dt.Rows[j].ItemArray.Length; rowJ++)
  1744. {
  1745. row.Cells.Add(CreateTextBoxCell(this.resShow(dt.Rows[j][rowJ].ToString()), ""));
  1746. if (double.TryParse(dt.Rows[j][rowJ].ToString(), out dValue))
  1747. totalValueList[rowJ - startFromIndex] = totalValueList[rowJ - startFromIndex] + dValue;
  1748. }
  1749. this.dataGridView2.Rows.Add(row);
  1750. }
  1751. }
  1752. }
  1753. this.dataGridView_Total.Rows.Clear();
  1754. if (this.dataGridView2.Rows.Count > 0 && this.dataGridView_Total.Columns.Count == totalValueList.Count)
  1755. {
  1756. DataGridViewRow row = new DataGridViewRow();
  1757. row.Height = 30;
  1758. for (int i = 0; i < this.dataGridView_Total.Columns.Count; i++)
  1759. {
  1760. row.Cells.Add(CreateTextBoxCell(this.resShow((totalValueList[i] / this.dataGridView2.Rows.Count).ToString()), ""));
  1761. }
  1762. this.dataGridView_Total.Rows.Add(row);
  1763. }
  1764. }
  1765. #region 公共按钮
  1766. private void zoomInButton_Click(object sender, EventArgs e)
  1767. {
  1768. this.documentWorkspace.ZoomIn();
  1769. }
  1770. private void zoomOutButton_Click(object sender, EventArgs e)
  1771. {
  1772. this.documentWorkspace.ZoomOut();
  1773. }
  1774. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1775. {
  1776. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1777. }
  1778. private void actualSizeButton_Click(object sender, EventArgs e)
  1779. {
  1780. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1781. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1782. }
  1783. private void pointerButton_Click(object sender, EventArgs e)
  1784. {
  1785. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
  1786. }
  1787. private void mobileModeButton_Click(object sender, EventArgs e)
  1788. {
  1789. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1790. }
  1791. #endregion
  1792. #region 矩形拖动
  1793. /// <summary>
  1794. /// 防止拖动鼠标与小手动作的冲突
  1795. /// </summary>
  1796. /// <returns></returns>
  1797. protected bool CanUseMouseFunctions()
  1798. {//#22071
  1799. return this.documentWorkspace.ActiveTool != Annotation.Enum.DrawToolType.MoveMode;
  1800. }
  1801. /// <summary>
  1802. /// 鼠标按下
  1803. /// </summary>
  1804. /// <param name="drawArea"></param>
  1805. /// <param name="e"></param>
  1806. protected virtual void OnMouseDown(object sender, MouseEventArgs e)
  1807. {
  1808. //// 换算后的点
  1809. //PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1810. }
  1811. /// <summary>
  1812. /// 移动
  1813. /// </summary>
  1814. /// <param name="sender"></param>
  1815. /// <param name="e"></param>
  1816. protected virtual void onMouseMove(object sender, MouseEventArgs e)
  1817. {
  1818. this.documentWorkspace.Refresh();
  1819. //// 换算后的点
  1820. //PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1821. }
  1822. /// <summary>
  1823. /// 鼠标抬起
  1824. /// </summary>
  1825. /// <param name="sender"></param>
  1826. /// <param name="e"></param>
  1827. protected virtual void onMouseUp(object sender, MouseEventArgs e)
  1828. {
  1829. //m_canMove = false;
  1830. }
  1831. #endregion
  1832. #endregion
  1833. #region 可调用方法
  1834. /// <summary>
  1835. /// 颜色点击事件
  1836. /// </summary>
  1837. /// <param name="sender"></param>
  1838. /// <param name="e"></param>
  1839. protected void panel1_Click(object sender, EventArgs e)
  1840. {
  1841. this.panelC = (Panel)sender;
  1842. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panelC.BackColor);
  1843. this.colorsFormGrid.ShowDialog();
  1844. }
  1845. ///// <summary>
  1846. ///// 是否能取到二值的结果
  1847. ///// </summary>
  1848. ///// <returns></returns>
  1849. //protected Boolean getBinaryChecked()
  1850. //{
  1851. // return (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null);
  1852. //}
  1853. /// <summary>
  1854. /// 返回当前选择的图片内容
  1855. /// </summary>
  1856. /// <returns></returns>
  1857. protected DocumentWorkspace getCurrentWorkspace()
  1858. {
  1859. return this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index];
  1860. }
  1861. /// <summary>
  1862. /// 返回当前选择的图片tag
  1863. /// </summary>
  1864. /// <returns></returns>
  1865. protected string getCurrentWorkTag()
  1866. {
  1867. return this.imageList_img.Images.Keys[this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : lstView_img.SelectedItems[0].Index/*lstView_img.SelectedItems[0].Index*/];
  1868. }
  1869. #endregion
  1870. #region 需继承方法
  1871. /// <summary>
  1872. /// 小数点位数变化时刷新界面的数据
  1873. /// </summary>
  1874. protected virtual void RefreshDataGridView1()
  1875. {
  1876. }
  1877. /// <summary>
  1878. /// 图片索引改变后调用的事件
  1879. /// </summary>
  1880. protected virtual void refreshWhileImgChanged()
  1881. {
  1882. }
  1883. /// <summary>
  1884. /// 计算结果是否存在
  1885. /// </summary>
  1886. /// <returns>返回是否可以计算和保存结果</returns>
  1887. protected virtual bool resultCalculateExist()
  1888. {
  1889. return false;
  1890. }
  1891. /// <summary>
  1892. /// 计算结果
  1893. /// </summary>
  1894. /// <param name="sender"></param>
  1895. /// <param name="e"></param>
  1896. protected virtual void buttonCalculate_Click(object sender, EventArgs e)
  1897. {
  1898. }
  1899. /// <summary>
  1900. /// 点击保存结果按钮,用来返回需要新增的一行数据
  1901. /// </summary>
  1902. /// <param name="tag"></param>
  1903. /// <param name="imgName"></param>
  1904. /// <returns></returns>
  1905. protected virtual DataTable toInsertTableRow(string tag, string imgName)
  1906. {
  1907. DataTable dt = new DataTable(tag);
  1908. return dt;
  1909. }
  1910. /// <summary>
  1911. /// 保存结果
  1912. /// </summary>
  1913. protected virtual void buildListBox_analysisResult()
  1914. {
  1915. if (this.matOrg == null)
  1916. {
  1917. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  1918. return;
  1919. }
  1920. string imgName = getCurrentWorkspace().GetFriendlyName();
  1921. string tag = getCurrentWorkTag();
  1922. bool replace = false;
  1923. int rowIndex = 0;
  1924. if (!resultCalculateExist())
  1925. {
  1926. MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
  1927. return;
  1928. }
  1929. if (!calculate1d)
  1930. {
  1931. MessageBox.Show("请先计算结果"/*PdnResources.GetString("Menu.Pleasedrawthemeasuringlinefirst.text")*/);
  1932. return;
  1933. }
  1934. if (this.listView2.Items.Count > 0)
  1935. {
  1936. foreach (ListViewItem item in this.listView2.Items)
  1937. {
  1938. if (item.Tag.Equals(tag))
  1939. {
  1940. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theanalysisreertoreplaceit.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1941. if (dr == DialogResult.OK)
  1942. {
  1943. replace = true;
  1944. }
  1945. else
  1946. {
  1947. return;
  1948. }
  1949. break;
  1950. }
  1951. }
  1952. }
  1953. if (!replace)
  1954. {
  1955. ListViewItem listViewItem = new ListViewItem();
  1956. listViewItem.SubItems[0].Text = imgName;
  1957. listViewItem.Tag = "" + tag;
  1958. if (this.listView2.Items.Count == 0)
  1959. this.listView2.Items.Add(listViewItem);
  1960. else
  1961. this.listView2.Items.Insert(0, listViewItem);
  1962. }
  1963. //有重名需要替换
  1964. if (replace)
  1965. {
  1966. for (int i = 0; i < this.resultTableList.Count; i++)
  1967. {
  1968. if (this.resultTableList[i].TableName.Equals(tag))
  1969. {
  1970. rowIndex = i;
  1971. this.resultTableList.Remove(this.resultTableList[i]);
  1972. resultTableList.Insert(rowIndex, toInsertTableRow(tag, imgName));
  1973. }
  1974. }
  1975. }
  1976. //新增
  1977. else
  1978. resultTableList.Add(toInsertTableRow(tag, imgName));
  1979. RefreshDataGridView2();
  1980. //保存处理后的图片
  1981. double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.selectPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1982. List<Bitmap> tempBit = new List<Bitmap>();
  1983. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.imageMat);// this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1984. originalBit.Tag = pantographRatio;
  1985. tempBit.Add(originalBit);
  1986. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1987. Graphics graphics = Graphics.FromImage(newBit);
  1988. if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
  1989. {
  1990. Mat targetMat = this.documentWorkspace.PhaseModels[0].mat;
  1991. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  1992. }
  1993. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1994. drawSubclass/*Draw*/(graphics);
  1995. newBit.Tag = pantographRatio;
  1996. tempBit.Add(newBit);
  1997. if (bitDic.ContainsKey(tag))
  1998. bitDic[tag] = tempBit;
  1999. else
  2000. bitDic.Add(tag, tempBit);
  2001. //拼接中间数据
  2002. //-->
  2003. bool isExist = false;//是否已存在进行替换
  2004. int modelIndex = -1;//要替换的下标
  2005. for (int j = 0; j < tempDataModel.Count; j++)
  2006. {
  2007. if (tempDataModel[j].tagName.Equals(tag))
  2008. {
  2009. isExist = true;
  2010. modelIndex = j;
  2011. break;
  2012. }
  2013. }
  2014. if (isExist && modelIndex > -1)
  2015. {
  2016. List<List<string>> tempDataList = buildTempDataList();
  2017. if (tempDataList != null)
  2018. tempDataModel[modelIndex].dataList = tempDataList;
  2019. }
  2020. else
  2021. {
  2022. ExportProjectModel newModel = new ExportProjectModel();
  2023. newModel.tagName = tag;
  2024. newModel.picName = getCurrentWorkspace().GetFriendlyName();
  2025. List<List<string>> tempDataList = buildTempDataList();
  2026. newModel.dataList = tempDataList;
  2027. if (tempDataList != null)
  2028. tempDataModel.Add(newModel);
  2029. }
  2030. //buildListBoxArea_analysisResult();
  2031. }
  2032. /// <summary>
  2033. /// 拼接中间数据
  2034. /// </summary>
  2035. /// <returns></returns>
  2036. protected virtual List<List<string>> buildTempDataList()
  2037. {
  2038. return null;
  2039. //List<List<string>> dataList = new List<List<string>>();
  2040. //return dataList;
  2041. }
  2042. /// <summary>
  2043. /// 添加内容单元格
  2044. /// </summary>
  2045. /// <param name="text"></param>
  2046. /// <param name="tag"></param>
  2047. /// <returns></returns>
  2048. protected DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
  2049. {
  2050. DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
  2051. textboxcell.Value = text;
  2052. textboxcell.Tag = tag;
  2053. return textboxcell;
  2054. }
  2055. /// <summary>
  2056. /// 小数位数格式化 //0916###18530
  2057. /// </summary>
  2058. /// <param name="resValue"></param>
  2059. /// <returns></returns>
  2060. protected string resShow(string resValue)
  2061. {
  2062. if (string.IsNullOrEmpty(resValue))
  2063. {
  2064. return "0";
  2065. }
  2066. double dValue;
  2067. if (!double.TryParse(resValue, out dValue))
  2068. {
  2069. return resValue;
  2070. }
  2071. return Math.Round(dValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  2072. }
  2073. protected virtual void SubclassInitialize()
  2074. {
  2075. throw new NotImplementedException();
  2076. }
  2077. /// <summary>
  2078. /// 报告模板命名
  2079. /// </summary>
  2080. /// <returns></returns>
  2081. protected virtual string getTemplateName()
  2082. {
  2083. throw new NotImplementedException();
  2084. }
  2085. /// <summary>
  2086. /// 项目工程内的文件夹路径名称
  2087. /// </summary>
  2088. /// <returns></returns>
  2089. protected virtual string getProjectEngineeringName()
  2090. {
  2091. throw new NotImplementedException();
  2092. }
  2093. protected virtual void drawSubclass(Graphics graphics)
  2094. {
  2095. ////显示辅助线
  2096. //if (showGridChecked())
  2097. // if (isAreaType)
  2098. // guideClass.DrawAreaGuide(graphics, this.comboBox1.SelectedItem);
  2099. // else
  2100. // guideClass.DrawGuideLines(graphics, this.comboBox1.SelectedItem);
  2101. ////显示截点
  2102. //if (drawGuidePoints())
  2103. // styleClass.DrawGuidePoints(graphics);
  2104. }
  2105. ///// <summary>
  2106. ///// 刷新图形边线点集合
  2107. ///// </summary>
  2108. //protected virtual void AddRectangleToRectangleFCaps()
  2109. //{
  2110. // this.documentWorkspace.Refresh();
  2111. //}
  2112. #endregion
  2113. }
  2114. }