NonFMetalsStandardDialog.cs 104 KB

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