using System;
/*using System.Drawing;
using System.Windows.Forms;
using System.Collections;*/
//sing CategoryTheory;


namespace FormulaEditor
{
	/// <summary>
	/// The simple symbol of math formula 
	/// </summary>
    [Serializable()]
	public class IndexedSymbol : SimpleSymbol, INullArityOperation
	{

		/// <summary>
		/// The associated object
		/// </summary>
		protected object obj;


		/// <summary>
		/// Type of object
		/// </summary>
		protected object objType;

		/// <summary>
		/// Y - coordinate of child
		/// </summary>
		//private int y;

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="c">the symbol</param>
		public IndexedSymbol(char c) : this(c, (byte)FormulaConstants.Indexed, true)
		{
			s = "" + c;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="c">the symbol</param>
		/// <param name="type">the type</param>
		/// <param name="italic">the italic flag</param>
		public IndexedSymbol(char c, byte type, bool italic) : base(c, type, italic)
		{
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="c">the symbol</param>
		/// <param name="type">the type</param>
		/// <param name="italic">the italic flag</param>
		/// <param name="s">string representation</param>
		public IndexedSymbol(char c, byte type, bool italic, String s) : base(c, type, italic, s)
		{
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="c">the symbol</param>
		/// <param name="italic">the italic flag</param>
		/// <param name="type">the type</param>
		public IndexedSymbol(char c,  bool italic, byte type) : base(c, italic, type)
		{
		}


		/// <summary>
		/// Sets this object to formula
		/// </summary>
		/// <param name="formula">the formula to set</param>
		public override void SetToFormula(MathFormula formula)
		{
			base.SetToFormula(formula);
			/*if (italic)
			{
				font = fontsItalic[level];
			}
			else
			{
				font = fonts[level];
			}
			widthInsert = (int)graphics.MeasureString("y", font, 100).Width;
			*/
			if (this is BracketsSymbol | this is BinarySymbol | this is BinaryFunctionSymbol)
			{
				return;
			}
			children.Clear();
			if (level < (sizes.Length - 1))
			{
				MathFormula child = new MathFormula((byte)(level + 1), sizes);
				children.Add(child);
				//childPositions = new Point[]{new Point()};
				return;
			}
			children = null;
		}







		/// <summary>
		/// ICloneable interface implementation
		/// </summary>
		/// <returns></returns>
		public override object Clone()
		{
			return new IndexedSymbol(symbol, type, italic, s);
		}

		/// <summary>
		/// The associated object
		/// </summary>
		public object Object
		{
			get
			{
				return obj;
			}
			set
			{
				obj = value;
			}
		}

		public virtual int SubscriptIndex
		{
			get
			{
				MathFormula f = this[0];
				string s = "";
				for (int i = 0; i < f.Count; i++)
				{
					s += f[i].Symbol;
				}
				return Int32.Parse(s);
			}
		}

		/// <summary>
		/// Arity of this operation
		/// </summary>
		public int Arity
		{
			get
			{
				return 0;
			}
		}

		/// <summary>
		/// Return type
		/// </summary>
		public object ReturnType
		{
			get
			{
				return obj;
			}
		}

		/// <summary>
		/// The "is powered" sign
		/// </summary>
		public virtual bool IsPowered
		{
			get
			{
				return false;
			}
		}



		/// <summary>
		/// Calculates result of this operation
		/// </summary>
		public object this[object[] o]
		{
			get
			{
				return obj;
			}
		}

	}
}
