using OpenCvSharp; using OpenCvSharp.Extensions; using PaintDotNet.Base.CommTool; using PaintDotNet.Camera; using PaintDotNet.Camera; using PaintDotNet.Data.Param; using PaintDotNet.ImageCollect; using PaintDotNet.ImageCollect.CameraEDOF; using PaintDotNet.Preview2; using PaintDotNet.Setting; using PaintDotNet.Setting.LabelComponent; using StageController; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace PaintDotNet.Menus { public delegate void UpdateCameraList(List cameras); /// /// 图像采集菜单 /// internal sealed class ImageCollectionMenu : PdnMenuItem { public int index = 0; private PdnMenuItem menuCameraSelection; private PdnMenuItem menuCameraSetting; private PdnMenuItem menuCameraAdjust; private PdnMenuItem menuCameraFrame; private PdnMenuItem menuCameraConventional; private ToolStripSeparator menuSeparator1; private PdnMenuItem menuImageCollectHdr; private ToolStripSeparator menuSeparator2; private PdnMenuItem menuPreviewAction; private PdnMenuItem menuPreview2Action; private PdnMenuItem menuPreviewActionClose; private PdnMenuItem menuShootAction; private ToolStripSeparator menuSeparator3; private PdnMenuItem menuAutofocus; private PdnMenuItem menuRealTimeDepth; private PdnMenuItem menuRealTimeStitching; private PdnMenuItem menuAutomaticDepth; private PdnMenuItem menuImageStitching; private PdnMenuItem menuTimedShooting; private PdnMenuItem menuVideoRecording; private PdnMenuItem menuZaxisScan; private PdnMenuItem menuMultiDimensional; private PdnMenuItem menuListOfLocations; private PdnMenuItem menuTwainSelection; private PdnMenuItem menuTwainOpen; // 曝光 private PdnMenuItem menuAdjustExposure; // 白平衡 private PdnMenuItem menuAdjustWhiteBalance; // 增益 private PdnMenuItem menuAdjustGain; // 饱和度 private PdnMenuItem menuAdjustSaturation; // 相机模式 private PdnMenuItem menuFrameColorMode; // 相机分辨率 private PdnMenuItem menuResolution; // ROI private PdnMenuItem menuROI; // 图像旋转 private PdnMenuItem menuCommonRotate; public ImageCollectionMenu(int menuId) { InitializeComponent(); this.MenuId = menuId; } protected override void OnAppWorkspaceChanged() { base.OnAppWorkspaceChanged(); } private void InitializeComponent() { //相机选择 this.menuCameraSelection = new PdnMenuItem(ActionType.CameraSelection); this.menuCameraSelection.AutomaticScript = false; //相机设置 this.menuCameraSetting = new PdnMenuItem(ActionType.CameraSetting); this.menuCameraSetting.AutomaticScript = false; //调节 this.menuCameraAdjust = new PdnMenuItem(ActionType.CameraAdjust); this.menuCameraAdjust.AutomaticScript = false; //边框 this.menuCameraFrame = new PdnMenuItem(ActionType.CameraFrame); this.menuCameraFrame.AutomaticScript = false; //常规 this.menuCameraConventional = new PdnMenuItem(ActionType.CameraConventional); this.menuCameraConventional.AutomaticScript = false; //分隔线 this.menuSeparator1 = new ToolStripSeparator(); //HDR this.menuImageCollectHdr = new PdnMenuItem(ActionType.ImageCollectHdr); this.menuImageCollectHdr.AutomaticScript = false; this.menuImageCollectHdr.Checked = CameraConfigs.GetInstance().GetCurrentCameraParamModel().parame.HDR == 1; //分隔线 this.menuSeparator2 = new ToolStripSeparator(); //预览 this.menuPreviewAction = new PdnMenuItem(ActionType.PreviewExtraction); this.menuPreviewAction.AutomaticScript = false; //预览 this.menuPreview2Action = new PdnMenuItem(ActionType.Preview2); this.menuPreview2Action.AutomaticScript = false; this.menuPreview2Action.Image = PdnResources.GetImageResource("Icons.Preview2.png").Reference; //关闭预览 this.menuPreviewActionClose = new PdnMenuItem(ActionType.PreviewExtractionClose); this.menuPreviewActionClose.AutomaticScript = false; //拍摄 this.menuShootAction = new PdnMenuItem(ActionType.ShootAction); this.menuShootAction.AutomaticScript = false; //分隔线 this.menuSeparator3 = new ToolStripSeparator(); //自动聚焦 this.menuAutofocus = new PdnMenuItem(ActionType.Autofocus); this.menuAutofocus.AutomaticScript = false; //实时景深扩展 this.menuRealTimeDepth = new PdnMenuItem(ActionType.RealTimeDepth); this.menuRealTimeDepth.AutomaticScript = false; //实时图像拼接 this.menuRealTimeStitching = new PdnMenuItem(ActionType.RealTimeStitching); this.menuRealTimeStitching.AutomaticScript = false; //自动景深扩展 this.menuAutomaticDepth = new PdnMenuItem(ActionType.AutomaticDepth); this.menuAutomaticDepth.AutomaticScript = false; //图像拼接 this.menuImageStitching = new PdnMenuItem(ActionType.ImageStitching); this.menuImageStitching.AutomaticScript = false; //实时拍摄 this.menuTimedShooting = new PdnMenuItem(ActionType.TimedShooting); this.menuTimedShooting.AutomaticScript = false; //视频录像 this.menuVideoRecording = new PdnMenuItem(ActionType.VideoRecording); this.menuVideoRecording.AutomaticScript = false; //z轴扫描 this.menuZaxisScan = new PdnMenuItem(ActionType.ZaxisScan); this.menuZaxisScan.AutomaticScript = false; //多维图像合成 this.menuMultiDimensional = new PdnMenuItem(ActionType.MultiDimensional); this.menuMultiDimensional.AutomaticScript = false; //位置列表 this.menuListOfLocations = new PdnMenuItem(ActionType.ListOfLocations); this.menuListOfLocations.AutomaticScript = false; // 曝光 this.menuAdjustExposure = new PdnMenuItem(ActionType.AdjustExposure); this.menuAdjustExposure.AutomaticScript = false; // 白平衡 this.menuAdjustWhiteBalance = new PdnMenuItem(ActionType.AdjustWhiteBalance); this.menuAdjustWhiteBalance.AutomaticScript = false; // 增益 this.menuAdjustGain = new PdnMenuItem(ActionType.AdjustGain); this.menuAdjustGain.AutomaticScript = false; // 饱和度 this.menuAdjustSaturation = new PdnMenuItem(ActionType.AdjustSaturation); this.menuAdjustSaturation.AutomaticScript = false; // 相机模式 this.menuFrameColorMode = new PdnMenuItem(ActionType.FrameCameraMode); this.menuFrameColorMode.AutomaticScript = false; // 相机设置 this.menuResolution = new PdnMenuItem(ActionType.FrameCameraSet1); this.menuResolution.AutomaticScript = false; // 相机设置 this.menuROI = new PdnMenuItem(ActionType.FrameCameraSet2); this.menuROI.AutomaticScript = false; // 图像旋转 this.menuCommonRotate = new PdnMenuItem(ActionType.CommonRotate); this.menuCommonRotate.AutomaticScript = false; //Twain this.menuTwainSelection = new PdnMenuItem(ActionType.TwainSelect); this.menuTwainSelection.AutomaticScript = false; this.menuTwainSelection.Image = PdnResources.GetImageResource("Icons.TwainSelect.png").Reference; //Twain this.menuTwainOpen = new PdnMenuItem(ActionType.TwainOpen); this.menuTwainOpen.AutomaticScript = false; this.menuTwainOpen.Image = PdnResources.GetImageResource("Icons.TwainOpen.png").Reference; // // 主菜单 // this.DropDownItems.AddRange(new ToolStripItem[] { this.menuCameraSelection, this.menuTwainSelection, this.menuTwainOpen, this.menuCameraSetting, this.menuCameraAdjust, this.menuCameraFrame, this.menuCameraConventional, this.menuSeparator1, this.menuImageCollectHdr, //this.menuSeparator2, this.menuPreviewAction, this.menuPreviewActionClose, this.menuPreview2Action, this.menuShootAction, this.menuSeparator3, this.menuAutofocus, this.menuRealTimeDepth, this.menuRealTimeStitching, this.menuAutomaticDepth, this.menuImageStitching, this.menuTimedShooting, this.menuVideoRecording, this.menuZaxisScan, this.menuMultiDimensional, this.menuListOfLocations }); this.Name = "Menu.ImageCollection"; this.Text = PdnResources.GetString("Menu.ImageCollection.Text"); // // 相机设置 // this.menuCameraSetting.Click += new System.EventHandler(this.CameraSeting_Click); //调节 this.menuCameraAdjust.Click += null; this.menuCameraAdjust.DropDownItems.AddRange(new ToolStripItem[] { this.menuAdjustExposure, this.menuAdjustWhiteBalance, this.menuAdjustGain, this.menuAdjustSaturation }); // // 调节 - 曝光时间 // this.menuAdjustExposure.NeedWaitKey = true; this.menuAdjustExposure.Click += new System.EventHandler(this.AdjustExposure_Click); this.menuAdjustExposure.Text = PdnResources.GetString("Menu.timeofexposure.text"); this.menuAdjustExposure.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionExposureTimeIcon.png").Reference; // // 调节 - 白平衡 // this.menuAdjustWhiteBalance.NeedWaitKey = true; this.menuAdjustWhiteBalance.Click += new System.EventHandler(this.AdjustWhiteBalance_Click); this.menuAdjustWhiteBalance.Text = PdnResources.GetString("Menu.Image.WhiteBalance.Text"); this.menuAdjustWhiteBalance.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionWhiteBalanceIcon.png").Reference; // // 调节 - 增益 // this.menuAdjustGain.NeedWaitKey = true; this.menuAdjustGain.Click += new System.EventHandler(this.AdjustGain_Click); this.menuAdjustGain.Text = PdnResources.GetString("Menu.imagecapture.adjust.Gain.text"); this.menuAdjustGain.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionGainIcon.png").Reference; // // 调节 - 饱和度 // this.menuAdjustSaturation.NeedWaitKey = true; this.menuAdjustSaturation.Click += new System.EventHandler(this.AdjustSaturation_Click); this.menuAdjustSaturation.Text = PdnResources.GetString("Menu.saturation.text"); this.menuAdjustSaturation.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionSaturationIcon.png").Reference; // // 边框 // this.menuCameraFrame.Click += null; this.menuCameraFrame.DropDownItems.AddRange(new ToolStripItem[] { this.menuFrameColorMode, this.menuResolution, this.menuROI }); // // 黑白、彩色 - 相机模式 // this.menuFrameColorMode.NeedWaitKey = true; this.menuFrameColorMode.Click += new System.EventHandler(this.Color_Click); this.menuFrameColorMode.Text = PdnResources.GetString("Menu.Cameramode.text"); this.menuFrameColorMode.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionFrameCameraModeIcon.png").Reference; // // 边框 - 相机分辨率 // this.menuResolution.NeedWaitKey = true; this.menuResolution.Click += new System.EventHandler(this.Resolution_Click); this.menuResolution.Text = PdnResources.GetString("ImageCollectionMenu.Resolution"); this.menuResolution.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionFrameCameraSetIcon.png").Reference; // // 边框 - ROI // this.menuROI.NeedWaitKey = true; this.menuROI.Click += new System.EventHandler(this.ROI_Click); this.menuROI.Text = "ROI"; this.menuROI.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionROISetIcon.png").Reference; // // 常规 // this.menuCameraConventional.Click += null; this.menuCameraConventional.DropDownItems.AddRange(new ToolStripItem[] { this.menuCommonRotate, }); // // 边框 - 相机设置 // this.menuCommonRotate.NeedWaitKey = true; this.menuCommonRotate.Click += new System.EventHandler(this.CommonRotate_Click); this.menuCommonRotate.Text = PdnResources.GetString("Menu.Imagerotation.text"); this.menuCommonRotate.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionCommonRotateIcon.png").Reference; // //Twain // this.menuTwainSelection.NeedWaitKey = true; this.menuTwainSelection.Click += MenuTwainSelection_Click; this.menuTwainSelection.Text = PdnResources.GetString("Menu.LabelAction.LabelSelect.Text") + "TWAIN"; menuTwainSelection.ToolTipText = PdnResources.GetString("Menu.ImageCollection.ClickRefreshList.text"); // //Twain // this.menuTwainOpen.NeedWaitKey = true; this.menuTwainOpen.Click += MenuTwainOpen_Click; ; this.menuTwainOpen.Text = PdnResources.GetString("CommonAction.Open") + "TWAIN"; // // HDR // this.menuImageCollectHdr.Click += new System.EventHandler(this.HDR_Click); // // 预览窗口 // this.menuPreviewAction.NeedWaitKey = true; this.menuPreviewAction.Click += new System.EventHandler(this.previewExtraction_Click); // // 预览窗口 // this.menuPreview2Action.NeedWaitKey = true; this.menuPreview2Action.Click += new System.EventHandler(this.preview2_Click); // // 关闭预览 // this.menuPreviewActionClose.NeedWaitKey = true; this.menuPreviewActionClose.Click += new System.EventHandler(this.PreviewActionClose_Click); // // 拍摄 // this.menuShootAction.NeedWaitKey = true; this.menuShootAction.Click += new System.EventHandler(this.Shoot_Click); // // 自动聚焦 // this.menuAutofocus.NeedWaitKey = true; this.menuAutofocus.Click += new System.EventHandler(this.Autofocus_Click); // // 实时景深扩展 // this.menuRealTimeDepth.Click += new System.EventHandler(this.CameraRealTimeDepth_Click); // // 实时图像拼接 // this.menuRealTimeStitching.Click += new System.EventHandler(this.CameraRealTimeStitching_Click); // // 自动景深扩展 // this.menuAutomaticDepth.Click += new System.EventHandler(this.CameraAutomaticDepth_Click); // // 图像拼接 // this.menuImageStitching.Click += new System.EventHandler(this.CameraImageStitching_Click); // // 实时拍摄 // this.menuTimedShooting.Click += new System.EventHandler(this.CameraTimedShooting_Click); // // 视频录像 // this.menuVideoRecording.Click += new System.EventHandler(this.CameraVideoRecording_Click); // // Z轴扫描 // this.menuZaxisScan.Click += new System.EventHandler(this.CameraZaxisScan_Click); // // 多维图像合成 // this.menuMultiDimensional.Click += new System.EventHandler(this.MultiDimensiona_Click); // // 位置列表 // this.menuListOfLocations.Click += new System.EventHandler(this.ListOfLocations_Click); // // 加载菜单的文字和icon // this.LoadNames(this.Name); this.LoadIcons(); } private void preview2_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["Preview2Dialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new Preview2Dialog() { _app = AppWorkspace }/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } #region Twain string _twainlistPath = Application.StartupPath + "\\twainlist"; TwainMessageForm f1 = new TwainMessageForm(); bool _isInited = false; private void InitTwain() { f1.CaptureCallBack = (s) => { AppWorkspace.OpenFileInNewWorkspace(s); System.IO.File.Delete(s); }; f1.ListCallBack = () => { UpdateTwainList(); }; if (System.IO.File.Exists(_twainlistPath)) { UpdateTwainList(); } } int _twSelect = -1; dynamic _tagSelect; public void UpdateTwainList() { var list = System.IO.File.ReadAllLines(_twainlistPath); if (!IsTwainListChanged(list)) return; menuTwainSelection.DropDownItems.Clear(); _twSelect = -1; for (int i = 0; i < list.Length; i++) { ToolStripMenuItem mi = new ToolStripMenuItem(); var name = list[i]; mi.Tag = new { Name = name, Index = i }; if (name == "TuCamera") { if (!CameraManager.IsLive) continue; mi.Text = CameraManager.CurrentCamera.GetName(); } else { mi.Text = name; } mi.Alignment = ToolStripItemAlignment.Right; mi.ImageAlign = ContentAlignment.MiddleRight; mi.ImageScaling = ToolStripItemImageScaling.None; // mi.CanSelect = true; if (_twSelect == -1) { _tagSelect = mi.Tag; _twSelect = i; } mi.Checked = i == _twSelect; mi.Click += (s1, e1) => { _tagSelect = (s1 as ToolStripMenuItem).Tag as dynamic; _twSelect = _tagSelect.Index; foreach (ToolStripMenuItem item in menuTwainSelection.DropDownItems) { item.Checked = s1 == item; } }; this.menuTwainSelection.DropDownItems.Add(mi); } } private bool IsTwainListChanged(string[] list) { if (list.Length != menuTwainSelection.DropDownItems.Count) { return true; } for (int i = 0; i < list.Length; i++) { if (list[i] != menuTwainSelection.DropDownItems[i].Text) return true; } return false; } static string _procName = "Saraff.Twain"; static string _procPath = Application.StartupPath + "\\" + _procName + ".exe"; private void MenuTwainSelection_Click(object sender, EventArgs e) { try { Process.Start(_procPath, f1.Handle.ToString() + " list"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void MenuTwainOpen_Click(object sender, EventArgs e) { try { if (_twSelect != -1) { if (Process.GetProcessesByName(_procName).Length > 0) return; Process.Start(_procPath, f1.Handle.ToString() + " open " + _twSelect); new Task(MaxTopTwainForm).Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private const int HWND_TOPMOST = 0; private const int SWP_NOMOVE = 0x0002; private const int SWP_NOSIZE = 0x0001; [DllImport("user32.dll")] static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr WndInsertAfter, int x, int y, int cx, int cy, int uFlags); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); private void MaxTopTwainForm() { var timeout = 100000;//10秒 var time = DateTime.Now; var name = _tagSelect.Name; if (name == "ZEISS TWAIN") { name = "Axiocam"; } else { return; } while ((DateTime.Now - time).TotalMilliseconds < timeout) { IntPtr handle = FindWindow(null, name); if (handle == IntPtr.Zero) { Thread.Sleep(100); continue; } SetWindowPos(handle, new IntPtr(HWND_TOPMOST), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); int r = ShowWindow(handle, 3); return; } } class TwainMessageForm : Form { public Action CaptureCallBack; public Action ListCallBack; protected override void DefWndProc(ref Message m) { switch (m.Msg) { case 444://处理消息 int id = (int)m.WParam; string ss = id + ".jpg"; CaptureCallBack?.Invoke(ss); break; case 445: ListCallBack?.Invoke(); break; default: base.DefWndProc(ref m); break; } } } #endregion #region 自动聚焦 /// /// 自动聚焦 /// /// /// private void Autofocus_Click(object sender, EventArgs e) { if (AutoFocusWorkflow.IsWorking) return; TransferProgressDialog.ShowDialog("自动聚焦", "聚焦中......", () => AutoFocusWorkflow.AutoFocus(AxisController.GetInstance(), () => { return m_camera.OneShoot(); }), (s1, e1) => { AutoFocusWorkflow.Stop(); }); } #endregion protected override void OnDropDownOpening(EventArgs e) { InitCameraList(); if (!_isInited) { InitTwain(); _isInited = true; } } public void InitCameraList() { this.menuCameraSelection.DropDownItems.Clear(); Func> func = new Func>(() => { return CameraManager.GetInstance().GetCameraList(); ; }); AsyncCallback callback = new AsyncCallback((x) => { var result = func.EndInvoke(x); UpdateCameraList ut = new UpdateCameraList(UpdateCameraListMehod); this.Parent.BeginInvoke(ut, result); }); func.BeginInvoke(callback, ""); } public void UpdateCameraListMehod(List cameras) { this.menuCameraSelection.DropDownItems.Clear(); if (cameras != null && cameras.Count > 0) { for (int i = 0; i < cameras.Count; i++) { ToolStripMenuItem mi = new ToolStripMenuItem(cameras[i].GetName()); mi.Alignment = ToolStripItemAlignment.Right; mi.ImageAlign = ContentAlignment.MiddleRight; mi.ImageScaling = ToolStripItemImageScaling.None; mi.Tag = i; mi.Click += new EventHandler(this.MenuCreameItem_Click); if (cameras[i].GetName() == CameraManager.CurrentCamera.GetName()) mi.Checked = true; mi.Text = cameras[i].GetNameEx(); this.menuCameraSelection.DropDownItems.Add(mi); } } else { index = 0; } } private void MenuCreameItem_Click(object sender, EventArgs e) { if (sender != null) { foreach (ToolStripMenuItem mi in this.menuCameraSelection.DropDownItems) { mi.Checked = false; } ToolStripMenuItem temp = (ToolStripMenuItem)sender; this.index = (int)(temp.Tag); // 选中相机 CameraManager.GetInstance().SetCurrentCamera(index); temp.Checked = true; // 如果设置界面打开,则刷新相机名称和SN Form form = Application.OpenForms["CameraSettingDialog"]; if (form != null && !form.IsDisposed) { ((CameraSettingDialog)form).InitializeData(); } } } private void CommonRotate_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CommonRotateDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CommonRotateDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void Resolution_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Resolution)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void ROI_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.ROI)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void Color_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Color)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void AdjustSaturation_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["AdjustSaturationDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustSaturationDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void AdjustGain_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["AdjustGainDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustGainDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void AdjustWhiteBalance_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["AdjustWhiteBalanceDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustWhiteBalanceDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void AdjustExposure_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["AdjustExposureDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustExposureDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private void HDR_Click(object sender, EventArgs e) { menuImageCollectHdr.Checked = !menuImageCollectHdr.Checked; CameraConfigs.GetInstance().GetCurrentCameraParamModel().parame.HDR = menuImageCollectHdr.Checked ? 1 : 0; m_camera.HDR = menuImageCollectHdr.Checked ? 1 : 0; } /// /// 预览窗口 /// /// /// private void previewExtraction_Click(object sender, System.EventArgs e) { if (CameraManager.IsLive) { Form form = Application.OpenForms["CameraPreviewDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraPreviewDialog(AppWorkspace) : null, AppWorkspace); } else { Tips(); } // if (CameraManager.IsLive) //{ // Form form = Application.OpenForms["Preview2Dialog"];//尝试获取已经弹出的窗口对象 // FloatingFormMethod.ShowFloatForm(form, form == null ? new Preview2Dialog() { _app = AppWorkspace }/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); //} //else //{ // MessageBox.Show("未找到可用相机"); //} // new Preview2.Preview2Dialog() { _app = AppWorkspace }.Show(); } /// /// 关闭预览 /// /// /// private void PreviewActionClose_Click(object sender, System.EventArgs e) { if (CameraPreviewDialog.cameraPreviewDialog != null) { CameraPreviewDialog.cameraPreviewDialog.Close(); } Form form = Application.OpenForms["Preview2Dialog"]; if (form != null) form.Close(); } #region 拍摄 private ICamera m_camera { get { return CameraManager.CurrentCamera; } } /// /// 拍摄 /// /// /// private void Shoot_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } CameraManager.Shoot((bitmap) => { if (bitmap == null) return; var mode = Startup.instance.configModel.CaptureSaveMode; this.Parent.Invoke(new Action(() => { AppWorkspace.DisplayShoot(bitmap, null, Preview2Context.P2Config.CaptureRuler, mode); })); }); } #endregion /// /// 相机设置点击 /// /// /// private void CameraSeting_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraSettingDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraSettingDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 实时拍摄 /// /// /// private void CameraTimedShooting_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraTimedShooting"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraTimedShooting(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 视频录像 /// /// /// private void CameraVideoRecording_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraVideoRecording"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraVideoRecording()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// Z轴扫描 /// /// /// private void CameraZaxisScan_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraZaxisScan"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraZaxisScan(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 实时景深扩展 /// /// /// private void CameraRealTimeDepth_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraRealTimeDepth"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraRealTimeDepth(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 自动景深扩展 /// /// /// private void CameraAutomaticDepth_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraAutomaticDepth"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraAutomaticDepth(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 图像拼接 /// /// /// private void CameraImageStitching_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraImageStitching"]; FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraImageStitching(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 实时图像拼接 /// /// /// private void CameraRealTimeStitching_Click(object sender, System.EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["CameraRealTimeStitchingDialog"];//尝试获取已经弹出的窗口对象 FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraRealTimeStitchingDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } /// /// 多维图像合成 /// /// /// private void MultiDimensiona_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["MultiDimensionaDialog"]; FloatingFormMethod.ShowFloatForm(form, form == null ? new MultiDimensionaDialog(AppWorkspace) : null, AppWorkspace); //Form form = Application.OpenForms["MultiDimensionaDialog"]; //if ((form == null) || (form.IsDisposed)) //{ // MultiDimensionaDialog af = new MultiDimensionaDialog(AppWorkspace); // af.StartPosition = FormStartPosition.CenterScreen; // af.Show ##### Dialog(); //} //else //{ // form.Activate(); // form.WindowState = FormWindowState.Normal; //} } /// /// 位置列表 /// /// /// private void ListOfLocations_Click(object sender, EventArgs e) { if (!CameraManager.IsLive) { Tips(); return; } Form form = Application.OpenForms["ListOfLocationsDialog"];//尝试获取已经弹出的窗口对象 //using (var form = new ListOfLocationsDialog(AppWorkspace)) form.ShowDialog() ; FloatingFormMethod.ShowFloatForm(form, form == null ? new ListOfLocationsDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace); } private string GetCultureInfoName(CultureInfo ci) { CultureInfo en_US = new CultureInfo("en-US"); if (ci.Equals(en_US)) { return GetCultureInfoName(ci.Parent); } else { return ci.NativeName; } } void Tips() { MessageBox.Show(PdnResources.GetString("Menu.ImageCollection.AvailableCamera")); } } }