Пример #1
0
            public void MouseMove(MouseEventArgs e)
            {
                _fantom.BelongsTo = _link.CurrentCutting;

                CuttingControl.PointInfo pi = _link.CurrentCutting.QueryPointInfo(e.X, e.Y);
                bool loDiag    = pi.TransX - pi.TransY - _cx + _cy < 0;
                bool loRevDiag = -pi.TransX - pi.TransY + _cx + _cy < 0;

                if (loDiag && loRevDiag || !loDiag && !loRevDiag)
                {
                    _fantom.X      = _vert.X;
                    _fantom.Y      = _vert.Y;
                    _fantom.Width  = _vert.Width;
                    _fantom.Height = _vert.Height;
                    _choosenCut    = CutType.Vertical;
                }
                else
                {
                    _fantom.X      = _horz.X;
                    _fantom.Y      = _horz.Y;
                    _fantom.Width  = _horz.Width;
                    _fantom.Height = _horz.Height;
                    _choosenCut    = CutType.Horizontal;
                }
                _link.CurrentCutting.CurrentCutFantom = _fantom;
            }
Пример #2
0
            public void MouseMove(MouseEventArgs e)
            {
                decimal detailx         = 290;
                decimal detaily         = 600;
                bool    detailcanrotate = true;

                CuttingControl.PointInfo pi = _link.CurrentCutting.QueryPointInfo(e.X, e.Y);
                if (pi.Section == null || pi.Section.SectionType != SectionType.Free)
                {
                    goto notFit;
                }

                Section.CanFitInfo cfi = pi.Section.CanFit(detailx, detaily, detailcanrotate);
                if (!cfi.CanFit)
                {
                    goto notFit;
                }

                if (cfi.NeedRotate)
                {
                    decimal t = detailx;
                    detailx = detaily;
                    detaily = t;
                }

                _fantom.BelongsTo = _link.CurrentCutting;
                _currentSection   = pi.Section;

                // для поворачиваемых деталей выбираем какой стороной расположить, в зависимости от
                // положения указателя над или под диагоналями, т.е. более длинная сторона распологается
                // вдоль той стороны свободной секции, ближе к которой находится указатель
                bool canRotate = cfi.CanRotate && detailx != detaily; // есть смысл в повороте?

                if (canRotate)
                {
                    float detailLonger;
                    float detailShorter;
                    bool  loDiag    = (float)pi.Section.Width * pi.SecY - (float)pi.Section.Height * pi.SecX < 0;
                    bool  loRevDiag = (float)pi.Section.Width * pi.SecY + (float)pi.Section.Height * pi.SecX - (float)(pi.Section.Width * pi.Section.Height) < 0;
                    if (detailx > detaily)
                    {
                        detailLonger  = (float)detailx;
                        detailShorter = (float)detaily;
                    }
                    else
                    {
                        detailLonger  = (float)detaily;
                        detailShorter = (float)detailx;
                    }
                    if (loDiag && loRevDiag || !loDiag && !loRevDiag)
                    {
                        _fantom.Width  = detailLonger;
                        _fantom.Height = detailShorter;
                    }
                    else
                    {
                        _fantom.Width  = detailShorter;
                        _fantom.Height = detailLonger;
                    }
                }
                else
                {
                    _fantom.Width  = (float)detailx;
                    _fantom.Height = (float)detaily;
                }

                _needChooseCut = _fantom.Width < (float)pi.Section.Width && _fantom.Height < (float)pi.Section.Height;

                // выбираем угол, возле которого расположить деталь - угол к которому ближе всего указатель
                // и одновременно определяем 2 возможных основых реза, из которых потом нужно будет выбрать
                _loX = pi.SecX < (float)(pi.Section.Width / 2);  // перед вертикальной серединой
                _loY = pi.SecY < (float)(pi.Section.Height / 2); // под горизонтальной серединой
                if (_loX && _loY)
                {
                    _fantom.X = (float)pi.Section.X;
                    _fantom.Y = (float)pi.Section.Y;

                    if (_needChooseCut)
                    {
                        _vertCut.X      = _fantom.X + _fantom.Width;
                        _vertCut.Y      = _fantom.Y;
                        _vertCut.Width  = 4; /*TODO*/
                        _vertCut.Height = (float)pi.Section.Height;
                        _horzCut.X      = _fantom.X;
                        _horzCut.Y      = _fantom.Y + _fantom.Height;
                        _horzCut.Width  = (float)pi.Section.Width;
                        _horzCut.Height = 4; /*TODO*/
                    }
                }
                else if (_loX && !_loY)
                {
                    _fantom.X = (float)pi.Section.X;
                    _fantom.Y = (float)(pi.Section.Y + pi.Section.Height) - _fantom.Height;

                    if (_needChooseCut)
                    {
                        _vertCut.X      = _fantom.X + _fantom.Width;
                        _vertCut.Y      = (float)pi.Section.Y;
                        _vertCut.Width  = 4; /*TODO*/
                        _vertCut.Height = (float)pi.Section.Height;
                        _horzCut.X      = _fantom.X;
                        _horzCut.Y      = _fantom.Y - 4;
                        _horzCut.Width  = (float)pi.Section.Width;
                        _horzCut.Height = 4; /*TODO*/
                    }
                }
                else if (!_loX && !_loY)
                {
                    _fantom.X = (float)(pi.Section.X + pi.Section.Width) - _fantom.Width;
                    _fantom.Y = (float)(pi.Section.Y + pi.Section.Height) - _fantom.Height;

                    if (_needChooseCut)
                    {
                        _vertCut.X      = _fantom.X - 4;
                        _vertCut.Y      = (float)pi.Section.Y;
                        _vertCut.Width  = 4; /*TODO*/
                        _vertCut.Height = (float)pi.Section.Height;
                        _horzCut.X      = (float)pi.Section.X;
                        _horzCut.Y      = _fantom.Y - 4;
                        _horzCut.Width  = (float)pi.Section.Width;
                        _horzCut.Height = 4; /*TODO*/
                    }
                }
                else if (!_loX && _loY)
                {
                    _fantom.X = (float)(pi.Section.X + pi.Section.Width) - _fantom.Width;
                    _fantom.Y = (float)pi.Section.Y;

                    if (_needChooseCut)
                    {
                        _vertCut.X      = _fantom.X - 4;
                        _vertCut.Y      = (float)pi.Section.Y;
                        _vertCut.Width  = 4; /*TODO*/
                        _vertCut.Height = (float)pi.Section.Height;
                        _horzCut.X      = (float)pi.Section.X;
                        _horzCut.Y      = _fantom.Y + _fantom.Height;
                        _horzCut.Width  = (float)pi.Section.Width;
                        _horzCut.Height = 4; /*TODO*/
                    }
                }

                _link.CurrentCutting.CurrentDetailFantom = _fantom;
                _link.CurrentCutting.Cursor = null;
                goto exit;

notFit:
                _link.CurrentCutting.Cursor = Cursors.No;
                _link.CurrentCutting.CurrentDetailFantom = null;

exit:
                ;
            }