/// <summary> /// Deletes zeros /// </summary> private void DelZero() { MathSymbol s = First; if (s != null) { MathSymbol s1 = s.Next; if (s1 != null) { if (s.SymbolType == (int)FormulaConstants.Number & s.DoubleValue == 0 & s.Symbol == '?' & s1.Symbol == '-') { s.Remove(); } } } s = First; while (s != null) { if (s.HasChildren) { for (int i = 0; i < s.Count; i++) { s[i].DelZero(); } } s = s.Next; } }
/// <summary> /// Key up /// </summary> /// <param name="sender">Sender</param> /// <param name="args">Arguments</param> private void keyUp(object sender, KeyEventArgs args) { if (args.KeyData != Keys.Back) { return; } MathSymbol sym = formula.Last; if (sym != null) { sym.Remove(); DrawFormulaOnComponent(); } }
/// <summary> /// Deletes unnecessary multiplication symbols /// </summary> private void DelMult() { MathSymbol s = First; if (s != null) { MathSymbol s1 = s.Next; while (s1 != null) { if (s1.SymbolType == (int)FormulaConstants.Binary & s1.Symbol == '*') { if (s.SymbolType != (int)FormulaConstants.Number | s1.Next.SymbolType != (int)FormulaConstants.Number) { s1.Remove(); s = s.Next; if (s == null) { break; } s1 = s.Next; continue; } } s = s1; s1 = s.Next; } } s = First; while (s != null) { if (s.HasChildren) { for (int i = 0; i < s.Count; i++) { s[i].DelMult(); } } s = s.Next; } }
/// <summary> /// Reverses digital to symbolic represrntation /// </summary> private void ReverseNumber() { MathSymbol s = First; while (s != null) { if (s.SymbolType == (int)FormulaConstants.Number) { if (s.Symbol == '?') { List <MathFormula> f = s.Children; double a = s.DoubleValue; if (a == Math.E | a == Math.PI) { s.Append(new SimpleSymbol((a == Math.E) ? 'e' : 'p')); MathSymbol s1 = s.Next; s.Remove(); s1.Children = f; s = s1.Next; continue; } int b = 0; bool intv = false; if (Math.Abs(a - Math.Ceiling(a)) < ROUND_EPS) { b = (int)Math.Ceiling(a); intv = true; } else if (Math.Abs(a - Math.Floor(a)) < ROUND_EPS) { b = (int)Math.Floor(a); intv = true; } string str = ""; if (intv) { str = b + ""; } else { str = a + ""; } MathSymbol sOne = s; for (int i = 0; i < str.Length; i++) { MathSymbol symb = (str[i] == MathSymbol.DecimalSep[0]) ? new BinarySymbol('.') : new SimpleSymbol(str[i], false, (int)FormulaConstants.Number); sOne.Append(symb); sOne = sOne.Next; } s.Remove(); sOne.Children = f; s = sOne.Next; } } else { s = s.Next; } } s = First; while (s != null) { if (s.HasChildren) { List <MathFormula> f = s.Children; if (f != null) { for (int i = 0; i < f.Count; i++) { MathFormula form = f[i] as MathFormula; if (form.Count > 0) { form.ReverseNumber(); } } } } s = s.Next; } }
/// <summary> /// The "on click" event handler /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The event arguments</param> private void onMouseClicked(object sender, MouseEventArgs e) { translate(e); if (movedSymbol == null) { movedSymbol = newSymbol; if (movedSymbol != null) { if (movedSymbol is DateTimeSymbol) { DateTimeSymbol dts = movedSymbol as DateTimeSymbol; dts.DateTime = dateTime.DateTime; } IDrawableSymbol ds = movedSymbol as IDrawableSymbol; wImage = ds.PureDrawable.SymbolImage.Width; hImage = ds.PureDrawable.SymbolImage.Height; control.Cursor = CURSOR_MOVE; oldX = imagePoint.X; oldY = imagePoint.Y; DrawCursor(); if (newCursor != null) { DrawCursor(newCursor, true, true); } } if (newRemoveCursor != null) { MathSymbol s = (MathSymbol)newRemoveCursor; if (s.Contains(newCursor)) { newCursor = null; oldCursor = null; } s.Remove(); newRemoveCursor = null; oldRemoveCursor = null; DrawFormulaOnComponent(); } } else { if (newCursor == null) { movedSymbol = null; DrawCursor(); newCursor = null; oldCursor = null; control.Cursor = CURSOR_EDIT; } else { if (newCursor is MathSymbol) { MathSymbol ds = newCursor as MathSymbol; newCursor = MathSymbolDrawable.InsertObject(ds, movedSymbol) as IInsertedObject; } else if (newCursor is MathFormulaDrawable) { MathFormulaDrawable mf = newCursor as MathFormulaDrawable; newCursor = mf.InsertObject(movedSymbol) as IInsertedObject; } //newCursor = newCursor.InsertObject(movedSymbol); movedSymbol = null; DrawCursor(); DrawFormulaOnComponent(); oldCursor = movedSymbol as IInsertedObject; control.Cursor = CURSOR_EDIT; } } }