123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- using OpenCvSharp;
- using OpenCvSharp.Extensions;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Data.Param;
- using PaintDotNet.ImageCollect;
- using PaintDotNet.ImageCollect.CameraComponent;
- using PaintDotNet.ImageCollect.CameraEDOF;
- 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.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using TUCAMAPI;
- using TUCamera;
- namespace PaintDotNet.Menus
- {
- public delegate void UpdateCameraList(List<TUCamera.TUCamera> 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 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 menuTwain;
- // 曝光
- 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.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.menuTwain = new PdnMenuItem(ActionType.Twain);
- this.menuTwain.AutomaticScript = false;
- //
- // 主菜单
- //
- this.DropDownItems.AddRange(new ToolStripItem[] {
- this.menuCameraSelection,
- this.menuTwain,
- this.menuCameraSetting,
- this.menuCameraAdjust,
- this.menuCameraFrame,
- this.menuCameraConventional,
- this.menuSeparator1,
- this.menuImageCollectHdr,
- //this.menuSeparator2,
- this.menuPreviewAction,
- this.menuPreviewActionClose,
- 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 = "相机分辨率";
- 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.menuTwain.NeedWaitKey = true;
- this.menuTwain.Click += MenuTwain_Click;
- this.menuTwain.Text = "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.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();
- }
- const int MSG_TWAIN = 0x444;
- private void MenuTwain_Click(object sender, EventArgs e)
- {
- var f1 = new TwainMessageForm();
- f1.CallBack = (s) =>
- {
- AppWorkspace.OpenFileInNewWorkspace(s);
- System.IO.File.Delete(s);
- };
- // TUCameraManager.GetInstance().UnInitManager();
- try
- {
- Process.Start("Saraff.Twain.exe", f1.Handle.ToString());
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- class TwainMessageForm : Form
- {
- public Action<string> CallBack;
- protected override void DefWndProc(ref Message m)
- {
- switch (m.Msg)
- {
- case 444://处理消息
- int id = (int)m.WParam;
- string ss = id + ".jpg";
- CallBack?.Invoke(ss);
- break;
- default:
- base.DefWndProc(ref m);
- break;
- }
- }
- }
- #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();
- }
- public void InitCameraList()
- {
- this.menuCameraSelection.DropDownItems.Clear();
- Func<List<TUCamera.TUCamera>> func = new Func<List<TUCamera.TUCamera>>(() =>
- {
- return TUCameraManager.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<TUCamera.TUCamera> 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 (this.index == i)
- mi.Checked = true;
- 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);
- // 选中相机
- TUCameraManager.GetInstance().SetCurrentCamera(index);
- temp.Checked = true;
- // 检测相机是否合法
- Startup.cameraSNLegal = false;
- Startup.instance.CheckCameraSN();
- // 如果设置界面打开,则刷新相机名称和SN
- Form form = Application.OpenForms["CameraSettingDialog"];
- if (form != null && !form.IsDisposed)
- {
- ((CameraSettingDialog)form).InitializeData();
- }
- }
- }
- private void CommonRotate_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["CommonRotateDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new CommonRotateDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void Resolution_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Resolution)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void ROI_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.ROI)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void Color_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Color)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void AdjustSaturation_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["AdjustSaturationDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustSaturationDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void AdjustGain_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["AdjustGainDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustGainDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void AdjustWhiteBalance_Click(object sender, EventArgs e)
- {
- Form form = Application.OpenForms["AdjustWhiteBalanceDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustWhiteBalanceDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- private void AdjustExposure_Click(object sender, EventArgs e)
- {
- 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.SetHdr(menuImageCollectHdr.Checked ? 1 : 0);
- }
- /// <summary>
- /// 预览窗口
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void previewExtraction_Click(object sender, System.EventArgs e)
- {
- if (Startup.cameraSNLegal)
- {
- Form form = Application.OpenForms["CameraPreviewDialog"];//尝试获取已经弹出的窗口对象
- FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraPreviewDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- }
- else
- {
- MessageBox.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();
- }
- }
- #region 拍摄
- private TUCamera.TUCamera m_camera
- {
- get
- {
- return TUCameraManager.GetInstance().GetCurrentCamera();
- }
- }
- private CameraConfigs m_cameraConfig;
- private Bitmap m_bitmap;
- /// <summary>
- /// 拍摄
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Shoot_Click(object sender, EventArgs e)
- {
- if (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- return;
- }
- var bitmap = m_camera.OneShoot();
- if (bitmap == null)
- return;
- var mode = Startup.instance.configModel.CaptureSaveMode;
- AppWorkspace.DisplayShoot(bitmap, null, Startup.instance.configModel.CaptureHasRoler, mode);
- }
- object obj = new object();
- public void CallbackDraw(Bitmap bitmap)
- {
- m_camera.m_bufHandler -= CallbackDraw;
- lock (obj)
- {
- try
- {
- m_bitmap = bitmap;
- }
- catch (Exception)
- {
- Console.WriteLine("关闭窗口后接受到数据");
- }
- }
- }
- #endregion
- /// <summary>
- /// 相机设置点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CameraSeting_Click(object sender, System.EventArgs e)
- {
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- return;
- }
- //if (!AxisController.GetInstance().IsOpen)
- //{
- // MessageBox.Show(PdnResources.GetString("Message.AxisController.NotConnected"));
- // 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- return;
- }
- //if (!AxisController.GetInstance().IsOpen)
- //{
- // MessageBox.Show(PdnResources.GetString("Message.AxisController.NotConnected"));
- // 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 (!Startup.cameraSNLegal)
- //{
- // MessageBox.Show("不支持此相机");
- // return;
- //}
- Form form = Application.OpenForms["CameraImageStitching"];
- FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraImageStitching(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
- //if ((form == null) || (form.IsDisposed))
- //{
- // CameraImageStitching af = new CameraImageStitching(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 CameraRealTimeStitching_Click(object sender, System.EventArgs e)
- {
- if (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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 (!Startup.cameraSNLegal)
- {
- MessageBox.Show("不支持此相机");
- 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;
- }
- }
- }
- }
|