コード例 #1
0
        private void ctrlTemplateImage_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyData == (Keys.A))
                ProgramCore.MainForm.ctrlRenderControl.headController.SelectAll();
            else if (e.KeyData == (Keys.D))
                ProgramCore.MainForm.ctrlRenderControl.headController.ClearPointsSelection();
            else if (e.KeyData == (Keys.ShiftKey | Keys.Shift))
                shiftKeyPressed = true;
            else if (e.KeyData == Keys.Enter)
            {
                switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
                {
                    case Mode.HeadLine:
                        if (ProgramCore.MainForm.HeadProfile)
                        {
                            if (isProfileSmoothing)
                            {
                                isProfileSmoothing = false;
                                ProgramCore.MainForm.panelFront.UpdateProfileSmoothing(isProfileSmoothing);
                            }
                            else
                            if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count == 2)
                            {
                                if (ProgramCore.MainForm.ctrlRenderControl.headController.AllPoints.Count > 3)
                                {
                                    foreach (var point in ProgramCore.MainForm.ctrlRenderControl.headController.AllPoints)
                                        point.UpdateWorldPoint();

                                    #region История (undo)

                                    Dictionary<Guid, MeshUndoInfo> undoInfo;
                                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.GetUndoInfo(out undoInfo);
                                    var isProfile = ProgramCore.MainForm.HeadProfile;
                                    var teInfo = isProfile ? ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo : ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo;
                                    var historyElem = new HistoryHeadShapeLines(undoInfo, null, teInfo, isProfile);
                                    ProgramCore.MainForm.ctrlRenderControl.historyController.Add(historyElem);

                                    #endregion

                                    var userPoints = ProgramCore.MainForm.ctrlRenderControl.headController.AllPoints.Select(x => x.ValueMirrored).ToList();
                                    List<Vector2> pointsTop = new List<Vector2>();
                                    List<Vector2> pointsBottom = null;
                                    var lipsY = ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.GetLipsTopY();
                                    var prevPoint = Vector2.Zero;
                                    for (int i = 0; i < userPoints.Count; ++i)
                                    {
                                        var p = userPoints[i];
                                        var x = p.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX;
                                        var y = p.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY;
                                        var point = ProgramCore.MainForm.ctrlRenderControl.camera.GetWorldPoint((int)x, (int)y,
                                            ProgramCore.MainForm.ctrlRenderControl.Width, ProgramCore.MainForm.ctrlRenderControl.Height, 1.0f).Zy;

                                        if (point.Y < lipsY && i > 0)
                                        {
                                            if (pointsBottom == null)
                                            {
                                                var tempPoint = point - prevPoint;
                                                var d = (point.Y - prevPoint.Y) / (prevPoint.Y - lipsY);
                                                var center = prevPoint + tempPoint * d;
                                                pointsTop.Add(center);
                                                pointsBottom = new List<Vector2>();
                                                pointsBottom.Add(center);
                                            }
                                            pointsBottom.Add(point);
                                        }
                                        else
                                        {
                                            prevPoint = point;
                                            pointsTop.Add(point);
                                        }
                                    }

                                    ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(MeshPartType.ProfileTop, pointsTop, Vector2.Zero);
                                    ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(MeshPartType.ProfileBottom, pointsBottom, Vector2.Zero);

                                    var th = new Thread(() =>
                                    {
                                        Thread.CurrentThread.IsBackground = true;
                                        ProgramCore.MainForm.ctrlRenderControl.headMeshesController.Smooth();
                                    });

                                    th.Start();
                                    while (th.IsAlive)
                                        ProgramCore.Progress("Please wait");

                                    ProfileSmoothing = new ProfileSmoothing(ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh, undoInfo);
                                }

                                foreach (var p in ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Parts)
                                    p.UpdateNormals();

                                ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Clear();
                                //ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = ProgramCore.MainForm.ctrlRenderControl.HeadLineMode == MeshPartType.ProfileTop ? MeshPartType.ProfileBottom : MeshPartType.ProfileTop;
                                ProgramCore.MainForm.ctrlRenderControl.UpdateProfileRectangle();
                                isProfileSmoothing = true;
                                ProgramCore.MainForm.panelFront.UpdateProfileSmoothing(isProfileSmoothing);
                            }
                            else
                                FinishLine();
                        }
                        else
                            FinishLine();
                        break;
                    case Mode.None:
                        if (ProgramCore.MainForm.HeadProfile)
                            switch (ControlPointsMode)
                            {
                                case ProfileControlPointsMode.MoveControlPoints:
                                    UpdateProfileImageByControlPoints();

                                    UpdateProfileRectangle();
                                    ProgramCore.MainForm.ctrlRenderControl.UpdateProfileRectangle();
                                    ControlPointsMode = ProfileControlPointsMode.UpdateRightLeft;
                                    break;
                                case ProfileControlPointsMode.UpdateRightLeft:
                                    UpdateProfileRectangle();
                                    foreach (var point in profileControlPoints)
                                        point.Selected = false;

                                    ControlPointsMode = ProfileControlPointsMode.None;
                                    break;
                            }

                        break;
                }
            }
        }
