Ejemplo n.º 1
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            HObjectEntry entry;

            if (obj == null)
            {
                return;
            }
            if (obj is HImage)
            {
                double r, c;
                int    h, w, area;
                string s;
                viewPort.HMouseUp    -= new HalconDotNet.HMouseEventHandler(this.mouseUp);
                viewPort.HMouseDown  -= new HalconDotNet.HMouseEventHandler(this.mouseDown);
                viewPort.HMouseMove  -= new HalconDotNet.HMouseEventHandler(this.mouseMoved);
                viewPort.HMouseWheel -= new HalconDotNet.HMouseEventHandler(this.HMouseWheel);
                area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                ((HImage)obj).GetImagePointer1(out s, out w, out h);
                //if (area == (w * h))
                //{
                clearList();
                if ((h != imageHeight) || (w != imageWidth))
                {
                    imageHeight   = h;
                    imageWidth    = w;
                    zoomWndFactor = (double)imageWidth / viewPort.Width;
                    Size   WindSize = viewPort.Size;
                    double WindC    = ((double)WindSize.Height) / ((double)WindSize.Width);
                    double ImgC     = ((double)imageHeight) / ((double)imageWidth);
                    if (WindC > ImgC)
                    {
                        h = (int)(w * WindC);
                        setImagePart(0 - (h - imageHeight) / 2, 0, h - (h - imageHeight) / 2, w);
                    }
                    else
                    {
                        w = (int)(h / WindC);
                        setImagePart(0, 0, h, w);
                    }
                    zoomImage(imageHeight / 2, imageHeight / 2, 1);
                }
                //}//if
                viewPort.HMouseUp    += new HalconDotNet.HMouseEventHandler(this.mouseUp);
                viewPort.HMouseDown  += new HalconDotNet.HMouseEventHandler(this.mouseDown);
                viewPort.HMouseMove  += new HalconDotNet.HMouseEventHandler(this.mouseMoved);
                viewPort.HMouseWheel += new HalconDotNet.HMouseEventHandler(this.HMouseWheel);
            }                                                     //if
            entry = new HObjectEntry(obj, mGC.copyContextList()); //
            HObjList.Add(entry);
            if (HObjList.Count > MAXNUMOBJLIST)
            {
                HObjList.RemoveAt(1);
            }
        }
Ejemplo n.º 2
0
        public void addIconicVar(HObject obj)
        {
            if (obj == null)
            {
                return;
            }

            //if (entry != null)
            //viewPort.HalconWindow.DispObj(entry.HObj);

            //  HRegion ddd = new HRegion();
            tempImage.Dispose();
            tempImage = new HImage(obj);

            if (tempImage != null)
            //if (obj is HImage)
            {
                double r, c;
                int    h, w, area;
                string s;
                area = tempImage.GetDomain().AreaCenter(out r, out c);
                tempImage.GetImagePointer1(out s, out w, out h);

                //area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                //((HImage)obj).GetImagePointer1(out s, out w, out h);

                if (area == (w * h))
                {
                    clearList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        imageHeight   = h;
                        imageWidth    = w;
                        zoomWndFactor = (double)imageWidth / viewPort.Width;
                        setImagePart(0, 0, h, w);
                    }
                }//if
            }            //if

            //entry.
            entry = new HObjectEntry(tempImage, mGC.copyContextList());

            //HObjList.Add(entry);

            //if (HObjList.Count > MAXNUMOBJLIST)
            //    HObjList.RemoveAt(1);

            repaint();
        }
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            //HObjectEntry entry;

            if (obj == null)
            {
                return;
            }

            if (obj is HImage)
            {
                double r, c;
                int    h, w, area;
                string s;

                _lastImage = (HImage)obj;

                area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                ((HImage)obj).GetImagePointer1(out s, out w, out h);

                if (area == (w * h))
                {
                    clearList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        imageHeight   = h;
                        imageWidth    = w;
                        zoomWndFactor = (double)imageWidth / _viewPort.Width;
                        setImagePart(0, 0, h, w);
                    }
                }        //if
            }            //if

            var entry = new HObjectEntry(obj, mGC.copyContextList());

            HObjList.Add(entry);

            if (HObjList.Count > MAXNUMOBJLIST)
            {
                HObjList.RemoveAt(1);
            }
        }
