Exemplo n.º 1
0
        private void DrawPlane_MouseMove(object sender, MouseEventArgs e)
        {
            switch (MouseState)
            {
            case MouseButtons.None:
                Point mpos = e.Location;
                mpos.X -= DrawCenter.X;
                mpos.Y -= DrawCenter.Y;

                Point sid = new Point((int)Math.Round((decimal)mpos.X / UnitSizeNUD.Value), (int)Math.Round((decimal)mpos.Y / UnitSizeNUD.Value));
                if (sid != FocusID)
                {
                    FocusID  = sid;
                    MousePos = e.Location;
                    DrawPlane.Refresh();
                }
                break;

            case MouseButtons.Middle:
                Point diff = e.Location - new Size(MousePos);
                DrawCenter += new Size(diff);
                MousePos    = e.Location;
                DrawPlane.Refresh();
                break;
            }
        }
Exemplo n.º 2
0
 public Task <bool> CircleAsync(DrawPlane plane, double radius, int stepCount = 64, bool doLog = true)
 {
     return(Task.FromResult(CommandAsync(new Func <bool>(() => Circle(plane, radius, stepCount, doLog)))));
 }
Exemplo n.º 3
0
        public bool Circle(DrawPlane plane, double radius, int stepCount = 64, bool doLog = true)
        {
            if (doLog)
            {
                OnMessageCall($"Drawing circle. Radius: {radius}");
            }

            double circleLength = radius * 2 * Math.PI;
            double stepLength   = circleLength / stepCount;

            return
                (stepOut() &&
                 drawCircle() &&
                 stepIn());

            bool stepOut()
            {
                switch (plane)
                {
                case DrawPlane.XY:
                    if (!OffsetMove(0, 0, 5.0) ||
                        !OffsetMove(-radius, 0, 0) ||
                        !OffsetMove(0, 0, -5.0))
                    {
                        return(false);
                    }
                    break;

                case DrawPlane.YZ:
                    if (!OffsetMove(-5.0, 0, 0) ||
                        !OffsetMove(0, 0, -radius) ||
                        !OffsetMove(5.0, 0, 0))
                    {
                        return(false);
                    }
                    break;

                case DrawPlane.XZ:
                    if (!OffsetMove(0, -5.0, 0) ||
                        !OffsetMove(-radius, 0, 0) ||
                        !OffsetMove(0, 5.0, 0))
                    {
                        return(false);
                    }
                    break;
                }

                return(true);
            }

            bool stepIn()
            {
                switch (plane)
                {
                case DrawPlane.XY:
                    if (!OffsetMove(0, 0, 5.0) ||
                        !OffsetMove(radius, 0, 0) ||
                        !OffsetMove(0, 0, -5.0))
                    {
                        return(false);
                    }
                    break;

                case DrawPlane.YZ:
                    if (!OffsetMove(-5.0, 0, 0) ||
                        !OffsetMove(0, 0, radius) ||
                        !OffsetMove(5.0, 0, 0))
                    {
                        return(false);
                    }
                    break;

                case DrawPlane.XZ:
                    if (!OffsetMove(0, -5.0, 0) ||
                        !OffsetMove(radius, 0, 0) ||
                        !OffsetMove(0, 5.0, 0))
                    {
                        return(false);
                    }
                    break;
                }

                return(true);
            }

            bool drawCircle()
            {
                for (int i = 0; i < stepCount; i++)
                {
                    double angle = 2 * Math.PI * i / stepCount;

                    switch (plane)
                    {
                    case DrawPlane.XY:
                        if (!OffsetMove(Math.Sin(angle) * stepLength, Math.Cos(angle) * stepLength, 0))
                        {
                            return(false);
                        }
                        break;

                    case DrawPlane.YZ:
                        if (!OffsetMove(0, Math.Cos(angle) * stepLength, Math.Sin(angle) * stepLength))
                        {
                            return(false);
                        }
                        break;

                    case DrawPlane.XZ:
                        if (!OffsetMove(Math.Sin(angle) * stepLength, 0, Math.Cos(angle) * stepLength))
                        {
                            return(false);
                        }
                        break;
                    }
                }

                return(true);
            }
        }