コード例 #2
0
        public void pictureTemplate_MouseMove(object sender, MouseEventArgs e)
        {
            if (startMousePoint == Vector2.Zero)
                startMousePoint = new Vector2(e.X, e.Y);

            var firstMove = false;
            if (Math.Abs(startMousePoint.X - e.X) > 1 || Math.Abs(startMousePoint.Y - e.Y) > 1) // small exp
            {
                if (!startMove)
                    firstMove = true;

                startMove = true;
            }

            if (leftMousePressed)
            {
                Vector2 newPoint;
                Vector2 delta2;
                newPoint.X = (e.X - ImageTemplateOffsetX) / (ImageTemplateWidth * 1f);
                newPoint.Y = (e.Y - ImageTemplateOffsetY) / (ImageTemplateHeight * 1f);
                switch (ProgramCore.MainForm.ctrlRenderControl.ScaleMode)
                {
                    case ScaleMode.Move:
                        {
                            if (ProgramCore.MainForm.HeadProfile)
                                break;

                            switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
                            {
                                //      case Mode.HeadShapedots:
                                case Mode.HeadLine: // эти моды только для этих режимов!
                                case Mode.HeadAutodots:
                                case Mode.HeadAutodotsFirstTime:
                                case Mode.HeadAutodotsLassoStart:
                                case Mode.HeadAutodotsLassoActive:

                                    newPoint = new Vector2(e.X, e.Y);
                                    delta2 = newPoint - headLastPoint;
                                    ImageTemplateOffsetX = (int)(tempOffsetPoint.X + delta2.X);
                                    ImageTemplateOffsetY = (int)(tempOffsetPoint.Y + delta2.Y);
                                    RecalcEyeMouthRect();
                                    UpdateFaceRect();
                                    break;
                            }
                        }
                        break;
                    case ScaleMode.Zoom:
                        {
                            if (ProgramCore.MainForm.HeadProfile)
                                break;
                            switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
                            {
                                //   case Mode.HeadShapedots:
                                case Mode.HeadLine: // эти моды только для этих режимов!
                                case Mode.HeadAutodots:
                                case Mode.HeadAutodotsFirstTime:
                                case Mode.HeadAutodotsLassoStart:
                                case Mode.HeadAutodotsLassoActive:
                                    if (startMove)
                                    {
                                        var s = imageScale + (headLastPoint.Y - e.Y) * 0.01f;
                                        if (s < 1.0f)
                                            imageScale = 1.0f;
                                        else if (s > 5.0f)
                                            imageScale = 5.0f;
                                        else
                                        {
                                            ApplyScale(s);
                                            RefreshPictureBox();
                                        }
                                        headLastPoint = new Vector2(e.X, e.Y);
                                        RecalcEyeMouthRect();
                                        UpdateFaceRect();
                                    }
                                    break;
                            }
                        }
                        break;
                    case ScaleMode.None:

                        #region Если нет зума - обрабатываем обычные режимы

                        switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
                        {
                            case Mode.HeadAutodotsFirstTime:
                            case Mode.HeadAutodots:
                                if (ProgramCore.Project.ShapeFlip != FlipType.None)
                                    return;

                                if (firstMove &&
                                    ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.SelectedPoints.Count >
                                    0)
                                {
                                    var history =
                                        new HistoryHeadAutoDots(
                                            ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots);
                                    ProgramCore.MainForm.ctrlRenderControl.historyController.Add(history);

                                    Dictionary<Guid, MeshUndoInfo> undoInfo;
                                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.GetUndoInfo(
                                        out undoInfo);
                                    ProgramCore.MainForm.ctrlRenderControl.historyController.Add(
                                        new HistoryHeadShapeDots(undoInfo,
                                            ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots));
                                }

                                if (startMove)
                                {
                                    if (firstMove)
                                        Cursor = ProgramCore.MainForm.GrabbingCursor;

                                    delta2 = newPoint - headLastPointRelative;
                                    if (moveRectIndex != -1) //таскаем прямоугольничек
                                    {
                                        var deltaX = (int)(e.X - headLastPoint.X);
                                        var deltaY = (int)(e.Y - headLastPoint.Y);
                                        switch (moveRectIndex)
                                        {
                                            case 1:
                                                FaceRectTransformed.X += deltaX;
                                                FaceRectTransformed.Width -= deltaX;
                                                FaceRectTransformed.Y += deltaY;
                                                FaceRectTransformed.Height -= deltaY;
                                                break;
                                            case 2:
                                                FaceRectTransformed.Width += deltaX;
                                                FaceRectTransformed.Y += deltaY;
                                                FaceRectTransformed.Height -= deltaY;
                                                break;
                                            case 3:
                                                FaceRectTransformed.Width += deltaX;
                                                FaceRectTransformed.Height += deltaY;
                                                break;
                                            case 4:
                                                FaceRectTransformed.Width -= deltaX;
                                                FaceRectTransformed.X += deltaX;
                                                FaceRectTransformed.Height += deltaY;
                                                break;
                                        }
                                        headLastPoint = new Vector2(e.X, e.Y);

                                        Vector2 center;
                                        var temp = FaceRectTransformed.X + FaceRectTransformed.Width * 0.5f;
                                        center.X = ((temp - ImageTemplateOffsetX) / (ImageTemplateWidth * 1f));
                                        temp = FaceRectTransformed.Y + FaceRectTransformed.Height * 0.5f;
                                        center.Y = (temp - ImageTemplateOffsetY) / (ImageTemplateHeight * 1f);

                                        var newWidth = (FaceRectTransformed.Width) / (ImageTemplateWidth * 1f);
                                        var newHeight = (FaceRectTransformed.Height) / (ImageTemplateHeight * 1f);
                                        var kx = newWidth / tempMoveRectWidth;
                                        var ky = newHeight / tempMoveRectHeight;
                                        foreach (
                                            var point in
                                                ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots
                                                    .SelectedPoints)
                                        {
                                            var p = point.ValueMirrored - tempMoveRectCenter;
                                            p.X *= kx;
                                            p.Y *= ky;
                                            point.ValueMirrored = p + center;
                                            point.UpdateWorldPoint();
                                        }
                                        tempMoveRectCenter = center;
                                        tempMoveRectWidth = newWidth;
                                        tempMoveRectHeight = newHeight;
                                        UpdateUserCenterPositions(false, true);
                                    }
                                    else // таскаем точки
                                    {
                                        var selectedPoints =
                                            ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots
                                                .SelectedPoints;
                                        for (var i = 0; i < selectedPoints.Count; i++)
                                        {
                                            var headPoint = selectedPoints[i];
                                            headPoint.ValueMirrored = headTempPoints[i].ValueMirrored + delta2;

                                            headPoint.UpdateWorldPoint();
                                        }
                                        UpdateUserCenterPositions(true, true);
                                    }
                                }
                                break;
                            case Mode.HeadLine:
                                if (ProgramCore.Project.ShapeFlip != FlipType.None)
                                    return;

                                if (LineSelectionMode)
                                {
                                    if (firstMove &&
                                        ProgramCore.MainForm.ctrlRenderControl.headController.SelectedPoints.Count > 0)
                                    {
                                        var isProfile = ProgramCore.MainForm.HeadProfile;
                                        var teInfo = isProfile
                                            ? ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper
                                                .ShapeProfileInfo
                                            : ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo;
                                        var historyElem = new HistoryHeadShapeLines(null,
                                            ProgramCore.MainForm.ctrlRenderControl.headController.Lines, teInfo,
                                            isProfile);
                                        historyElem.Group =
                                            ProgramCore.MainForm.ctrlRenderControl.historyController.currentGroup;
                                        ProgramCore.MainForm.ctrlRenderControl.historyController.Add(historyElem);
                                    }

                                    delta2 = newPoint - headLastPointRelative;
                                    for (var i = 0;
                                        i < ProgramCore.MainForm.ctrlRenderControl.headController.SelectedPoints.Count;
                                        i++)
                                    {
                                        var headPoint =
                                            ProgramCore.MainForm.ctrlRenderControl.headController.SelectedPoints[i];
                                        headPoint.ValueMirrored = headTempPoints[i].ValueMirrored + delta2;
                                        headPoint.UpdateWorldPoint();
                                    }
                                }
                                break;
                            /*     case Mode.HeadShapedots:
                                     if (ProgramCore.Project.ShapeFlip != FlipType.None)
                                         return;

                                     if (startMove)
                                     {
                                         if (firstMove)
                                             Cursor = ProgramCore.MainForm.GrabbingCursor;

                                         if (firstMove &&
                                             ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.SelectedPoints
                                                 .Count > 0)
                                         {
                                             Dictionary<Guid, MeshUndoInfo> undoInfo;
                                             ProgramCore.MainForm.ctrlRenderControl.headMeshesController.GetUndoInfo(
                                                 out undoInfo);
                                             ProgramCore.MainForm.ctrlRenderControl.historyController.Add(
                                                 new HistoryHeadShapeDots(undoInfo,
                                                     ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots));
                                         }

                                         delta2 = newPoint - headLastPointRelative;
                                         if (moveRectIndex != -1) //таскаем прямоугольничек
                                         {
                                             var deltaX = (int)(e.X - headLastPoint.X);
                                             var deltaY = (int)(e.Y - headLastPoint.Y);
                                             switch (moveRectIndex)
                                             {
                                                 case 1:
                                                     FaceRectTransformed.X += deltaX;
                                                     FaceRectTransformed.Width -= deltaX;
                                                     FaceRectTransformed.Y += deltaY;
                                                     FaceRectTransformed.Height -= deltaY;
                                                     break;
                                                 case 2:
                                                     FaceRectTransformed.Width += deltaX;
                                                     FaceRectTransformed.Y += deltaY;
                                                     FaceRectTransformed.Height -= deltaY;
                                                     break;
                                                 case 3:
                                                     FaceRectTransformed.Width += deltaX;
                                                     FaceRectTransformed.Height += deltaY;
                                                     break;
                                                 case 4:
                                                     FaceRectTransformed.Width -= deltaX;
                                                     FaceRectTransformed.X += deltaX;
                                                     FaceRectTransformed.Height += deltaY;
                                                     break;
                                             }
                                             headLastPoint = new Vector2(e.X, e.Y);

                                             Vector2 center;
                                             var temp = FaceRectTransformed.X + FaceRectTransformed.Width * 0.5f;
                                             center.X = ((temp - ImageTemplateOffsetX) / (ImageTemplateWidth * 1f));
                                             temp = FaceRectTransformed.Y + FaceRectTransformed.Height * 0.5f;
                                             center.Y = (temp - ImageTemplateOffsetY) / (ImageTemplateHeight * 1f);

                                             var newWidth = (FaceRectTransformed.Width) / (ImageTemplateWidth * 1f);
                                             var newHeight = (FaceRectTransformed.Height) / (ImageTemplateHeight * 1f);
                                             var kx = newWidth / tempMoveRectWidth;
                                             var ky = newHeight / tempMoveRectHeight;
                                             foreach (
                                                 var point in
                                                     ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots
                                                         .SelectedPoints)
                                             {
                                                 var p = point.ValueMirrored - tempMoveRectCenter;
                                                 p.X *= kx;
                                                 p.Y *= ky;
                                                 point.ValueMirrored = p + center;
                                                 point.UpdateWorldPoint();
                                             }
                                             tempMoveRectCenter = center;
                                             tempMoveRectWidth = newWidth;
                                             tempMoveRectHeight = newHeight;
                                             UpdateUserCenterPositions(false, true);
                                         }
                                         else // таскаем точки
                                         {
                                             var selectedPoints =
                                                 ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots
                                                     .SelectedPoints;
                                             for (var i = 0; i < selectedPoints.Count; i++)
                                             {
                                                 var headPoint = selectedPoints[i];
                                                 headPoint.ValueMirrored = headTempPoints[i].ValueMirrored + delta2;
                                                 headPoint.UpdateWorldPoint();
                                             }
                                             UpdateUserCenterPositions(true, true);
                                         }
                                     }
                                     else Cursor = ProgramCore.MainForm.GrabCursor;
                                     break;*/
                            case Mode.None:
                                {
                                    switch (ControlPointsMode)
                                    {
                                        case ProfileControlPointsMode.MoveControlPoints:
                                        case ProfileControlPointsMode.UpdateRightLeft:
                                            {
                                                delta2 = newPoint - headLastPointRelative;
                                                for (var i = 0; i < profileControlPoints.Count; i++)
                                                {
                                                    var headPoint = profileControlPoints[i];
                                                    if (!headPoint.Selected)
                                                        continue;

                                                    headPoint.ValueMirrored = headTempPoints[i].ValueMirrored + delta2;
                                                }
                                            }
                                            break;
                                    }
                                }
                                break;
                        }

                        #endregion

                        break;
                }

            }
            else
            {
                switch (ProgramCore.MainForm.ctrlRenderControl.ScaleMode)
                {
                    case ScaleMode.None:
                        {
                            switch (ProgramCore.MainForm.ctrlRenderControl.Mode)
                            {
                                case Mode.HeadAutodotsFirstTime:
                                case Mode.HeadAutodots:
                                    if (ProgramCore.Project.ShapeFlip != FlipType.None)
                                        return;

                                    if ((e.X >= MouthTransformed.X - HalfPointRectSize && e.X <= MouthTransformed.X + HalfPointRectSize && e.Y >= MouthTransformed.Y - HalfPointRectSize && e.Y <= MouthTransformed.Y + HalfPointRectSize)       // рот
                                   || (e.X >= LeftEyeTransformed.X - HalfPointRectSize && e.X <= LeftEyeTransformed.X + HalfPointRectSize && e.Y >= LeftEyeTransformed.Y - HalfPointRectSize && e.Y <= LeftEyeTransformed.Y + HalfPointRectSize)  // левый глаз
                                   || (e.X >= RightEyeTransformed.X - HalfPointRectSize && e.X <= RightEyeTransformed.X + HalfPointRectSize && e.Y >= RightEyeTransformed.Y - HalfPointRectSize && e.Y <= RightEyeTransformed.Y + HalfPointRectSize)  // правый глаз
                                    || (e.X >= NoseTransformed.X - HalfPointRectSize && e.X <= NoseTransformed.X + HalfPointRectSize && e.Y >= NoseTransformed.Y - HalfPointRectSize && e.Y <= NoseTransformed.Y + HalfPointRectSize) // нос
                                    || (e.X >= CentralFacePoint.X - HalfPointRectSize && e.X <= CentralFacePoint.X + HalfPointRectSize && e.Y >= CentralFacePoint.Y - HalfPointRectSize && e.Y <= CentralFacePoint.Y + HalfPointRectSize) // прямоугольник и выделение всех точек
                                    || ProgramCore.MainForm.ctrlRenderControl.headController.UpdateAutodotsPointSelection(e.X, e.Y, false))
                                        Cursor = ProgramCore.MainForm.GrabCursor;
                                    else
                                        Cursor = Cursors.Arrow;
                                    break;
                                    /*        case Mode.HeadShapedots:
                                                if (ProgramCore.Project.ShapeFlip != FlipType.None)
                                                    return;
                                                if ((e.X >= MouthTransformed.X - HalfPointRectSize &&
                                                     e.X <= MouthTransformed.X + HalfPointRectSize &&
                                                     e.Y >= MouthTransformed.Y - HalfPointRectSize &&
                                                     e.Y <= MouthTransformed.Y + HalfPointRectSize) // рот
                                                    ||
                                                    (e.X >= LeftEyeTransformed.X - HalfPointRectSize &&
                                                     e.X <= LeftEyeTransformed.X + HalfPointRectSize &&
                                                     e.Y >= LeftEyeTransformed.Y - HalfPointRectSize &&
                                                     e.Y <= LeftEyeTransformed.Y + HalfPointRectSize) // левый глаз
                                                    ||
                                                    (e.X >= RightEyeTransformed.X - HalfPointRectSize &&
                                                     e.X <= RightEyeTransformed.X + HalfPointRectSize &&
                                                     e.Y >= RightEyeTransformed.Y - HalfPointRectSize &&
                                                     e.Y <= RightEyeTransformed.Y + HalfPointRectSize) // правый глаз
                                                    ||
                                                    (e.X >= NoseTransformed.X - HalfPointRectSize &&
                                                     e.X <= NoseTransformed.X + HalfPointRectSize &&
                                                     e.Y >= NoseTransformed.Y - HalfPointRectSize &&
                                                     e.Y <= NoseTransformed.Y + HalfPointRectSize) // нос
                                                    ||
                                                    (e.X >= CentralFacePoint.X - HalfPointRectSize &&
                                                     e.X <= CentralFacePoint.X + HalfPointRectSize &&
                                                     e.Y >= CentralFacePoint.Y - HalfPointRectSize &&
                                                     e.Y <= CentralFacePoint.Y + HalfPointRectSize)
                                                    // прямоугольник и выделение всех точек
                                                    ||
                                                    ProgramCore.MainForm.ctrlRenderControl.headController
                                                        .UpdateShapedotsPointSelection(e.X, e.Y, false))
                                                    Cursor = ProgramCore.MainForm.GrabCursor;
                                                else
                                                    Cursor = Cursors.Arrow;
                                                break;*/
                            }
                            break;

                        }
                }
            }
        }
