Exemple #1
0
        public override void CanvasTool_MouseMove(object sender, MouseEventArgs e)
        {
            if (_canvas == null || CurrentLayer() == null || !CurrentLayer().IsLine)
            {
                return;
            }
            if (!IsWorking())
            {
                return;
            }

            _tempPoint = e.Location;
            OECPVertex vtx  = new OECPVertex(_tempPoint.X, _tempPoint.Y);
            var        tpEd = _canvas.C2I(vtx);

            if (_ptCollection.Count == 2)
            {
                _ptCollection[1] = tpEd;
            }
            else
            {
                _ptCollection.Add(tpEd);
            }
            _canvas.RepaintCanvas();
        }
Exemple #2
0
        public override void CanvasTool_MouseDown(object sender, MouseEventArgs e)
        {
            if (_canvas == null || CurrentLayer() == null || !CurrentLayer().IsLine)
            {
                return;
            }
            if (WorkStopped())
            {
                return;
            }
            OECPVertex vtx = new OECPVertex(e.Location.X, e.Location.Y);

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

                SetBusy();
                var st = _canvas.C2I(vtx);
                _ptCollection.Add(st);
                _canvas.VertexLayer().AddElement(st);
                _canvas.RepaintCanvas();
                return;
            }
            if (IsWorking())
            {
                SetWaiting();

                _canvas.FreezeRightClickMenu(true);
                if (e.Button == MouseButtons.Left)
                {
                    var edPt = _canvas.C2I(vtx);
                    _ptCollection.Add(edPt);
                    _canvas.VertexLayer().AddElements(_ptCollection);

                    var line = new OECPLine(_ptCollection[0], _ptCollection[1]);
                    CurrentLayer().AddElement(line);

                    _ptCollection.Clear();
                    _canvas.RepaintCanvas();
                }

                if (e.Button == MouseButtons.Right)
                {
                    var vtxLayer = _canvas.VertexLayer();
                    if (vtxLayer == null)
                    {
                        return;
                    }
                    vtx = _ptCollection[0];
                    vtxLayer.DeleteVertex(vtx);
                    _ptCollection.Clear();
                    _canvas.RepaintCanvas();
                }
            }
        }
Exemple #3
0
        //将初始矩形的坐标投影到当前画布状态
        private OECPVertex I2C(OECPVertex vtx)
        {
            var t           = (OECPVertex)vtx.Clone();;
            var w2dw1       = _square.Width / _dSquare.Width;
            var cUnitVector = new PointF(_dSquare.Location.X - vtx.X, _dSquare.Location.Y - vtx.Y);
            var x0          = _square.Location.X - cUnitVector.X * w2dw1;
            var y0          = _square.Location.Y - cUnitVector.Y * w2dw1;

            t.X = x0;
            t.Y = y0;
            return(t);
        }
Exemple #4
0
        //获得初始正方形上对应的点
        private OECPVertex C2I(OECPVertex vtx)
        {
            var tVtx        = (OECPVertex)vtx.Clone();
            var w2dw1       = _square.Width / _dSquare.Width;
            var cUnitVector = new PointF(_square.Location.X - vtx.X, _square.Location.Y - vtx.Y);
            var x0          = _dSquare.Location.X - cUnitVector.X / w2dw1;
            var y0          = _dSquare.Location.Y - cUnitVector.Y / w2dw1;

            tVtx.X = x0;
            tVtx.Y = y0;
            return(tVtx);
        }
Exemple #5
0
        public static bool VertexOnLine(OECPVertex vtx, List <OECPLayer> lineLayers, ref OECPVertex projVtx)
        {
            foreach (OECPLayer lineLayer in lineLayers)
            {
                foreach (OECPElement ele in lineLayer.LayerElements())
                {
                    var line = (OECPLine)ele;

                    if (line.Distance(vtx) <= vtx.BufferTolerance)
                    {
                        projVtx = line.GetProjectVertex(vtx);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #6
0
        public bool VertexOnLine(OECPVertex vtx, ref OECPVertex projVtx)
        {
            var lst = new List <OECPLayer>();

            foreach (OECPLayer layer in Layers)
            {
                if (!layer.IsLine)
                {
                    continue;
                }
                if (!layer.IsVisible)
                {
                    continue;
                }
                lst.Add(layer);
            }
            return(CanvasUtil.VertexOnLine(vtx, lst, ref projVtx));
        }
Exemple #7
0
        bool VertexAtBoundary(OECPVertex vtx, RectangleF square)
        {
            var leftLine  = new OECPLine(new OECPVertex(square.Left, square.Top), new OECPVertex(square.Left, square.Bottom), true);
            var rightLine = new OECPLine(new OECPVertex(square.Right, square.Top), new OECPVertex(square.Right, square.Bottom), true);
            var topLine   = new OECPLine(new OECPVertex(square.Left, square.Top), new OECPVertex(square.Right, square.Top), true);
            var botLine   = new OECPLine(new OECPVertex(square.Left, square.Bottom), new OECPVertex(square.Right, square.Bottom), true);

            bool onLeft = leftLine.VertexOnLine(vtx);

            if (onLeft)
            {
                _projVtx = leftLine.GetProjectVertex(vtx);
                return(true);
            }
            bool onRight = rightLine.VertexOnLine(vtx);

            if (onRight)
            {
                _projVtx = rightLine.GetProjectVertex(vtx);
                return(true);
            }
            bool onTop = topLine.VertexOnLine(vtx);

            if (onTop)
            {
                _projVtx = topLine.GetProjectVertex(vtx);
                return(true);
            }
            bool onBot = botLine.VertexOnLine(vtx);

            if (onBot)
            {
                _projVtx = botLine.GetProjectVertex(vtx);
                return(true);
            }
            return(false);
        }
Exemple #8
0
        public override void CanvasTool_Paint(object sender, PaintEventArgs e)
        {
            if (_canvas == null || CurrentLayer() == null || !CurrentLayer().IsLine)
            {
                return;
            }
            if (!IsWorking())
            {
                return;
            }

            OECPVertex vtx  = new OECPVertex(_tempPoint.X, _tempPoint.Y);
            var        stPt = _canvas.I2C(_ptCollection[0]);

            if (_ptCollection.Count == 1)
            {
                DrawShape(stPt.X, stPt.Y, e.Graphics);
            }

            if (_ptCollection.Count == 2)
            {
                DrawShape(stPt.X, stPt.Y, vtx.X, vtx.Y, e.Graphics);
            }
        }
Exemple #9
0
 OECPVertex ICanvasSignal.C2I(OECPVertex cVtx)
 {
     return(C2I(cVtx));
 }
Exemple #10
0
 OECPVertex ICanvasSignal.I2C(OECPVertex iVtx)
 {
     return(I2C(iVtx));
 }