MathTools: Adapted to Scatter changes

git-svn-id: svn://ultimatepp.org/upp/trunk@12568 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2018-11-25 11:11:48 +00:00
parent d3371f9118
commit 1fcdbe0834
6 changed files with 111 additions and 97 deletions

View file

@ -14,10 +14,12 @@ void TabCalculator::Init() {
gridConstants.AddColumn(t_("Name"));
gridConstants.AddColumn(t_("Value"));
gridConstants.AddColumn(t_("Units"));
gridConstants.WhenLeftDouble = THISBACK(OnConstant);
gridVariables.AddColumn(t_("Name"));
gridVariables.AddColumn(t_("Value"));
gridVariables.AddColumn(t_("Units"));
code.SetFont(Courier(14));
code.DisableBreakpointing();
@ -37,69 +39,81 @@ void TabCalculator::Init() {
void TabCalculator::UpdateVars() {
String name;
double value;
doubleUnit value;
gridConstants.Clear();
for (int i = 0; i < eval.GetConstantsCount(); ++i) {
eval.GetConstant(i, name, value);
gridConstants.Add(name, value);
gridConstants.Add(name, value.val, value.unit.GetString());
}
gridVariables.Clear();
for (int i = 0; i < eval.GetVariablesCount(); ++i) {
eval.GetVariable(i, name, value);
gridVariables.Add(name, value);
gridVariables.Add(name, value.val, value.unit.GetString());
}
}
/*double EvalExpr2::TermUnit(CParser& p) {
if(p.IsId()) {
//Estan almacenadas laslas unidades
String strId = p.ReadId();
String strsearch;
if (noCase)
strsearch = ToUpper(strId);
else
strsearch = strId;
double ret = constants.Get(strsearch, Null);
if (IsNull(ret)) {
ret = variables.Get(strsearch, Null);
if (IsNull(ret)) {
if (errorIfUndefined)
EvalThrowError(p, Format(t_("Unknown var '%s'"), strId));
ret = variables.GetAdd(strsearch, 0);
}
}
return ret;
}
EvalThrowError(p, t_("Unit id not found"));
EvalExpr2::EvalExpr2() {
units.Add("kg", Unit(1, 0, 0));
units.Add("kg2", Unit(2, 0, 0));
units.Add("kgm", Unit(1, 1, 0));
units.Add("m", Unit(0, 1, 0));
units.Add("m2", Unit(0, 2, 0));
units.Add("m3", Unit(0, 3, 0));
units.Add("seg", Unit(0, 0, 1));
units.Add("s", Unit(0, 0, 1));
units.Add("seg2", Unit(0, 0, 2));
units.Add("s2", Unit(0, 0, 2));
units.Add("N", Unit(1, 1, -2));
for (int i = 0; i < units.GetCount(); ++i)
units.SetKey(i, ToLower(units.GetKey(i)));
}
Unit EvalExpr2::TermUnit(CParser& p) {
if(!p.IsId())
EvalThrowError(p, t_("Unit id not found"));
String strId = ToLower(p.ReadId());
int id = units.Find(strId);
if (id < 0)
EvalThrowError(p, Format(t_("Unknown unit '%s'"), strId));
return units[id];
}
double EvalExpr2::PowUnit(CParser& p) {
Unit EvalExpr2::PowUnit(CParser& p) {
Unit x = TermUnit(p);
for(;;) {
if(p.Char('^'))
x = x.pow(p.ReadDouble());
x.Exp(p.ReadDouble());
else
return x;
}
}
Unit EvalExpr2::MulUnit(CParser& p) {
Unit x = Pow(p);
Unit x = PowUnit(p);
for(;;) {
if(p.Char('*'))
x = x * MulUnit(p);
else if(p.Char('/')) {
Unit y = PowUnit(p);
x = x / y;
if(p.Char('*')) {
Unit multp = MulUnit(p);
x.Mult(multp);
} else if(p.Char('/')) {
Unit multp = MulUnit(p);
x.Div(multp);
} else
return x;
}
}
Unit EvalExpr2::EvalUnit(CParser& p) {
return MulUnit(p);
}*/
CParser::Pos pos = p.GetPos();
Unit res;
try {
res = MulUnit(p);
} catch(...) {
p.SetPos(pos);
}
return res;
}
String EvalExpr2::Eval2(String line, int numDecimals, int tabChars) {
line = TrimBoth(line);
@ -111,7 +125,7 @@ String EvalExpr2::Eval2(String line, int numDecimals, int tabChars) {
p.Set(line);
String var, cte;
int expFrom;
double val;
doubleUnit val;
if (p.IsId()) {
CParser::Pos pos = p.GetPos();
@ -137,23 +151,47 @@ String EvalExpr2::Eval2(String line, int numDecimals, int tabChars) {
expFrom = int(p.GetPtr() - line.Begin());
val = Exp(p);
}
int expTo = int(p.GetPtr() - line.Begin() - 1);
String exp = TrimBoth(line.Mid(expFrom, expTo - expFrom + 1));
String strVal = FormatDoubleFix(val, numDecimals);
String strVal = FormatDoubleFix(val.val, numDecimals);
bool expIsNum = exp == strVal;
if (!var.IsEmpty()) {
if (!var.IsEmpty())
newstr << var << " = ";
variables.GetAdd(var) = val;
} else if (!cte.IsEmpty())
else if (!cte.IsEmpty())
newstr << cte << " = ";
if (!expIsNum)
newstr << exp << " = ";
newstr << strVal;
String strUnit;
Unit unit = EvalUnit(p);
if (!IsNull(unit))
strUnit = unit.GetString();
CParser::Pos pos = p.GetPos();
if (p.Char('=')) {
if (p.IsDouble2()) {
p.ReadDouble();
unit = EvalUnit(p);
if (!IsNull(unit))
strUnit = unit.GetString();
} else
p.SetPos(pos);
} else
p.SetPos(pos);
newstr << " " << strUnit;
if (!var.IsEmpty()) {
if (IsNull(val.unit))
val.unit = unit;
SetVariable(var, val);
}
newstr << " ";
int newstrlen = newstr.GetCount();
int len;
@ -162,15 +200,6 @@ String EvalExpr2::Eval2(String line, int numDecimals, int tabChars) {
for (; len - newstrlen > 0; --len)
newstr << " ";
CParser::Pos pos = p.GetPos();
if (p.Char('=')) {
if (p.IsDouble2())
p.ReadDouble();
else
p.SetPos(pos);
} else
p.SetPos(pos);
String comment = TrimBoth(line.Mid(int(p.GetPtr() - line.Begin())));
newstr << TrimBoth(comment);
}
@ -196,7 +225,8 @@ void TabCalculator::OnChange() {
continue;
int pos0 = code.GetPos(line, 0);
code.Remove(pos0, str.GetCount());
int pos1 = code.GetPos(line+1, 0);
code.Remove(pos0, pos1 - pos0 - 1);
int errPos = str.Find(t_("Error"));
if (errPos >= 0)

View file

@ -39,7 +39,8 @@ void TabData::Init() {
down.splitterDown.SetPos(splitterDownPos, 0);
up.scatter.SetMouseHandling(true, true).ShowButtons().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg();
up.scatter.SetMode(ScatterDraw::MD_ANTIALIASED);
const int totalCols = 50;
editGrid.SetCount(totalCols);
@ -258,7 +259,7 @@ void TabData::OnOpen(bool force, bool updateButtons) {
return;
FindFile ff(fileName);
if(!ff || !ff.IsFile()) {
Exclamation(t_("File does not exist"));
Exclamation(Format(t_("File '%s' does not exist"), DeQtf(fileName)));
return;
}
openMenuButton.PreSelect(fileName);

View file

@ -118,45 +118,20 @@ private:
int splitterPos, splitterDownPos;
};
class Unit {
public:
Unit() : M(0), L(0), T(0) {}
Unit(double m, double l, double t) {
M = m;
L = l;
T = t;
}
Value GetString() {
String ret;
if (M != 0)
ret << "Kg" << "^" << M;
if (L != 0) {
if (!ret.IsEmpty())
ret << "*";
ret << "m" << "^" << L;
}
if (T != 0) {
if (!ret.IsEmpty())
ret << "*";
ret << "sec" << "^" << T;
}
return ret;
}
void pow(double val) {
M = ::pow(M, val);
L = ::pow(L, val);
T = ::pow(T, val);
}
private:
double M, L, T;
};
class EvalExpr2 : public EvalExpr {
public:
EvalExpr2();
String Eval2(String line, int numDecimals, int tabChars);
Unit EvalUnit(CParser& p);
private:
double TermUnit(CParser& p);
Unit TermUnit(CParser& p);
Unit PowUnit(CParser& p);
Unit MulUnit(CParser& p);
VectorMap<String, Unit> units;
};
class TabCalculator : public WithTabCalculator<Tool> {

View file

@ -8,10 +8,9 @@ LAYOUT(TabCalculator, 712, 360)
ITEM(Label, dv___1, SetLabel(t_("Variables")).RightPosZ(0, 136).TopPosZ(264, 18))
ITEM(Label, dv___2, SetLabel(t_("Functions")).RightPosZ(0, 136).TopPosZ(2, 18))
ITEM(Label, dv___3, SetLabel(t_("Constants")).RightPosZ(0, 136).TopPosZ(132, 18))
ITEM(Option, trigInGrad, SetLabel(t_("Trig. in grad.")).LeftPosZ(180, 92).BottomPosZ(2, 18))
ITEM(Label, dv___5, SetLabel(t_("Tab. chars.")).LeftPosZ(412, 60).BottomPosZ(2, 18))
ITEM(Label, dv___4, SetLabel(t_("Tab. chars.")).LeftPosZ(412, 60).BottomPosZ(2, 18))
ITEM(EditIntSpin, tabChars, Max(40).Min(2).NotNull(true).LeftPosZ(472, 40).BottomPosZ(2, 18))
ITEM(Label, dv___7, SetLabel(t_("Num. decimals:")).LeftPosZ(288, 84).BottomPosZ(2, 18))
ITEM(Label, dv___6, SetLabel(t_("Num. decimals:")).LeftPosZ(288, 84).BottomPosZ(2, 18))
ITEM(EditIntSpin, numDecimals, Max(15).Min(0).NotNull(true).LeftPosZ(372, 32).BottomPosZ(2, 18))
ITEM(ArrayCtrl, gridFunctions, RightPosZ(-2, 138).TopPosZ(20, 108))
ITEM(ArrayCtrl, gridConstants, RightPosZ(-2, 138).TopPosZ(152, 108))

View file

@ -21,9 +21,6 @@ esES("Funciones")
T_("Constants")
esES("Constantes")
T_("Case sensitivity")
esES("Sensib. a may/min")
T_("Tab. chars.")
esES("Carac. tab.")
@ -33,6 +30,9 @@ esES("Num. decimales:")
T_("Just edit")
esES("Solo editar")
T_("Case sensitivity")
esES("Sensib. a may/min")
T_("Autoset")
esES("Auto sel.")
@ -66,9 +66,18 @@ esES("Nombre")
T_("Value")
esES("Valor")
T_("Error %s")
T_("Units")
esES("")
T_("Unit id not found")
esES("Id de la unidad no encontrado")
T_("Unknown unit '%s'")
esES("Unidad '%s' desconocida")
T_("Error %s")
esES("Error %s")
T_("Error")
esES("")
@ -112,8 +121,8 @@ esES("No se han encontrado datos&Quiz\303\241s '\302\272 fila es cabecera' no "
T_("Series")
esES("")
T_("File does not exist")
esES("El fichero no existe")
T_("File '%s' does not exist")
esES("El fichero '%s' no existe")
T_("Problem reading binary file")
esES("Problema abriendo fichero binario")

View file

@ -1,4 +1,4 @@
TOPIC("MathTools$en-us")
#include "MathTools$en-us.tppi"
TOPIC("MathTools_en-us")
#include "MathTools_en-us.tppi"
END_TOPIC