コード例 #3
0
        public void btnPolyLine_Click(object sender, EventArgs e)
        {
            if (UserConfig.ByName("Options")["Tutorials", "LineTool", "1"] == "1")
                frmTutLineTool.ShowDialog(this);

            if (btnPolyLine.Tag.ToString() == "2")
            {
                if (ProgramCore.MainForm.HeadProfile && ProgramCore.MainForm.ctrlTemplateImage.ControlPointsMode != ProfileControlPointsMode.None)
                {
                    MessageBox.Show("Set Control Points !", "HeadShop", MessageBoxButtons.OK);
                    return; // значит загрузили картинку, но не назначили ей опорные точки. нельзя ниче делатЬ!
                }

                ++ProgramCore.MainForm.ctrlRenderControl.historyController.currentGroup;
                btnPolyLine.Tag = "1";
                btnDots.Tag = btnShapeTool.Tag = "2";

                btnPolyLine.Image = Properties.Resources.btnPolyLinePressed;
                btnDots.Image = Properties.Resources.btnDotsNormal;
                btnShapeTool.Image = Properties.Resources.btnHandNormal1;

                SetDefaultHeadRotation();
                ProgramCore.MainForm.DisableRotating();

                ProgramCore.MainForm.ctrlRenderControl.Mode = Mode.HeadLine;
                ProgramCore.MainForm.ctrlTemplateImage.UpdateUserCenterPositions(false, true);

                //  UpdateFlipEnable(ProgramCore.Project.ShapeFlip);
                SetPanelLogic();
                if (ProgramCore.MainForm.HeadProfile)
                {
                    ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.ProfileTop;
                    ProgramCore.MainForm.ctrlTemplateImage.UpdateProfileLocation();
                }
            }
            else
            {
                btnPolyLine.Tag = "2";
                btnPolyLine.Image = Properties.Resources.btnPolyLineNormal;

                var userPoints = ProgramCore.MainForm.ctrlRenderControl.headController.AllPoints.Select(x => x.Value).ToList();
                if (userPoints.Count >= 3)          // если твое условие - просто не выполняем ничего. но интерфейсно все равно отключить надо!
                {
                    #region История (undo)

                    Dictionary<Guid, MeshUndoInfo> undoInfo;
                    ProgramCore.MainForm.ctrlRenderControl.headMeshesController.GetUndoInfo(out undoInfo);
                    var isProfile = ProgramCore.MainForm.HeadProfile;
                    var teInfo = isProfile ? ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo : ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo;
                    var historyElem = new HistoryHeadShapeLines(undoInfo, ProgramCore.MainForm.ctrlRenderControl.headController.Lines, teInfo, isProfile);
                    historyElem.Group = ProgramCore.MainForm.ctrlRenderControl.historyController.currentGroup;
                    ProgramCore.MainForm.ctrlRenderControl.historyController.Add(historyElem);

                    #endregion

                    ProgramCore.MainForm.ctrlTemplateImage.FinishLine();
                    switch (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode)
                    {
                        case MeshPartType.LEye:
                        case MeshPartType.REye:
                            userPoints.RemoveAt(userPoints.Count - 1);
                            var center = ProgramCore.MainForm.ctrlRenderControl.HeadLineMode == MeshPartType.LEye ? ProgramCore.Project.LeftEyeUserCenter : ProgramCore.Project.RightEyeCenter;
                            center = MirroredHeadPoint.UpdateWorldPoint(center);

                            ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, center);
                            break;
                        case MeshPartType.Nose: //тут центр не нужен,сказал воваш..
                            ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, Vector2.Zero);
                            break;
                        case MeshPartType.Lip: // ТУТ ЦЕНТР???
                            ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, Vector2.Zero);
                            break;
                        case MeshPartType.Head:
                            userPoints.RemoveAt(userPoints.Count - 1);
                            var leftTop = new Vector2(ProgramCore.Project.LeftEyeUserCenter.X, Math.Max(ProgramCore.Project.LeftEyeUserCenter.Y, ProgramCore.Project.RightEyeUserCenter.Y));
                            var rightBottom = new Vector2(ProgramCore.Project.RightEyeUserCenter.X, ProgramCore.Project.MouthUserCenter.Y);

                            var eyesMouthRect = new RectangleF(leftTop.X, leftTop.Y, rightBottom.X - leftTop.X, rightBottom.Y - leftTop.Y);
                            center = new Vector2(eyesMouthRect.X + eyesMouthRect.Width * 0.5f, eyesMouthRect.Y + eyesMouthRect.Height * 0.5f);
                            center = MirroredHeadPoint.UpdateWorldPoint(center);

                            ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, center);
                            break;
                    }
                }

                ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Clear();

                ProgramCore.MainForm.EnableRotating();
                UpdateNormals();

                ProgramCore.MainForm.ctrlRenderControl.Mode = Mode.None;
                ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.None;

                ProgramCore.MainForm.ctrlTemplateImage.LineSelectionMode = false;
                ProgramCore.MainForm.ctrlTemplateImage.ResetProfileRects();
                ProgramCore.MainForm.ctrlRenderControl.ProfileFaceRect = RectangleF.Empty;

                //    DisableFlip();
                SetPanelLogic();
            }
        }