ViewSettingMenu.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base;
  3. using PaintDotNet.Data.Param;
  4. using PaintDotNet.FieldView;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Drawing.Imaging;
  10. using System.Globalization;
  11. using System.Windows.Forms;
  12. namespace PaintDotNet.Menus
  13. {
  14. /// <summary>
  15. /// 视场菜单
  16. /// </summary>
  17. internal sealed class ViewSettingMenu : PdnMenuItem
  18. {
  19. private PdnMenuItem menuViewSelect;
  20. private PdnMenuItem menuViewDeleteSelect;
  21. private PdnMenuItem menuViewClearAll;
  22. private ToolStripSeparator menuHelpSeparator1;
  23. private PdnMenuItem menuOvalView;
  24. private PdnMenuItem menuRoundView;
  25. private PdnMenuItem menuRectangleView;
  26. private PdnMenuItem menuRectangleExView;
  27. private PdnMenuItem menuTriangleView;
  28. private PdnMenuItem menuTriangleExView;
  29. private PdnMenuItem menuSquareView;
  30. private PdnMenuItem menuPolygonView;
  31. private ToolStripSeparator menuHelpSeparator2;
  32. private PdnMenuItem menuMergeFieldOfView;
  33. private PdnMenuItem menuDeleteFieldOfView;
  34. private ToolStripSeparator menuHelpSeparator3;
  35. private PdnMenuItem menuShearFieldOfView;
  36. private PdnMenuItem menuTransparentCut;
  37. private ToolStripSeparator menuHelpSeparator4;
  38. private PdnMenuItem menuOpenFieldOfView;
  39. private PdnMenuItem menuModifyFieldOfView;
  40. private PdnMenuItem menuSaveFieldOfView;
  41. private ChangeViewDialog changeViewDialog;
  42. public ViewSettingMenu(int menuId)
  43. {
  44. InitializeComponent();
  45. this.MenuId = menuId;
  46. this.AutoNextScript = false;
  47. this.AutomaticScript = false;
  48. }
  49. protected override void OnAppWorkspaceChanged()
  50. {
  51. base.OnAppWorkspaceChanged();
  52. }
  53. protected override void OnDropDownOpening(EventArgs e)
  54. {
  55. //this.RecursiveData(this.DropDownItems);
  56. base.OnDropDownOpening(e);
  57. }
  58. private void InitializeComponent()
  59. {
  60. this.menuViewSelect = new PdnMenuItem(ActionType.ViewSelect);
  61. this.menuViewDeleteSelect = new PdnMenuItem(ActionType.ViewDeleteSelect);
  62. this.menuViewClearAll = new PdnMenuItem(ActionType.ViewClearAll);
  63. this.menuHelpSeparator1 = new ToolStripSeparator();
  64. this.menuOvalView = new PdnMenuItem(ActionType.OvalView);
  65. this.menuRoundView = new PdnMenuItem(ActionType.RoundView);
  66. this.menuRectangleView = new PdnMenuItem(ActionType.RectangleView);
  67. this.menuRectangleExView = new PdnMenuItem(ActionType.RectangleExView);
  68. this.menuTriangleView = new PdnMenuItem(ActionType.TriangleView);
  69. this.menuTriangleExView = new PdnMenuItem(ActionType.TriangleExView);
  70. this.menuSquareView = new PdnMenuItem(ActionType.SquareView);
  71. this.menuPolygonView = new PdnMenuItem(ActionType.PolygonView);
  72. this.menuHelpSeparator2 = new ToolStripSeparator();
  73. this.menuMergeFieldOfView = new PdnMenuItem(ActionType.MergeFieldOfView);
  74. this.menuDeleteFieldOfView = new PdnMenuItem(ActionType.DeleteFieldOfView);
  75. this.menuHelpSeparator3 = new ToolStripSeparator();
  76. this.menuShearFieldOfView = new PdnMenuItem(ActionType.ShearFieldOfView);
  77. this.menuTransparentCut = new PdnMenuItem(ActionType.TransparentCut);
  78. this.menuHelpSeparator4 = new ToolStripSeparator();
  79. this.menuOpenFieldOfView = new PdnMenuItem(ActionType.OpenFieldOfView);
  80. this.menuModifyFieldOfView = new PdnMenuItem(ActionType.ModifyFieldOfView);
  81. this.menuSaveFieldOfView = new PdnMenuItem(ActionType.SaveFieldOfView);
  82. //
  83. // 主菜单
  84. //
  85. this.DropDownItems.AddRange(new ToolStripItem[] {
  86. this.menuViewSelect,
  87. this.menuViewDeleteSelect,
  88. this.menuViewClearAll,
  89. this.menuHelpSeparator1,
  90. this.menuOvalView,
  91. this.menuRoundView,
  92. this.menuRectangleView,
  93. this.menuRectangleExView,
  94. this.menuTriangleView,
  95. this.menuTriangleExView,
  96. this.menuSquareView,
  97. this.menuPolygonView,
  98. this.menuHelpSeparator2,
  99. this.menuMergeFieldOfView,
  100. this.menuDeleteFieldOfView,
  101. this.menuHelpSeparator3,
  102. this.menuShearFieldOfView,
  103. this.menuTransparentCut,
  104. this.menuHelpSeparator4,
  105. this.menuOpenFieldOfView,
  106. this.menuModifyFieldOfView,
  107. this.menuSaveFieldOfView
  108. });
  109. this.Name = "Menu.ViewSetting";
  110. this.Text = PdnResources.GetString("Menu.ViewSetting.Text");
  111. //
  112. // 选择视场
  113. //
  114. this.menuViewSelect.Click += new EventHandler(MenuViewSelect_Click);
  115. this.menuViewSelect.NeedWaitKey = true;
  116. //
  117. // 删除选择
  118. //
  119. this.menuViewDeleteSelect.Click += new System.EventHandler(MenuViewDeleteSelect_Click);
  120. this.menuViewDeleteSelect.NeedWaitKey = true;
  121. //
  122. // 清空全部
  123. //
  124. this.menuViewClearAll.Click += new System.EventHandler(MenuViewClearAll_Click);
  125. this.menuViewClearAll.NeedWaitKey = true;
  126. //
  127. // 椭圆视场
  128. //
  129. this.menuOvalView.Click += new System.EventHandler(MenuOvalView_Click);
  130. this.menuOvalView.NeedWaitKey = true;
  131. //
  132. // 圆形视场
  133. //
  134. this.menuRoundView.Click += new System.EventHandler(MenuRoundView_Click);
  135. this.menuRoundView.NeedWaitKey = true;
  136. //
  137. // 矩形视场
  138. //
  139. this.menuRectangleView.Click += new System.EventHandler(MenuRectangleView_Click);
  140. this.menuRectangleView.NeedWaitKey = true;
  141. //
  142. // 矩形视场
  143. //
  144. this.menuRectangleExView.Click += new System.EventHandler(MenuRectangleExView_Click);
  145. this.menuRectangleExView.NeedWaitKey = true;
  146. //
  147. // 直角三角形视场
  148. //
  149. this.menuTriangleView.Click += new System.EventHandler(MenuTriangleView_Click);
  150. this.menuTriangleView.NeedWaitKey = true;
  151. //
  152. // 任意三角形视场
  153. //
  154. this.menuTriangleExView.Click += new System.EventHandler(MenuTriangleExView_Click);
  155. this.menuTriangleExView.NeedWaitKey = true;
  156. //
  157. // 正方形视场
  158. //
  159. this.menuSquareView.Click += new System.EventHandler(MenuSquareView_Click);
  160. this.menuSquareView.NeedWaitKey = true;
  161. //
  162. // 多边形视场
  163. //
  164. this.menuPolygonView.Click += new System.EventHandler(MenuPolygonView_Click);
  165. this.menuPolygonView.NeedWaitKey = true;
  166. //
  167. // 合并视场
  168. //
  169. this.menuMergeFieldOfView.Click += new System.EventHandler(MenuMergeFieldOfView_Click);
  170. this.menuMergeFieldOfView.NeedWaitKey = true;
  171. this.menuMergeFieldOfView.Checked = true;
  172. //
  173. // 删除视场
  174. //
  175. this.menuDeleteFieldOfView.Click += new System.EventHandler(MenuDeleteFieldOfView_Click);
  176. this.menuDeleteFieldOfView.NeedWaitKey = true;
  177. this.menuDeleteFieldOfView.Checked = false;
  178. //
  179. // 剪切视场
  180. //
  181. this.menuShearFieldOfView.Click += new System.EventHandler(MenuShearFieldOfView_Click);
  182. this.menuShearFieldOfView.NeedWaitKey = true;
  183. //
  184. // 透明剪切
  185. //
  186. this.menuTransparentCut.Click += new System.EventHandler(MenuTransparentCut_Click);
  187. this.menuTransparentCut.NeedWaitKey = true;
  188. //
  189. // 打开视场
  190. //
  191. this.menuOpenFieldOfView.Click += new System.EventHandler(MenuOpenFieldOfView_Click);
  192. this.menuOpenFieldOfView.NeedWaitKey = true;
  193. //
  194. // 修改视场
  195. //
  196. this.menuModifyFieldOfView.Click += new System.EventHandler(MenuModifyFieldOfView_Click);
  197. this.menuModifyFieldOfView.NeedWaitKey = true;
  198. //
  199. // 保存视场
  200. //
  201. this.menuSaveFieldOfView.Click += new System.EventHandler(MenuSaveFieldOfView_Click);
  202. this.menuSaveFieldOfView.NeedWaitKey = true;
  203. //
  204. // 加载菜单的文字和icon
  205. //
  206. this.LoadNames(this.Name);
  207. this.LoadIcons();
  208. }
  209. /// <summary>
  210. /// 选择视场
  211. /// </summary>
  212. /// <param name="sender"></param>
  213. /// <param name="e"></param>
  214. private void MenuViewSelect_Click(object sender, EventArgs e)
  215. {
  216. if (AppWorkspace.ActiveDocumentWorkspace != null)
  217. {
  218. if (AppWorkspace.startScriptRecording)
  219. {
  220. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  221. }
  222. AppWorkspace.ActiveDocumentWorkspace.activeTool = DrawToolType.Pointer;
  223. }
  224. }
  225. /// <summary>
  226. /// 删除选择的视场
  227. /// </summary>
  228. /// <param name="sender"></param>
  229. /// <param name="e"></param>
  230. private void MenuViewDeleteSelect_Click(object sender, EventArgs e)
  231. {
  232. if (AppWorkspace.ActiveDocumentWorkspace != null)
  233. {
  234. if (AppWorkspace.startScriptRecording)
  235. {
  236. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  237. }
  238. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  239. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteSelection(DrawClass.View);
  240. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  241. }
  242. }
  243. /// <summary>
  244. /// 清空全部
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. private void MenuViewClearAll_Click(object sender, EventArgs e)
  249. {
  250. if (AppWorkspace.ActiveDocumentWorkspace != null)
  251. {
  252. if (AppWorkspace.startScriptRecording)
  253. {
  254. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  255. }
  256. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteAllView();
  257. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  258. }
  259. }
  260. /// <summary>
  261. /// 椭圆视场
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. private void MenuOvalView_Click(object sender, EventArgs e)
  266. {
  267. if (AppWorkspace.ActiveDocumentWorkspace != null)
  268. {
  269. if (AppWorkspace.startScriptRecording)
  270. {
  271. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  272. }
  273. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewOval;
  274. }
  275. }
  276. /// <summary>
  277. /// 圆形视场
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void MenuRoundView_Click(object sender, EventArgs e)
  282. {
  283. if (AppWorkspace.ActiveDocumentWorkspace != null)
  284. {
  285. if (AppWorkspace.startScriptRecording)
  286. {
  287. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  288. }
  289. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewCircle;
  290. }
  291. }
  292. /// <summary>
  293. /// 矩形视场
  294. /// </summary>
  295. /// <param name="sender"></param>
  296. /// <param name="e"></param>
  297. private void MenuRectangleView_Click(object sender, EventArgs e)
  298. {
  299. if (AppWorkspace.ActiveDocumentWorkspace != null)
  300. {
  301. if (AppWorkspace.startScriptRecording)
  302. {
  303. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  304. }
  305. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewRectangle;
  306. }
  307. }
  308. /// <summary>
  309. /// 矩形视场
  310. /// </summary>
  311. /// <param name="sender"></param>
  312. /// <param name="e"></param>
  313. private void MenuRectangleExView_Click(object sender, EventArgs e)
  314. {
  315. if (AppWorkspace.ActiveDocumentWorkspace != null)
  316. {
  317. if (AppWorkspace.startScriptRecording)
  318. {
  319. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  320. }
  321. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewRectangleEx;
  322. }
  323. }
  324. /// <summary>
  325. /// 三角形视场
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. /// <param name="e"></param>
  329. private void MenuTriangleView_Click(object sender, EventArgs e)
  330. {
  331. if (AppWorkspace.ActiveDocumentWorkspace != null)
  332. {
  333. if (AppWorkspace.startScriptRecording)
  334. {
  335. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  336. }
  337. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewTriangle;
  338. }
  339. }
  340. /// <summary>
  341. /// 任意三角形视场
  342. /// </summary>
  343. /// <param name="sender"></param>
  344. /// <param name="e"></param>
  345. private void MenuTriangleExView_Click(object sender, EventArgs e)
  346. {
  347. if (AppWorkspace.ActiveDocumentWorkspace != null)
  348. {
  349. if (AppWorkspace.startScriptRecording)
  350. {
  351. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  352. }
  353. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewTriangleEx;
  354. }
  355. }
  356. /// <summary>
  357. /// 正方形视场
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void MenuSquareView_Click(object sender, EventArgs e)
  362. {
  363. if (AppWorkspace.ActiveDocumentWorkspace != null)
  364. {
  365. if (AppWorkspace.startScriptRecording)
  366. {
  367. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  368. }
  369. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewSquare;
  370. }
  371. }
  372. /// <summary>
  373. /// 多边形视场
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void MenuPolygonView_Click(object sender, EventArgs e)
  378. {
  379. if (AppWorkspace.ActiveDocumentWorkspace != null)
  380. {
  381. if (AppWorkspace.startScriptRecording)
  382. {
  383. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  384. }
  385. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ViewPolygon;
  386. }
  387. }
  388. /// <summary>
  389. /// 合并视场
  390. /// </summary>
  391. /// <param name="sender"></param>
  392. /// <param name="e"></param>
  393. private void MenuMergeFieldOfView_Click(object sender, EventArgs e)
  394. {
  395. if (AppWorkspace.ActiveDocumentWorkspace != null)
  396. {
  397. AppWorkspace.ActiveDocumentWorkspace.CombineMode = CombineMode.Union;
  398. if (!AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView)
  399. {
  400. if (AppWorkspace.startScriptRecording)
  401. {
  402. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  403. }
  404. AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView = AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView;
  405. AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView = !AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView;
  406. this.menuMergeFieldOfView.Checked = AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView;
  407. this.menuDeleteFieldOfView.Checked = AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView;
  408. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  409. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  410. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  411. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  412. }
  413. }
  414. }
  415. /// <summary>
  416. /// 删除视场
  417. /// </summary>
  418. /// <param name="sender"></param>
  419. /// <param name="e"></param>
  420. private void MenuDeleteFieldOfView_Click(object sender, EventArgs e)
  421. {
  422. if (AppWorkspace.ActiveDocumentWorkspace != null)
  423. {
  424. AppWorkspace.ActiveDocumentWorkspace.CombineMode = CombineMode.Complement;
  425. if(!AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView)
  426. {
  427. if (AppWorkspace.startScriptRecording)
  428. {
  429. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  430. }
  431. AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView = AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView;
  432. AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView = !AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView;
  433. this.menuMergeFieldOfView.Checked = AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView;
  434. this.menuDeleteFieldOfView.Checked = AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView;
  435. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  436. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  437. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  438. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// 剪切视场
  444. /// </summary>
  445. /// <param name="sender"></param>
  446. /// <param name="e"></param>
  447. private void MenuShearFieldOfView_Click(object sender, EventArgs e)
  448. {
  449. if (this.AppWorkspace!=null && this.AppWorkspace.ActiveDocumentWorkspace!=null)
  450. {
  451. Bitmap bitmap = this.AppWorkspace.ActiveDocumentWorkspace.GetCutSizeWithColorWhiteOrTransparent(false);
  452. if(bitmap!=null)
  453. {
  454. if (AppWorkspace.startScriptRecording)
  455. {
  456. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  457. }
  458. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  459. Document document = Document.FromImage(bitmap);
  460. dw.Document = document;
  461. dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  462. dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
  463. dw.fileText = PdnResources.GetString("Menu.ViewSetting.ShearFieldOfView.Text") + "-" + Startup.instance.step_length;
  464. AppWorkspace.ActiveDocumentWorkspace = dw;
  465. Startup.instance.step_length += 1;
  466. }
  467. }
  468. }
  469. /// <summary>
  470. /// 透明剪切
  471. /// </summary>
  472. /// <param name="sender"></param>
  473. /// <param name="e"></param>
  474. private void MenuTransparentCut_Click(object sender, EventArgs e)
  475. {
  476. if (this.AppWorkspace != null && this.AppWorkspace.ActiveDocumentWorkspace != null)
  477. {
  478. Bitmap bitmap = this.AppWorkspace.ActiveDocumentWorkspace.GetCutSizeWithColorWhiteOrTransparent(true);
  479. if (bitmap != null)
  480. {
  481. if (AppWorkspace.startScriptRecording)
  482. {
  483. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  484. }
  485. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  486. Document document = Document.FromImage(bitmap);
  487. dw.Document = document;
  488. dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  489. dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
  490. dw.fileText = PdnResources.GetString("Menu.ViewSetting.TransparentCut.Text") + "-" + Startup.instance.step_length;
  491. AppWorkspace.ActiveDocumentWorkspace = dw;
  492. Startup.instance.step_length += 1;
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// 打开视场
  498. /// </summary>
  499. /// <param name="sender"></param>
  500. /// <param name="e"></param>
  501. private void MenuOpenFieldOfView_Click(object sender, EventArgs e)
  502. {
  503. using (OpenViewDialog dialog = new OpenViewDialog(AppWorkspace))
  504. {
  505. if (AppWorkspace.startScriptRecording)
  506. {
  507. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  508. }
  509. dialog.StartPosition = FormStartPosition.CenterScreen;
  510. dialog.ShowDialog();
  511. }
  512. }
  513. /// <summary>
  514. /// 修改视场
  515. /// </summary>
  516. /// <param name="sender"></param>
  517. /// <param name="e"></param>
  518. private void MenuModifyFieldOfView_Click(object sender, EventArgs e)
  519. {
  520. //如果当前界面有视场、并且选中的是视场
  521. if (AppWorkspace.ActiveDocumentWorkspace!=null
  522. && AppWorkspace.ActiveDocumentWorkspace.GraphicsList!=null
  523. && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count>0
  524. && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.SelectionCount==1)
  525. {
  526. if (AppWorkspace.startScriptRecording)
  527. {
  528. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  529. }
  530. changeViewDialog = (ChangeViewDialog)Application.OpenForms["ChangeViewDialog"];//尝试获取已经弹出的窗口对象
  531. FloatingFormMethod.ShowFloatForm(changeViewDialog, changeViewDialog == null ? new ChangeViewDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  532. //if (changeViewDialog == null)
  533. //{
  534. // changeViewDialog = new ChangeViewDialog(AppWorkspace);
  535. // changeViewDialog.StartPosition = FormStartPosition.CenterScreen;
  536. // changeViewDialog.Show();
  537. //}
  538. //else
  539. //{
  540. // if (!changeViewDialog.IsDisposed)
  541. // {
  542. // changeViewDialog.WindowState = FormWindowState.Normal;
  543. // }
  544. // else
  545. // {
  546. // changeViewDialog = new ChangeViewDialog(AppWorkspace);
  547. // changeViewDialog.StartPosition = FormStartPosition.CenterScreen;
  548. // changeViewDialog.Show();
  549. // }
  550. //}
  551. }
  552. else
  553. {
  554. MessageBox.Show(PdnResources.GetString("Menu.leaseonlyonefieldofviewtomodify.Text"));
  555. }
  556. }
  557. /// <summary>
  558. /// 保存视场
  559. /// </summary>
  560. /// <param name="sender"></param>
  561. /// <param name="e"></param>
  562. private void MenuSaveFieldOfView_Click(object sender, EventArgs e)
  563. {
  564. if(AppWorkspace.ActiveDocumentWorkspace!=null)
  565. {
  566. Region region = AppWorkspace.ActiveDocumentWorkspace.GetRegion();
  567. Bitmap bitmap = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  568. //判断当前surfacebox内是否有视场
  569. if (region != null)
  570. {
  571. using (SaveViewDialog dialog = new SaveViewDialog(AppWorkspace, region, bitmap))
  572. {
  573. if (AppWorkspace.startScriptRecording)
  574. {
  575. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  576. }
  577. dialog.StartPosition = FormStartPosition.CenterScreen;
  578. dialog.ShowDialog();
  579. }
  580. }
  581. else
  582. {
  583. MessageBox.Show(PdnResources.GetString("Menu.Drawthefieldofviewfirst.Text"));
  584. }
  585. }
  586. }
  587. private string GetCultureInfoName(CultureInfo ci)
  588. {
  589. CultureInfo en_US = new CultureInfo("en-US");
  590. if (ci.Equals(en_US))
  591. {
  592. return GetCultureInfoName(ci.Parent);
  593. }
  594. else
  595. {
  596. return ci.NativeName;
  597. }
  598. }
  599. }
  600. }