Ejemplo n.º 4
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            HObjectEntry entry;
            if (obj == null) return;

            var image = obj as HImage;
            if (image != null)
            {
                double r, c;
                int h, w, area;
                string s;

                area = image.GetDomain().AreaCenter(out r, out c);
                image.GetImagePointer1(out s, out w, out h);

                if (area == (w * h))
                {
                    clearList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        imageHeight = h;
                        imageWidth = w;
                        zoomWndFactor = (double)imageWidth / viewPort.Width;
                        int d = w < h ? w : h;
                        setImagePart(0, 0, d, d);
                    }
                }//if
            }//if

            entry = new HObjectEntry(obj, mGC.copyContextList());

            HObjList.Add(entry);

            if (HObjList.Count > MAXNUMOBJLIST)
                HObjList.RemoveAt(1);
        }
Ejemplo n.º 5
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void AddHObject(HObject obj, string color, bool isImage)
        {
            HObjectEntry entry;
            HTuple       hv_Width = null, hv_Height = null;

            if (obj == null)
            {
                return;
            }
            if (isImage)
            {
                if (obj.IsInitialized())
                {
                    HOperatorSet.GetImageSize(obj, out hv_Width, out hv_Height);
                    clearList();

                    if ((hv_Height != imageHeight) || (hv_Width != imageWidth))
                    {
                        viewPort.HalconWindow.SetDraw("margin");
                        imageHeight = hv_Height;
                        imageWidth  = hv_Width;
                        setImagePart(0, 0, hv_Width, hv_Height);
                    }
                    HObjList.Clear();
                    StrList.Clear();
                }
                else
                {
                    viewPort.HalconWindow.ClearWindow();
                    HObjList.Clear();
                    StrList.Clear();
                }
            }
            if (obj.IsInitialized())
            {
                entry = new HObjectEntry(obj, color, mGC.copyContextList());
                HObjList.Add(entry);
            }

            //if (HObjList.Count > MAXNUMOBJLIST)
            //    HObjList.RemoveAt(1);
        }
Ejemplo n.º 6
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            HObjectEntry entry;

            if (obj == null)
            {
                return;
            }

            if (obj is HImage)
            {
                double r, c;
                int    h, w, area;
                string s;

                area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                ((HImage)obj).GetImagePointer1(out s, out w, out h);
                imgHeight = h;
                imgWidth  = w;
                if (true)//area == (w * h))//大小不同也清除原来的
                {
                    clearList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        int    _beginRow, _begin_Col, _endRow, _endCol;
                        double ratio_win = (double)viewPort.ActualWidth / (double)viewPort.ActualHeight;
                        double ratio_img = (double)w / (double)h;
                        imageHeight = h;
                        imageWidth  = w;
                        if (ratio_win >= ratio_img)
                        {
                            _beginRow     = 0;
                            _endRow       = h - 1;
                            _begin_Col    = (int)(-w * (ratio_win / ratio_img - 1d) / 2d);
                            _endCol       = (int)(w + w * (ratio_win / ratio_img - 1d) / 2d);
                            zoomWndFactor = (double)h / viewPort.ActualHeight;
                        }
                        else
                        {
                            _begin_Col    = 0;
                            _endCol       = w - 1;
                            _beginRow     = (int)(-h * (ratio_img / ratio_win - 1d) / 2d);
                            _endRow       = (int)(h + h * (ratio_img / ratio_win - 1d) / 2d);
                            zoomWndFactor = (double)w / viewPort.ActualWidth;
                        }
                        //viewPort.HalconWindow.SetPart(_beginRow, _begin_Col, _endRow, _endCol);
                        setImagePart(_beginRow, _begin_Col, (int)viewPort.ActualHeight, (int)viewPort.ActualWidth);
                        //setImagePart(_beginRow, _begin_Col, _endRow-_beginRow, _endCol-_begin_Col);
                        clearList();

                        zoomImage(zoomWndFactor);
                    }
                } //if
            }     //if

            entry = new HObjectEntry(obj, mGC.copyContextList());

            HObjList.Add(entry);

            if (HObjList.Count > MAXNUMOBJLIST)
            {
                HObjList.RemoveAt(1);
            }
        }
