예제 #1
0
        /// <summary>
        /// Initializes the image dimension, mouse delegation, and the
        /// graphical context setup of the instance.
        /// </summary>
        /// <param name="view"> HALCON window </param>
        public HWndCtrl(HWindowControlWPF view)
        {
            viewPort     = view;
            stateView    = MODE_VIEW_NONE;
            windowWidth  = viewPort.ActualWidth;
            windowHeight = viewPort.ActualHeight;

            zoomWndFactor = (double)imageWidth / viewPort.ActualWidth;
            zoomAddOn     = Math.Pow(0.9, 5);
            zoomWndSize   = 150;

            /*default*/
            CompRangeX = new int[] { 0, 100 };
            CompRangeY = new int[] { 0, 100 };

            prevCompX = prevCompY = 0;

            dispROI = MODE_INCLUDE_ROI;//1;

            //viewPort.HMouseUp += ViewPort_HMouseUp;
            //viewPort.HMouseDown += ViewPort_HMouseDown;
            //viewPort.HMouseMove += ViewPort_HMouseMove;
            viewPort.HMouseWheel += ViewPort_HMouseWheel;

            viewPort.SizeChanged += ViewPort_SizeChanged;


            addInfoDelegate    = new FuncDelegate(dummyV);
            NotifyIconObserver = new IconicDelegate(dummy);

            // graphical stack
            HObjList           = new ArrayList(20);
            mGC                = new GraphicsContext();
            mGC.gcNotification = new GCDelegate(exceptionGC);
        }
        /// <summary>
        /// Initializes the image dimension, mouse delegation, and the
        /// graphical context setup of the instance.
        /// </summary>
        /// <param name="viewPort"> HALCON window </param>
        public ViewController(HWindowControlWPF viewPort)
        {
            this.viewPort      = viewPort;
            this.RoiController = new ROIController(this);

            stateView = MODE_VIEW_NONE;

            zoomWndFactor = (double)ImageWidth / this.viewPort.ActualWidth;
            zoomAddOn     = Math.Pow(0.9, 5);
            zoomWndSize   = 150;

            dispROI = MODE_INCLUDE_ROI;

            this.viewPort.HMouseUp   += ViewPort_HMouseUp;
            this.viewPort.HMouseDown += this.MouseDown;
            this.viewPort.HMouseMove += this.MouseMove;
            //建立鼠标离开控件的可见部分触发事件
            this.viewPort.MouseLeave += this.ViewPort_MouseLeave;
            //建立键盘按下触发事件
            this.viewPort.KeyDown += this.ViewPort_KeyDown;

            //设置窗口操作模式为移动
            SetViewState(ViewController.MODE_VIEW_MOVE);
        }
예제 #3
0
        /// <summary>
        /// Binds a Halcon window to a View Roi Manager.
        /// </summary>
        /// <param name="manager">The View Roi Manager.</param>
        /// <param name="halconWindow">The Halcon window.</param>
        /// <param name="imageBorderName">The name of the Border Control containing the Halcon window control.</param>
        /// <param name="loadImageViewModelName">The name of the load image view model to use.</param>
        /// <param name="windowClass">The main window class instance. (Pass "this")</param>
        public static void BindHalconWindow(
            ViewROIManager manager,
            HWindowControlWPF halconWindow,
            string imageBorderName,
            string loadImageViewModelName,
            MainWindow windowClass)
        {
            windowClass.DisposeCollection.Add(windowClass.Events().ContentRendered.Subscribe(_ =>
            {
                manager.LocHWindowControl = halconWindow;

                manager.LocHWindowControl.ContextMenu.ItemsSource = windowClass.MainViewModel.MenuItems;

                // Set the data template.
                manager.LocHWindowControl.ContextMenu.ItemTemplate = windowClass.ContextMenuDataTemplate;

                // Set the ItemsPanelTemplate.
                manager.LocHWindowControl.ContextMenu.ItemsPanel = windowClass.ContextMenuItemsPanelTemplate;
            }));

            windowClass.DisposeCollection.Add(windowClass.MainViewModel.MenuItems.ItemsAdded
                                              .Where(_ => manager.LocHWindowControl != null)
                                              .Subscribe(
                                                  _ =>
            {
                manager.LocHWindowControl.ContextMenu.ItemsSource = windowClass.MainViewModel.MenuItems;

                // Set the data template.
                manager.LocHWindowControl.ContextMenu.ItemTemplate = windowClass.ContextMenuDataTemplate;

                // Set the ItemsPanelTemplate.
                manager.LocHWindowControl.ContextMenu.ItemsPanel = windowClass.ContextMenuItemsPanelTemplate;
            }));

            windowClass.DisposeCollection.Add(windowClass.Events().LayoutUpdated
                                              .Select(_ => System.Reactive.Unit.Default)
                                              .InvokeCommand(manager.AdjustAspectCommand));

            ParameterExpression targetParameter = LExpression.Parameter(typeof(MainWindow), "x");
            MemberExpression    mainVMExp       = LExpression.Property(targetParameter, "MainViewModel");
            MemberExpression    viewModelExp    = LExpression.Property(mainVMExp, loadImageViewModelName);
            MemberExpression    imageHeightExp  = LExpression.Property(viewModelExp, "ImageHeight");
            MemberExpression    imageWidthExp   = LExpression.Property(viewModelExp, "ImageWidth");
            Expression <Func <MainWindow, int> > imageHeightTargetExp = LExpression.Lambda <Func <MainWindow, int> >(imageHeightExp, new ParameterExpression[] { targetParameter });
            Expression <Func <MainWindow, int> > imageWidthTargetExp  = LExpression.Lambda <Func <MainWindow, int> >(imageWidthExp, new ParameterExpression[] { targetParameter });

            // Using Subscribe here because BindTo sets up a two-way binding which is not wanted.
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(imageHeightTargetExp)
                                              .Subscribe(x => manager.ImageHeight = x));
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(imageWidthTargetExp)
                                              .Subscribe(x => manager.ImageWidth = x));

            MemberExpression borderExp       = LExpression.PropertyOrField(targetParameter, imageBorderName);
            MemberExpression actualHeightExp = LExpression.Property(borderExp, "ActualHeight");
            MemberExpression actualWidthExp  = LExpression.Property(borderExp, "ActualWidth");
            Expression <Func <MainWindow, double> > actualHeightTargetExp = LExpression.Lambda <Func <MainWindow, double> >(actualHeightExp, new ParameterExpression[] { targetParameter });
            Expression <Func <MainWindow, double> > actualWidthTargetExp  = LExpression.Lambda <Func <MainWindow, double> >(actualWidthExp, new ParameterExpression[] { targetParameter });

            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(actualHeightTargetExp)
                                              .Subscribe(x => manager.ContainerHeight = x));
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(actualWidthTargetExp)
                                              .Subscribe(x => manager.ContainerWidth = x));
        }