123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023 |
- using OpenCvSharp;
- using PaintDotNet.Adjust;
- using PaintDotNet.Adjust.BaseImage;
- using PaintDotNet.Annotation;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Annotation.Label;
- using PaintDotNet.Base;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Data.Param;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Menus
- {
- /// <summary>
- /// 编辑菜单
- /// </summary>
- internal sealed class EditMenu : PdnMenuItem
- {
- private PdnMenuItem menuEditUndo;
- private PdnMenuItem menuEditRedo;
- private PdnMenuItem menuEditCopy;
- private PdnMenuItem menuEditPaste;
- private PdnMenuItem menuEditDelete;
- private ToolStripSeparator menuEditSeparator1;
- private PdnMenuItem menuViewZoomIn;
- private PdnMenuItem menuViewZoomOut;
- private PdnMenuItem menuViewActualSize;
- private PdnMenuItem menuViewZoomToWindow;
- private PdnMenuItem menuViewZoomToWidth;
- private PdnMenuItem menuViewZoomToHeight;
- private ToolStripSeparator menuEditSeparator2;
- private PdnMenuItem menuImageCut;
- private PdnMenuItem menuLockZoom;
- private PdnMenuItem menuFixedMultiple;
- private ToolStripSeparator menuEditSeparator3;
- private PdnMenuItem menuImageFlipHorizontal;
- private PdnMenuItem menuImageFlipVertical;
- private PdnMenuItem menuImageFlipCenter;
- private ToolStripSeparator menuEditSeparator4;
- private PdnMenuItem menuImageRotate90CW;
- private PdnMenuItem menuImageRotate180;
- private PdnMenuItem menuImageRotate90CCW;
- private Bitmap copyedBitmap;//复制的图片
- private int nameNum = 0;//命名使用
- private bool OnBackspaceTyped(Keys keys)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- //this.menuEditFillSelection.PerformClick();
- return true;
- }
- else
- {
- return false;
- }
- }
- public EditMenu(int menuId)
- {
- //PdnBaseForm.RegisterFormHotKey(Keys.Back, OnBackspaceTyped);
- //PdnBaseForm.RegisterFormHotKey(Keys.Shift | Keys.Delete, OnLeftHandedCutHotKey);
- PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Insert, OnLeftHandedCopyHotKey);
- PdnBaseForm.RegisterFormHotKey(Keys.Shift | Keys.Insert, OnLeftHandedPasteHotKey);
- InitializeComponent();
- this.MenuId = menuId;
- }
- /**
- private bool OnLeftHandedCutHotKey(Keys keys)
- {
- this.menuEditCut.PerformClick();
- return true;
- }**/
- private bool OnLeftHandedCopyHotKey(Keys keys)
- {
- this.menuEditCopy.PerformClick();
- return true;
- }
- private bool OnLeftHandedPasteHotKey(Keys keys)
- {
- this.menuEditPaste.PerformClick();
- return true;
- }
- private void InitializeComponent()
- {
- this.menuEditUndo = new PdnMenuItem(ActionType.Undo);
- this.menuEditRedo = new PdnMenuItem(ActionType.Redo);
- this.menuEditCopy = new PdnMenuItem(ActionType.Copy);
- this.menuEditPaste = new PdnMenuItem(ActionType.Paste);
- this.menuEditDelete = new PdnMenuItem(ActionType.Delete);
- this.menuEditSeparator1 = new ToolStripSeparator();
- this.menuViewZoomIn = new PdnMenuItem(ActionType.ZoomIn);
- this.menuViewZoomOut = new PdnMenuItem(ActionType.ZoomOut);
- this.menuViewActualSize = new PdnMenuItem(ActionType.ActualSize, true);
- this.menuViewZoomToWindow = new PdnMenuItem(ActionType.ZoomToWindow, true);
- this.menuViewZoomToWidth = new PdnMenuItem(ActionType.ZoomToWidth, true);
- this.menuViewZoomToHeight = new PdnMenuItem(ActionType.ZoomToHeight, true);
- this.menuEditSeparator2 = new ToolStripSeparator();
- this.menuImageCut = new PdnMenuItem(ActionType.ImageCut);
- this.menuLockZoom = new PdnMenuItem(ActionType.LockZoom);
- this.menuFixedMultiple = new PdnMenuItem(ActionType.FixedMultiple);
- //this.menuFixedMultiple.Visible = false;
- this.menuEditSeparator3 = new ToolStripSeparator();
- this.menuImageFlipHorizontal = new PdnMenuItem(ActionType.FlipHorizontal);
- this.menuImageFlipVertical = new PdnMenuItem(ActionType.FlipVertical);
- this.menuImageFlipCenter = new PdnMenuItem(ActionType.FlipCenter);
- this.menuEditSeparator4 = new ToolStripSeparator();
- this.menuImageRotate90CW = new PdnMenuItem(ActionType.Rotate90CW);
- this.menuImageRotate180 = new PdnMenuItem(ActionType.Rotate180);
- this.menuImageRotate90CCW = new PdnMenuItem(ActionType.Rotate90CCW);
- //
- // EditMenu
- //
- this.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- this.menuEditUndo,
- this.menuEditRedo,
- this.menuEditCopy,
- this.menuEditPaste,
- this.menuEditDelete,
- this.menuEditSeparator1,
- this.menuViewZoomIn,
- this.menuViewZoomOut,
- this.menuViewActualSize,
- this.menuViewZoomToWindow,
- this.menuViewZoomToWidth,
- this.menuViewZoomToHeight,
- this.menuEditSeparator2,
- this.menuImageCut,
- this.menuLockZoom,
- this.menuFixedMultiple,
- this.menuEditSeparator3,
- this.menuImageFlipHorizontal,
- this.menuImageFlipVertical,
- this.menuImageFlipCenter,
- this.menuEditSeparator4,
- this.menuImageRotate90CW,
- this.menuImageRotate180,
- this.menuImageRotate90CCW
- }); ;
- this.Name = "Menu.Edit";
- this.Text = PdnResources.GetString("Menu.Edit.Text");
- //
- // 撤销
- //
- this.menuEditUndo.Click += new EventHandler(this.MenuEditUndo_Click);
- //
- // 恢复
- //
- this.menuEditRedo.Click += new EventHandler(this.MenuEditRedo_Click);
- //
- // 复制
- //
- this.menuEditCopy.Click += new EventHandler(this.MenuEditCopy_Click);
- //
- // 粘贴
- //
- this.menuEditPaste.Click += new EventHandler(this.MenuEditPaste_Click);
- //
- // 删除
- //
- this.menuEditDelete.Click += new EventHandler(this.MenuEditDelete_Click);
- //
- // 放大
- //
- this.menuViewZoomIn.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomIn.ShortcutKeyDisplayString");
- this.menuViewZoomIn.NeedWaitKey = true;
- this.menuViewZoomIn.Click += new EventHandler(this.MenuViewZoomIn_Click);
- //
- // 缩小
- //
- this.menuViewZoomOut.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomOut.ShortcutKeyDisplayString");
- this.menuViewZoomOut.NeedWaitKey = true;
- this.menuViewZoomOut.Click += new EventHandler(this.MenuViewZoomOut_Click);
- //
- // 实际大小
- //
- this.menuViewActualSize.NeedWaitKey = true;
- this.menuViewActualSize.Click += new EventHandler(this.MenuViewActualSize_Click);
- //
- // 合适大小
- //
- this.menuViewZoomToWindow.NeedWaitKey = true;
- this.menuViewZoomToWindow.Click += new EventHandler(this.MenuViewZoomToWindow_Click);
- //
- // 合适宽度
- //
- this.menuViewZoomToWidth.NeedWaitKey = true;
- this.menuViewZoomToWidth.Click += new EventHandler(this.MenuViewZoomToWidth_Click);
- //
- //
- // 合适高度
- this.menuViewZoomToHeight.NeedWaitKey = true;
- this.menuViewZoomToHeight.Click += new EventHandler(this.MenuViewZoomToHeight_Click);
- //
- // 图片裁剪
- //
- this.menuImageCut.NeedWaitKey = true;
- this.menuImageCut.AutomaticScript = false;
- this.menuImageCut.Click += new EventHandler(this.MenuImageCut_Click);
- //
- // 锁定扩缩
- //
- this.menuLockZoom.Click += new EventHandler(this.MenuLockZoom_Click);
- //
- // 定倍显示
- //
- this.menuFixedMultiple.Click += new EventHandler(this.MenuFixedMultiple_Click);
- //
- // 水平翻转
- //
- this.menuImageFlipHorizontal.Click += new EventHandler(this.MenuImageFlipHorizontal_Click);
- //
- // 垂直翻转
- //
- this.menuImageFlipVertical.Click += new EventHandler(this.MenuImageFlipVertical_Click);
- //
- // 中心翻转
- //
- this.menuImageFlipCenter.Click += new EventHandler(this.MenuImageFlipCenter_Click);
- //
- // 旋转90度
- //
- this.menuImageRotate90CW.Click += new EventHandler(this.MenuImageRotate90_Click);
- //this.menuImageRotate90CW.ShortcutKeys = Keys.Control | Keys.J;
- //
- // 旋转180度
- //
- this.menuImageRotate180.Click += new EventHandler(this.MenuImageRotate180_Click);
- //this.menuImageRotate180.ShortcutKeys = Keys.Control | Keys.J;
- //
- // 旋转270度
- //
- this.menuImageRotate90CCW.Click += new EventHandler(this.MenuImageRotate270_Click);
- //this.menuImageRotate90CCW.ShortcutKeys = Keys.Control | Keys.J;
- //
- // 加载菜单的文字和icon
- //
- this.LoadNames(this.Name);
- this.LoadIcons();
- }
- protected override void OnDropDownOpening(EventArgs e)
- {
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.ActualSize : false;
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableSize : false;
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableWidth : false;
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.SuitableHeight : false;
- this.menuLockZoom.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.LockZoom : false;
- this.menuFixedMultiple.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.FixedMultiple : false;
- if (AppWorkspace.ActiveDocumentWorkspace == null/* || AppWorkspace.ScriptRunning*/)
- {
- this.menuViewZoomToWindow.Enabled = false;
- this.menuViewActualSize.Enabled = false;
- this.menuEditCopy.Enabled = false;
- this.menuEditDelete.Enabled = false;
- this.menuLockZoom.Checked = false;
- this.menuFixedMultiple.Enabled = false;
- }
- else
- {
- this.menuViewZoomToWindow.Enabled = true;
- //this.menuViewZoomToSelection.Enabled = !AppWorkspace.ActiveDocumentWorkspace.Selection.IsEmpty;
- this.menuViewActualSize.Enabled = true;
- this.menuEditCopy.Enabled = true;
- //this.menuLockZoom.Checked = AppWorkspace.isLockZoom;
- this.menuEditDelete.Enabled = false;
- if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList != null && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
- {
- for (int i = 0; i < AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count; i++)
- {
- if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].Selected)
- {
- this.menuEditDelete.Enabled = true;
- break;
- }
- }
- }
- //this.menuViewZoomToWindow.Checked = (AppWorkspace.ActiveDocumentWorkspace.ZoomBasis == ZoomBasis.FitToWindow);
- this.menuFixedMultiple.Enabled = true;
- }
- if (copyedBitmap != null/* && !AppWorkspace.ScriptRunning*/)
- this.menuEditPaste.Enabled = true;
- else
- this.menuEditPaste.Enabled = false;
- //this.menuEditDelete.Enabled = selection;
- //this.menuEditCut.Enabled = selection && bitmapLayer;
- // find out if there's anything on the clipboard that we can use
- //bool isClipImageAvailable = Utility.IsClipboardImageAvailable();
- //this.menuEditPaste.Enabled = isClipImageAvailable && (AppWorkspace.ActiveDocumentWorkspace != null);
- /**
- if (!this.menuEditPaste.Enabled)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- bool canHandle;
- try
- {
- IDataObject pasted = Clipboard.GetDataObject();
- }
- catch (ExternalException)
- {
- canHandle = false;
- }
- if (canHandle)
- {
- this.menuEditPaste.Enabled = true;
- }
- }
- }**/
- if (AppWorkspace.ActiveDocumentWorkspace != null/* && !AppWorkspace.ScriptRunning*/)
- {
- 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
- this.menuEditRedo.Enabled = (AppWorkspace.ActiveDocumentWorkspace.undoManager.CanRedo);// (AppWorkspace.ActiveDocumentWorkspace.History.RedoStack.Count > 0);
- }
- else
- {
- this.menuEditUndo.Enabled = false;
- this.menuEditRedo.Enabled = false;
- }
- //this.RecursiveData(this.DropDownItems);
- base.OnDropDownOpening(e);
- }
- /// <summary>
- /// 撤销
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuEditUndo_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.undoManager.Undo();
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- /**
- if (AppWorkspace.ActiveDocumentWorkspace != null &&
- !AppWorkspace.ActiveDocumentWorkspace.IsMouseCaptured())
- {
- AppWorkspace.ActiveDocumentWorkspace.PerformAction(new HistoryUndoAction());
- }**/
- }
- /// <summary>
- /// 恢复
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuEditRedo_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.undoManager.Redo();
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- /**
- if (AppWorkspace.ActiveDocumentWorkspace != null &&
- !AppWorkspace.ActiveDocumentWorkspace.IsMouseCaptured())
- {
- AppWorkspace.ActiveDocumentWorkspace.PerformAction(new HistoryRedoAction());
- }**/
- }
- /// <summary>
- /// 复制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuEditCopy_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace!=null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- copyedBitmap = new Bitmap(temp.Width, temp.Height);
- Graphics graphics = Graphics.FromImage(copyedBitmap);
- graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
-
- if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
- {
- //获取裁剪的矩形区域
- List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
- ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
- RectangleF cutRectangle = imageCutDraw.Rectangle;
- copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
- }
- }
- }
- /// <summary>
- /// 粘贴
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuEditPaste_Click(object sender, EventArgs e)
- {
- if (copyedBitmap != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(copyedBitmap);
- dw.Document = document;
- //图片命名
- nameNum++;
- int numLength = nameNum.ToString().Length;
- string joinName = "";
- switch (numLength)
- {
- case 1:
- joinName = "00" + nameNum;
- break;
- case 2:
- joinName = "0" + nameNum;
- break;
- default:
- joinName = nameNum.ToString();
- break;
- }
- dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
- dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text")+"-" + joinName;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuEditDelete_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if(AppWorkspace.ActiveDocumentWorkspace.GraphicsList != null && AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count > 0)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- for (int i = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.Count - 1; i >= 0; i--)
- {
- if(AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].Selected == true)
- {
- //对数字标记做单独处理
- if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i].drawToolType == DrawToolType.DrawNumberMark)
- {
- DrawNumberMark drawNumberMark = (DrawNumberMark)AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i];
- List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawNumberMark);
- if (objList != null && objList.Count > 0)
- {
- for (int j = 0; j < objList.Count; j++)
- {
- DrawNumberMark modifyNum = (DrawNumberMark)objList[j];
- if (modifyNum.nowNum > drawNumberMark.nowNum)
- {
- modifyNum.nowNum -= 1;
- }
- }
- }
- }
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.RemoveObj(AppWorkspace.ActiveDocumentWorkspace.GraphicsList[i]);
- }
- }
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- private void MenuViewZoomIn_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.ZoomIn();
- }
- }
- private void MenuViewZoomOut_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.ZoomOut();
- }
- }
- private void MenuViewActualSize_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- if (!AppWorkspace.ActiveDocumentWorkspace.ActualSize)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActualSize = !AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- }
- else
- {
- AppWorkspace.ActiveDocumentWorkspace.ActualSize = !AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- AppWorkspace.UpdateBottomButtonSelectionStatus();
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- }
- private void MenuViewZoomToWindow_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- if (!AppWorkspace.ActiveDocumentWorkspace.SuitableSize)
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableSize = !AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- else
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableSize = !AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- AppWorkspace.UpdateBottomButtonSelectionStatus();
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- }
- private void MenuViewZoomToWidth_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- if (!AppWorkspace.ActiveDocumentWorkspace.SuitableWidth)
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = !AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- else
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = !AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWidth;
- }
- }
- private void MenuViewZoomToHeight_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- if (!AppWorkspace.ActiveDocumentWorkspace.SuitableHeight)
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = !AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- AppWorkspace.ActiveDocumentWorkspace.SuitableWidth = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableWidth, "ZoomToWidth");
- this.menuViewZoomToWidth.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableWidth;
- AppWorkspace.ActiveDocumentWorkspace.SuitableSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableSize, "ZoomToWindow");
- this.menuViewZoomToWindow.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableSize;
- AppWorkspace.ActiveDocumentWorkspace.ActualSize = false;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.ActualSize, "ActualSize");
- this.menuViewActualSize.Checked = AppWorkspace.ActiveDocumentWorkspace.ActualSize;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- else
- {
- AppWorkspace.ActiveDocumentWorkspace.SuitableHeight = !AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.SuitableHeight, "ZoomToHeight");
- this.menuViewZoomToHeight.Checked = AppWorkspace.ActiveDocumentWorkspace.SuitableHeight;
- this.AppWorkspace.UpdateBottomButtonSelectionStatus();
- }
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToHeight;
- }
- }
- private void MenuImageCut_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.ImageCut;
- }
- }
- /// <summary>
- /// 锁定扩缩
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuLockZoom_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.LockZoom = !AppWorkspace.ActiveDocumentWorkspace.LockZoom;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.LockZoom, "LockZoom");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.LockZoom, "LockZoom");
- this.menuLockZoom.Checked = !this.menuLockZoom.Checked;
- AppWorkspace.UpdateBottomButtonSelectionStatus();
- AppWorkspace.isLockZoom = this.menuLockZoom.Checked;
- AppWorkspace.lockScaleRatio = AppWorkspace.ActiveDocumentWorkspace.ScaleFactor.Ratio;
- }
- }
- /// <summary>
- /// 定倍显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuFixedMultiple_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.ActiveDocumentWorkspace.FixedMultiple = !AppWorkspace.ActiveDocumentWorkspace.FixedMultiple;
- this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.FixedMultiple, "FixedMultiple");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.FixedMultiple, "FixedMultiple");
- this.menuFixedMultiple.Checked = AppWorkspace.ActiveDocumentWorkspace.FixedMultiple;
- int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
- if (dotPitch <= 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.hedotdistancefirstandthenadjustthedisplayoperation.Text")+"!");
- return;
- }
- mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
- if(screenList == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Failedtogetpointdistanceinformation.Text"));
- return;
- }
- double pointPitch = 0;
- try
- {
- pointPitch = double.Parse(screenList.point_pitch);//获取点距
- }
- catch (System.Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pointdistanceinformationexception.Text"));
- return;
- }
- if (pointPitch <= 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pointdistanceinformationexception.Text"));
- return;
- }
- string imgName = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();//原始图片名
- Bitmap oldBit = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();//原始图片
- //获取系统的毫米标尺
- double unitLength = 0;
- //AppWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
- unitLength = AppWorkspace.ActiveDocumentWorkspace.GetRuler(MeasurementUnit.Millimeter);
- if (unitLength == 0)
- unitLength = 1;
- int oldWidth = oldBit.Width;
- int oldHeight = oldBit.Height;
- int targetWidth = 0;
- int targetHeight = 0;
- if (oldWidth <= 1 || oldHeight <= 1)//像素最小为1,之后不再处理
- return;
- double pantographRatio = unitLength / pointPitch;//缩放比
- double aspectRatio = oldWidth / (oldHeight * 1d);//宽高比
- if (oldWidth <= oldHeight)
- {
- if (Startup.instance.ruleDB != null)
- targetWidth = (int)(oldWidth * pantographRatio * (double)Startup.instance.ruleDB.gain_multiple);
- else
- targetWidth = (int)(oldWidth * pantographRatio);
- if (targetWidth < 1 || targetWidth > oldWidth)//像素值异常不做处理
- return;
- targetHeight = (int)(targetWidth / aspectRatio);
-
- }
- else
- {
- if (Startup.instance.ruleDB != null)
- targetHeight = (int)(oldHeight * pantographRatio * (double)Startup.instance.ruleDB.gain_multiple);
- else
- targetHeight = (int)(oldHeight * pantographRatio);
- if (targetHeight < 1 || targetHeight > oldHeight)//像素值异常不做处理
- return;
- targetWidth = (int)(targetHeight * aspectRatio);
- }
- //缩放图片
- using (Bitmap targetBit = new Bitmap(targetWidth, targetHeight))
- {
- using (Graphics g = Graphics.FromImage(targetBit))
- {
- g.DrawImage(oldBit, new Rectangle(0, 0, targetWidth, targetHeight), new Rectangle(0, 0, oldWidth, oldHeight), GraphicsUnit.Pixel);
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(targetBit);
- dw.Document = document;
- dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
- dw.fileText = imgName;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- }
- }
- }
- }
- /// <summary>
- /// 水平镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageFlipHorizontal_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.HorizontalMirroringButton_Click(sender, null);
- }
- }
- /// <summary>
- /// 垂直镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageFlipVertical_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.VerticalMirrorButton_Click(sender, null);
- }
- }
- /// <summary>
- /// 中心镜像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageFlipCenter_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- AppWorkspace.CenterMirrorButton_Click(sender, null);
- }
- }
- /// <summary>
- /// 旋转90度
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageRotate90_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- Mat dst = new Mat();
- GeometryIntent.ImageRotate(src, dst, FlipMode.Y);
- if (AppWorkspace.ScriptRunning)
- {
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- AppWorkspace.ActiveDocumentWorkspace.Document = document;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 旋转180度
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageRotate180_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- Mat dst = new Mat();
- GeometryIntent.ImageRotate(src, dst, FlipMode.XY);
- if (AppWorkspace.ScriptRunning)
- {
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- AppWorkspace.ActiveDocumentWorkspace.Document = document;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 旋转270度
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MenuImageRotate270_Click(object sender, EventArgs e)
- {
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (AppWorkspace.startScriptRecording)
- {
- AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
- }
- Mat src = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap());
- Mat dst = new Mat();
- GeometryIntent.ImageRotate(src, dst, FlipMode.X);
- if (AppWorkspace.ScriptRunning)
- {
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- dw.Document = document;
- dw.fileText = PdnResources.GetString("Menu.Edit.Text") + "-" + ((PdnMenuItem)sender).Text + "-" + Startup.instance.step_length;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- else
- {
- ZoomBasis zoom = AppWorkspace.ActiveDocumentWorkspace.ZoomBasis;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(dst));
- AppWorkspace.ActiveDocumentWorkspace.Document = document;
- AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = zoom;
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- }
- }
- }
- }
|