Ejemplo n.º 7
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            HObjectEntry entry;
            bool         BeScale = false;

            if (obj == null)
            {
                return;
            }
            HObject outimage = new HObject();


            if (obj is HImage)
            {
                double r, c;
                int    h, w, area;
                string s;

                area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                ((HImage)obj).GetImagePointer1(out s, out w, out h);
                setNewImage(obj as HImage, out outimage, w, h);
                if (area == (w * h))
                {
                    clearList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        imageHeight   = h;
                        imageWidth    = w;
                        BeScale       = true;
                        zoomWndFactor = (double)imageWidth / viewPort.Width;
                        setImagePart1(0, 0, h, w);
                    }
                }                //if
                entry = new HObjectEntry(obj, mGC.copyContextList());
                if (area == (w * h))
                {
                    if (BeScale)
                    {
                        if (obj is HImage)
                        {
                            if (hv_scale < 1)
                            {
                                HTuple width_new = viewPort.Size.Width - w * hv_scale;
                                switch (w)
                                {
                                case 5472:
                                    zoomImage(width_new * 0.6, 0, 1 / hv_scale);
                                    break;

                                case 2448:
                                    zoomImage(width_new * 0.7, 0, 1 / hv_scale);
                                    break;

                                case 2560:
                                case 2592:
                                    zoomImage(width_new * 0.7, 0, 1 / hv_scale);
                                    break;

                                case 1280:
                                    zoomImage(width_new * 1.2, 0, 1 / hv_scale);
                                    break;

                                default:
                                    break;
                                }


                                BeScale = false;
                            }
                            else
                            {
                                HTuple width_small = -(viewPort.Size.Width - w * hv_scale);
                                zoomImage(width_small * 2.5, 0, 1 / hv_scale);
                                BeScale = false;
                            }
                        }
                    }
                }
            }            //if
            else
            {
                entry = new HObjectEntry(obj, mGC.copyContextList());
            }


            HObjList.Add(entry);

            if (HObjList.Count > MAXNUMOBJLIST)
            {
                HObjList.RemoveAt(1);
            }
        }
Ejemplo n.º 8
0
        /********************************************************************/
        /*                      GRAPHICSSTACK                               */
        /********************************************************************/

        /// <summary>
        /// Adds an iconic object to the graphics stack similar to the way
        /// it is defined for the HDevelop graphics stack.
        /// </summary>
        /// <param name="obj">Iconic object</param>
        public void addIconicVar(HObject obj)
        {
            HObjectEntry entry;

            if (obj == null)
            {
                return;
            }

            if (obj is HImage)
            {
                //double r, c;
                //int area;
                int    h, w;
                string s;

                //area = ((HImage)obj).GetDomain().AreaCenter(out r, out c);
                ((HImage)obj).GetImagePointer1(out s, out w, out h);

                HTuple width, height;
                HOperatorSet.GetSystem("width", out width);
                HOperatorSet.GetSystem("height", out height);
                //在某种情况下,Get的值正确的也未生效,需要再设置一遍,原因未知
                HOperatorSet.SetSystem("width", width);
                HOperatorSet.SetSystem("height", height);

                if (Image_Auto_Fit)//area == (w * h))//大小不同也清除原来的
                {
                    clearList();
                    clearMsgList();

                    if ((h != imageHeight) || (w != imageWidth))
                    {
                        int    _beginRow, _begin_Col, _endRow, _endCol;
                        double ratio_win = (double)viewPort.ActualWidth / (double)viewPort.ActualHeight;
                        double ratio_img = (double)w / (double)h;
                        imageHeight = h;
                        imageWidth  = w;
                        if (ratio_win >= ratio_img)
                        {
                            _beginRow     = 0;
                            _endRow       = h - 1;
                            _begin_Col    = (int)(-w * (ratio_win / ratio_img - 1d) / 2d);
                            _endCol       = (int)(w + w * (ratio_win / ratio_img - 1d) / 2d);
                            zoomWndFactor = (double)h / viewPort.ActualHeight;
                        }
                        else
                        {
                            _begin_Col    = 0;
                            _endCol       = w - 1;
                            _beginRow     = (int)(-h * (ratio_img / ratio_win - 1d) / 2d);
                            _endRow       = (int)(h + h * (ratio_img / ratio_win - 1d) / 2d);
                            zoomWndFactor = (double)w / viewPort.ActualWidth;
                        }
                        //viewPort.HalconWindow.SetPart(_beginRow, _begin_Col, _endRow, _endCol);
                        setImagePart(_beginRow, _begin_Col, (int)viewPort.ActualHeight, (int)viewPort.ActualWidth);
                        //setImagePart(_beginRow, _begin_Col, _endRow-_beginRow, _endCol-_begin_Col);
                        //clearList();

                        zoomImage(zoomWndFactor);
                    }
                } //if
            }     //if

            entry = new HObjectEntry(obj, mGC.copyContextList());

            HObjList.Add(entry);

            if (HObjList.Count > MAXNUMOBJLIST)
            {
                HObjList.RemoveAt(1);
            }

            if (HObjListChanged != null)
            {
                HObjListChanged(null, null);
            }
        }