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

namespace Motion6D
{
    public class PositionFactory : IPositionFactory
    {

        #region Fields

        static public readonly PositionFactory Object = new PositionFactory();

        static public readonly string OwnName = "Position";

        static private IPositionFactory factory = Object;

        #endregion

        #region Ctor

        protected PositionFactory()
        {
        }
        #endregion

        #region IPositionFactory Members

        public virtual IPosition Create(object[] o)
        {
            try
            {
                double[] d = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    d[i] = (double)o[i];
                }
                return new Position(d);
            }
            catch (Exception)
            {
            }
            return null;
        }

        public virtual IPositionFactory this[string name]
        {
            get
            {
                return Object;
            }
        }

        public virtual string[] Names
        {
            get
            {
                return new string[] { OwnName };
            }
        }

        public virtual string Name
        {
            get
            {
                return OwnName;
            }
        }

        #endregion


        #region Specific Members

        static public IPositionFactory Factory
        {
            get 
            { 
                return factory; 
            }
            set 
            { 
                factory = value; 
            }
        }

        #endregion

    }
}
