using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms;


namespace UIControl
{
    public partial class HMI
    {
        void Draw_PickerPrinter(Graphics g, RectangleF rect,
            int motAxisY, int motAxisZ, bool reverse,
            Boolean LockY, Boolean LockZ, Boolean ItemOn, Boolean ItemPickOK,
            Boolean CylFW, Boolean CylBW)
        {
            //실제 로봇의 길이를 입력한다 (단위:mm)
            var RealLenY = 400;
            var RealLenZ = 250;

            g.FillRectangle(Brushes.DimGray, rect);
            if (LockY) g.DrawRect(rect, Color.Blue, 5);
            else g.DrawRect(rect, Color.White);

            var PXName = motAxisY == 2 ? arMotPosNameLM : arMotPosNameRM;
            g.DrawString(PXName, this.arFont_MotPosName, Brushes.Black, rect, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.DirectionVertical });

            var RPosY = this.arMotorPosition[motAxisY];
            var RPosZ = this.arMotorPosition[motAxisZ];
            //RPosY = 0;
            //RPosZ = 300;

            //모터의 실제 위치에 뭉치를 그린다.

            var PosY = (float)(rect.Top + (rect.Height - (rect.Height * RPosY / RealLenY)));

            //Y뭉치를 그린다
            var rectYP = new RectangleF(rect.X - 1, PosY - (rect.Width / 2.0f), rect.Width + 2, rect.Width);
            g.FillRectangle(Brushes.Yellow, rectYP);
            g.DrawRect(rectYP, Color.Black, 2);
            //g.DrawLine(Pens.Red, rect.X - 30, PosY, rect.Right + 130, PosY);


            //Z축을 그린다.
            RectangleF rectZ = RectangleF.Empty;
            var zwidth = 60;
            if (reverse) rectZ = new RectangleF(rect.X - zwidth, PosY - 10, zwidth, 20);
            else rectZ = new RectangleF(rect.Right, PosY - 10, zwidth, 20);

            float PosZ = 0f;
            if (reverse) PosZ = (float)(rectZ.Left + rectZ.Width - (rectZ.Width * RPosZ / RealLenZ));
            else PosZ = (float)(rectZ.Left + rectZ.Width * RPosZ / RealLenZ);

            g.FillRectangle(Brushes.DimGray, rectZ);
            if (LockZ) g.DrawRect(rectZ, Color.Blue, 5);
            else g.DrawRect(rectZ, Color.White);

            //z축 포지션 이름
            var ZposName = motAxisZ == 3 ? arMotPosNameLZ : arMotPosNameRZ;
            g.DrawString(ZposName, this.arFont_MotPosName, Brushes.Black, rectZ, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });

            //var CylStr = string.Format("FW:{0},BW:{1}", CylFW, CylBW);
            //if (CylFW == true && CylFW != CylBW) CylStr = "FW";
            //else if (CylBW == true && CylFW != CylBW) CylStr = "BW";
            //g.DrawString(CylStr, this.arFont_MotPosName, Brushes.Red, rectZ.Left, rectZ.Top - 20);

            //Z뭉치를 그린다
            var rectZP = new RectangleF(PosZ - (rectZ.Height / 2.0f), rectZ.Y - 1, rectZ.Height, rectZ.Height + 2);
            if (ItemOn)
            {
                g.FillRectangle(Brushes.Lime, rectZP);
                g.DrawRect(rectZP, Color.Black, 2);


            }
            else
            {
                g.FillRectangle(Brushes.SkyBlue, rectZP);
                g.DrawRect(rectZP, Color.Black, 2);
            }
            using (Font f = new Font("Consolas", 10, FontStyle.Bold))
                g.DrawString((ItemPickOK ? "O" : "X"), f, Brushes.Black, rectZP, new StringFormat
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                });

            //g.DrawLine(Pens.Blue, PosZ, rectZ.Top - 30, PosZ, rectZ.Bottom + 100);

        }
    }
}
