EditMenu.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Adjust.BaseImage;
  4. using PaintDotNet.Annotation;
  5. using PaintDotNet.Annotation.Enum;
  6. using PaintDotNet.Annotation.Label;
  7. using PaintDotNet.Base;
  8. using PaintDotNet.Base.CommTool;
  9. using PaintDotNet.Data.Param;
  10. using PaintDotNet.DbOpreate.DbBll;
  11. using PaintDotNet.DbOpreate.DbModel;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Drawing;
  15. using System.Windows.Forms;
  16. namespace PaintDotNet.Menus
  17. {
  18. /// <summary>
  19. /// 编辑菜单
  20. /// </summary>
  21. internal sealed class EditMenu : PdnMenuItem
  22. {
  23. private PdnMenuItem menuEditUndo;
  24. private PdnMenuItem menuEditRedo;
  25. private PdnMenuItem menuEditCopy;
  26. private PdnMenuItem menuEditPaste;
  27. private PdnMenuItem menuEditDelete;
  28. private ToolStripSeparator menuEditSeparator1;
  29. private PdnMenuItem menuViewZoomIn;
  30. private PdnMenuItem menuViewZoomOut;
  31. private PdnMenuItem menuViewActualSize;
  32. private PdnMenuItem menuViewZoomToWindow;
  33. private PdnMenuItem menuViewZoomToWidth;
  34. private PdnMenuItem menuViewZoomToHeight;
  35. private ToolStripSeparator menuEditSeparator2;
  36. private PdnMenuItem menuImageCut;
  37. private PdnMenuItem menuLockZoom;
  38. private PdnMenuItem menuFixedMultiple;
  39. private ToolStripSeparator menuEditSeparator3;
  40. private PdnMenuItem menuImageFlipHorizontal;
  41. private PdnMenuItem menuImageFlipVertical;
  42. private PdnMenuItem menuImageFlipCenter;
  43. private ToolStripSeparator menuEditSeparator4;
  44. private PdnMenuItem menuImageRotate90CW;
  45. private PdnMenuItem menuImageRotate180;
  46. private PdnMenuItem menuImageRotate90CCW;
  47. private Bitmap copyedBitmap;//复制的图片
  48. private int nameNum = 0;//命名使用
  49. private bool OnBackspaceTyped(Keys keys)
  50. {
  51. if (AppWorkspace.ActiveDocumentWorkspace != null)
  52. {
  53. //this.menuEditFillSelection.PerformClick();
  54. return true;
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. }
  61. public EditMenu(int menuId)
  62. {
  63. //PdnBaseForm.RegisterFormHotKey(Keys.Back, OnBackspaceTyped);
  64. //PdnBaseForm.RegisterFormHotKey(Keys.Shift | Keys.Delete, OnLeftHandedCutHotKey);
  65. PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Insert, OnLeftHandedCopyHotKey);
  66. PdnBaseForm.RegisterFormHotKey(Keys.Shift | Keys.Insert, OnLeftHandedPasteHotKey);
  67. InitializeComponent();
  68. this.MenuId = menuId;
  69. }
  70. /**
  71. private bool OnLeftHandedCutHotKey(Keys keys)
  72. {
  73. this.menuEditCut.PerformClick();
  74. return true;
  75. }**/
  76. private bool OnLeftHandedCopyHotKey(Keys keys)
  77. {
  78. this.menuEditCopy.PerformClick();
  79. return true;
  80. }
  81. private bool OnLeftHandedPasteHotKey(Keys keys)
  82. {
  83. this.menuEditPaste.PerformClick();
  84. return true;
  85. }
  86. private void InitializeComponent()
  87. {
  88. this.menuEditUndo = new PdnMenuItem(ActionType.Undo);
  89. this.menuEditRedo = new PdnMenuItem(ActionType.Redo);
  90. this.menuEditCopy = new PdnMenuItem(ActionType.Copy);
  91. this.menuEditPaste = new PdnMenuItem(ActionType.Paste);
  92. this.menuEditDelete = new PdnMenuItem(ActionType.Delete);
  93. this.menuEditSeparator1 = new ToolStripSeparator();
  94. this.menuViewZoomIn = new PdnMenuItem(ActionType.ZoomIn);
  95. this.menuViewZoomOut = new PdnMenuItem(ActionType.ZoomOut);
  96. this.menuViewActualSize = new PdnMenuItem(ActionType.ActualSize, true);
  97. this.menuViewZoomToWindow = new PdnMenuItem(ActionType.ZoomToWindow, true);
  98. this.menuViewZoomToWidth = new PdnMenuItem(ActionType.ZoomToWidth, true);
  99. this.menuViewZoomToHeight = new PdnMenuItem(ActionType.ZoomToHeight, true);
  100. this.menuEditSeparator2 = new ToolStripSeparator();
  101. this.menuImageCut = new PdnMenuItem(ActionType.ImageCut);
  102. this.menuLockZoom = new PdnMenuItem(ActionType.LockZoom);
  103. this.menuFixedMultiple = new PdnMenuItem(ActionType.FixedMultiple);
  104. //this.menuFixedMultiple.Visible = false;
  105. this.menuEditSeparator3 = new ToolStripSeparator();
  106. this.menuImageFlipHorizontal = new PdnMenuItem(ActionType.FlipHorizontal);
  107. this.menuImageFlipVertical = new PdnMenuItem(ActionType.FlipVertical);
  108. this.menuImageFlipCenter = new PdnMenuItem(ActionType.FlipCenter);
  109. this.menuEditSeparator4 = new ToolStripSeparator();
  110. this.menuImageRotate90CW = new PdnMenuItem(ActionType.Rotate90CW);
  111. this.menuImageRotate180 = new PdnMenuItem(ActionType.Rotate180);
  112. this.menuImageRotate90CCW = new PdnMenuItem(ActionType.Rotate90CCW);
  113. //
  114. // EditMenu
  115. //
  116. this.DropDownItems.AddRange(
  117. new ToolStripItem[]
  118. {
  119. this.menuEditUndo,
  120. this.menuEditRedo,
  121. this.menuEditCopy,
  122. this.menuEditPaste,
  123. this.menuEditDelete,
  124. this.menuEditSeparator1,
  125. this.menuViewZoomIn,
  126. this.menuViewZoomOut,
  127. this.menuViewActualSize,
  128. this.menuViewZoomToWindow,
  129. this.menuViewZoomToWidth,
  130. this.menuViewZoomToHeight,
  131. this.menuEditSeparator2,
  132. this.menuImageCut,
  133. this.menuLockZoom,
  134. this.menuFixedMultiple,
  135. this.menuEditSeparator3,
  136. this.menuImageFlipHorizontal,
  137. this.menuImageFlipVertical,
  138. this.menuImageFlipCenter,
  139. this.menuEditSeparator4,
  140. this.menuImageRotate90CW,
  141. this.menuImageRotate180,
  142. this.menuImageRotate90CCW
  143. }); ;
  144. this.Name = "Menu.Edit";
  145. this.Text = PdnResources.GetString("Menu.Edit.Text");
  146. //
  147. // 撤销
  148. //
  149. this.menuEditUndo.Click += new EventHandler(this.MenuEditUndo_Click);
  150. //
  151. // 恢复
  152. //
  153. this.menuEditRedo.Click += new EventHandler(this.MenuEditRedo_Click);
  154. //
  155. // 复制
  156. //
  157. this.menuEditCopy.Click += new EventHandler(this.MenuEditCopy_Click);
  158. //
  159. // 粘贴
  160. //
  161. this.menuEditPaste.Click += new EventHandler(this.MenuEditPaste_Click);
  162. //
  163. // 删除
  164. //
  165. this.menuEditDelete.Click += new EventHandler(this.MenuEditDelete_Click);
  166. //
  167. // 放大
  168. //
  169. this.menuViewZoomIn.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomIn.ShortcutKeyDisplayString");
  170. this.menuViewZoomIn.NeedWaitKey = true;
  171. this.menuViewZoomIn.Click += new EventHandler(this.MenuViewZoomIn_Click);
  172. //
  173. // 缩小
  174. //
  175. this.menuViewZoomOut.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomOut.ShortcutKeyDisplayString");
  176. this.menuViewZoomOut.NeedWaitKey = true;
  177. this.menuViewZoomOut.Click += new EventHandler(this.MenuViewZoomOut_Click);
  178. //
  179. // 实际大小
  180. //
  181. this.menuViewActualSize.NeedWaitKey = true;
  182. this.menuViewActualSize.Click += new EventHandler(this.MenuViewActualSize_Click);
  183. //
  184. // 合适大小
  185. //
  186. this.menuViewZoomToWindow.NeedWaitKey = true;
  187. this.menuViewZoomToWindow.Click += new EventHandler(this.MenuViewZoomToWindow_Click);
  188. //
  189. // 合适宽度
  190. //
  191. this.menuViewZoomToWidth.NeedWaitKey = true;
  192. this.menuViewZoomToWidth.Click += new EventHandler(this.MenuViewZoomToWidth_Click);
  193. //
  194. //
  195. // 合适高度
  196. this.menuViewZoomToHeight.NeedWaitKey = true;
  197. this.menuViewZoomToHeight.Click += new EventHandler(this.MenuViewZoomToHeight_Click);
  198. //
  199. // 图片裁剪
  200. //
  201. this.menuImageCut.NeedWaitKey = true;
  202. this.menuImageCut.AutomaticScript = false;
  203. this.menuImageCut.Click += new EventHandler(this.MenuImageCut_Click);
  204. //
  205. // 锁定扩缩
  206. //
  207. this.menuLockZoom.Click += new EventHandler(this.MenuLockZoom_Click);
  208. //
  209. // 定倍显示
  210. //
  211. this.menuFixedMultiple.Click += new EventHandler(this.MenuFixedMultiple_Click);
  212. //
  213. // 水平翻转
  214. //
  215. this.menuImageFlipHorizontal.Click += new EventHandler(this.MenuImageFlipHorizontal_Click);
  216. //
  217. // 垂直翻转
  218. //
  219. this.menuImageFlipVertical.Click += new EventHandler(this.MenuImageFlipVertical_Click);
  220. //
  221. // 中心翻转
  222. //
  223. this.menuImageFlipCenter.Click += new EventHandler(this.MenuImageFlipCenter_Click);
  224. //
  225. // 旋转90度
  226. //
  227. this.menuImageRotate90CW.Click += new EventHandler(this.MenuImageRotate90_Click);
  228. //this.menuImageRotate90CW.ShortcutKeys = Keys.Control | Keys.J;
  229. //
  230. // 旋转180度
  231. //
  232. this.menuImageRotate180.Click += new EventHandler(this.MenuImageRotate180_Click);
  233. //this.menuImageRotate180.ShortcutKeys = Keys.Control | Keys.J;
  234. //
  235. // 旋转270度
  236. //
  237. this.menuImageRotate90CCW.Click += new EventHandler(this.MenuImageRotate270_Click);
  238. //this.menuImageRotate90CCW.ShortcutKeys = Keys.Control | Keys.J;
  239. //
  240. // 加载菜单的文字和icon
  241. //
  242. this.LoadNames(this.Name);
  243. this.LoadIcons();
  244. }
  245. protected override void OnDropDownOpening(EventArgs e)
  246. {
  247. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.ActualSize : false;
  248. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableSize : false;
  249. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableWidth : false;
  250. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableHeight : false;
  251. this.menuLockZoom.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.LockZoom : false;
  252. this.menuFixedMultiple.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.FixedMultiple : false;
  253. if (AppWorkspace.ActiveDocumentWorkspace == null/* || AppWorkspace.ScriptRunning*/)
  254. {
  255. this.menuViewZoomToWindow.Enabled = false;
  256. this.menuViewActualSize.Enabled = false;
  257. this.menuEditCopy.Enabled = false;
  258. this.menuEditDelete.Enabled = false;
  259. this.menuLockZoom.Checked = false;
  260. this.menuFixedMultiple.Enabled = false;
  261. }
  262. else
  263. {
  264. this.menuViewZoomToWindow.Enabled = true;
  265. //this.menuViewZoomToSelection.Enabled = !AppWorkspace.ActiveDocumentWorkspace.Selection.IsEmpty;
  266. this.menuViewActualSize.Enabled = true;
  267. this.menuEditCopy.Enabled = true;
  268. //this.menuLockZoom.Checked = AppWorkspace.isLockZoom;
  269. this.menuEditDelete.Enabled = false;
  270. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList != null && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
  271. {
  272. for (int i = 0; i < AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count; i++)
  273. {
  274. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].Selected)
  275. {
  276. this.menuEditDelete.Enabled = true;
  277. break;
  278. }
  279. }
  280. }
  281. //this.menuViewZoomToWindow.Checked = (AppWorkspace.ActiveDocumentWorkspace.ZoomBasis == ZoomBasis.FitToWindow);
  282. this.menuFixedMultiple.Enabled = true;
  283. }
  284. if (copyedBitmap != null/* && !AppWorkspace.ScriptRunning*/)
  285. this.menuEditPaste.Enabled = true;
  286. else
  287. this.menuEditPaste.Enabled = false;
  288. //this.menuEditDelete.Enabled = selection;
  289. //this.menuEditCut.Enabled = selection && bitmapLayer;
  290. // find out if there's anything on the clipboard that we can use
  291. //bool isClipImageAvailable = Utility.IsClipboardImageAvailable();
  292. //this.menuEditPaste.Enabled = isClipImageAvailable && (AppWorkspace.ActiveDocumentWorkspace != null);
  293. /**
  294. if (!this.menuEditPaste.Enabled)
  295. {
  296. if (AppWorkspace.ActiveDocumentWorkspace != null)
  297. {
  298. bool canHandle;
  299. try
  300. {
  301. IDataObject pasted = Clipboard.GetDataObject();
  302. }
  303. catch (ExternalException)
  304. {
  305. canHandle = false;
  306. }
  307. if (canHandle)
  308. {
  309. this.menuEditPaste.Enabled = true;
  310. }
  311. }
  312. }**/
  313. if (AppWorkspace.ActiveDocumentWorkspace != null/* && !AppWorkspace.ScriptRunning*/)
  314. {
  315. this.menuEditUndo.Enabled = (AppWorkspace.ActiveDocumentWorkspace.undoManager.CanUndo);// (AppWorkspace.ActiveDocumentWorkspace.History.UndoStack.Count > 1); // top of stack is always assumed to be a "NullHistoryMemento," which is not undoable! thus we don't count it
  316. this.menuEditRedo.Enabled = (AppWorkspace.ActiveDocumentWorkspace.undoManager.CanRedo);// (AppWorkspace.ActiveDocumentWorkspace.History.RedoStack.Count > 0);
  317. }
  318. else
  319. {
  320. this.menuEditUndo.Enabled = false;
  321. this.menuEditRedo.Enabled = false;
  322. }
  323. //this.RecursiveData(this.DropDownItems);
  324. base.OnDropDownOpening(e);
  325. }
  326. /// <summary>
  327. /// 撤销
  328. /// </summary>
  329. /// <param name="sender"></param>
  330. /// <param name="e"></param>
  331. private void MenuEditUndo_Click(object sender, EventArgs e)
  332. {
  333. if (AppWorkspace.ActiveDocumentWorkspace != null)
  334. {
  335. if (AppWorkspace.startScriptRecording)
  336. {
  337. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  338. }
  339. AppWorkspace.ActiveDocumentWorkspace.undoManager.Undo();
  340. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  341. }
  342. /**
  343. if (AppWorkspace.ActiveDocumentWorkspace != null &&
  344. !AppWorkspace.ActiveDocumentWorkspace.IsMouseCaptured())
  345. {
  346. AppWorkspace.ActiveDocumentWorkspace.PerformAction(new HistoryUndoAction());
  347. }**/
  348. }
  349. /// <summary>
  350. /// 恢复
  351. /// </summary>
  352. /// <param name="sender"></param>
  353. /// <param name="e"></param>
  354. private void MenuEditRedo_Click(object sender, EventArgs e)
  355. {
  356. if (AppWorkspace.ActiveDocumentWorkspace != null)
  357. {
  358. if (AppWorkspace.startScriptRecording)
  359. {
  360. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  361. }
  362. AppWorkspace.ActiveDocumentWorkspace.undoManager.Redo();
  363. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  364. }
  365. /**
  366. if (AppWorkspace.ActiveDocumentWorkspace != null &&
  367. !AppWorkspace.ActiveDocumentWorkspace.IsMouseCaptured())
  368. {
  369. AppWorkspace.ActiveDocumentWorkspace.PerformAction(new HistoryRedoAction());
  370. }**/
  371. }
  372. /// <summary>
  373. /// 复制
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void MenuEditCopy_Click(object sender, EventArgs e)
  378. {
  379. if (AppWorkspace.ActiveDocumentWorkspace!=null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  380. {
  381. if (AppWorkspace.startScriptRecording)
  382. {
  383. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  384. }
  385. Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  386. copyedBitmap = new Bitmap(temp.Width, temp.Height);
  387. Graphics graphics = Graphics.FromImage(copyedBitmap);
  388. graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
  389. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
  390. {
  391. //获取裁剪的矩形区域
  392. List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  393. ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
  394. RectangleF cutRectangle = imageCutDraw.Rectangle;
  395. copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
  396. }
  397. }
  398. }
  399. /// <summary>
  400. /// 粘贴
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void MenuEditPaste_Click(object sender, EventArgs e)
  405. {
  406. if (copyedBitmap != null)
  407. {
  408. if (AppWorkspace.startScriptRecording)
  409. {
  410. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  411. }
  412. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  413. Document document = Document.FromImage(copyedBitmap);
  414. dw.Document = document;
  415. //图片命名
  416. nameNum++;
  417. int numLength = nameNum.ToString().Length;
  418. string joinName = "";
  419. switch (numLength)
  420. {
  421. case 1:
  422. joinName = "00" + nameNum;
  423. break;
  424. case 2:
  425. joinName = "0" + nameNum;
  426. break;
  427. default:
  428. joinName = nameNum.ToString();
  429. break;
  430. }
  431. dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  432. dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
  433. dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text")+"-" + joinName;
  434. AppWorkspace.ActiveDocumentWorkspace = dw;
  435. }
  436. }
  437. /// <summary>
  438. /// 删除
  439. /// </summary>
  440. /// <param name="sender"></param>
  441. /// <param name="e"></param>
  442. private void MenuEditDelete_Click(object sender, EventArgs e)
  443. {
  444. if (AppWorkspace.ActiveDocumentWorkspace != null)
  445. {
  446. if(AppWorkspace.ActiveDocumentWorkspace.GraphicsList != null && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
  447. {
  448. if (AppWorkspace.startScriptRecording)
  449. {
  450. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  451. }
  452. for (int i = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count - 1; i >= 0; i--)
  453. {
  454. if(AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].Selected == true)
  455. {
  456. //对数字标记做单独处理
  457. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].drawToolType == DrawToolType.DrawNumberMark)
  458. {
  459. DrawNumberMark drawNumberMark = (DrawNumberMark)AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i];
  460. List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawNumberMark);
  461. if (objList != null && objList.Count > 0)
  462. {
  463. for (int j = 0; j < objList.Count; j++)
  464. {
  465. DrawNumberMark modifyNum = (DrawNumberMark)objList[j];
  466. if (modifyNum.nowNum > drawNumberMark.nowNum)
  467. {
  468. modifyNum.nowNum -= 1;
  469. }
  470. }
  471. }
  472. }
  473. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.RemoveObj(AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i]);
  474. }
  475. }
  476. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  477. }
  478. }
  479. }
  480. private void MenuViewZoomIn_Click(object sender, EventArgs e)
  481. {
  482. if (AppWorkspace.ActiveDocumentWorkspace != null)
  483. {
  484. if (AppWorkspace.startScriptRecording)
  485. {
  486. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  487. }
  488. AppWorkspace.ActiveDocumentWorkspace.ZoomIn();
  489. }
  490. }
  491. private void MenuViewZoomOut_Click(object sender, EventArgs e)
  492. {
  493. if (AppWorkspace.ActiveDocumentWorkspace != null)
  494. {
  495. if (AppWorkspace.startScriptRecording)
  496. {
  497. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  498. }
  499. AppWorkspace.ActiveDocumentWorkspace.ZoomOut();
  500. }
  501. }
  502. private void MenuViewActualSize_Click(object sender, EventArgs e)
  503. {
  504. if (AppWorkspace.ActiveDocumentWorkspace != null)
  505. {
  506. if (AppWorkspace.startScriptRecording)
  507. {
  508. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  509. }
  510. if (!AppWorkspace.ActiveDocumentWorkspace.ActualSize)
  511. {
  512. AppWorkspace.ActiveDocumentWorkspace.ActualSize = !AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  513. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  514. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  515. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  516. AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
  517. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  518. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  519. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  520. AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
  521. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  522. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  523. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  524. AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
  525. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  526. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  527. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  528. }
  529. else
  530. {
  531. AppWorkspace.ActiveDocumentWorkspace.ActualSize = !AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  532. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  533. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  534. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  535. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  536. }
  537. AppWorkspace.UpdateBottomButtonSelectionStatus();
  538. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  539. AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  540. }
  541. }
  542. private void MenuViewZoomToWindow_Click(object sender, EventArgs e)
  543. {
  544. if (AppWorkspace.ActiveDocumentWorkspace != null)
  545. {
  546. if (AppWorkspace.startScriptRecording)
  547. {
  548. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  549. }
  550. if (!AppWorkspace.ActiveDocumentWorkspace.SuitableSize)
  551. {
  552. AppWorkspace.ActiveDocumentWorkspace.SuitableSize = !AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  553. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  554. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  555. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  556. AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
  557. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  558. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  559. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  560. AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
  561. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  562. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  563. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  564. AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
  565. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  566. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  567. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  568. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  569. }
  570. else
  571. {
  572. AppWorkspace.ActiveDocumentWorkspace.SuitableSize = !AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  573. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  574. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  575. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  576. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  577. }
  578. AppWorkspace.UpdateBottomButtonSelectionStatus();
  579. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  580. }
  581. }
  582. private void MenuViewZoomToWidth_Click(object sender, EventArgs e)
  583. {
  584. if (AppWorkspace.ActiveDocumentWorkspace != null)
  585. {
  586. if (AppWorkspace.startScriptRecording)
  587. {
  588. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  589. }
  590. if (!AppWorkspace.ActiveDocumentWorkspace.SuitableWidth)
  591. {
  592. AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = !AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  593. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  594. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  595. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  596. AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
  597. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  598. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  599. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  600. AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
  601. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  602. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  603. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  604. AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
  605. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  606. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  607. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  608. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  609. }
  610. else
  611. {
  612. AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = !AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  613. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  614. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  615. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  616. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  617. }
  618. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWidth;
  619. }
  620. }
  621. private void MenuViewZoomToHeight_Click(object sender, EventArgs e)
  622. {
  623. if (AppWorkspace.ActiveDocumentWorkspace != null)
  624. {
  625. if (AppWorkspace.startScriptRecording)
  626. {
  627. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  628. }
  629. if (!AppWorkspace.ActiveDocumentWorkspace.SuitableHeight)
  630. {
  631. AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = !AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  632. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  633. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  634. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  635. AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
  636. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  637. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  638. this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
  639. AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
  640. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  641. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
  642. this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
  643. AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
  644. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  645. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
  646. this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
  647. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  648. }
  649. else
  650. {
  651. AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = !AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  652. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  653. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  654. this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
  655. this.AppWorkspace.UpdateBottomButtonSelectionStatus();
  656. }
  657. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToHeight;
  658. }
  659. }
  660. private void MenuImageCut_Click(object sender, EventArgs e)
  661. {
  662. if (AppWorkspace.ActiveDocumentWorkspace != null)
  663. {
  664. if (AppWorkspace.startScriptRecording)
  665. {
  666. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  667. }
  668. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ImageCut;
  669. }
  670. }
  671. /// <summary>
  672. /// 锁定扩缩
  673. /// </summary>
  674. /// <param name="sender"></param>
  675. /// <param name="e"></param>
  676. private void MenuLockZoom_Click(object sender, EventArgs e)
  677. {
  678. if (AppWorkspace.ActiveDocumentWorkspace != null)
  679. {
  680. if (AppWorkspace.startScriptRecording)
  681. {
  682. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  683. }
  684. AppWorkspace.ActiveDocumentWorkspace.LockZoom = !AppWorkspace.ActiveDocumentWorkspace.LockZoom;
  685. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.LockZoom, "LockZoom");
  686. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.LockZoom, "LockZoom");
  687. this.menuLockZoom.Checked = !this.menuLockZoom.Checked;
  688. AppWorkspace.UpdateBottomButtonSelectionStatus();
  689. AppWorkspace.isLockZoom = this.menuLockZoom.Checked;
  690. AppWorkspace.lockScaleRatio = AppWorkspace.ActiveDocumentWorkspace.ScaleFactor.Ratio;
  691. }
  692. }
  693. /// <summary>
  694. /// 定倍显示
  695. /// </summary>
  696. /// <param name="sender"></param>
  697. /// <param name="e"></param>
  698. private void MenuFixedMultiple_Click(object sender, EventArgs e)
  699. {
  700. if (AppWorkspace.ActiveDocumentWorkspace != null)
  701. {
  702. if (AppWorkspace.startScriptRecording)
  703. {
  704. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  705. }
  706. AppWorkspace.ActiveDocumentWorkspace.FixedMultiple = !AppWorkspace.ActiveDocumentWorkspace.FixedMultiple;
  707. this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.FixedMultiple, "FixedMultiple");
  708. this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.FixedMultiple, "FixedMultiple");
  709. this.menuFixedMultiple.Checked = AppWorkspace.ActiveDocumentWorkspace.FixedMultiple;
  710. int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
  711. if (dotPitch <= 0)
  712. {
  713. MessageBox.Show(PdnResources.GetString("Menu.hedotdistancefirstandthenadjustthedisplayoperation.Text")+"!");
  714. return;
  715. }
  716. mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
  717. if(screenList == null)
  718. {
  719. MessageBox.Show(PdnResources.GetString("Menu.Failedtogetpointdistanceinformation.Text"));
  720. return;
  721. }
  722. double pointPitch = 0;
  723. try
  724. {
  725. pointPitch = double.Parse(screenList.point_pitch);//获取点距
  726. }
  727. catch (System.Exception)
  728. {
  729. MessageBox.Show(PdnResources.GetString("Menu.Pointdistanceinformationexception.Text"));
  730. return;
  731. }
  732. if (pointPitch <= 0)
  733. {
  734. MessageBox.Show(PdnResources.GetString("Menu.Pointdistanceinformationexception.Text"));
  735. return;
  736. }
  737. string imgName = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();//原始图片名
  738. Bitmap oldBit = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();//原始图片
  739. //获取系统的毫米标尺
  740. double unitLength = 0;
  741. //AppWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
  742. unitLength = AppWorkspace.ActiveDocumentWorkspace.GetRuler(MeasurementUnit.Millimeter);
  743. if (unitLength == 0)
  744. unitLength = 1;
  745. int oldWidth = oldBit.Width;
  746. int oldHeight = oldBit.Height;
  747. int targetWidth = 0;
  748. int targetHeight = 0;
  749. if (oldWidth <= 1 || oldHeight <= 1)//像素最小为1,之后不再处理
  750. return;
  751. double pantographRatio = unitLength / pointPitch;//缩放比
  752. double aspectRatio = oldWidth / (oldHeight * 1d);//宽高比
  753. if (oldWidth <= oldHeight)
  754. {
  755. if (Startup.instance.ruleDB != null)
  756. targetWidth = (int)(oldWidth * pantographRatio * (double)Startup.instance.ruleDB.gain_multiple);
  757. else
  758. targetWidth = (int)(oldWidth * pantographRatio);
  759. if (targetWidth < 1 || targetWidth > oldWidth)//像素值异常不做处理
  760. return;
  761. targetHeight = (int)(targetWidth / aspectRatio);
  762. }
  763. else
  764. {
  765. if (Startup.instance.ruleDB != null)
  766. targetHeight = (int)(oldHeight * pantographRatio * (double)Startup.instance.ruleDB.gain_multiple);
  767. else
  768. targetHeight = (int)(oldHeight * pantographRatio);
  769. if (targetHeight < 1 || targetHeight > oldHeight)//像素值异常不做处理
  770. return;
  771. targetWidth = (int)(targetHeight * aspectRatio);
  772. }
  773. //缩放图片
  774. using (Bitmap targetBit = new Bitmap(targetWidth, targetHeight))
  775. {
  776. using (Graphics g = Graphics.FromImage(targetBit))
  777. {
  778. g.DrawImage(oldBit, new Rectangle(0, 0, targetWidth, targetHeight), new Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel);
  779. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  780. Document document = Document.FromImage(targetBit);
  781. dw.Document = document;
  782. dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  783. dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
  784. dw.fileText = imgName;
  785. AppWorkspace.ActiveDocumentWorkspace = dw;
  786. }
  787. }
  788. }
  789. }
  790. /// <summary>
  791. /// 水平镜像
  792. /// </summary>
  793. /// <param name="sender"></param>
  794. /// <param name="e"></param>
  795. private void MenuImageFlipHorizontal_Click(object sender, EventArgs e)
  796. {
  797. if (AppWorkspace.ActiveDocumentWorkspace != null)
  798. {
  799. if (AppWorkspace.startScriptRecording)
  800. {
  801. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  802. }
  803. AppWorkspace.HorizontalMirroringButton_Click(sender, null);
  804. }
  805. }
  806. /// <summary>
  807. /// 垂直镜像
  808. /// </summary>
  809. /// <param name="sender"></param>
  810. /// <param name="e"></param>
  811. private void MenuImageFlipVertical_Click(object sender, EventArgs e)
  812. {
  813. if (AppWorkspace.ActiveDocumentWorkspace != null)
  814. {
  815. if (AppWorkspace.startScriptRecording)
  816. {
  817. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  818. }
  819. AppWorkspace.VerticalMirrorButton_Click(sender, null);
  820. }
  821. }
  822. /// <summary>
  823. /// 中心镜像
  824. /// </summary>
  825. /// <param name="sender"></param>
  826. /// <param name="e"></param>
  827. private void MenuImageFlipCenter_Click(object sender, EventArgs e)
  828. {
  829. if (AppWorkspace.ActiveDocumentWorkspace != null)
  830. {
  831. if (AppWorkspace.startScriptRecording)
  832. {
  833. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  834. }
  835. AppWorkspace.CenterMirrorButton_Click(sender, null);
  836. }
  837. }
  838. /// <summary>
  839. /// 旋转90度
  840. /// </summary>
  841. /// <param name="sender"></param>
  842. /// <param name="e"></param>
  843. private void MenuImageRotate90_Click(object sender, EventArgs e)
  844. {
  845. if (AppWorkspace.ActiveDocumentWorkspace != null)
  846. {
  847. if (AppWorkspace.startScriptRecording)
  848. {
  849. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  850. }
  851. Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
  852. Mat dst = new Mat();
  853. GeometryIntent.ImageRotate(src, dst, FlipMode.Y);
  854. if (AppWorkspace.ScriptRunning)
  855. {
  856. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  857. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  858. dw.Document = document;
  859. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  860. AppWorkspace.ActiveDocumentWorkspace = dw;
  861. Startup.instance.step_length += 1;
  862. }
  863. else
  864. {
  865. ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
  866. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  867. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  868. AppWorkspace.ActiveDocumentWorkspace.Document = document;
  869. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
  870. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  871. }
  872. }
  873. }
  874. /// <summary>
  875. /// 旋转180度
  876. /// </summary>
  877. /// <param name="sender"></param>
  878. /// <param name="e"></param>
  879. private void MenuImageRotate180_Click(object sender, EventArgs e)
  880. {
  881. if (AppWorkspace.ActiveDocumentWorkspace != null)
  882. {
  883. if (AppWorkspace.startScriptRecording)
  884. {
  885. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  886. }
  887. Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
  888. Mat dst = new Mat();
  889. GeometryIntent.ImageRotate(src, dst, FlipMode.XY);
  890. if (AppWorkspace.ScriptRunning)
  891. {
  892. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  893. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  894. dw.Document = document;
  895. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  896. AppWorkspace.ActiveDocumentWorkspace = dw;
  897. Startup.instance.step_length += 1;
  898. }
  899. else
  900. {
  901. ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
  902. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  903. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  904. AppWorkspace.ActiveDocumentWorkspace.Document = document;
  905. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
  906. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  907. }
  908. }
  909. }
  910. /// <summary>
  911. /// 旋转270度
  912. /// </summary>
  913. /// <param name="sender"></param>
  914. /// <param name="e"></param>
  915. private void MenuImageRotate270_Click(object sender, EventArgs e)
  916. {
  917. if (AppWorkspace.ActiveDocumentWorkspace != null)
  918. {
  919. if (AppWorkspace.startScriptRecording)
  920. {
  921. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  922. }
  923. Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
  924. Mat dst = new Mat();
  925. GeometryIntent.ImageRotate(src, dst, FlipMode.X);
  926. if (AppWorkspace.ScriptRunning)
  927. {
  928. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  929. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  930. dw.Document = document;
  931. dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
  932. AppWorkspace.ActiveDocumentWorkspace = dw;
  933. Startup.instance.step_length += 1;
  934. }
  935. else
  936. {
  937. ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
  938. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  939. Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
  940. AppWorkspace.ActiveDocumentWorkspace.Document = document;
  941. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
  942. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  943. }
  944. }
  945. }
  946. }
  947. }