LabelListDialog.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. using Metis.ImageLabel;
  2. using PaintDotNet.Annotation;
  3. using PaintDotNet.Annotation.Enum;
  4. using PaintDotNet.Base.CommTool;
  5. using PaintDotNet.Base.SettingModel;
  6. using PaintDotNet.Base.XmlSaveModel;
  7. using PaintDotNet.CustomControl;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Windows.Forms;
  13. namespace PaintDotNet.ImageLabel
  14. {
  15. /// <summary>
  16. /// 标注列表
  17. /// </summary>
  18. internal class LabelListDialog : FloatingToolForm
  19. {
  20. private GroupBox groupBox1;
  21. private DataGridView dataGridView1;
  22. private AppWorkspace appWorkspace;
  23. private LabelStyleChangeDialog labelStyleChangeDialog;
  24. private LabelWaterMarkStyleDialog labelWaterMarkStyleDialog;
  25. private LabelWorkTypeStyleDialog labelWorkTypeStyleDialog;
  26. private LabelRulerStyleDialog labelRulerStyleDialog;
  27. private Button button2;
  28. private Button button1;
  29. private Button button5;
  30. private Button button4;
  31. private Button button3;
  32. private ComboBox comboBox1;
  33. private List<DrawObject> drawLabelList;//标注的list
  34. private string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\LabelListModel.xml";
  35. private LabelListModel labelListModel;
  36. private List<string> hasDrawList = new List<string>();
  37. private Dictionary<int, List<DrawObject>> everyDataDict = new Dictionary<int, List<DrawObject>>();
  38. public LabelListDialog(AppWorkspace appWorkspace)
  39. {
  40. this.appWorkspace = appWorkspace;
  41. InitializeComponent();
  42. InitializeLanguageText();
  43. InitDataGridViewUI();
  44. InitDataGridViewData();
  45. this.dataGridView1.CellContentClick += new DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
  46. this.appWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(RefreshDateGridView);//切换窗口
  47. this.appWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(resetData);//切换窗口
  48. this.comboBox1.SelectedIndex = 0;
  49. #region [读取xml数据]
  50. this.readLabelListXml();
  51. #endregion
  52. }
  53. /// <summary>
  54. ///
  55. /// </summary>
  56. /// <param name="sender"></param>
  57. /// <param name="e"></param>
  58. public void resetData(object sender, EventArgs e)
  59. {
  60. this.hasDrawList.Clear();
  61. comboBox1.SelectedIndex = 0;
  62. }
  63. /// <summary>
  64. /// 刷新列表数据
  65. /// </summary>
  66. /// <param name="sender"></param>
  67. /// <param name="e"></param>
  68. public void RefreshDateGridView(object sender, EventArgs e)
  69. {
  70. this.dataGridView1.Rows.Clear();
  71. InitDataGridViewData();
  72. }
  73. private void InitDataGridViewUI()
  74. {
  75. this.dataGridView1.ColumnHeadersHeight = 25;
  76. DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
  77. h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  78. h1.Width = 150;
  79. DataGridViewButtonColumn h2 = new DataGridViewButtonColumn();
  80. h2.Width = 37;
  81. DataGridViewButtonColumn h3 = new DataGridViewButtonColumn();
  82. h3.Width = 37;
  83. DataGridViewButtonColumn h4 = new DataGridViewButtonColumn();
  84. h4.Width = 37;
  85. DataGridViewButtonColumn h5 = new DataGridViewButtonColumn();
  86. h5.Width = 37;
  87. DataGridViewButtonColumn h6 = new DataGridViewButtonColumn();
  88. h6.Width = 37;
  89. DataGridViewButtonColumn h7 = new DataGridViewButtonColumn();
  90. h7.Width = 37;
  91. this.dataGridView1.Columns.Add(h1);
  92. this.dataGridView1.Columns.Add(h2);
  93. this.dataGridView1.Columns.Add(h3);
  94. this.dataGridView1.Columns.Add(h4);
  95. this.dataGridView1.Columns.Add(h5);
  96. this.dataGridView1.Columns.Add(h6);
  97. this.dataGridView1.Columns.Add(h7);
  98. DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1);
  99. helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.ImageOverlays.Labelinfolist.Label.text")));
  100. helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 6, PdnResources.GetString("Menu.operation.text")));
  101. this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  102. this.dataGridView1.Columns[0].ReadOnly = true;
  103. this.dataGridView1.AllowUserToResizeRows = false;
  104. this.dataGridView1.AllowUserToResizeColumns = false;
  105. }
  106. public void InitDataGridViewData()
  107. {
  108. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  109. {
  110. drawLabelList = new List<DrawObject>();
  111. for (int i = 0; i < this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count; i++)
  112. {
  113. if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].objectType == DrawClass.Label)
  114. {
  115. drawLabelList.Add(this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i]);
  116. }
  117. }
  118. if (drawLabelList.Count > 0)
  119. {
  120. for (int j = 0; j < drawLabelList.Count; j++)
  121. {
  122. DataGridViewRow row = new DataGridViewRow();
  123. row.Cells.Add(CreateTextBoxCell(PdnResources.GetString("Menu.LabelAction." + drawLabelList[j].drawToolType + ".Text"), drawLabelList[j]));
  124. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.upward.Text"), 1));
  125. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.down.Text"), 2));
  126. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Onthemost.Text"), 3));
  127. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Underthemost.Text"), 4));
  128. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Imagement.Measurementlist.Attributes.text"), 5));
  129. row.Cells.Add(CreateButtonCell("锁定", 6, drawLabelList[j].isLocked));
  130. this.dataGridView1.Rows.Add(row);
  131. //if (drawLabelList[j].Selected == true)
  132. //{
  133. // this.dataGridView1.Rows[j].Cells[0].Selected = true;
  134. //}
  135. }
  136. this.dataGridView1.ClearSelection();//默认会选中第一行的第一个单元格,只能绑完数据再清
  137. for (int k = 0; k < this.dataGridView1.Rows.Count; k++)
  138. {
  139. DrawObject dd = (DrawObject)this.dataGridView1.Rows[k].Cells[0].Tag;
  140. if (dd.Selected)
  141. {
  142. this.dataGridView1.Rows[k].Cells[0].Selected = true;
  143. }
  144. }
  145. }
  146. }
  147. else
  148. {
  149. this.dataGridView1.ClearSelection();
  150. drawLabelList = null;
  151. }
  152. }
  153. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  154. {
  155. var senderGrid = (DataGridView)sender;
  156. if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
  157. e.RowIndex >= 0)
  158. {
  159. switch (int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString()))
  160. {
  161. case 1:
  162. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  163. if (!drawLabelList[e.RowIndex].isLocked) {
  164. drawLabelList[e.RowIndex].Selected = true;
  165. }
  166. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToMoveUp();
  167. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  168. this.dataGridView1.Rows.Clear();
  169. InitDataGridViewData();
  170. break;
  171. case 2:
  172. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  173. if (!drawLabelList[e.RowIndex].isLocked)
  174. {
  175. drawLabelList[e.RowIndex].Selected = true;
  176. }
  177. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToMoveDown();
  178. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  179. this.dataGridView1.Rows.Clear();
  180. InitDataGridViewData();
  181. break;
  182. case 3:
  183. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  184. if (!drawLabelList[e.RowIndex].isLocked)
  185. {
  186. drawLabelList[e.RowIndex].Selected = true;
  187. }
  188. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToFront();
  189. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  190. this.dataGridView1.Rows.Clear();
  191. InitDataGridViewData();
  192. break;
  193. case 4:
  194. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  195. if (!drawLabelList[e.RowIndex].isLocked)
  196. {
  197. drawLabelList[e.RowIndex].Selected = true;
  198. }
  199. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToBack();
  200. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  201. this.dataGridView1.Rows.Clear();
  202. InitDataGridViewData();
  203. break;
  204. case 5:
  205. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  206. if (!drawLabelList[e.RowIndex].isLocked)
  207. {
  208. drawLabelList[e.RowIndex].Selected = true;
  209. }
  210. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  211. this.dataGridView1.ClearSelection();
  212. this.dataGridView1.Rows[e.RowIndex].Cells[0].Selected = true;
  213. //判断如果是水印
  214. if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawWaterMark)
  215. {
  216. labelWaterMarkStyleDialog = new LabelWaterMarkStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
  217. labelWaterMarkStyleDialog.StartPosition = FormStartPosition.CenterScreen;
  218. labelWaterMarkStyleDialog.ShowDialog();
  219. }
  220. //判断如果是工字线
  221. else if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawWorkType)
  222. {
  223. labelWorkTypeStyleDialog = new LabelWorkTypeStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
  224. labelWorkTypeStyleDialog.StartPosition = FormStartPosition.CenterScreen;
  225. labelWorkTypeStyleDialog.ShowDialog();
  226. }
  227. //如果是标尺
  228. else if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawAutoRuler || drawLabelList[e.RowIndex].drawToolType ==
  229. DrawToolType.DrawHandModeRuler || drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawPrestoredRuler)
  230. {
  231. labelRulerStyleDialog = new LabelRulerStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
  232. labelRulerStyleDialog.StartPosition = FormStartPosition.CenterParent;
  233. labelRulerStyleDialog.ShowDialog();
  234. }
  235. //如果是其它
  236. else
  237. {
  238. labelStyleChangeDialog = new LabelStyleChangeDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
  239. labelStyleChangeDialog.StartPosition = FormStartPosition.CenterScreen;
  240. labelStyleChangeDialog.ShowDialog();
  241. }
  242. break;
  243. case 6:
  244. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  245. this.lockData(e.RowIndex);
  246. break;
  247. }
  248. }
  249. }
  250. private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
  251. {
  252. DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
  253. textboxcell.Value = text;
  254. textboxcell.Tag = tag;
  255. return textboxcell;
  256. }
  257. public DataGridViewButtonCell CreateButtonCell(string text, object tag, bool isLocked = false)
  258. {
  259. DataGridViewButtonCell buttonCell = new DataGridViewButtonCell();
  260. buttonCell.FlatStyle = FlatStyle.Popup;
  261. if (isLocked)
  262. {
  263. buttonCell.Style.BackColor = System.Drawing.Color.Red;
  264. }
  265. buttonCell.Value = text;
  266. buttonCell.Tag = tag;
  267. return buttonCell;
  268. }
  269. private void InitializeLanguageText()
  270. {
  271. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  272. this.button2.Text = PdnResources.GetString("Menu.ImageOverlays.Labelinfolist.Clearall.text");
  273. this.button1.Text = PdnResources.GetString("Menu.Applyall.text");
  274. this.Text = PdnResources.GetString("Menu.LabelAction.LabelListAction.Text");
  275. }
  276. private void InitializeComponent()
  277. {
  278. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  279. this.groupBox1 = new System.Windows.Forms.GroupBox();
  280. this.comboBox1 = new System.Windows.Forms.ComboBox();
  281. this.button5 = new System.Windows.Forms.Button();
  282. this.button4 = new System.Windows.Forms.Button();
  283. this.button3 = new System.Windows.Forms.Button();
  284. this.button2 = new System.Windows.Forms.Button();
  285. this.button1 = new System.Windows.Forms.Button();
  286. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  287. this.groupBox1.SuspendLayout();
  288. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  289. this.SuspendLayout();
  290. //
  291. // groupBox1
  292. //
  293. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  294. | System.Windows.Forms.AnchorStyles.Right)));
  295. this.groupBox1.Controls.Add(this.comboBox1);
  296. this.groupBox1.Controls.Add(this.button5);
  297. this.groupBox1.Controls.Add(this.button4);
  298. this.groupBox1.Controls.Add(this.button3);
  299. this.groupBox1.Controls.Add(this.button2);
  300. this.groupBox1.Controls.Add(this.button1);
  301. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  302. this.groupBox1.Name = "groupBox1";
  303. this.groupBox1.Size = new System.Drawing.Size(544, 52);
  304. this.groupBox1.TabIndex = 0;
  305. this.groupBox1.TabStop = false;
  306. this.groupBox1.Text = "操作";
  307. //
  308. // comboBox1
  309. //
  310. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  311. this.comboBox1.FormattingEnabled = true;
  312. this.comboBox1.Items.AddRange(new object[] {
  313. "当前"});
  314. this.comboBox1.Location = new System.Drawing.Point(19, 22);
  315. this.comboBox1.Name = "comboBox1";
  316. this.comboBox1.Size = new System.Drawing.Size(121, 20);
  317. this.comboBox1.TabIndex = 5;
  318. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  319. //
  320. // button5
  321. //
  322. this.button5.Location = new System.Drawing.Point(317, 20);
  323. this.button5.Name = "button5";
  324. this.button5.Size = new System.Drawing.Size(75, 23);
  325. this.button5.TabIndex = 4;
  326. this.button5.Text = "另存";
  327. this.button5.UseVisualStyleBackColor = true;
  328. this.button5.Click += new System.EventHandler(this.button5_Click);
  329. //
  330. // button4
  331. //
  332. this.button4.Location = new System.Drawing.Point(236, 20);
  333. this.button4.Name = "button4";
  334. this.button4.Size = new System.Drawing.Size(75, 23);
  335. this.button4.TabIndex = 3;
  336. this.button4.Text = "保存";
  337. this.button4.UseVisualStyleBackColor = true;
  338. this.button4.Click += new System.EventHandler(this.button4_Click);
  339. //
  340. // button3
  341. //
  342. this.button3.Location = new System.Drawing.Point(155, 20);
  343. this.button3.Name = "button3";
  344. this.button3.Size = new System.Drawing.Size(75, 23);
  345. this.button3.TabIndex = 2;
  346. this.button3.Text = "删除";
  347. this.button3.UseVisualStyleBackColor = true;
  348. this.button3.Click += new System.EventHandler(this.button3_Click);
  349. //
  350. // button2
  351. //
  352. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  353. this.button2.Location = new System.Drawing.Point(471, 20);
  354. this.button2.Name = "button2";
  355. this.button2.Size = new System.Drawing.Size(67, 23);
  356. this.button2.TabIndex = 1;
  357. this.button2.Text = "清除全部";
  358. this.button2.UseVisualStyleBackColor = true;
  359. this.button2.Click += new System.EventHandler(this.button2_Click);
  360. //
  361. // button1
  362. //
  363. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  364. this.button1.Location = new System.Drawing.Point(398, 20);
  365. this.button1.Name = "button1";
  366. this.button1.Size = new System.Drawing.Size(67, 23);
  367. this.button1.TabIndex = 0;
  368. this.button1.Text = "应用全部";
  369. this.button1.UseVisualStyleBackColor = true;
  370. this.button1.Click += new System.EventHandler(this.button1_Click);
  371. //
  372. // dataGridView1
  373. //
  374. this.dataGridView1.AllowUserToAddRows = false;
  375. this.dataGridView1.AllowUserToDeleteRows = false;
  376. this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  377. | System.Windows.Forms.AnchorStyles.Left)
  378. | System.Windows.Forms.AnchorStyles.Right)));
  379. this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  380. this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
  381. this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
  382. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  383. dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
  384. dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  385. dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
  386. dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  387. dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  388. dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  389. this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
  390. this.dataGridView1.Location = new System.Drawing.Point(13, 72);
  391. this.dataGridView1.Name = "dataGridView1";
  392. this.dataGridView1.RowHeadersVisible = false;
  393. this.dataGridView1.RowTemplate.Height = 23;
  394. this.dataGridView1.Size = new System.Drawing.Size(544, 263);
  395. this.dataGridView1.TabIndex = 1;
  396. this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
  397. this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
  398. //
  399. // LabelListDialog
  400. //
  401. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  402. this.ClientSize = new System.Drawing.Size(570, 347);
  403. this.Controls.Add(this.dataGridView1);
  404. this.Controls.Add(this.groupBox1);
  405. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  406. this.Name = "LabelListDialog";
  407. this.Text = "标注信息列表";
  408. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LabelListDialog_FormClosing);
  409. this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.LabelListDialog_FormClosed);
  410. this.Controls.SetChildIndex(this.groupBox1, 0);
  411. this.Controls.SetChildIndex(this.dataGridView1, 0);
  412. this.groupBox1.ResumeLayout(false);
  413. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  414. this.ResumeLayout(false);
  415. }
  416. private void dataGridView1_SelectionChanged(object sender, EventArgs e)
  417. {
  418. }
  419. /// <summary>
  420. /// 清除全部
  421. /// </summary>
  422. /// <param name="sender"></param>
  423. /// <param name="e"></param>
  424. private void button2_Click(object sender, EventArgs e)
  425. {
  426. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  427. {
  428. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Clear();
  429. //this.appWorkspace.ActiveDocumentWorkspace.tools[(int)(this.appWorkspace.ActiveDocumentWorkspace.activeTool)].beginWithNewObject();
  430. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  431. this.dataGridView1.Rows.Clear();
  432. drawLabelList.Clear();
  433. this.hasDrawList.Clear();
  434. }
  435. }
  436. /// <summary>
  437. /// 应用全部
  438. /// </summary>
  439. /// <param name="sender"></param>
  440. /// <param name="e"></param>
  441. private void button1_Click(object sender, EventArgs e)
  442. {
  443. if (drawLabelList != null && drawLabelList.Count > 0)
  444. {
  445. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
  446. {
  447. if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  448. {
  449. for (int j = drawLabelList.Count - 1; j >= 0; j--)
  450. {
  451. DrawObject newObj = drawLabelList[j].Clone(this.appWorkspace.DocumentWorkspaces[i]);
  452. this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Add(newObj);
  453. //newObj.change = false;
  454. }
  455. this.appWorkspace.DocumentWorkspaces[i].Refresh();
  456. }
  457. }
  458. //for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
  459. //{
  460. // if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  461. // {
  462. // for (int k = 0; k < this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; k++)
  463. // {
  464. // this.appWorkspace.DocumentWorkspaces[i].GraphicsList[k].change = false;
  465. // }
  466. // }
  467. //}
  468. }
  469. }
  470. private void LabelListDialog_FormClosed(object sender, FormClosedEventArgs e)
  471. {
  472. drawLabelList = null;
  473. }
  474. /// <summary>
  475. /// 选中单元格后 画布对应标注图形也选中
  476. /// </summary>
  477. /// <param name="sender"></param>
  478. /// <param name="e"></param>
  479. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  480. {
  481. if (e.ColumnIndex == 0 && e.RowIndex >= 0)
  482. {
  483. var senderGrid = (DataGridView)sender;
  484. var selectedCells = senderGrid.SelectedCells;
  485. if (selectedCells.Count > 0)
  486. {
  487. DrawObject dObject;
  488. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  489. for (int i = 0; i < selectedCells.Count; i++)
  490. {
  491. dObject = (DrawObject)senderGrid.SelectedCells[i].Tag;
  492. if (!dObject.isLocked) {
  493. dObject.Selected = true;
  494. }
  495. }
  496. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  497. }
  498. }
  499. }
  500. private void LabelListDialog_FormClosing(object sender, FormClosingEventArgs e)
  501. {
  502. appWorkspace.Widgets.LabelListDialog.Visible = false;
  503. this.appWorkspace.toolBar.RefreshBtnSelect(false, "LabelListAction");
  504. this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "LabelListAction");
  505. }
  506. #region [新增方法]
  507. /// <summary>
  508. /// 读取xml数据
  509. /// </summary>
  510. private void readLabelListXml()
  511. {
  512. if (!System.IO.File.Exists(filePath))
  513. {
  514. labelListModel = new LabelListModel();
  515. LabelData labelData = new LabelData();
  516. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  517. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  518. }
  519. }
  520. /// <summary>
  521. /// 保存
  522. /// </summary>
  523. /// <param name="sender"></param>
  524. /// <param name="e"></param>
  525. private void button4_Click(object sender, EventArgs e)
  526. {
  527. if (this.appWorkspace.ActiveDocumentWorkspace == null) {
  528. return;
  529. }
  530. // 默认存到Default中
  531. if (comboBox1.SelectedIndex == 0)
  532. {
  533. button5_Click(null, null);
  534. }
  535. else
  536. {
  537. if (labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList == null)
  538. {
  539. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList = new List<LabelDataDetails>();
  540. }
  541. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Clear();
  542. foreach (var item in drawLabelList)
  543. {
  544. LabelDataDetails dataDetails = new LabelDataDetails();
  545. LabelMeasureDataModel labelData = new LabelMeasureDataModel();
  546. labelData.drawClass = "Label";
  547. labelData.drawToolType = item.drawToolType.ToString();
  548. labelData.points = item.GetPoints();
  549. labelData.style = item.GetStyle();
  550. labelData.content = item.GetContent();
  551. dataDetails.drawObject = labelData;
  552. dataDetails.isLocked = false;
  553. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Add(dataDetails);
  554. }
  555. List<DrawObject> list = new List<DrawObject>();
  556. list.AddRange(this.drawLabelList);
  557. if (everyDataDict.ContainsKey(comboBox1.SelectedIndex))
  558. {
  559. everyDataDict[comboBox1.SelectedIndex] = list;
  560. }
  561. else {
  562. everyDataDict.Add(comboBox1.SelectedIndex, list);
  563. }
  564. }
  565. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  566. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  567. }
  568. /// <summary>
  569. /// 删除
  570. /// </summary>
  571. /// <param name="sender"></param>
  572. /// <param name="e"></param>
  573. private void button3_Click(object sender, EventArgs e)
  574. {
  575. if (comboBox1.SelectedIndex == 0)
  576. {
  577. MessageBox.Show("当前选项不可删除!");
  578. return;
  579. }
  580. DialogResult dr = MessageBox.Show("您确定要删除当前标注信息吗?", PdnResources.GetString("Form.OkButton.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  581. if (dr != DialogResult.OK)
  582. {
  583. return;
  584. }
  585. int index = comboBox1.SelectedIndex;
  586. comboBox1.Items.RemoveAt(index);
  587. labelListModel.labelDataList.RemoveAt(index - 1);
  588. everyDataDict.Remove(index - 1);
  589. comboBox1.SelectedIndex = 0;
  590. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  591. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  592. }
  593. /// <summary>
  594. /// 另存为
  595. /// </summary>
  596. /// <param name="sender"></param>
  597. /// <param name="e"></param>
  598. private void button5_Click(object sender, EventArgs e)
  599. {
  600. if (this.appWorkspace.ActiveDocumentWorkspace == null)
  601. {
  602. return;
  603. }
  604. //調用委托
  605. LabelListChangeName form = new LabelListChangeName();
  606. //调用子窗体中的委托,将方法给委托
  607. form.TransferEvent += frm_TransEvent;
  608. form.ShowDialog();
  609. }
  610. /// <summary>
  611. /// 委托
  612. /// </summary>
  613. /// <param name="jianyanxiangmuName"></param>
  614. /// <param name="guige1"></param>
  615. /// <param name="guige2"></param>
  616. /// <param name="isEdit"></param>
  617. private void frm_TransEvent(string name)
  618. {
  619. comboBox1.Items.Add(name);
  620. LabelData data = new LabelData();
  621. data.name = name;
  622. data.labelDataDetailList = new List<LabelDataDetails>();
  623. foreach (var item in drawLabelList)
  624. {
  625. LabelDataDetails dataDetails = new LabelDataDetails();
  626. LabelMeasureDataModel labelData = new LabelMeasureDataModel();
  627. labelData.drawClass = "Label";
  628. labelData.drawToolType = item.drawToolType.ToString();
  629. labelData.points = item.GetPoints();
  630. labelData.style = item.GetStyle();
  631. labelData.content = item.GetContent();
  632. dataDetails.drawObject = labelData;
  633. dataDetails.isLocked = false;
  634. data.labelDataDetailList.Add(dataDetails);
  635. }
  636. labelListModel.labelDataList.Add(data);
  637. List<DrawObject> list = new List<DrawObject>();
  638. foreach (var item in this.drawLabelList) {
  639. list.Add(item.Clone());
  640. }
  641. everyDataDict.Add(labelListModel.labelDataList.Count - 1, list);
  642. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  643. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  644. }
  645. /// <summary>
  646. /// 切换xml文件
  647. /// </summary>
  648. /// <param name="sender"></param>
  649. /// <param name="e"></param>
  650. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  651. {
  652. this.dataGridView1.Rows.Clear();
  653. if (comboBox1.SelectedIndex == 0)
  654. {
  655. RefreshDateGridView(null,null);
  656. }
  657. else {
  658. this.drawLabelList.Clear();
  659. var labelData = labelListModel.labelDataList[comboBox1.SelectedIndex - 1];
  660. bool hasDraw = this.hasDrawList.Contains(labelData.name);
  661. if (!hasDraw)
  662. {
  663. this.hasDrawList.Add(labelData.name);
  664. }
  665. List<DrawObject> list;
  666. everyDataDict.TryGetValue(comboBox1.SelectedIndex - 1, out list);
  667. if (list == null) {
  668. list = new List<DrawObject>();
  669. }
  670. this.drawLabelList.AddRange(list);
  671. if (drawLabelList.Count > 0)
  672. {
  673. for (int j = 0; j < drawLabelList.Count; j++)
  674. {
  675. DataGridViewRow row = new DataGridViewRow();
  676. row.Cells.Add(CreateTextBoxCell(PdnResources.GetString("Menu.LabelAction." + drawLabelList[j].drawToolType + ".Text"), drawLabelList[j]));
  677. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.upward.Text"), 1));
  678. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.down.Text"), 2));
  679. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Onthemost.Text"), 3));
  680. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Underthemost.Text"), 4));
  681. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Imagement.Measurementlist.Attributes.text"), 5));
  682. row.Cells.Add(CreateButtonCell("锁定", 6, drawLabelList[j].isLocked));
  683. this.dataGridView1.Rows.Add(row);
  684. if (!hasDraw) {
  685. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add(drawLabelList[j]);
  686. }
  687. }
  688. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  689. this.dataGridView1.ClearSelection();//默认会选中第一行的第一个单元格,只能绑完数据再清
  690. for (int k = 0; k < this.dataGridView1.Rows.Count; k++)
  691. {
  692. DrawObject dd = (DrawObject)this.dataGridView1.Rows[k].Cells[0].Tag;
  693. if (dd.Selected)
  694. {
  695. this.dataGridView1.Rows[k].Cells[0].Selected = true;
  696. }
  697. }
  698. }
  699. }
  700. }
  701. /// <summary>
  702. /// 锁定数据
  703. /// </summary>
  704. /// <param name="index"></param>
  705. private void lockData(int index)
  706. {
  707. var drawObject = drawLabelList[index];
  708. drawObject.isLocked = !drawObject.isLocked;
  709. if (drawObject.isLocked)
  710. {
  711. this.dataGridView1.Rows[index].Cells[6].Style.BackColor = System.Drawing.Color.Red;
  712. }
  713. else {
  714. this.dataGridView1.Rows[index].Cells[6].Style.BackColor = DataGridView.DefaultBackColor;
  715. }
  716. this.dataGridView1.Rows[index].Cells[6].Selected = false;
  717. this.dataGridView1.Rows[index].Cells[0].Selected = true;
  718. }
  719. public void getData()
  720. {
  721. everyDataDict.Clear();
  722. comboBox1.Items.Clear();
  723. comboBox1.Items.Add("当前");
  724. if (this.appWorkspace.ActiveDocumentWorkspace == null)
  725. {
  726. return;
  727. }
  728. labelListModel = XmlSerializeHelper.DESerializer<LabelListModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  729. if (labelListModel.labelDataList.Count > 0)
  730. {
  731. foreach (var item in labelListModel.labelDataList)
  732. {
  733. var index = labelListModel.labelDataList.IndexOf(item);
  734. List<DrawObject> list = new List<DrawObject>();
  735. foreach (var drawObject in item.labelDataDetailList)
  736. {
  737. string className = InvariantData.path_Label + "." + drawObject.drawObject.drawToolType;
  738. object[] parameters = new object[4];
  739. parameters[0] = this.appWorkspace.ActiveDocumentWorkspace;
  740. parameters[1] = drawObject.drawObject.points;
  741. parameters[2] = drawObject.drawObject.style;
  742. parameters[3] = drawObject.drawObject.content;
  743. object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
  744. list.Add(((DrawObject)obj));
  745. //this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add((DrawObject)obj);
  746. }
  747. if (everyDataDict.ContainsKey(index)) {
  748. everyDataDict[index] = list;
  749. } else {
  750. everyDataDict.Add(index, list);
  751. }
  752. comboBox1.Items.Add(item.name);
  753. }
  754. }
  755. comboBox1.SelectedIndex = 0;
  756. }
  757. #endregion
  758. }
  759. }