RuleListForm.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. using PaintDotNet.Base.SettingModel;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.DbOpreate.DbBll;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Windows.Forms;
  10. using PaintDotNet.ImageCollect;
  11. namespace PaintDotNet.Measuring
  12. {
  13. internal class RuleListForm : FloatingToolForm
  14. {
  15. /// <summary>
  16. /// 主配置,包含了选定的标尺的配置
  17. /// </summary>
  18. private ConfigModel configModel = Startup.instance.configModel;
  19. /// <summary>
  20. /// 选定的标尺在listview的items内的下标
  21. /// </summary>
  22. private int index = -1;
  23. /// <summary>
  24. /// 初始化下拉标记
  25. /// </summary>
  26. private bool initComboBox = false;
  27. /// <summary>
  28. /// 工作控件
  29. /// </summary>
  30. private AppWorkspace appWorkspace;
  31. /// <summary>
  32. /// 临时数据-理论比例尺
  33. /// </summary>
  34. public static ListViewItem viewItem;
  35. /// <summary>
  36. /// 临时标尺-任意标尺和推算标尺
  37. /// </summary>
  38. public static List<ListViewItem> viewItemList = new List<ListViewItem>();
  39. #region 控件
  40. private ComboBox comboBox1;
  41. private Button button1;
  42. private Button button3;
  43. private Button button4;
  44. private Button button5;
  45. private Button button6;
  46. private Button button7;
  47. private ListView listView1;
  48. public Button button2;
  49. public Button button8;
  50. private ToolTip toolTip1;
  51. #endregion
  52. public RuleListForm(AppWorkspace appWorkspace)
  53. {
  54. this.appWorkspace = appWorkspace;
  55. InitializeComponent();
  56. InitializeButtonBackgroudImage();
  57. InitializeToolTip();
  58. this.Text = PdnResources.GetString("Menu.MeasureAction.RulerCalibration.Text");
  59. this.MinimizeBox = true;
  60. this.MinimumSize = this.Size;
  61. InitUnitData();
  62. InitListViewHeader();
  63. InitListViewData();
  64. }
  65. private void InitializeToolTip()
  66. {
  67. this.toolTip1 = new ToolTip();
  68. this.toolTip1.SetToolTip(this.button1, PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text"));
  69. this.toolTip1.SetToolTip(this.button4, PdnResources.GetString("Menu.Modifytheruler.text"));
  70. this.toolTip1.SetToolTip(this.button3, PdnResources.GetString("Menu.Imagement.Rulersetting.Deleteruler.text"));
  71. this.toolTip1.SetToolTip(this.button5, PdnResources.GetString("Menu.Imagement.Rulersetting.activetheruler.text"));
  72. this.toolTip1.SetToolTip(this.button2, PdnResources.GetString("Menu.Imagement.Rulersetting.current.text"));
  73. this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Applytoall.text"));
  74. this.toolTip1.SetToolTip(this.button6, PdnResources.GetString("Menu.user-definedruler.text"));
  75. this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.Refresh.text"));
  76. this.toolTip1.ShowAlways = true;
  77. }
  78. private void InitializeButtonBackgroudImage()
  79. {
  80. this.button1.FlatStyle = FlatStyle.Flat;
  81. this.button1.FlatAppearance.BorderSize = 0;
  82. this.button1.BackgroundImageLayout = ImageLayout.Center;
  83. this.button1.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference;
  84. this.button4.FlatStyle = FlatStyle.Flat;
  85. this.button4.FlatAppearance.BorderSize = 0;
  86. this.button4.BackgroundImageLayout = ImageLayout.Center;
  87. this.button4.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference;
  88. this.button3.FlatStyle = FlatStyle.Flat;
  89. this.button3.FlatAppearance.BorderSize = 0;
  90. this.button3.BackgroundImageLayout = ImageLayout.Center;
  91. this.button3.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference;
  92. this.button5.FlatStyle = FlatStyle.Flat;
  93. this.button5.FlatAppearance.BorderSize = 0;
  94. this.button5.BackgroundImageLayout = ImageLayout.Center;
  95. this.button5.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListActivationIcon.png").Reference;
  96. this.button6.FlatStyle = FlatStyle.Flat;
  97. this.button6.FlatAppearance.BorderSize = 0;
  98. this.button6.BackgroundImageLayout = ImageLayout.Center;
  99. this.button6.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListCustomizeIcon.png").Reference;
  100. this.button7.FlatStyle = FlatStyle.Flat;
  101. this.button7.FlatAppearance.BorderSize = 0;
  102. this.button7.BackgroundImageLayout = ImageLayout.Center;
  103. this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListRefureshIcon.png").Reference;
  104. this.button2.FlatStyle = FlatStyle.Flat;
  105. this.button2.FlatAppearance.BorderSize = 0;
  106. this.button2.BackgroundImageLayout = ImageLayout.Center;
  107. this.button2.BackgroundImage = PdnResources.GetImageResource("Icons.MenuNow.png").Reference;
  108. this.button8.FlatStyle = FlatStyle.Flat;
  109. this.button8.FlatAppearance.BorderSize = 0;
  110. this.button8.BackgroundImageLayout = ImageLayout.Center;
  111. this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.MenuAll.png").Reference;
  112. }
  113. /// <summary>
  114. /// 初始化单位下拉
  115. /// </summary>
  116. private void InitUnitData()
  117. {
  118. //单位选择
  119. this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null);
  120. this.comboBox1.DisplayMember = "Value";
  121. this.comboBox1.ValueMember = "Key";
  122. if (configModel != null/* && configModel.Unit < comboBox1.Items.Count && configModel.Unit >= 0*/)
  123. {//1013###19355
  124. try
  125. {
  126. this.comboBox1.SelectedValue = configModel.Unit;
  127. }
  128. catch (Exception)
  129. {
  130. this.comboBox1.SelectedIndex = 3;
  131. }
  132. }
  133. else
  134. this.comboBox1.SelectedIndex = 3;
  135. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  136. //此操作,移除第一个(像素),如果确定不需要像素了,再把代码删除
  137. /**
  138. object ds = this.comboBox1.DataSource;
  139. this.comboBox1.DataSource = null;
  140. IList items = null;
  141. //ListBox/ComboBox 的 Items 是 IList 类型或数组,而数组也实现了 IList 接口
  142. IList lst = ds as IList;
  143. for (int i = 1; i < lst.Count; i++)
  144. {
  145. items.Add(lst[i]);
  146. }
  147. this.comboBox1.DataSource = items;
  148. **/
  149. }
  150. /// <summary>
  151. /// 初始化标尺列头
  152. /// </summary>
  153. private void InitListViewHeader()
  154. {
  155. this.listView1.View = View.Details;
  156. ColumnHeader header0 = new ColumnHeader();
  157. header0.Text = "";
  158. header0.Width = 25;
  159. this.listView1.Columns.Add(header0);
  160. ColumnHeader header = new ColumnHeader();
  161. header.Text = PdnResources.GetString("Menu.Rulername.text");
  162. header.Width = 100;
  163. this.listView1.Columns.Add(header);
  164. ColumnHeader header1 = new ColumnHeader();
  165. header1.Text = PdnResources.GetString("Menu.unit.text") + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  166. header1.Width = 70;
  167. this.listView1.Columns.Add(header1);
  168. ColumnHeader header2 = new ColumnHeader();
  169. header2.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text");
  170. this.listView1.Columns.Add(header2);
  171. ColumnHeader header3 = new ColumnHeader();
  172. header3.Text = PdnResources.GetString("Menu.Pixellength.text");
  173. this.listView1.Columns.Add(header3);
  174. ColumnHeader header4 = new ColumnHeader();
  175. header4.Text = PdnResources.GetString("Menu.Physicallength.text");
  176. this.listView1.Columns.Add(header4);
  177. ColumnHeader header5 = new ColumnHeader();
  178. header5.Text = PdnResources.GetString("Menu.Unitsofmeasurement.text");
  179. this.listView1.Columns.Add(header5);
  180. ColumnHeader header6 = new ColumnHeader();
  181. header6.Text = PdnResources.GetString("Menu.ImageResolution.text");
  182. this.listView1.Columns.Add(header6);
  183. ColumnHeader header7 = new ColumnHeader();
  184. header7.Text = PdnResources.GetString("Menu.magnificationchanger.text");
  185. this.listView1.Columns.Add(header7);
  186. ColumnHeader header8 = new ColumnHeader();
  187. header8.Text = PdnResources.GetString("Menu.interface.text");
  188. this.listView1.Columns.Add(header8);
  189. ColumnHeader header9 = new ColumnHeader();
  190. header9.Text = PdnResources.GetString("Menu.oculars.text");
  191. this.listView1.Columns.Add(header9);
  192. ColumnHeader header10 = new ColumnHeader();
  193. header10.Text = PdnResources.GetString("Menu.thecamera.text");
  194. this.listView1.Columns.Add(header10);
  195. ColumnHeader header11 = new ColumnHeader();
  196. header11.Text = PdnResources.GetString("Menu.Objectlens.text");
  197. this.listView1.Columns.Add(header11);
  198. ColumnHeader header12 = new ColumnHeader();
  199. header12.Text = PdnResources.GetString("Menu.microscope.text");
  200. this.listView1.Columns.Add(header12);
  201. }
  202. /// <summary>
  203. /// 初始化标尺列表
  204. /// </summary>
  205. public void InitListViewData()
  206. {
  207. this.listView1.Items.Clear();
  208. List<mic_rulers> list = Startup.instance.mic_rulersAll;
  209. if (list != null)
  210. {
  211. for (int i = 0; i < list.Count; i++)
  212. {
  213. mic_rulers rule = list[i];
  214. ListViewItem item = new ListViewItem();
  215. item.Tag = rule;
  216. item.Text = "";
  217. if (configModel != null)
  218. {
  219. if (configModel.RulerId == rule.id)
  220. {
  221. index = i;
  222. item.Text = "√";
  223. }
  224. }
  225. //计算每像素物理长度
  226. double proportion = Math.Round((double)rule.physical_length / rule.pixel_length, 4);
  227. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  228. item.SubItems.Add(rule.ruler_name);
  229. item.SubItems.Add(content);
  230. item.SubItems.Add(rule.gain_multiple.ToString());
  231. item.SubItems.Add(rule.pixel_length.ToString());
  232. item.SubItems.Add(rule.physical_length.ToString());
  233. item.SubItems.Add(InvariantData.ruleUnitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString());
  234. item.SubItems.Add(rule.ruler_width + "*" + rule.ruler_height);
  235. item.SubItems.Add(rule.ruler_zoom);
  236. item.SubItems.Add(rule.ruler_connector);
  237. item.SubItems.Add(rule.ruler_eyepiece);
  238. item.SubItems.Add(rule.ruler_camera);
  239. item.SubItems.Add(rule.objective_lens);
  240. item.SubItems.Add(rule.microscope);
  241. this.listView1.Items.Add(item);
  242. }
  243. }
  244. if (viewItem != null)
  245. {
  246. //刷新不清掉选中状态会进入切换选中事件然后报错
  247. viewItem.Selected = false;
  248. viewItem.ForeColor = Color.Black;
  249. viewItem.BackColor = Color.White;
  250. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  251. viewItem.Font = f;
  252. //this.listView1.Items.Add(viewItem);
  253. }
  254. if (viewItemList != null && viewItemList.Count > 0)
  255. {
  256. foreach (ListViewItem item in viewItemList)
  257. {
  258. //刷新不清掉选中状态会进入切换选中事件然后报错
  259. item.Selected = false;
  260. item.ForeColor = Color.Black;
  261. item.BackColor = Color.White;
  262. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  263. item.Font = f;
  264. this.listView1.Items.Add(item);
  265. }
  266. }
  267. this.appWorkspace.ToolBar.refreshRulersComboBoxList();
  268. }
  269. private void InitializeComponent()
  270. {
  271. this.listView1 = new System.Windows.Forms.ListView();
  272. this.comboBox1 = new System.Windows.Forms.ComboBox();
  273. this.button1 = new System.Windows.Forms.Button();
  274. this.button3 = new System.Windows.Forms.Button();
  275. this.button4 = new System.Windows.Forms.Button();
  276. this.button5 = new System.Windows.Forms.Button();
  277. this.button6 = new System.Windows.Forms.Button();
  278. this.button7 = new System.Windows.Forms.Button();
  279. this.button2 = new System.Windows.Forms.Button();
  280. this.button8 = new System.Windows.Forms.Button();
  281. this.SuspendLayout();
  282. //
  283. // listView1
  284. //
  285. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  286. | System.Windows.Forms.AnchorStyles.Left)
  287. | System.Windows.Forms.AnchorStyles.Right)));
  288. this.listView1.FullRowSelect = true;
  289. this.listView1.HideSelection = false;
  290. this.listView1.Location = new System.Drawing.Point(12, 40);
  291. this.listView1.MultiSelect = false;
  292. this.listView1.Name = "listView1";
  293. this.listView1.ShowItemToolTips = true;
  294. this.listView1.Size = new System.Drawing.Size(267, 191);
  295. this.listView1.TabIndex = 1;
  296. this.listView1.UseCompatibleStateImageBehavior = false;
  297. this.listView1.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listView1_ItemSelectionChanged);
  298. this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
  299. //
  300. // comboBox1
  301. //
  302. this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  303. this.comboBox1.FormattingEnabled = true;
  304. this.comboBox1.Location = new System.Drawing.Point(175, 238);
  305. this.comboBox1.Name = "comboBox1";
  306. this.comboBox1.Size = new System.Drawing.Size(104, 20);
  307. this.comboBox1.TabIndex = 2;
  308. //
  309. // button1
  310. //
  311. this.button1.Location = new System.Drawing.Point(11, 12);
  312. this.button1.Name = "button1";
  313. this.button1.Size = new System.Drawing.Size(29, 23);
  314. this.button1.TabIndex = 3;
  315. this.button1.UseVisualStyleBackColor = true;
  316. this.button1.Click += new System.EventHandler(this.button1_Click);
  317. //
  318. // button3
  319. //
  320. this.button3.Location = new System.Drawing.Point(75, 12);
  321. this.button3.Name = "button3";
  322. this.button3.Size = new System.Drawing.Size(29, 23);
  323. this.button3.TabIndex = 5;
  324. this.button3.UseVisualStyleBackColor = true;
  325. this.button3.Click += new System.EventHandler(this.button3_Click);
  326. //
  327. // button4
  328. //
  329. this.button4.Location = new System.Drawing.Point(43, 12);
  330. this.button4.Name = "button4";
  331. this.button4.Size = new System.Drawing.Size(29, 23);
  332. this.button4.TabIndex = 6;
  333. this.button4.UseVisualStyleBackColor = true;
  334. this.button4.Click += new System.EventHandler(this.button4_Click);
  335. //
  336. // button5
  337. //
  338. this.button5.Location = new System.Drawing.Point(106, 12);
  339. this.button5.Name = "button5";
  340. this.button5.Size = new System.Drawing.Size(29, 23);
  341. this.button5.TabIndex = 7;
  342. this.button5.UseVisualStyleBackColor = true;
  343. this.button5.Click += new System.EventHandler(this.button5_Click);
  344. //
  345. // button6
  346. //
  347. this.button6.Location = new System.Drawing.Point(202, 12);
  348. this.button6.Name = "button6";
  349. this.button6.Size = new System.Drawing.Size(29, 23);
  350. this.button6.TabIndex = 8;
  351. this.button6.UseVisualStyleBackColor = true;
  352. this.button6.Click += new System.EventHandler(this.button6_Click);
  353. //
  354. // button7
  355. //
  356. this.button7.Location = new System.Drawing.Point(234, 12);
  357. this.button7.Name = "button7";
  358. this.button7.Size = new System.Drawing.Size(29, 23);
  359. this.button7.TabIndex = 9;
  360. this.button7.UseVisualStyleBackColor = true;
  361. this.button7.Click += new System.EventHandler(this.button7_Click);
  362. //
  363. // button2
  364. //
  365. this.button2.Location = new System.Drawing.Point(138, 12);
  366. this.button2.Name = "button2";
  367. this.button2.Size = new System.Drawing.Size(29, 23);
  368. this.button2.TabIndex = 10;
  369. this.button2.UseVisualStyleBackColor = true;
  370. this.button2.Click += new System.EventHandler(this.button2_Click);
  371. //
  372. // button8
  373. //
  374. this.button8.Location = new System.Drawing.Point(170, 12);
  375. this.button8.Name = "button8";
  376. this.button8.Size = new System.Drawing.Size(29, 23);
  377. this.button8.TabIndex = 11;
  378. this.button8.UseVisualStyleBackColor = true;
  379. this.button8.Click += new System.EventHandler(this.button8_Click);
  380. //
  381. // RuleListForm
  382. //
  383. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  384. this.ClientSize = new System.Drawing.Size(291, 270);
  385. this.Controls.Add(this.button8);
  386. this.Controls.Add(this.button2);
  387. this.Controls.Add(this.button7);
  388. this.Controls.Add(this.button6);
  389. this.Controls.Add(this.button5);
  390. this.Controls.Add(this.button4);
  391. this.Controls.Add(this.button3);
  392. this.Controls.Add(this.button1);
  393. this.Controls.Add(this.comboBox1);
  394. this.Controls.Add(this.listView1);
  395. this.Location = new System.Drawing.Point(0, 0);
  396. this.Name = "RuleListForm";
  397. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RuleListForm_FormClosing);
  398. this.Controls.SetChildIndex(this.listView1, 0);
  399. this.Controls.SetChildIndex(this.comboBox1, 0);
  400. this.Controls.SetChildIndex(this.button1, 0);
  401. this.Controls.SetChildIndex(this.button3, 0);
  402. this.Controls.SetChildIndex(this.button4, 0);
  403. this.Controls.SetChildIndex(this.button5, 0);
  404. this.Controls.SetChildIndex(this.button6, 0);
  405. this.Controls.SetChildIndex(this.button7, 0);
  406. this.Controls.SetChildIndex(this.button2, 0);
  407. this.Controls.SetChildIndex(this.button8, 0);
  408. this.ResumeLayout(false);
  409. }
  410. /// <summary>
  411. /// listView1 ItemSelectionChanged事件
  412. /// </summary>
  413. /// <param name="sender"></param>
  414. /// <param name="e"></param>
  415. private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  416. {
  417. listView1.FullRowSelect = true;
  418. if (this.listView1.SelectedItems.Count > 0)
  419. {
  420. listView1.SelectedItems[0].SubItems[0].ForeColor = Color.Blue;
  421. //先清除原有格式
  422.                 foreach (ListViewItem item in listView1.Items)
  423. {
  424. //去掉所有对号
  425. //item.Text = "";
  426. item.ForeColor = Color.Black;
  427. }
  428. foreach (ListViewItem item in listView1.Items)
  429. {
  430. item.BackColor = Color.White;
  431. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  432. item.Font = f;
  433. }
  434. //打上对号
  435. //listView1.SelectedItems[0].Text = "√";
  436.                 //加粗字体
  437.                 Font f2 = new Font(Control.DefaultFont, FontStyle.Bold);
  438. listView1.SelectedItems[0].SubItems[0].Font = f2;
  439.                 //设置选中行背景颜色
  440.                 listView1.SelectedItems[0].BackColor = Color.LightBlue;
  441. if (!listView1.SelectedItems[0].Selected)
  442. listView1.SelectedItems[0].Selected = true;
  443. index = e.ItemIndex;
  444. }
  445. }
  446. /// <summary>
  447. /// 新增标尺
  448. /// </summary>
  449. /// <param name="sender"></param>
  450. /// <param name="e"></param>
  451. private void button1_Click(object sender, System.EventArgs e)
  452. {
  453. RuleAddForm ruleAddForm = new RuleAddForm(1, appWorkspace);
  454. ruleAddForm.StartPosition = FormStartPosition.CenterScreen;
  455. ruleAddForm.ShowDialog();
  456. }
  457. /// <summary>
  458. /// 修改标尺
  459. /// </summary>
  460. /// <param name="sender"></param>
  461. /// <param name="e"></param>
  462. private void button4_Click(object sender, EventArgs e)
  463. {
  464. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  465. {
  466. if (((mic_rulers)this.listView1.SelectedItems[0].Tag).id > 0/*"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)*/)
  467. {
  468. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  469. if (mic_Rulers.ruler_type == 1)
  470. {
  471. int id = mic_Rulers.id;
  472. RuleAddForm ruleAddForm = new RuleAddForm(2, appWorkspace);
  473. //ruleAddForm.ruleModel = mic_rulers_BLL.FindDefault(id);
  474. ruleAddForm.ruleModel = mic_Rulers;
  475. if (System.IO.File.Exists(Application.StartupPath + "\\RuleFile\\" + id + ".xml"))
  476. ruleAddForm.ruleFileModel = XmlSerializeHelper.DESerializer<RulerFileModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\RuleFile\\" + id + ".xml", FileMode.Open));
  477. else
  478. ruleAddForm.ruleFileModel = new RulerFileModel();
  479. ruleAddForm.StartPosition = FormStartPosition.CenterScreen;
  480. ruleAddForm.InitializeEditData();
  481. ruleAddForm.ShowDialog();
  482. }
  483. else
  484. {
  485. CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, mic_Rulers, 2);
  486. customRulerDialog.StartPosition = FormStartPosition.CenterScreen;
  487. customRulerDialog.ShowDialog();
  488. }
  489. }
  490. else
  491. {
  492. //if ("temporary".Equals(this.listView1.SelectedItems[0].Tag) || "temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  493. //{
  494. MessageBox.Show(PdnResources.GetString("Menu.Temporaryrulercannotbemodified.Text") + "!", PdnResources.GetString("Menu.hint.text"));
  495. //}
  496. }
  497. }
  498. else
  499. {
  500. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  501. }
  502. }
  503. /// <summary>
  504. /// 删除标尺,当前激活的标尺不允许删除
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void button3_Click(object sender, EventArgs e)
  509. {
  510. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  511. {
  512. if (!"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  513. {
  514. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  515. int id = mic_Rulers.id;
  516. if (id == configModel.RulerId)
  517. {
  518. MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text"));
  519. return;
  520. }
  521. else
  522. {
  523. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  524. if (dr == DialogResult.OK)
  525. {
  526. //删除数据库文件
  527. mic_rulers_BLL.Del(id);
  528. DelRule(id);
  529. //删除标尺xml文件
  530. string filePath = Application.StartupPath + "\\RuleFile\\" + id + ".xml";
  531. if (System.IO.File.Exists(filePath))
  532. {
  533. System.IO.File.Delete(filePath);
  534. }
  535. }
  536. }
  537. }
  538. else
  539. {
  540. if (this.listView1.SelectedItems[0].Text == "√")
  541. {
  542. MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text"));
  543. return;
  544. }
  545. //理论比例尺
  546. if ("temporary".Equals(this.listView1.SelectedItems[0].Tag))
  547. {
  548. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  549. if (dr == DialogResult.OK)
  550. {
  551. this.listView1.SelectedItems[0].Remove();
  552. viewItem.SubItems.Clear();
  553. viewItem = null;
  554. }
  555. }
  556. //临时标尺
  557. else if ("temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  558. {
  559. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  560. if (dr == DialogResult.OK)
  561. {
  562. ListViewItem selectedItem = this.listView1.SelectedItems[0];
  563. if (viewItemList != null && viewItemList.Count > 0)
  564. {
  565. for (int i = 0; i < viewItemList.Count; i++)
  566. {
  567. if (viewItemList[i].Equals(selectedItem))
  568. {
  569. viewItemList.Remove(viewItemList[i]);
  570. }
  571. }
  572. }
  573. }
  574. }
  575. }
  576. InitListViewData();
  577. //刷新预览窗口
  578. if (CameraPreviewDialog.cameraPreviewDialog != null)
  579. CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  580. }
  581. else
  582. {
  583. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  584. }
  585. }
  586. public void DelRule(int id)
  587. {
  588. int index = 0;
  589. for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
  590. {
  591. if (Startup.instance.mic_rulersAll[i].id == id)
  592. {
  593. index = i;
  594. }
  595. }
  596. Startup.instance.mic_rulersAll.Remove(Startup.instance.mic_rulersAll[index]);
  597. }
  598. /// <summary>
  599. /// 设置当前选中标尺
  600. /// </summary>
  601. /// <param name="index"></param>
  602. public void SetActiveRulerIndex(int selectIndex)
  603. {
  604. //判断选中索引是否是激活的索引
  605. bool SelectIndex = false;
  606. for (int i = 0; i < this.listView1.Items.Count; i++)
  607. {
  608. if (((mic_rulers)this.listView1.Items[i].Tag).id == Startup.instance.configModel.RulerId)
  609. {
  610. if (selectIndex == i )
  611. SelectIndex = true;
  612. break;
  613. }
  614. }
  615. if (selectIndex < this.listView1.Items.Count && (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0 || !SelectIndex))
  616. {
  617. this.listView1.Items[selectIndex].Selected = true;
  618. this.button5ActionImply(selectIndex);
  619. //this.button5.PerformClick();
  620. }
  621. }
  622. /// <summary>
  623. /// 刷新当前选中的标尺-编辑后使用
  624. /// </summary>
  625. public void RefreshActiveRuler()
  626. {
  627. ListViewItem selectedItem = null;
  628. foreach (ListViewItem item in this.listView1.Items)
  629. {
  630. if (item.Text == "√")
  631. {
  632. selectedItem = item;
  633. break;
  634. }
  635. }
  636. if (selectedItem != null)
  637. {
  638. //只有普通标尺可编辑
  639. if (!"temporary".Equals(selectedItem.Tag) && !"temporaryList".Equals(selectedItem.Tag))
  640. {
  641. if (configModel.RulerId != 0)
  642. {
  643. //调用startup的方法
  644. Startup.instance.InitRulerInfo();
  645. Startup.instance.InitUnitInfo();
  646. //this.appWorkspace.ToolBar.refreshRulersComboBox();
  647. initComboBox = true;//1019###19594
  648. }
  649. }
  650. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  651. {
  652. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(this.comboBox1.SelectedIndex + 1));
  653. this.appWorkspace.UpdateDocInfoInStatusBar();
  654. }
  655. this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  656. }
  657. }
  658. /// <summary>
  659. /// 激活当前选中标尺
  660. /// </summary>
  661. /// <param name="sender"></param>
  662. /// <param name="e"></param>
  663. private void button5_Click(object sender, EventArgs e)
  664. {
  665. this.button5ActionImply(-1);
  666. }
  667. /// <summary>
  668. /// 激活当前选中标尺
  669. /// </summary>
  670. /// <param name="activeRulerIndex">通过自定义菜单设置当前选中标尺时,index不等于-1,用于解决窗口未初始化时标尺无法激活的问题</param>
  671. private void button5ActionImply(int activeRulerIndex)
  672. {
  673. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1 || activeRulerIndex > -1)
  674. {
  675. bool existSelectedItem = (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1);
  676. if (existSelectedItem && this.listView1.SelectedItems[0].Text == "√"
  677. || !existSelectedItem && this.listView1.Items[activeRulerIndex].Text == "√")
  678. {
  679. MessageBox.Show(PdnResources.GetString("Menu.Currentlyselectedruleractive.Text"));
  680. return;
  681. }
  682. mic_rulers mic_Rulers;
  683. if (existSelectedItem)
  684. mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  685. else
  686. mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag;
  687. int id = mic_Rulers.id;
  688. if (id != configModel.RulerId)
  689. {
  690. int oldId = configModel.RulerId;
  691. //激活当前标尺到configModel
  692. configModel.RulerId = id;
  693. //保存xml文件
  694. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  695. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  696. if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  697. {
  698. //调用startup的方法
  699. Startup.instance.InitRulerInfo();
  700. Startup.instance.InitUnitInfo();
  701. //处理当前的listview
  702. if (index >= 0)
  703. {
  704. this.listView1.Items[index].Text = "";
  705. }
  706. foreach (ListViewItem item in listView1.Items)
  707. {
  708. //去掉所有对号
  709. item.Text = "";
  710. }
  711. if (existSelectedItem)
  712. this.listView1.SelectedItems[0].Text = "√";
  713. else
  714. this.listView1.Items[activeRulerIndex].Text = "√";
  715. this.listView1.Refresh();
  716. this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  717. if (CameraPreviewDialog.cameraPreviewDialog != null)
  718. CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  719. initComboBox = true;//1019###19594
  720. }
  721. else
  722. {
  723. configModel.RulerId = oldId;
  724. MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text"));
  725. }
  726. }
  727. //普通标尺
  728. //if (existSelectedItem && !"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)
  729. // || !existSelectedItem && !"temporary".Equals(this.listView1.Items[activeRulerIndex].Tag) && !"temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag))
  730. //{
  731. //mic_rulers mic_Rulers;
  732. // if (existSelectedItem)
  733. // mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  734. // else
  735. // mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag;
  736. // int id = mic_Rulers.id;
  737. // if (id != configModel.RulerId)
  738. // {
  739. // int oldId = configModel.RulerId;
  740. // //激活当前标尺到configModel
  741. // configModel.RulerId = id;
  742. // //保存xml文件
  743. // string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  744. // string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  745. // if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  746. // {
  747. // //调用startup的方法
  748. // Startup.instance.InitRulerInfo();
  749. // Startup.instance.InitUnitInfo();
  750. // //处理当前的listview
  751. // if (index >= 0)
  752. // {
  753. // this.listView1.Items[index].Text = "";
  754. // }
  755. // foreach (ListViewItem item in listView1.Items)
  756. // {
  757. // //去掉所有对号
  758. // item.Text = "";
  759. // }
  760. // if (existSelectedItem)
  761. // this.listView1.SelectedItems[0].Text = "√";
  762. // else
  763. // this.listView1.Items[activeRulerIndex].Text = "√";
  764. // this.listView1.Refresh();
  765. // this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  766. // if (CameraPreviewDialog.cameraPreviewDialog != null)
  767. // CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  768. // initComboBox = true;//1019###19594
  769. // }
  770. // else
  771. // {
  772. // configModel.RulerId = oldId;
  773. // MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text"));
  774. // }
  775. // }
  776. //}
  777. ////理论比例尺
  778. //else if (existSelectedItem && "temporary".Equals(this.listView1.SelectedItems[0].Tag)
  779. // || !existSelectedItem && "temporary".Equals(this.listView1.Items[activeRulerIndex].Tag))
  780. //{
  781. // this.ActivateTemporaryRuler();
  782. //}
  783. ////临时标尺
  784. //else if (existSelectedItem && "temporaryList".Equals(this.listView1.SelectedItems[0].Tag)
  785. // || !existSelectedItem && "temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag))
  786. //{
  787. // ListViewItem selectedItem;
  788. // if (existSelectedItem)
  789. // selectedItem = this.listView1.SelectedItems[0];
  790. // else
  791. // selectedItem = this.listView1.Items[activeRulerIndex];
  792. // if (viewItemList != null && viewItemList.Count > 0)
  793. // {
  794. // for (int i = 0; i < viewItemList.Count; i++)
  795. // {
  796. // if (viewItemList[i].Equals(selectedItem))
  797. // {
  798. // //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  799. // Startup.instance.rules.Clear();
  800. // //重置已激活的标尺,不知道对不对
  801. // configModel.RulerId = 0;
  802. // string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  803. // string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  804. // FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  805. // Startup.instance.measurementUnit = MeasurementUnit.Micron;
  806. // double unitLength = (Convert.ToDouble(viewItemList[i].SubItems[4].Text) / Convert.ToDouble(viewItemList[i].SubItems[3].Text));
  807. // Startup.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  808. // Startup.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  809. // Startup.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  810. // Startup.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  811. // Startup.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  812. // foreach (ListViewItem item in listView1.Items)
  813. // {
  814. // //去掉所有对号
  815. // item.Text = "";
  816. // }
  817. // viewItemList[i].Text = "√";
  818. // break;
  819. // }
  820. // }
  821. // }
  822. //}
  823. //else
  824. //{
  825. //}
  826. }
  827. else
  828. {
  829. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  830. }
  831. //刷新预览窗口的
  832. if (this.appWorkspace != null)
  833. {
  834. if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
  835. {
  836. this.appWorkspace.cameraPreviewDialog.documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  837. }
  838. }
  839. this.appWorkspace.UpdateDocInfoInStatusBar();
  840. }
  841. /// <summary>
  842. /// 自定义标尺
  843. /// </summary>
  844. /// <param name="sender"></param>
  845. /// <param name="e"></param>
  846. private void button6_Click(object sender, EventArgs e)
  847. {
  848. CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, null, 1);
  849. customRulerDialog.StartPosition = FormStartPosition.CenterScreen;
  850. customRulerDialog.ShowDialog();
  851. }
  852. /// <summary>
  853. /// 刷新
  854. /// </summary>
  855. /// <param name="sender"></param>
  856. /// <param name="e"></param>
  857. private void button7_Click(object sender, EventArgs e)
  858. {
  859. InitListViewData();
  860. }
  861. /// <summary>
  862. /// 激活临时标尺
  863. /// </summary>
  864. public void ActivateTemporaryRuler()
  865. {
  866. if (viewItem != null && !viewItem.Equals(""))
  867. {
  868. //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  869. Startup.instance.rules.Clear();
  870. //重置已激活的标尺,不知道对不对
  871. configModel.RulerId = 0;
  872. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  873. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  874. FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  875. Startup.instance.measurementUnit = MeasurementUnit.Micron;
  876. double unitLength = (Convert.ToDouble(viewItem.SubItems[4].Text) / Convert.ToDouble(viewItem.SubItems[3].Text));
  877. Startup.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  878. Startup.instance.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
  879. Startup.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  880. Startup.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  881. Startup.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  882. Startup.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  883. foreach (ListViewItem item in listView1.Items)
  884. {
  885. //去掉所有对号
  886. item.Text = "";
  887. }
  888. viewItem.Text = "√";
  889. }
  890. }
  891. /// <summary>
  892. /// 单位下拉的SelectIndexChange事件
  893. /// </summary>
  894. /// <param name="sender"></param>
  895. /// <param name="e"></param>
  896. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  897. {
  898. if (initComboBox || configModel != null)//1019###19594
  899. {
  900. int oldUint = configModel.Unit;
  901. //需要先改变配置内的单位
  902. //configModel.Unit = (int)(((DictionaryEntry)(this.comboBox1.SelectedValue)).Key);
  903. configModel.Unit = (int)(this.comboBox1.SelectedValue);
  904. //保存xml文件
  905. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  906. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  907. if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  908. {
  909. //在调用初始化单位信息的方法
  910. Startup.instance.InitUnitInfo();
  911. this.appWorkspace.Units = (MeasurementUnit)configModel.Unit;
  912. this.appWorkspace.ViewConfigStrip_UnitsChanged(null, null);
  913. //循环刷新所有窗口
  914. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  915. {
  916. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  917. }
  918. //刷新预览窗口
  919. if (this.appWorkspace != null)
  920. {
  921. if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
  922. {
  923. this.appWorkspace.cameraPreviewDialog.documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  924. }
  925. }
  926. this.appWorkspace.opticalDensityDialog.RefreshOpticalDensity(null, null);
  927. if (this.appWorkspace != null)
  928. {
  929. this.appWorkspace.RefreshListView();
  930. this.appWorkspace.UpdateDocInfoInStatusBar();
  931. }
  932. }
  933. else
  934. {
  935. configModel.Unit = oldUint;
  936. MessageBox.Show(PdnResources.GetString("Menu.Unitswitchfailed.Text"));
  937. }
  938. }
  939. initComboBox = true;
  940. }
  941. private void RefreshComboBox() {
  942. }
  943. /// <summary>
  944. /// 双击激活标尺
  945. /// </summary>
  946. /// <param name="sender"></param>
  947. /// <param name="e"></param>
  948. private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
  949. {
  950. this.button5.PerformClick();
  951. }
  952. private void RuleListForm_FormClosing(object sender, FormClosingEventArgs e)
  953. {
  954. this.appWorkspace.toolBar.RefreshBtnSelect(false, "SubRulerCalibration");
  955. this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "SubRulerCalibration");
  956. }
  957. //应用到全部图片
  958. private void button8_Click(object sender, EventArgs e)
  959. {
  960. if (this.listView1.SelectedItems.Count == 0)
  961. {
  962. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  963. return;
  964. }
  965. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  966. //循环刷新所有窗口
  967. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  968. {
  969. documentWorkspace.xmlSaveModel = mic_Rulers;
  970. documentWorkspace.InitRulerInfo();
  971. //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  972. }
  973. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  974. {
  975. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  976. documentWorkspace.Units = Startup.instance.measurementUnit;
  977. }
  978. this.appWorkspace.UpdateDocInfoInStatusBar();
  979. this.appWorkspace.RefreshListView();
  980. }
  981. /// <summary>
  982. /// 应用到当前图片
  983. /// </summary>
  984. /// <param name="sender"></param>
  985. /// <param name="e"></param>
  986. private void button2_Click(object sender, EventArgs e)
  987. {
  988. if (this.listView1.SelectedItems.Count == 0)
  989. {
  990. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  991. return;
  992. }
  993. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  994. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  995. {
  996. this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers;
  997. this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo();
  998. this.appWorkspace.UpdateDocInfoInStatusBar();
  999. this.appWorkspace.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit;
  1000. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1001. this.appWorkspace.RefreshListView();
  1002. }
  1003. }
  1004. /// <summary>
  1005. /// 系统激活应用当前
  1006. /// </summary>
  1007. public void MenuSubApplyCurrent()
  1008. {
  1009. mic_rulers mic_Rulers = Startup.instance.ruleDB;
  1010. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  1011. {
  1012. this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers;
  1013. this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo();
  1014. this.appWorkspace.UpdateDocInfoInStatusBar();
  1015. this.appWorkspace.ActiveDocumentWorkspace.Units = Startup.instance.measurementUnit;
  1016. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1017. this.appWorkspace.RefreshListView();
  1018. }
  1019. }
  1020. /// <summary>
  1021. /// 系统激活应用全部
  1022. /// </summary>
  1023. public void MenuSubApplyAll()
  1024. {
  1025. mic_rulers mic_Rulers = Startup.instance.ruleDB;
  1026. //循环刷新所有窗口
  1027. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  1028. {
  1029. documentWorkspace.xmlSaveModel = mic_Rulers;
  1030. documentWorkspace.InitRulerInfo();
  1031. //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1032. }
  1033. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  1034. {
  1035. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1036. documentWorkspace.Units = Startup.instance.measurementUnit;
  1037. }
  1038. this.appWorkspace.UpdateDocInfoInStatusBar();
  1039. this.appWorkspace.RefreshListView();
  1040. }
  1041. }
  1042. }