123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116 |
- 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
- {
- /// <summary>
- /// 主配置,包含了选定的标尺的配置
- /// </summary>
- private ConfigModel configModel = Startup.instance.configModel;
- /// <summary>
- /// 选定的标尺在listview的items内的下标
- /// </summary>
- private int index = -1;
- /// <summary>
- /// 初始化下拉标记
- /// </summary>
- private bool initComboBox = false;
- /// <summary>
- /// 工作控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 临时数据-理论比例尺
- /// </summary>
- public static ListViewItem viewItem;
- /// <summary>
- /// 临时标尺-任意标尺和推算标尺
- /// </summary>
- public static List<ListViewItem> viewItemList = new List<ListViewItem>();
- #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;
- }
- /// <summary>
- /// 初始化单位下拉
- /// </summary>
- 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;
- **/
- }
- /// <summary>
- /// 初始化标尺列头
- /// </summary>
- 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);
- }
- /// <summary>
- /// 初始化标尺列表
- /// </summary>
- public void InitListViewData()
- {
- this.listView1.Items.Clear();
- List<mic_rulers> 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);
- }
- /// <summary>
- /// listView1 ItemSelectionChanged事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- }
- /// <summary>
- /// 新增标尺
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, System.EventArgs e)
- {
- RuleAddForm ruleAddForm = new RuleAddForm(1, appWorkspace);
- ruleAddForm.StartPosition = FormStartPosition.CenterScreen;
- ruleAddForm.ShowDialog();
- }
- /// <summary>
- /// 修改标尺
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<RulerFileModel>(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"));
- }
- }
- /// <summary>
- /// 删除标尺,当前激活的标尺不允许删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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]);
- }
- /// <summary>
- /// 设置当前选中标尺
- /// </summary>
- /// <param name="index"></param>
- 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();
- }
- }
- /// <summary>
- /// 刷新当前选中的标尺-编辑后使用
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 激活当前选中标尺
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- this.button5ActionImply(-1);
- }
- /// <summary>
- /// 激活当前选中标尺
- /// </summary>
- /// <param name="activeRulerIndex">通过自定义菜单设置当前选中标尺时,index不等于-1,用于解决窗口未初始化时标尺无法激活的问题</param>
- 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>(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>(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>(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();
- }
- /// <summary>
- /// 自定义标尺
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, null, 1);
- customRulerDialog.StartPosition = FormStartPosition.CenterScreen;
- customRulerDialog.ShowDialog();
- }
- /// <summary>
- /// 刷新
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- InitListViewData();
- }
- /// <summary>
- /// 激活临时标尺
- /// </summary>
- public void ActivateTemporaryRuler()
- {
- if (viewItem != null && !viewItem.Equals(""))
- {
- //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
- Startup.instance.rules.Clear();
- //重置已激活的标尺,不知道对不对
- configModel.RulerId = 0;
- string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(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 = "√";
- }
- }
- /// <summary>
- /// 单位下拉的SelectIndexChange事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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>(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() {
- }
- /// <summary>
- /// 双击激活标尺
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 应用到当前图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 系统激活应用当前
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 系统激活应用全部
- /// </summary>
- 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();
- }
- }
- }
|