ImageCollectionMenu.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. using OpenCvSharp;
  2. using OpenCvSharp.Extensions;
  3. using PaintDotNet.Base.CommTool;
  4. using PaintDotNet.Data.Param;
  5. using PaintDotNet.ImageCollect;
  6. using PaintDotNet.ImageCollect.CameraComponent;
  7. using PaintDotNet.ImageCollect.CameraEDOF;
  8. using PaintDotNet.Setting;
  9. using PaintDotNet.Setting.LabelComponent;
  10. using StageController;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.Globalization;
  16. using System.Runtime.InteropServices;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using TUCAMAPI;
  21. using TUCamera;
  22. namespace PaintDotNet.Menus
  23. {
  24. public delegate void UpdateCameraList(List<TUCamera.TUCamera> cameras);
  25. /// <summary>
  26. /// 图像采集菜单
  27. /// </summary>
  28. internal sealed class ImageCollectionMenu : PdnMenuItem
  29. {
  30. public int index = 0;
  31. private PdnMenuItem menuCameraSelection;
  32. private PdnMenuItem menuCameraSetting;
  33. private PdnMenuItem menuCameraAdjust;
  34. private PdnMenuItem menuCameraFrame;
  35. private PdnMenuItem menuCameraConventional;
  36. private ToolStripSeparator menuSeparator1;
  37. private PdnMenuItem menuImageCollectHdr;
  38. private ToolStripSeparator menuSeparator2;
  39. private PdnMenuItem menuPreviewAction;
  40. private PdnMenuItem menuPreviewActionClose;
  41. private PdnMenuItem menuShootAction;
  42. private ToolStripSeparator menuSeparator3;
  43. private PdnMenuItem menuAutofocus;
  44. private PdnMenuItem menuRealTimeDepth;
  45. private PdnMenuItem menuRealTimeStitching;
  46. private PdnMenuItem menuAutomaticDepth;
  47. private PdnMenuItem menuImageStitching;
  48. private PdnMenuItem menuTimedShooting;
  49. private PdnMenuItem menuVideoRecording;
  50. private PdnMenuItem menuZaxisScan;
  51. private PdnMenuItem menuMultiDimensional;
  52. private PdnMenuItem menuListOfLocations;
  53. private PdnMenuItem menuTwain;
  54. // 曝光
  55. private PdnMenuItem menuAdjustExposure;
  56. // 白平衡
  57. private PdnMenuItem menuAdjustWhiteBalance;
  58. // 增益
  59. private PdnMenuItem menuAdjustGain;
  60. // 饱和度
  61. private PdnMenuItem menuAdjustSaturation;
  62. // 相机模式
  63. private PdnMenuItem menuFrameColorMode;
  64. // 相机分辨率
  65. private PdnMenuItem menuResolution;
  66. // ROI
  67. private PdnMenuItem menuROI;
  68. // 图像旋转
  69. private PdnMenuItem menuCommonRotate;
  70. public ImageCollectionMenu(int menuId)
  71. {
  72. InitializeComponent();
  73. this.MenuId = menuId;
  74. }
  75. protected override void OnAppWorkspaceChanged()
  76. {
  77. base.OnAppWorkspaceChanged();
  78. }
  79. private void InitializeComponent()
  80. {
  81. //相机选择
  82. this.menuCameraSelection = new PdnMenuItem(ActionType.CameraSelection);
  83. this.menuCameraSelection.AutomaticScript = false;
  84. //相机设置
  85. this.menuCameraSetting = new PdnMenuItem(ActionType.CameraSetting);
  86. this.menuCameraSetting.AutomaticScript = false;
  87. //调节
  88. this.menuCameraAdjust = new PdnMenuItem(ActionType.CameraAdjust);
  89. this.menuCameraAdjust.AutomaticScript = false;
  90. //边框
  91. this.menuCameraFrame = new PdnMenuItem(ActionType.CameraFrame);
  92. this.menuCameraFrame.AutomaticScript = false;
  93. //常规
  94. this.menuCameraConventional = new PdnMenuItem(ActionType.CameraConventional);
  95. this.menuCameraConventional.AutomaticScript = false;
  96. //分隔线
  97. this.menuSeparator1 = new ToolStripSeparator();
  98. //HDR
  99. this.menuImageCollectHdr = new PdnMenuItem(ActionType.ImageCollectHdr);
  100. this.menuImageCollectHdr.AutomaticScript = false;
  101. this.menuImageCollectHdr.Checked = CameraConfigs.GetInstance().GetCurrentCameraParamModel().parame.HDR == 1;
  102. //分隔线
  103. this.menuSeparator2 = new ToolStripSeparator();
  104. //预览
  105. this.menuPreviewAction = new PdnMenuItem(ActionType.PreviewExtraction);
  106. this.menuPreviewAction.AutomaticScript = false;
  107. //关闭预览
  108. this.menuPreviewActionClose = new PdnMenuItem(ActionType.PreviewExtractionClose);
  109. this.menuPreviewActionClose.AutomaticScript = false;
  110. //拍摄
  111. this.menuShootAction = new PdnMenuItem(ActionType.ShootAction);
  112. this.menuShootAction.AutomaticScript = false;
  113. //分隔线
  114. this.menuSeparator3 = new ToolStripSeparator();
  115. //自动聚焦
  116. this.menuAutofocus = new PdnMenuItem(ActionType.Autofocus);
  117. this.menuAutofocus.AutomaticScript = false;
  118. //实时景深扩展
  119. this.menuRealTimeDepth = new PdnMenuItem(ActionType.RealTimeDepth);
  120. this.menuRealTimeDepth.AutomaticScript = false;
  121. //实时图像拼接
  122. this.menuRealTimeStitching = new PdnMenuItem(ActionType.RealTimeStitching);
  123. this.menuRealTimeStitching.AutomaticScript = false;
  124. //自动景深扩展
  125. this.menuAutomaticDepth = new PdnMenuItem(ActionType.AutomaticDepth);
  126. this.menuAutomaticDepth.AutomaticScript = false;
  127. //图像拼接
  128. this.menuImageStitching = new PdnMenuItem(ActionType.ImageStitching);
  129. this.menuImageStitching.AutomaticScript = false;
  130. //实时拍摄
  131. this.menuTimedShooting = new PdnMenuItem(ActionType.TimedShooting);
  132. this.menuTimedShooting.AutomaticScript = false;
  133. //视频录像
  134. this.menuVideoRecording = new PdnMenuItem(ActionType.VideoRecording);
  135. this.menuVideoRecording.AutomaticScript = false;
  136. //z轴扫描
  137. this.menuZaxisScan = new PdnMenuItem(ActionType.ZaxisScan);
  138. this.menuZaxisScan.AutomaticScript = false;
  139. //多维图像合成
  140. this.menuMultiDimensional = new PdnMenuItem(ActionType.MultiDimensional);
  141. this.menuMultiDimensional.AutomaticScript = false;
  142. //位置列表
  143. this.menuListOfLocations = new PdnMenuItem(ActionType.ListOfLocations);
  144. this.menuListOfLocations.AutomaticScript = false;
  145. // 曝光
  146. this.menuAdjustExposure = new PdnMenuItem(ActionType.AdjustExposure);
  147. this.menuAdjustExposure.AutomaticScript = false;
  148. // 白平衡
  149. this.menuAdjustWhiteBalance = new PdnMenuItem(ActionType.AdjustWhiteBalance);
  150. this.menuAdjustWhiteBalance.AutomaticScript = false;
  151. // 增益
  152. this.menuAdjustGain = new PdnMenuItem(ActionType.AdjustGain);
  153. this.menuAdjustGain.AutomaticScript = false;
  154. // 饱和度
  155. this.menuAdjustSaturation = new PdnMenuItem(ActionType.AdjustSaturation);
  156. this.menuAdjustSaturation.AutomaticScript = false;
  157. // 相机模式
  158. this.menuFrameColorMode = new PdnMenuItem(ActionType.FrameCameraMode);
  159. this.menuFrameColorMode.AutomaticScript = false;
  160. // 相机设置
  161. this.menuResolution = new PdnMenuItem(ActionType.FrameCameraSet1);
  162. this.menuResolution.AutomaticScript = false;
  163. // 相机设置
  164. this.menuROI = new PdnMenuItem(ActionType.FrameCameraSet2);
  165. this.menuROI.AutomaticScript = false;
  166. // 图像旋转
  167. this.menuCommonRotate = new PdnMenuItem(ActionType.CommonRotate);
  168. this.menuCommonRotate.AutomaticScript = false;
  169. //Twain
  170. this.menuTwain = new PdnMenuItem(ActionType.Twain);
  171. this.menuTwain.AutomaticScript = false;
  172. //
  173. // 主菜单
  174. //
  175. this.DropDownItems.AddRange(new ToolStripItem[] {
  176. this.menuCameraSelection,
  177. this.menuTwain,
  178. this.menuCameraSetting,
  179. this.menuCameraAdjust,
  180. this.menuCameraFrame,
  181. this.menuCameraConventional,
  182. this.menuSeparator1,
  183. this.menuImageCollectHdr,
  184. //this.menuSeparator2,
  185. this.menuPreviewAction,
  186. this.menuPreviewActionClose,
  187. this.menuShootAction,
  188. this.menuSeparator3,
  189. this.menuAutofocus,
  190. this.menuRealTimeDepth,
  191. this.menuRealTimeStitching,
  192. this.menuAutomaticDepth,
  193. this.menuImageStitching,
  194. this.menuTimedShooting,
  195. this.menuVideoRecording,
  196. this.menuZaxisScan,
  197. this.menuMultiDimensional,
  198. this.menuListOfLocations
  199. });
  200. this.Name = "Menu.ImageCollection";
  201. this.Text = PdnResources.GetString("Menu.ImageCollection.Text");
  202. //
  203. // 相机设置
  204. //
  205. this.menuCameraSetting.Click += new System.EventHandler(this.CameraSeting_Click);
  206. //调节
  207. this.menuCameraAdjust.Click += null;
  208. this.menuCameraAdjust.DropDownItems.AddRange(new ToolStripItem[] {
  209. this.menuAdjustExposure,
  210. this.menuAdjustWhiteBalance,
  211. this.menuAdjustGain,
  212. this.menuAdjustSaturation
  213. });
  214. //
  215. // 调节 - 曝光时间
  216. //
  217. this.menuAdjustExposure.NeedWaitKey = true;
  218. this.menuAdjustExposure.Click += new System.EventHandler(this.AdjustExposure_Click);
  219. this.menuAdjustExposure.Text = PdnResources.GetString("Menu.timeofexposure.text");
  220. this.menuAdjustExposure.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionExposureTimeIcon.png").Reference;
  221. //
  222. // 调节 - 白平衡
  223. //
  224. this.menuAdjustWhiteBalance.NeedWaitKey = true;
  225. this.menuAdjustWhiteBalance.Click += new System.EventHandler(this.AdjustWhiteBalance_Click);
  226. this.menuAdjustWhiteBalance.Text = PdnResources.GetString("Menu.Image.WhiteBalance.Text");
  227. this.menuAdjustWhiteBalance.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionWhiteBalanceIcon.png").Reference;
  228. //
  229. // 调节 - 增益
  230. //
  231. this.menuAdjustGain.NeedWaitKey = true;
  232. this.menuAdjustGain.Click += new System.EventHandler(this.AdjustGain_Click);
  233. this.menuAdjustGain.Text = PdnResources.GetString("Menu.imagecapture.adjust.Gain.text");
  234. this.menuAdjustGain.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionGainIcon.png").Reference;
  235. //
  236. // 调节 - 饱和度
  237. //
  238. this.menuAdjustSaturation.NeedWaitKey = true;
  239. this.menuAdjustSaturation.Click += new System.EventHandler(this.AdjustSaturation_Click);
  240. this.menuAdjustSaturation.Text = PdnResources.GetString("Menu.saturation.text");
  241. this.menuAdjustSaturation.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionSaturationIcon.png").Reference;
  242. //
  243. // 边框
  244. //
  245. this.menuCameraFrame.Click += null;
  246. this.menuCameraFrame.DropDownItems.AddRange(new ToolStripItem[] {
  247. this.menuFrameColorMode,
  248. this.menuResolution,
  249. this.menuROI
  250. });
  251. //
  252. // 黑白、彩色 - 相机模式
  253. //
  254. this.menuFrameColorMode.NeedWaitKey = true;
  255. this.menuFrameColorMode.Click += new System.EventHandler(this.Color_Click);
  256. this.menuFrameColorMode.Text = PdnResources.GetString("Menu.Cameramode.text");
  257. this.menuFrameColorMode.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionFrameCameraModeIcon.png").Reference;
  258. //
  259. // 边框 - 相机分辨率
  260. //
  261. this.menuResolution.NeedWaitKey = true;
  262. this.menuResolution.Click += new System.EventHandler(this.Resolution_Click);
  263. this.menuResolution.Text = "相机分辨率";
  264. this.menuResolution.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionFrameCameraSetIcon.png").Reference;
  265. //
  266. // 边框 - ROI
  267. //
  268. this.menuROI.NeedWaitKey = true;
  269. this.menuROI.Click += new System.EventHandler(this.ROI_Click);
  270. this.menuROI.Text = "ROI";
  271. this.menuROI.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionROISetIcon.png").Reference;
  272. //
  273. // 常规
  274. //
  275. this.menuCameraConventional.Click += null;
  276. this.menuCameraConventional.DropDownItems.AddRange(new ToolStripItem[] {
  277. this.menuCommonRotate,
  278. });
  279. //
  280. // 边框 - 相机设置
  281. //
  282. this.menuCommonRotate.NeedWaitKey = true;
  283. this.menuCommonRotate.Click += new System.EventHandler(this.CommonRotate_Click);
  284. this.menuCommonRotate.Text = PdnResources.GetString("Menu.Imagerotation.text");
  285. this.menuCommonRotate.Image = PdnResources.GetImageResource("Icons.MenuImageCollectionCommonRotateIcon.png").Reference;
  286. //
  287. //Twain
  288. //
  289. this.menuTwain.NeedWaitKey = true;
  290. this.menuTwain.Click += MenuTwain_Click;
  291. this.menuTwain.Text = "TWAIN";
  292. //
  293. // HDR
  294. //
  295. this.menuImageCollectHdr.Click += new System.EventHandler(this.HDR_Click);
  296. //
  297. // 预览窗口
  298. //
  299. this.menuPreviewAction.NeedWaitKey = true;
  300. this.menuPreviewAction.Click += new System.EventHandler(this.previewExtraction_Click);
  301. //
  302. // 关闭预览
  303. //
  304. this.menuPreviewActionClose.NeedWaitKey = true;
  305. this.menuPreviewActionClose.Click += new System.EventHandler(this.PreviewActionClose_Click);
  306. //
  307. // 拍摄
  308. //
  309. this.menuShootAction.NeedWaitKey = true;
  310. this.menuShootAction.Click += new System.EventHandler(this.Shoot_Click);
  311. //
  312. // 自动聚焦
  313. //
  314. this.menuAutofocus.NeedWaitKey = true;
  315. this.menuAutofocus.Click += new System.EventHandler(this.Autofocus_Click);
  316. //
  317. // 实时景深扩展
  318. //
  319. this.menuRealTimeDepth.Click += new System.EventHandler(this.CameraRealTimeDepth_Click);
  320. //
  321. // 实时图像拼接
  322. //
  323. this.menuRealTimeStitching.Click += new System.EventHandler(this.CameraRealTimeStitching_Click);
  324. //
  325. // 自动景深扩展
  326. //
  327. this.menuAutomaticDepth.Click += new System.EventHandler(this.CameraAutomaticDepth_Click);
  328. //
  329. // 图像拼接
  330. //
  331. this.menuImageStitching.Click += new System.EventHandler(this.CameraImageStitching_Click);
  332. //
  333. // 实时拍摄
  334. //
  335. this.menuTimedShooting.Click += new System.EventHandler(this.CameraTimedShooting_Click);
  336. //
  337. // 视频录像
  338. //
  339. this.menuVideoRecording.Click += new System.EventHandler(this.CameraVideoRecording_Click);
  340. //
  341. // Z轴扫描
  342. //
  343. this.menuZaxisScan.Click += new System.EventHandler(this.CameraZaxisScan_Click);
  344. //
  345. // 多维图像合成
  346. //
  347. this.menuMultiDimensional.Click += new System.EventHandler(this.MultiDimensiona_Click);
  348. //
  349. // 位置列表
  350. //
  351. this.menuListOfLocations.Click += new System.EventHandler(this.ListOfLocations_Click);
  352. //
  353. // 加载菜单的文字和icon
  354. //
  355. this.LoadNames(this.Name);
  356. this.LoadIcons();
  357. }
  358. const int MSG_TWAIN = 0x444;
  359. private void MenuTwain_Click(object sender, EventArgs e)
  360. {
  361. var f1 = new TwainMessageForm();
  362. f1.CallBack = (s) =>
  363. {
  364. AppWorkspace.OpenFileInNewWorkspace(s);
  365. System.IO.File.Delete(s);
  366. };
  367. // TUCameraManager.GetInstance().UnInitManager();
  368. try
  369. {
  370. Process.Start("Saraff.Twain.exe", f1.Handle.ToString());
  371. }
  372. catch (Exception ex)
  373. {
  374. MessageBox.Show(ex.Message);
  375. }
  376. }
  377. class TwainMessageForm : Form
  378. {
  379. public Action<string> CallBack;
  380. protected override void DefWndProc(ref Message m)
  381. {
  382. switch (m.Msg)
  383. {
  384. case 444://处理消息
  385. int id = (int)m.WParam;
  386. string ss = id + ".jpg";
  387. CallBack?.Invoke(ss);
  388. break;
  389. default:
  390. base.DefWndProc(ref m);
  391. break;
  392. }
  393. }
  394. }
  395. #region 自动聚焦
  396. /// <summary>
  397. /// 自动聚焦
  398. /// </summary>
  399. /// <param name="sender"></param>
  400. /// <param name="e"></param>
  401. private void Autofocus_Click(object sender, EventArgs e)
  402. {
  403. if (AutoFocusWorkflow.IsWorking) return;
  404. TransferProgressDialog.ShowDialog("自动聚焦", "聚焦中......", () =>
  405. AutoFocusWorkflow.AutoFocus(AxisController.GetInstance(), () => { return m_camera.OneShoot(); }), (s1, e1) => { AutoFocusWorkflow.Stop(); });
  406. }
  407. #endregion
  408. protected override void OnDropDownOpening(EventArgs e)
  409. {
  410. InitCameraList();
  411. }
  412. public void InitCameraList()
  413. {
  414. this.menuCameraSelection.DropDownItems.Clear();
  415. Func<List<TUCamera.TUCamera>> func = new Func<List<TUCamera.TUCamera>>(() =>
  416. {
  417. return TUCameraManager.GetInstance().GetCameraList(); ;
  418. });
  419. AsyncCallback callback = new AsyncCallback((x) =>
  420. {
  421. var result = func.EndInvoke(x);
  422. UpdateCameraList ut = new UpdateCameraList(UpdateCameraListMehod);
  423. this.Parent.BeginInvoke(ut, result);
  424. });
  425. func.BeginInvoke(callback, "");
  426. }
  427. public void UpdateCameraListMehod(List<TUCamera.TUCamera> cameras)
  428. {
  429. this.menuCameraSelection.DropDownItems.Clear();
  430. if (cameras != null && cameras.Count > 0)
  431. {
  432. for (int i = 0; i < cameras.Count; i++)
  433. {
  434. ToolStripMenuItem mi = new ToolStripMenuItem(cameras[i].GetName());
  435. mi.Alignment = ToolStripItemAlignment.Right;
  436. mi.ImageAlign = ContentAlignment.MiddleRight;
  437. mi.ImageScaling = ToolStripItemImageScaling.None;
  438. mi.Tag = i;
  439. mi.Click += new EventHandler(this.MenuCreameItem_Click);
  440. if (this.index == i)
  441. mi.Checked = true;
  442. this.menuCameraSelection.DropDownItems.Add(mi);
  443. }
  444. }
  445. else
  446. {
  447. index = 0;
  448. }
  449. }
  450. private void MenuCreameItem_Click(object sender, EventArgs e)
  451. {
  452. if (sender != null)
  453. {
  454. foreach (ToolStripMenuItem mi in this.menuCameraSelection.DropDownItems)
  455. {
  456. mi.Checked = false;
  457. }
  458. ToolStripMenuItem temp = (ToolStripMenuItem)sender;
  459. this.index = (int)(temp.Tag);
  460. // 选中相机
  461. TUCameraManager.GetInstance().SetCurrentCamera(index);
  462. temp.Checked = true;
  463. // 检测相机是否合法
  464. Startup.cameraSNLegal = false;
  465. Startup.instance.CheckCameraSN();
  466. // 如果设置界面打开,则刷新相机名称和SN
  467. Form form = Application.OpenForms["CameraSettingDialog"];
  468. if (form != null && !form.IsDisposed)
  469. {
  470. ((CameraSettingDialog)form).InitializeData();
  471. }
  472. }
  473. }
  474. private void CommonRotate_Click(object sender, EventArgs e)
  475. {
  476. Form form = Application.OpenForms["CommonRotateDialog"];//尝试获取已经弹出的窗口对象
  477. FloatingFormMethod.ShowFloatForm(form, form == null ? new CommonRotateDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  478. }
  479. private void Resolution_Click(object sender, EventArgs e)
  480. {
  481. Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
  482. FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Resolution)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  483. }
  484. private void ROI_Click(object sender, EventArgs e)
  485. {
  486. Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
  487. FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.ROI)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  488. }
  489. private void Color_Click(object sender, EventArgs e)
  490. {
  491. Form form = Application.OpenForms["FrameCameraModeDialog"];//尝试获取已经弹出的窗口对象
  492. FloatingFormMethod.ShowFloatForm(form, form == null ? new FrameCameraModeDialog(FrameCameraMode.Color)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  493. }
  494. private void AdjustSaturation_Click(object sender, EventArgs e)
  495. {
  496. Form form = Application.OpenForms["AdjustSaturationDialog"];//尝试获取已经弹出的窗口对象
  497. FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustSaturationDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  498. }
  499. private void AdjustGain_Click(object sender, EventArgs e)
  500. {
  501. Form form = Application.OpenForms["AdjustGainDialog"];//尝试获取已经弹出的窗口对象
  502. FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustGainDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  503. }
  504. private void AdjustWhiteBalance_Click(object sender, EventArgs e)
  505. {
  506. Form form = Application.OpenForms["AdjustWhiteBalanceDialog"];//尝试获取已经弹出的窗口对象
  507. FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustWhiteBalanceDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  508. }
  509. private void AdjustExposure_Click(object sender, EventArgs e)
  510. {
  511. Form form = Application.OpenForms["AdjustExposureDialog"];//尝试获取已经弹出的窗口对象
  512. FloatingFormMethod.ShowFloatForm(form, form == null ? new AdjustExposureDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  513. }
  514. private void HDR_Click(object sender, EventArgs e)
  515. {
  516. menuImageCollectHdr.Checked = !menuImageCollectHdr.Checked;
  517. CameraConfigs.GetInstance().GetCurrentCameraParamModel().parame.HDR = menuImageCollectHdr.Checked ? 1 : 0;
  518. m_camera.SetHdr(menuImageCollectHdr.Checked ? 1 : 0);
  519. }
  520. /// <summary>
  521. /// 预览窗口
  522. /// </summary>
  523. /// <param name="sender"></param>
  524. /// <param name="e"></param>
  525. private void previewExtraction_Click(object sender, System.EventArgs e)
  526. {
  527. if (Startup.cameraSNLegal)
  528. {
  529. Form form = Application.OpenForms["CameraPreviewDialog"];//尝试获取已经弹出的窗口对象
  530. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraPreviewDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  531. }
  532. else
  533. {
  534. MessageBox.Show("不支持此相机");
  535. }
  536. }
  537. /// <summary>
  538. /// 关闭预览
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void PreviewActionClose_Click(object sender, System.EventArgs e)
  543. {
  544. if (CameraPreviewDialog.cameraPreviewDialog != null)
  545. {
  546. CameraPreviewDialog.cameraPreviewDialog.Close();
  547. }
  548. }
  549. #region 拍摄
  550. private TUCamera.TUCamera m_camera
  551. {
  552. get
  553. {
  554. return TUCameraManager.GetInstance().GetCurrentCamera();
  555. }
  556. }
  557. private CameraConfigs m_cameraConfig;
  558. private Bitmap m_bitmap;
  559. /// <summary>
  560. /// 拍摄
  561. /// </summary>
  562. /// <param name="sender"></param>
  563. /// <param name="e"></param>
  564. private void Shoot_Click(object sender, EventArgs e)
  565. {
  566. if (!Startup.cameraSNLegal)
  567. {
  568. MessageBox.Show("不支持此相机");
  569. return;
  570. }
  571. var bitmap = m_camera.OneShoot();
  572. if (bitmap == null)
  573. return;
  574. var mode = Startup.instance.configModel.CaptureSaveMode;
  575. AppWorkspace.DisplayShoot(bitmap, null, Startup.instance.configModel.CaptureHasRoler, mode);
  576. }
  577. object obj = new object();
  578. public void CallbackDraw(Bitmap bitmap)
  579. {
  580. m_camera.m_bufHandler -= CallbackDraw;
  581. lock (obj)
  582. {
  583. try
  584. {
  585. m_bitmap = bitmap;
  586. }
  587. catch (Exception)
  588. {
  589. Console.WriteLine("关闭窗口后接受到数据");
  590. }
  591. }
  592. }
  593. #endregion
  594. /// <summary>
  595. /// 相机设置点击
  596. /// </summary>
  597. /// <param name="sender"></param>
  598. /// <param name="e"></param>
  599. private void CameraSeting_Click(object sender, System.EventArgs e)
  600. {
  601. Form form = Application.OpenForms["CameraSettingDialog"];//尝试获取已经弹出的窗口对象
  602. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraSettingDialog()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  603. }
  604. /// <summary>
  605. /// 实时拍摄
  606. /// </summary>
  607. /// <param name="sender"></param>
  608. /// <param name="e"></param>
  609. private void CameraTimedShooting_Click(object sender, System.EventArgs e)
  610. {
  611. if (!Startup.cameraSNLegal)
  612. {
  613. MessageBox.Show("不支持此相机");
  614. return;
  615. }
  616. Form form = Application.OpenForms["CameraTimedShooting"];//尝试获取已经弹出的窗口对象
  617. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraTimedShooting(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  618. }
  619. /// <summary>
  620. /// 视频录像
  621. /// </summary>
  622. /// <param name="sender"></param>
  623. /// <param name="e"></param>
  624. private void CameraVideoRecording_Click(object sender, System.EventArgs e)
  625. {
  626. if (!Startup.cameraSNLegal)
  627. {
  628. MessageBox.Show("不支持此相机");
  629. return;
  630. }
  631. Form form = Application.OpenForms["CameraVideoRecording"];//尝试获取已经弹出的窗口对象
  632. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraVideoRecording()/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  633. }
  634. /// <summary>
  635. /// Z轴扫描
  636. /// </summary>
  637. /// <param name="sender"></param>
  638. /// <param name="e"></param>
  639. private void CameraZaxisScan_Click(object sender, System.EventArgs e)
  640. {
  641. if (!Startup.cameraSNLegal)
  642. {
  643. MessageBox.Show("不支持此相机");
  644. return;
  645. }
  646. //if (!AxisController.GetInstance().IsOpen)
  647. //{
  648. // MessageBox.Show(PdnResources.GetString("Message.AxisController.NotConnected"));
  649. // return;
  650. //}
  651. Form form = Application.OpenForms["CameraZaxisScan"];//尝试获取已经弹出的窗口对象
  652. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraZaxisScan(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  653. }
  654. /// <summary>
  655. /// 实时景深扩展
  656. /// </summary>
  657. /// <param name="sender"></param>
  658. /// <param name="e"></param>
  659. private void CameraRealTimeDepth_Click(object sender, System.EventArgs e)
  660. {
  661. if (!Startup.cameraSNLegal)
  662. {
  663. MessageBox.Show("不支持此相机");
  664. return;
  665. }
  666. Form form = Application.OpenForms["CameraRealTimeDepth"];//尝试获取已经弹出的窗口对象
  667. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraRealTimeDepth(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  668. }
  669. /// <summary>
  670. /// 自动景深扩展
  671. /// </summary>
  672. /// <param name="sender"></param>
  673. /// <param name="e"></param>
  674. private void CameraAutomaticDepth_Click(object sender, System.EventArgs e)
  675. {
  676. if (!Startup.cameraSNLegal)
  677. {
  678. MessageBox.Show("不支持此相机");
  679. return;
  680. }
  681. //if (!AxisController.GetInstance().IsOpen)
  682. //{
  683. // MessageBox.Show(PdnResources.GetString("Message.AxisController.NotConnected"));
  684. // return;
  685. //}
  686. Form form = Application.OpenForms["CameraAutomaticDepth"];//尝试获取已经弹出的窗口对象
  687. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraAutomaticDepth(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  688. }
  689. /// <summary>
  690. /// 图像拼接
  691. /// </summary>
  692. /// <param name="sender"></param>
  693. /// <param name="e"></param>
  694. private void CameraImageStitching_Click(object sender, System.EventArgs e)
  695. {
  696. //if (!Startup.cameraSNLegal)
  697. //{
  698. // MessageBox.Show("不支持此相机");
  699. // return;
  700. //}
  701. Form form = Application.OpenForms["CameraImageStitching"];
  702. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraImageStitching(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  703. //if ((form == null) || (form.IsDisposed))
  704. //{
  705. // CameraImageStitching af = new CameraImageStitching(AppWorkspace);
  706. // af.StartPosition = FormStartPosition.CenterScreen;
  707. // af.Show ##### Dialog();
  708. //}
  709. //else
  710. //{
  711. // form.Activate();
  712. // form.WindowState = FormWindowState.Normal;
  713. //}
  714. }
  715. /// <summary>
  716. /// 实时图像拼接
  717. /// </summary>
  718. /// <param name="sender"></param>
  719. /// <param name="e"></param>
  720. private void CameraRealTimeStitching_Click(object sender, System.EventArgs e)
  721. {
  722. if (!Startup.cameraSNLegal)
  723. {
  724. MessageBox.Show("不支持此相机");
  725. return;
  726. }
  727. Form form = Application.OpenForms["CameraRealTimeStitchingDialog"];//尝试获取已经弹出的窗口对象
  728. FloatingFormMethod.ShowFloatForm(form, form == null ? new CameraRealTimeStitchingDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  729. }
  730. /// <summary>
  731. /// 多维图像合成
  732. /// </summary>
  733. /// <param name="sender"></param>
  734. /// <param name="e"></param>
  735. private void MultiDimensiona_Click(object sender, EventArgs e)
  736. {
  737. if (!Startup.cameraSNLegal)
  738. {
  739. MessageBox.Show("不支持此相机");
  740. return;
  741. }
  742. Form form = Application.OpenForms["MultiDimensionaDialog"];
  743. FloatingFormMethod.ShowFloatForm(form, form == null ? new MultiDimensionaDialog(AppWorkspace) : null, AppWorkspace);
  744. //Form form = Application.OpenForms["MultiDimensionaDialog"];
  745. //if ((form == null) || (form.IsDisposed))
  746. //{
  747. // MultiDimensionaDialog af = new MultiDimensionaDialog(AppWorkspace);
  748. // af.StartPosition = FormStartPosition.CenterScreen;
  749. // af.Show ##### Dialog();
  750. //}
  751. //else
  752. //{
  753. // form.Activate();
  754. // form.WindowState = FormWindowState.Normal;
  755. //}
  756. }
  757. /// <summary>
  758. /// 位置列表
  759. /// </summary>
  760. /// <param name="sender"></param>
  761. /// <param name="e"></param>
  762. private void ListOfLocations_Click(object sender, EventArgs e)
  763. {
  764. if (!Startup.cameraSNLegal)
  765. {
  766. MessageBox.Show("不支持此相机");
  767. return;
  768. }
  769. Form form = Application.OpenForms["ListOfLocationsDialog"];//尝试获取已经弹出的窗口对象
  770. //using (var form = new ListOfLocationsDialog(AppWorkspace)) form.ShowDialog() ;
  771. FloatingFormMethod.ShowFloatForm(form, form == null ? new ListOfLocationsDialog(AppWorkspace)/*没有弹出的窗口对象则创建*/ : null, AppWorkspace);
  772. }
  773. private string GetCultureInfoName(CultureInfo ci)
  774. {
  775. CultureInfo en_US = new CultureInfo("en-US");
  776. if (ci.Equals(en_US))
  777. {
  778. return GetCultureInfoName(ci.Parent);
  779. }
  780. else
  781. {
  782. return ci.NativeName;
  783. }
  784. }
  785. }
  786. }