Ejemplo n.º 1
0
        /// <summary>
        /// Show Properties dialog. Return true if list is changed
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public bool ShowPropertiesDialog(ImageDrawBox parent)
        {
            if (SelectionCount < 1)
            {
                return(false);
            }

            GraphicsProperties properties = GetProperties();
            PropertiesDialog   dlg        = new PropertiesDialog();

            dlg.Properties = properties;

            CommandChangeState c = new CommandChangeState(this);

            if (dlg.ShowDialog(parent) != DialogResult.OK)
            {
                return(false);
            }

            if (ApplyProperties(properties))
            {
                c.NewState(this);
                parent.AddCommandToHistory(c);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Left nouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point p = GetEventPointInArea(drawArea, e);

            // Create new polygon, add it to the list
            // and keep reference to it
            newPolygon = new DrawPolygon(p.X, p.Y, p.X + 1, p.Y + 1);
            AddNewObject(drawArea, newPolygon);
            lastX = p.X;
            lastY = p.Y;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add new object to draw area.
        /// Function is called when user left-clicks draw area,
        /// and one of ToolObject-derived tools is active.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="o"></param>
        protected void AddNewObject(ImageDrawBox drawArea, DrawObject o)
        {
            drawArea.GraphicsList.UnselectAll();

            o.Selected = true;
            drawArea.GraphicsList.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();

            drawArea.SetDirty();
        }
Ejemplo n.º 4
0
        protected Point GetEventPointInArea(ImageDrawBox drawArea, MouseEventArgs e)
        {
            //Point p = new Point(Math.Abs(drawArea.AutoScrollPosition.X) + e.X, Math.Abs(drawArea.AutoScrollPosition.Y) + e.Y);
            //string status = "X: " + p.X + ", Y: " + p.Y;
            //((MainForm)drawArea.Parent).SetStatusStrip(status);
            //return p;

            //logger.Debug(String.Format("Tool-X:{0}, Y:{1}", e.X, e.Y));

            Point p = new Point((int)(Math.Round(e.X / drawArea.ZoomFactor)), (int)(Math.Round(e.Y / drawArea.ZoomFactor)));

            return(p);
        }
Ejemplo n.º 5
0
        public override void OnMouseMove(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);

            drawArea.Cursor = Cursor;

            if (e.Button == MouseButtons.Left)
            {
                drawArea.GraphicsList[0].MoveHandleTo(pointscroll, 5);
                drawArea.Refresh();
                drawArea.GraphicsList.Dirty = true;
            }
        }
Ejemplo n.º 6
0
        public ImageForm(string title, string imgFileName, Image <Bgr, Byte> img)
        {
            InitializeComponent();

            originalImage       = img;
            originalRGBChannels = img.Split();//BGR

            _imageBox          = new ImageDrawBox();
            _imageBox.DrawForm = this;
            _imageBox.init();
            _imageBox.Dock = DockStyle.None;
            this.Controls.Add(_imageBox);
            _imageBox.Image = originalImage.Clone();
            //_imageBox.SetZoomScale(1.0, new Point(0, 0));
            this.Text = title;
            this.FullImageFileName = imgFileName;
        }
Ejemplo n.º 7
0
        public SetUnitForm(ImageDrawBox drawArea, double pixels)
        {
            InitializeComponent();

            try
            {
                this.drawArea = drawArea;
                if (pixels < 0)
                {
                    this.groupBoxCreateNewScale.Enabled = false;
                }
                init(pixels);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(ImageDrawBox drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                //Point pointscroll = GetEventPointInArea(drawArea, e);
                // Make group selection
                //zhoujin - user zoomfactor
                //drawArea.GraphicsList.SelectInRectangle(
                //    DrawRectangle.GetNormalizedRectangle(new Point(startPoint.X + Math.Abs(drawArea.AutoScrollPosition.X), startPoint.Y + Math.Abs(drawArea.AutoScrollPosition.Y)),
                //                                        new Point(lastPoint.X + Math.Abs(drawArea.AutoScrollPosition.X), lastPoint.Y + Math.Abs(drawArea.AutoScrollPosition.Y))));
                double zoomFactor = drawArea.ZoomFactor;
                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(new Point(ConvertToZoomed(startPoint.X, zoomFactor), ConvertToZoomed(startPoint.Y, zoomFactor)),
                                                         new Point(ConvertToZoomed(lastPoint.X, zoomFactor), ConvertToZoomed(lastPoint.Y, zoomFactor))));

                selectMode = SelectionMode.None;
            }

            if (resizedObject != null)
            {
                // after resizing
                resizedObject.Normalize();
                resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();
            drawArea.GraphicsList.Dirty = true;

            if (commandChangeState != null && wasMove)
            {
                // Keep state after moving/resizing and add command to history
                commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(ImageDrawBox drawArea, MouseEventArgs e)
        {
            drawArea.GraphicsList[0].Normalize();
            drawArea.AddCommandToHistory(new CommandAdd(drawArea.GraphicsList[0]));
            drawArea.ActiveTool = ImageDrawBox.DrawToolType.Pointer;

            //TODO : 这部分代码需要整理
            //zhoujin: 如果是正在定标则删除图形,并弹出定标窗口
            if (drawArea.DrawMode == ImageDrawBox.DrawingMode.SetUnit)
            {
                DrawObject drawObj = drawArea.GraphicsList[0];
                //定标只支持用画直线的方式
                if (drawObj is DrawLine)
                {
                    DrawLine    drawLine    = drawObj as DrawLine;
                    double      pxLen       = CalcLenght(drawLine.StartPoint, drawLine.EndPoint);
                    SetUnitForm setUnitForm = new SetUnitForm(drawArea, pxLen);
                    setUnitForm.ShowDialog();
                    drawArea.GraphicsList.DeleteLastAddedObject();
                    drawArea.DrawMode = ImageDrawBox.DrawingMode.Measure;
                }
            }
            if (drawArea.DrawMode == ImageDrawBox.DrawingMode.SetROI)
            {
                DrawObject drawObj = drawArea.GraphicsList[0];
                //设置ROI只支持用矩形绘制
                if (drawObj is DrawRectangle)
                {
                    DrawRectangle drawRect = drawObj as DrawRectangle;
                    drawArea.SetROI(drawRect.GetBoundingBox());
                    drawArea.GraphicsList.DeleteLastAddedObject();
                    drawArea.DrawMode = ImageDrawBox.DrawingMode.Measure;
                }
            }

            drawArea.Capture = false;
            drawArea.Refresh();
            drawArea.GraphicsList.Dirty = true;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Mouse move - resize new polygon
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseMove(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point p = GetEventPointInArea(drawArea, e);

            drawArea.Cursor = Cursor;

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (newPolygon == null)
            {
                return;                 // precaution
            }
            Point point    = new Point(p.X, p.Y);
            int   distance = (p.X - lastX) * (p.X - lastX) + (p.Y - lastY) * (p.Y - lastY);

            if (distance < minDistance)
            {
                // Distance between last two points is less than minimum -
                // move last pointscroll
                newPolygon.MoveHandleTo(point, newPolygon.HandleCount);
                drawArea.GraphicsList.Dirty = true;
            }
            else
            {
                // Add new pointscroll
                newPolygon.AddPoint(point);
                lastX = p.X;
                lastY = p.Y;
                drawArea.GraphicsList.Dirty = true;
            }

            drawArea.Refresh();
        }
Ejemplo n.º 11
0
        //private CustomPictureBox pictureBox;

        public PreviewForm()
        {
            InitializeComponent();

            //test code
            _imageBox          = new ImageDrawBox();
            _imageBox.DrawForm = this;
            _imageBox.init();
            _imageBox.Dock = DockStyle.None;
            //_imageBox.BackColor = Color.Transparent;
            this.Controls.Add(_imageBox);

            //test
            //_imageBack = new PictureBox();
            ////_imageBack.init();
            //_imageBack.Dock = DockStyle.None;
            //this.Controls.Add(_imageBack);

            //_imageBox.BringToFront();

            //test code-尝试将imageBox设置为_imageBack
            PreviewForm.imageBox = _imageBox;
            //PreviewForm.imageBox = _imageBack;
        }
Ejemplo n.º 12
0
        public override void OnMouseUp(ImageDrawBox drawArea, MouseEventArgs e)
        {
            newPolygon = null;

            base.OnMouseUp(drawArea, e);
        }
Ejemplo n.º 13
0
        public override void OnMouseDown(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);

            AddNewObject(drawArea, new DrawRectangle(pointscroll.X, pointscroll.Y, 1, 1));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);

            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(pointscroll);

                if (handleNumber > 0)
                {
                    selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.GraphicsList.Dirty = true;
                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(pointscroll) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor             = Cursors.SizeAll;
                    drawArea.GraphicsList.Dirty = true;
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                selectMode = SelectionMode.NetSelection;
            }

            lastPoint.X  = e.X;
            lastPoint.Y  = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Mouse is moved.
        /// None button is pressed, or left button is pressed.
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseMove(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);
            Point oldPoint    = lastPoint;

            wasMove = true;

            // set cursor when mouse button is not pressed
            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                {
                    int n = drawArea.GraphicsList[i].HitTest(pointscroll);

                    if (n > 0)
                    {
                        cursor = drawArea.GraphicsList[i].GetHandleCursor(n);
                        break;
                    }
                }

                if (cursor == null)
                {
                    cursor = Cursors.Default;
                }

                drawArea.Cursor = cursor;

                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            /// Left button is pressed

            // Find difference between previous and current position
            int dx = e.X - lastPoint.X;
            int dy = e.Y - lastPoint.Y;

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;

            // resize
            if (selectMode == SelectionMode.Size)
            {
                if (resizedObject != null)
                {
                    resizedObject.MoveHandleTo(pointscroll, resizedObjectHandle);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                    drawArea.GraphicsList.Dirty = true;
                }
            }

            // move
            if (selectMode == SelectionMode.Move)
            {
                foreach (DrawObject o in drawArea.GraphicsList.Selection)
                {
                    //o.Move(dx, dy);
                    o.Move((int)(Math.Round(dx / drawArea.ZoomFactor)), (int)(Math.Round(dy / drawArea.ZoomFactor)));
                }

                drawArea.Cursor = Cursors.SizeAll;
                drawArea.SetDirty();
                drawArea.Refresh();
                drawArea.GraphicsList.Dirty = true;
            }

            if (selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, oldPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Draw new selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, new Point(e.X, e.Y))),
                    Color.Black,
                    FrameStyle.Dashed);

                return;
            }
        }
Ejemplo n.º 16
0
        public override void OnMouseDown(ImageDrawBox drawArea, MouseEventArgs e)
        {
            Point p = GetEventPointInArea(drawArea, e);

            AddNewObject(drawArea, new DrawEllipse(p.X, p.Y, 1, 1));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Left mouse button is released
 /// </summary>
 /// <param name="drawArea"></param>
 /// <param name="e"></param>
 public virtual void OnMouseUp(ImageDrawBox drawArea, MouseEventArgs e)
 {
 }