using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EpsonC3Com
{
    public class RobCoord
    {
        public class Coord   //one coord class, can check and normalize value
        {
            private double val;
            double min;     //due to size of instance give access to bounds
            double max;
            double norm;

            public Coord(double inCoord)    //contructor of coord instance, set input value as double
            {
                val = inCoord;
            }
            public Coord(double minVal, double maxVal, double normVal)  //contruct coord instance only with bounds
            {
                min = minVal;
                max = maxVal;
                norm = normVal;
                val = normVal;
            }
            //contruct coord instance only with bounds and value
            public Coord(double inCoord, double minVal, double maxVal, double normVal)
            {
                min = minVal;
                max = maxVal;
                norm = normVal;
                val = inCoord;
            }
            public void SetBound(double minVal, double maxVal, double normVal)
            {
                min = minVal;
                max = maxVal;
                norm = normVal;
            }
            public double Real
            {
                get { return val; }
                set { val = value; }
            }
            //vraci 
            public string Str
            {
                get { return val.ToString(System.Globalization.CultureInfo.InvariantCulture); }
                set { val = Convert.ToDouble(value, System.Globalization.CultureInfo.InvariantCulture); }
            }

            public bool Check(bool normalize)
            {
                if ((val <= min) || (val >= max))
                {
                    if (normalize) val = norm;
                    return false;
                }
                return true;
            }
        }

        public class XYZ
        {
            public Coord x = null, y = null, z = null, u = null, v = null, w = null;
            public enum CoordName
            {
                X, Y, Z, U, V, W
            };

            public XYZ()
            {
                InitBounds();
            }
            public XYZ(double xI, double yI, double zI)
            {
                InitBounds();
                x.Real = xI;
                y.Real = yI;
                z.Real = zI;
                u.Real = 0;
                v.Real = 0;
                w.Real = 0;
            }
            public XYZ(double xI, double yI, double zI, double uI, double vI, double wI)
            {
                InitBounds();
                x.Real = xI;
                y.Real = yI;
                z.Real = zI;
                u.Real = uI;
                v.Real = vI;
                w.Real = wI;
            }
            public RobCoord.XYZ ConvertTool()
            {
                return new XYZ(-x.Real, y.Real, z.Real, u.Real, -v.Real, w.Real);
            }
            public bool CheckCoord(bool normalize)
            {
                bool resultCheck = true;

                if (!x.Check(normalize)) resultCheck = false;
                if (!y.Check(normalize)) resultCheck = false;
                if (!z.Check(normalize)) resultCheck = false;
                if (!u.Check(normalize)) resultCheck = false;
                if (!v.Check(normalize)) resultCheck = false;
                if (!w.Check(normalize)) resultCheck = false;

                return resultCheck;
            }
            void InitBounds()
            {
                x = new Coord(-400, 400, 0);
                y = new Coord(200, 450, 200);
                z = new Coord(0, 400, 0);
                u = new Coord(-180, 180, 0);
                v = new Coord(-180, 180, 0);
                w = new Coord(-180, 180, 0);
            }
            void SetBounds(CoordName numCoord, double minVal, double maxVal, double normVal)
            {
                switch (numCoord)
                {
                    case CoordName.X: x.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.Y: y.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.Z: z.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.U: u.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.V: v.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.W: w.SetBound(minVal, maxVal, normVal); break;
                }
            }
        }

        public class JntAngl
        {
            public Coord J1;
            public Coord J2;
            public Coord J3;
            public Coord J4;
            public Coord J5;
            public Coord J6;

            public enum CoordName
            {
                J1, J2, J3, J4, J5, J6
            };

            public JntAngl()
            {
                InitBounds();
            }
            public JntAngl(double J1in, double J2in, double J3in, double J4in, double J5in, double J6in)
            {
                InitBounds();
                J1.Real = J1in;
                J2.Real = J2in;
                J3.Real = J3in;
                J4.Real = J4in;
                J5.Real = J5in;
                J6.Real = J6in;
            }
            public JntAngl(double[] JntIn)
            {
                InitBounds();
                if (JntIn.Length == 6)
                {
                    J1.Real = JntIn[0];
                    J2.Real = JntIn[1];
                    J3.Real = JntIn[2];
                    J4.Real = JntIn[3];
                    J5.Real = JntIn[4];
                    J6.Real = JntIn[5];
                }
            }
            public bool CheckCoord(bool normalize)
            {
                bool resultCheck = true;

                if (J1.Check(normalize)) resultCheck = false;
                if (J2.Check(normalize)) resultCheck = false;
                if (J3.Check(normalize)) resultCheck = false;
                if (J4.Check(normalize)) resultCheck = false;
                if (J5.Check(normalize)) resultCheck = false;
                if (J6.Check(normalize)) resultCheck = false;

                return resultCheck;
            }
            public void InitBounds()
            {
                J1 = new Coord(-170, 170, 0);
                J2 = new Coord(-160, 65, 0);
                J3 = new Coord(-51, 225, 0);
                J4 = new Coord(-200, 200, 0);
                J5 = new Coord(-135, 135, 0);
                J6 = new Coord(-360, 360, 0);
            }
            void SetBounds(CoordName numCoord, double minVal, double maxVal, double normVal)
            {
                switch (numCoord)
                {
                    case CoordName.J1: J1.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.J2: J2.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.J3: J3.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.J4: J4.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.J5: J5.SetBound(minVal, maxVal, normVal); break;
                    case CoordName.J6: J6.SetBound(minVal, maxVal, normVal); break;
                }
            }
        }
    }
}
