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 { /// /// 标注列表 /// 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 drawLabelList;//标注的list private string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\LabelListModel.xml"; private LabelListModel labelListModel; private List hasDrawList = new List(); private Dictionary> everyDataDict = new Dictionary>(); 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 } /// /// /// /// /// public void resetData(object sender, EventArgs e) { this.hasDrawList.Clear(); comboBox1.SelectedIndex = 0; } /// /// 刷新列表数据 /// /// /// 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(); 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) { } /// /// 清除全部 /// /// /// 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(); } } /// /// 应用全部 /// /// /// 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; } /// /// 选中单元格后 画布对应标注图形也选中 /// /// /// 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 [新增方法] /// /// 读取xml数据 /// 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); } } /// /// 保存 /// /// /// 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(); } 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 list = new List(); 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); } /// /// 删除 /// /// /// 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); } /// /// 另存为 /// /// /// private void button5_Click(object sender, EventArgs e) { if (this.appWorkspace.ActiveDocumentWorkspace == null) { return; } //調用委托 LabelListChangeName form = new LabelListChangeName(); //调用子窗体中的委托,将方法给委托 form.TransferEvent += frm_TransEvent; form.ShowDialog(); } /// /// 委托 /// /// /// /// /// private void frm_TransEvent(string name) { comboBox1.Items.Add(name); LabelData data = new LabelData(); data.name = name; data.labelDataDetailList = new List(); 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 list = new List(); 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); } /// /// 切换xml文件 /// /// /// 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 list; everyDataDict.TryGetValue(comboBox1.SelectedIndex - 1, out list); if (list == null) { list = new List(); } 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; } } } } } /// /// 锁定数据 /// /// 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(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); if (labelListModel.labelDataList.Count > 0) { foreach (var item in labelListModel.labelDataList) { var index = labelListModel.labelDataList.IndexOf(item); List list = new List(); 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 } }