MethodCutOffDialog.cs 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115
  1. using OpenCvSharp;
  2. using PaintDotNet.Base.SettingModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using GroupBox = System.Windows.Forms.GroupBox;
  8. using CheckBox = System.Windows.Forms.CheckBox;
  9. using Button = System.Windows.Forms.Button;
  10. using System.Data;
  11. using PaintDotNet.Base.CommTool;
  12. using System.Drawing.Drawing2D;
  13. using PaintDotNet.Annotation.Enum;
  14. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.ManualMethod
  15. {
  16. internal class MethodCutOffDialog : GrainSizeStandardDialog
  17. {
  18. /// <summary>
  19. /// 调色板
  20. /// </summary>
  21. private ColorsForm colorsFormGrid;
  22. private Panel panelC;
  23. /// <summary>
  24. /// 鼠标状态(0:添加 1:删除 2:选择)
  25. /// </summary>
  26. private int mouseStatus = -1;
  27. /// <summary>
  28. /// 测量线类型(0:全方位 1:水平 2:垂直)
  29. /// </summary>
  30. private int lineStyle = 0;
  31. /// <summary>
  32. /// 线条矩形
  33. /// </summary>
  34. private Dictionary<PointF[], int> rectangleFsLines = new Dictionary<PointF[], int>();
  35. private int selectLineIndex = -1;
  36. private PointF movePointStart;
  37. bool canMove = false;
  38. int movePointIndex = -1;
  39. bool canAdd = false;
  40. private int defaultIndex = -1;
  41. private bool canChange = false;
  42. /// <summary>
  43. /// 标尺
  44. /// </summary>
  45. private double unitLength;
  46. /// <summary>
  47. /// 数据展示
  48. /// </summary>
  49. private DataTable dataTable;
  50. /// <summary>
  51. /// 存在视场标记
  52. /// </summary>
  53. private bool existViewFlag = false;
  54. /// <summary>
  55. /// 线条绘制点矩形集合
  56. /// </summary>
  57. private Dictionary<RectangleF[], int> rectangleFs = new Dictionary<RectangleF[], int>();
  58. /// <summary>
  59. /// 线条绘制点矩形
  60. /// </summary>
  61. private RectangleF[] rectangleFsArr = new RectangleF[2];
  62. /// <summary>
  63. /// 线条矩形
  64. /// </summary>
  65. private PointF[] pointFsLine = new PointF[4];
  66. /// <summary>
  67. /// 测定结果暂存
  68. /// </summary>
  69. private List<DataTable> dataTable1s = new List<DataTable>();
  70. /// <summary>
  71. /// 储存点击保存结果后的所有原图与分析图
  72. /// </summary>
  73. private Dictionary<string, List<Bitmap>> bitCeDingDic = new Dictionary<string, List<Bitmap>>();
  74. protected static string ParamKey_MainFontSize = "MainFontSize";//字号
  75. protected static string ParamKey_MainFontColor = "MainFontColor"; // 字体颜色
  76. protected static string ParamKey_MainLineWidth = "MainLineWidth";
  77. protected static string ParamKey_MainLineColor = "MainLineColor";
  78. #region 组件
  79. private GroupBox groupBox11;
  80. private CheckBox checkBox3_0;
  81. private DataGridViewTextBoxColumn ColumnTotal1;
  82. private DataGridViewTextBoxColumn ColumnTotal2;
  83. private DataGridViewTextBoxColumn ColumnTotal3;
  84. private DataGridViewTextBoxColumn ColumnTotal4;
  85. private DataGridViewTextBoxColumn ColumnTotal5;
  86. private DataGridViewTextBoxColumn ColumnTotal6;
  87. private DataGridViewTextBoxColumn Column1;
  88. private DataGridViewTextBoxColumn Column2;
  89. private DataGridViewTextBoxColumn Column3;
  90. private DataGridViewTextBoxColumn Column4;
  91. private DataGridViewTextBoxColumn Column5;
  92. private DataGridViewTextBoxColumn Graisize;
  93. private DataGridViewTextBoxColumn Grainnumber;
  94. private DataGridViewTextBoxColumn Grainintercept;
  95. private DataGridViewTextBoxColumn Graingrade;
  96. private GroupBox groupBox1;
  97. private Button button10;
  98. private Button button7_0;
  99. private GroupBox groupBox2;
  100. private Label label4;
  101. private Label label3;
  102. private Label label5;
  103. private DataGridViewTextBoxColumn Column11;
  104. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
  105. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
  106. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
  107. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
  108. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;
  109. private Label label8;
  110. private Label label7;
  111. private Label label6;
  112. private Label label1;
  113. private Panel panel2;
  114. private Panel panel1;
  115. private NumericUpDown numericUpDown3;
  116. private NumericUpDown numericUpDown4;
  117. private Button button2;
  118. private DataGridView dataGridView1;
  119. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn9;
  120. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn10;
  121. private Label labelNum;
  122. private Label labelMin;
  123. private Label labelMax;
  124. private DataGridViewTextBoxColumn Column6;
  125. #endregion 组件
  126. #region 构造函数
  127. public MethodCutOffDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) : base(appWorkspace, menuItem, null, 0)
  128. {
  129. //
  130. //初始化色板
  131. //
  132. this.colorsFormGrid = new ColorsForm();
  133. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  134. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  135. getSonData();
  136. }
  137. #endregion 构造函数
  138. #region 初始化组件
  139. private void InitializeComponentText()
  140. {
  141. //this.groupBox10.Text = PdnResources.GetString("Menu.sectionoperation.text");
  142. }
  143. private void InitializeComponent()
  144. {
  145. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  146. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  147. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
  148. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
  149. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
  150. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
  151. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
  152. this.groupBox11 = new System.Windows.Forms.GroupBox();
  153. this.numericUpDown4 = new System.Windows.Forms.NumericUpDown();
  154. this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
  155. this.panel2 = new System.Windows.Forms.Panel();
  156. this.panel1 = new System.Windows.Forms.Panel();
  157. this.label8 = new System.Windows.Forms.Label();
  158. this.label7 = new System.Windows.Forms.Label();
  159. this.label6 = new System.Windows.Forms.Label();
  160. this.label1 = new System.Windows.Forms.Label();
  161. this.checkBox3_0 = new System.Windows.Forms.CheckBox();
  162. this.Graisize = new System.Windows.Forms.DataGridViewTextBoxColumn();
  163. this.Grainnumber = new System.Windows.Forms.DataGridViewTextBoxColumn();
  164. this.Grainintercept = new System.Windows.Forms.DataGridViewTextBoxColumn();
  165. this.Graingrade = new System.Windows.Forms.DataGridViewTextBoxColumn();
  166. this.groupBox1 = new System.Windows.Forms.GroupBox();
  167. this.button2 = new System.Windows.Forms.Button();
  168. this.button10 = new System.Windows.Forms.Button();
  169. this.button7_0 = new System.Windows.Forms.Button();
  170. this.groupBox2 = new System.Windows.Forms.GroupBox();
  171. this.labelNum = new System.Windows.Forms.Label();
  172. this.labelMin = new System.Windows.Forms.Label();
  173. this.labelMax = new System.Windows.Forms.Label();
  174. this.label5 = new System.Windows.Forms.Label();
  175. this.label4 = new System.Windows.Forms.Label();
  176. this.label3 = new System.Windows.Forms.Label();
  177. this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  178. this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  179. this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  180. this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  181. this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  182. this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  183. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  184. this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  185. this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  186. this.groupBox_img.SuspendLayout();
  187. this.groupBox_analysisResult1.SuspendLayout();
  188. this.groupBox3.SuspendLayout();
  189. this.groupBox11.SuspendLayout();
  190. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit();
  191. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
  192. this.groupBox1.SuspendLayout();
  193. this.groupBox2.SuspendLayout();
  194. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  195. this.SuspendLayout();
  196. //
  197. // groupBox11
  198. //
  199. this.groupBox11.Controls.Add(this.numericUpDown4);
  200. this.groupBox11.Controls.Add(this.numericUpDown3);
  201. this.groupBox11.Controls.Add(this.panel2);
  202. this.groupBox11.Controls.Add(this.panel1);
  203. this.groupBox11.Controls.Add(this.label8);
  204. this.groupBox11.Controls.Add(this.label7);
  205. this.groupBox11.Controls.Add(this.label6);
  206. this.groupBox11.Controls.Add(this.label1);
  207. this.groupBox11.Controls.Add(this.checkBox3_0);
  208. this.groupBox11.Location = new System.Drawing.Point(178, 364);
  209. this.groupBox11.Name = "groupBox11";
  210. this.groupBox11.Size = new System.Drawing.Size(356, 83);
  211. this.groupBox11.TabIndex = 39;
  212. this.groupBox11.TabStop = false;
  213. //
  214. // numericUpDown4
  215. //
  216. this.numericUpDown4.Location = new System.Drawing.Point(60, 37);
  217. this.numericUpDown4.Maximum = new decimal(new int[] {
  218. 9999,
  219. 0,
  220. 0,
  221. 0});
  222. this.numericUpDown4.Minimum = new decimal(new int[] {
  223. 1,
  224. 0,
  225. 0,
  226. 0});
  227. this.numericUpDown4.Name = "numericUpDown4";
  228. this.numericUpDown4.Size = new System.Drawing.Size(55, 21);
  229. this.numericUpDown4.TabIndex = 30;
  230. this.numericUpDown4.Value = new decimal(new int[] {
  231. 20,
  232. 0,
  233. 0,
  234. 0});
  235. //
  236. // numericUpDown3
  237. //
  238. this.numericUpDown3.Location = new System.Drawing.Point(60, 59);
  239. this.numericUpDown3.Maximum = new decimal(new int[] {
  240. 9999,
  241. 0,
  242. 0,
  243. 0});
  244. this.numericUpDown3.Minimum = new decimal(new int[] {
  245. 1,
  246. 0,
  247. 0,
  248. 0});
  249. this.numericUpDown3.Name = "numericUpDown3";
  250. this.numericUpDown3.Size = new System.Drawing.Size(55, 21);
  251. this.numericUpDown3.TabIndex = 29;
  252. this.numericUpDown3.Value = new decimal(new int[] {
  253. 1,
  254. 0,
  255. 0,
  256. 0});
  257. //
  258. // panel2
  259. //
  260. this.panel2.BackColor = System.Drawing.Color.Blue;
  261. this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  262. this.panel2.Location = new System.Drawing.Point(218, 60);
  263. this.panel2.Name = "panel2";
  264. this.panel2.Size = new System.Drawing.Size(49, 17);
  265. this.panel2.TabIndex = 28;
  266. this.panel2.Click += new System.EventHandler(this.panelC_Click);
  267. //
  268. // panel1
  269. //
  270. this.panel1.BackColor = System.Drawing.Color.Yellow;
  271. this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  272. this.panel1.Location = new System.Drawing.Point(218, 39);
  273. this.panel1.Name = "panel1";
  274. this.panel1.Size = new System.Drawing.Size(49, 17);
  275. this.panel1.TabIndex = 27;
  276. this.panel1.Click += new System.EventHandler(this.panelC_Click);
  277. //
  278. // label8
  279. //
  280. this.label8.AutoSize = true;
  281. this.label8.Location = new System.Drawing.Point(147, 63);
  282. this.label8.Name = "label8";
  283. this.label8.Size = new System.Drawing.Size(65, 12);
  284. this.label8.TabIndex = 8;
  285. this.label8.Text = "截距颜色:";
  286. //
  287. // label7
  288. //
  289. this.label7.AutoSize = true;
  290. this.label7.Location = new System.Drawing.Point(147, 42);
  291. this.label7.Name = "label7";
  292. this.label7.Size = new System.Drawing.Size(65, 12);
  293. this.label7.TabIndex = 7;
  294. this.label7.Text = "字体颜色:";
  295. //
  296. // label6
  297. //
  298. this.label6.AutoSize = true;
  299. this.label6.Location = new System.Drawing.Point(13, 63);
  300. this.label6.Name = "label6";
  301. this.label6.Size = new System.Drawing.Size(41, 12);
  302. this.label6.TabIndex = 6;
  303. this.label6.Text = "线宽:";
  304. //
  305. // label1
  306. //
  307. this.label1.AutoSize = true;
  308. this.label1.Location = new System.Drawing.Point(13, 42);
  309. this.label1.Name = "label1";
  310. this.label1.Size = new System.Drawing.Size(41, 12);
  311. this.label1.TabIndex = 5;
  312. this.label1.Text = "字号:";
  313. //
  314. // checkBox3_0
  315. //
  316. this.checkBox3_0.AutoSize = true;
  317. this.checkBox3_0.Checked = true;
  318. this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked;
  319. this.checkBox3_0.Location = new System.Drawing.Point(15, 19);
  320. this.checkBox3_0.Name = "checkBox3_0";
  321. this.checkBox3_0.Size = new System.Drawing.Size(15, 14);
  322. this.checkBox3_0.TabIndex = 0;
  323. this.checkBox3_0.UseVisualStyleBackColor = true;
  324. this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged);
  325. //
  326. // Graisize
  327. //
  328. this.Graisize.Name = "Graisize";
  329. this.Graisize.ReadOnly = true;
  330. //
  331. // Grainnumber
  332. //
  333. this.Grainnumber.Name = "Grainnumber";
  334. this.Grainnumber.ReadOnly = true;
  335. //
  336. // Grainintercept
  337. //
  338. this.Grainintercept.Name = "Grainintercept";
  339. this.Grainintercept.ReadOnly = true;
  340. //
  341. // Graingrade
  342. //
  343. this.Graingrade.Name = "Graingrade";
  344. this.Graingrade.ReadOnly = true;
  345. //
  346. // groupBox1
  347. //
  348. this.groupBox1.Controls.Add(this.button2);
  349. this.groupBox1.Controls.Add(this.button10);
  350. this.groupBox1.Controls.Add(this.button7_0);
  351. this.groupBox1.Location = new System.Drawing.Point(179, 315);
  352. this.groupBox1.Name = "groupBox1";
  353. this.groupBox1.Size = new System.Drawing.Size(356, 43);
  354. this.groupBox1.TabIndex = 40;
  355. this.groupBox1.TabStop = false;
  356. //
  357. // button2
  358. //
  359. this.button2.BackColor = System.Drawing.SystemColors.Control;
  360. this.button2.Location = new System.Drawing.Point(215, 12);
  361. this.button2.Name = "button2";
  362. this.button2.Size = new System.Drawing.Size(95, 26);
  363. this.button2.TabIndex = 14;
  364. this.button2.UseVisualStyleBackColor = false;
  365. this.button2.Click += new System.EventHandler(this.button2_Click);
  366. //
  367. // button10
  368. //
  369. this.button10.BackColor = System.Drawing.SystemColors.Control;
  370. this.button10.Location = new System.Drawing.Point(114, 12);
  371. this.button10.Name = "button10";
  372. this.button10.Size = new System.Drawing.Size(95, 26);
  373. this.button10.TabIndex = 13;
  374. this.button10.UseVisualStyleBackColor = false;
  375. this.button10.Click += new System.EventHandler(this.button10_Click);
  376. //
  377. // button7_0
  378. //
  379. this.button7_0.BackColor = System.Drawing.SystemColors.Control;
  380. this.button7_0.Location = new System.Drawing.Point(13, 12);
  381. this.button7_0.Name = "button7_0";
  382. this.button7_0.Size = new System.Drawing.Size(95, 26);
  383. this.button7_0.TabIndex = 12;
  384. this.button7_0.UseVisualStyleBackColor = false;
  385. this.button7_0.Click += new System.EventHandler(this.button7_0_Click);
  386. this.button7_0.LostFocus += new System.EventHandler(this.button7_0_LostFocus);
  387. //
  388. // groupBox2
  389. //
  390. this.groupBox2.Controls.Add(this.labelNum);
  391. this.groupBox2.Controls.Add(this.labelMin);
  392. this.groupBox2.Controls.Add(this.labelMax);
  393. this.groupBox2.Controls.Add(this.label5);
  394. this.groupBox2.Controls.Add(this.label4);
  395. this.groupBox2.Controls.Add(this.label3);
  396. this.groupBox2.Location = new System.Drawing.Point(179, 446);
  397. this.groupBox2.Name = "groupBox2";
  398. this.groupBox2.Size = new System.Drawing.Size(356, 39);
  399. this.groupBox2.TabIndex = 41;
  400. this.groupBox2.TabStop = false;
  401. //
  402. // labelNum
  403. //
  404. this.labelNum.AutoSize = true;
  405. this.labelNum.Location = new System.Drawing.Point(309, 17);
  406. this.labelNum.Name = "labelNum";
  407. this.labelNum.Size = new System.Drawing.Size(0, 12);
  408. this.labelNum.TabIndex = 7;
  409. //
  410. // labelMin
  411. //
  412. this.labelMin.AutoSize = true;
  413. this.labelMin.Location = new System.Drawing.Point(176, 17);
  414. this.labelMin.Name = "labelMin";
  415. this.labelMin.Size = new System.Drawing.Size(0, 12);
  416. this.labelMin.TabIndex = 6;
  417. //
  418. // labelMax
  419. //
  420. this.labelMax.AutoSize = true;
  421. this.labelMax.Location = new System.Drawing.Point(57, 17);
  422. this.labelMax.Name = "labelMax";
  423. this.labelMax.Size = new System.Drawing.Size(0, 12);
  424. this.labelMax.TabIndex = 5;
  425. //
  426. // label5
  427. //
  428. this.label5.AutoSize = true;
  429. this.label5.Location = new System.Drawing.Point(13, 17);
  430. this.label5.Name = "label5";
  431. this.label5.Size = new System.Drawing.Size(41, 12);
  432. this.label5.TabIndex = 4;
  433. this.label5.Text = "最大:";
  434. //
  435. // label4
  436. //
  437. this.label4.AutoSize = true;
  438. this.label4.Location = new System.Drawing.Point(129, 17);
  439. this.label4.Name = "label4";
  440. this.label4.Size = new System.Drawing.Size(41, 12);
  441. this.label4.TabIndex = 3;
  442. this.label4.Text = "最小:";
  443. //
  444. // label3
  445. //
  446. this.label3.AutoSize = true;
  447. this.label3.Location = new System.Drawing.Point(262, 17);
  448. this.label3.Name = "label3";
  449. this.label3.Size = new System.Drawing.Size(41, 12);
  450. this.label3.TabIndex = 2;
  451. this.label3.Text = "数量:";
  452. //
  453. // Column11
  454. //
  455. this.Column11.Name = "Column11";
  456. //
  457. // dataGridViewTextBoxColumn1
  458. //
  459. this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
  460. //
  461. // dataGridViewTextBoxColumn2
  462. //
  463. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  464. this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle1;
  465. this.dataGridViewTextBoxColumn2.HeaderText = "1";
  466. this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
  467. this.dataGridViewTextBoxColumn2.ReadOnly = true;
  468. this.dataGridViewTextBoxColumn2.Width = 50;
  469. //
  470. // dataGridViewTextBoxColumn3
  471. //
  472. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  473. this.dataGridViewTextBoxColumn3.DefaultCellStyle = dataGridViewCellStyle2;
  474. this.dataGridViewTextBoxColumn3.HeaderText = ".5";
  475. this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
  476. this.dataGridViewTextBoxColumn3.ReadOnly = true;
  477. this.dataGridViewTextBoxColumn3.Width = 50;
  478. //
  479. // dataGridViewTextBoxColumn4
  480. //
  481. dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  482. this.dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle3;
  483. this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
  484. this.dataGridViewTextBoxColumn4.ReadOnly = true;
  485. this.dataGridViewTextBoxColumn4.Width = 55;
  486. //
  487. // dataGridViewTextBoxColumn5
  488. //
  489. dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  490. this.dataGridViewTextBoxColumn5.DefaultCellStyle = dataGridViewCellStyle4;
  491. this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
  492. this.dataGridViewTextBoxColumn5.ReadOnly = true;
  493. this.dataGridViewTextBoxColumn5.Width = 69;
  494. //
  495. // dataGridView1
  496. //
  497. this.dataGridView1.AllowUserToAddRows = false;
  498. this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  499. dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  500. dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control;
  501. dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  502. dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText;
  503. dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  504. dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  505. dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  506. this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle5;
  507. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  508. this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  509. this.dataGridViewTextBoxColumn9,
  510. this.dataGridViewTextBoxColumn10});
  511. this.dataGridView1.Location = new System.Drawing.Point(178, 487);
  512. this.dataGridView1.MultiSelect = false;
  513. this.dataGridView1.Name = "dataGridView1";
  514. this.dataGridView1.ReadOnly = true;
  515. this.dataGridView1.RowHeadersVisible = false;
  516. this.dataGridView1.RowTemplate.Height = 23;
  517. this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
  518. this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
  519. this.dataGridView1.Size = new System.Drawing.Size(356, 101);
  520. this.dataGridView1.TabIndex = 42;
  521. this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
  522. //
  523. // dataGridViewTextBoxColumn9
  524. //
  525. dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  526. this.dataGridViewTextBoxColumn9.DefaultCellStyle = dataGridViewCellStyle6;
  527. this.dataGridViewTextBoxColumn9.Name = "dataGridViewTextBoxColumn9";
  528. this.dataGridViewTextBoxColumn9.ReadOnly = true;
  529. this.dataGridViewTextBoxColumn9.Width = 111;
  530. //
  531. // dataGridViewTextBoxColumn10
  532. //
  533. dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
  534. this.dataGridViewTextBoxColumn10.DefaultCellStyle = dataGridViewCellStyle7;
  535. this.dataGridViewTextBoxColumn10.Name = "dataGridViewTextBoxColumn10";
  536. this.dataGridViewTextBoxColumn10.ReadOnly = true;
  537. this.dataGridViewTextBoxColumn10.Width = 242;
  538. //
  539. // MethodCutOffDialog
  540. //
  541. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  542. this.ClientSize = new System.Drawing.Size(1127, 810);
  543. this.Controls.Add(this.dataGridView1);
  544. this.Controls.Add(this.groupBox1);
  545. this.Controls.Add(this.groupBox2);
  546. this.Controls.Add(this.groupBox11);
  547. this.KeyPreview = true;
  548. this.Name = "MethodCutOffDialog";
  549. this.Load += new System.EventHandler(this.MethodCutOffDialog_Load);
  550. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MethodCutOffDialog_KeyDown);
  551. this.Controls.SetChildIndex(this.groupBox11, 0);
  552. this.Controls.SetChildIndex(this.groupBox2, 0);
  553. this.Controls.SetChildIndex(this.groupBox3, 0);
  554. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  555. this.Controls.SetChildIndex(this.groupBox_img, 0);
  556. this.Controls.SetChildIndex(this.groupBox_review, 0);
  557. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  558. this.Controls.SetChildIndex(this.groupBox_report, 0);
  559. this.Controls.SetChildIndex(this.groupBox1, 0);
  560. this.Controls.SetChildIndex(this.dataGridView1, 0);
  561. this.groupBox_img.ResumeLayout(false);
  562. this.groupBox_analysisResult1.ResumeLayout(false);
  563. this.groupBox3.ResumeLayout(false);
  564. this.groupBox11.ResumeLayout(false);
  565. this.groupBox11.PerformLayout();
  566. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit();
  567. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
  568. this.groupBox1.ResumeLayout(false);
  569. this.groupBox2.ResumeLayout(false);
  570. this.groupBox2.PerformLayout();
  571. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  572. this.ResumeLayout(false);
  573. }
  574. #endregion 初始化组件
  575. #region 需继承方法
  576. /// <summary>
  577. /// 保存参数
  578. /// </summary>
  579. protected override void saveSonData()
  580. {
  581. saveParamValue(ParamKey_displaygrainboundaries, checkBox3_0.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);
  582. saveParamValue(ParamKey_MainFontSize, numericUpDown4.Value.ToString(), (int)Base.Dtryt.Interger);
  583. saveParamValue(ParamKey_MainFontColor, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger);
  584. saveParamValue(ParamKey_MainLineWidth, numericUpDown3.Value.ToString(), (int)Base.Dtryt.Interger);
  585. saveParamValue(ParamKey_MainLineColor, panel2.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger);
  586. }
  587. /// <summary>
  588. /// 获取参数
  589. /// </summary>
  590. protected override void getSonData()
  591. {
  592. object ShowGrainBoundry;
  593. if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))
  594. checkBox3_0.Checked = Convert.ToInt32(ShowGrainBoundry) == 0 ? true : false;
  595. if (GetParamValue1(ParamKey_MainFontSize, out ShowGrainBoundry))
  596. numericUpDown4.Value = Convert.ToInt32(ShowGrainBoundry);
  597. if (GetParamValue1(ParamKey_MainFontColor, out ShowGrainBoundry))
  598. panel1.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry));
  599. if (GetParamValue1(ParamKey_MainLineWidth, out ShowGrainBoundry))
  600. numericUpDown3.Value = Convert.ToInt32(ShowGrainBoundry);
  601. if (GetParamValue1(ParamKey_MainLineColor, out ShowGrainBoundry))
  602. panel2.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry));
  603. }
  604. /// <summary>
  605. /// 保存结果
  606. /// </summary>
  607. protected override void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false)
  608. {
  609. //if (this.listView1.SelectedItems.Count == 0)
  610. //{
  611. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  612. // return;
  613. //}
  614. //if (this.dataGridView1.Rows.Count == 0)
  615. //{
  616. // MessageBox.Show(PdnResources.GetString("Menu.Noresultdata.text") + "!");
  617. // return;
  618. //}
  619. //string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  620. //string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index];
  621. //DataTable dataTable = new DataTable();
  622. //bool replace = false;
  623. //int add = 0;
  624. //foreach (ListViewItem item in this.listView2.Items)
  625. //{
  626. // if (item.Tag.Equals(tag))
  627. // {
  628. // add++;
  629. // DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  630. // if (dr == DialogResult.OK)
  631. // {
  632. // replace = true;
  633. // this.listView2.Items.Remove(item);
  634. // }
  635. // break;
  636. // }
  637. //}
  638. //if (replace || this.listView2.Items.Count == 0 || add == 0)
  639. //{
  640. // ListViewItem listViewItem = new ListViewItem();
  641. // listViewItem.SubItems[0].Text = imgName;
  642. // listViewItem.Tag = "" + tag;
  643. // if (this.listView2.Items.Count == 0)
  644. // this.listView2.Items.Add(listViewItem);
  645. // else
  646. // this.listView2.Items.Insert(0, listViewItem);
  647. // this.dataGridView4.Rows.Clear();
  648. // for (int i = 0; i < this.dataTable.Rows.Count; i++)
  649. // {
  650. // DataGridViewRow dgvr = new DataGridViewRow();
  651. // dgvr.Tag = tag;
  652. // foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  653. // {
  654. // dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  655. // }
  656. // dgvr.Cells[0].Value = imgName;
  657. // dgvr.Cells[1].Value = this.dataTable.Rows[i][0];
  658. // dgvr.Cells[2].Value = Math.Round(Convert.ToDouble(this.dataTable.Rows[i][1]), Convert.ToInt32(this.numericUpDown1.Value));
  659. // this.dataGridView4.Rows.Add(dgvr);
  660. // }
  661. // dataTable.TableName = tag;
  662. // foreach (System.Data.DataTable dataTable1 in dataTables)
  663. // {
  664. // if (dataTable1.TableName.Equals(dataTable.TableName))
  665. // {
  666. // dataTables.Remove(dataTable1);
  667. // break;
  668. // }
  669. // }
  670. // foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  671. // {
  672. // dataTable.Columns.Add(c.HeaderText);
  673. // }
  674. // for (int i = 0; i < this.dataTable.Rows.Count; i++)
  675. // {
  676. // DataRow dataRow = dataTable.NewRow();
  677. // dataRow[0] = imgName;
  678. // dataRow[1] = this.dataTable.Rows[i][0];
  679. // dataRow[2] = this.dataTable.Rows[i][1];
  680. // dataTable.Rows.Add(dataRow);
  681. // }
  682. // this.dataTables.Add(dataTable);
  683. // if (this.allShow)
  684. // AllShow();
  685. // this.listView2.Items[0].Selected = true;
  686. // if (this.documentWorkspace.PhaseModels[0].mat != null)
  687. // {
  688. // //保存处理后的图片
  689. // List<Bitmap> tempBit = new List<Bitmap>();
  690. // Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  691. // tempBit.Add(originalBit);
  692. // Bitmap processedBit = BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  693. // Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  694. // Graphics graphics = Graphics.FromImage(newBit);
  695. // graphics.DrawImage(processedBit, new PointF(0, 0));
  696. // Draw(graphics);
  697. // tempBit.Add(newBit);
  698. // if (bitDic.ContainsKey(tag))
  699. // bitDic[tag] = tempBit;
  700. // else
  701. // bitDic.Add(tag, tempBit);
  702. // }
  703. // //拼接中间数据
  704. // List<List<string>> dataList = new List<List<string>>();
  705. // List<string> columnName = new List<string>();
  706. // columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  707. // columnName.Add(PdnResources.GetString("Menu.Linelength.text") + "(μm)");
  708. // columnName.Add(PdnResources.GetString("Menu.Startingcoordinates.text"));
  709. // columnName.Add(PdnResources.GetString("Menu.Endpointcoordinates.Text"));
  710. // dataList.Add(columnName);
  711. // int no = 0;
  712. // foreach (var item in rectangleFs)
  713. // {
  714. // double length = BasicCalculationHelper.GetDistance(new Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 10) * unitLength;
  715. // no++;
  716. // List<string> strList = new List<string>();
  717. // strList.Add("" + no);
  718. // strList.Add("" + length);
  719. // strList.Add("(" + (Convert.ToInt32(item.Key[0].X) + 6).ToString() + "," + (Convert.ToInt32(item.Key[0].Y) + 6).ToString() + ")");
  720. // strList.Add("(" + (Convert.ToInt32(item.Key[1].X) + 6).ToString() + "," + (Convert.ToInt32(item.Key[1].Y) + 6).ToString() + ")");
  721. // dataList.Add(strList);
  722. // }
  723. // bool isExist = false;//是否已存在进行替换
  724. // int modelIndex = -1;//要替换的下标
  725. // for (int j = 0; j < tempDataModel.Count; j++)
  726. // {
  727. // if (tempDataModel[j].tagName.Equals(tag))
  728. // {
  729. // isExist = true;
  730. // modelIndex = j;
  731. // break;
  732. // }
  733. // }
  734. // if (isExist && modelIndex > -1)
  735. // tempDataModel[modelIndex].dataList = dataList;
  736. // else
  737. // {
  738. // ExportProjectModel newModel = new ExportProjectModel();
  739. // newModel.tagName = tag;
  740. // newModel.picName = imgName;
  741. // newModel.dataList = dataList;
  742. // tempDataModel.Add(newModel);
  743. // }
  744. //}
  745. if (this.imageMat == null)
  746. {
  747. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  748. return;
  749. }
  750. if (this.dataGridView1.Rows.Count == 0)
  751. {
  752. MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text"));
  753. return;
  754. }
  755. //if (this.comboBox1.SelectedItem == null || PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem))
  756. //{
  757. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text") + "!");
  758. // return;
  759. //}
  760. double value4Total = this.dataGridView1.Rows.Count - 1;// 0;
  761. //foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  762. //{
  763. // value4Total += double.Parse(Row.Cells[3].Value.ToString());//交点个数
  764. //}
  765. if (value4Total < 1)
  766. {
  767. MessageBox.Show("请添加截距后保存结果");
  768. return;
  769. }
  770. string imgName = getCurrentWorkspace().GetFriendlyName();
  771. string tag = getCurrentWorkTag();
  772. DataTable dataTable = new DataTable();
  773. bool replace = false;
  774. int add = 0;
  775. foreach (ListViewItem item in this.listView2.Items)
  776. {
  777. if (item.Tag.Equals(tag))
  778. {
  779. add++;
  780. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  781. if (dr == DialogResult.OK)
  782. {
  783. replace = true;
  784. }
  785. break;
  786. }
  787. }
  788. if (replace || this.listView2.Items.Count == 0 || add == 0)
  789. {
  790. if (!replace)
  791. {
  792. ListViewItem listViewItem = new ListViewItem();
  793. listViewItem.SubItems[0].Text = imgName;
  794. listViewItem.Tag = "" + tag;
  795. if (this.listView2.Items.Count == 0)
  796. this.listView2.Items.Add(listViewItem);
  797. else
  798. this.listView2.Items.Insert(0, listViewItem);
  799. }
  800. this.dataGridView2.Rows.Clear();
  801. DataGridViewRow dgvr = new DataGridViewRow();
  802. dgvr.Tag = tag;
  803. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  804. {
  805. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  806. }
  807. dgvr.Cells[0].Value = imgName;
  808. //DataGridViewRow firRow = this.dataGridView1.Rows[0];
  809. //object value1 = firRow.Cells[0].Value;//网格
  810. //object value2 = firRow.Cells[1].Value;//网格长度
  811. //object value3 = firRow.Cells[2].Value;//网格条数
  812. //double value2Total = 0;
  813. //foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  814. //{
  815. // value2Total += (double.Parse(Row.Cells[1].Value.ToString()) * double.Parse(Row.Cells[2].Value.ToString()));//网格总长度
  816. //}
  817. ////double value4Total = 0;
  818. ////foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  819. ////{
  820. //// value4Total += double.Parse(Row.Cells[3].Value.ToString());//交点个数
  821. ////}
  822. ////if (value4Total == 0)//###20791
  823. ////{
  824. //// MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text"));
  825. //// return;
  826. ////}
  827. //////double value4Per = value4Total / this.dataGridView1.Rows.Count;
  828. dgvr.Cells[1].Value = this.labelNum.Text;// value1;
  829. dgvr.Cells[2].Value = this.labelMax.Text;// value2Total;
  830. dgvr.Cells[3].Value = this.labelMin.Text;// value4Total;
  831. //dgvr.Cells[4].Value = value4Per;//级别
  832. decimal M = 1;// this.getGainMultiple();
  833. DataGridViewRow lastRow = this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1];
  834. double small_l = double.Parse(lastRow.Cells[1].Value.ToString());// value2Total / (value4Total * (double)M);
  835. dgvr.Cells[4].Value = small_l;
  836. ////毫米转微米
  837. //decimal A = Convert.ToDecimal(small_l * 1);
  838. ////dgvr.Cells[4].Value = small_l;// Math.Round(A, Convert.ToInt32(this.numericUpDown1_0.Value));
  839. //double[] lengths = {453, 320 , 269, 226, 190, 177, 160, 135, 113, 106,
  840. // 95.0, 89.0, 80.0, 67.3, 62.0, 56.6, 53.2, 47.6, 44.3, 40.0, 35.4, 33.6, 31.0,
  841. // 28.3, 26.6 , 23.8, 22.2, 20.0, 17.7, 16.8, 14.1, 13.3, 11.9,
  842. // 10.0, 8.86, 8.41, 7.98, 7.07, 6.20, 5.95, 5.32, 5.00, 4.43, 4.20, 3.54, 2.97
  843. //, 2.66, 2.50, 2.22};
  844. //// 差值
  845. //decimal differenceNew;
  846. //decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 1.22, (double)A - 454)));
  847. //int first = 0;
  848. //if ((double)A < lengths[lengths.Length - 1])
  849. // first = lengths.Length - 1;
  850. //else
  851. // for (int firstI = 0; firstI < lengths.Length; firstI++)
  852. // {
  853. // double item = lengths[firstI];
  854. // differenceNew = Math.Abs(A - Convert.ToDecimal(item));
  855. // if (differenceNew < differenceOld)
  856. // {
  857. // differenceOld = Math.Abs(A - Convert.ToDecimal(item));
  858. // first = firstI;
  859. // }
  860. // }
  861. //string[] valueG = {"00A", "0" , "0.5", "1.0", "1.5", "1.5"/**/, "2.0", "2.5", "3.0", "3.0",
  862. // "3.5", "3.5", "4.0", "4.5", "4.5", "5.0", "5.0", "5.5", "5.5", "6.0", "6.0", "6.5", "6.5",
  863. // "7.0", "7.0" , "7.5", "7.5", "8.0", "8.0", "8.5", "9.0", "9.0", "9.5",
  864. // "10.0", "10.0", "10.5", "10.5", "11.0", "11.0", "11.5", "11.5", "12.0", "12.0", "12.5", "13.0", "13.5"
  865. //, "13.5", "14.0", "14.0"};
  866. dgvr.Cells[5].Value = -6.643856 * Math.Log10(small_l * 0.001) - 3.288;// valueG[first];
  867. this.dataGridView2.Rows.Add(dgvr);
  868. dataTable.TableName = tag;
  869. foreach (System.Data.DataTable dataTable1 in dataTables)
  870. {
  871. if (dataTable1.TableName.Equals(dataTable.TableName))
  872. {
  873. dataTables.Remove(dataTable1);
  874. break;
  875. }
  876. }
  877. for (int i = 0; i < this.dataGridView2.Columns.Count; i++)
  878. {
  879. dataTable.Columns.Add("" + i);
  880. }
  881. DataRow dataRow = dataTable.NewRow();
  882. dataRow["0"] = imgName;
  883. dataRow["1"] = dgvr.Cells[1].Value;// "网格1";
  884. dataRow["2"] = dgvr.Cells[2].Value;
  885. dataRow["3"] = dgvr.Cells[3].Value;
  886. dataRow["4"] = dgvr.Cells[4].Value;
  887. dataRow["5"] = dgvr.Cells[5].Value;
  888. //dataRow["6"] = dgvr.Cells[6].Value;
  889. dataTable.Rows.Add(dataRow);
  890. this.dataTables.Add(dataTable);
  891. if (this.allShow)
  892. AllShow();
  893. this.RefreshDataGridView4();
  894. //保存处理后的图片
  895. double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.selectPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  896. List<Bitmap> tempBit = new List<Bitmap>();
  897. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.imageMat);// this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  898. originalBit.Tag = pantographRatio;
  899. tempBit.Add(originalBit);
  900. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  901. Graphics graphics = Graphics.FromImage(newBit);
  902. //if (true)
  903. //{ }//0914###18810
  904. if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
  905. {
  906. Mat targetMat = this.PhaseModel0Mat;
  907. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  908. }
  909. if (this.documentWorkspace.PhaseModels[1].choise && this.documentWorkspace.PhaseModels[1].mat != null)
  910. {
  911. Mat targetMat = this.documentWorkspace.PhaseModels[1].mat;
  912. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  913. }
  914. if (this.documentWorkspace.PhaseModels[2].choise && this.documentWorkspace.PhaseModels[2].mat != null)
  915. {
  916. Mat targetMat = this.documentWorkspace.PhaseModels[2].mat;
  917. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  918. }
  919. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  920. drawSubclass/*Draw*/(graphics);
  921. newBit.Tag = pantographRatio;
  922. tempBit.Add(newBit);
  923. if (bitDic.ContainsKey(tag))
  924. bitDic[tag] = tempBit;
  925. else
  926. bitDic.Add(tag, tempBit);
  927. ////保存处理后的图片
  928. //List<Bitmap> tempBit = new List<Bitmap>();
  929. ////Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  930. ////tempBit.Add(originalBit);
  931. ////Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  932. ////Graphics graphics = Graphics.FromImage(newBit);
  933. ////Draw(graphics);
  934. ////tempBit.Add(newBit);
  935. //foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitCeDingDic)
  936. //{
  937. // tempBit.Add(kv.Value[0]);
  938. // tempBit.Add(kv.Value[1]);
  939. //}
  940. //if (bitDic.ContainsKey(tag))
  941. // bitDic[tag] = tempBit;
  942. //else
  943. // bitDic.Add(tag, tempBit);
  944. //中间数据-拼接中间数据
  945. List<List<string>> dataList = new List<List<string>>();
  946. List<string> columnName = new List<string>();
  947. columnName.Add("编号"/*PdnResources.GetString("Menu.Tools.GridLine.Text")*/);
  948. columnName.Add("截距长度"/*PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Lengthofdetectionline.text")*/);
  949. //columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Nnlines.text"));
  950. //columnName.Add(PdnResources.GetString("Menu.Thenumberofsections.text"));
  951. dataList.Add(columnName);
  952. foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  953. {
  954. List<string> strList = new List<string>();
  955. strList.Add(Row.Cells[0].Value.ToString());
  956. strList.Add(Row.Cells[1].Value.ToString());
  957. //strList.Add(Row.Cells[2].Value.ToString());
  958. //strList.Add(Row.Cells[3].Value.ToString());
  959. dataList.Add(strList);
  960. }
  961. bool isExist = false;//是否已存在进行替换
  962. int modelIndex = -1;//要替换的下标
  963. for (int j = 0; j < tempDataModel.Count; j++)
  964. {
  965. if (tempDataModel[j].tagName.Equals(tag))
  966. {
  967. isExist = true;
  968. modelIndex = j;
  969. break;
  970. }
  971. }
  972. if (isExist && modelIndex > -1)
  973. tempDataModel[modelIndex].dataList = dataList;
  974. else
  975. {
  976. Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
  977. newModel.tagName = tag;
  978. newModel.picName = imgName;
  979. newModel.dataList = dataList;
  980. tempDataModel.Add(newModel);
  981. }
  982. }
  983. }
  984. /// <summary>
  985. /// 是否显示晶界
  986. /// </summary>
  987. /// <returns></returns>
  988. protected override Boolean ShowGrainBoundryChecked()
  989. {
  990. return checkBox3_0.Checked;
  991. }
  992. //是否绘制辅助线
  993. protected override bool showGridChecked()
  994. {
  995. return false;// checkBox4.Checked;
  996. }
  997. //是否绘制截点
  998. protected override bool drawGuidePoints()
  999. {
  1000. return false;// (matOrg != null && this.checkBox5_0.Checked);
  1001. }
  1002. //是否显示截点
  1003. protected override Boolean drawDisplaySections()//##1
  1004. {
  1005. return false;// this.checkBox5_0.Checked;
  1006. }
  1007. //辅助线类型
  1008. protected override string[] getTypeNames()
  1009. {
  1010. return new string[] {
  1011. PdnResources.GetString("Menu.Verticalauxiliaryline.text"),
  1012. PdnResources.GetString("Menu.Horizontalauxiliaryline.text"),
  1013. PdnResources.GetString("Menu.Singlecircleauxiliaryline.text"),
  1014. PdnResources.GetString("Menu.Three-circleauxiliaryline.text"),
  1015. PdnResources.GetString("Menu.Compositeauxiliaryline.text")};
  1016. }
  1017. protected override string getTemplateName()
  1018. {
  1019. return "Template.Manager.item3.GrainSizeCutOffManualMethod";// "Template.Manager.item3.GrainSizeCutOff6394Method";
  1020. }
  1021. protected override string getProjectEngineeringName()
  1022. {
  1023. return "Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text";
  1024. }
  1025. protected override string getModelName()
  1026. {
  1027. return "GrainSizeGuideStyleModel.xml";
  1028. }
  1029. protected override void SubclassInitialize()
  1030. {
  1031. InitializeComponent();
  1032. InitializeComponentText();
  1033. DetailListNotDoubleIndex.Add(0);
  1034. //DetailListNotDoubleIndex.Add(1);
  1035. IndexChangedFromIndex.Clear();
  1036. IndexChangedToIndex.Clear();
  1037. IndexChangedFromIndex.Add(1);
  1038. IndexChangedFromIndex.Add(2);
  1039. IndexChangedFromIndex.Add(3);
  1040. IndexChangedFromIndex.Add(4);
  1041. IndexChangedFromIndex.Add(5);
  1042. IndexChangedToIndex.Add(0, new int[] { 2, 0 });//平均
  1043. IndexChangedToIndex.Add(1, new int[] { 2/*1*/, 1 });//求和
  1044. IndexChangedToIndex.Add(2, new int[] { 2, 2 });//平均
  1045. IndexChangedToIndex.Add(3, new int[] { 2/*3*/, 3 });//级别
  1046. IndexChangedToIndex.Add(4, new int[] { 2, 4 });//平均
  1047. for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
  1048. {
  1049. this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  1050. }
  1051. //for (int i = 0; i < this.dataGridView2.Columns.Count; i++)
  1052. //{
  1053. // this.dataGridView2.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  1054. //}
  1055. //for (int i = 0; i < this.dataGridView4.Columns.Count; i++)
  1056. //{
  1057. // this.dataGridView4.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  1058. //}
  1059. }
  1060. #endregion
  1061. private void MethodCutOffDialog_Load(object sender, EventArgs e)
  1062. {
  1063. this.button_ApplyToAll.Visible = false;
  1064. this.button_SaveAll.Visible = false;
  1065. this.btn_Grainboundarytoreproduce.Location = new System.Drawing.Point(912, 20);
  1066. this.btn_saveresult.Location = new System.Drawing.Point(993, 20);
  1067. object ShowGrainBoundry;
  1068. if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))//显示晶界
  1069. this.checkBox3_0.Checked = (bool)ShowGrainBoundry;
  1070. //if (GetParamValue1(ParamKey_displaygrid, out ShowGrainBoundry))//显示网格
  1071. // this.checkBox4.Checked = (bool)ShowGrainBoundry;
  1072. //if (GetParamValue1(ParamKey_displaysections, out ShowGrainBoundry))//显示截点
  1073. // this.checkBox5_0.Checked = (bool)ShowGrainBoundry;
  1074. this.groupBox3.Visible = false;
  1075. this.ColumnTotal1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1076. this.ColumnTotal2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1077. this.ColumnTotal3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1078. this.ColumnTotal4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1079. this.ColumnTotal5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1080. this.ColumnTotal6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1081. this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1082. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1083. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1084. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1085. this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1086. this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  1087. this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  1088. this.ColumnTotal2,
  1089. this.ColumnTotal3,
  1090. this.ColumnTotal4,
  1091. this.ColumnTotal5,
  1092. this.ColumnTotal6});
  1093. //
  1094. // ColumnTotal1
  1095. //
  1096. this.ColumnTotal1.Name = "ColumnTotal1";
  1097. this.ColumnTotal1.ReadOnly = true;
  1098. //
  1099. // ColumnTotal2
  1100. //
  1101. this.ColumnTotal2.Name = "ColumnTotal2";
  1102. this.ColumnTotal2.ReadOnly = true;
  1103. //
  1104. // ColumnTotal3
  1105. //
  1106. this.ColumnTotal3.Name = "ColumnTotal3";
  1107. this.ColumnTotal3.ReadOnly = true;
  1108. //
  1109. // ColumnTotal4
  1110. //
  1111. this.ColumnTotal4.Name = "ColumnTotal4";
  1112. this.ColumnTotal4.ReadOnly = true;
  1113. //
  1114. // ColumnTotal5
  1115. //
  1116. this.ColumnTotal5.Name = "ColumnTotal5";
  1117. this.ColumnTotal5.ReadOnly = true;
  1118. //
  1119. // ColumnTotal6
  1120. //
  1121. this.ColumnTotal6.Name = "ColumnTotal6";
  1122. this.ColumnTotal6.ReadOnly = true;
  1123. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  1124. this.Column1,
  1125. this.Column2,
  1126. this.Column3,
  1127. this.Column4,
  1128. this.Column5,
  1129. this.Column6});
  1130. //
  1131. // Column1
  1132. //
  1133. this.Column1.Name = "Column1";
  1134. this.Column1.ReadOnly = true;
  1135. //
  1136. // Column2
  1137. //
  1138. this.Column2.Name = "Column2";
  1139. this.Column2.ReadOnly = true;
  1140. //
  1141. // Column3
  1142. //
  1143. this.Column3.Name = "Graisize";
  1144. this.Column3.ReadOnly = true;
  1145. //
  1146. // Column4
  1147. //
  1148. this.Column4.Name = "Grainnumber";
  1149. this.Column4.ReadOnly = true;
  1150. //
  1151. // Column5
  1152. //
  1153. this.Column5.Name = "Grainintercept";
  1154. this.Column5.ReadOnly = true;
  1155. //
  1156. // Column6
  1157. //
  1158. this.Column6.Name = "Graingrade";
  1159. this.Column6.ReadOnly = true;
  1160. this.dataGridViewTextBoxColumn9.HeaderText = "编号";// PdnResources.GetString("Menu.packet.text");
  1161. this.dataGridViewTextBoxColumn10.HeaderText = "截距长度";// PdnResources.GetString("Menu.Depthofnitridinglayer.text");
  1162. //this.button8.Text = PdnResources.GetString("Menu.1.5/2section.text");
  1163. //this.button6_0.Text = PdnResources.GetString("Menu.0.5sectionstyle.text");
  1164. this.button2.Text = "选择截距";
  1165. this.button10.Text = "删除截距";
  1166. this.button7_0.Text = "添加截距";
  1167. this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
  1168. //this.checkBox5_0.Text = PdnResources.GetString("Menu.displaysections.text");
  1169. //this.checkBox4.Text = PdnResources.GetString("Menu.displaygrid.text");
  1170. this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text");
  1171. this.ColumnTotal1.HeaderText = PdnResources.GetString("Menu.Intersectinggrainnumber.Text");
  1172. this.ColumnTotal2.HeaderText = "截距数量";//PdnResources.GetString("Menu.Numberofgrainsingrid.Text");
  1173. this.ColumnTotal3.HeaderText = "最大截距";// PdnResources.GetString("Menu.Totalmeshlength.Text") + "(μm)";
  1174. this.ColumnTotal4.HeaderText = "最小截距";// PdnResources.GetString("Menu.umberofpoints.Text");
  1175. this.ColumnTotal5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)";
  1176. this.ColumnTotal6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
  1177. this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  1178. this.Column2.HeaderText = "截距数量";// PdnResources.GetString("Menu.Tools.GridLine.Text");
  1179. this.Column3.HeaderText = "最大截距";// PdnResources.GetString("Menu.Gridlength.text") + "(μm)";
  1180. this.Column4.HeaderText = "最小截距";// PdnResources.GetString("Menu.Thenumberofsections.text");
  1181. this.Column5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)";// "平均截距";//
  1182. this.Column6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");// "";//
  1183. this.Text = "手动测量";// "GBT6394_2017(" + PdnResources.GetString("Menu.sectionmethod.text") + ")";
  1184. //this.groupBox_img.Size = new System.Drawing.Size(158, 722);
  1185. //this.groupBox_review.Size = new System.Drawing.Size(575, 722);
  1186. //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 800);
  1187. //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 800);
  1188. //this.groupBox_report.Location = new System.Drawing.Point(974, 800);
  1189. }
  1190. ///// <summary>
  1191. ///// 是否显示网格
  1192. ///// </summary>
  1193. ///// <param name="sender"></param>
  1194. ///// <param name="e"></param>
  1195. //private void checkBox4_CheckedChanged(object sender, EventArgs e)
  1196. //{
  1197. // this.documentWorkspace.Refresh();
  1198. //}
  1199. ///// <summary>
  1200. ///// 是否显示截点
  1201. ///// </summary>
  1202. ///// <param name="sender"></param>
  1203. ///// <param name="e"></param>
  1204. //private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
  1205. //{
  1206. // if (!this.checkBox4.Checked)
  1207. // MessageBox.Show(PdnResources.GetString("Menu.Nogrid.text")+"!");
  1208. // this.documentWorkspace.Refresh();
  1209. //}
  1210. /// <summary>
  1211. /// 是否显示晶界
  1212. /// </summary>
  1213. /// <param name="sender"></param>
  1214. /// <param name="e"></param>
  1215. private void checkBox3_0_CheckedChanged(object sender, EventArgs e)
  1216. {
  1217. if (this.documentWorkspace.PhaseModels.Count > 0)
  1218. {
  1219. if (!bcOriginChecked() && getGrainBoundryChecked() && checkBox3_0.Checked)
  1220. {
  1221. this.documentWorkspace.PhaseModels[1].choise = true;
  1222. }
  1223. else
  1224. {
  1225. this.documentWorkspace.PhaseModels[1].choise = false;
  1226. }
  1227. }
  1228. this.documentWorkspace.Refresh();
  1229. }
  1230. protected override void refreshWhileImgChanged()
  1231. {
  1232. object ShowGrainBoundry;
  1233. if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))//显示晶界
  1234. this.checkBox3_0.Checked = (bool)ShowGrainBoundry;
  1235. //base.refreshWhileImgChanged();
  1236. if (getCurrentWorkspace() != null/* && this.listView1.FocusedItem.Selected*/)
  1237. this.unitLength = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  1238. rectangleFs.Clear();
  1239. ////二值化集成4
  1240. //binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  1241. rectangleFsArr = new RectangleF[] { };
  1242. rectangleFs.Clear();
  1243. pointFsLine = new PointF[] { };
  1244. this.dataGridView1.Rows.Clear();
  1245. selectLineIndex = -1;
  1246. rectangleFsLines.Clear();
  1247. }
  1248. protected override void onMouseUp(object sender, MouseEventArgs e)
  1249. {
  1250. //base.onMouseUp(sender, e);
  1251. canAdd = false;
  1252. canMove = false;
  1253. movePointIndex = -1;
  1254. RefrashData();
  1255. if (mouseStatus == 2)
  1256. SelectDataRow();
  1257. }
  1258. /// <summary>
  1259. /// 相颜色点击事件
  1260. /// </summary>
  1261. /// <param name="sender"></param>
  1262. /// <param name="e"></param>
  1263. private void panelC_Click(object sender, EventArgs e)
  1264. {
  1265. this.panelC = (Panel)sender;
  1266. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
  1267. this.colorsFormGrid.ShowDialog();
  1268. }
  1269. /// <summary>
  1270. /// PanelC的调色板颜色改变
  1271. /// </summary>
  1272. /// <param name="sender"></param>
  1273. /// <param name="e"></param>
  1274. private void gridColorChanged(object sender, EventArgs e)
  1275. {
  1276. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1277. //更改背景色,触发事件
  1278. this.panelC.BackColor = color;
  1279. this.documentWorkspace.Refresh();
  1280. //关闭色板
  1281. this.colorsFormGrid.Close();
  1282. }
  1283. private void SelectDataRow()
  1284. {
  1285. if (this.dataGridView1.Rows.Count > selectLineIndex && selectLineIndex >= 0)
  1286. this.dataGridView1.Rows[selectLineIndex].Selected = true;
  1287. if (dataGridView1.SelectedRows.Count > 0)
  1288. selectLineIndex = dataGridView1.SelectedRows[0].Index;
  1289. }
  1290. /// <summary>
  1291. /// 刷新数据展示
  1292. /// </summary>
  1293. private void RefrashData()
  1294. {
  1295. canChange = true;
  1296. if (this.rectangleFs.Count == 0)
  1297. return;
  1298. this.dataGridView1.Rows.Clear();
  1299. int count = 0;
  1300. double lengthMax = 0;
  1301. double lengthMin = 0;
  1302. if (rectangleFs.Count > 0)
  1303. {
  1304. foreach (var item in rectangleFs)
  1305. {
  1306. lengthMin = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength;
  1307. break;
  1308. }
  1309. }
  1310. foreach (var item in rectangleFs)
  1311. {
  1312. count++;
  1313. DataGridViewRow dgvr = new DataGridViewRow();
  1314. foreach (DataGridViewColumn Column in this.dataGridView1.Columns)
  1315. {
  1316. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1317. }
  1318. double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength;
  1319. dgvr.Cells[0].Value = ""/*"L"*/ + count;
  1320. if (length < lengthMin)
  1321. lengthMin = length;
  1322. if (length > lengthMax)
  1323. lengthMax = length;
  1324. dgvr.Cells[1].Value = this.DecnumString(length.ToString());// Math.Round(length, Convert.ToInt32(this.numericUpDown1.Value));
  1325. this.dataGridView1.Rows.Add(dgvr);
  1326. }
  1327. labelMax.Text = this.DecnumString(lengthMax.ToString());
  1328. labelMin.Text = this.DecnumString(lengthMin.ToString());
  1329. labelNum.Text = rectangleFs.Count.ToString();
  1330. dataTable = new DataTable();
  1331. foreach (DataGridViewColumn Column in this.dataGridView1.Columns)
  1332. {
  1333. dataTable.Columns.Add(Column.HeaderText);
  1334. }
  1335. count = 0;
  1336. foreach (var item in rectangleFs)
  1337. {
  1338. count++;
  1339. DataRow dataRow = dataTable.NewRow();
  1340. double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength;
  1341. dataRow[0] = ""/*"L"*/ + count;
  1342. dataRow[1] = length;
  1343. this.dataTable.Rows.Add(dataRow);
  1344. }
  1345. double allLength = 0;
  1346. for (int i = 0; i < dataTable.Rows.Count; i++)
  1347. {
  1348. allLength += Convert.ToDouble(dataTable.Rows[i][1]);
  1349. }
  1350. DataGridViewRow dgvr1 = new DataGridViewRow();
  1351. foreach (DataGridViewColumn Column in this.dataGridView1.Columns)
  1352. {
  1353. dgvr1.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1354. }
  1355. dgvr1.Cells[0].Value = PdnResources.GetString("Menu.Image.Average.Text");
  1356. dgvr1.Cells[1].Value = this.DecnumString(allLength / this.dataTable.Rows.Count + "");// Math.Round(allLength / this.dataTable.Rows.Count, Convert.ToInt32(this.numericUpDown1.Value));
  1357. this.dataGridView1.Rows.Add(dgvr1);
  1358. canChange = false;
  1359. if (this.dataGridView1.DisplayedRowCount(false) == this.dataGridView1.RowCount)//#####################
  1360. {
  1361. //没有
  1362. this.dataGridViewTextBoxColumn10.Width = 242;
  1363. }
  1364. else
  1365. {
  1366. //有
  1367. this.dataGridViewTextBoxColumn10.Width = 227;
  1368. }
  1369. }
  1370. PointF point1;
  1371. protected override void onMouseMove(object sender, MouseEventArgs e)
  1372. {
  1373. base.onMouseMove(sender, e);
  1374. // 换算后的点
  1375. this.point1 = documentWorkspace.GetScalePoint(e.Location);
  1376. // 全方位线
  1377. if (lineStyle == 0)
  1378. {
  1379. if (mouseStatus == 0 && canAdd)
  1380. {
  1381. rectangleFsArr[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12);
  1382. PointF startPoint = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y + 6);
  1383. PointF endPoint = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y + 6);
  1384. //计算需要旋转的角度
  1385. double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
  1386. double sAngle1 = 270 + angle;
  1387. double eAngle1 = 90 + angle;
  1388. System.Drawing.Point point3 = new System.Drawing.Point();
  1389. System.Drawing.Point point4 = new System.Drawing.Point();
  1390. System.Drawing.Point point5 = new System.Drawing.Point();
  1391. System.Drawing.Point point6 = new System.Drawing.Point();
  1392. if (sAngle1 is double.NaN && eAngle1 is double.NaN)
  1393. {
  1394. }
  1395. else
  1396. {
  1397. point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1);
  1398. point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1);
  1399. point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1);
  1400. point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1);
  1401. }
  1402. pointFsLine[0] = point3;
  1403. pointFsLine[1] = point4;
  1404. pointFsLine[2] = point6;
  1405. pointFsLine[3] = point5;
  1406. }
  1407. }
  1408. // 水平线
  1409. else if (lineStyle == 1)
  1410. {
  1411. if (mouseStatus == 0 && canAdd)
  1412. {
  1413. rectangleFsArr[1] = new RectangleF(point1.X - 6, rectangleFsArr[0].Y, 12, 12);
  1414. pointFsLine[0] = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9);
  1415. pointFsLine[1] = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3);
  1416. pointFsLine[3] = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9);
  1417. pointFsLine[2] = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3);
  1418. }
  1419. }
  1420. // 垂直线
  1421. else if (lineStyle == 2)
  1422. {
  1423. if (mouseStatus == 0 && canAdd)
  1424. {
  1425. rectangleFsArr[1] = new RectangleF(rectangleFsArr[0].X, point1.Y - 6, 12, 12);
  1426. pointFsLine[0] = new PointF(rectangleFsArr[0].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, rectangleFsArr[0].Y + 6);
  1427. pointFsLine[1] = new PointF(rectangleFsArr[0].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, rectangleFsArr[0].Y + 6);
  1428. pointFsLine[3] = new PointF(rectangleFsArr[1].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, rectangleFsArr[1].Y + 6);
  1429. pointFsLine[2] = new PointF(rectangleFsArr[1].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, rectangleFsArr[1].Y + 6);
  1430. }
  1431. }
  1432. if (this.mouseStatus == 2 && canMove)
  1433. {
  1434. if (this.selectLineIndex != -1)
  1435. {
  1436. int indexRectangleFs = -1;
  1437. foreach (var item in rectangleFs)
  1438. {
  1439. indexRectangleFs++;
  1440. if (selectLineIndex == indexRectangleFs)
  1441. {
  1442. // 全方位线
  1443. if (item.Value == 0)
  1444. {
  1445. // 线条起始点移动
  1446. if (movePointIndex == 0)
  1447. {
  1448. item.Key[0] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12);
  1449. }
  1450. else if (movePointIndex == 1)
  1451. {
  1452. item.Key[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12);
  1453. }
  1454. else if (movePointIndex == 2)
  1455. {
  1456. item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1457. item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1458. movePointStart = point1;
  1459. }
  1460. PointF startPoint = new PointF(item.Key[0].X + 6, item.Key[0].Y + 6);
  1461. PointF endPoint = new PointF(item.Key[1].X + 6, item.Key[1].Y + 6);
  1462. //计算需要旋转的角度
  1463. double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
  1464. double sAngle1 = 270 + angle;
  1465. double eAngle1 = 90 + angle;
  1466. System.Drawing.Point point3 = new System.Drawing.Point();
  1467. System.Drawing.Point point4 = new System.Drawing.Point();
  1468. System.Drawing.Point point5 = new System.Drawing.Point();
  1469. System.Drawing.Point point6 = new System.Drawing.Point();
  1470. if (sAngle1 is double.NaN && eAngle1 is double.NaN)
  1471. {
  1472. }
  1473. else
  1474. {
  1475. point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1);
  1476. point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1);
  1477. point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1);
  1478. point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1);
  1479. }
  1480. int indexRectangleFsLines = -1;
  1481. foreach (var item1 in rectangleFsLines)
  1482. {
  1483. indexRectangleFsLines++;
  1484. if (indexRectangleFsLines == indexRectangleFs)
  1485. {
  1486. item1.Key[0] = point3;
  1487. item1.Key[1] = point4;
  1488. item1.Key[2] = point6;
  1489. item1.Key[3] = point5;
  1490. //item1.Key[0] = new PointF(point3.X + 6, point3.Y + 9);
  1491. //item1.Key[1] = new PointF(point4.X + 6, point3.Y - 9);
  1492. //item1.Key[2] = new PointF(point6.X + 6, point6.Y + 9);
  1493. //item1.Key[3] = new PointF(point5.X + 6, point3.Y - 9);
  1494. }
  1495. }
  1496. }
  1497. // 水平线
  1498. else if (item.Value == 1)
  1499. {
  1500. // 线条起始点移动
  1501. if (movePointIndex == 0)
  1502. {
  1503. item.Key[0] = new RectangleF(point1.X - 6, item.Key[1].Y, 12, 12);
  1504. }
  1505. else if (movePointIndex == 1)
  1506. {
  1507. item.Key[1] = new RectangleF(point1.X - 6, item.Key[0].Y, 12, 12);
  1508. }
  1509. else if (movePointIndex == 2)
  1510. {
  1511. item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1512. item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1513. movePointStart = point1;
  1514. }
  1515. int selectIndex = -1;
  1516. foreach (var item1 in rectangleFsLines)
  1517. {
  1518. selectIndex++;
  1519. if (selectIndex == selectLineIndex)
  1520. {
  1521. item1.Key[0] = new PointF(item.Key[0].X + 6, item.Key[0].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9);
  1522. item1.Key[1] = new PointF(item.Key[0].X + 6, item.Key[0].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3);
  1523. item1.Key[3] = new PointF(item.Key[1].X + 6, item.Key[1].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9);
  1524. item1.Key[2] = new PointF(item.Key[1].X + 6, item.Key[1].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3);
  1525. }
  1526. }
  1527. }
  1528. // 垂直线
  1529. else if (item.Value == 2)
  1530. {
  1531. // 线条起始点移动
  1532. if (movePointIndex == 0)
  1533. {
  1534. item.Key[0] = new RectangleF(item.Key[1].X, point1.Y - 6, 12, 12);
  1535. }
  1536. else if (movePointIndex == 1)
  1537. {
  1538. item.Key[1] = new RectangleF(item.Key[0].X, point1.Y - 6, 12, 12);
  1539. }
  1540. else if (movePointIndex == 2)
  1541. {
  1542. item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1543. item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y);
  1544. movePointStart = point1;
  1545. }
  1546. int selectIndex = -1;
  1547. foreach (var item1 in rectangleFsLines)
  1548. {
  1549. selectIndex++;
  1550. if (selectIndex == selectLineIndex)
  1551. {
  1552. item1.Key[0] = new PointF(item.Key[0].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, item.Key[0].Y + 6);
  1553. item1.Key[1] = new PointF(item.Key[0].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, item.Key[0].Y + 6);
  1554. item1.Key[3] = new PointF(item.Key[1].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, item.Key[1].Y + 6);
  1555. item1.Key[2] = new PointF(item.Key[1].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, item.Key[1].Y + 6);
  1556. }
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. this.documentWorkspace.Refresh();
  1564. }
  1565. protected override void drawSubclass(Graphics graphics, string imagesKey = null, int analysisPicture = -1)
  1566. {
  1567. //base.drawSubclass(graphics);
  1568. Pen linePen = new Pen(this.panel2.BackColor, Convert.ToInt32(this.numericUpDown3.Value));
  1569. Pen linePen1 = new Pen(this.panel1.BackColor, Convert.ToInt32(this.numericUpDown3.Value));
  1570. //linePen.CustomStartCap = lineCap;
  1571. //linePen.CustomEndCap = lineCap;
  1572. int drawIndex = -1;
  1573. foreach (var item in rectangleFs)
  1574. {
  1575. drawIndex++;
  1576. if (selectLineIndex != -1 && drawIndex == this.selectLineIndex)
  1577. {
  1578. linePen.DashStyle = DashStyle.DashDot;
  1579. }
  1580. else
  1581. linePen.DashStyle = DashStyle.Solid;
  1582. graphics.DrawLine(linePen, new PointF(item.Key[0].X + 6, item.Key[0].Y + 6), new PointF(item.Key[1].X + 6, item.Key[1].Y + 6));
  1583. PointF startPoint = new PointF(item.Key[0].X + 6, item.Key[0].Y + 6);
  1584. PointF endPoint = new PointF(item.Key[1].X + 6, item.Key[1].Y + 6);
  1585. double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(startPoint.X) + 6, Convert.ToInt32(startPoint.Y) + 6), new System.Drawing.Point(Convert.ToInt32(endPoint.X) + 6, Convert.ToInt32(endPoint.Y) + 6), getNumericUpDown1Value()) * unitLength;
  1586. //计算需要旋转的角度
  1587. double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
  1588. if (item.Value == 0)
  1589. {
  1590. //
  1591. // 绘制两侧竖线
  1592. //
  1593. double sAngle1 = 270 + angle;
  1594. double eAngle1 = 90 + angle;
  1595. System.Drawing.Point point3 = new System.Drawing.Point();
  1596. System.Drawing.Point point4 = new System.Drawing.Point();
  1597. System.Drawing.Point point5 = new System.Drawing.Point();
  1598. System.Drawing.Point point6 = new System.Drawing.Point();
  1599. if (sAngle1 is double.NaN && eAngle1 is double.NaN)
  1600. {
  1601. }
  1602. else
  1603. {
  1604. point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1);
  1605. point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1);
  1606. point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1);
  1607. point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1);
  1608. }
  1609. graphics.DrawLine(linePen1, point3, point4);
  1610. graphics.DrawLine(linePen1, point5, point6);
  1611. SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)));
  1612. PointF cen1 = new PointF((point3.X + point5.X) / 2, (point3.Y + point5.Y) / 2);
  1613. PointF cen2 = new PointF((point4.X + point6.X) / 2, (point4.Y + point6.Y) / 2);
  1614. PointF drawP1 = new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2);
  1615. PointF drawP2 = new PointF(cen2.X - sizeF.Width / 2, cen2.Y - sizeF.Height / 2);
  1616. PointF drawP3;
  1617. if (angle < 90)
  1618. drawP3 = drawP1;
  1619. else
  1620. drawP3 = drawP2;
  1621. Matrix mtxSave = graphics.Transform;
  1622. Matrix matrix = graphics.Transform;
  1623. // 画布旋转
  1624. if (angle < 90)
  1625. {
  1626. matrix.RotateAt((float)angle, new PointF(cen1.X, cen1.Y));
  1627. graphics.Transform = matrix;
  1628. }
  1629. else
  1630. {
  1631. angle = BasicCalculationHelper.Angle(endPoint, startPoint, new PointF(endPoint.X, startPoint.Y));
  1632. matrix.RotateAt((float)angle, new PointF(cen2.X, cen2.Y));
  1633. graphics.Transform = matrix;
  1634. }
  1635. graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(this.panel1.BackColor/*Color.Black*/), drawP3);
  1636. //还原为原始旋转矩阵
  1637. graphics.Transform = mtxSave;
  1638. matrix.Dispose();
  1639. }
  1640. else if (item.Value == 1)
  1641. {
  1642. graphics.DrawLine(linePen1, new PointF(startPoint.X, startPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/)
  1643. , new PointF(startPoint.X, startPoint.Y/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/));
  1644. graphics.DrawLine(linePen1, new PointF(endPoint.X, endPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/)
  1645. , new PointF(endPoint.X, endPoint.Y/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/));
  1646. SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)));
  1647. PointF cen1 = new PointF((startPoint.X + endPoint.X) / 2, startPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/);
  1648. graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(Color.Black), new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2));
  1649. }
  1650. else if (item.Value == 2)
  1651. {
  1652. graphics.DrawLine(linePen1, new PointF(startPoint.X/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/, startPoint.Y)
  1653. , new PointF(startPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, startPoint.Y));
  1654. graphics.DrawLine(linePen1, new PointF(endPoint.X/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/, endPoint.Y)
  1655. , new PointF(endPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, endPoint.Y));
  1656. SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)));
  1657. PointF cen1 = new PointF(startPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, (startPoint.Y + endPoint.Y) / 2);
  1658. Matrix mtxSave = graphics.Transform;
  1659. Matrix matrix = graphics.Transform;
  1660. matrix.RotateAt((float)90, new PointF(cen1.X, cen1.Y));
  1661. graphics.Transform = matrix;
  1662. graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(Color.Black), new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2));
  1663. //还原为原始旋转矩阵
  1664. graphics.Transform = mtxSave;
  1665. matrix.Dispose();
  1666. }
  1667. if (selectLineIndex != -1 && drawIndex == this.selectLineIndex)
  1668. {
  1669. graphics.FillRectangle(new SolidBrush(Color.Black), item.Key[0]);
  1670. graphics.FillRectangle(new SolidBrush(Color.Black), item.Key[1]);
  1671. }
  1672. }
  1673. System.Drawing.Drawing2D.GraphicsPath myGraphicsPath;
  1674. Region myRegion;
  1675. int selectIndex = -1;
  1676. foreach (var item in rectangleFsLines)
  1677. {
  1678. selectIndex++;
  1679. myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
  1680. myRegion = new Region();
  1681. myGraphicsPath.Reset();
  1682. myGraphicsPath.AddPolygon(new PointF[] { item.Key[0], item.Key[1], item.Key[2], item.Key[3] });
  1683. myRegion.MakeEmpty();
  1684. myRegion.Union(myGraphicsPath);
  1685. //graphics.FillRegion(new SolidBrush(Color.Black), myRegion);
  1686. }
  1687. linePen.Dispose();
  1688. linePen1.Dispose();
  1689. }
  1690. /// <summary>
  1691. /// 鼠标按下
  1692. /// </summary>
  1693. /// <param name="drawArea"></param>
  1694. /// <param name="e"></param>
  1695. protected override void OnMouseDown(object sender, MouseEventArgs e)
  1696. {
  1697. if (this.documentWorkspace.CompositionSurface == null)
  1698. return;
  1699. //// 换算后的点
  1700. //PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1701. //if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  1702. // && point1.X >= 0
  1703. // && point1.Y >= 0
  1704. // && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  1705. //{
  1706. // RectangleF rectangleF;
  1707. // // 复合辅助线
  1708. // int add = GSSClass.GuideClass.getAddOfRStyle(point1, this.comboBox1.SelectedItem, out rectangleF);
  1709. // if (add == 0 && GSSClass.styleClass.PointKb > 0)
  1710. // rectangleF = GSSClass.GuideClass.RectangleFLine;
  1711. // //手动添加截点
  1712. // if (this.documentWorkspace.ActiveTool == Annotation.Enum.DrawToolType.InclusionNoEffect && GSSClass.styleClass.OnMouseDownNext(point1, sender, e))
  1713. // GSSClass.styleClass.OnMouseDownFirst(point1, rectangleF, GSSClass.linePointList, e);
  1714. //}
  1715. //if (GSSClass.styleClass.PointKb == 0)
  1716. //{
  1717. // //辅助线缩放
  1718. // GSSClass.GuideClass.OnMouseDown(point1, sender, e);
  1719. // //辅助线移动
  1720. // base.OnMouseDown(sender, e);//##
  1721. //}
  1722. if (e.Button == MouseButtons.Left)
  1723. {
  1724. // 换算后的点
  1725. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1726. selectLineIndex = -1;
  1727. if (mouseStatus == 0)
  1728. {
  1729. canAdd = true;
  1730. rectangleFsArr = new RectangleF[2];
  1731. pointFsLine = new PointF[4];
  1732. rectangleFsArr[0] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12);
  1733. rectangleFsArr[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12);
  1734. Dictionary<RectangleF[], int> rectangleFs1 = new Dictionary<RectangleF[], int>();
  1735. foreach (var item in rectangleFs)
  1736. {
  1737. rectangleFs1.Add(item.Key, item.Value);
  1738. }
  1739. rectangleFs = new Dictionary<RectangleF[], int>();
  1740. rectangleFs = rectangleFs1;
  1741. if (lineStyle == 0)
  1742. rectangleFs.Add(rectangleFsArr, 0);
  1743. else if (lineStyle == 1)
  1744. rectangleFs.Add(rectangleFsArr, 1);
  1745. else if (lineStyle == 2)
  1746. rectangleFs.Add(rectangleFsArr, 2);
  1747. if (lineStyle == 0)
  1748. rectangleFsLines.Add(pointFsLine, 0);
  1749. else if (lineStyle == 1)
  1750. rectangleFsLines.Add(pointFsLine, 1);
  1751. else if (lineStyle == 2)
  1752. rectangleFsLines.Add(pointFsLine, 2);
  1753. }
  1754. if (mouseStatus == 2)
  1755. {
  1756. System.Drawing.Drawing2D.GraphicsPath myGraphicsPath;
  1757. Region myRegion;
  1758. int selectIndex = -1;
  1759. foreach (var item in rectangleFsLines)
  1760. {
  1761. selectIndex++;
  1762. myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
  1763. myRegion = new Region();
  1764. myGraphicsPath.Reset();
  1765. myGraphicsPath.AddPolygon(new PointF[] { item.Key[0], item.Key[1], item.Key[2], item.Key[3] });
  1766. myRegion.MakeEmpty();
  1767. myRegion.Union(myGraphicsPath);
  1768. //返回判断点是否在多边形里
  1769. //RectangleF rectangleF = myRegion.GetBounds(rag)
  1770. double L = BasicCalculationHelper.GetDisFromPointToLine(item.Key[0], item.Key[2], point1);
  1771. bool myPoint = L < 10 /*myRegion.IsVisible(point1)*/;
  1772. if (myPoint)
  1773. {
  1774. selectLineIndex = selectIndex;
  1775. break;
  1776. }
  1777. }
  1778. if (selectLineIndex == -1)
  1779. {
  1780. selectIndex = -1;
  1781. foreach (var item in rectangleFs)
  1782. {
  1783. selectIndex++;
  1784. if (item.Key[0].Contains(point1))
  1785. {
  1786. selectLineIndex = selectIndex;
  1787. break;
  1788. }
  1789. else if (item.Key[1].Contains(point1))
  1790. {
  1791. selectLineIndex = selectIndex;
  1792. break;
  1793. }
  1794. }
  1795. }
  1796. //else
  1797. // {
  1798. // if(this.dataGridView1.Rows.Count > selectLineIndex)
  1799. // this.dataGridView1.Rows[selectLineIndex].Selected = true;
  1800. //}
  1801. }
  1802. if (mouseStatus == 2)
  1803. {
  1804. int indexRectangleFs = -1;
  1805. foreach (var item in rectangleFs)
  1806. {
  1807. indexRectangleFs++;
  1808. System.Drawing.Drawing2D.GraphicsPath myGraphicsPath;
  1809. Region myRegion;
  1810. int indexRectangleFsLines = -1;
  1811. bool myPoint = false;
  1812. foreach (var item1 in rectangleFsLines)
  1813. {
  1814. indexRectangleFsLines++;
  1815. if (indexRectangleFs == indexRectangleFsLines)
  1816. {
  1817. myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
  1818. myRegion = new Region();
  1819. myGraphicsPath.Reset();
  1820. myGraphicsPath.AddPolygon(new PointF[] { item1.Key[0], item1.Key[1], item1.Key[2], item1.Key[3] });
  1821. myRegion.MakeEmpty();
  1822. myRegion.Union(myGraphicsPath);
  1823. //返回判断点是否在多边形里
  1824. //myPoint = myRegion.IsVisible(point1);
  1825. double L = BasicCalculationHelper.GetDisFromPointToLine(item1.Key[0], item1.Key[2], point1);
  1826. myPoint = L < 10 /*myRegion.IsVisible(point1)*/;
  1827. if (myPoint)
  1828. {
  1829. break;
  1830. }
  1831. }
  1832. }
  1833. if (item.Key[0].Contains(point1))
  1834. {
  1835. movePointStart = point1;
  1836. movePointIndex = 0;
  1837. canMove = true;
  1838. }
  1839. else if (item.Key[1].Contains(point1))
  1840. {
  1841. movePointStart = point1;
  1842. movePointIndex = 1;
  1843. canMove = true;
  1844. }
  1845. else if (myPoint)
  1846. {
  1847. movePointStart = point1;
  1848. movePointIndex = 2;
  1849. canMove = true;
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. private void AllShow()
  1856. {
  1857. this.dataGridView2.Rows.Clear();
  1858. for (int i = 0; i < this.dataTables.Count; i++)
  1859. {
  1860. DataGridViewRow dgvr = new DataGridViewRow();
  1861. dgvr.Tag = this.dataTables[i].TableName;
  1862. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  1863. {
  1864. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1865. }
  1866. for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
  1867. {
  1868. //if (c > 2 && c < 4)
  1869. // dgvr.Cells[c].Value = Math.Round((double)Convert.ToDecimal(this.dataTables[i].Rows[0][c]), Convert.ToInt32(this.numericUpDown1_0.Value)).ToString();
  1870. //else
  1871. dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
  1872. }
  1873. this.dataGridView2.Rows.Add(dgvr);
  1874. }
  1875. }
  1876. private void button6_0_Click(object sender, EventArgs e)
  1877. {
  1878. if (this.imageMat != null)
  1879. {
  1880. //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!");
  1881. GSSClass.styleClass.PointKb = 1;
  1882. }
  1883. else
  1884. {
  1885. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  1886. }
  1887. }
  1888. private void button7_0_LostFocus(object sender, EventArgs e)
  1889. {
  1890. this.mouseStatus = -1;
  1891. }
  1892. /// <summary>
  1893. /// 添加测量线
  1894. /// </summary>
  1895. /// <param name="sender"></param>
  1896. /// <param name="e"></param>
  1897. private void button7_0_Click(object sender, EventArgs e)
  1898. {
  1899. if (this.imageMat != null)
  1900. {
  1901. this.mouseStatus = 0;
  1902. this.selectLineIndex = -1;
  1903. }
  1904. else
  1905. {
  1906. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  1907. }
  1908. }
  1909. private void button8_Click(object sender, EventArgs e)
  1910. {
  1911. if (this.imageMat != null)
  1912. {
  1913. //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!");
  1914. GSSClass.styleClass.PointKb = 3;
  1915. }
  1916. else
  1917. {
  1918. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
  1919. }
  1920. }
  1921. /// <summary>
  1922. /// 选择截距
  1923. /// </summary>
  1924. /// <param name="sender"></param>
  1925. /// <param name="e"></param>
  1926. private void button2_Click(object sender, EventArgs e)
  1927. {
  1928. this.mouseStatus = 2;
  1929. this.selectLineIndex = -1;
  1930. }
  1931. /// <summary>
  1932. /// 删除截距
  1933. /// </summary>
  1934. /// <param name="sender"></param>
  1935. /// <param name="e"></param>
  1936. private void button10_Click(object sender, EventArgs e)
  1937. {
  1938. this.mouseStatus = 1;
  1939. if (this.mouseStatus == 1)
  1940. {
  1941. if (selectLineIndex == -1)
  1942. {
  1943. MessageBox.Show("请先选择要删除的测量线!");
  1944. return;
  1945. }
  1946. int deleteIndex = -1;
  1947. foreach (var item in rectangleFs)
  1948. {
  1949. deleteIndex++;
  1950. if (deleteIndex == selectLineIndex)
  1951. {
  1952. rectangleFs.Remove(item.Key);
  1953. break;
  1954. }
  1955. }
  1956. deleteIndex = -1;
  1957. foreach (var item in rectangleFsLines)
  1958. {
  1959. deleteIndex++;
  1960. if (deleteIndex == selectLineIndex)
  1961. {
  1962. rectangleFsLines.Remove(item.Key);
  1963. break;
  1964. }
  1965. }
  1966. selectLineIndex = 0;
  1967. if (selectLineIndex < -1)
  1968. selectLineIndex = -1;
  1969. if (rectangleFs.Count == 0)
  1970. this.dataGridView1.Rows.Clear();
  1971. if (mouseStatus == 2)
  1972. SelectDataRow();
  1973. RefrashData();
  1974. this.documentWorkspace.Refresh();
  1975. }
  1976. }
  1977. private void dataGridView1_SelectionChanged(object sender, EventArgs e)
  1978. {
  1979. //canChange = true;
  1980. if (!canChange)
  1981. {
  1982. SelectDataRow();
  1983. this.documentWorkspace.Refresh();
  1984. }
  1985. }
  1986. /// <summary>
  1987. /// 获取参数
  1988. /// </summary>
  1989. protected override object saveRecordingData(string key)
  1990. {
  1991. object value = null;
  1992. switch (key)
  1993. {
  1994. case "MainFontSize":
  1995. value = numericUpDown4.Value;
  1996. break;
  1997. case "MainFontColor":
  1998. value = panel1.BackColor.ToArgb();
  1999. break;
  2000. case "MainLineWidth":
  2001. value = numericUpDown3.Value;
  2002. break;
  2003. case "MainLineColor":
  2004. value = panel2.BackColor.ToArgb();
  2005. break;
  2006. }
  2007. return value;
  2008. }
  2009. private void MethodCutOffDialog_KeyDown(object sender, KeyEventArgs e)
  2010. {
  2011. if (e.KeyCode == Keys.Delete)
  2012. {
  2013. button10_Click(null, null);
  2014. e.Handled = true;
  2015. }
  2016. }
  2017. }
  2018. }