/// <summary> /// 一次性计算出结果 返回结果值并修改表达式 /// </summary> /// <returns></returns> public string GetValueFinal() { CalData cd = UIController.SimpleCal(value); if (cd == null) { throw new AssignedError("AssignedError::Not defined " + express + "!Ex"); } ExpData ed = cd as ExpData; string str = ed.GetValueEx(); // string s =new UExpData ((cd as ExpData).GetExpress()).GetValueEx(); if (str == null) { str = "0"; throw new ExpError("ExpError::Something Wrong Happened!Final" + '\n'); } value = str; express = str; return(str); }
//f(x,y)=x+y+t /// <summary> /// 替换已知变量,fstr是一个字符串表达式:x+y 不是f=x+y ,没有用了,底层已经能够替换掉它了 /// 没有变量是会原串返回的 /// 里面找未知数时会调用底层 CalString 的函数,里面已经自动排除sin,cos,avg等 函数名了 /// </summary> /// <param name="fstr">含参表达式</param> /// <param name="ps">排除变量</param> /// <returns>返回FuncExpressTemp为替换后的string /// 或含有未知变量返回null</returns> public static string ReplaceParamers(string fstr, string[] ps = null) { string[] strarr = null; FuncString fs = new FuncString(fstr); // fs.SetFuncExpressTemp(fstr); fs.SetFuncExpress(fstr); //为向下兼容不出错 FuncCal fc = new FuncCal(); if (ps == null) { strarr = fs.FindUnKnown(); } else { strarr = fs.FindUnKnown(ps); } fs.SetParamers(strarr); //为向下兼容不出错,不明觉厉 if (strarr.Length != 0) { PushToShow("含有未知数 尝试替换已知变量"); } string[] paramersdata = new string[strarr.Length]; fc.SetFuncString(fs); for (int i = 0; i < strarr.Length; i++) { if (tdc.CheckName(strarr[i])) { CalData datatemp = tdc.GetData(strarr[i]).GetCalData(); switch (datatemp.CalType) { case DataType.BLOCK: { PushToShow("Type not match!"); } break; case DataType.EXP: { ExpData ed = (ExpData)datatemp; paramersdata[i] = ed.GetValueEx(); PushToShow("提取" + strarr[i] + "的值:" + paramersdata[i]); break; } case DataType.MATRIX: { Matrix matrix = (Matrix)datatemp; PushToShow(matrix.ToString()); } break; } // if (datatemp.CalType == DataType.EXP) { // ExpData ed = (ExpData)datatemp; // paramersdata[i] = ed.GetValueEx(); // PushToShow("提取" + strarr[i] + "的值:" + paramersdata[i]); // } // // else // PushToShow("Type not match!"); continue; } PushToShow("未发现变量" + strarr[i] + "还未定义其值\n退出"); return(null); } if (paramersdata.Length != 0) { fc.DealFuncstring(paramersdata); } else { fs.SetFuncExpressTemp(fstr); } return(fc.GetFuncString().GetFuncExpressTemp()); }