/// <summary> 
        /// Defines the initial settings for the window 
        /// control. In the very beginning, the window control needs 
        /// to know the view mode of the application form to perform 
        /// the right behavior for incoming mouse events on the 
        /// HALCON window.
        /// </summary>
        private void InteractiveForm_Load(object sender, System.EventArgs e)
        {
            String fileName = "patras";
            HImage image;

            viewController = new HWndCtrl(viewPort);
            roiController  = new ROIController();
            viewController.useROIController(roiController);
            viewController.setViewState(HWndCtrl.MODE_VIEW_NONE);

            try
            {
                image   = new HImage(fileName);
            }
            catch(HOperatorException)
            {
                MessageBox.Show("Problem occured while reading file!",
                    "InteractROIForm",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            viewController.addIconicVar(image);
            viewController.repaint();
        }
        /// <summary>
        /// In the beginning, some initialization tasks are performed. 
        /// The control instances, like ROIController and WindowController,
        /// are initialized and registered with each other. Also, the
        /// delegates of the models are linked to update methods
        /// to get notified about changes.
        /// </summary>
        public MatchingForm()
        {
            InitializeComponent();

            mView = new HWndCtrl(viewPort);

            createModelWindowMode = Color.RoyalBlue;
            trainModelWindowMode  = Color.Chartreuse;

            roiController = new ROIController();
            mView.useROIController(roiController);

            roiController.setROISign(ROIController.MODE_ROI_POS);

            mView.NotifyIconObserver = new IconicDelegate(UpdateViewData);
            roiController.NotifyRCObserver = new IconicDelegate(UpdateViewData);

            mView.setViewState(HWndCtrl.MODE_VIEW_NONE);

            locked = true;
            parameterSet = new MatchingParam();
            Init(parameterSet);
            locked = false;

            mAssistant = new MatchingAssistant(parameterSet);
            mAssistant.NotifyIconObserver  = new MatchingDelegate(UpdateMatching);
            mAssistant.NotifyParamObserver = new AutoParamDelegate(UpdateButton);

            speedOptHandler		= new MatchingOptSpeed(mAssistant, parameterSet);
            speedOptHandler.NotifyStatisticsObserver = new  StatisticsDelegate(UpdateStatisticsData);

            inspectOptHandler	= new MatchingOptStatistics(mAssistant, parameterSet);
            inspectOptHandler.NotifyStatisticsObserver = new  StatisticsDelegate(UpdateStatisticsData);
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool Init(out string message)
        {
            _isReady = true;
            message = "";
            try
            {
                _roiController = new ROIController();
                mView = new HWndCtrl(this.ViewPort);
                mView.useROIController(_roiController);
                _roiController.NotifyRCObserver = new IconicDelegate(On_ROIUpdated);// ROI 操作通知

                mAssistant = new MeasureAssistant(_roiController);
                mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults);

                initFileDialog();
                initializeGrabImage();
            }
            catch (Exception ex)
            {
                _isReady = false;
                message = ex.Message;
            }
            return _isReady;
        }
        /// <summary>
        /// Loads MeasureForm and initializes view functions
        /// to include in the MeasureAssistant.
        /// </summary>
        private void MeasureForm_Load(object sender, System.EventArgs e)
        {
            mView = new HWndCtrl(viewPort);
            roiController = new ROIController();
            mView.useROIController(roiController);
            mAssistant = new MeasureAssistant(roiController);
            mShadow = new HXLDCont();

            mView.setViewState(HWndCtrl.MODE_VIEW_NONE);
            mView.changeGraphicSettings(GraphicsContext.GC_LINEWIDTH, 1);

            roiController.NotifyRCObserver = new IconicDelegate(UpdateROIData);
            mAssistant.NotifyMeasureObserver = new MeasureDelegate(UpdateMeasureResults);

            plotGraphWindow = new FunctionPlot(panelAxis, true);

              openImageFileDialog.InitialDirectory =
            (string)(HSystem.GetSystem("image_dir").TupleSplit(";"));
            Init();

            mView.setDispLevel(HWndCtrl.MODE_EXCLUDE_ROI);
        }