using PaintDotNet.Annotation.Enum;
using PaintDotNet.Base;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Data.Param;
using PaintDotNet.ImageCollect;
using PaintDotNet.Instrument;
using PaintDotNet.SystemLayer;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace PaintDotNet.Menus
{
///
/// 工具菜单
///
internal sealed class ToolsMenu : PdnMenuItem
{
//网格
private PdnMenuItem menuToolsGridLine;
//辅助线
private PdnMenuItem menuToolsAuxiliaryLine;
//视图标尺
private PdnMenuItem menuToolsViewRuler;
//分隔线
private ToolStripSeparator menuToolsSeperator1;
//捕获窗口
private PdnMenuItem menuToolsCaptureWindow;
//捕获图像
private PdnMenuItem menuToolsCapturePicture;
//分割线
private ToolStripSeparator menuToolsSeperator2;
//直方图
private PdnMenuItem menuToolsHistogram;
//像素跟踪
private PdnMenuItem menuToolsPixelTracking;
//三维灰度
private PdnMenuItem menuToolsSurfacePlot;
//三维展示
private PdnMenuItem menuToolsSurfacePlotShow;
//图像索引
private PdnMenuItem menuToolsImageIndex;
//分隔线
private ToolStripSeparator menuToolsSeperator3;
//脚本
private PdnMenuItem menuToolsScript;
//工作流程
private PdnMenuItem menuToolsWorkFlow;
//快捷工具
private PdnMenuItem menuToolsFast;
//分隔线
private ToolStripSeparator menuToolsSeperator4;
//划痕处理
private PdnMenuItem menuToolsScratchTreatment;
//污迹处理
private PdnMenuItem menuToolsSmudgeTreatment;
//分隔线
private ToolStripSeparator menuToolsSeperator5;
//分栏显示
private PdnMenuItem menuToolsColumnDisplay;
//图片对比
private PdnMenuItem menuToolsPictureComparison;
//自定义界面
private PdnMenuItem menuToolsCustomInterface;
//生成快捷方式
private PdnMenuItem menuToolsCreateShortcut;
//图片信息
private PdnMenuItem menuToolsImageInfo;
//分隔线
private ToolStripSeparator menuToolsSeperator6;
//项目工程
private PdnMenuItem menuToolsOpenProject;
//添加到工程
private PdnMenuItem menuToolsAddToProject;
//分隔线
private ToolStripSeparator menuToolsSeperator7;
//模板管理
private PdnMenuItem menuToolsTemplateManager;
//生成报告
private PdnMenuItem menuToolsCreateReport;
//分隔线
private ToolStripSeparator menuToolsSeperator8;
//重新启动
private PdnMenuItem menuToolsSelfRestart;
//恢复图片
private PdnMenuItem menuToolsRestoreImages;
//
// 以下是非模态对话框
//
//脚本管理窗口
private ScriptManageDialog scriptManageDialog;
public ToolsMenu(int menuId)
{
InitializeComponent();
this.MenuId = menuId;
}
private void InitializeComponent()
{
this.menuToolsGridLine = new PdnMenuItem(ActionType.GridLine, true);
this.menuToolsAuxiliaryLine = new PdnMenuItem(ActionType.AuxiliaryLine, true);
this.menuToolsViewRuler = new PdnMenuItem(ActionType.ViewRuler, true);
this.menuToolsSeperator1 = new ToolStripSeparator();
this.menuToolsCaptureWindow = new PdnMenuItem(ActionType.CaptureWindow);
this.menuToolsCapturePicture = new PdnMenuItem(ActionType.CapturePicture);
this.menuToolsSeperator2 = new ToolStripSeparator();
this.menuToolsHistogram = new PdnMenuItem(ActionType.Histogram);
this.menuToolsPixelTracking = new PdnMenuItem(ActionType.PixelTracking);
this.menuToolsSurfacePlot = new PdnMenuItem(ActionType.SurfacePlot);
this.menuToolsSurfacePlotShow = new PdnMenuItem(ActionType.SurfacePlotShow);
this.menuToolsImageIndex = new PdnMenuItem(ActionType.ImageIndex);
this.menuToolsSeperator3 = new ToolStripSeparator();
this.menuToolsScript = new PdnMenuItem(ActionType.Script);
this.menuToolsWorkFlow = new PdnMenuItem(ActionType.WorkFlow);
this.menuToolsFast = new PdnMenuItem(ActionType.ToolsFast);
this.menuToolsSeperator4 = new ToolStripSeparator();
this.menuToolsScratchTreatment = new PdnMenuItem(ActionType.ScratchTreatment);
this.menuToolsSmudgeTreatment = new PdnMenuItem(ActionType.SmudgeTreatment);
this.menuToolsSeperator5 = new ToolStripSeparator();
this.menuToolsColumnDisplay = new PdnMenuItem(ActionType.ColumnDisplay);
this.menuToolsPictureComparison = new PdnMenuItem(ActionType.PictureComparison);
this.menuToolsCustomInterface = new PdnMenuItem(ActionType.CustomInterface);
this.menuToolsCreateShortcut = new PdnMenuItem(ActionType.CreateShortcut);
this.menuToolsImageInfo = new PdnMenuItem(ActionType.ImageInfo);
this.menuToolsSeperator6 = new ToolStripSeparator();
this.menuToolsOpenProject = new PdnMenuItem(ActionType.OpenProject);
this.menuToolsAddToProject = new PdnMenuItem(ActionType.AddToProject);
this.menuToolsSeperator7 = new ToolStripSeparator();
this.menuToolsTemplateManager = new PdnMenuItem(ActionType.TemplateManager);
this.menuToolsCreateReport = new PdnMenuItem(ActionType.CreateReport);
this.menuToolsSeperator8 = new ToolStripSeparator();
this.menuToolsRestoreImages = new PdnMenuItem(ActionType.RestoreImages);
this.menuToolsSelfRestart = new PdnMenuItem(ActionType.SelfRestart);
//
// ToolsMenu
//
this.DropDownItems.AddRange(
new ToolStripItem[]
{
this.menuToolsGridLine,
this.menuToolsAuxiliaryLine,
this.menuToolsViewRuler,
this.menuToolsSeperator1,
this.menuToolsCaptureWindow,
this.menuToolsCapturePicture,
this.menuToolsSeperator2,
this.menuToolsHistogram,
this.menuToolsPixelTracking,
this.menuToolsSurfacePlot,
this.menuToolsSurfacePlotShow,
this.menuToolsImageIndex,
this.menuToolsSeperator3,
this.menuToolsScript,
this.menuToolsWorkFlow,
this.menuToolsFast,
this.menuToolsSeperator4,
this.menuToolsScratchTreatment,
this.menuToolsSmudgeTreatment,
this.menuToolsSeperator5,
this.menuToolsColumnDisplay,
this.menuToolsPictureComparison,
this.menuToolsCustomInterface,
this.menuToolsCreateShortcut,
this.menuToolsImageInfo,
this.menuToolsSeperator6,
this.menuToolsOpenProject,
this.menuToolsAddToProject,
this.menuToolsSeperator7,
this.menuToolsTemplateManager,
this.menuToolsCreateReport,
this.menuToolsSeperator8,
this.menuToolsRestoreImages,
this.menuToolsSelfRestart
});
this.Name = "Menu.Tools";
this.Text = PdnResources.GetString("Menu.Tools.Text");
//
// 网格
//
this.menuToolsGridLine.Click += new EventHandler(MenuToolsGridLine_Click);
//
// 辅助线
//
this.menuToolsAuxiliaryLine.Click += new EventHandler(MenuToolsAuxiliaryLine_Click);
//
// 视图标尺
//
this.menuToolsViewRuler.Click += new EventHandler(MenuToolsViewRuler_Click);
//
// 捕获窗口
//
this.menuToolsCaptureWindow.Click += new EventHandler(MenuToolsCaptureWindow_Click);
//
// 捕获图片
//
this.menuToolsCapturePicture.Click += new EventHandler(MenuToolsCapturePicture_Click);
//
// 直方图
//
this.menuToolsHistogram.Click += new EventHandler(MenuToolsHistogram_Click);
// 像素跟踪
//
this.menuToolsPixelTracking.Click += new EventHandler(MenuToolsPixelTracking_Click);
//
// 三维灰度
//
this.menuToolsSurfacePlot.Click += new EventHandler(MenuToolsSurfacePlot_Click);
//
// 三维展示
//
this.menuToolsSurfacePlotShow.Click += new EventHandler(MenuToolsSurfacePlotShow_Click);
//
// 图像索引
//
this.menuToolsImageIndex.Click += new EventHandler(MenuToolsImageIndex_Click);
//
// 脚本管理
//
this.menuToolsScript.Click += new EventHandler(MenuToolsScript_Click);
//
// 工作流程
//
this.menuToolsWorkFlow.Click += new EventHandler(MenuToolsWorkFlow_Click);
//
// 快捷菜单
//
this.menuToolsFast.Click += new EventHandler(MenuToolsFast_Click);
//
// 划痕处理
//
this.menuToolsScratchTreatment.Click += new EventHandler(MenuToolsScratchTreatment_Click);
//
// 污迹处理
//
this.menuToolsSmudgeTreatment.Click += new EventHandler(MenuToolsSmudgeTreatment_Click);
//
// 分栏显示
//
this.menuToolsColumnDisplay.Click += new EventHandler(MenuToolsColumnDisplay_Click);
//
// 图片对比
//
this.menuToolsPictureComparison.Click += new EventHandler(MenuToolsPictureComparison_Click);
//
// 自定义界面
//
this.menuToolsCustomInterface.Click += new EventHandler(MenuToolsCustomInterface_Click);
//
// 生成快捷方式
//
this.menuToolsCreateShortcut.Click += new EventHandler(MenuToolsCreateShortcut_Click);
//
// 图片信息
//
this.menuToolsImageInfo.Click += new EventHandler(MenuToolsImageInfo_Click);
//
// 项目工程
//
this.menuToolsOpenProject.Click += new EventHandler(MenuToolsOpenProject_Click);
//
// 添加到工程
//
this.menuToolsAddToProject.Click += new EventHandler(MenuToolsAddToProject_Click);
//
// 模板管理
//
this.menuToolsTemplateManager.Click += new EventHandler(MenuToolsTemplateManager_Click);
//
// 生成报告
//
this.menuToolsCreateReport.Click += new EventHandler(MenuToolsCreateReport_Click);
//
// 恢复图片
//
this.menuToolsRestoreImages.Click += new EventHandler(MenuToolsRestoreImages_Click);
//
// 重新启动
//
this.menuToolsSelfRestart.Click += new EventHandler(MenuToolsSelfRestart_Click);
//
// 加载菜单的文字和icon
//
this.LoadNames(this.Name);
this.LoadIcons();
}
protected override void OnDropDownOpening(EventArgs e)
{
this.menuToolsGridLine.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.GridLineEnabled : false;
this.menuToolsAuxiliaryLine.Checked = AppWorkspace.ActiveDocumentWorkspace != null ? AppWorkspace.ActiveDocumentWorkspace.AuxiliaryLineEnabled : false;
this.menuToolsViewRuler.Checked = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
this.menuToolsSmudgeTreatment.Checked = AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible;
this.menuToolsScratchTreatment.Checked = AppWorkspace.Widgets.ScratchTreatmentDialog.Visible;
this.menuToolsOpenProject.Checked = AppWorkspace.Widgets.ProjectEngineering.Visible;
this.menuToolsWorkFlow.Checked = AppWorkspace.Widgets.WorkFlowDialog.Visible;
this.menuToolsHistogram.Checked = AppWorkspace.Widgets.HistogramDialog.Visible;
this.menuToolsPixelTracking.Checked = AppWorkspace.Widgets.PixelTrackingDialog.Visible;
this.menuToolsImageIndex.Checked = AppWorkspace.Widgets.ImageIndexDialog.Visible;
if (SurfacePlotWindow.form != null)
this.menuToolsSurfacePlot.Checked = true;
else
this.menuToolsSurfacePlot.Checked = false;
base.OnDropDownOpening(e);
}
///
/// 网格
///
///
///
private void MenuToolsGridLine_Click(object sender, EventArgs e)
{
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.ActiveDocumentWorkspace.GridLineEnabled = !AppWorkspace.ActiveDocumentWorkspace.GridLineEnabled;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.GridLineEnabled, "GridLine");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.GridLineEnabled, "GridLine");
AppWorkspace.UpdateBottomButtonSelectionStatus();
AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
}
///
/// 辅助线
///
///
///
private void MenuToolsAuxiliaryLine_Click(object sender, EventArgs e)
{
if(AppWorkspace.ActiveDocumentWorkspace!=null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.ActiveDocumentWorkspace.AuxiliaryLineEnabled = !Settings.CurrentUser.GetBoolean(SettingNames.DrawAuxiliaryLine, false);
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.AuxiliaryLineEnabled, "AuxiliaryLine");
Settings.CurrentUser.SetBoolean(SettingNames.DrawAuxiliaryLine, AppWorkspace.ActiveDocumentWorkspace.AuxiliaryLineEnabled);
AppWorkspace.UpdateBottomButtonSelectionStatus();
AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
}
///
/// 隐藏显示标尺
///
///
///
private void MenuToolsViewRuler_Click(object sender, EventArgs e)
{
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.ActiveDocumentWorkspace.RulersEnabled = !Settings.CurrentUser.GetBoolean(SettingNames.Rulers, false);
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.RulersEnabled, "ViewRuler");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.ActiveDocumentWorkspace.RulersEnabled, "ViewRuler");
Settings.CurrentUser.SetBoolean(SettingNames.Rulers, AppWorkspace.ActiveDocumentWorkspace.RulersEnabled);
}
}
///
/// 捕获屏幕
///
///
///
private void MenuToolsCaptureWindow_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
Bitmap myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
g.Dispose();
DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(Camera.Tools.ToMat(myImage));
dw.Document = document;
dw.xmlSaveModel = Startup.instance.ruleDB;
dw.InitRulerInfo();
dw.fileText = PdnResources.GetString("Menu.Tools.CaptureWindow.Text")+"-00" + Startup.instance.step_length;
AppWorkspace.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
///
/// 捕获图片,这个功能临时当作copy的功能
/// 但是这个功能最终是和定倍有关系的
///
///
///
private void MenuToolsCapturePicture_Click(object sender, EventArgs e)
{
if(AppWorkspace.ActiveDocumentWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.ActiveDocumentWorkspace.ClearDoubleBuffer();
Document document = Document.FromImageMat(Camera.Tools.ToMat((Bitmap)(AppWorkspace.ActiveDocumentWorkspace.GetClientRangePic())));
DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
dw.Document = document;
dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
dw.fileText = PdnResources.GetString("Menu.Tools.CapturePicture.Text") +"-00" + Startup.instance.step_length;
AppWorkspace.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
}
///
/// 直方图
///
///
///
private void MenuToolsHistogram_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
AppWorkspace.Widgets.HistogramDialog.Visible = !AppWorkspace.Widgets.HistogramDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.HistogramDialog.Visible, "Histogram");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.HistogramDialog.Visible, "Histogram");
this.menuToolsHistogram.Checked = AppWorkspace.Widgets.HistogramDialog.Visible;
}
else
{
if (AppWorkspace.Widgets.HistogramDialog.Visible == false)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseopenthepicture.Text"));//后可以使用直方图
}
else
AppWorkspace.Widgets.HistogramDialog.Visible = false;
}
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
if (this.AppWorkspace.ActiveDocumentWorkspace.best)
this.AppWorkspace.ActiveDocumentWorkspace.buttonType = 0;
else if (this.AppWorkspace.ActiveDocumentWorkspace.maxMin)
this.AppWorkspace.ActiveDocumentWorkspace.buttonType = 1;
else if (this.AppWorkspace.ActiveDocumentWorkspace.gamma45)
this.AppWorkspace.ActiveDocumentWorkspace.buttonType = 2;
else if (this.AppWorkspace.ActiveDocumentWorkspace.origin)
this.AppWorkspace.ActiveDocumentWorkspace.buttonType = 3;
this.AppWorkspace.RefreshHistogram();
AppWorkspace.ActiveDocumentWorkspace.Focus();
}
//using (HistogramDialog dialog = new HistogramDialog(AppWorkspace))
//{
// dialog.ShowDialog();
//}
}
///
/// 像素跟踪
///
///
///
private void MenuToolsPixelTracking_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.Widgets.PixelTrackingDialog.Visible = !AppWorkspace.Widgets.PixelTrackingDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.PixelTrackingDialog.Visible, "PixelTracking");
this.menuToolsPixelTracking.Checked = AppWorkspace.Widgets.PixelTrackingDialog.Visible;
if (CameraPreviewDialog.cameraPreviewDialog != null)
CameraPreviewDialog.cameraPreviewDialog.documentWorkspace.Focus();
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
AppWorkspace.ActiveDocumentWorkspace.Focus();
}
}
///
/// 三维灰度
///
///
///
private void MenuToolsSurfacePlot_Click(object sender, EventArgs e)
{
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
if (SurfacePlotWindow.form != null)
{
SurfacePlotWindow.form.Close();
this.menuToolsSurfacePlot.Checked = false;
}
else
{
SurfacePlotWindow.Run(this.AppWorkspace);
this.menuToolsSurfacePlot.Checked = true;
}
}
/*RegularTetrahedron3D*/
else
MessageBox.Show(PdnResources.GetString("Menu.Pleaseopenthepicture.Text"));
}
///
/// 三维显示
///
///
///
private void MenuToolsSurfacePlotShow_Click(object sender, EventArgs e)
{
using (ImageThreeDShowDialog imageDepthExtensionDialog = new ImageThreeDShowDialog(this.AppWorkspace))
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
imageDepthExtensionDialog.StartPosition = FormStartPosition.CenterScreen;
imageDepthExtensionDialog.ShowDialog();
}
}
///
/// 图像索引
///
///
///
private void MenuToolsImageIndex_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.Widgets.ImageIndexDialog.Visible = !AppWorkspace.Widgets.ImageIndexDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.ImageIndexDialog.Visible, "ImageIndex");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.ImageIndexDialog.Visible, "ImageIndex");
AppWorkspace.Widgets.ImageIndexDialog.Width = AppWorkspace.Widgets.ImageIndexDialog.fromMinSize;
this.menuToolsImageIndex.Checked = AppWorkspace.Widgets.ImageIndexDialog.Visible;
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
AppWorkspace.ActiveDocumentWorkspace.Focus();
}
//ImageIndexDialog dialog = new ImageIndexDialog(AppWorkspace,816);
//dialog.ShowDialog();
//Form form = Application.OpenForms["ImageIndexDialog"];//尝试获取已经弹出的窗口对象
//FloatingFormMethod.ShowFloatForm(form, form == null ? new ImageIndexDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
//this.menuToolsImageIndex.Checked = AppWorkspace.Widgets.ImageIndexDialog.Visible;
}
///
/// 脚本
///
///
///
private void MenuToolsScript_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
scriptManageDialog = (ScriptManageDialog)Application.OpenForms["ScriptManageDialog"];//尝试获取已经弹出的窗口对象
bool nullFLag = false;
if (scriptManageDialog == null)
{
nullFLag = true;
scriptManageDialog = new ScriptManageDialog(AppWorkspace);
AppWorkspace.ScriptDialog = scriptManageDialog;
}
FloatingFormMethod.ShowFloatForm(nullFLag ? null : scriptManageDialog, scriptManageDialog, AppWorkspace);
//if (scriptManageDialog == null)
//{
// scriptManageDialog = new ScriptManageDialog(AppWorkspace);
// AppWorkspace.ScriptDialog = scriptManageDialog;
// scriptManageDialog.StartPosition = FormStartPosition.CenterScreen;
// scriptManageDialog.Show();
//}
//else
//{
// if (!scriptManageDialog.IsDisposed)
// {
// scriptManageDialog.WindowState = FormWindowState.Normal;
// }
// else
// {
// scriptManageDialog = new ScriptManageDialog(AppWorkspace);
// AppWorkspace.ScriptDialog = scriptManageDialog;
// scriptManageDialog.StartPosition = FormStartPosition.CenterScreen;
// scriptManageDialog.Show();
// }
//}
}
///
/// 工作流程
///
///
///
private void MenuToolsWorkFlow_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.Widgets.WorkFlowDialog.Visible = !AppWorkspace.Widgets.WorkFlowDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.WorkFlowDialog.Visible, "WorkFlow");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.WorkFlowDialog.Visible, "WorkFlow");
this.menuToolsWorkFlow.Checked = AppWorkspace.Widgets.WorkFlowDialog.Visible;
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
AppWorkspace.ActiveDocumentWorkspace.Focus();
}
}
///
/// 快捷菜单
///
///
///
private void MenuToolsFast_Click(object sender, EventArgs e)
{
if (AppWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.toolsPanel.Visible = !AppWorkspace.toolsPanel.Visible;
}
}
///
/// 划痕处理
///
///
///
private void MenuToolsScratchTreatment_Click(object sender, EventArgs e)
{
if (AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible)
AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible = false;
if (AppWorkspace.ActiveDocumentWorkspace != null)
AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawScratchTreatmentLine;
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.menuToolsSmudgeTreatment.Checked = AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible;
AppWorkspace.Widgets.ScratchTreatmentDialog.Visible = !AppWorkspace.Widgets.ScratchTreatmentDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.menuToolsScratchTreatment.Checked = AppWorkspace.Widgets.ScratchTreatmentDialog.Visible;
}
}
///
/// 污迹处理
///
///
///
private void MenuToolsSmudgeTreatment_Click(object sender, EventArgs e)
{
//if (AppWorkspace.ActiveDocumentWorkspace != null)
//{
// AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeRectangle;// DrawSmudgePolygon;// DrawSmudgeEllipse;//
//}
if (AppWorkspace.Widgets.ScratchTreatmentDialog.Visible)
AppWorkspace.Widgets.ScratchTreatmentDialog.Visible = false;
AppWorkspace.Widgets.SmudgeTreatmentDialog.RefreshActiveTool();
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.ScratchTreatmentDialog.Visible, "ScratchTreatment");
this.menuToolsScratchTreatment.Checked = AppWorkspace.Widgets.ScratchTreatmentDialog.Visible;
AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible = !AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible;
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible, "SmudgeTreatment");
this.menuToolsSmudgeTreatment.Checked = AppWorkspace.Widgets.SmudgeTreatmentDialog.Visible;
}
}
///
/// 自定义界面
///
///
///
private void MenuToolsCustomInterface_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
CustomInterfaceDialog dialog = new CustomInterfaceDialog(AppWorkspace);
dialog.ShowDialog();
}
///
/// 软件重启
///
///
///
private void MenuToolsSelfRestart_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.orestartthesoftwareModifiedimageswillnotbesaved.Text")+"!", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
if (dr == DialogResult.OK)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
FileOperationHelper.DeleteFolder(Application.StartupPath + "\\BackupImages");//删除备份文件
FileOperationHelper.DeleteFolder(Application.StartupPath + "\\BackupImagesTemp");//删除备份文件
Application.ExitThread();
Restart();
}
//Startup.CloseApplication();
//SystemLayer.Shell.RestartApplication();
}
///
/// 恢复图片
///
///
///
private void MenuToolsRestoreImages_Click(object sender, EventArgs e)
{
List imageList = FileOperationHelper.RestoreImages();
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
if (imageList != null && imageList.Count > 0)
{
foreach (string imgName in imageList)
{
//Document document = Document.FromImage(Image.FromFile(imgName));
Document document = Document.FromImageMat(new OpenCvSharp.Mat(imgName));
DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
dw.Document = document;
dw.fileText = Path.GetFileNameWithoutExtension(imgName);
AppWorkspace.ActiveDocumentWorkspace = dw;
}
}
else
MessageBox.Show(PdnResources.GetString("Menu.Therearenopicturestorecover.Text"));
}
private void Restart()
{
Thread thtmp = new Thread(new ParameterizedThreadStart(run));
object appName = Application.ExecutablePath;
Thread.Sleep(2000);
thtmp.Start(appName);
}
private void run(Object obj)
{
Process ps = new Process();
ps.StartInfo.FileName = obj.ToString();
ps.Start();
}
///
/// 分栏显示
///
///
///
private void MenuToolsColumnDisplay_Click(object sender, EventArgs e)
{
using (ColumnsShowDialog columnsShowDialog = new ColumnsShowDialog(this.AppWorkspace))
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
columnsShowDialog.StartPosition = FormStartPosition.CenterScreen;
columnsShowDialog.ShowDialog();
}
}
///
/// 图片信息
///
///
///
private void MenuToolsImageInfo_Click(object sender, EventArgs e)
{
using (ImageInformation imageInformation = new ImageInformation(this.AppWorkspace))
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
imageInformation.StartPosition = FormStartPosition.CenterScreen;
imageInformation.ShowDialog();
}
}
///
/// 项目工程
///
///
///
private void MenuToolsOpenProject_Click(object sender, EventArgs e)
{
AppWorkspace.Widgets.ProjectEngineering.Visible = !AppWorkspace.Widgets.ProjectEngineering.Visible;
if (AppWorkspace.ActiveDocumentWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
this.AppWorkspace.toolBar.RefreshBtnSelect(AppWorkspace.Widgets.ProjectEngineering.Visible, "OpenProject");
this.AppWorkspace.toolsPanel.RefreshBtnSelect(AppWorkspace.Widgets.ProjectEngineering.Visible, "OpenProject");
this.menuToolsOpenProject.Checked = AppWorkspace.Widgets.ProjectEngineering.Visible;
AppWorkspace.ActiveDocumentWorkspace.Focus();
}
}
///
/// 添加到工程
/// 1、如果项目工程选择了常规操作,可以任意添加
/// 2、如果项目工程选择了通用分析、专用分析,则必须选择其下的文件夹或项目进行添加
///
///
///
private void MenuToolsAddToProject_Click(object sender, EventArgs e)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
//如果选择了文件夹,则添加到工程
if (AppWorkspace.Widgets.ProjectEngineering.TreeNode!=null)
{
AppWorkspace.Widgets.ProjectEngineering.AddToProject();
}
//如果没有选择则提示,用户选择文件夹,并显示出来项目工程窗口
else
{
AppWorkspace.Widgets.ProjectEngineering.Visible = true;
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecttheprojectprojectnode.Text"));
}
}
///
/// 图像对比
///
///
///
private void MenuToolsPictureComparison_Click(object sender, EventArgs e)
{
using (ImageComparison imageComparison = new ImageComparison(this.AppWorkspace))
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
imageComparison.StartPosition = FormStartPosition.CenterScreen;
imageComparison.ShowDialog();
}
}
///
/// 生成快捷方式
///
///
///
private void MenuToolsCreateShortcut_Click(object sender, EventArgs e)
{
if (AppWorkspace != null)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
AppWorkspace.DoSaveLnk();
}
}
///
/// 模板管理
///
///
///
private void MenuToolsTemplateManager_Click(object sender, EventArgs e)
{
using (TemplateManagerDialog dialog = new TemplateManagerDialog())
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
dialog.StartPosition = FormStartPosition.CenterParent;
dialog.ShowDialog();
}
}
///
/// 生成报告
///
///
///
private void MenuToolsCreateReport_Click(object sender, EventArgs e)
{
if (AppWorkspace.DocumentWorkspaces != null && AppWorkspace.DocumentWorkspaces.Count() > 0)
{
if (AppWorkspace.startScriptRecording)
{
AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List());
}
using (CreateReportDialog createReportDialog = new CreateReportDialog(this.AppWorkspace))
{
createReportDialog.StartPosition = FormStartPosition.CenterScreen;
createReportDialog.ShowDialog();
}
}
else
MessageBox.Show(PdnResources.GetString("Menu.Thereportcannotbegeneratedwithoutanopenim.Text"));
}
}
}