Derived formula only from Formula
This commit is contained in:
parent
e4f79ccab6
commit
8dda10d5da
2 changed files with 4 additions and 14 deletions
|
|
@ -458,21 +458,12 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
|
|
||||||
void _solveForVariable(VariableSpec variable) {
|
void _solveForVariable(VariableSpec variable) {
|
||||||
// Check if the formula is already a DerivedFormula
|
// Check if the formula is already a DerivedFormula
|
||||||
if (formula is DerivedFormula) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('Cannot create derived formula from another derived formula'),
|
|
||||||
duration: Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create a DerivedFormula with this input variable as output
|
// Create a DerivedFormula with this input variable as output
|
||||||
|
var rootFormula = FormulaInterface.getRootFormula(formula);
|
||||||
final derivedFormula = DerivedFormula(
|
final derivedFormula = DerivedFormula(
|
||||||
outputName: variable.name,
|
outputName: variable.name,
|
||||||
originalFormula: formula,
|
originalFormula: rootFormula
|
||||||
);
|
);
|
||||||
|
|
||||||
// Navigate to the new DerivedFormula screen
|
// Navigate to the new DerivedFormula screen
|
||||||
|
|
|
||||||
|
|
@ -196,11 +196,10 @@ class DerivedFormula implements FormulaInterface {
|
||||||
return f.input.every( (vs) => vs.unit != "string") && f.output.unit != "string";
|
return f.input.every( (vs) => vs.unit != "string") && f.output.unit != "string";
|
||||||
}
|
}
|
||||||
|
|
||||||
DerivedFormula({required this.outputName, required FormulaInterface originalFormula}) {
|
DerivedFormula({required this.outputName, required this.originalFormula}) {
|
||||||
|
|
||||||
this.originalFormula = FormulaInterface.getRootFormula(originalFormula);
|
|
||||||
|
|
||||||
if( !isDerivable(this.originalFormula) ){
|
if( !isDerivable(originalFormula) ){
|
||||||
throw ArgumentError(
|
throw ArgumentError(
|
||||||
"Derived formulas are not supported for formulas with string inputs, because we can't solve for them. Original formula: ${originalFormula.toString()}");
|
"Derived formulas are not supported for formulas with string inputs, because we can't solve for them. Original formula: ${originalFormula.toString()}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue