/// <summary> /// Repaints the HALCON window 'hwnd' /// </summary> /// <param name="hwnd"></param> public void Repaint(HalconDotNet.HWindow hwnd) { int count = this._hObjList.Count; InteractiveROI.HObjectEntry hobjentry; HalconDotNet.HSystem.SetSystem("flush_graphic", "false"); //不更新图形变量 hwnd.ClearWindow(); this._GC.LastGCSettings.Clear(); //显示图像,应用图形上下文 for (int i = 0; i < count; i++) { hobjentry = (InteractiveROI.HObjectEntry) this._hObjList[i]; this._GC.ApplyGraphicSettings(hwnd, hobjentry.GCSettings); hwnd.DispObj(hobjentry.HObj); } this.NotifyInfo("加载图像并应用图形上下文完成"); if ((this._ROICtrller != null) && (this._ROIDispMode == MODE_INCLUDE_ROI)) { this._ROICtrller.PaintData(hwnd); } HalconDotNet.HSystem.SetSystem("flush_graphic", "true"); //更新图形变量 hwnd.SetColor("black"); hwnd.DispLine(-100.0, -100.0, -101.0, -101.0); //不知何用 }
/// <summary> /// 鼠标拖动事件的处理函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void MouseMove(object sender, HalconDotNet.HMouseEventArgs e) { //响应鼠标左键的动作,右键用于右键快捷菜单,而不响应右键 if (e.Button == System.Windows.Forms.MouseButtons.Left) { double deltaX, deltaY, posX, posY; double zoomZone; //由鼠标按下到抬起(即前次的状态是按下) if (!_mousePressed) { return; } //在ROI管理器非空且ROI是否添加绘制的标记为MODE_INCLUDE_ROI,且有活动ROI if (_ROICtrller != null && _ROIPaintMode == PAINT_MODE_INCLUDE_ROI && _ROICtrller.GetActiveROIIdx() != -1) { //执行ROI管理器对于鼠标移动的处理,并返回活动ROI的索引(有ROI选中时,无法操作[移动]图像) _ROICtrller.MouseMoveAction(e.Y, e.X); } else if (_viewMode == VIEW_MODE_MOVE) { //显示控件的视图状态为MODE_VIEW_MOVE(移动图像) deltaY = (e.Y - _startRow); deltaX = (e.X - _startCol); if ((int)deltaY != 0 || (int)deltaX != 0) { //位置发生变化,移动图像 MoveImage(deltaY, deltaX); } } else if (_viewMode == HWndCtrller.VIEW_MODE_MAGNIFY) { //显示控件的视图状态为MODE_VIEW_MAGNIFY(在鼠标当前位置创建放大窗口) if (_zoomWindow != null) { HalconDotNet.HSystem.SetSystem("flush_graphic", "false"); _zoomWindow.ClearWindow(); posY = ((e.Y - _imgRow1) / (_imgRow2 - _imgRow1)) * _hWndCtrl.Height; posX = ((e.X - _imgCol1) / (_imgCol2 - _imgCol1)) * _hWndCtrl.Width; zoomZone = (_zoomWndSize / 2) * ZoomWndFactor * ZoomAddOn; _zoomWindow.SetWindowExtents((int)posY - (_zoomWndSize / 2), (int)posX - (_zoomWndSize / 2), _zoomWndSize, _zoomWndSize); _zoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone), (int)(e.Y + zoomZone), (int)(e.X + zoomZone)); Repaint(_zoomWindow); HalconDotNet.HSystem.SetSystem("flush_graphic", "true"); _zoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0); } } } }
public override void Draw(HalconDotNet.HWindow window) { window.DispLine(_startRow, _startCol, _extentRow, _extentCol); window.DispRectangle2(_startRow, _startCol, 0, 4, 4); window.DispObj(_arrowHandle); window.DispRectangle2(_locateRow, _locateCol, 0, 4, 4); }