using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Windows.Forms; using PaintDotNet.ImageCollect; namespace PaintDotNet.Measuring { internal class RuleListForm : FloatingToolForm { /// /// 主配置,包含了选定的标尺的配置 /// private ConfigModel configModel = Startup.instance.configModel; /// /// 选定的标尺在listview的items内的下标 /// private int index = -1; /// /// 初始化下拉标记 /// private bool initComboBox = false; /// /// 工作控件 /// private AppWorkspace appWorkspace; /// /// 临时数据-理论比例尺 /// public static ListViewItem viewItem; /// /// 临时标尺-任意标尺和推算标尺 /// public static List viewItemList = new List(); #region 控件 private ComboBox comboBox1; private Button button1; private Button button3; private Button button4; private Button button5; private Button button6; private Button button7; private ListView listView1; public Button button2; public Button button8; private ToolTip toolTip1; #endregion public RuleListForm(AppWorkspace appWorkspace) { this.appWorkspace = appWorkspace; InitializeComponent(); InitializeButtonBackgroudImage(); InitializeToolTip(); this.Text = PdnResources.GetString("Menu.MeasureAction.RulerCalibration.Text"); this.MinimizeBox = true; this.MinimumSize = this.Size; InitUnitData(); InitListViewHeader(); InitListViewData(); } private void InitializeToolTip() { this.toolTip1 = new ToolTip(); this.toolTip1.SetToolTip(this.button1, PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text")); this.toolTip1.SetToolTip(this.button4, PdnResources.GetString("Menu.Modifytheruler.text")); this.toolTip1.SetToolTip(this.button3, PdnResources.GetString("Menu.Imagement.Rulersetting.Deleteruler.text")); this.toolTip1.SetToolTip(this.button5, PdnResources.GetString("Menu.Imagement.Rulersetting.activetheruler.text")); this.toolTip1.SetToolTip(this.button2, PdnResources.GetString("Menu.Imagement.Rulersetting.current.text")); this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Applytoall.text")); this.toolTip1.SetToolTip(this.button6, PdnResources.GetString("Menu.user-definedruler.text")); this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.Refresh.text")); this.toolTip1.ShowAlways = true; } private void InitializeButtonBackgroudImage() { this.button1.FlatStyle = FlatStyle.Flat; this.button1.FlatAppearance.BorderSize = 0; this.button1.BackgroundImageLayout = ImageLayout.Center; this.button1.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference; this.button4.FlatStyle = FlatStyle.Flat; this.button4.FlatAppearance.BorderSize = 0; this.button4.BackgroundImageLayout = ImageLayout.Center; this.button4.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference; this.button3.FlatStyle = FlatStyle.Flat; this.button3.FlatAppearance.BorderSize = 0; this.button3.BackgroundImageLayout = ImageLayout.Center; this.button3.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference; this.button5.FlatStyle = FlatStyle.Flat; this.button5.FlatAppearance.BorderSize = 0; this.button5.BackgroundImageLayout = ImageLayout.Center; this.button5.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListActivationIcon.png").Reference; this.button6.FlatStyle = FlatStyle.Flat; this.button6.FlatAppearance.BorderSize = 0; this.button6.BackgroundImageLayout = ImageLayout.Center; this.button6.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListCustomizeIcon.png").Reference; this.button7.FlatStyle = FlatStyle.Flat; this.button7.FlatAppearance.BorderSize = 0; this.button7.BackgroundImageLayout = ImageLayout.Center; this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListRefureshIcon.png").Reference; this.button2.FlatStyle = FlatStyle.Flat; this.button2.FlatAppearance.BorderSize = 0; this.button2.BackgroundImageLayout = ImageLayout.Center; this.button2.BackgroundImage = PdnResources.GetImageResource("Icons.MenuNow.png").Reference; this.button8.FlatStyle = FlatStyle.Flat; this.button8.FlatAppearance.BorderSize = 0; this.button8.BackgroundImageLayout = ImageLayout.Center; this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.MenuAll.png").Reference; } /// /// 初始化单位下拉 /// private void InitUnitData() { //单位选择 this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null); this.comboBox1.DisplayMember = "Value"; this.comboBox1.ValueMember = "Key"; if (configModel != null/* && configModel.Unit < comboBox1.Items.Count && configModel.Unit >= 0*/) {//1013###19355 try { this.comboBox1.SelectedValue = configModel.Unit; } catch (Exception) { this.comboBox1.SelectedIndex = 3; } } else this.comboBox1.SelectedIndex = 3; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); //此操作,移除第一个(像素),如果确定不需要像素了,再把代码删除 /** object ds = this.comboBox1.DataSource; this.comboBox1.DataSource = null; IList items = null; //ListBox/ComboBox 的 Items 是 IList 类型或数组,而数组也实现了 IList 接口 IList lst = ds as IList; for (int i = 1; i < lst.Count; i++) { items.Add(lst[i]); } this.comboBox1.DataSource = items; **/ } /// /// 初始化标尺列头 /// private void InitListViewHeader() { this.listView1.View = View.Details; ColumnHeader header0 = new ColumnHeader(); header0.Text = ""; header0.Width = 25; this.listView1.Columns.Add(header0); ColumnHeader header = new ColumnHeader(); header.Text = PdnResources.GetString("Menu.Rulername.text"); header.Width = 100; this.listView1.Columns.Add(header); ColumnHeader header1 = new ColumnHeader(); header1.Text = PdnResources.GetString("Menu.unit.text") + "/" + PdnResources.GetString("MeasurementUnit.Pixel"); header1.Width = 70; this.listView1.Columns.Add(header1); ColumnHeader header2 = new ColumnHeader(); header2.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text"); this.listView1.Columns.Add(header2); ColumnHeader header3 = new ColumnHeader(); header3.Text = PdnResources.GetString("Menu.Pixellength.text"); this.listView1.Columns.Add(header3); ColumnHeader header4 = new ColumnHeader(); header4.Text = PdnResources.GetString("Menu.Physicallength.text"); this.listView1.Columns.Add(header4); ColumnHeader header5 = new ColumnHeader(); header5.Text = PdnResources.GetString("Menu.Unitsofmeasurement.text"); this.listView1.Columns.Add(header5); ColumnHeader header6 = new ColumnHeader(); header6.Text = PdnResources.GetString("Menu.ImageResolution.text"); this.listView1.Columns.Add(header6); ColumnHeader header7 = new ColumnHeader(); header7.Text = PdnResources.GetString("Menu.magnificationchanger.text"); this.listView1.Columns.Add(header7); ColumnHeader header8 = new ColumnHeader(); header8.Text = PdnResources.GetString("Menu.interface.text"); this.listView1.Columns.Add(header8); ColumnHeader header9 = new ColumnHeader(); header9.Text = PdnResources.GetString("Menu.oculars.text"); this.listView1.Columns.Add(header9); ColumnHeader header10 = new ColumnHeader(); header10.Text = PdnResources.GetString("Menu.thecamera.text"); this.listView1.Columns.Add(header10); ColumnHeader header11 = new ColumnHeader(); header11.Text = PdnResources.GetString("Menu.Objectlens.text"); this.listView1.Columns.Add(header11); ColumnHeader header12 = new ColumnHeader(); header12.Text = PdnResources.GetString("Menu.microscope.text"); this.listView1.Columns.Add(header12); } /// /// 初始化标尺列表 /// public void InitListViewData() { this.listView1.Items.Clear(); List list = Startup.instance.mic_rulersAll; if (list != null) { for (int i = 0; i < list.Count; i++) { mic_rulers rule = list[i]; ListViewItem item = new ListViewItem(); item.Tag = rule; item.Text = ""; if (configModel != null) { if (configModel.RulerId == rule.id) { index = i; item.Text = "√"; } } //计算每像素物理长度 double proportion = Math.Round((double)rule.physical_length / rule.pixel_length, 4); string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel"); item.SubItems.Add(rule.ruler_name); item.SubItems.Add(content); item.SubItems.Add(rule.gain_multiple.ToString()); item.SubItems.Add(rule.pixel_length.ToString()); item.SubItems.Add(rule.physical_length.ToString()); item.SubItems.Add(InvariantData.ruleUnitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString()); item.SubItems.Add(rule.ruler_width + "*" + rule.ruler_height); item.SubItems.Add(rule.ruler_zoom); item.SubItems.Add(rule.ruler_connector); item.SubItems.Add(rule.ruler_eyepiece); item.SubItems.Add(rule.ruler_camera); item.SubItems.Add(rule.objective_lens); item.SubItems.Add(rule.microscope); this.listView1.Items.Add(item); } } if (viewItem != null) { //刷新不清掉选中状态会进入切换选中事件然后报错 viewItem.Selected = false; viewItem.ForeColor = Color.Black; viewItem.BackColor = Color.White; Font f = new Font(Control.DefaultFont, FontStyle.Regular); viewItem.Font = f; //this.listView1.Items.Add(viewItem); } if (viewItemList != null && viewItemList.Count > 0) { foreach (ListViewItem item in viewItemList) { //刷新不清掉选中状态会进入切换选中事件然后报错 item.Selected = false; item.ForeColor = Color.Black; item.BackColor = Color.White; Font f = new Font(Control.DefaultFont, FontStyle.Regular); item.Font = f; this.listView1.Items.Add(item); } } this.appWorkspace.ToolBar.refreshRulersComboBoxList(); } private void InitializeComponent() { this.listView1 = new System.Windows.Forms.ListView(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.button1 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // listView1 // this.listView1.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.listView1.FullRowSelect = true; this.listView1.HideSelection = false; this.listView1.Location = new System.Drawing.Point(12, 40); this.listView1.MultiSelect = false; this.listView1.Name = "listView1"; this.listView1.ShowItemToolTips = true; this.listView1.Size = new System.Drawing.Size(267, 191); this.listView1.TabIndex = 1; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listView1_ItemSelectionChanged); this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick); // // comboBox1 // this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(175, 238); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(104, 20); this.comboBox1.TabIndex = 2; // // button1 // this.button1.Location = new System.Drawing.Point(11, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(29, 23); this.button1.TabIndex = 3; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button3 // this.button3.Location = new System.Drawing.Point(75, 12); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(29, 23); this.button3.TabIndex = 5; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Location = new System.Drawing.Point(43, 12); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(29, 23); this.button4.TabIndex = 6; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button5 // this.button5.Location = new System.Drawing.Point(106, 12); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(29, 23); this.button5.TabIndex = 7; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button6 // this.button6.Location = new System.Drawing.Point(202, 12); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(29, 23); this.button6.TabIndex = 8; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // button7 // this.button7.Location = new System.Drawing.Point(234, 12); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(29, 23); this.button7.TabIndex = 9; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // button2 // this.button2.Location = new System.Drawing.Point(138, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(29, 23); this.button2.TabIndex = 10; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button8 // this.button8.Location = new System.Drawing.Point(170, 12); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(29, 23); this.button8.TabIndex = 11; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // RuleListForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(291, 270); this.Controls.Add(this.button8); this.Controls.Add(this.button2); this.Controls.Add(this.button7); this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button1); this.Controls.Add(this.comboBox1); this.Controls.Add(this.listView1); this.Location = new System.Drawing.Point(0, 0); this.Name = "RuleListForm"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RuleListForm_FormClosing); this.Controls.SetChildIndex(this.listView1, 0); this.Controls.SetChildIndex(this.comboBox1, 0); this.Controls.SetChildIndex(this.button1, 0); this.Controls.SetChildIndex(this.button3, 0); this.Controls.SetChildIndex(this.button4, 0); this.Controls.SetChildIndex(this.button5, 0); this.Controls.SetChildIndex(this.button6, 0); this.Controls.SetChildIndex(this.button7, 0); this.Controls.SetChildIndex(this.button2, 0); this.Controls.SetChildIndex(this.button8, 0); this.ResumeLayout(false); } /// /// listView1 ItemSelectionChanged事件 /// /// /// private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { listView1.FullRowSelect = true; if (this.listView1.SelectedItems.Count > 0) { listView1.SelectedItems[0].SubItems[0].ForeColor = Color.Blue; //先清除原有格式                 foreach (ListViewItem item in listView1.Items) { //去掉所有对号 //item.Text = ""; item.ForeColor = Color.Black; } foreach (ListViewItem item in listView1.Items) { item.BackColor = Color.White; Font f = new Font(Control.DefaultFont, FontStyle.Regular); item.Font = f; } //打上对号 //listView1.SelectedItems[0].Text = "√";                 //加粗字体                 Font f2 = new Font(Control.DefaultFont, FontStyle.Bold); listView1.SelectedItems[0].SubItems[0].Font = f2;                 //设置选中行背景颜色                 listView1.SelectedItems[0].BackColor = Color.LightBlue; if (!listView1.SelectedItems[0].Selected) listView1.SelectedItems[0].Selected = true; index = e.ItemIndex; } } /// /// 新增标尺 /// /// /// private void button1_Click(object sender, System.EventArgs e) { RuleAddForm ruleAddForm = new RuleAddForm(1, appWorkspace); ruleAddForm.StartPosition = FormStartPosition.CenterScreen; ruleAddForm.ShowDialog(); } /// /// 修改标尺 /// /// /// private void button4_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) { if (((mic_rulers)this.listView1.SelectedItems[0].Tag).id > 0/*"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)*/) { mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; if (mic_Rulers.ruler_type == 1) { int id = mic_Rulers.id; RuleAddForm ruleAddForm = new RuleAddForm(2, appWorkspace); //ruleAddForm.ruleModel = mic_rulers_BLL.FindDefault(id); ruleAddForm.ruleModel = mic_Rulers; if (System.IO.File.Exists(Application.StartupPath + "\\RuleFile\\" + id + ".xml")) ruleAddForm.ruleFileModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\RuleFile\\" + id + ".xml", FileMode.Open)); else ruleAddForm.ruleFileModel = new RulerFileModel(); ruleAddForm.StartPosition = FormStartPosition.CenterScreen; ruleAddForm.InitializeEditData(); ruleAddForm.ShowDialog(); } else { CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, mic_Rulers, 2); customRulerDialog.StartPosition = FormStartPosition.CenterScreen; customRulerDialog.ShowDialog(); } } else { //if ("temporary".Equals(this.listView1.SelectedItems[0].Tag) || "temporaryList".Equals(this.listView1.SelectedItems[0].Tag)) //{ MessageBox.Show(PdnResources.GetString("Menu.Temporaryrulercannotbemodified.Text") + "!", PdnResources.GetString("Menu.hint.text")); //} } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text")); } } /// /// 删除标尺,当前激活的标尺不允许删除 /// /// /// private void button3_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) { if (!"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)) { mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; int id = mic_Rulers.id; if (id == configModel.RulerId) { MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text")); return; } else { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { //删除数据库文件 mic_rulers_BLL.Del(id); DelRule(id); //删除标尺xml文件 string filePath = Application.StartupPath + "\\RuleFile\\" + id + ".xml"; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } } } else { if (this.listView1.SelectedItems[0].Text == "√") { MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text")); return; } //理论比例尺 if ("temporary".Equals(this.listView1.SelectedItems[0].Tag)) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { this.listView1.SelectedItems[0].Remove(); viewItem.SubItems.Clear(); viewItem = null; } } //临时标尺 else if ("temporaryList".Equals(this.listView1.SelectedItems[0].Tag)) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { ListViewItem selectedItem = this.listView1.SelectedItems[0]; if (viewItemList != null && viewItemList.Count > 0) { for (int i = 0; i < viewItemList.Count; i++) { if (viewItemList[i].Equals(selectedItem)) { viewItemList.Remove(viewItemList[i]); } } } } } } InitListViewData(); //刷新预览窗口 if (CameraPreviewDialog.cameraPreviewDialog != null) CameraPreviewDialog.cameraPreviewDialog.BindingRule(); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text")); } } public void DelRule(int id) { int index = 0; for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++) { if (Startup.instance.mic_rulersAll[i].id == id) { index = i; } } Startup.instance.mic_rulersAll.Remove(Startup.instance.mic_rulersAll[index]); } /// /// 设置当前选中标尺 /// /// public void SetActiveRulerIndex(int selectIndex) { //判断选中索引是否是激活的索引 bool SelectIndex = false; for (int i = 0; i < this.listView1.Items.Count; i++) { if (((mic_rulers)this.listView1.Items[i].Tag).id == Startup.instance.configModel.RulerId) { if (selectIndex == i ) SelectIndex = true; break; } } if (selectIndex < this.listView1.Items.Count && (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0 || !SelectIndex)) { this.listView1.Items[selectIndex].Selected = true; this.button5ActionImply(selectIndex); //this.button5.PerformClick(); } } /// /// 刷新当前选中的标尺-编辑后使用 /// public void RefreshActiveRuler() { ListViewItem selectedItem = null; foreach (ListViewItem item in this.listView1.Items) { if (item.Text == "√") { selectedItem = item; break; } } if (selectedItem != null) { //只有普通标尺可编辑 if (!"temporary".Equals(selectedItem.Tag) && !"temporaryList".Equals(selectedItem.Tag)) { if (configModel.RulerId != 0) { //调用startup的方法 Startup.instance.InitRulerInfo(); Startup.instance.InitUnitInfo(); //this.appWorkspace.ToolBar.refreshRulersComboBox(); initComboBox = true;//1019###19594 } } if (this.appWorkspace.ActiveDocumentWorkspace != null) { this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(this.comboBox1.SelectedIndex + 1)); this.appWorkspace.UpdateDocInfoInStatusBar(); } this.appWorkspace.ToolBar.refreshRulersComboBoxActive(); } } /// /// 激活当前选中标尺 /// /// /// private void button5_Click(object sender, EventArgs e) { this.button5ActionImply(-1); } /// /// 激活当前选中标尺 /// /// 通过自定义菜单设置当前选中标尺时,index不等于-1,用于解决窗口未初始化时标尺无法激活的问题 private void button5ActionImply(int activeRulerIndex) { if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1 || activeRulerIndex > -1) { bool existSelectedItem = (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1); if (existSelectedItem && this.listView1.SelectedItems[0].Text == "√" || !existSelectedItem && this.listView1.Items[activeRulerIndex].Text == "√") { MessageBox.Show(PdnResources.GetString("Menu.Currentlyselectedruleractive.Text")); return; } mic_rulers mic_Rulers; if (existSelectedItem) mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; else mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag; int id = mic_Rulers.id; if (id != configModel.RulerId) { int oldId = configModel.RulerId; //激活当前标尺到configModel configModel.RulerId = id; //保存xml文件 string configXml = XmlSerializeHelper.XmlSerialize(configModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) { //调用startup的方法 Startup.instance.InitRulerInfo(); Startup.instance.InitUnitInfo(); //处理当前的listview if (index >= 0) { this.listView1.Items[index].Text = ""; } foreach (ListViewItem item in listView1.Items) { //去掉所有对号 item.Text = ""; } if (existSelectedItem) this.listView1.SelectedItems[0].Text = "√"; else this.listView1.Items[activeRulerIndex].Text = "√"; this.listView1.Refresh(); this.appWorkspace.ToolBar.refreshRulersComboBoxActive(); if (CameraPreviewDialog.cameraPreviewDialog != null) CameraPreviewDialog.cameraPreviewDialog.BindingRule(); initComboBox = true;//1019###19594 } else { configModel.RulerId = oldId; MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text")); } } //普通标尺 //if (existSelectedItem && !"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag) // || !existSelectedItem && !"temporary".Equals(this.listView1.Items[activeRulerIndex].Tag) && !"temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag)) //{ //mic_rulers mic_Rulers; // if (existSelectedItem) // mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; // else // mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag; // int id = mic_Rulers.id; // if (id != configModel.RulerId) // { // int oldId = configModel.RulerId; // //激活当前标尺到configModel // configModel.RulerId = id; // //保存xml文件 // string configXml = XmlSerializeHelper.XmlSerialize(configModel); // string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; // if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) // { // //调用startup的方法 // Startup.instance.InitRulerInfo(); // Startup.instance.InitUnitInfo(); // //处理当前的listview // if (index >= 0) // { // this.listView1.Items[index].Text = ""; // } // foreach (ListViewItem item in listView1.Items) // { // //去掉所有对号 // item.Text = ""; // } // if (existSelectedItem) // this.listView1.SelectedItems[0].Text = "√"; // else // this.listView1.Items[activeRulerIndex].Text = "√"; // this.listView1.Refresh(); // this.appWorkspace.ToolBar.refreshRulersComboBoxActive(); // if (CameraPreviewDialog.cameraPreviewDialog != null) // CameraPreviewDialog.cameraPreviewDialog.BindingRule(); // initComboBox = true;//1019###19594 // } // else // { // configModel.RulerId = oldId; // MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text")); // } // } //} ////理论比例尺 //else if (existSelectedItem && "temporary".Equals(this.listView1.SelectedItems[0].Tag) // || !existSelectedItem && "temporary".Equals(this.listView1.Items[activeRulerIndex].Tag)) //{ // this.ActivateTemporaryRuler(); //} ////临时标尺 //else if (existSelectedItem && "temporaryList".Equals(this.listView1.SelectedItems[0].Tag) // || !existSelectedItem && "temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag)) //{ // ListViewItem selectedItem; // if (existSelectedItem) // selectedItem = this.listView1.SelectedItems[0]; // else // selectedItem = this.listView1.Items[activeRulerIndex]; // if (viewItemList != null && viewItemList.Count > 0) // { // for (int i = 0; i < viewItemList.Count; i++) // { // if (viewItemList[i].Equals(selectedItem)) // { // //计算单位长度 比如0.05英寸/像素; 100纳米/像素; // Startup.instance.rules.Clear(); // //重置已激活的标尺,不知道对不对 // configModel.RulerId = 0; // string configXml = XmlSerializeHelper.XmlSerialize(configModel); // string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; // FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create); // Startup.instance.measurementUnit = MeasurementUnit.Micron; // double unitLength = (Convert.ToDouble(viewItemList[i].SubItems[4].Text) / Convert.ToDouble(viewItemList[i].SubItems[3].Text)); // Startup.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸 // Startup.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米 // Startup.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米 // Startup.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米 // Startup.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米 // foreach (ListViewItem item in listView1.Items) // { // //去掉所有对号 // item.Text = ""; // } // viewItemList[i].Text = "√"; // break; // } // } // } //} //else //{ //} } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text")); } //刷新预览窗口的 if (this.appWorkspace != null) { if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed) { this.appWorkspace.cameraPreviewDialog.documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); } } this.appWorkspace.UpdateDocInfoInStatusBar(); } /// /// 自定义标尺 /// /// /// private void button6_Click(object sender, EventArgs e) { CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, null, 1); customRulerDialog.StartPosition = FormStartPosition.CenterScreen; customRulerDialog.ShowDialog(); } /// /// 刷新 /// /// /// private void button7_Click(object sender, EventArgs e) { InitListViewData(); } /// /// 激活临时标尺 /// public void ActivateTemporaryRuler() { if (viewItem != null && !viewItem.Equals("")) { //计算单位长度 比如0.05英寸/像素; 100纳米/像素; Startup.instance.rules.Clear(); //重置已激活的标尺,不知道对不对 configModel.RulerId = 0; string configXml = XmlSerializeHelper.XmlSerialize(configModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create); Startup.instance.measurementUnit = MeasurementUnit.Micron; double unitLength = (Convert.ToDouble(viewItem.SubItems[4].Text) / Convert.ToDouble(viewItem.SubItems[3].Text)); Startup.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸 Startup.instance.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔 Startup.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米 Startup.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米 Startup.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米 Startup.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米 foreach (ListViewItem item in listView1.Items) { //去掉所有对号 item.Text = ""; } viewItem.Text = "√"; } } /// /// 单位下拉的SelectIndexChange事件 /// /// /// private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (initComboBox || configModel != null)//1019###19594 { int oldUint = configModel.Unit; //需要先改变配置内的单位 //configModel.Unit = (int)(((DictionaryEntry)(this.comboBox1.SelectedValue)).Key); configModel.Unit = (int)(this.comboBox1.SelectedValue); //保存xml文件 string configXml = XmlSerializeHelper.XmlSerialize(configModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) { //在调用初始化单位信息的方法 Startup.instance.InitUnitInfo(); this.appWorkspace.Units = (MeasurementUnit)configModel.Unit; this.appWorkspace.ViewConfigStrip_UnitsChanged(null, null); //循环刷新所有窗口 foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces) { documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); } //刷新预览窗口 if (this.appWorkspace != null) { if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed) { this.appWorkspace.cameraPreviewDialog.documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); } } this.appWorkspace.opticalDensityDialog.RefreshOpticalDensity(null, null); if (this.appWorkspace != null) { this.appWorkspace.RefreshListView(); this.appWorkspace.UpdateDocInfoInStatusBar(); } } else { configModel.Unit = oldUint; MessageBox.Show(PdnResources.GetString("Menu.Unitswitchfailed.Text")); } } initComboBox = true; } private void RefreshComboBox() { } /// /// 双击激活标尺 /// /// /// private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) { this.button5.PerformClick(); } private void RuleListForm_FormClosing(object sender, FormClosingEventArgs e) { this.appWorkspace.toolBar.RefreshBtnSelect(false, "SubRulerCalibration"); this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "SubRulerCalibration"); } //应用到全部图片 private void button8_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text")); return; } mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; //循环刷新所有窗口 foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces) { documentWorkspace.xmlSaveModel = mic_Rulers; documentWorkspace.InitRulerInfo(); //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); } foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces) { documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); documentWorkspace.Units = Startup.instance.measurementUnit; } this.appWorkspace.UpdateDocInfoInStatusBar(); this.appWorkspace.RefreshListView(); } /// /// 应用到当前图片 /// /// /// private void button2_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text")); return; } mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag; if (this.appWorkspace.ActiveDocumentWorkspace != null) { this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers; this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo(); this.appWorkspace.UpdateDocInfoInStatusBar(); this.appWorkspace.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit; this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); this.appWorkspace.RefreshListView(); } } /// /// 系统激活应用当前 /// public void MenuSubApplyCurrent() { mic_rulers mic_Rulers = Startup.instance.ruleDB; if (this.appWorkspace.ActiveDocumentWorkspace != null) { this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers; this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo(); this.appWorkspace.UpdateDocInfoInStatusBar(); this.appWorkspace.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit; this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); this.appWorkspace.RefreshListView(); } } /// /// 系统激活应用全部 /// public void MenuSubApplyAll() { mic_rulers mic_Rulers = Startup.instance.ruleDB; //循环刷新所有窗口 foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces) { documentWorkspace.xmlSaveModel = mic_Rulers; documentWorkspace.InitRulerInfo(); //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); } foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces) { documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue); documentWorkspace.Units = Startup.instance.measurementUnit; } this.appWorkspace.UpdateDocInfoInStatusBar(); this.appWorkspace.RefreshListView(); } } }