123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071 |
- 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<ICamera> cameras);
- /// <summary>
- /// 图像采集菜单
- /// </summary>
- 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<string> 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 自动聚焦
- /// <summary>
- /// 自动聚焦
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<List<ICamera>> func = new Func<List<ICamera>>(() =>
- {
- 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<ICamera> 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;
- }
- /// <summary>
- /// 预览窗口
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 关闭预览
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- }
- /// <summary>
- /// 拍摄
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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
- /// <summary>
- /// 相机设置点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 实时拍摄
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 视频录像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// Z轴扫描
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 实时景深扩展
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 自动景深扩展
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 图像拼接
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 实时图像拼接
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 多维图像合成
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- //}
- }
- /// <summary>
- /// 位置列表
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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"));
- }
- }
- }
|