LabelListDialog.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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. this.comboBox1.Items.AddRange(new object[] {
  276. PdnResources.GetString("LabelList.Current")});
  277. this.button5.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Saveas.text");
  278. this.button4.Text = PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText");
  279. this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  280. }
  281. private void InitializeComponent()
  282. {
  283. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  284. this.groupBox1 = new System.Windows.Forms.GroupBox();
  285. this.comboBox1 = new System.Windows.Forms.ComboBox();
  286. this.button5 = new System.Windows.Forms.Button();
  287. this.button4 = new System.Windows.Forms.Button();
  288. this.button3 = new System.Windows.Forms.Button();
  289. this.button2 = new System.Windows.Forms.Button();
  290. this.button1 = new System.Windows.Forms.Button();
  291. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  292. this.groupBox1.SuspendLayout();
  293. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  294. this.SuspendLayout();
  295. //
  296. // groupBox1
  297. //
  298. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  299. | System.Windows.Forms.AnchorStyles.Right)));
  300. this.groupBox1.Controls.Add(this.comboBox1);
  301. this.groupBox1.Controls.Add(this.button5);
  302. this.groupBox1.Controls.Add(this.button4);
  303. this.groupBox1.Controls.Add(this.button3);
  304. this.groupBox1.Controls.Add(this.button2);
  305. this.groupBox1.Controls.Add(this.button1);
  306. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  307. this.groupBox1.Name = "groupBox1";
  308. this.groupBox1.Size = new System.Drawing.Size(544, 52);
  309. this.groupBox1.TabIndex = 0;
  310. this.groupBox1.TabStop = false;
  311. this.groupBox1.Text = "操作";
  312. //
  313. // comboBox1
  314. //
  315. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  316. this.comboBox1.FormattingEnabled = true;
  317. this.comboBox1.Location = new System.Drawing.Point(19, 22);
  318. this.comboBox1.Name = "comboBox1";
  319. this.comboBox1.Size = new System.Drawing.Size(121, 20);
  320. this.comboBox1.TabIndex = 5;
  321. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  322. //
  323. // button5
  324. //
  325. this.button5.Location = new System.Drawing.Point(317, 20);
  326. this.button5.Name = "button5";
  327. this.button5.Size = new System.Drawing.Size(75, 23);
  328. this.button5.TabIndex = 4;
  329. this.button5.Text = "另存";
  330. this.button5.UseVisualStyleBackColor = true;
  331. this.button5.Click += new System.EventHandler(this.button5_Click);
  332. //
  333. // button4
  334. //
  335. this.button4.Location = new System.Drawing.Point(236, 20);
  336. this.button4.Name = "button4";
  337. this.button4.Size = new System.Drawing.Size(75, 23);
  338. this.button4.TabIndex = 3;
  339. this.button4.Text = "保存";
  340. this.button4.UseVisualStyleBackColor = true;
  341. this.button4.Click += new System.EventHandler(this.button4_Click);
  342. //
  343. // button3
  344. //
  345. this.button3.Location = new System.Drawing.Point(155, 20);
  346. this.button3.Name = "button3";
  347. this.button3.Size = new System.Drawing.Size(75, 23);
  348. this.button3.TabIndex = 2;
  349. this.button3.Text = "删除";
  350. this.button3.UseVisualStyleBackColor = true;
  351. this.button3.Click += new System.EventHandler(this.button3_Click);
  352. //
  353. // button2
  354. //
  355. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  356. this.button2.Location = new System.Drawing.Point(471, 20);
  357. this.button2.Name = "button2";
  358. this.button2.Size = new System.Drawing.Size(67, 23);
  359. this.button2.TabIndex = 1;
  360. this.button2.Text = "清除全部";
  361. this.button2.UseVisualStyleBackColor = true;
  362. this.button2.Click += new System.EventHandler(this.button2_Click);
  363. //
  364. // button1
  365. //
  366. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  367. this.button1.Location = new System.Drawing.Point(398, 20);
  368. this.button1.Name = "button1";
  369. this.button1.Size = new System.Drawing.Size(67, 23);
  370. this.button1.TabIndex = 0;
  371. this.button1.Text = "应用全部";
  372. this.button1.UseVisualStyleBackColor = true;
  373. this.button1.Click += new System.EventHandler(this.button1_Click);
  374. //
  375. // dataGridView1
  376. //
  377. this.dataGridView1.AllowUserToAddRows = false;
  378. this.dataGridView1.AllowUserToDeleteRows = false;
  379. this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  380. | System.Windows.Forms.AnchorStyles.Left)
  381. | System.Windows.Forms.AnchorStyles.Right)));
  382. this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  383. this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
  384. this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
  385. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  386. dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
  387. dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  388. dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
  389. dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  390. dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  391. dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  392. this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
  393. this.dataGridView1.Location = new System.Drawing.Point(13, 72);
  394. this.dataGridView1.Name = "dataGridView1";
  395. this.dataGridView1.RowHeadersVisible = false;
  396. this.dataGridView1.RowTemplate.Height = 23;
  397. this.dataGridView1.Size = new System.Drawing.Size(544, 263);
  398. this.dataGridView1.TabIndex = 1;
  399. this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
  400. this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
  401. //
  402. // LabelListDialog
  403. //
  404. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  405. this.ClientSize = new System.Drawing.Size(570, 347);
  406. this.Controls.Add(this.dataGridView1);
  407. this.Controls.Add(this.groupBox1);
  408. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  409. this.Name = "LabelListDialog";
  410. this.Text = "标注信息列表";
  411. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LabelListDialog_FormClosing);
  412. this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.LabelListDialog_FormClosed);
  413. this.Controls.SetChildIndex(this.groupBox1, 0);
  414. this.Controls.SetChildIndex(this.dataGridView1, 0);
  415. this.groupBox1.ResumeLayout(false);
  416. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  417. this.ResumeLayout(false);
  418. }
  419. private void dataGridView1_SelectionChanged(object sender, EventArgs e)
  420. {
  421. }
  422. /// <summary>
  423. /// 清除全部
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void button2_Click(object sender, EventArgs e)
  428. {
  429. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  430. {
  431. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Clear();
  432. //this.appWorkspace.ActiveDocumentWorkspace.tools[(int)(this.appWorkspace.ActiveDocumentWorkspace.ActiveTool)].beginWithNewObject();
  433. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  434. this.dataGridView1.Rows.Clear();
  435. drawLabelList.Clear();
  436. this.hasDrawList.Clear();
  437. }
  438. }
  439. /// <summary>
  440. /// 应用全部
  441. /// </summary>
  442. /// <param name="sender"></param>
  443. /// <param name="e"></param>
  444. private void button1_Click(object sender, EventArgs e)
  445. {
  446. if (drawLabelList != null && drawLabelList.Count > 0)
  447. {
  448. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
  449. {
  450. if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  451. {
  452. for (int j = drawLabelList.Count - 1; j >= 0; j--)
  453. {
  454. DrawObject newObj = drawLabelList[j].Clone(this.appWorkspace.DocumentWorkspaces[i]);
  455. this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Add(newObj);
  456. //newObj.change = false;
  457. }
  458. this.appWorkspace.DocumentWorkspaces[i].Refresh();
  459. }
  460. }
  461. //for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
  462. //{
  463. // if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  464. // {
  465. // for (int k = 0; k < this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; k++)
  466. // {
  467. // this.appWorkspace.DocumentWorkspaces[i].GraphicsList[k].change = false;
  468. // }
  469. // }
  470. //}
  471. }
  472. }
  473. private void LabelListDialog_FormClosed(object sender, FormClosedEventArgs e)
  474. {
  475. drawLabelList = null;
  476. }
  477. /// <summary>
  478. /// 选中单元格后 画布对应标注图形也选中
  479. /// </summary>
  480. /// <param name="sender"></param>
  481. /// <param name="e"></param>
  482. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  483. {
  484. if (e.ColumnIndex == 0 && e.RowIndex >= 0)
  485. {
  486. var senderGrid = (DataGridView)sender;
  487. var selectedCells = senderGrid.SelectedCells;
  488. if (selectedCells.Count > 0)
  489. {
  490. DrawObject dObject;
  491. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  492. for (int i = 0; i < selectedCells.Count; i++)
  493. {
  494. dObject = (DrawObject)senderGrid.SelectedCells[i].Tag;
  495. if (!dObject.isLocked) {
  496. dObject.Selected = true;
  497. }
  498. }
  499. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  500. }
  501. }
  502. }
  503. private void LabelListDialog_FormClosing(object sender, FormClosingEventArgs e)
  504. {
  505. appWorkspace.Widgets.LabelListDialog.Visible = false;
  506. this.appWorkspace.toolBar.RefreshBtnSelect(false, "LabelListAction");
  507. this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "LabelListAction");
  508. }
  509. #region [新增方法]
  510. /// <summary>
  511. /// 读取xml数据
  512. /// </summary>
  513. private void readLabelListXml()
  514. {
  515. if (!System.IO.File.Exists(filePath))
  516. {
  517. labelListModel = new LabelListModel();
  518. LabelData labelData = new LabelData();
  519. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  520. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  521. }
  522. }
  523. /// <summary>
  524. /// 保存
  525. /// </summary>
  526. /// <param name="sender"></param>
  527. /// <param name="e"></param>
  528. private void button4_Click(object sender, EventArgs e)
  529. {
  530. if (this.appWorkspace.ActiveDocumentWorkspace == null) {
  531. return;
  532. }
  533. // 默认存到Default中
  534. if (comboBox1.SelectedIndex == 0)
  535. {
  536. button5_Click(null, null);
  537. }
  538. else
  539. {
  540. if (labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList == null)
  541. {
  542. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList = new List<LabelDataDetails>();
  543. }
  544. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Clear();
  545. foreach (var item in drawLabelList)
  546. {
  547. LabelDataDetails dataDetails = new LabelDataDetails();
  548. LabelMeasureDataModel labelData = new LabelMeasureDataModel();
  549. labelData.drawClass = "Label";
  550. labelData.drawToolType = item.drawToolType.ToString();
  551. labelData.points = item.GetPoints();
  552. labelData.style = item.GetStyle();
  553. labelData.content = item.GetContent();
  554. dataDetails.drawObject = labelData;
  555. dataDetails.isLocked = false;
  556. labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Add(dataDetails);
  557. }
  558. List<DrawObject> list = new List<DrawObject>();
  559. list.AddRange(this.drawLabelList);
  560. if (everyDataDict.ContainsKey(comboBox1.SelectedIndex))
  561. {
  562. everyDataDict[comboBox1.SelectedIndex] = list;
  563. }
  564. else {
  565. everyDataDict.Add(comboBox1.SelectedIndex, list);
  566. }
  567. }
  568. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  569. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  570. }
  571. /// <summary>
  572. /// 删除
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void button3_Click(object sender, EventArgs e)
  577. {
  578. if (comboBox1.SelectedIndex == 0)
  579. {
  580. MessageBox.Show("当前选项不可删除!");
  581. return;
  582. }
  583. DialogResult dr = MessageBox.Show("您确定要删除当前标注信息吗?", PdnResources.GetString("Form.OkButton.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  584. if (dr != DialogResult.OK)
  585. {
  586. return;
  587. }
  588. int index = comboBox1.SelectedIndex;
  589. comboBox1.Items.RemoveAt(index);
  590. labelListModel.labelDataList.RemoveAt(index - 1);
  591. everyDataDict.Remove(index - 1);
  592. comboBox1.SelectedIndex = 0;
  593. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  594. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  595. }
  596. /// <summary>
  597. /// 另存为
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void button5_Click(object sender, EventArgs e)
  602. {
  603. if (this.appWorkspace.ActiveDocumentWorkspace == null)
  604. {
  605. return;
  606. }
  607. //調用委托
  608. LabelListChangeName form = new LabelListChangeName();
  609. //调用子窗体中的委托,将方法给委托
  610. form.TransferEvent += frm_TransEvent;
  611. form.ShowDialog();
  612. }
  613. /// <summary>
  614. /// 委托
  615. /// </summary>
  616. /// <param name="jianyanxiangmuName"></param>
  617. /// <param name="guige1"></param>
  618. /// <param name="guige2"></param>
  619. /// <param name="isEdit"></param>
  620. private void frm_TransEvent(string name)
  621. {
  622. comboBox1.Items.Add(name);
  623. LabelData data = new LabelData();
  624. data.name = name;
  625. data.labelDataDetailList = new List<LabelDataDetails>();
  626. foreach (var item in drawLabelList)
  627. {
  628. LabelDataDetails dataDetails = new LabelDataDetails();
  629. LabelMeasureDataModel labelData = new LabelMeasureDataModel();
  630. labelData.drawClass = "Label";
  631. labelData.drawToolType = item.drawToolType.ToString();
  632. labelData.points = item.GetPoints();
  633. labelData.style = item.GetStyle();
  634. labelData.content = item.GetContent();
  635. dataDetails.drawObject = labelData;
  636. dataDetails.isLocked = false;
  637. data.labelDataDetailList.Add(dataDetails);
  638. }
  639. labelListModel.labelDataList.Add(data);
  640. List<DrawObject> list = new List<DrawObject>();
  641. foreach (var item in this.drawLabelList) {
  642. list.Add(item.Clone());
  643. }
  644. everyDataDict.Add(labelListModel.labelDataList.Count - 1, list);
  645. string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
  646. FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
  647. }
  648. /// <summary>
  649. /// 切换xml文件
  650. /// </summary>
  651. /// <param name="sender"></param>
  652. /// <param name="e"></param>
  653. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  654. {
  655. this.dataGridView1.Rows.Clear();
  656. if (comboBox1.SelectedIndex == 0)
  657. {
  658. RefreshDateGridView(null,null);
  659. }
  660. else {
  661. this.drawLabelList.Clear();
  662. var labelData = labelListModel.labelDataList[comboBox1.SelectedIndex - 1];
  663. bool hasDraw = this.hasDrawList.Contains(labelData.name);
  664. if (!hasDraw)
  665. {
  666. this.hasDrawList.Add(labelData.name);
  667. }
  668. List<DrawObject> list;
  669. everyDataDict.TryGetValue(comboBox1.SelectedIndex - 1, out list);
  670. if (list == null) {
  671. list = new List<DrawObject>();
  672. }
  673. this.drawLabelList.AddRange(list);
  674. if (drawLabelList.Count > 0)
  675. {
  676. for (int j = 0; j < drawLabelList.Count; j++)
  677. {
  678. DataGridViewRow row = new DataGridViewRow();
  679. row.Cells.Add(CreateTextBoxCell(PdnResources.GetString("Menu.LabelAction." + drawLabelList[j].drawToolType + ".Text"), drawLabelList[j]));
  680. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.upward.Text"), 1));
  681. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.down.Text"), 2));
  682. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Onthemost.Text"), 3));
  683. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Underthemost.Text"), 4));
  684. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Imagement.Measurementlist.Attributes.text"), 5));
  685. row.Cells.Add(CreateButtonCell("锁定", 6, drawLabelList[j].isLocked));
  686. this.dataGridView1.Rows.Add(row);
  687. if (!hasDraw) {
  688. this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add(drawLabelList[j]);
  689. }
  690. }
  691. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  692. this.dataGridView1.ClearSelection();//默认会选中第一行的第一个单元格,只能绑完数据再清
  693. for (int k = 0; k < this.dataGridView1.Rows.Count; k++)
  694. {
  695. DrawObject dd = (DrawObject)this.dataGridView1.Rows[k].Cells[0].Tag;
  696. if (dd.Selected)
  697. {
  698. this.dataGridView1.Rows[k].Cells[0].Selected = true;
  699. }
  700. }
  701. }
  702. }
  703. }
  704. /// <summary>
  705. /// 锁定数据
  706. /// </summary>
  707. /// <param name="index"></param>
  708. private void lockData(int index)
  709. {
  710. var drawObject = drawLabelList[index];
  711. drawObject.isLocked = !drawObject.isLocked;
  712. if (drawObject.isLocked)
  713. {
  714. this.dataGridView1.Rows[index].Cells[6].Style.BackColor = System.Drawing.Color.Red;
  715. }
  716. else {
  717. this.dataGridView1.Rows[index].Cells[6].Style.BackColor = DataGridView.DefaultBackColor;
  718. }
  719. this.dataGridView1.Rows[index].Cells[6].Selected = false;
  720. this.dataGridView1.Rows[index].Cells[0].Selected = true;
  721. }
  722. public void getData()
  723. {
  724. everyDataDict.Clear();
  725. comboBox1.Items.Clear();
  726. comboBox1.Items.Add("当前");
  727. if (this.appWorkspace.ActiveDocumentWorkspace == null)
  728. {
  729. return;
  730. }
  731. labelListModel = XmlSerializeHelper.DESerializer<LabelListModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  732. if (labelListModel.labelDataList.Count > 0)
  733. {
  734. foreach (var item in labelListModel.labelDataList)
  735. {
  736. var index = labelListModel.labelDataList.IndexOf(item);
  737. List<DrawObject> list = new List<DrawObject>();
  738. foreach (var drawObject in item.labelDataDetailList)
  739. {
  740. string className = InvariantData.path_Label + "." + drawObject.drawObject.drawToolType;
  741. object[] parameters = new object[4];
  742. parameters[0] = this.appWorkspace.ActiveDocumentWorkspace;
  743. parameters[1] = drawObject.drawObject.points;
  744. parameters[2] = drawObject.drawObject.style;
  745. parameters[3] = drawObject.drawObject.content;
  746. object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
  747. list.Add(((DrawObject)obj));
  748. //this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add((DrawObject)obj);
  749. }
  750. if (everyDataDict.ContainsKey(index)) {
  751. everyDataDict[index] = list;
  752. } else {
  753. everyDataDict.Add(index, list);
  754. }
  755. comboBox1.Items.Add(item.name);
  756. }
  757. }
  758. comboBox1.SelectedIndex = 0;
  759. }
  760. #endregion
  761. }
  762. }