private void LoadToolItems(IFloatToolBarLayer toolbar) { FloatToolItem it; Image img = Image.FromFile(@"F:\杂项\服务.png"); it = new FloatToolItem("AOI(自由多边形)", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("AOI区域(矩形)", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("AOI区域(圆形)", img); toolbar.ToolItems.Add(it); toolbar.ToolItems.Add(new FloatToolItem("-")); it = new FloatToolItem("橡皮檫", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("魔术棒", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("闪烁", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("撤销", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("重做", img); toolbar.ToolItems.Add(it); it = new FloatToolItem("清除判识结果", img); toolbar.ToolItems.Add(it); }
private bool IsFitOtherToolItem(FloatToolItem item) { if (_floatToolBar.CurrentToolItem != null && _floatToolBar.CurrentToolItem.Text != item.Text) { return(true); } return(false); }
internal void FloatToolItemClick(FloatToolItem item) { IPencilToolLayer aoiLayer = null; switch (item.Text) { case "绘制AOI": _toolbarManager.Close(); aoiLayer = new PencilToolLayer(); aoiLayer.PencilType = enumPencilType.FreeCurve; aoiLayer.PencilIsFinished = (result) => { //if (!_ismultiAoi) // ClearAoi(); _aoiContainer.AddAOI(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) // _canvas.CurrentViewControl = new DefaultControlLayer(); }; _canvas.CurrentViewControl = aoiLayer; CloseOtherLayerEdit(); break; case "绘制AOI(矩形)": _toolbarManager.Close(); aoiLayer = new PencilToolLayer(); aoiLayer.PencilType = enumPencilType.Rectangle; aoiLayer.PencilIsFinished = (result) => { //if (!_ismultiAoi) // ClearAoi(); _aoiContainer.AddAOI(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) //_canvas.CurrentViewControl = new DefaultControlLayer(); }; _canvas.CurrentViewControl = aoiLayer; CloseOtherLayerEdit(); break; case "绘制AOI(多边形)": _toolbarManager.Close(); aoiLayer = new PencilToolLayer(); aoiLayer.PencilType = enumPencilType.Polygon; aoiLayer.PencilIsFinished = (result) => { //if (!_ismultiAoi) // ClearAoi(); _aoiContainer.AddAOI(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) // _canvas.CurrentViewControl = new DefaultControlLayer(); }; _canvas.CurrentViewControl = aoiLayer; CloseOtherLayerEdit(); break; case "绘制AOI(圆形)": _toolbarManager.Close(); aoiLayer = new PencilToolLayer(); aoiLayer.PencilType = enumPencilType.Circle; aoiLayer.PencilIsFinished = (result) => { //if (!_ismultiAoi) // ClearAoi(); _aoiContainer.AddAOI(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) // _canvas.CurrentViewControl = new DefaultControlLayer(); }; _canvas.CurrentViewControl = aoiLayer; CloseOtherLayerEdit(); break; case "导入AOI": _toolbarManager.Close(); _canvas.CurrentViewControl = new PencilToolLayer(); if (_contextMenuHandler.HandleImportAOI()) { _canvas.Refresh(enumRefreshType.All); } _canvas.CurrentViewControl = new DefaultControlLayer(); CloseOtherLayerEdit(); break; case "交互选择AOI": _toolbarManager.Close(); aoiLayer = new PencilToolLayer(); aoiLayer.PencilType = enumPencilType.Rectangle; _selectedAOILayer.AOIContaingerLayer = _aoiContainer; _selectedAOILayer.Edit = true; aoiLayer.PencilIsFinished = (result) => { if (_contextMenuHandler.HandleSelectAOIFromFeatures(result)) { _canvas.CurrentViewControl = new DefaultControlLayer(); _canvas.Refresh(enumRefreshType.All); } }; _canvas.CurrentViewControl = aoiLayer; break; case "删除AOI区域": _toolbarManager.Close(); ClearAoiAndResetCurrentViewControl(); break; case "魔术棒": _toolbarManager.Close(); IPencilToolLayer magicLayer = new PencilToolLayer(); _canvas.CurrentViewControl = magicLayer; magicLayer.PencilIsFinished = (result) => { _contextMenuHandler.HandleAdsorb(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) // _canvas.CurrentViewControl = new DefaultControlLayer(); _canvas.Refresh(enumRefreshType.All); }; CloseOtherLayerEdit(); break; case "魔术棒判识": _toolbarManager.Close(); IContextMenuArgProvider argProvider = _toolbarManager.Show(_contextMenuHandler.GetArgProviderUI(enumCanvasViewerMenu.MagicWand)); if (argProvider == null) { return; } IPencilToolLayer magicWandLayer = new PencilToolLayer(); magicWandLayer.PencilType = enumPencilType.Point; _canvas.CurrentViewControl = magicWandLayer; ContextMenuToolbarManager barManager = (_toolbarManager as ContextMenuToolbarManager); if (barManager != null) { barManager.ucDispose = new ContextMenuToolbarManager.UCDisposeDeleg(UCDispose); } magicWandLayer.PencilIsFinished = (result) => { if (IsFitOtherToolItem(item)) { return; } Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("tolerance", argProvider.GetArg("tolerance")); args.Add("iscontinued", argProvider.GetArg("iscontinued")); //获取参数 _contextMenuHandler.HandleMagicWandExtracting(result, args); _currentPencilToolText = item.Text; //_canvas.CurrentViewControl = new DefaultControlLayer(); }; CloseOtherLayerEdit(); break; case "橡皮檫": _toolbarManager.Close(); IPencilToolLayer earseLayer = new PencilToolLayer(); _canvas.CurrentViewControl = earseLayer; earseLayer.PencilIsFinished = (result) => { _contextMenuHandler.HandleErase(result); _currentPencilToolText = item.Text; //if (Control.ModifierKeys != Keys.Control) // _canvas.CurrentViewControl = new DefaultControlLayer(); _canvas.Refresh(enumRefreshType.All); }; CloseOtherLayerEdit(); break; case "闪烁": _contextMenuHandler.HandleFlash(); CloseOtherLayerEdit(); break; case "撤销": _contextMenuHandler.HandleUnDo(); CloseOtherLayerEdit(); break; case "重做": _contextMenuHandler.HandleReDo(); CloseOtherLayerEdit(); break; case "清除判识结果": _contextMenuHandler.HandleRemoveAll(); CloseOtherLayerEdit(); break; case "多感兴趣区域": TryResetPencilTool(); _ismultiAoi = !_ismultiAoi; _aoiContainer.IsOnlyOneAOI = !_ismultiAoi; item.Image = GetMultiAoiImage(); try { _canvas.Refresh(enumRefreshType.All); } catch (Exception ex) { Console.WriteLine(ex.Message); } CloseOtherLayerEdit(); break; } }