/// <summary> /// 异步校验表达式 /// </summary> /// <param name="error"></param> public void Validate(UnityAction <bool, string> error) { var text = StringExpressionInput.text; Loading.SetActive(true); try { var sym = CalcArgs.GetSymexpr(text); var list = new List <string>(); GetAllFactors(sym, list); foreach (var item in RecordManager.tempRecord.quantities) { if (item.processMethod == 1) { if (list.Contains("k_" + item.Symbol) || list.Contains("Δ" + item.Symbol)) { Loading.SetActive(false); error?.Invoke(false, $"直接计算的物理量{item.Name}不能使用变化量或变化率"); return; } } else if (item.processMethod == 2) { if (list.Contains("k_" + item.Symbol) || list.Contains(item.Symbol)) { Loading.SetActive(false); error?.Invoke(false, $"逐差法处理的物理量{item.Name}不能直接使用其测量平均值或变化率"); return; } } else if (item.processMethod == 3 || item.processMethod == 4) { if (list.Contains(item.Symbol) || list.Contains("Δ" + item.Symbol)) { Loading.SetActive(false); error?.Invoke(false, $"物理量{item.Name}不能直接使用其测量平均值或变化量"); return; } } } LatexEquationRender.Render(sym.ToLaTeX(), action: _ => { Loading.SetActive(false); var(res, message) = StaticMethods.ValidExpression(ExpressionToCalc(text)); error?.Invoke(res, message); }, errorHandler: () => { Loading.SetActive(false); error?.Invoke(false, "表达式渲染失败"); }); } catch { Loading.SetActive(false); error?.Invoke(false, "表达式格式不正确"); } }
public void Render() { var text = _Expression.text; LatexEquationRender.Render(CalcArgs.GetSymexpr(text).ToLaTeX(), x => { _Image.FitHeight(x); }); }
/// <summary> /// 渲染合成量表达式图片 /// </summary> public void Render() { var exp = CalcArgs.GetSymexpr( EnterExpression.ExpressionToShow(RecordManager.tempRecord.stringExpression)) .ToLaTeX(); LatexEquationRender.Render(exp, x => { _Image.FitImage(x, 270, 40); }); }
/// <summary> /// 渲染表达式 /// </summary> public void Render() { var text = StringExpressionInput.text; if (string.IsNullOrEmpty(text)) { LatexEquationRender.Render("expr.", LoadSprite); } else { LatexEquationRender.Render(CalcArgs.GetSymexpr(text).ToLaTeX(), LoadSprite); } }
public static string ExpressionToShow(string expr) { try { var sym = CalcArgs.GetSymexpr(expr); var factors = new List <string>(); GetAllFactors(sym, factors); factors = factors.OrderByDescending(x => x.Length).ToList(); Dictionary <string, string> replacement = new Dictionary <string, string>(); foreach (var item in factors) { string guid = GetUniqueIDTO22(); replacement.Add(guid, item); expr = expr.Replace(item, guid); } foreach (var item in RecordManager.tempRecord.quantities) { var replace = replacement.Where(x => x.Value.Equals(item.Symbol)); if (replace.Any()) { var tmp = replace.First(); if (item.processMethod == 1) { expr = expr.Replace(tmp.Key, item.Symbol); } else if (item.processMethod == 2) { expr = expr.Replace(tmp.Key, "Δ" + item.Symbol); } else if (item.processMethod == 3 || item.processMethod == 4) { expr = expr.Replace(tmp.Key, "k_" + item.Symbol); } } } } catch { } return(expr); }