/// <summary> /// Appends new symbol to this object /// </summary> /// <param name="symbol">the symbol to append</param> public void Append(MathSymbol symbol) { MathSymbol s = Next; if (s != null) { s.Insert(symbol); return; } parent.InsertObject(symbol); }
/// <summary> /// Creates Element from symbol /// </summary> /// <param name="symbol">The symbol</param> /// <param name="document">The doucument</param> /// <param name="creator">Creator</param> /// <returns>The element</returns> public static XElement CreateElement(MathSymbol symbol, IXmlSymbolCreator creator) { XElement e = creator.CreateElement(symbol); for (int i = 0; i < symbol.Count; i++) { XElement el = MathFormula.CreateElement(symbol[i], creator); e.Add(el); } return(e); }
/// <summary> /// Appends the symbol to formula /// </summary> /// <param name="formula">Formula the formula to append</param> /// <returns>Next inserted object</returns> public MathFormula Append(MathFormula formula) { try { MathSymbol symbol = (MathSymbol)Clone(); symbol.SetToFormula(formula); formula.Add(symbol); symbol.parent = formula; } finally { } return(formula); }
/// <summary> /// Wraps this symbol by brackets /// </summary> /// <returns>Next symbol</returns> public MathSymbol Wrap(string prohibited) { sym = Next; if (ShouldWrapped) { Insert(Bra); Append(Ket); } if (HasChildren) { for (int i = 0; i < Count; i++) { this[i].Wrap(prohibited); } } return(sym); }
/// <summary> /// Checks whether children contains the symbol /// </summary> /// <param name="s">the symbol</param> /// <returns>the result of checking</returns> public bool Contains(MathSymbol s) { if (s == this) { return(true); } if (HasChildren) { for (int i = 0; i < Count; i++) { if (this[i].Contains(s)) { return(true); } } } return(false); }
/// <summary> /// Craeates symbol from Xml element /// </summary> /// <param name="e">The element</param> /// <param name="creator">The creator</param> /// <returns>The symbol</returns> public static MathSymbol CreateSymbol(XElement e, IXmlSymbolCreator creator) { MathSymbol s = creator.CreateSymbol(e); IEnumerable <XElement> l = e.GetElementsByTagName("F"); List <MathFormula> list = new List <MathFormula>(); foreach (XElement el in l) { if (el.Parent != e) { continue; } MathFormula f = MathFormula.CreateFormula(el, creator); list.Add(f); } s.Children = list; return(s); }
/// <summary> /// Inserts symbol /// </summary> /// <param name="formula">The formula to insert</param> /// <param name="previosSymbol">The previos symbol</param> /// <returns>Inserted object</returns> public object InsertBefore(MathFormula formula, MathSymbol previosSymbol) { try { MathSymbol symbol = (MathSymbol)Clone(); symbol.SetToFormula(formula); int n = formula.IndexOf(previosSymbol); formula.Insert(n, symbol); symbol.parent = formula; if (symbol is BracketsSymbol) { return(symbol[0]); } return(symbol.NextObject); } finally { } }
private static void getOperationIndexes(MathFormula formula, List <int> list) { for (int i = 0; i < formula.Count; i++) { MathSymbol s = formula[i]; for (int j = 0; j < s.Count; j++) { getOperationIndexes(s[j], list); } if (!(s is SeriesSymbol)) { continue; } SeriesSymbol ss = s as SeriesSymbol; int ind = ss.index; if (!list.Contains(ind)) { list.Add(ind); } } }
/// <summary> /// Makes copy of the symbol /// </summary> /// <returns>the copy</returns> public MathSymbol Copy() { try { sym = Clone() as MathSymbol; if (children != null) { sym.children = new List <MathFormula>(); for (int i = 0; i < Count; i++) { if (this[i] != null) { sym.children.Add(this[i].Copy()); } } } sym.doubleValue = doubleValue; return(sym); } finally { } }
/// <summary> /// Sets operations to formula /// </summary> /// <param name="formula">The formula</param> /// <param name="table">Table of operations</param> public static void SetOperations(MathFormula formula, Dictionary <int, IOperationAcceptor> table) { for (int i = 0; i < formula.Count; i++) { MathSymbol s = formula[i]; for (int j = 0; j < s.Count; j++) { SetOperations(s[j], table); } if (!(s is SeriesSymbol)) { continue; } SeriesSymbol ss = s as SeriesSymbol; int ind = ss.index; ss.acceptor = null; if (!table.ContainsKey(ind)) { throw new Exception("Operation with index " + ind + " does not exist"); } IOperationAcceptor acc = table[ind]; ss.acceptor = acc; } }
/// <summary> /// Resets auxiliary variables /// </summary> public void Zero() { sym = null; sym1 = null; }
/// <summary> /// Insetrs symbol before this symbol /// </summary> /// <param name="symbol">The symbol</param> /// <param name="inserted">Inserted symbol</param> /// <returns>The inserted object</returns> public static object InsertObject(MathSymbol symbol, MathSymbol inserted) { return(inserted.InsertBefore(symbol.Parent, symbol)); }
/// <summary> /// Transformation of string representation of double values /// </summary> /// <returns>the transformation result</returns> public MathSymbol TranNumber() { string str = ""; sym = Next; if (type != (byte)FormulaConstants.Number) { if (symbol != '.' | !s.Equals(".")) { return(sym); } } str += symbol; if (HasChildren) { if (str.Length > 2) { if (str[1] == 'x') { ulong a = Hex(str); ulong b = a >> 32; if (b == 0) { doubleValue = a; symbol = '?'; return(sym); } ulongValue = a; symbol = '$'; return(sym); } } if (!MathFormula.Resources.ContainsKey(".")) { str = str.Replace('.', DecimalSep[0]); } if (double.TryParse(str, out doubleValue)) { symbol = '?'; } return(sym); } MathFormula f = new MathFormula((byte)0); while (true) { try { if (sym == null) { if (str.Length > 2) { if (str[1] == 'x') { ulong a = Hex(str); ulong b = a >> 32; if (b == 0) { doubleValue = a; symbol = '?'; return(sym); } ulongValue = a; symbol = '$'; return(sym); } } str = str.Replace('.', DecimalSep[0]); if (double.TryParse(str, out doubleValue)) { symbol = '?'; } return(sym); } if ((sym.type != (byte)FormulaConstants.Number) & (sym.symbol != '.')) { if (str.Length > 2) { if ((str[1] == 'x')) { ulong a = Hex(str); ulong b = a >> 32; if (b == 0) { doubleValue = a; symbol = '?'; return(sym); } ulongValue = a; symbol = '$'; return(sym); } } str = str.Replace('.', DecimalSep[0]); doubleValue = Double.Parse(str); symbol = '?'; return(sym); } if (sym.HasChildren) { children[0] = sym.children[0]; str = str.Replace('.', DecimalSep[0]); doubleValue = Double.Parse(str); sym.Remove(); return(Next); } else { str += sym.symbol; if (str.Equals("..")) { return(sym); } sym1 = sym.Next; sym.Remove(); sym = sym1; } } finally { //throw new Exception(ERRORS[4] + ex.getMessage()); } } }
/// <summary> /// Replaces this symbol /// </summary> /// <param name="s">the symbol to replace</param> public void Replace(MathSymbol s) { Append(s); Remove(); }
/// <summary> /// Inserts symbol before this object /// </summary> /// <param name="symbol">the symbol to insert</param> public void Insert(MathSymbol symbol) { InsertObject(this, symbol); }
/// <summary> /// Checks whether the symbol is same /// </summary> /// <param name="sym">Symbol</param> /// <returns>True if same and false otherwise</returns> public virtual bool IsSame(MathSymbol sym) { return(false); }