123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855 |
- using Metis.ImageLabel;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Base.XmlSaveModel;
- using PaintDotNet.CustomControl;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- namespace PaintDotNet.ImageLabel
- {
- /// <summary>
- /// 标注列表
- /// </summary>
- internal class LabelListDialog : FloatingToolForm
- {
- private GroupBox groupBox1;
- private DataGridView dataGridView1;
- private AppWorkspace appWorkspace;
- private LabelStyleChangeDialog labelStyleChangeDialog;
- private LabelWaterMarkStyleDialog labelWaterMarkStyleDialog;
- private LabelWorkTypeStyleDialog labelWorkTypeStyleDialog;
- private LabelRulerStyleDialog labelRulerStyleDialog;
- private Button button2;
- private Button button1;
- private Button button5;
- private Button button4;
- private Button button3;
- private ComboBox comboBox1;
- private List<DrawObject> drawLabelList;//标注的list
- private string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\LabelListModel.xml";
- private LabelListModel labelListModel;
- private List<string> hasDrawList = new List<string>();
- private Dictionary<int, List<DrawObject>> everyDataDict = new Dictionary<int, List<DrawObject>>();
- public LabelListDialog(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- InitDataGridViewUI();
- InitDataGridViewData();
- this.dataGridView1.CellContentClick += new DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
- this.appWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(RefreshDateGridView);//切换窗口
- this.appWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(resetData);//切换窗口
- this.comboBox1.SelectedIndex = 0;
- #region [读取xml数据]
- this.readLabelListXml();
- #endregion
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void resetData(object sender, EventArgs e)
- {
- this.hasDrawList.Clear();
- comboBox1.SelectedIndex = 0;
- }
- /// <summary>
- /// 刷新列表数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void RefreshDateGridView(object sender, EventArgs e)
- {
- this.dataGridView1.Rows.Clear();
- InitDataGridViewData();
- }
- private void InitDataGridViewUI()
- {
- this.dataGridView1.ColumnHeadersHeight = 25;
-
- DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
- h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
- h1.Width = 150;
- DataGridViewButtonColumn h2 = new DataGridViewButtonColumn();
- h2.Width = 37;
- DataGridViewButtonColumn h3 = new DataGridViewButtonColumn();
- h3.Width = 37;
- DataGridViewButtonColumn h4 = new DataGridViewButtonColumn();
- h4.Width = 37;
- DataGridViewButtonColumn h5 = new DataGridViewButtonColumn();
- h5.Width = 37;
- DataGridViewButtonColumn h6 = new DataGridViewButtonColumn();
- h6.Width = 37;
- DataGridViewButtonColumn h7 = new DataGridViewButtonColumn();
- h7.Width = 37;
- this.dataGridView1.Columns.Add(h1);
- this.dataGridView1.Columns.Add(h2);
- this.dataGridView1.Columns.Add(h3);
- this.dataGridView1.Columns.Add(h4);
- this.dataGridView1.Columns.Add(h5);
- this.dataGridView1.Columns.Add(h6);
- this.dataGridView1.Columns.Add(h7);
- DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1);
- helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.ImageOverlays.Labelinfolist.Label.text")));
- helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 6, PdnResources.GetString("Menu.operation.text")));
-
- this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView1.Columns[0].ReadOnly = true;
- this.dataGridView1.AllowUserToResizeRows = false;
- this.dataGridView1.AllowUserToResizeColumns = false;
- }
- public void InitDataGridViewData()
- {
- if (this.appWorkspace.ActiveDocumentWorkspace != null)
- {
- drawLabelList = new List<DrawObject>();
- for (int i = 0; i < this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Count; i++)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i].objectType == DrawClass.Label)
- {
- drawLabelList.Add(this.appWorkspace.ActiveDocumentWorkspace.GraphicsList[i]);
- }
- }
- if (drawLabelList.Count > 0)
- {
- for (int j = 0; j < drawLabelList.Count; j++)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(PdnResources.GetString("Menu.LabelAction." + drawLabelList[j].drawToolType + ".Text"), drawLabelList[j]));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.upward.Text"), 1));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.down.Text"), 2));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Onthemost.Text"), 3));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Underthemost.Text"), 4));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Imagement.Measurementlist.Attributes.text"), 5));
- row.Cells.Add(CreateButtonCell("锁定", 6, drawLabelList[j].isLocked));
- this.dataGridView1.Rows.Add(row);
- //if (drawLabelList[j].Selected == true)
- //{
- // this.dataGridView1.Rows[j].Cells[0].Selected = true;
- //}
- }
- this.dataGridView1.ClearSelection();//默认会选中第一行的第一个单元格,只能绑完数据再清
- for (int k = 0; k < this.dataGridView1.Rows.Count; k++)
- {
- DrawObject dd = (DrawObject)this.dataGridView1.Rows[k].Cells[0].Tag;
- if (dd.Selected)
- {
- this.dataGridView1.Rows[k].Cells[0].Selected = true;
- }
- }
- }
- }
- else
- {
- this.dataGridView1.ClearSelection();
- drawLabelList = null;
- }
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- var senderGrid = (DataGridView)sender;
- if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
- e.RowIndex >= 0)
- {
- switch (int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString()))
- {
- case 1:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- if (!drawLabelList[e.RowIndex].isLocked) {
- drawLabelList[e.RowIndex].Selected = true;
- }
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToMoveUp();
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- InitDataGridViewData();
- break;
- case 2:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- if (!drawLabelList[e.RowIndex].isLocked)
- {
- drawLabelList[e.RowIndex].Selected = true;
- }
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToMoveDown();
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- InitDataGridViewData();
- break;
- case 3:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- if (!drawLabelList[e.RowIndex].isLocked)
- {
- drawLabelList[e.RowIndex].Selected = true;
- }
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToFront();
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- InitDataGridViewData();
- break;
- case 4:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- if (!drawLabelList[e.RowIndex].isLocked)
- {
- drawLabelList[e.RowIndex].Selected = true;
- }
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.MoveSelectionToBack();
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- InitDataGridViewData();
- break;
- case 5:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- if (!drawLabelList[e.RowIndex].isLocked)
- {
- drawLabelList[e.RowIndex].Selected = true;
- }
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.ClearSelection();
- this.dataGridView1.Rows[e.RowIndex].Cells[0].Selected = true;
- //判断如果是水印
- if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawWaterMark)
- {
- labelWaterMarkStyleDialog = new LabelWaterMarkStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
- labelWaterMarkStyleDialog.StartPosition = FormStartPosition.CenterScreen;
- labelWaterMarkStyleDialog.ShowDialog();
- }
- //判断如果是工字线
- else if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawWorkType)
- {
- labelWorkTypeStyleDialog = new LabelWorkTypeStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
- labelWorkTypeStyleDialog.StartPosition = FormStartPosition.CenterScreen;
- labelWorkTypeStyleDialog.ShowDialog();
- }
- //如果是标尺
- else if (drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawAutoRuler || drawLabelList[e.RowIndex].drawToolType ==
- DrawToolType.DrawHandModeRuler || drawLabelList[e.RowIndex].drawToolType == DrawToolType.DrawPrestoredRuler)
- {
- labelRulerStyleDialog = new LabelRulerStyleDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
- labelRulerStyleDialog.StartPosition = FormStartPosition.CenterParent;
- labelRulerStyleDialog.ShowDialog();
- }
- //如果是其它
- else
- {
- labelStyleChangeDialog = new LabelStyleChangeDialog(this.appWorkspace, drawLabelList[e.RowIndex]);
- labelStyleChangeDialog.StartPosition = FormStartPosition.CenterScreen;
- labelStyleChangeDialog.ShowDialog();
- }
- break;
- case 6:
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- this.lockData(e.RowIndex);
-
- break;
- }
- }
- }
- private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
- {
- DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
- textboxcell.Value = text;
- textboxcell.Tag = tag;
- return textboxcell;
- }
- public DataGridViewButtonCell CreateButtonCell(string text, object tag, bool isLocked = false)
- {
- DataGridViewButtonCell buttonCell = new DataGridViewButtonCell();
- buttonCell.FlatStyle = FlatStyle.Popup;
- if (isLocked)
- {
- buttonCell.Style.BackColor = System.Drawing.Color.Red;
- }
- buttonCell.Value = text;
- buttonCell.Tag = tag;
- return buttonCell;
- }
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
- this.button2.Text = PdnResources.GetString("Menu.ImageOverlays.Labelinfolist.Clearall.text");
- this.button1.Text = PdnResources.GetString("Menu.Applyall.text");
- this.Text = PdnResources.GetString("Menu.LabelAction.LabelListAction.Text");
- this.comboBox1.Items.AddRange(new object[] {
- PdnResources.GetString("LabelList.Current")});
- this.button5.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Saveas.text");
- this.button4.Text = PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText");
- this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
- }
- private void InitializeComponent()
- {
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.button5 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.dataGridView1 = new System.Windows.Forms.DataGridView();
- this.groupBox1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.comboBox1);
- this.groupBox1.Controls.Add(this.button5);
- this.groupBox1.Controls.Add(this.button4);
- this.groupBox1.Controls.Add(this.button3);
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Controls.Add(this.button1);
- this.groupBox1.Location = new System.Drawing.Point(13, 13);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(544, 52);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "操作";
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(19, 22);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(121, 20);
- this.comboBox1.TabIndex = 5;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(317, 20);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 4;
- this.button5.Text = "另存";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(236, 20);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 3;
- this.button4.Text = "保存";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(155, 20);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 2;
- this.button3.Text = "删除";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button2
- //
- this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button2.Location = new System.Drawing.Point(471, 20);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(67, 23);
- this.button2.TabIndex = 1;
- this.button2.Text = "清除全部";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button1
- //
- this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button1.Location = new System.Drawing.Point(398, 20);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(67, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "应用全部";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // dataGridView1
- //
- this.dataGridView1.AllowUserToAddRows = false;
- this.dataGridView1.AllowUserToDeleteRows = false;
- this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
- this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
- this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
- dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
- dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
- dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
- this.dataGridView1.Location = new System.Drawing.Point(13, 72);
- this.dataGridView1.Name = "dataGridView1";
- this.dataGridView1.RowHeadersVisible = false;
- this.dataGridView1.RowTemplate.Height = 23;
- this.dataGridView1.Size = new System.Drawing.Size(544, 263);
- this.dataGridView1.TabIndex = 1;
- this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
- this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
- //
- // LabelListDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(570, 347);
- this.Controls.Add(this.dataGridView1);
- this.Controls.Add(this.groupBox1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Name = "LabelListDialog";
- this.Text = "标注信息列表";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LabelListDialog_FormClosing);
- this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.LabelListDialog_FormClosed);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.dataGridView1, 0);
- this.groupBox1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
- this.ResumeLayout(false);
- }
- private void dataGridView1_SelectionChanged(object sender, EventArgs e)
- {
-
- }
- /// <summary>
- /// 清除全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace != null)
- {
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Clear();
- //this.appWorkspace.ActiveDocumentWorkspace.tools[(int)(this.appWorkspace.ActiveDocumentWorkspace.ActiveTool)].beginWithNewObject();
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.Rows.Clear();
- drawLabelList.Clear();
- this.hasDrawList.Clear();
- }
- }
- /// <summary>
- /// 应用全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (drawLabelList != null && drawLabelList.Count > 0)
- {
- for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
- {
- if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
- {
- for (int j = drawLabelList.Count - 1; j >= 0; j--)
- {
- DrawObject newObj = drawLabelList[j].Clone(this.appWorkspace.DocumentWorkspaces[i]);
- this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Add(newObj);
- //newObj.change = false;
- }
- this.appWorkspace.DocumentWorkspaces[i].Refresh();
- }
- }
- //for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Count(); i++)
- //{
- // if (!this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
- // {
- // for (int k = 0; k < this.appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; k++)
- // {
- // this.appWorkspace.DocumentWorkspaces[i].GraphicsList[k].change = false;
- // }
- // }
- //}
- }
- }
- private void LabelListDialog_FormClosed(object sender, FormClosedEventArgs e)
- {
- drawLabelList = null;
- }
- /// <summary>
- /// 选中单元格后 画布对应标注图形也选中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex == 0 && e.RowIndex >= 0)
- {
- var senderGrid = (DataGridView)sender;
- var selectedCells = senderGrid.SelectedCells;
- if (selectedCells.Count > 0)
- {
- DrawObject dObject;
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- for (int i = 0; i < selectedCells.Count; i++)
- {
- dObject = (DrawObject)senderGrid.SelectedCells[i].Tag;
- if (!dObject.isLocked) {
- dObject.Selected = true;
- }
- }
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- private void LabelListDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- appWorkspace.Widgets.LabelListDialog.Visible = false;
- this.appWorkspace.toolBar.RefreshBtnSelect(false, "LabelListAction");
- this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "LabelListAction");
- }
- #region [新增方法]
- /// <summary>
- /// 读取xml数据
- /// </summary>
- private void readLabelListXml()
- {
- if (!System.IO.File.Exists(filePath))
- {
- labelListModel = new LabelListModel();
- LabelData labelData = new LabelData();
- string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
- FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace == null) {
- return;
- }
- // 默认存到Default中
- if (comboBox1.SelectedIndex == 0)
- {
- button5_Click(null, null);
- }
- else
- {
- if (labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList == null)
- {
- labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList = new List<LabelDataDetails>();
- }
- labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Clear();
- foreach (var item in drawLabelList)
- {
- LabelDataDetails dataDetails = new LabelDataDetails();
- LabelMeasureDataModel labelData = new LabelMeasureDataModel();
- labelData.drawClass = "Label";
- labelData.drawToolType = item.drawToolType.ToString();
- labelData.points = item.GetPoints();
- labelData.style = item.GetStyle();
- labelData.content = item.GetContent();
- dataDetails.drawObject = labelData;
- dataDetails.isLocked = false;
- labelListModel.labelDataList[comboBox1.SelectedIndex].labelDataDetailList.Add(dataDetails);
- }
- List<DrawObject> list = new List<DrawObject>();
- list.AddRange(this.drawLabelList);
- if (everyDataDict.ContainsKey(comboBox1.SelectedIndex))
- {
- everyDataDict[comboBox1.SelectedIndex] = list;
- }
- else {
- everyDataDict.Add(comboBox1.SelectedIndex, list);
- }
- }
- string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
- FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (comboBox1.SelectedIndex == 0)
- {
- MessageBox.Show("当前选项不可删除!");
- return;
- }
- DialogResult dr = MessageBox.Show("您确定要删除当前标注信息吗?", PdnResources.GetString("Form.OkButton.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr != DialogResult.OK)
- {
- return;
- }
- int index = comboBox1.SelectedIndex;
- comboBox1.Items.RemoveAt(index);
- labelListModel.labelDataList.RemoveAt(index - 1);
- everyDataDict.Remove(index - 1);
- comboBox1.SelectedIndex = 0;
- string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
- FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 另存为
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (this.appWorkspace.ActiveDocumentWorkspace == null)
- {
- return;
- }
- //調用委托
- LabelListChangeName form = new LabelListChangeName();
- //调用子窗体中的委托,将方法给委托
- form.TransferEvent += frm_TransEvent;
- form.ShowDialog();
- }
- /// <summary>
- /// 委托
- /// </summary>
- /// <param name="jianyanxiangmuName"></param>
- /// <param name="guige1"></param>
- /// <param name="guige2"></param>
- /// <param name="isEdit"></param>
- private void frm_TransEvent(string name)
- {
- comboBox1.Items.Add(name);
- LabelData data = new LabelData();
- data.name = name;
- data.labelDataDetailList = new List<LabelDataDetails>();
- foreach (var item in drawLabelList)
- {
- LabelDataDetails dataDetails = new LabelDataDetails();
- LabelMeasureDataModel labelData = new LabelMeasureDataModel();
- labelData.drawClass = "Label";
- labelData.drawToolType = item.drawToolType.ToString();
- labelData.points = item.GetPoints();
- labelData.style = item.GetStyle();
- labelData.content = item.GetContent();
- dataDetails.drawObject = labelData;
- dataDetails.isLocked = false;
- data.labelDataDetailList.Add(dataDetails);
- }
- labelListModel.labelDataList.Add(data);
- List<DrawObject> list = new List<DrawObject>();
- foreach (var item in this.drawLabelList) {
- list.Add(item.Clone());
- }
- everyDataDict.Add(labelListModel.labelDataList.Count - 1, list);
- string xml = XmlSerializeHelper.XmlSerialize(labelListModel);
- FileOperationHelper.WriteStringToFile(xml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 切换xml文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.dataGridView1.Rows.Clear();
- if (comboBox1.SelectedIndex == 0)
- {
- RefreshDateGridView(null,null);
- }
- else {
- this.drawLabelList.Clear();
- var labelData = labelListModel.labelDataList[comboBox1.SelectedIndex - 1];
- bool hasDraw = this.hasDrawList.Contains(labelData.name);
- if (!hasDraw)
- {
- this.hasDrawList.Add(labelData.name);
- }
- List<DrawObject> list;
- everyDataDict.TryGetValue(comboBox1.SelectedIndex - 1, out list);
- if (list == null) {
- list = new List<DrawObject>();
- }
- this.drawLabelList.AddRange(list);
- if (drawLabelList.Count > 0)
- {
- for (int j = 0; j < drawLabelList.Count; j++)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(PdnResources.GetString("Menu.LabelAction." + drawLabelList[j].drawToolType + ".Text"), drawLabelList[j]));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.upward.Text"), 1));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.down.Text"), 2));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Onthemost.Text"), 3));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Underthemost.Text"), 4));
- row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Imagement.Measurementlist.Attributes.text"), 5));
- row.Cells.Add(CreateButtonCell("锁定", 6, drawLabelList[j].isLocked));
- this.dataGridView1.Rows.Add(row);
- if (!hasDraw) {
- this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add(drawLabelList[j]);
- }
- }
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- this.dataGridView1.ClearSelection();//默认会选中第一行的第一个单元格,只能绑完数据再清
- for (int k = 0; k < this.dataGridView1.Rows.Count; k++)
- {
- DrawObject dd = (DrawObject)this.dataGridView1.Rows[k].Cells[0].Tag;
- if (dd.Selected)
- {
- this.dataGridView1.Rows[k].Cells[0].Selected = true;
- }
- }
- }
- }
- }
- /// <summary>
- /// 锁定数据
- /// </summary>
- /// <param name="index"></param>
- private void lockData(int index)
- {
- var drawObject = drawLabelList[index];
- drawObject.isLocked = !drawObject.isLocked;
- if (drawObject.isLocked)
- {
- this.dataGridView1.Rows[index].Cells[6].Style.BackColor = System.Drawing.Color.Red;
- }
- else {
- this.dataGridView1.Rows[index].Cells[6].Style.BackColor = DataGridView.DefaultBackColor;
- }
- this.dataGridView1.Rows[index].Cells[6].Selected = false;
- this.dataGridView1.Rows[index].Cells[0].Selected = true;
- }
- public void getData()
- {
- everyDataDict.Clear();
- comboBox1.Items.Clear();
- comboBox1.Items.Add("当前");
- if (this.appWorkspace.ActiveDocumentWorkspace == null)
- {
- return;
- }
- labelListModel = XmlSerializeHelper.DESerializer<LabelListModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
- if (labelListModel.labelDataList.Count > 0)
- {
- foreach (var item in labelListModel.labelDataList)
- {
- var index = labelListModel.labelDataList.IndexOf(item);
- List<DrawObject> list = new List<DrawObject>();
- foreach (var drawObject in item.labelDataDetailList)
- {
- string className = InvariantData.path_Label + "." + drawObject.drawObject.drawToolType;
- object[] parameters = new object[4];
- parameters[0] = this.appWorkspace.ActiveDocumentWorkspace;
- parameters[1] = drawObject.drawObject.points;
- parameters[2] = drawObject.drawObject.style;
- parameters[3] = drawObject.drawObject.content;
- object obj = Activator.CreateInstance(Type.GetType(className + "," + InvariantData.assembly_Annotation), parameters);
- list.Add(((DrawObject)obj));
- //this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.Add((DrawObject)obj);
- }
- if (everyDataDict.ContainsKey(index)) {
- everyDataDict[index] = list;
- } else {
- everyDataDict.Add(index, list);
- }
- comboBox1.Items.Add(item.name);
- }
- }
- comboBox1.SelectedIndex = 0;
- }
- #endregion
- }
- }
|